public class JPAEntityManager extends Object implements javax.persistence.EntityManager
Modifier and Type | Field and Description |
---|---|
protected boolean |
closed |
protected org.datanucleus.ExecutionContext |
ec
The underlying ExecutionContext managing the persistence.
|
protected JPAEntityManagerFactory |
emf
Parent EntityManagerFactory.
|
protected JPAFetchPlan |
fetchPlan
Fetch Plan (extension).
|
protected javax.persistence.FlushModeType |
flushMode
The Flush Mode.
|
protected javax.persistence.PersistenceContextType |
persistenceContextType
Type of Persistence Context
|
protected javax.persistence.SynchronizationType |
syncType |
protected javax.persistence.EntityTransaction |
tx
Current Transaction (when using ResourceLocal).
|
Constructor and Description |
---|
JPAEntityManager(JPAEntityManagerFactory theEMF,
org.datanucleus.PersistenceNucleusContext nucleusCtx,
javax.persistence.PersistenceContextType contextType,
javax.persistence.SynchronizationType syncType)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clear the persistence context, causing all managed entities to become detached.
|
void |
close()
Close an (application-managed) EntityManager.
|
boolean |
contains(Object entity)
Check if the instance belongs to the current persistence context.
|
<T> javax.persistence.EntityGraph<T> |
createEntityGraph(Class<T> rootType) |
javax.persistence.EntityGraph<?> |
createEntityGraph(String graphName) |
JPAQuery |
createNamedQuery(String queryName)
Create an instance of Query for executing a named query (in JPQL or native).
|
<T> javax.persistence.TypedQuery<T> |
createNamedQuery(String queryName,
Class<T> resultClass)
Create an instance of Query for executing a named query (in JPQL or native).
|
javax.persistence.StoredProcedureQuery |
createNamedStoredProcedureQuery(String procName)
Create an instance of Query for executing a stored procedure.
|
javax.persistence.Query |
createNativeQuery(String queryString)
Create an instance of Query for executing a native query statement.
|
javax.persistence.Query |
createNativeQuery(String queryString,
Class resultClass)
Create an instance of Query for executing a "native" query.
|
javax.persistence.Query |
createNativeQuery(String queryString,
String resultSetMapping)
Create an instance of Query for executing a native query.
|
javax.persistence.Query |
createQuery(javax.persistence.criteria.CriteriaDelete crit) |
<T> javax.persistence.TypedQuery<T> |
createQuery(javax.persistence.criteria.CriteriaQuery<T> criteriaQuery)
Method to return a query for the specified Criteria Query.
|
javax.persistence.Query |
createQuery(javax.persistence.criteria.CriteriaUpdate crit) |
JPAQuery |
createQuery(String queryString)
Create an instance of Query for executing a JPQL statement.
|
<T> javax.persistence.TypedQuery<T> |
createQuery(String queryString,
Class<T> resultClass) |
javax.persistence.StoredProcedureQuery |
createStoredProcedureQuery(String procName)
Create an instance of Query for executing a stored procedure.
|
javax.persistence.StoredProcedureQuery |
createStoredProcedureQuery(String procedureName,
Class... resultClasses)
Create an instance of StoredProcedureQuery for executing a stored procedure in the database.
|
javax.persistence.StoredProcedureQuery |
createStoredProcedureQuery(String procedureName,
String... resultSetMappings)
Create an instance of StoredProcedureQuery for executing a stored procedure in the database.
|
void |
detach(Collection entities) |
void |
detach(Object... entities) |
void |
detach(Object entity)
Remove the given entity from the persistence context, causing a managed entity to become
detached.
|
<T> T |
find(Class<T> entityClass,
Object primaryKey,
javax.persistence.LockModeType lock) |
<T> T |
find(Class<T> entityClass,
Object primaryKey,
javax.persistence.LockModeType lock,
Map<String,Object> properties)
Method to return the persistent object of the specified entity type with the provided PK.
|
<T> T |
find(Class<T> entityClass,
Object primaryKey,
Map<String,Object> properties)
Find by primary key, using the specified properties.
|
Object |
find(Class entityClass,
Object primaryKey)
Method to find an object from its primary key.
|
void |
flush()
Synchronize the persistence context to the underlying database.
|
javax.persistence.criteria.CriteriaBuilder |
getCriteriaBuilder()
Return an instance of QueryBuilder for the creation of Criteria API QueryDefinition objects.
|
Object |
getDelegate()
Return the underlying provider object for the EntityManager, if available.
|
javax.persistence.EntityGraph<?> |
getEntityGraph(String graphName) |
<T> List<javax.persistence.EntityGraph<? super T>> |
getEntityGraphs(Class<T> entityClass) |
javax.persistence.EntityManagerFactory |
getEntityManagerFactory()
Return the entity manager factory for the entity manager.
|
org.datanucleus.ExecutionContext |
getExecutionContext() |
JPAFetchPlan |
getFetchPlan()
Acessor for the current FetchPlan
|
javax.persistence.FlushModeType |
getFlushMode()
Get the flush mode that applies to all objects contained in the persistence context.
|
static javax.persistence.LockModeType |
getJPALockModeTypeForLockType(short lockType)
Convenience method to convert from LockManager lock type to JPA LockModeType
|
javax.persistence.LockModeType |
getLockMode(Object entity)
Get the current lock mode for the entity instance.
|
static short |
getLockTypeForJPALockModeType(javax.persistence.LockModeType lock)
Convenience method to convert from the JPA LockModeType to the type expected by LockManager
|
javax.persistence.metamodel.Metamodel |
getMetamodel()
Return an instance of Metamodel interface for access to the metamodel of the persistence unit.
|
Map<String,Object> |
getProperties()
Get the properties and associated values that are in effect for the entity manager.
|
Object |
getReference(Class entityClass,
Object primaryKey)
Get an instance, whose state may be lazily fetched.
|
Set<String> |
getSupportedProperties()
Get the names of the properties that are supported for use with the entity manager.
|
javax.persistence.EntityTransaction |
getTransaction()
Return the resource-level transaction object.
|
boolean |
isContainerManaged() |
boolean |
isJoinedToTransaction()
Return whether this EntityManager is joined to the current transaction.
|
boolean |
isOpen()
Determine whether the EntityManager is open.
|
boolean |
isTransactionActive() |
void |
joinTransaction()
Indicate to the EntityManager that a JTA transaction is active so join to it.
|
void |
lock(Object entity,
javax.persistence.LockModeType lockMode)
Set the lock mode for an entity object contained in the persistence context.
|
void |
lock(Object entity,
javax.persistence.LockModeType lock,
Map<String,Object> properties)
Set the lock mode for an entity object contained in the persistence context.
|
Collection |
merge(Collection entities) |
Object[] |
merge(Object... entities) |
Object |
merge(Object entity)
Merge the state of the given entity into the current persistence context.
|
void |
persist(Collection entities) |
void |
persist(Object... entities) |
void |
persist(Object entity)
Make an instance managed and persistent.
|
void |
refresh(Object entity)
Refresh the state of the instance from the database, overwriting changes made to the entity, if any.
|
void |
refresh(Object entity,
javax.persistence.LockModeType lock) |
void |
refresh(Object entity,
javax.persistence.LockModeType lock,
Map<String,Object> properties) |
void |
refresh(Object entity,
Map<String,Object> properties)
Refresh the state of the instance from the database, using the specified properties,
and overwriting changes made to the entity, if any.
|
void |
remove(Collection entities) |
void |
remove(Object... entities) |
void |
remove(Object entity)
Remove the entity instance.
|
void |
setFlushMode(javax.persistence.FlushModeType flushMode)
Set the flush mode that applies to all objects contained in the persistence context.
|
void |
setProperty(String propertyName,
Object value)
Set an entity manager property.
|
<T> T |
unwrap(Class<T> cls)
Return an object of the specified type to allow access to the provider-specific API.
|
protected boolean closed
protected org.datanucleus.ExecutionContext ec
protected JPAEntityManagerFactory emf
protected javax.persistence.EntityTransaction tx
protected javax.persistence.FlushModeType flushMode
protected javax.persistence.PersistenceContextType persistenceContextType
protected javax.persistence.SynchronizationType syncType
protected JPAFetchPlan fetchPlan
public JPAEntityManager(JPAEntityManagerFactory theEMF, org.datanucleus.PersistenceNucleusContext nucleusCtx, javax.persistence.PersistenceContextType contextType, javax.persistence.SynchronizationType syncType)
theEMF
- The parent EntityManagerFactorynucleusCtx
- Nucleus ContextcontextType
- The Persistence Context typesyncType
- The Synchronisation typepublic void clear()
clear
in interface javax.persistence.EntityManager
public boolean isContainerManaged()
public boolean isOpen()
isOpen
in interface javax.persistence.EntityManager
public org.datanucleus.ExecutionContext getExecutionContext()
public void close()
close
in interface javax.persistence.EntityManager
public javax.persistence.EntityManagerFactory getEntityManagerFactory()
getEntityManagerFactory
in interface javax.persistence.EntityManager
IllegalStateException
- if the entity manager has
been closed.public JPAFetchPlan getFetchPlan()
public boolean contains(Object entity)
contains
in interface javax.persistence.EntityManager
entity
- The entityIllegalArgumentException
- if not an entitypublic Object find(Class entityClass, Object primaryKey)
find
in interface javax.persistence.EntityManager
entityClass
- The entity classprimaryKey
- The PK valueIllegalArgumentException
- if the first argument does not denote an entity type or the second argument is
not a valid type for that entity's primary keypublic <T> T find(Class<T> entityClass, Object primaryKey, Map<String,Object> properties)
find
in interface javax.persistence.EntityManager
entityClass
- Class of the entity requiredprimaryKey
- The PK valueproperties
- standard and vendor-specific propertiesIllegalArgumentException
- if the first argument does not denote an entity type or the
second argument is is not a valid type for that entity's primary key or is nullpublic <T> T find(Class<T> entityClass, Object primaryKey, javax.persistence.LockModeType lock)
find
in interface javax.persistence.EntityManager
public <T> T find(Class<T> entityClass, Object primaryKey, javax.persistence.LockModeType lock, Map<String,Object> properties)
find
in interface javax.persistence.EntityManager
entityClass
- Entity typeprimaryKey
- PK. Can be an instanceof the PK type, or the key when using single-fieldlock
- Any locking to applyproperties
- Any optional properties to control the operationpublic Object getDelegate()
getDelegate
in interface javax.persistence.EntityManager
public <T> T unwrap(Class<T> cls)
unwrap
in interface javax.persistence.EntityManager
cls
- the class of the object to be returned. This is normally either the underlying
EntityManager implementation class or an interface that it implements.javax.persistence.PersistenceException
- if the provider does not support the call.public Object getReference(Class entityClass, Object primaryKey)
getReference
in interface javax.persistence.EntityManager
entityClass
- Class of the entityprimaryKey
- The PKIllegalArgumentException
- if the first argument does not denote an entity type or the second argument is not
a valid type for that entities PKjavax.persistence.EntityNotFoundException
- if the entity state cannot be accessedpublic void lock(Object entity, javax.persistence.LockModeType lockMode)
lock
in interface javax.persistence.EntityManager
entity
- The EntitylockMode
- Lock modejavax.persistence.PersistenceException
- if an unsupported lock call is madeIllegalArgumentException
- if the instance is not an entity or is a detached entityjavax.persistence.TransactionRequiredException
- if there is no transactionpublic void lock(Object entity, javax.persistence.LockModeType lock, Map<String,Object> properties)
lock
in interface javax.persistence.EntityManager
entity
- The Entitylock
- Lock modeproperties
- Optional properties controlling the operationjavax.persistence.PersistenceException
- if an unsupported lock call is madeIllegalArgumentException
- if the instance is not an entity or is a detached entityjavax.persistence.TransactionRequiredException
- if there is no transactionpublic void persist(Object entity)
persist
in interface javax.persistence.EntityManager
entity
- The Entityjavax.persistence.EntityExistsException
- if the entity already exists.
(The EntityExistsException may be thrown when the persist operation is invoked,
or the EntityExistsException/PersistenceException may be thrown at flush/commit time.)IllegalArgumentException
- if not an entityjavax.persistence.TransactionRequiredException
- if invoked on a container-managed entity manager
of type PersistenceContextType.TRANSACTION and there is no transaction.public void persist(Collection entities)
public void persist(Object... entities)
public Object merge(Object entity)
merge
in interface javax.persistence.EntityManager
entity
- The EntityIllegalArgumentException
- if instance is not an entity or is a removed entityjavax.persistence.TransactionRequiredException
- if invoked on a container-managed entity manager
of type PersistenceContextType.TRANSACTION and there is no transaction.public Collection merge(Collection entities)
public void detach(Object entity)
detach
in interface javax.persistence.EntityManager
entity
- The entityIllegalArgumentException
- if the instance is not an entitypublic void detach(Collection entities)
public void detach(Object... entities)
public void refresh(Object entity)
refresh
in interface javax.persistence.EntityManager
entity
- The EntityIllegalArgumentException
- if not an entity or entity is not managedjavax.persistence.TransactionRequiredException
- if invoked on a container-managed entity manager
of type PersistenceContextType.TRANSACTION and there is no transaction.javax.persistence.EntityNotFoundException
- if the entity no longer exists in the databasepublic void refresh(Object entity, Map<String,Object> properties)
refresh
in interface javax.persistence.EntityManager
entity
- The entityproperties
- standard and vendor-specific propertiesIllegalArgumentException
- if the instance is not an entity or the entity is not managedjavax.persistence.TransactionRequiredException
- if invoked on a container-managed entity manager
of type PersistenceContextType.TRANSACTION and there is no transaction.javax.persistence.EntityNotFoundException
- if the entity no longer exists in the databasepublic void refresh(Object entity, javax.persistence.LockModeType lock)
refresh
in interface javax.persistence.EntityManager
public void refresh(Object entity, javax.persistence.LockModeType lock, Map<String,Object> properties)
refresh
in interface javax.persistence.EntityManager
public void remove(Object entity)
remove
in interface javax.persistence.EntityManager
entity
- The EntityIllegalArgumentException
- if not an entity or if a detached entityjavax.persistence.TransactionRequiredException
- if invoked on a container-managed entity manager
of type PersistenceContextType.TRANSACTION and there is no transaction.public void remove(Collection entities)
public void remove(Object... entities)
public void flush()
flush
in interface javax.persistence.EntityManager
javax.persistence.TransactionRequiredException
- if there is no transactionjavax.persistence.PersistenceException
- if the flush failspublic javax.persistence.FlushModeType getFlushMode()
getFlushMode
in interface javax.persistence.EntityManager
public void setFlushMode(javax.persistence.FlushModeType flushMode)
setFlushMode
in interface javax.persistence.EntityManager
flushMode
- Mode of flushpublic javax.persistence.LockModeType getLockMode(Object entity)
getLockMode
in interface javax.persistence.EntityManager
entity
- The entity in questionjavax.persistence.TransactionRequiredException
- if there is no transactionIllegalArgumentException
- if the instance is not a managed entity and a transaction is activepublic javax.persistence.EntityTransaction getTransaction()
getTransaction
in interface javax.persistence.EntityManager
IllegalStateException
- if invoked on a JTA EntityManager.public void joinTransaction()
joinTransaction
in interface javax.persistence.EntityManager
javax.persistence.TransactionRequiredException
- if there is no transaction.public boolean isJoinedToTransaction()
isJoinedToTransaction
in interface javax.persistence.EntityManager
public <T> javax.persistence.TypedQuery<T> createQuery(javax.persistence.criteria.CriteriaQuery<T> criteriaQuery)
createQuery
in interface javax.persistence.EntityManager
criteriaQuery
- The Criteria querypublic javax.persistence.Query createQuery(javax.persistence.criteria.CriteriaUpdate crit)
createQuery
in interface javax.persistence.EntityManager
public javax.persistence.Query createQuery(javax.persistence.criteria.CriteriaDelete crit)
createQuery
in interface javax.persistence.EntityManager
public javax.persistence.criteria.CriteriaBuilder getCriteriaBuilder()
getCriteriaBuilder
in interface javax.persistence.EntityManager
IllegalStateException
- if the entity manager has been closed.public <T> javax.persistence.TypedQuery<T> createNamedQuery(String queryName, Class<T> resultClass)
createNamedQuery
in interface javax.persistence.EntityManager
queryName
- the name of a query defined in metadataIllegalArgumentException
- if a query has not been defined with the given namepublic JPAQuery createNamedQuery(String queryName)
createNamedQuery
in interface javax.persistence.EntityManager
queryName
- the name of a query defined in metadataIllegalArgumentException
- if a query has not been defined with the given namepublic javax.persistence.Query createNativeQuery(String queryString)
createNativeQuery
in interface javax.persistence.EntityManager
queryString
- a native query stringpublic javax.persistence.Query createNativeQuery(String queryString, Class resultClass)
createNativeQuery
in interface javax.persistence.EntityManager
queryString
- a native query stringresultClass
- the class of the resulting instance(s)public javax.persistence.Query createNativeQuery(String queryString, String resultSetMapping)
createNativeQuery
in interface javax.persistence.EntityManager
queryString
- a native query stringresultSetMapping
- the name of the result set mappingpublic javax.persistence.StoredProcedureQuery createNamedStoredProcedureQuery(String procName)
createNamedStoredProcedureQuery
in interface javax.persistence.EntityManager
procName
- the name of the stored procedure defined in metadataIllegalArgumentException
- if a stored procedure has not been defined with the given namepublic javax.persistence.StoredProcedureQuery createStoredProcedureQuery(String procName)
createStoredProcedureQuery
in interface javax.persistence.EntityManager
procName
- Name of stored procedure defined in metadatapublic javax.persistence.StoredProcedureQuery createStoredProcedureQuery(String procedureName, Class... resultClasses)
createStoredProcedureQuery
in interface javax.persistence.EntityManager
procedureName
- name of the stored procedure in the databaseresultClasses
- classes to which the result sets produced by the stored procedure are to
be mappedIllegalArgumentException
- if a stored procedure of the given name does not exist or the
query execution will failpublic javax.persistence.StoredProcedureQuery createStoredProcedureQuery(String procedureName, String... resultSetMappings)
createStoredProcedureQuery
in interface javax.persistence.EntityManager
procedureName
- name of the stored procedure in the databaseresultSetMappings
- the names of the result set mappings to be used in mapping result sets
returned by the stored procedureIllegalArgumentException
- if a stored procedure or result set mapping of the given name does not exist
or the query execution will failpublic <T> javax.persistence.TypedQuery<T> createQuery(String queryString, Class<T> resultClass)
createQuery
in interface javax.persistence.EntityManager
public JPAQuery createQuery(String queryString)
createQuery
in interface javax.persistence.EntityManager
queryString
- a Java Persistence query stringIllegalArgumentException
- if query string is not validpublic void setProperty(String propertyName, Object value)
setProperty
in interface javax.persistence.EntityManager
propertyName
- Name of the propertyvalue
- The valueIllegalArgumentException
- if the second argument is not valid for the implementationpublic Map<String,Object> getProperties()
getProperties
in interface javax.persistence.EntityManager
public Set<String> getSupportedProperties()
public javax.persistence.metamodel.Metamodel getMetamodel()
getMetamodel
in interface javax.persistence.EntityManager
IllegalStateException
- if the entity manager has been closed.public boolean isTransactionActive()
public static short getLockTypeForJPALockModeType(javax.persistence.LockModeType lock)
lock
- JPA LockModeTypepublic static javax.persistence.LockModeType getJPALockModeTypeForLockType(short lockType)
lockType
- Lock typepublic <T> javax.persistence.EntityGraph<T> createEntityGraph(Class<T> rootType)
createEntityGraph
in interface javax.persistence.EntityManager
public javax.persistence.EntityGraph<?> createEntityGraph(String graphName)
createEntityGraph
in interface javax.persistence.EntityManager
public javax.persistence.EntityGraph<?> getEntityGraph(String graphName)
getEntityGraph
in interface javax.persistence.EntityManager
Copyright © 2015. All rights reserved.