Class EntityManagerImpl
- All Implemented Interfaces:
EntityManager,AutoCloseable,JpaEntityManager
Purpose: Contains the implementation of the EntityManager.
Description: This class provides the implementation for the combined EclipseLink and JPA EntityManager class.
Responsibilities: It is responsible for tracking transaction state and the objects within that transaction.
- Since:
- TopLink Essentials - JPA 1.0
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanJoin existing transaction property, allows reading through write connection.protected booleanProperty to avoid writing to the cache on commit (merge)protected booleanProperty to avoid resuming unit of work if going to be closed on commit anyway.protected UnitOfWork.CommitOrderTypeAllow updates to be ordered by id to avoid possible deadlocks.protected booleanprotected Map<String, ConnectionPolicy> In case of composite persistence unit this map is used instead of connectionPolicy attribute.protected ConnectionPolicyConnection policy used to create ClientSession, allows using a different pool/connection/exclusive connections.protected AbstractSessionReferences the DatabaseSession that this deployment is using.protected RepeatableWriteUnitOfWorkStores the UnitOfWork representing the persistence context.protected EntityManagerFactoryDelegateReferences to the parent factory that has created this entity manager.protected StringThe FlashClearCache mode to be used.protected FlushModeTypeFlush mode property, allows flush before query to be avoided.protected booleanStore if this entity manager has been closed.protected WeakHashMap<QueryImpl, QueryImpl> Keep a list of openQueries that are executed in this entity manager.protected booleanProperty to avoid discover new objects in unit of work if application always uses persist.Local properties passed from createEntityManager.protected AbstractSessionStores a session used for read-only queries.protected ReferenceModeReference mode property, allows weak unit of work references to allow garbage collection during a transaction.protected booleanDetermine if does-exist should be performed on persist.protected SynchronizationTypeTracks if this EntityManager should automatically associate with the transaction or not -
Constructor Summary
ConstructorsConstructorDescriptionEntityManagerImpl(String sessionName) Constructor returns an EntityManager assigned to the a particular DatabaseSession.EntityManagerImpl(EntityManagerFactoryDelegate factory, Map properties, SynchronizationType syncType) Constructor called from the EntityManagerFactory to create an EntityManagerEntityManagerImpl(AbstractSession databaseSession, SynchronizationType syncType) Constructor called from the EntityManagerFactory to create an EntityManagerEntityManagerImpl(AbstractSession databaseSession, Map properties, SynchronizationType syncType) Constructor called from the EntityManagerFactory to create an EntityManager -
Method Summary
Modifier and TypeMethodDescriptionvoidaddOpenQuery(QueryImpl query) Queries that leave the connection and are executed against this entity manager will be added here.protected ObjectcheckForTransaction(boolean validateExistence) Return the current, joined transaction object.voidclear()Clear the persistence context, causing all managed entities to become detached.voidclose()Closes this EntityManager.protected voidClose any open queries executed against this entity manager.0booleanCheck if the instance belongs to the current persistence context.protected booleancontains(Object entity, UnitOfWork uow) Check if the instance belongs to the current persistence context.copy(Object entityOrEntities, AttributeGroup group) This method will return copy the passed entity using the passed AttributeGroup.protected voidcreateConnectionPolicies(Map mapOfProperties) Create connection policy using properties.protected voidCreate connection policy using properties.protected static ConnectionPolicycreateConnectionPolicy(ServerSession serverSession, Map properties) Create connection policy using properties.createDescriptorNamedQuery(String queryName, Class<?> descriptorClass) This method will create a query object that wraps a EclipseLink Named Query.createDescriptorNamedQuery(String queryName, Class<?> descriptorClass, List argumentTypes) This method will create a query object that wraps a EclipseLink Named Query.<T> EntityGraph<T> createEntityGraph(Class<T> rootType) createEntityGraph(String graphName) createNamedQuery(String name) Create an instance of Query for executing a named query (in EJBQL or native SQL).<T> TypedQuery<T> createNamedQuery(String name, Class<T> resultClass) Create an instance of TypedQuery for executing a named query (in the Java Persistence query language or in native SQL).Create an instance of StoredProcedureQuery for executing a stored procedure in the database.createNativeQuery(String sqlString) Create an instance of Query for executing a native SQL query.createNativeQuery(String sqlString, Class resultType) This method is used to create a query using SQL.createNativeQuery(String sqlString, String resultSetMapping) Create an instance of Query for executing a native SQL query.createQuery(CriteriaDelete deleteQuery) <T> TypedQuery<T> createQuery(CriteriaQuery<T> criteriaQuery) createQuery(CriteriaUpdate updateQuery) createQuery(String jpqlString) Create an instance of Query for executing an JPQL query.<T> TypedQuery<T> createQuery(String qlString, Class<T> resultClass) Create an instance of TypedQuery for executing a Java Persistence query language statement.createQuery(Expression expression, Class<?> resultType) This method is used to create a query using a EclipseLink Expression and the return type.createQuery(Call call) This method is used to create a query using a EclipseLink Call.createQuery(Call call, Class<?> entityClass) This method is used to create a query using a EclipseLink Call.createQuery(DatabaseQuery databaseQuery) This method is used to create a query using a EclipseLink DatabaseQuery.createQueryByExample(Object exampleObject) This method is used to create a query using a EclipseLink by example.protected DatabaseQuerycreateQueryInternal(Expression expression, Class<?> resultType) This method is used to create a query using a EclipseLink Expression and the return type.createStoredProcedureQuery(String procedureName) Create an instance ofStoredProcedureQueryfor executing a stored procedure in the database.createStoredProcedureQuery(String procedureName, Class... resultClasses) Create an instance ofStoredProcedureQueryfor executing a stored procedure in the database.createStoredProcedureQuery(String procedureName, String... resultSetMappings) Create an instance ofStoredProcedureQueryfor executing a stored procedure in the database.voidRemove the given entity from the persistence context, causing a managed entity to become detached.protected void<T> TFind by primary key.<T> Tfind(Class<T> entityClass, Object primaryKey, LockModeType lockMode) Find by primary key and lock.<T> TFind by primary key and lock.<T> TFind by primary key, using the specified properties.Find by primary key.protected ObjectfindInternal(ClassDescriptor descriptor, AbstractSession session, Object id, LockModeType lockMode, Map<String, Object> properties) Find by primary key.voidflush()Synchronize the persistence context with the underlying database.Return the underlying database sessionThis method returns the current session to the requestor.This method returns the current session to the requestor.Return an instance of CriteriaBuilder for the creation of Criteria API Query objects.Return the underlying database sessionReturn the underlying provider object for the EntityManager, if available.getEntityGraph(String graphName) <T> List<EntityGraph<? super T>> getEntityGraphs(Class<T> entityClass) Return the entity manager factory for the entity manager.Get the flush mode that applies to all objects contained in the persistence context.getLockMode(Object entity) getMemberDatabaseSession(Class<?> cls) Return the member DatabaseSessionImpl that maps cls in session broker.getMemberServerSession(Class<?> cls) Return the member ServerSession that maps cls in session broker.getMemberSessionName(Class<?> cls) Return the name of member session that maps cls.Return an instance of Metamodel interface for access to the metamodel of the persistence unit.Return the weak reference to the open queries.Return the weak reference to the open queries.Get the properties and associated values that are in effect for the entity manager.protected StringGet the local EntityManager property from the properties Map.protected static StringgetPropertiesHandlerProperty(String name, String value) Verifies and (if required) translates the value.getProperty(String name) The method search for user defined property passed in from EntityManager, if it is not found then search for it from EntityManagerFactory properties.getQueryHints(Object entity, EntityManagerImpl.OperationType operation) Before any find or refresh operation, gather any persistence unit properties that should be applied to the query.protected ReadObjectQuerygetReadObjectQuery(Class<?> referenceClass, Object primaryKey, Map properties) Build a selection query for the primary key values.protected ReadObjectQuerygetReadObjectQuery(Object entity, Map properties) Build a selection query for the given entity.protected ReadObjectQuerygetReadObjectQuery(Map properties) Build a selection query using the given properties.Return a read-only session (client session) for read-only operations.<T> TgetReference(Class<T> entityClass, Object primaryKey) Get an instance, whose state may be lazily fetched.Return the underlying server session, throws ClassCastException if it's not a ServerSession.This method will return a Session outside of a transaction and null within a transaction.Return the underlying session broker, throws ClassCastException if it's not a SessionBroker.Get the names of the properties that are supported for use with the entity manager.INTERNAL: Tracks if this EntityManager should automatically associate with the transaction or notReturns the resource-level transaction object.This method will return the active UnitOfWorkbooleanThis method is used in contains to check if we already have a persistence context.protected voidinitialize(Map properties) Initialize the state after construction.booleanisBroker()Indicates whether the underlying session is a session broker.booleanInternal method.booleanbooleanisOpen()Indicates whether or not this entity manager and its entity manager factory are open.protected static booleanisPropertyToBeAdded(String value) Property value is to be added if it's non null and not an empty string.protected static booleanisPropertyToBeAdded(DataSource ds, String dsName) protected static booleanisPropertyToBeRemoved(String value) Property value of an empty string indicates that the existing property should be removed.protected static BooleanisPropertyValueToBeUpdated(String oldValue, String newValue) voidIndicate to the EntityManager that a JTA transaction is active.voidload(Object entityOrEntities, AttributeGroup group) This method will load the passed entity or collection of entities using the passed AttributeGroup.voidlock(Object entity, LockModeType lockMode) Set the lock mode for an entity object contained in the persistence context.voidSet the lock mode for an entity object contained in the persistence context.<T> Tmerge(T entity) Merge the state of the given entity into the current persistence context, using the unqualified class name as the entity name.protected ObjectmergeInternal(Object entity) Merge the state of the given entity into the current persistence context, using the unqualified class name as the entity name.voidIf in a transaction this method will check for existence and register the object if it is new.protected voidProcess the local EntityManager properties only.static voidprocessUnfetchedAttribute(FetchGroupTracker entity, String attributeName) INTERNAL: Load/fetch the unfetched object.static voidprocessUnfetchedAttributeForSet(FetchGroupTracker entity, String attributeName) INTERNAL: Load/fetch the unfetched object.voidRefresh the state of the instance from the database.voidrefresh(Object entity, LockModeType lockMode) Refresh the state of the instance from the database, overwriting changes made to the entity, if any, and lock it with respect to given lock mode type.voidRefresh the state of the instance from the database, overwriting changes made to the entity, if any, and lock it with respect to given lock mode type.voidRefresh the state of the instance from the database, using the specified properties, and overwriting changes made to the entity, if any.voidRemove the instance.voidInternal method called by EntityTransactionImpl class in case of transaction rollback.voidsetAbstractSession(AbstractSession session) INTERNAL: Set the underlying database sessionprotected voidvoidsetFlushMode(FlushModeType flushMode) Set the flush mode that applies to all objects contained in the persistence context.protected voidvoidsetProperties(Map properties) Use this method to set properties into existing EntityManager that are normally passed to createEntityManager method.voidsetProperty(String propertyName, Object value) protected voidInternal method.booleanIndicate the early transaction should be forced to start.boolean<T> TReturn an object of the specified type to allow access to the provider-specific API.voidvoidused to save having to constantly use a try/catch to call setRollbackOnly
-
Field Details
-
isOpen
protected boolean isOpenStore if this entity manager has been closed. -
extendedPersistenceContext
Stores the UnitOfWork representing the persistence context. -
readOnlySession
Stores a session used for read-only queries. -
databaseSession
References the DatabaseSession that this deployment is using. -
factory
References to the parent factory that has created this entity manager. Ensures that the factory is not garbage collected. -
beginEarlyTransaction
protected boolean beginEarlyTransactionJoin existing transaction property, allows reading through write connection. -
properties
Local properties passed from createEntityManager. -
flushMode
Flush mode property, allows flush before query to be avoided. -
referenceMode
Reference mode property, allows weak unit of work references to allow garbage collection during a transaction. -
connectionPolicy
Connection policy used to create ClientSession, allows using a different pool/connection/exclusive connections. Not used in SessionBroker case (composite persistence unit case). -
connectionPolicies
In case of composite persistence unit this map is used instead of connectionPolicy attribute. Member sessions' ConnectionPolicies keyed by sessions' names (composite members' persistence unit names). Used only in SessionBroker case (composite persistence unit case): in that case guaranteed to be always non null. -
openQueriesMap
Keep a list of openQueries that are executed in this entity manager. -
closeOnCommit
protected boolean closeOnCommitProperty to avoid resuming unit of work if going to be closed on commit anyway. -
persistOnCommit
protected boolean persistOnCommitProperty to avoid discover new objects in unit of work if application always uses persist. -
cacheStoreBypass
protected boolean cacheStoreBypassProperty to avoid writing to the cache on commit (merge) -
flushClearCache
The FlashClearCache mode to be used. Relevant only in case call to flush method followed by call to clear method.- See Also:
-
shouldValidateExistence
protected boolean shouldValidateExistenceDetermine if does-exist should be performed on persist. -
commitOrder
Allow updates to be ordered by id to avoid possible deadlocks. -
commitWithoutPersistRules
protected boolean commitWithoutPersistRules -
syncType
Tracks if this EntityManager should automatically associate with the transaction or not
-
-
Constructor Details
-
EntityManagerImpl
Constructor returns an EntityManager assigned to the a particular DatabaseSession.- Parameters:
sessionName- the DatabaseSession name that should be used. This constructor can potentially throw EclipseLink exceptions regarding the existence, or errors with the specified session.
-
EntityManagerImpl
Constructor called from the EntityManagerFactory to create an EntityManager- Parameters:
databaseSession- the databaseSession assigned to this deployment.
-
EntityManagerImpl
public EntityManagerImpl(AbstractSession databaseSession, Map properties, SynchronizationType syncType) Constructor called from the EntityManagerFactory to create an EntityManager- Parameters:
databaseSession- the databaseSession assigned to this deployment. Note: The properties argument is provided to allow properties to be passed into this EntityManager, but there are currently no such properties implemented
-
EntityManagerImpl
public EntityManagerImpl(EntityManagerFactoryDelegate factory, Map properties, SynchronizationType syncType) Constructor called from the EntityManagerFactory to create an EntityManager- Parameters:
factory- the EntityMangerFactoryImpl that created this entity manager. Note: The properties argument is provided to allow properties to be passed into this EntityManager, but there are currently no such properties implemented
-
-
Method Details
-
getOpenQueriesMap
Return the weak reference to the open queries. -
getOpenQueriesSet
Return the weak reference to the open queries. -
addOpenQuery
Queries that leave the connection and are executed against this entity manager will be added here. On rollback or commit any left over open queries should be closed. -
initialize
Initialize the state after construction. -
clear
public void clear()Clear the persistence context, causing all managed entities to become detached. Changes made to entities that have not been flushed to the database will not be persisted.- Specified by:
clearin interfaceEntityManager
-
removeExtendedPersistenceContext
public void removeExtendedPersistenceContext()Internal method called by EntityTransactionImpl class in case of transaction rollback. The caller is responsible for releasing extendedPersistenceContext and it's parent. -
persist
If in a transaction this method will check for existence and register the object if it is new. The instance of the entity provided will become managed.- Specified by:
persistin interfaceEntityManager- Throws:
IllegalArgumentException- if the given Object is not an entity.
-
merge
public <T> T merge(T entity) Merge the state of the given entity into the current persistence context, using the unqualified class name as the entity name.- Specified by:
mergein interfaceEntityManager- Returns:
- the instance that the state was merged to
-
mergeInternal
Merge the state of the given entity into the current persistence context, using the unqualified class name as the entity name.- Returns:
- the instance that the state was merged to
- Throws:
IllegalArgumentException- if given Object is not an entity or is a removed entity
-
remove
Remove the instance.- Specified by:
removein interfaceEntityManager- Throws:
IllegalArgumentException- if Object passed in is not an entity
-
find
Find by primary key.- Specified by:
findin interfaceEntityManager- Parameters:
entityClass- - the entity class to find.primaryKey- - the entity primary key value, or primary key class, or a List of primary key values.- Returns:
- the found entity instance or null if the entity does not exist
- Throws:
IllegalArgumentException- if the first argument does not denote an entity type or the second argument is not a valid type for that entity's primary key.
-
find
Find by primary key, using the specified properties. Search for an entity of the specified class and primary key. If the entity instance is contained in the persistence context it is returned from there. If a vendor-specific property or hint is not recognized, it is silently ignored.- Specified by:
findin interfaceEntityManager- Parameters:
properties- standard and vendor-specific properties- Returns:
- the found entity instance or null if the entity does not exist
- Throws:
IllegalArgumentException- 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 null- Since:
- Java Persistence API 2.0
-
find
Find by primary key and lock. Search for an entity of the specified class and primary key and lock it with respect to the specified lock type. If the entity instance is contained in the persistence context it is returned from there. If the entity is found within the persistence context and the lock mode type is pessimistic and the entity has a version attribute, the persistence provider must perform optimistic version checks when obtaining the database lock. If these checks fail, the OptimisticLockException will be thrown. If the lock mode type is pessimistic and the entity instance is found but cannot be locked: - the PessimisticLockException will be thrown if the database locking failure causes transaction-level rollback. - the LockTimeoutException will be thrown if the database locking failure causes only statement-level rollback- Specified by:
findin interfaceEntityManager- Returns:
- the found entity instance or null if the entity does not exist
- Throws:
IllegalArgumentException- if the first argument does not denote an entity type or the second argument is not a valid type for that entity's primary key or is nullTransactionRequiredException- if there is no transaction and a lock mode other than NONE is setOptimisticLockException- if the optimistic version check failsPessimisticLockException- if pessimistic locking fails and the transaction is rolled backLockTimeoutException- if pessimistic locking fails and only the statement is rolled backPersistenceException- if an unsupported lock call is made
-
find
public <T> T find(Class<T> entityClass, Object primaryKey, LockModeType lockMode, Map<String, Object> properties) Find by primary key and lock. Search for an entity of the specified class and primary key and lock it with respect to the specified lock type. If the entity instance is contained in the persistence context it is returned from there. If the entity is found within the persistence context and the lock mode type is pessimistic and the entity has a version attribute, the persistence provider must perform optimistic version checks when obtaining the database lock. If these checks fail, the OptimisticLockException will be thrown. If the lock mode type is pessimistic and the entity instance is found but cannot be locked: - the PessimisticLockException will be thrown if the database locking failure causes transaction-level rollback. - the LockTimeoutException will be thrown if the database locking failure causes only statement-level rollback If a vendor-specific property or hint is not recognized, it is silently ignored. Portable applications should not rely on the standard timeout hint. Depending on the database in use and the locking mechanisms used by the provider, the hint may or may not be observed.- Specified by:
findin interfaceEntityManager- Parameters:
properties- standard and vendor-specific properties and hints- Returns:
- the found entity instance or null if the entity does not exist
- Throws:
IllegalArgumentException- if the first argument does not denote an entity type or the second argument is not a valid type for that entity's primary key or is nullTransactionRequiredException- if there is no transaction and a lock mode other than NONE is setOptimisticLockException- if the optimistic version check failsPessimisticLockException- if pessimistic locking fails and the transaction is rolled backLockTimeoutException- if pessimistic locking fails and only the statement is rolled backPersistenceException- if an unsupported lock call is made
-
find
Find by primary key.- Parameters:
entityName- - the entity class to find.primaryKey- - the entity primary key value, or primary key class, or a List of primary key values.- Returns:
- the found entity instance or null, if the entity does not exist.
- Throws:
IllegalArgumentException- if the first argument does not indicate an entity or if the second argument is not a valid type for that entity's primaryKey.
-
findInternal
protected Object findInternal(ClassDescriptor descriptor, AbstractSession session, Object id, LockModeType lockMode, Map<String, Object> properties) Find by primary key.- Parameters:
descriptor- - the entity class to find.id- - the entity primary key value, or primary key class, or a List of primary key values.- Returns:
- the found entity instance or null, if the entity does not exist.
- Throws:
IllegalArgumentException- if the first argument does not denote an entity type or the second argument is not a valid type for that entity's primary key.
-
flush
public void flush()Synchronize the persistence context with the underlying database.- Specified by:
flushin interfaceEntityManager
-
detectTransactionWrapper
protected void detectTransactionWrapper() -
refresh
Refresh the state of the instance from the database.- Specified by:
refreshin interfaceEntityManager- Parameters:
entity- instance registered in the current persistence context.
-
refresh
Refresh the state of the instance from the database, using the specified properties, and overwriting changes made to the entity, if any. If a vendor-specific property or hint is not recognized, it is silently ignored.- Specified by:
refreshin interfaceEntityManager- Parameters:
properties- standard and vendor-specific properties- Throws:
IllegalArgumentException- if the instance is not an entity or the entity is not managedTransactionRequiredException- if invoked on a container-managed entity manager of type PersistenceContextType.TRANSACTION and there is no transaction.EntityNotFoundException- if the entity no longer exists in the database- Since:
- Java Persistence API 2.0
-
refresh
Refresh the state of the instance from the database, overwriting changes made to the entity, if any, and lock it with respect to given lock mode type. If the lock mode type is pessimistic and the entity instance is found but cannot be locked: - the PessimisticLockException will be thrown if the database locking failure causes transaction-level rollback. - the LockTimeoutException will be thrown if the database locking failure causes only statement-level rollback.- Specified by:
refreshin interfaceEntityManager- Throws:
IllegalArgumentException- if the instance is not an entity or the entity is not managedTransactionRequiredException- if there is no transactionEntityNotFoundException- if the entity no longer exists in the databasePessimisticLockException- if pessimistic locking fails and the transaction is rolled backLockTimeoutException- if pessimistic locking fails and only the statement is rolled backPersistenceException- if an unsupported lock call is made
-
refresh
Refresh the state of the instance from the database, overwriting changes made to the entity, if any, and lock it with respect to given lock mode type. If the lock mode type is pessimistic and the entity instance is found but cannot be locked: - the PessimisticLockException will be thrown if the database locking failure causes transaction-level rollback. - the LockTimeoutException will be thrown if the database locking failure causes only statement-level rollback If a vendor-specific property or hint is not recognized, it is silently ignored. Portable applications should not rely on the standard timeout hint. Depending on the database in use and the locking mechanisms used by the provider, the hint may or may not be observed.- Specified by:
refreshin interfaceEntityManager- Parameters:
properties- standard and vendor-specific properties and hints- Throws:
IllegalArgumentException- if the instance is not an entity or the entity is not managedTransactionRequiredException- if there is no transactionEntityNotFoundException- if the entity no longer exists in the databasePessimisticLockException- if pessimistic locking fails and the transaction is rolled backLockTimeoutException- if pessimistic locking fails and only the statement is rolled backPersistenceException- if an unsupported lock call is made
-
contains
Check if the instance belongs to the current persistence context.- Specified by:
containsin interfaceEntityManager- Throws:
IllegalArgumentException- if given Object is not an entity
-
contains
Check if the instance belongs to the current persistence context. -
createDescriptorNamedQuery
Description copied from interface:JpaEntityManagerThis method will create a query object that wraps a EclipseLink Named Query.- Specified by:
createDescriptorNamedQueryin interfaceJpaEntityManager
-
createDescriptorNamedQuery
public Query createDescriptorNamedQuery(String queryName, Class<?> descriptorClass, List argumentTypes) Description copied from interface:JpaEntityManagerThis method will create a query object that wraps a EclipseLink Named Query.- Specified by:
createDescriptorNamedQueryin interfaceJpaEntityManager
-
createNamedQuery
Create an instance of Query for executing a named query (in EJBQL or native SQL).- Specified by:
createNamedQueryin interfaceEntityManager- Parameters:
name- the name of a query defined in metadata- Returns:
- the new query instance
-
createNamedQuery
Create an instance of TypedQuery for executing a named query (in the Java Persistence query language or in native SQL).- Specified by:
createNamedQueryin interfaceEntityManager- Parameters:
name- the name of a query defined in metadataresultClass- the type of the query result- Returns:
- the new query instance
- Throws:
IllegalArgumentException- if a query has not been defined with the given name or if the query string is found to be invalid
-
createNamedStoredProcedureQuery
Create an instance of StoredProcedureQuery for executing a stored procedure in the database.- Specified by:
createNamedStoredProcedureQueryin interfaceEntityManager- Parameters:
name- name assigned to the stored procedure query in metadata- Returns:
- the new stored procedure query instance
- Throws:
IllegalArgumentException- if a query has not been defined with the given name
-
createNativeQuery
Create an instance of Query for executing a native SQL query.- Specified by:
createNativeQueryin interfaceEntityManager- Parameters:
sqlString- a native SQL query string- Returns:
- the new query instance
-
createNativeQuery
This method is used to create a query using SQL. The class, must be the expected return type.- Specified by:
createNativeQueryin interfaceEntityManager
-
createNativeQuery
Create an instance of Query for executing a native SQL query.- Specified by:
createNativeQueryin interfaceEntityManager- Parameters:
sqlString- a native SQL query stringresultSetMapping- the name of the result set mapping- Returns:
- the new query instance
- Throws:
IllegalArgumentException- if query string is not valid
-
getActiveSession
This method returns the current session to the requestor. The current session will be a the active UnitOfWork within a transaction and will be a 'scrap' UnitOfWork outside of a transaction. The caller is concerned about the results then the getSession() or getUnitOfWork() API should be called.- Specified by:
getActiveSessionin interfaceJpaEntityManager
-
getActiveSessionIfExists
This method returns the current session to the requestor. The current session will be a the active UnitOfWork within a transaction and will be a 'scrap' UnitOfWork outside of a transaction. The caller is concerned about the results then the getSession() or getUnitOfWork() API should be called. -
getDelegate
Return the underlying provider object for the EntityManager, if available. The result of this method is implementation specific.- Specified by:
getDelegatein interfaceEntityManager
-
getFlushMode
Get the flush mode that applies to all objects contained in the persistence context.- Specified by:
getFlushModein interfaceEntityManager- Returns:
- flushMode
-
getUnitOfWork
This method will return the active UnitOfWork- Specified by:
getUnitOfWorkin interfaceJpaEntityManager
-
getSession
This method will return a Session outside of a transaction and null within a transaction.- Specified by:
getSessionin interfaceJpaEntityManager
-
getTransaction
Returns the resource-level transaction object. The EntityTransaction instance may be used serially to begin and commit multiple transactions.- Specified by:
getTransactionin interfaceEntityManager- Returns:
- EntityTransaction instance
- Throws:
IllegalStateException- if invoked on a JTA EntityManager.
-
getProperty
The method search for user defined property passed in from EntityManager, if it is not found then search for it from EntityManagerFactory properties. -
getReadObjectQuery
protected ReadObjectQuery getReadObjectQuery(Class<?> referenceClass, Object primaryKey, Map properties) Build a selection query for the primary key values. -
getReadObjectQuery
Build a selection query using the given properties. -
getReadObjectQuery
Build a selection query for the given entity. -
getReference
Get an instance, whose state may be lazily fetched. If the requested instance does not exist in the database, throws EntityNotFoundException when the instance state is first accessed. (The container is permitted to throw EntityNotFoundException when get is called.) The application should not expect that the instance state will be available upon detachment, unless it was accessed by the application while the entity manager was open.- Specified by:
getReferencein interfaceEntityManager- Returns:
- the found entity instance.
- Throws:
IllegalArgumentException- if the first argument does not denote an entity type or the second argument is not a valid type for that entity's primary key.EntityNotFoundException- if the entity state cannot be accessed.
-
getReadOnlySession
Return a read-only session (client session) for read-only operations. -
getDatabaseSession
Return the underlying database session- Specified by:
getDatabaseSessionin interfaceJpaEntityManager
-
getAbstractSession
Return the underlying database session- Specified by:
getAbstractSessionin interfaceJpaEntityManager
-
setAbstractSession
INTERNAL: Set the underlying database session -
getServerSession
Return the underlying server session, throws ClassCastException if it's not a ServerSession.- Specified by:
getServerSessionin interfaceJpaEntityManager
-
getSessionBroker
Return the underlying session broker, throws ClassCastException if it's not a SessionBroker.- Specified by:
getSessionBrokerin interfaceJpaEntityManager
-
getMemberDatabaseSession
Return the member DatabaseSessionImpl that maps cls in session broker. Return null if either not a session broker or cls is not mapped. Session broker implement composite persistence unit.- Specified by:
getMemberDatabaseSessionin interfaceJpaEntityManager
-
getMemberServerSession
Return the member ServerSession that maps cls in session broker. Return null if either not a session broker or cls is not mapped. Session broker implement composite persistence unit.- Specified by:
getMemberServerSessionin interfaceJpaEntityManager
-
getMemberSessionName
Return the name of member session that maps cls. Return null if either not a session broker or cls is not mapped. Session broker implement composite persistence unit.- Specified by:
getMemberSessionNamein interfaceJpaEntityManager
-
createQuery
This method is used to create a query using a EclipseLink Expression and the return type.- Specified by:
createQueryin interfaceJpaEntityManager
-
createQuery
This method is used to create a query using a EclipseLink DatabaseQuery.- Specified by:
createQueryin interfaceJpaEntityManager
-
createQuery
- Specified by:
createQueryin interfaceEntityManager- Since:
- Java Persistence 2.0
- See Also:
-
createQueryByExample
This method is used to create a query using a EclipseLink by example.- Specified by:
createQueryByExamplein interfaceJpaEntityManager
-
createQuery
This method is used to create a query using a EclipseLink Call.- Specified by:
createQueryin interfaceJpaEntityManager
-
createQuery
This method is used to create a query using a EclipseLink Call.- Specified by:
createQueryin interfaceJpaEntityManager
-
createQuery
Create an instance of Query for executing an JPQL query.- Specified by:
createQueryin interfaceEntityManager- Parameters:
jpqlString- an JPQL query string- Returns:
- the new query instance
-
createQuery
Create an instance of TypedQuery for executing a Java Persistence query language statement.- Specified by:
createQueryin interfaceEntityManager- Parameters:
qlString- a Java Persistence query stringresultClass- the type of the query result- Returns:
- the new query instance
- Throws:
IllegalArgumentException- if the query string is found to be invalid
-
createQueryInternal
This method is used to create a query using a EclipseLink Expression and the return type. -
createStoredProcedureQuery
Create an instance ofStoredProcedureQueryfor executing a stored procedure in the database.Parameters must be registered before the stored procedure can be executed.
If the stored procedure returns one or more result sets, any result set will be returned as a list of type Object[].
- Specified by:
createStoredProcedureQueryin interfaceEntityManager- Parameters:
procedureName- name of the stored procedure in the database- Returns:
- the new stored procedure query instance
- Throws:
IllegalArgumentException- if a stored procedure of the given name does not exist (or the query execution will fail)- Since:
- EclipseLink 2.5/Java Persistence 2.1
-
createStoredProcedureQuery
public StoredProcedureQuery createStoredProcedureQuery(String procedureName, Class... resultClasses) Create an instance ofStoredProcedureQueryfor executing a stored procedure in the database.Parameters must be registered before the stored procedure can be executed.
The
resultClassarguments must be specified in the order in which the result sets will be returned by the stored procedure invocation.- Specified by:
createStoredProcedureQueryin interfaceEntityManager- Parameters:
procedureName- name of the stored procedure in the databaseresultClasses- classes to which the result sets produced by the stored procedure are to be mapped- Returns:
- the new stored procedure query instance
- Throws:
IllegalArgumentException- if a stored procedure of the given name does not exist (or the query execution will fail)- Since:
- EclipseLink 2.5/Java Persistence 2.1
-
createStoredProcedureQuery
public StoredProcedureQuery createStoredProcedureQuery(String procedureName, String... resultSetMappings) Create an instance ofStoredProcedureQueryfor executing a stored procedure in the database.Parameters must be registered before the stored procedure can be executed.
The
resultSetMappingarguments must be specified in the order in which the result sets will be returned by the stored procedure invocation.- Specified by:
createStoredProcedureQueryin interfaceEntityManager- Parameters:
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 procedure- Returns:
- the new stored procedure query instance
- Throws:
IllegalArgumentException- if a stored procedure or result set mapping of the given name does not exist (or the query execution will fail)- Since:
- EclipseLink 2.5/Java Persistence 2.1
-
close
public void close()Closes this EntityManager.
After invoking this method, all methods on the instance will throw an
IllegalStateExceptionexcept forisOpen, which will returnfalse.This should be called when a method is finished with the EntityManager in a bean-managed transaction environment or when executed outside a container. Closing of the EntityManager is handled by the container when using container-managed transactions.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceEntityManager
-
closeOpenQueries
protected void closeOpenQueries()Close any open queries executed against this entity manager.0 -
isFlushModeAUTO
public boolean isFlushModeAUTO()Internal method. Indicates whether flushMode is AUTO.- Returns:
- boolean
-
isOpen
public boolean isOpen()Indicates whether or not this entity manager and its entity manager factory are open. Returnstrueuntil a call toclose()is made.- Specified by:
isOpenin interfaceEntityManager
-
lock
Set the lock mode for an entity object contained in the persistence context.- Specified by:
lockin interfaceEntityManager- Throws:
PersistenceException- if an unsupported lock call is madeIllegalArgumentException- if the instance is not an entity or is a detached entityTransactionRequiredException- if there is no transaction
-
lock
Set the lock mode for an entity object contained in the persistence context.- Specified by:
lockin interfaceEntityManager- Throws:
PersistenceException- if an unsupported lock call is madeIllegalArgumentException- if the instance is not an entity or is a detached entityTransactionRequiredException- if there is no transaction
-
verifyOpen
public void verifyOpen() -
verifyOpenWithSetRollbackOnly
public void verifyOpenWithSetRollbackOnly()used to save having to constantly use a try/catch to call setRollbackOnly -
getActivePersistenceContext
-
setProperties
Use this method to set properties into existing EntityManager that are normally passed to createEntityManager method. Note that if the method called when active persistence context already exists then properties used to create persistence context will be ignored until the new persistence context is created (that happens either after transaction rolled back or after clear method was called). -
setProperty
- Specified by:
setPropertyin interfaceEntityManager- See Also:
-
hasActivePersistenceContext
public boolean hasActivePersistenceContext()This method is used in contains to check if we already have a persistence context. If there is no active persistence context the method returns false -
checkForTransaction
Return the current, joined transaction object. If validateExistence is true throw an error if there is no joined transaction, otherwise return null. -
shouldFlushBeforeQuery
public boolean shouldFlushBeforeQuery() -
shouldBeginEarlyTransaction
public boolean shouldBeginEarlyTransaction()Indicate the early transaction should be forced to start. This allows for reading through the write connection. As a side effect, this will also prevent anything from being cached. -
joinTransaction
public void joinTransaction()Indicate to the EntityManager that a JTA transaction is active. This method should be called on a JTA application managed EntityManager that was created outside the scope of the active transaction to associate it with the current JTA transaction.- Specified by:
joinTransactionin interfaceEntityManager- Throws:
TransactionRequiredException- if there is no transaction.
-
setRollbackOnly
protected void setRollbackOnly()Internal method. Sets transaction to rollback only. -
processProperties
protected void processProperties()Process the local EntityManager properties only. The persistence unit properties are processed by the factory. -
getPropertiesHandlerProperty
Get the local EntityManager property from the properties Map. This only searches the local Map. The persistence unit properties are processed by the EntityManagerFactory. -
getPropertiesHandlerProperty
Verifies and (if required) translates the value. -
setEntityTransactionWrapper
protected void setEntityTransactionWrapper() -
setFlushMode
Set the flush mode that applies to all objects contained in the persistence context.- Specified by:
setFlushModein interfaceEntityManager
-
setJTATransactionWrapper
protected void setJTATransactionWrapper() -
createConnectionPolicy
protected void createConnectionPolicy()Create connection policy using properties. Default connection policy created if no connection properties specified. Should be called only in case this.databaseSession is a ServerSession. -
createConnectionPolicies
Create connection policy using properties. Default connection policy created if no connection properties specified. Should be called only in case this.databaseSession is a SessionBroker. -
createConnectionPolicy
protected static ConnectionPolicy createConnectionPolicy(ServerSession serverSession, Map properties) Create connection policy using properties. Default connection policy created if no connection properties specified. -
isBroker
public boolean isBroker()Indicates whether the underlying session is a session broker. Session broker implement composite persistence unit.- Specified by:
isBrokerin interfaceJpaEntityManager
-
isPropertyToBeAdded
Property value is to be added if it's non null and not an empty string. -
isPropertyToBeAdded
-
isPropertyToBeRemoved
Property value of an empty string indicates that the existing property should be removed. -
isPropertyValueToBeUpdated
- Returns:
- null: no change; TRUE: substitute oldValue by newValue; FALSE: remove oldValue
-
detach
Remove the given entity from the persistence context, causing a managed entity to become detached. Unflushed changes made to the entity if any (including removal of the entity), will not be synchronized to the database. Entities which previously referenced the detached entity will continue to reference it.- Specified by:
detachin interfaceEntityManager- Throws:
IllegalArgumentException- if the instance is not an entity- Since:
- Java Persistence 2.0
-
getCriteriaBuilder
Return an instance of CriteriaBuilder for the creation of Criteria API Query objects.- Specified by:
getCriteriaBuilderin interfaceEntityManager- Returns:
- CriteriaBuilder instance
- Throws:
IllegalStateException- if the entity manager has been closed.- Since:
- Java Persistence 2.0
- See Also:
-
getQueryHints
protected HashMap<String,Object> getQueryHints(Object entity, EntityManagerImpl.OperationType operation) Before any find or refresh operation, gather any persistence unit properties that should be applied to the query. -
getMetamodel
Return an instance of Metamodel interface for access to the metamodel of the persistence unit.- Specified by:
getMetamodelin interfaceEntityManager- Returns:
- Metamodel instance
- Throws:
IllegalStateException- if the entity manager has been closed.- Since:
- Java Persistence 2.0
- See Also:
-
getEntityManagerFactory
Return the entity manager factory for the entity manager.- Specified by:
getEntityManagerFactoryin interfaceEntityManager- Returns:
- EntityManagerFactory instance
- Throws:
IllegalStateException- if the entity manager has been closed.- Since:
- Java Persistence API 2.0
-
getLockMode
- Specified by:
getLockModein interfaceEntityManager- Since:
- Java Persistence API 2.0
- See Also:
-
getProperties
Get the properties and associated values that are in effect for the entity manager. Changing the contents of the map does not change the configuration in effect.- Specified by:
getPropertiesin interfaceEntityManager- Since:
- Java Persistence API 2.0
-
getSupportedProperties
Get the names of the properties that are supported for use with the entity manager. These correspond to properties and hints that may be passed to the methods of the EntityManager interface that take a properties argument or used with the PersistenceContext annotation. These properties include all standard entity manager hints and properties as well as vendor-specific ones supported by the provider. These properties may or may not currently be in effect.- Returns:
- property names
- Since:
- Java Persistence API 2.0
-
unwrap
Return an object of the specified type to allow access to the provider-specific API. If the provider's EntityManager implementation does not support the specified class, the PersistenceException is thrown.- Specified by:
unwrapin interfaceEntityManager- Parameters:
cls- the class of the object to be returned. This is normally either the underlying EntityManager implementation class or an interface that it implements.- Returns:
- an instance of the specified class
- Throws:
PersistenceException- if the provider does not support the call.- Since:
- Java Persistence API 2.0
-
load
This method will load the passed entity or collection of entities using the passed AttributeGroup. In case of collection all members should be either entities of the same type or have a common inheritance hierarchy mapped root class. The AttributeGroup should correspond to the entity type.- Specified by:
loadin interfaceJpaEntityManager
-
copy
This method will return copy the passed entity using the passed AttributeGroup. In case of collection all members should be either entities of the same type or have a common inheritance hierarchy mapped root class. The AttributeGroup should correspond to the entity type.- Specified by:
copyin interfaceJpaEntityManager
-
processUnfetchedAttribute
INTERNAL: Load/fetch the unfetched object. This method is used by the ClassWaver.. -
processUnfetchedAttributeForSet
INTERNAL: Load/fetch the unfetched object. This method is used by the ClassWeaver. -
createQuery
- Specified by:
createQueryin interfaceEntityManager
-
createQuery
- Specified by:
createQueryin interfaceEntityManager
-
isJoinedToTransaction
public boolean isJoinedToTransaction()- Specified by:
isJoinedToTransactionin interfaceEntityManager
-
createEntityGraph
- Specified by:
createEntityGraphin interfaceEntityManager
-
createEntityGraph
- Specified by:
createEntityGraphin interfaceEntityManager
-
getEntityGraph
- Specified by:
getEntityGraphin interfaceEntityManager
-
getEntityGraphs
- Specified by:
getEntityGraphsin interfaceEntityManager
-
getSyncType
INTERNAL: Tracks if this EntityManager should automatically associate with the transaction or not- Returns:
- the syncType
-