Class EntityManagerImpl

  • All Implemented Interfaces:
    java.lang.AutoCloseable, javax.persistence.EntityManager, JpaEntityManager

    public class EntityManagerImpl
    extends java.lang.Object
    implements 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
    Author:
    gyorke
    See Also:
    EntityManager, JpaEntityManager
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean beginEarlyTransaction
      Join existing transaction property, allows reading through write connection.
      protected boolean cacheStoreBypass
      Property to avoid writing to the cache on commit (merge)
      protected boolean closeOnCommit
      Property to avoid resuming unit of work if going to be closed on commit anyway.
      protected org.eclipse.persistence.sessions.UnitOfWork.CommitOrderType commitOrder
      Allow updates to be ordered by id to avoid possible deadlocks.
      protected boolean commitWithoutPersistRules  
      protected java.util.Map<java.lang.String,​org.eclipse.persistence.sessions.server.ConnectionPolicy> connectionPolicies
      In case of composite persistence unit this map is used instead of connectionPolicy attribute.
      protected org.eclipse.persistence.sessions.server.ConnectionPolicy connectionPolicy
      Connection policy used to create ClientSession, allows using a different pool/connection/exclusive connections.
      protected org.eclipse.persistence.internal.sessions.AbstractSession databaseSession
      References the DatabaseSession that this deployment is using.
      protected org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork extendedPersistenceContext
      Stores the UnitOfWork representing the persistence context.
      protected EntityManagerFactoryDelegate factory
      References to the parent factory that has created this entity manager.
      protected java.lang.String flushClearCache
      The FlashClearCache mode to be used.
      protected javax.persistence.FlushModeType flushMode
      Flush mode property, allows flush before query to be avoided.
      protected boolean isOpen
      Store if this entity manager has been closed.
      protected java.util.WeakHashMap<QueryImpl,​QueryImpl> openQueriesMap
      Keep a list of openQueries that are executed in this entity manager.
      protected boolean persistOnCommit
      Property to avoid discover new objects in unit of work if application always uses persist.
      protected java.util.Map properties
      Local properties passed from createEntityManager.
      protected org.eclipse.persistence.internal.sessions.AbstractSession readOnlySession
      Stores a session used for read-only queries.
      protected org.eclipse.persistence.config.ReferenceMode referenceMode
      Reference mode property, allows weak unit of work references to allow garbage collection during a transaction.
      protected boolean shouldValidateExistence
      Determine if does-exist should be performed on persist.
      protected javax.persistence.SynchronizationType syncType
      Tracks if this EntityManager should automatically associate with the transaction or not
      protected TransactionWrapperImpl transaction
      Allows transparent transactions across JTA and local transactions.
    • Constructor Summary

      Constructors 
      Constructor Description
      EntityManagerImpl​(java.lang.String sessionName)
      Constructor returns an EntityManager assigned to the a particular DatabaseSession.
      EntityManagerImpl​(EntityManagerFactoryDelegate factory, java.util.Map properties, javax.persistence.SynchronizationType syncType)
      Constructor called from the EntityManagerFactory to create an EntityManager
      EntityManagerImpl​(org.eclipse.persistence.internal.sessions.AbstractSession databaseSession, java.util.Map properties, javax.persistence.SynchronizationType syncType)
      Constructor called from the EntityManagerFactory to create an EntityManager
      EntityManagerImpl​(org.eclipse.persistence.internal.sessions.AbstractSession databaseSession, javax.persistence.SynchronizationType syncType)
      Constructor called from the EntityManagerFactory to create an EntityManager
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addOpenQuery​(QueryImpl query)
      Queries that leave the connection and are executed against this entity manager will be added here.
      protected java.lang.Object checkForTransaction​(boolean validateExistence)
      Return the current, joined transaction object.
      void clear()
      Clear the persistence context, causing all managed entities to become detached.
      void close()
      Closes this EntityManager.
      protected void closeOpenQueries()
      Close any open queries executed against this entity manager.0
      boolean contains​(java.lang.Object entity)
      Check if the instance belongs to the current persistence context.
      protected boolean contains​(java.lang.Object entity, org.eclipse.persistence.sessions.UnitOfWork uow)
      Check if the instance belongs to the current persistence context.
      java.lang.Object copy​(java.lang.Object entityOrEntities, org.eclipse.persistence.queries.AttributeGroup group)
      This method will return copy the passed entity using the passed AttributeGroup.
      protected void createConnectionPolicies​(java.util.Map mapOfProperties)
      Create connection policy using properties.
      protected void createConnectionPolicy()
      Create connection policy using properties.
      protected static org.eclipse.persistence.sessions.server.ConnectionPolicy createConnectionPolicy​(org.eclipse.persistence.sessions.server.ServerSession serverSession, java.util.Map properties)
      Create connection policy using properties.
      javax.persistence.Query createDescriptorNamedQuery​(java.lang.String queryName, java.lang.Class descriptorClass)
      This method will create a query object that wraps a EclipseLink Named Query.
      javax.persistence.Query createDescriptorNamedQuery​(java.lang.String queryName, java.lang.Class descriptorClass, java.util.List argumentTypes)
      This method will create a query object that wraps a EclipseLink Named Query.
      <T> javax.persistence.EntityGraph<T> createEntityGraph​(java.lang.Class<T> rootType)  
      javax.persistence.EntityGraph createEntityGraph​(java.lang.String graphName)  
      javax.persistence.Query createNamedQuery​(java.lang.String name)
      Create an instance of Query for executing a named query (in EJBQL or native SQL).
      <T> javax.persistence.TypedQuery<T> createNamedQuery​(java.lang.String name, java.lang.Class<T> resultClass)
      Create an instance of TypedQuery for executing a named query (in the Java Persistence query language or in native SQL).
      javax.persistence.StoredProcedureQuery createNamedStoredProcedureQuery​(java.lang.String name)
      Create an instance of StoredProcedureQuery for executing a stored procedure in the database.
      javax.persistence.Query createNativeQuery​(java.lang.String sqlString)
      Create an instance of Query for executing a native SQL query.
      javax.persistence.Query createNativeQuery​(java.lang.String sqlString, java.lang.Class resultType)
      This method is used to create a query using SQL.
      javax.persistence.Query createNativeQuery​(java.lang.String sqlString, java.lang.String resultSetMapping)
      Create an instance of Query for executing a native SQL query.
      javax.persistence.Query createQuery​(java.lang.String jpqlString)
      Create an instance of Query for executing an JPQL query.
      <T> javax.persistence.TypedQuery<T> createQuery​(java.lang.String qlString, java.lang.Class<T> resultClass)
      Create an instance of TypedQuery for executing a Java Persistence query language statement.
      javax.persistence.Query createQuery​(javax.persistence.criteria.CriteriaDelete deleteQuery)  
      <T> javax.persistence.TypedQuery<T> createQuery​(javax.persistence.criteria.CriteriaQuery<T> criteriaQuery)  
      javax.persistence.Query createQuery​(javax.persistence.criteria.CriteriaUpdate updateQuery)  
      javax.persistence.Query createQuery​(org.eclipse.persistence.expressions.Expression expression, java.lang.Class resultType)
      This method is used to create a query using a EclipseLink Expression and the return type.
      javax.persistence.Query createQuery​(org.eclipse.persistence.queries.Call call)
      This method is used to create a query using a EclipseLink Call.
      javax.persistence.Query createQuery​(org.eclipse.persistence.queries.Call call, java.lang.Class entityClass)
      This method is used to create a query using a EclipseLink Call.
      javax.persistence.Query createQuery​(org.eclipse.persistence.queries.DatabaseQuery databaseQuery)
      This method is used to create a query using a EclipseLink DatabaseQuery.
      javax.persistence.Query createQueryByExample​(java.lang.Object exampleObject)
      This method is used to create a query using a EclipseLink by example.
      protected org.eclipse.persistence.queries.DatabaseQuery createQueryInternal​(org.eclipse.persistence.expressions.Expression expression, java.lang.Class resultType)
      This method is used to create a query using a EclipseLink Expression and the return type.
      javax.persistence.StoredProcedureQuery createStoredProcedureQuery​(java.lang.String procedureName)
      Create an instance of StoredProcedureQuery for executing a stored procedure in the database.
      javax.persistence.StoredProcedureQuery createStoredProcedureQuery​(java.lang.String procedureName, java.lang.Class... resultClasses)
      Create an instance of StoredProcedureQuery for executing a stored procedure in the database.
      javax.persistence.StoredProcedureQuery createStoredProcedureQuery​(java.lang.String procedureName, java.lang.String... resultSetMappings)
      Create an instance of StoredProcedureQuery for executing a stored procedure in the database.
      void detach​(java.lang.Object entity)
      Remove the given entity from the persistence context, causing a managed entity to become detached.
      protected void detectTransactionWrapper()  
      <T> T find​(java.lang.Class<T> entityClass, java.lang.Object primaryKey)
      Find by primary key.
      <T> T find​(java.lang.Class<T> entityClass, java.lang.Object primaryKey, java.util.Map<java.lang.String,​java.lang.Object> properties)
      Find by primary key, using the specified properties.
      <T> T find​(java.lang.Class<T> entityClass, java.lang.Object primaryKey, javax.persistence.LockModeType lockMode)
      Find by primary key and lock.
      <T> T find​(java.lang.Class<T> entityClass, java.lang.Object primaryKey, javax.persistence.LockModeType lockMode, java.util.Map<java.lang.String,​java.lang.Object> properties)
      Find by primary key and lock.
      java.lang.Object find​(java.lang.String entityName, java.lang.Object primaryKey)
      Find by primary key.
      protected java.lang.Object findInternal​(org.eclipse.persistence.descriptors.ClassDescriptor descriptor, org.eclipse.persistence.internal.sessions.AbstractSession session, java.lang.Object id, javax.persistence.LockModeType lockMode, java.util.Map<java.lang.String,​java.lang.Object> properties)
      Find by primary key.
      void flush()
      Synchronize the persistence context with the underlying database.
      org.eclipse.persistence.internal.sessions.AbstractSession getAbstractSession()
      Return the underlying database session
      org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork getActivePersistenceContext​(java.lang.Object txn)  
      org.eclipse.persistence.sessions.Session getActiveSession()
      This method returns the current session to the requestor.
      org.eclipse.persistence.internal.sessions.AbstractSession getActiveSessionIfExists()
      This method returns the current session to the requestor.
      javax.persistence.criteria.CriteriaBuilder getCriteriaBuilder()
      Return an instance of CriteriaBuilder for the creation of Criteria API Query objects.
      org.eclipse.persistence.internal.sessions.DatabaseSessionImpl getDatabaseSession()
      Return the underlying database session
      java.lang.Object getDelegate()
      Return the underlying provider object for the EntityManager, if available.
      javax.persistence.EntityGraph getEntityGraph​(java.lang.String graphName)  
      <T> java.util.List<javax.persistence.EntityGraph<? super T>> getEntityGraphs​(java.lang.Class<T> entityClass)  
      javax.persistence.EntityManagerFactory getEntityManagerFactory()
      Return the entity manager factory for the entity manager.
      javax.persistence.FlushModeType getFlushMode()
      Get the flush mode that applies to all objects contained in the persistence context.
      javax.persistence.LockModeType getLockMode​(java.lang.Object entity)  
      org.eclipse.persistence.internal.sessions.DatabaseSessionImpl getMemberDatabaseSession​(java.lang.Class cls)
      Return the member DatabaseSessionImpl that maps cls in session broker.
      org.eclipse.persistence.sessions.server.ServerSession getMemberServerSession​(java.lang.Class cls)
      Return the member ServerSession that maps cls in session broker.
      java.lang.String getMemberSessionName​(java.lang.Class cls)
      Return the name of member session that maps cls.
      javax.persistence.metamodel.Metamodel getMetamodel()
      Return an instance of Metamodel interface for access to the metamodel of the persistence unit.
      protected java.util.Map<QueryImpl,​QueryImpl> getOpenQueriesMap()
      Return the weak reference to the open queries.
      protected java.util.Set<QueryImpl> getOpenQueriesSet()
      Return the weak reference to the open queries.
      java.util.Map<java.lang.String,​java.lang.Object> getProperties()
      Get the properties and associated values that are in effect for the entity manager.
      protected java.lang.String getPropertiesHandlerProperty​(java.lang.String name)
      Get the local EntityManager property from the properties Map.
      protected static java.lang.String getPropertiesHandlerProperty​(java.lang.String name, java.lang.String value)
      Verifies and (if required) translates the value.
      java.lang.Object getProperty​(java.lang.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.
      protected java.util.HashMap<java.lang.String,​java.lang.Object> getQueryHints​(java.lang.Object entity, EntityManagerImpl.OperationType operation)
      Before any find or refresh operation, gather any persistence unit properties that should be applied to the query.
      protected org.eclipse.persistence.queries.ReadObjectQuery getReadObjectQuery​(java.lang.Class referenceClass, java.lang.Object primaryKey, java.util.Map properties)
      Build a selection query for the primary key values.
      protected org.eclipse.persistence.queries.ReadObjectQuery getReadObjectQuery​(java.lang.Object entity, java.util.Map properties)
      Build a selection query for the given entity.
      protected org.eclipse.persistence.queries.ReadObjectQuery getReadObjectQuery​(java.util.Map properties)
      Build a selection query using the given properties.
      org.eclipse.persistence.sessions.Session getReadOnlySession()
      Return a read-only session (client session) for read-only operations.
      <T> T getReference​(java.lang.Class<T> entityClass, java.lang.Object primaryKey)
      Get an instance, whose state may be lazily fetched.
      org.eclipse.persistence.sessions.server.ServerSession getServerSession()
      Return the underlying server session, throws ClassCastException if it's not a ServerSession.
      org.eclipse.persistence.sessions.Session getSession()
      This method will return a Session outside of a transaction and null within a transaction.
      org.eclipse.persistence.sessions.broker.SessionBroker getSessionBroker()
      Return the underlying session broker, throws ClassCastException if it's not a SessionBroker.
      java.util.Set<java.lang.String> getSupportedProperties()
      Get the names of the properties that are supported for use with the entity manager.
      javax.persistence.SynchronizationType getSyncType()
      INTERNAL: Tracks if this EntityManager should automatically associate with the transaction or not
      javax.persistence.EntityTransaction getTransaction()
      Returns the resource-level transaction object.
      org.eclipse.persistence.sessions.UnitOfWork getUnitOfWork()
      This method will return the active UnitOfWork
      boolean hasActivePersistenceContext()
      This method is used in contains to check if we already have a persistence context.
      protected void initialize​(java.util.Map properties)
      Initialize the state after construction.
      boolean isBroker()
      Indicates whether the underlying session is a session broker.
      boolean isFlushModeAUTO()
      Internal method.
      boolean isJoinedToTransaction()  
      boolean isOpen()
      Indicates whether or not this entity manager and its entity manager factory are open.
      protected static boolean isPropertyToBeAdded​(java.lang.String value)
      Property value is to be added if it's non null and not an empty string.
      protected static boolean isPropertyToBeAdded​(javax.sql.DataSource ds, java.lang.String dsName)  
      protected static boolean isPropertyToBeRemoved​(java.lang.String value)
      Property value of an empty string indicates that the existing property should be removed.
      protected static java.lang.Boolean isPropertyValueToBeUpdated​(java.lang.String oldValue, java.lang.String newValue)  
      void joinTransaction()
      Indicate to the EntityManager that a JTA transaction is active.
      void load​(java.lang.Object entityOrEntities, org.eclipse.persistence.queries.AttributeGroup group)
      This method will load the passed entity or collection of entities using the passed AttributeGroup.
      void lock​(java.lang.Object entity, javax.persistence.LockModeType lockMode)
      Set the lock mode for an entity object contained in the persistence context.
      void lock​(java.lang.Object entity, javax.persistence.LockModeType lockMode, java.util.Map<java.lang.String,​java.lang.Object> properties)
      Set the lock mode for an entity object contained in the persistence context.
      <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.
      protected java.lang.Object mergeInternal​(java.lang.Object entity)
      Merge the state of the given entity into the current persistence context, using the unqualified class name as the entity name.
      void persist​(java.lang.Object entity)
      If in a transaction this method will check for existence and register the object if it is new.
      protected void processProperties()
      Process the local EntityManager properties only.
      static void processUnfetchedAttribute​(org.eclipse.persistence.queries.FetchGroupTracker entity, java.lang.String attributeName)
      INTERNAL: Load/fetch the unfetched object.
      static void processUnfetchedAttributeForSet​(org.eclipse.persistence.queries.FetchGroupTracker entity, java.lang.String attributeName)
      INTERNAL: Load/fetch the unfetched object.
      void refresh​(java.lang.Object entity)
      Refresh the state of the instance from the database.
      void refresh​(java.lang.Object entity, java.util.Map<java.lang.String,​java.lang.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 refresh​(java.lang.Object entity, javax.persistence.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.
      void refresh​(java.lang.Object entity, javax.persistence.LockModeType lockMode, java.util.Map<java.lang.String,​java.lang.Object> properties)
      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.
      void remove​(java.lang.Object entity)
      Remove the instance.
      void removeExtendedPersistenceContext()
      Internal method called by EntityTransactionImpl class in case of transaction rollback.
      void setAbstractSession​(org.eclipse.persistence.internal.sessions.AbstractSession session)
      INTERNAL: Set the underlying database session
      protected void setEntityTransactionWrapper()  
      void setFlushMode​(javax.persistence.FlushModeType flushMode)
      Set the flush mode that applies to all objects contained in the persistence context.
      protected void setJTATransactionWrapper()  
      void setProperties​(java.util.Map properties)
      Use this method to set properties into existing EntityManager that are normally passed to createEntityManager method.
      void setProperty​(java.lang.String propertyName, java.lang.Object value)  
      protected void setRollbackOnly()
      Internal method.
      boolean shouldBeginEarlyTransaction()
      Indicate the early transaction should be forced to start.
      boolean shouldFlushBeforeQuery()  
      <T> T unwrap​(java.lang.Class<T> cls)
      Return an object of the specified type to allow access to the provider-specific API.
      void verifyOpen()  
      void verifyOpenWithSetRollbackOnly()
      used to save having to constantly use a try/catch to call setRollbackOnly
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • transaction

        protected TransactionWrapperImpl transaction
        Allows transparent transactions across JTA and local transactions.
      • isOpen

        protected boolean isOpen
        Store if this entity manager has been closed.
      • extendedPersistenceContext

        protected org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork extendedPersistenceContext
        Stores the UnitOfWork representing the persistence context.
      • readOnlySession

        protected org.eclipse.persistence.internal.sessions.AbstractSession readOnlySession
        Stores a session used for read-only queries.
      • databaseSession

        protected org.eclipse.persistence.internal.sessions.AbstractSession databaseSession
        References the DatabaseSession that this deployment is using.
      • factory

        protected EntityManagerFactoryDelegate factory
        References to the parent factory that has created this entity manager. Ensures that the factory is not garbage collected.
      • beginEarlyTransaction

        protected boolean beginEarlyTransaction
        Join existing transaction property, allows reading through write connection.
      • properties

        protected java.util.Map properties
        Local properties passed from createEntityManager.
      • flushMode

        protected javax.persistence.FlushModeType flushMode
        Flush mode property, allows flush before query to be avoided.
      • referenceMode

        protected org.eclipse.persistence.config.ReferenceMode referenceMode
        Reference mode property, allows weak unit of work references to allow garbage collection during a transaction.
      • connectionPolicy

        protected org.eclipse.persistence.sessions.server.ConnectionPolicy 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

        protected java.util.Map<java.lang.String,​org.eclipse.persistence.sessions.server.ConnectionPolicy> 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

        protected java.util.WeakHashMap<QueryImpl,​QueryImpl> openQueriesMap
        Keep a list of openQueries that are executed in this entity manager.
      • closeOnCommit

        protected boolean closeOnCommit
        Property to avoid resuming unit of work if going to be closed on commit anyway.
      • persistOnCommit

        protected boolean persistOnCommit
        Property to avoid discover new objects in unit of work if application always uses persist.
      • cacheStoreBypass

        protected boolean cacheStoreBypass
        Property to avoid writing to the cache on commit (merge)
      • flushClearCache

        protected java.lang.String flushClearCache
        The FlashClearCache mode to be used. Relevant only in case call to flush method followed by call to clear method.
        See Also:
        FlushClearCache
      • shouldValidateExistence

        protected boolean shouldValidateExistence
        Determine if does-exist should be performed on persist.
      • commitOrder

        protected org.eclipse.persistence.sessions.UnitOfWork.CommitOrderType commitOrder
        Allow updates to be ordered by id to avoid possible deadlocks.
      • commitWithoutPersistRules

        protected boolean commitWithoutPersistRules
      • syncType

        protected javax.persistence.SynchronizationType syncType
        Tracks if this EntityManager should automatically associate with the transaction or not
    • Constructor Detail

      • EntityManagerImpl

        public EntityManagerImpl​(java.lang.String sessionName)
        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

        public EntityManagerImpl​(org.eclipse.persistence.internal.sessions.AbstractSession databaseSession,
                                 javax.persistence.SynchronizationType syncType)
        Constructor called from the EntityManagerFactory to create an EntityManager
        Parameters:
        databaseSession - the databaseSession assigned to this deployment.
      • EntityManagerImpl

        public EntityManagerImpl​(org.eclipse.persistence.internal.sessions.AbstractSession databaseSession,
                                 java.util.Map properties,
                                 javax.persistence.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,
                                 java.util.Map properties,
                                 javax.persistence.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 Detail

      • getOpenQueriesMap

        protected java.util.Map<QueryImpl,​QueryImpl> getOpenQueriesMap()
        Return the weak reference to the open queries.
      • getOpenQueriesSet

        protected java.util.Set<QueryImpl> getOpenQueriesSet()
        Return the weak reference to the open queries.
      • addOpenQuery

        public void addOpenQuery​(QueryImpl query)
        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.
        Parameters:
        query -
      • initialize

        protected void initialize​(java.util.Map properties)
        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:
        clear in interface javax.persistence.EntityManager
      • 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

        public void persist​(java.lang.Object entity)
        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:
        persist in interface javax.persistence.EntityManager
        Parameters:
        entity -
        Throws:
        java.lang.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:
        merge in interface javax.persistence.EntityManager
        Parameters:
        entity -
        Returns:
        the instance that the state was merged to
      • mergeInternal

        protected java.lang.Object mergeInternal​(java.lang.Object entity)
        Merge the state of the given entity into the current persistence context, using the unqualified class name as the entity name.
        Parameters:
        entity -
        Returns:
        the instance that the state was merged to
        Throws:
        java.lang.IllegalArgumentException - if given Object is not an entity or is a removed entity
      • remove

        public void remove​(java.lang.Object entity)
        Remove the instance.
        Specified by:
        remove in interface javax.persistence.EntityManager
        Parameters:
        entity -
        Throws:
        java.lang.IllegalArgumentException - if Object passed in is not an entity
      • find

        public <T> T find​(java.lang.Class<T> entityClass,
                          java.lang.Object primaryKey)
        Find by primary key.
        Specified by:
        find in interface javax.persistence.EntityManager
        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:
        java.lang.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

        public <T> T find​(java.lang.Class<T> entityClass,
                          java.lang.Object primaryKey,
                          java.util.Map<java.lang.String,​java.lang.Object> properties)
        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:
        find in interface javax.persistence.EntityManager
        Parameters:
        entityClass -
        primaryKey -
        properties - standard and vendor-specific properties
        Returns:
        the found entity instance or null if the entity does not exist
        Throws:
        java.lang.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

        public <T> T find​(java.lang.Class<T> entityClass,
                          java.lang.Object primaryKey,
                          javax.persistence.LockModeType lockMode)
        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:
        find in interface javax.persistence.EntityManager
        Parameters:
        entityClass -
        primaryKey -
        lockMode -
        Returns:
        the found entity instance or null if the entity does not exist
        Throws:
        java.lang.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 null
        javax.persistence.TransactionRequiredException - if there is no transaction and a lock mode other than NONE is set
        javax.persistence.OptimisticLockException - if the optimistic version check fails
        javax.persistence.PessimisticLockException - if pessimistic locking fails and the transaction is rolled back
        javax.persistence.LockTimeoutException - if pessimistic locking fails and only the statement is rolled back
        javax.persistence.PersistenceException - if an unsupported lock call is made
      • find

        public <T> T find​(java.lang.Class<T> entityClass,
                          java.lang.Object primaryKey,
                          javax.persistence.LockModeType lockMode,
                          java.util.Map<java.lang.String,​java.lang.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:
        find in interface javax.persistence.EntityManager
        Parameters:
        entityClass -
        primaryKey -
        lockMode -
        properties - standard and vendor-specific properties and hints
        Returns:
        the found entity instance or null if the entity does not exist
        Throws:
        java.lang.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 null
        javax.persistence.TransactionRequiredException - if there is no transaction and a lock mode other than NONE is set
        javax.persistence.OptimisticLockException - if the optimistic version check fails
        javax.persistence.PessimisticLockException - if pessimistic locking fails and the transaction is rolled back
        javax.persistence.LockTimeoutException - if pessimistic locking fails and only the statement is rolled back
        javax.persistence.PersistenceException - if an unsupported lock call is made
      • find

        public java.lang.Object find​(java.lang.String entityName,
                                     java.lang.Object primaryKey)
        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:
        java.lang.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 java.lang.Object findInternal​(org.eclipse.persistence.descriptors.ClassDescriptor descriptor,
                                                org.eclipse.persistence.internal.sessions.AbstractSession session,
                                                java.lang.Object id,
                                                javax.persistence.LockModeType lockMode,
                                                java.util.Map<java.lang.String,​java.lang.Object> properties)
        Find by primary key.
        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:
        java.lang.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:
        flush in interface javax.persistence.EntityManager
      • detectTransactionWrapper

        protected void detectTransactionWrapper()
      • refresh

        public void refresh​(java.lang.Object entity)
        Refresh the state of the instance from the database.
        Specified by:
        refresh in interface javax.persistence.EntityManager
        Parameters:
        entity - instance registered in the current persistence context.
      • refresh

        public void refresh​(java.lang.Object entity,
                            java.util.Map<java.lang.String,​java.lang.Object> properties)
        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:
        refresh in interface javax.persistence.EntityManager
        Parameters:
        entity -
        properties - standard and vendor-specific properties
        Throws:
        java.lang.IllegalArgumentException - if the instance is not an entity or the entity is not managed
        javax.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 database
        Since:
        Java Persistence API 2.0
      • refresh

        public void refresh​(java.lang.Object entity,
                            javax.persistence.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. 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:
        refresh in interface javax.persistence.EntityManager
        Parameters:
        entity -
        lockMode -
        Throws:
        java.lang.IllegalArgumentException - if the instance is not an entity or the entity is not managed
        javax.persistence.TransactionRequiredException - if there is no transaction
        javax.persistence.EntityNotFoundException - if the entity no longer exists in the database
        javax.persistence.PessimisticLockException - if pessimistic locking fails and the transaction is rolled back
        javax.persistence.LockTimeoutException - if pessimistic locking fails and only the statement is rolled back
        javax.persistence.PersistenceException - if an unsupported lock call is made
      • refresh

        public void refresh​(java.lang.Object entity,
                            javax.persistence.LockModeType lockMode,
                            java.util.Map<java.lang.String,​java.lang.Object> properties)
        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:
        refresh in interface javax.persistence.EntityManager
        Parameters:
        entity -
        lockMode -
        properties - standard and vendor-specific properties and hints
        Throws:
        java.lang.IllegalArgumentException - if the instance is not an entity or the entity is not managed
        javax.persistence.TransactionRequiredException - if there is no transaction
        javax.persistence.EntityNotFoundException - if the entity no longer exists in the database
        javax.persistence.PessimisticLockException - if pessimistic locking fails and the transaction is rolled back
        javax.persistence.LockTimeoutException - if pessimistic locking fails and only the statement is rolled back
        javax.persistence.PersistenceException - if an unsupported lock call is made
      • contains

        public boolean contains​(java.lang.Object entity)
        Check if the instance belongs to the current persistence context.
        Specified by:
        contains in interface javax.persistence.EntityManager
        Parameters:
        entity -
        Returns:
        Throws:
        java.lang.IllegalArgumentException - if given Object is not an entity
      • contains

        protected boolean contains​(java.lang.Object entity,
                                   org.eclipse.persistence.sessions.UnitOfWork uow)
        Check if the instance belongs to the current persistence context.
      • createDescriptorNamedQuery

        public javax.persistence.Query createDescriptorNamedQuery​(java.lang.String queryName,
                                                                  java.lang.Class descriptorClass)
        Description copied from interface: JpaEntityManager
        This method will create a query object that wraps a EclipseLink Named Query.
        Specified by:
        createDescriptorNamedQuery in interface JpaEntityManager
      • createDescriptorNamedQuery

        public javax.persistence.Query createDescriptorNamedQuery​(java.lang.String queryName,
                                                                  java.lang.Class descriptorClass,
                                                                  java.util.List argumentTypes)
        Description copied from interface: JpaEntityManager
        This method will create a query object that wraps a EclipseLink Named Query.
        Specified by:
        createDescriptorNamedQuery in interface JpaEntityManager
      • createNamedQuery

        public javax.persistence.Query createNamedQuery​(java.lang.String name)
        Create an instance of Query for executing a named query (in EJBQL or native SQL).
        Specified by:
        createNamedQuery in interface javax.persistence.EntityManager
        Parameters:
        name - the name of a query defined in metadata
        Returns:
        the new query instance
      • createNamedQuery

        public <T> javax.persistence.TypedQuery<T> createNamedQuery​(java.lang.String name,
                                                                    java.lang.Class<T> resultClass)
        Create an instance of TypedQuery for executing a named query (in the Java Persistence query language or in native SQL).
        Specified by:
        createNamedQuery in interface javax.persistence.EntityManager
        Parameters:
        name - the name of a query defined in metadata
        resultClass - the type of the query result
        Returns:
        the new query instance
        Throws:
        java.lang.IllegalArgumentException - if a query has not been defined with the given name or if the query string is found to be invalid
      • createNamedStoredProcedureQuery

        public javax.persistence.StoredProcedureQuery createNamedStoredProcedureQuery​(java.lang.String name)
        Create an instance of StoredProcedureQuery for executing a stored procedure in the database.
        Specified by:
        createNamedStoredProcedureQuery in interface javax.persistence.EntityManager
        Parameters:
        name - name assigned to the stored procedure query in metadata
        Returns:
        the new stored procedure query instance
        Throws:
        java.lang.IllegalArgumentException - if a query has not been defined with the given name
      • createNativeQuery

        public javax.persistence.Query createNativeQuery​(java.lang.String sqlString)
        Create an instance of Query for executing a native SQL query.
        Specified by:
        createNativeQuery in interface javax.persistence.EntityManager
        Parameters:
        sqlString - a native SQL query string
        Returns:
        the new query instance
      • createNativeQuery

        public javax.persistence.Query createNativeQuery​(java.lang.String sqlString,
                                                         java.lang.Class resultType)
        This method is used to create a query using SQL. The class, must be the expected return type.
        Specified by:
        createNativeQuery in interface javax.persistence.EntityManager
      • createNativeQuery

        public javax.persistence.Query createNativeQuery​(java.lang.String sqlString,
                                                         java.lang.String resultSetMapping)
        Create an instance of Query for executing a native SQL query.
        Specified by:
        createNativeQuery in interface javax.persistence.EntityManager
        Parameters:
        sqlString - a native SQL query string
        resultSetMapping - the name of the result set mapping
        Returns:
        the new query instance
        Throws:
        java.lang.IllegalArgumentException - if query string is not valid
      • getActiveSession

        public org.eclipse.persistence.sessions.Session 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:
        getActiveSession in interface JpaEntityManager
      • getActiveSessionIfExists

        public org.eclipse.persistence.internal.sessions.AbstractSession 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

        public java.lang.Object getDelegate()
        Return the underlying provider object for the EntityManager, if available. The result of this method is implementation specific.
        Specified by:
        getDelegate in interface javax.persistence.EntityManager
      • getFlushMode

        public javax.persistence.FlushModeType getFlushMode()
        Get the flush mode that applies to all objects contained in the persistence context.
        Specified by:
        getFlushMode in interface javax.persistence.EntityManager
        Returns:
        flushMode
      • getUnitOfWork

        public org.eclipse.persistence.sessions.UnitOfWork getUnitOfWork()
        This method will return the active UnitOfWork
        Specified by:
        getUnitOfWork in interface JpaEntityManager
      • getSession

        public org.eclipse.persistence.sessions.Session getSession()
        This method will return a Session outside of a transaction and null within a transaction.
        Specified by:
        getSession in interface JpaEntityManager
      • getTransaction

        public javax.persistence.EntityTransaction getTransaction()
        Returns the resource-level transaction object. The EntityTransaction instance may be used serially to begin and commit multiple transactions.
        Specified by:
        getTransaction in interface javax.persistence.EntityManager
        Returns:
        EntityTransaction instance
        Throws:
        java.lang.IllegalStateException - if invoked on a JTA EntityManager.
      • getProperty

        public java.lang.Object getProperty​(java.lang.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.
        Parameters:
        name -
        Returns:
      • getReadObjectQuery

        protected org.eclipse.persistence.queries.ReadObjectQuery getReadObjectQuery​(java.lang.Class referenceClass,
                                                                                     java.lang.Object primaryKey,
                                                                                     java.util.Map properties)
        Build a selection query for the primary key values.
      • getReadObjectQuery

        protected org.eclipse.persistence.queries.ReadObjectQuery getReadObjectQuery​(java.util.Map properties)
        Build a selection query using the given properties.
      • getReadObjectQuery

        protected org.eclipse.persistence.queries.ReadObjectQuery getReadObjectQuery​(java.lang.Object entity,
                                                                                     java.util.Map properties)
        Build a selection query for the given entity.
      • getReference

        public <T> T getReference​(java.lang.Class<T> entityClass,
                                  java.lang.Object primaryKey)
        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:
        getReference in interface javax.persistence.EntityManager
        Parameters:
        entityClass -
        primaryKey -
        Returns:
        the found entity instance.
        Throws:
        java.lang.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.
        javax.persistence.EntityNotFoundException - if the entity state cannot be accessed.
      • getReadOnlySession

        public org.eclipse.persistence.sessions.Session getReadOnlySession()
        Return a read-only session (client session) for read-only operations.
      • getDatabaseSession

        public org.eclipse.persistence.internal.sessions.DatabaseSessionImpl getDatabaseSession()
        Return the underlying database session
        Specified by:
        getDatabaseSession in interface JpaEntityManager
      • getAbstractSession

        public org.eclipse.persistence.internal.sessions.AbstractSession getAbstractSession()
        Return the underlying database session
        Specified by:
        getAbstractSession in interface JpaEntityManager
      • setAbstractSession

        public void setAbstractSession​(org.eclipse.persistence.internal.sessions.AbstractSession session)
        INTERNAL: Set the underlying database session
      • getServerSession

        public org.eclipse.persistence.sessions.server.ServerSession getServerSession()
        Return the underlying server session, throws ClassCastException if it's not a ServerSession.
        Specified by:
        getServerSession in interface JpaEntityManager
      • getSessionBroker

        public org.eclipse.persistence.sessions.broker.SessionBroker getSessionBroker()
        Return the underlying session broker, throws ClassCastException if it's not a SessionBroker.
        Specified by:
        getSessionBroker in interface JpaEntityManager
      • getMemberDatabaseSession

        public org.eclipse.persistence.internal.sessions.DatabaseSessionImpl getMemberDatabaseSession​(java.lang.Class cls)
        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:
        getMemberDatabaseSession in interface JpaEntityManager
      • getMemberServerSession

        public org.eclipse.persistence.sessions.server.ServerSession getMemberServerSession​(java.lang.Class cls)
        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:
        getMemberServerSession in interface JpaEntityManager
      • getMemberSessionName

        public java.lang.String getMemberSessionName​(java.lang.Class cls)
        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:
        getMemberSessionName in interface JpaEntityManager
      • createQuery

        public javax.persistence.Query createQuery​(org.eclipse.persistence.expressions.Expression expression,
                                                   java.lang.Class resultType)
        This method is used to create a query using a EclipseLink Expression and the return type.
        Specified by:
        createQuery in interface JpaEntityManager
      • createQuery

        public javax.persistence.Query createQuery​(org.eclipse.persistence.queries.DatabaseQuery databaseQuery)
        This method is used to create a query using a EclipseLink DatabaseQuery.
        Specified by:
        createQuery in interface JpaEntityManager
      • createQuery

        public <T> javax.persistence.TypedQuery<T> createQuery​(javax.persistence.criteria.CriteriaQuery<T> criteriaQuery)
        Specified by:
        createQuery in interface javax.persistence.EntityManager
        Since:
        Java Persistence 2.0
        See Also:
        EntityManager.createQuery(javax.persistence.criteria.CriteriaQuery)
      • createQueryByExample

        public javax.persistence.Query createQueryByExample​(java.lang.Object exampleObject)
        This method is used to create a query using a EclipseLink by example.
        Specified by:
        createQueryByExample in interface JpaEntityManager
      • createQuery

        public javax.persistence.Query createQuery​(org.eclipse.persistence.queries.Call call)
        This method is used to create a query using a EclipseLink Call.
        Specified by:
        createQuery in interface JpaEntityManager
      • createQuery

        public javax.persistence.Query createQuery​(org.eclipse.persistence.queries.Call call,
                                                   java.lang.Class entityClass)
        This method is used to create a query using a EclipseLink Call.
        Specified by:
        createQuery in interface JpaEntityManager
      • createQuery

        public javax.persistence.Query createQuery​(java.lang.String jpqlString)
        Create an instance of Query for executing an JPQL query.
        Specified by:
        createQuery in interface javax.persistence.EntityManager
        Parameters:
        jpqlString - an JPQL query string
        Returns:
        the new query instance
      • createQuery

        public <T> javax.persistence.TypedQuery<T> createQuery​(java.lang.String qlString,
                                                               java.lang.Class<T> resultClass)
        Create an instance of TypedQuery for executing a Java Persistence query language statement.
        Specified by:
        createQuery in interface javax.persistence.EntityManager
        Parameters:
        qlString - a Java Persistence query string
        resultClass - the type of the query result
        Returns:
        the new query instance
        Throws:
        java.lang.IllegalArgumentException - if the query string is found to be invalid
      • createQueryInternal

        protected org.eclipse.persistence.queries.DatabaseQuery createQueryInternal​(org.eclipse.persistence.expressions.Expression expression,
                                                                                    java.lang.Class resultType)
        This method is used to create a query using a EclipseLink Expression and the return type.
      • createStoredProcedureQuery

        public javax.persistence.StoredProcedureQuery createStoredProcedureQuery​(java.lang.String procedureName)
        Create an instance of StoredProcedureQuery for 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:
        createStoredProcedureQuery in interface javax.persistence.EntityManager
        Parameters:
        procedureName - name of the stored procedure in the database
        Returns:
        the new stored procedure query instance
        Throws:
        java.lang.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 javax.persistence.StoredProcedureQuery createStoredProcedureQuery​(java.lang.String procedureName,
                                                                                 java.lang.Class... resultClasses)
        Create an instance of StoredProcedureQuery for executing a stored procedure in the database.

        Parameters must be registered before the stored procedure can be executed.

        The resultClass arguments must be specified in the order in which the result sets will be returned by the stored procedure invocation.

        Specified by:
        createStoredProcedureQuery in interface javax.persistence.EntityManager
        Parameters:
        procedureName - name of the stored procedure in the database
        resultClasses - classes to which the result sets produced by the stored procedure are to be mapped
        Returns:
        the new stored procedure query instance
        Throws:
        java.lang.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 javax.persistence.StoredProcedureQuery createStoredProcedureQuery​(java.lang.String procedureName,
                                                                                 java.lang.String... resultSetMappings)
        Create an instance of StoredProcedureQuery for executing a stored procedure in the database.

        Parameters must be registered before the stored procedure can be executed.

        The resultSetMapping arguments must be specified in the order in which the result sets will be returned by the stored procedure invocation.

        Specified by:
        createStoredProcedureQuery in interface javax.persistence.EntityManager
        Parameters:
        procedureName - name of the stored procedure in the database
        resultSetMappings - 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:
        java.lang.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 IllegalStateException except for isOpen, which will return false .

        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:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface javax.persistence.EntityManager
      • 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. Returns true until a call to close() is made.
        Specified by:
        isOpen in interface javax.persistence.EntityManager
      • lock

        public void lock​(java.lang.Object entity,
                         javax.persistence.LockModeType lockMode)
        Set the lock mode for an entity object contained in the persistence context.
        Specified by:
        lock in interface javax.persistence.EntityManager
        Parameters:
        entity -
        lockMode -
        Throws:
        javax.persistence.PersistenceException - if an unsupported lock call is made
        java.lang.IllegalArgumentException - if the instance is not an entity or is a detached entity
        javax.persistence.TransactionRequiredException - if there is no transaction
      • lock

        public void lock​(java.lang.Object entity,
                         javax.persistence.LockModeType lockMode,
                         java.util.Map<java.lang.String,​java.lang.Object> properties)
        Set the lock mode for an entity object contained in the persistence context.
        Specified by:
        lock in interface javax.persistence.EntityManager
        Parameters:
        entity -
        lockMode -
        Throws:
        javax.persistence.PersistenceException - if an unsupported lock call is made
        java.lang.IllegalArgumentException - if the instance is not an entity or is a detached entity
        javax.persistence.TransactionRequiredException - 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

        public org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork getActivePersistenceContext​(java.lang.Object txn)
      • setProperties

        public void setProperties​(java.util.Map properties)
        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

        public void setProperty​(java.lang.String propertyName,
                                java.lang.Object value)
        Specified by:
        setProperty in interface javax.persistence.EntityManager
        See Also:
        EntityManager.setProperty(java.lang.String, java.lang.Object)
      • 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

        protected java.lang.Object checkForTransaction​(boolean validateExistence)
        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:
        joinTransaction in interface javax.persistence.EntityManager
        Throws:
        javax.persistence.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

        protected java.lang.String getPropertiesHandlerProperty​(java.lang.String name)
        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

        protected static java.lang.String getPropertiesHandlerProperty​(java.lang.String name,
                                                                       java.lang.String value)
        Verifies and (if required) translates the value.
      • setEntityTransactionWrapper

        protected void setEntityTransactionWrapper()
      • setFlushMode

        public void setFlushMode​(javax.persistence.FlushModeType flushMode)
        Set the flush mode that applies to all objects contained in the persistence context.
        Specified by:
        setFlushMode in interface javax.persistence.EntityManager
        Parameters:
        flushMode -
      • 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

        protected void createConnectionPolicies​(java.util.Map mapOfProperties)
        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 org.eclipse.persistence.sessions.server.ConnectionPolicy createConnectionPolicy​(org.eclipse.persistence.sessions.server.ServerSession serverSession,
                                                                                                         java.util.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:
        isBroker in interface JpaEntityManager
      • isPropertyToBeAdded

        protected static boolean isPropertyToBeAdded​(java.lang.String value)
        Property value is to be added if it's non null and not an empty string.
      • isPropertyToBeAdded

        protected static boolean isPropertyToBeAdded​(javax.sql.DataSource ds,
                                                     java.lang.String dsName)
      • isPropertyToBeRemoved

        protected static boolean isPropertyToBeRemoved​(java.lang.String value)
        Property value of an empty string indicates that the existing property should be removed.
      • isPropertyValueToBeUpdated

        protected static java.lang.Boolean isPropertyValueToBeUpdated​(java.lang.String oldValue,
                                                                      java.lang.String newValue)
        Returns:
        null: no change; TRUE: substitute oldValue by newValue; FALSE: remove oldValue
      • detach

        public void detach​(java.lang.Object entity)
        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:
        detach in interface javax.persistence.EntityManager
        Parameters:
        entity -
        Throws:
        java.lang.IllegalArgumentException - if the instance is not an entity
        Since:
        Java Persistence 2.0
      • getCriteriaBuilder

        public javax.persistence.criteria.CriteriaBuilder getCriteriaBuilder()
        Return an instance of CriteriaBuilder for the creation of Criteria API Query objects.
        Specified by:
        getCriteriaBuilder in interface javax.persistence.EntityManager
        Returns:
        CriteriaBuilder instance
        Throws:
        java.lang.IllegalStateException - if the entity manager has been closed.
        Since:
        Java Persistence 2.0
        See Also:
        EntityManager.getCriteriaBuilder()
      • getQueryHints

        protected java.util.HashMap<java.lang.String,​java.lang.Object> getQueryHints​(java.lang.Object entity,
                                                                                           EntityManagerImpl.OperationType operation)
        Before any find or refresh operation, gather any persistence unit properties that should be applied to the query.
      • getMetamodel

        public javax.persistence.metamodel.Metamodel getMetamodel()
        Return an instance of Metamodel interface for access to the metamodel of the persistence unit.
        Specified by:
        getMetamodel in interface javax.persistence.EntityManager
        Returns:
        Metamodel instance
        Throws:
        java.lang.IllegalStateException - if the entity manager has been closed.
        Since:
        Java Persistence 2.0
        See Also:
        EntityManager.getMetamodel()
      • getEntityManagerFactory

        public javax.persistence.EntityManagerFactory getEntityManagerFactory()
        Return the entity manager factory for the entity manager.
        Specified by:
        getEntityManagerFactory in interface javax.persistence.EntityManager
        Returns:
        EntityManagerFactory instance
        Throws:
        java.lang.IllegalStateException - if the entity manager has been closed.
        Since:
        Java Persistence API 2.0
      • getLockMode

        public javax.persistence.LockModeType getLockMode​(java.lang.Object entity)
        Specified by:
        getLockMode in interface javax.persistence.EntityManager
        Since:
        Java Persistence API 2.0
        See Also:
        EntityManager.getLockMode(java.lang.Object)
      • getProperties

        public java.util.Map<java.lang.String,​java.lang.Object> 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:
        getProperties in interface javax.persistence.EntityManager
        Since:
        Java Persistence API 2.0
      • getSupportedProperties

        public java.util.Set<java.lang.String> 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

        public <T> T unwrap​(java.lang.Class<T> cls)
        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:
        unwrap in interface javax.persistence.EntityManager
        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:
        javax.persistence.PersistenceException - if the provider does not support the call.
        Since:
        Java Persistence API 2.0
      • load

        public void load​(java.lang.Object entityOrEntities,
                         org.eclipse.persistence.queries.AttributeGroup group)
        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:
        load in interface JpaEntityManager
        Parameters:
        entityOrEntities -
      • copy

        public java.lang.Object copy​(java.lang.Object entityOrEntities,
                                     org.eclipse.persistence.queries.AttributeGroup group)
        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:
        copy in interface JpaEntityManager
        Parameters:
        entityOrEntities -
      • processUnfetchedAttribute

        public static void processUnfetchedAttribute​(org.eclipse.persistence.queries.FetchGroupTracker entity,
                                                     java.lang.String attributeName)
        INTERNAL: Load/fetch the unfetched object. This method is used by the ClassWaver..
      • processUnfetchedAttributeForSet

        public static void processUnfetchedAttributeForSet​(org.eclipse.persistence.queries.FetchGroupTracker entity,
                                                           java.lang.String attributeName)
        INTERNAL: Load/fetch the unfetched object. This method is used by the ClassWeaver.
      • createQuery

        public javax.persistence.Query createQuery​(javax.persistence.criteria.CriteriaUpdate updateQuery)
        Specified by:
        createQuery in interface javax.persistence.EntityManager
      • createQuery

        public javax.persistence.Query createQuery​(javax.persistence.criteria.CriteriaDelete deleteQuery)
        Specified by:
        createQuery in interface javax.persistence.EntityManager
      • isJoinedToTransaction

        public boolean isJoinedToTransaction()
        Specified by:
        isJoinedToTransaction in interface javax.persistence.EntityManager
      • createEntityGraph

        public <T> javax.persistence.EntityGraph<T> createEntityGraph​(java.lang.Class<T> rootType)
        Specified by:
        createEntityGraph in interface javax.persistence.EntityManager
      • createEntityGraph

        public javax.persistence.EntityGraph createEntityGraph​(java.lang.String graphName)
        Specified by:
        createEntityGraph in interface javax.persistence.EntityManager
      • getEntityGraph

        public javax.persistence.EntityGraph getEntityGraph​(java.lang.String graphName)
        Specified by:
        getEntityGraph in interface javax.persistence.EntityManager
      • getEntityGraphs

        public <T> java.util.List<javax.persistence.EntityGraph<? super T>> getEntityGraphs​(java.lang.Class<T> entityClass)
        Specified by:
        getEntityGraphs in interface javax.persistence.EntityManager
      • getSyncType

        public javax.persistence.SynchronizationType getSyncType()
        INTERNAL: Tracks if this EntityManager should automatically associate with the transaction or not
        Returns:
        the syncType