public class JPAEntityManager extends Object implements javax.persistence.EntityManager
| Modifier and Type | Field and Description |
|---|---|
protected org.datanucleus.ExecutionContext |
ec
The underlying ExecutionContext managing the persistence.
|
protected javax.persistence.EntityManagerFactory |
emf
Parent EntityManagerFactory.
|
protected JPAFetchPlan |
fetchPlan
Fetch Plan (extension).
|
protected javax.persistence.FlushModeType |
flushMode
The Flush Mode.
|
protected static org.datanucleus.util.Localiser |
LOCALISER
Localisation utility for output messages
|
protected javax.persistence.PersistenceContextType |
persistenceContextType
Type of Persistence Context
|
protected javax.persistence.EntityTransaction |
tx
Current Transaction (when using ResourceLocal).
|
| Constructor and Description |
|---|
JPAEntityManager(javax.persistence.EntityManagerFactory theEMF,
org.datanucleus.NucleusContext nucleusCtx,
javax.persistence.PersistenceContextType contextType)
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.
|
JPAQuery |
createNamedQuery(String queryName)
Create an instance of Query for executing a named query (in JPQL or SQL).
|
<T> javax.persistence.TypedQuery<T> |
createNamedQuery(String queryName,
Class<T> resultClass)
Create an instance of Query for executing a named query (in JPQL or SQL).
|
StoredProcedureQuery |
createNamedStoredProcedureQuery(String procName)
Create an instance of Query for executing a stored procedure.
|
javax.persistence.Query |
createNativeQuery(String sqlString)
Create an instance of Query for executing an SQL statement.
|
javax.persistence.Query |
createNativeQuery(String sqlString,
Class resultClass)
Create an instance of Query for executing an SQL query.
|
javax.persistence.Query |
createNativeQuery(String sqlString,
String resultSetMapping)
Create an instance of Query for executing an SQL query.
|
<T> javax.persistence.TypedQuery<T> |
createQuery(javax.persistence.criteria.CriteriaQuery<T> criteriaQuery)
Method to return a query for the specified Criteria Query.
|
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) |
StoredProcedureQuery |
createStoredProcedureQuery(String procName)
Create an instance of Query for executing a stored procedure.
|
StoredProcedureQuery |
createStoredProcedureQuery(String procedureName,
Class... resultClasses)
Create an instance of StoredProcedureQuery for executing a stored procedure in the database.
|
StoredProcedureQuery |
createStoredProcedureQuery(String procedureName,
String... resultSetMappings)
Create an instance of StoredProcedureQuery for executing a stored procedure in the database.
|
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.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 |
isOpen()
Determine whether the EntityManager is open.
|
boolean |
isTransactionActive() |
void |
joinTransaction()
Indicate to the EntityManager that a JTA transaction is active.
|
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.
|
Object |
merge(Object entity)
Merge the state of the given entity into the current persistence context.
|
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(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 static final org.datanucleus.util.Localiser LOCALISER
protected org.datanucleus.ExecutionContext ec
protected javax.persistence.EntityManagerFactory emf
protected javax.persistence.EntityTransaction tx
protected javax.persistence.FlushModeType flushMode
protected javax.persistence.PersistenceContextType persistenceContextType
protected JPAFetchPlan fetchPlan
public JPAEntityManager(javax.persistence.EntityManagerFactory theEMF,
org.datanucleus.NucleusContext nucleusCtx,
javax.persistence.PersistenceContextType contextType)
theEMF - The parent EntityManagerFactorynucleusCtx - Nucleus ContextcontextType - The Persistence Context typepublic void clear()
clear in interface javax.persistence.EntityManagerpublic boolean isOpen()
isOpen in interface javax.persistence.EntityManagerpublic org.datanucleus.ExecutionContext getExecutionContext()
public void close()
close in interface javax.persistence.EntityManagerIllegalStateException - if the EntityManager is container-managed.public javax.persistence.EntityManagerFactory getEntityManagerFactory()
getEntityManagerFactory in interface javax.persistence.EntityManagerIllegalStateException - if the entity manager has
been closed.public JPAFetchPlan getFetchPlan()
public boolean contains(Object entity)
contains in interface javax.persistence.EntityManagerentity - IllegalArgumentException - if not an entitypublic Object find(Class entityClass, Object primaryKey)
find in interface javax.persistence.EntityManagerentityClass - 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.EntityManagerentityClass - 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.EntityManagerpublic <T> T find(Class<T> entityClass, Object primaryKey, javax.persistence.LockModeType lock, Map<String,Object> properties)
find in interface javax.persistence.EntityManagerentityClass - 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.EntityManagerpublic <T> T unwrap(Class<T> cls)
unwrap in interface javax.persistence.EntityManagercls - 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.EntityManagerentityClass - 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.EntityManagerentity - 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.EntityManagerentity - 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.EntityManagerentity - 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 Object merge(Object entity)
merge in interface javax.persistence.EntityManagerentity - 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 void detach(Object entity)
detach in interface javax.persistence.EntityManagerentity - IllegalArgumentException - if the instance is not an entitypublic void refresh(Object entity)
refresh in interface javax.persistence.EntityManagerentity - 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.EntityManagerentity - properties - 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.EntityManagerpublic void refresh(Object entity, javax.persistence.LockModeType lock, Map<String,Object> properties)
refresh in interface javax.persistence.EntityManagerpublic void remove(Object entity)
remove in interface javax.persistence.EntityManagerentity - 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 flush()
flush in interface javax.persistence.EntityManagerjavax.persistence.TransactionRequiredException - if there is no transactionjavax.persistence.PersistenceException - if the flush failspublic javax.persistence.FlushModeType getFlushMode()
getFlushMode in interface javax.persistence.EntityManagerpublic void setFlushMode(javax.persistence.FlushModeType flushMode)
setFlushMode in interface javax.persistence.EntityManagerflushMode - Mode of flushpublic javax.persistence.LockModeType getLockMode(Object entity)
getLockMode in interface javax.persistence.EntityManagerentity - 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.EntityManagerIllegalStateException - if invoked on a JTA EntityManager.public void joinTransaction()
joinTransaction in interface javax.persistence.EntityManagerjavax.persistence.TransactionRequiredException - if there is no transaction.public <T> javax.persistence.TypedQuery<T> createQuery(javax.persistence.criteria.CriteriaQuery<T> criteriaQuery)
createQuery in interface javax.persistence.EntityManagercriteriaQuery - The Criteria querypublic javax.persistence.criteria.CriteriaBuilder getCriteriaBuilder()
getCriteriaBuilder in interface javax.persistence.EntityManagerIllegalStateException - if the entity manager has been closed.public <T> javax.persistence.TypedQuery<T> createNamedQuery(String queryName, Class<T> resultClass)
createNamedQuery in interface javax.persistence.EntityManagerqueryName - 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.EntityManagerqueryName - the name of a query defined in metadataIllegalArgumentException - if a query has not been defined with the given namepublic javax.persistence.Query createNativeQuery(String sqlString)
createNativeQuery in interface javax.persistence.EntityManagersqlString - a native SQL query stringpublic javax.persistence.Query createNativeQuery(String sqlString, Class resultClass)
createNativeQuery in interface javax.persistence.EntityManagersqlString - a native SQL query stringresultClass - the class of the resulting instance(s)public javax.persistence.Query createNativeQuery(String sqlString, String resultSetMapping)
createNativeQuery in interface javax.persistence.EntityManagersqlString - a native SQL query stringresultSetMapping - the name of the result set mappingpublic StoredProcedureQuery createNamedStoredProcedureQuery(String procName)
procName - the name of the stored procedure defined in metadataIllegalArgumentException - if a stored procedure has not been defined with the given namepublic StoredProcedureQuery createStoredProcedureQuery(String procName)
procName - Name of stored procedure defined in metadatapublic StoredProcedureQuery createStoredProcedureQuery(String procedureName, Class... resultClasses)
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 StoredProcedureQuery createStoredProcedureQuery(String procedureName, String... resultSetMappings)
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.EntityManagerpublic JPAQuery createQuery(String queryString)
createQuery in interface javax.persistence.EntityManagerqueryString - a Java Persistence query stringIllegalArgumentException - if query string is not validpublic void setProperty(String propertyName, Object value)
setProperty in interface javax.persistence.EntityManagerpropertyName - 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.EntityManagerpublic Set<String> getSupportedProperties()
public javax.persistence.metamodel.Metamodel getMetamodel()
getMetamodel in interface javax.persistence.EntityManagerIllegalStateException - 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 typeCopyright © 2012. All Rights Reserved.