Class EntityManagerFactoryDelegate

  • All Implemented Interfaces:
    java.lang.AutoCloseable, javax.persistence.EntityManagerFactory, javax.persistence.PersistenceUnitUtil, javax.persistence.PersistenceUtil, JpaEntityManagerFactory

    public class EntityManagerFactoryDelegate
    extends java.lang.Object
    implements javax.persistence.EntityManagerFactory, javax.persistence.PersistenceUnitUtil, JpaEntityManagerFactory

    Purpose: Provides the implementation for the EntityManager Factory.

    Description: This class will store a reference to the active ServerSession. When a request is made for an EntityManager an new EntityManager is created with the ServerSession and returned. The primary consumer of these EntityManager is assumed to be either the Container. There is one EntityManagerFactory per deployment.

    Since:
    TopLink Essentials - JPA 1.0
    Author:
    gyorke
    See Also:
    EntityManager, JpaEntityManager, JpaEntityManagerFactory
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean beginEarlyTransaction
      Default join existing transaction property, allows reading through write connection.
      protected boolean closeOnCommit
      Default property to avoid resuming unit of work if going to be closed on commit anyway.
      protected org.eclipse.persistence.sessions.UnitOfWork.CommitOrderType commitOrder
      Order updates by id to avoid potential deadlocks.
      protected boolean commitWithoutPersistRules  
      protected java.lang.String flushClearCache
      Default FlashClearCache mode to be used.
      protected javax.persistence.FlushModeType flushMode
      Default property, allows flush before query to be avoided.
      protected boolean isOpen
      Stores if closed has been called.
      protected javax.persistence.Cache myCache
      Reference to Cache Interface.
      protected JpaEntityManagerFactory owner
      Pointer to the EntityManagerFactoryImpl that created me
      protected boolean persistOnCommit
      Default property to avoid discover new objects in unit of work if application always uses persist.
      protected java.util.Map properties
      Persistence unit properties from create factory.
      protected org.eclipse.persistence.config.ReferenceMode referenceMode
      Default property, allows weak unit of work references.
      protected org.eclipse.persistence.internal.sessions.AbstractSession session
      Reference to the ServerSession for this deployment.
      protected EntityManagerSetupImpl setupImpl
      EntityManagerSetupImpl that deployed this factory.
      protected boolean shouldValidateExistence
      Default to determine if does-exist should be performed on persist.
      protected static java.util.Set<java.lang.String> supportedNonServerSessionProperties
      INTERNAL: The following properties passed to createEMF cached and processed on the emf directly.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T> void addNamedEntityGraph​(java.lang.String graphName, javax.persistence.EntityGraph<T> entityGraph)  
      void addNamedQuery​(java.lang.String name, javax.persistence.Query query)  
      void close()
      Closes this factory, releasing any resources that might be held by this factory.
      javax.persistence.EntityManager createEntityManager()
      PUBLIC: Returns an EntityManager for this deployment.
      javax.persistence.EntityManager createEntityManager​(java.util.Map properties)
      PUBLIC: Returns an EntityManager for this deployment.
      javax.persistence.EntityManager createEntityManager​(javax.persistence.SynchronizationType synchronizationType)  
      javax.persistence.EntityManager createEntityManager​(javax.persistence.SynchronizationType synchronizationType, java.util.Map map)  
      protected EntityManagerImpl createEntityManagerImpl​(java.util.Map properties, javax.persistence.SynchronizationType syncType)  
      protected void finalize()  
      org.eclipse.persistence.internal.sessions.AbstractSession getAbstractSession()
      INTERNAL: Returns the ServerSession that the Factory will be using and initializes it if it is not available.
      boolean getBeginEarlyTransaction()
      Return default join existing transaction property, allows reading through write connection.
      javax.persistence.Cache getCache()
      Access the cache that is associated with the entity manager factory (the "second level cache").
      boolean getCloseOnCommit()
      Return default property to avoid resuming unit of work if going to be closed on commit anyway.
      org.eclipse.persistence.sessions.UnitOfWork.CommitOrderType getCommitOrder()
      Return if updates should be ordered by primary key, to avoid potential database deadlocks.
      boolean getCommitWithoutPersistRules()
      Return default property to avoid discover new objects in unit of work if application always uses persist.
      javax.persistence.criteria.CriteriaBuilder getCriteriaBuilder()  
      org.eclipse.persistence.internal.sessions.DatabaseSessionImpl getDatabaseSession()
      INTERNAL: Returns the ServerSession that the Factory will be using and initializes it if it is not available.
      java.lang.String getFlushClearCache()
      Return the default FlashClearCache mode to be used.
      javax.persistence.FlushModeType getFlushMode()
      Return default property, allows flush before query to be avoided.
      java.lang.Object getIdentifier​(java.lang.Object entity)
      Returns the id of the entity.
      javax.persistence.metamodel.Metamodel getMetamodel()
      Return an instance of Metamodel interface for access to the metamodel of the persistence unit.
      JpaEntityManagerFactory getOwner()
      INTERNAL: Get the EntityManagerFactoryImpl that created this
      javax.persistence.PersistenceUnitUtil getPersistenceUnitUtil()
      Return interface providing access to utility methods for the persistence unit.
      boolean getPersistOnCommit()
      Return default property to avoid discover new objects in unit of work if application always uses persist.
      java.util.Map<java.lang.String,​java.lang.Object> getProperties()  
      java.lang.Object getProperty​(java.lang.String name)
      The method return user defined property passed in from EntityManagerFactory.
      org.eclipse.persistence.config.ReferenceMode getReferenceMode()
      Return default property, allows weak unit of work references.
      org.eclipse.persistence.sessions.server.ServerSession getServerSession()
      INTERNAL: Returns the ServerSession that the Factory will be using and initializes it if it is not available.
      org.eclipse.persistence.sessions.broker.SessionBroker getSessionBroker()
      INTERNAL: Returns the SessionBroker that the Factory will be using and initializes it if it is not available.
      EntityManagerSetupImpl getSetupImpl()
      INTERNAL: Return the EntityManagerSetupImpl associated with this factory
      boolean isLoaded​(java.lang.Object entity)
      Determine the load state of an entity belonging to the persistence unit.
      boolean isLoaded​(java.lang.Object entity, java.lang.String attributeName)
      Determine the load state of a given persistent attribute of an entity belonging to the persistence unit.
      boolean isOpen()
      Indicates whether or not this factory is open.
      protected void processProperties​(java.util.Map properties)
      Process all EntityManager properties.
      void refreshMetadata​(java.util.Map properties)
      ADVANCED: Re-bootstrap this factory.
      void setBeginEarlyTransaction​(boolean beginEarlyTransaction)
      Set default join existing transaction property, allows reading through write connection.
      void setCloseOnCommit​(boolean closeOnCommit)
      Set default property to avoid resuming unit of work if going to be closed on commit anyway.
      void setCommitOrder​(org.eclipse.persistence.sessions.UnitOfWork.CommitOrderType commitOrder)
      Set update ordering by primary key, to avoid potential database deadlocks.
      void setCommitWithoutPersistRules​(boolean commitWithoutPersistRules)
      Set default property to avoid discover new objects in unit of work if application always uses persist.
      void setFlushClearCache​(java.lang.String flushClearCache)
      Set the default FlashClearCache mode to be used.
      void setFlushMode​(javax.persistence.FlushModeType flushMode)
      Set default property, allows flush before query to be avoided.
      void setMetamodel​(javax.persistence.metamodel.Metamodel aMetamodel)
      INTERNAL: Convenience function to allow us to reset the Metamodel in the possible case that we want to regenerate it.
      void setPersistOnCommit​(boolean persistOnCommit)
      Set default property to avoid discover new objects in unit of work if application always uses persist.
      void setReferenceMode​(org.eclipse.persistence.config.ReferenceMode referenceMode)
      Set default property, allows weak unit of work references.
      void setShouldValidateExistence​(boolean shouldValidateExistence)
      Set the default to determine if does-exist should be performed on persist.
      boolean shouldValidateExistence()
      Return the default to determine if does-exist should be performed on persist.
      EntityManagerFactoryDelegate unwrap()
      Gets the underlying implementation of the EntityManagerFactory.
      <T> T unwrap​(java.lang.Class<T> cls)  
      protected void verifyOpen()  
      • Methods inherited from class java.lang.Object

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

      • myCache

        protected javax.persistence.Cache myCache
        Reference to Cache Interface.
      • session

        protected volatile org.eclipse.persistence.internal.sessions.AbstractSession session
        Reference to the ServerSession for this deployment.
      • isOpen

        protected boolean isOpen
        Stores if closed has been called.
      • properties

        protected java.util.Map properties
        Persistence unit properties from create factory.
      • supportedNonServerSessionProperties

        protected static final java.util.Set<java.lang.String> supportedNonServerSessionProperties
        INTERNAL: The following properties passed to createEMF cached and processed on the emf directly. None of these properties processed during predeploy or deploy.
      • beginEarlyTransaction

        protected boolean beginEarlyTransaction
        Default join existing transaction property, allows reading through write connection.
      • flushMode

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

        protected org.eclipse.persistence.config.ReferenceMode referenceMode
        Default property, allows weak unit of work references.
      • closeOnCommit

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

        protected boolean persistOnCommit
        Default property to avoid discover new objects in unit of work if application always uses persist.
      • flushClearCache

        protected java.lang.String flushClearCache
        Default 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
        Default to determine if does-exist should be performed on persist.
      • commitOrder

        protected org.eclipse.persistence.sessions.UnitOfWork.CommitOrderType commitOrder
        Order updates by id to avoid potential deadlocks. Default is true.
      • commitWithoutPersistRules

        protected boolean commitWithoutPersistRules
    • Constructor Detail

      • EntityManagerFactoryDelegate

        public EntityManagerFactoryDelegate​(org.eclipse.persistence.internal.sessions.AbstractSession databaseSession,
                                            JpaEntityManagerFactory owner)
        Will return an instance of the Factory. Should only be called by EclipseLink.
        Parameters:
        databaseSession -
      • EntityManagerFactoryDelegate

        public EntityManagerFactoryDelegate​(java.lang.String persistenceUnitName,
                                            java.util.Map<java.lang.String,​java.lang.Object> properties,
                                            java.util.List<org.eclipse.persistence.descriptors.ClassDescriptor> descriptors,
                                            JpaEntityManagerFactory owner)
        Create a dynamic persistence unit which does not use the persistence.xml. Instead all configuration is driven from the provided persistence unit properties and descriptors.
    • Method Detail

      • getDatabaseSession

        public org.eclipse.persistence.internal.sessions.DatabaseSessionImpl getDatabaseSession()
        INTERNAL: Returns the ServerSession that the Factory will be using and initializes it if it is not available. This method makes use of the partially constructed session stored in our setupImpl and completes its construction
        Specified by:
        getDatabaseSession in interface JpaEntityManagerFactory
      • getAbstractSession

        public org.eclipse.persistence.internal.sessions.AbstractSession getAbstractSession()
        INTERNAL: Returns the ServerSession that the Factory will be using and initializes it if it is not available. This method makes use of the partially constructed session stored in our setupImpl and completes its construction
      • getSetupImpl

        public EntityManagerSetupImpl getSetupImpl()
        INTERNAL: Return the EntityManagerSetupImpl associated with this factory
        Returns:
      • getServerSession

        public org.eclipse.persistence.sessions.server.ServerSession getServerSession()
        INTERNAL: Returns the ServerSession that the Factory will be using and initializes it if it is not available. This method makes use of the partially constructed session stored in our setupImpl and completes its construction TODO: should throw IllegalStateException if not ServerSession
        Specified by:
        getServerSession in interface JpaEntityManagerFactory
      • getSessionBroker

        public org.eclipse.persistence.sessions.broker.SessionBroker getSessionBroker()
        INTERNAL: Returns the SessionBroker that the Factory will be using and initializes it if it is not available. This method makes use of the partially constructed session stored in our setupImpl and completes its construction TODO: should throw IllegalStateException if not SessionBroker
        Specified by:
        getSessionBroker in interface JpaEntityManagerFactory
      • close

        public void close()
        Closes this factory, releasing any resources that might be held by this factory. After invoking this method, all methods on the instance will throw an IllegalStateException, except for isOpen, which will return false.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface javax.persistence.EntityManagerFactory
      • isOpen

        public boolean isOpen()
        Indicates whether or not this factory is open. Returns true until a call to close() is made.
        Specified by:
        isOpen in interface javax.persistence.EntityManagerFactory
      • createEntityManager

        public javax.persistence.EntityManager createEntityManager()
        PUBLIC: Returns an EntityManager for this deployment.
        Specified by:
        createEntityManager in interface javax.persistence.EntityManagerFactory
      • createEntityManager

        public javax.persistence.EntityManager createEntityManager​(java.util.Map properties)
        PUBLIC: Returns an EntityManager for this deployment.
        Specified by:
        createEntityManager in interface javax.persistence.EntityManagerFactory
      • createEntityManager

        public javax.persistence.EntityManager createEntityManager​(javax.persistence.SynchronizationType synchronizationType,
                                                                   java.util.Map map)
        Specified by:
        createEntityManager in interface javax.persistence.EntityManagerFactory
      • createEntityManager

        public javax.persistence.EntityManager createEntityManager​(javax.persistence.SynchronizationType synchronizationType)
        Specified by:
        createEntityManager in interface javax.persistence.EntityManagerFactory
      • createEntityManagerImpl

        protected EntityManagerImpl createEntityManagerImpl​(java.util.Map properties,
                                                            javax.persistence.SynchronizationType syncType)
      • unwrap

        public EntityManagerFactoryDelegate unwrap()
        Gets the underlying implementation of the EntityManagerFactory. This method will return a version of EntityManagerFactory that is based on the available metadata at the time it is called. Future calls to refresh will not affect that metadata on this EntityManagerFactory.
        Specified by:
        unwrap in interface JpaEntityManagerFactory
        Returns:
      • verifyOpen

        protected void verifyOpen()
      • finalize

        protected void finalize()
                         throws java.lang.Throwable
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable
      • getProperty

        public java.lang.Object getProperty​(java.lang.String name)
        The method return user defined property passed in from EntityManagerFactory.
      • processProperties

        protected void processProperties​(java.util.Map properties)
        Process all EntityManager properties. This allows all EntityManager properties specified in the persistence.xml, factory properties, or System properties to be preprocessed. This save the cost of processing these properties each time an EntityManager is created, which can add considerable overhead to both performance and concurrency as System properties are a Hashtable and synchronized. ATTENTION: If you add a new property to be processed in this method please also add the property's name to PersistenceUnitProperties.supportedNonServerSessionProperties
      • refreshMetadata

        public void refreshMetadata​(java.util.Map properties)
        ADVANCED: Re-bootstrap this factory. This method will rebuild the EntityManagerFactory. It should be used in conjunction with a MetadataSource to allow mappings to be changed in a running system. All existing EntityMangers will continue to function with the old metadata, but new factories will use the new metadata. This call will throw an exception when called on EntityManagerFactoryImplDelegate
        Specified by:
        refreshMetadata in interface JpaEntityManagerFactory
        Parameters:
        properties -
      • getBeginEarlyTransaction

        public boolean getBeginEarlyTransaction()
        Return default join existing transaction property, allows reading through write connection.
      • setBeginEarlyTransaction

        public void setBeginEarlyTransaction​(boolean beginEarlyTransaction)
        Set default join existing transaction property, allows reading through write connection.
      • getFlushMode

        public javax.persistence.FlushModeType getFlushMode()
        Return default property, allows flush before query to be avoided.
      • setFlushMode

        public void setFlushMode​(javax.persistence.FlushModeType flushMode)
        Set default property, allows flush before query to be avoided.
      • getReferenceMode

        public org.eclipse.persistence.config.ReferenceMode getReferenceMode()
        Return default property, allows weak unit of work references.
      • setReferenceMode

        public void setReferenceMode​(org.eclipse.persistence.config.ReferenceMode referenceMode)
        Set default property, allows weak unit of work references.
      • getCloseOnCommit

        public boolean getCloseOnCommit()
        Return default property to avoid resuming unit of work if going to be closed on commit anyway.
      • setCloseOnCommit

        public void setCloseOnCommit​(boolean closeOnCommit)
        Set default property to avoid resuming unit of work if going to be closed on commit anyway.
      • getPersistOnCommit

        public boolean getPersistOnCommit()
        Return default property to avoid discover new objects in unit of work if application always uses persist.
      • getPersistenceUnitUtil

        public javax.persistence.PersistenceUnitUtil getPersistenceUnitUtil()
        Return interface providing access to utility methods for the persistence unit.
        Specified by:
        getPersistenceUnitUtil in interface javax.persistence.EntityManagerFactory
        Returns:
        PersistenceUnitUtil interface
        Throws:
        java.lang.IllegalStateException - if the entity manager factory has been closed.
      • setPersistOnCommit

        public void setPersistOnCommit​(boolean persistOnCommit)
        Set default property to avoid discover new objects in unit of work if application always uses persist.
      • getCommitWithoutPersistRules

        public boolean getCommitWithoutPersistRules()
        Return default property to avoid discover new objects in unit of work if application always uses persist.
      • setCommitWithoutPersistRules

        public void setCommitWithoutPersistRules​(boolean commitWithoutPersistRules)
        Set default property to avoid discover new objects in unit of work if application always uses persist.
      • getFlushClearCache

        public java.lang.String getFlushClearCache()
        Return the default FlashClearCache mode to be used. Relevant only in case call to flush method followed by call to clear method.
        See Also:
        FlushClearCache
      • setFlushClearCache

        public void setFlushClearCache​(java.lang.String flushClearCache)
        Set the default FlashClearCache mode to be used. Relevant only in case call to flush method followed by call to clear method.
        See Also:
        FlushClearCache
      • shouldValidateExistence

        public boolean shouldValidateExistence()
        Return the default to determine if does-exist should be performed on persist.
      • setShouldValidateExistence

        public void setShouldValidateExistence​(boolean shouldValidateExistence)
        Set the default to determine if does-exist should be performed on persist.
      • getCache

        public javax.persistence.Cache getCache()
        Access the cache that is associated with the entity manager factory (the "second level cache").
        Specified by:
        getCache in interface javax.persistence.EntityManagerFactory
        Returns:
        instance of the Cache interface
        Throws:
        java.lang.IllegalStateException - if the entity manager factory has been closed
        Since:
        Java Persistence 2.0
        See Also:
        EntityManagerFactory.getCache()
      • getProperties

        public java.util.Map<java.lang.String,​java.lang.Object> getProperties()
        Specified by:
        getProperties in interface javax.persistence.EntityManagerFactory
        Since:
        Java Persistence API 2.0
        See Also:
        EntityManagerFactory.getProperties()
      • getCriteriaBuilder

        public javax.persistence.criteria.CriteriaBuilder getCriteriaBuilder()
        Specified by:
        getCriteriaBuilder in interface javax.persistence.EntityManagerFactory
        Since:
        Java Persistence 2.0
        See Also:
        EntityManagerFactory.getCriteriaBuilder()
      • 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.EntityManagerFactory
        Returns:
        Metamodel instance
        Throws:
        java.lang.IllegalStateException - if the entity manager factory has been closed.
        Since:
        Java Persistence 2.0
        See Also:
        EntityManagerFactory.getMetamodel()
      • getOwner

        public JpaEntityManagerFactory getOwner()
        INTERNAL: Get the EntityManagerFactoryImpl that created this
        Returns:
      • setMetamodel

        public void setMetamodel​(javax.persistence.metamodel.Metamodel aMetamodel)
        INTERNAL: Convenience function to allow us to reset the Metamodel in the possible case that we want to regenerate it. This function is outside of the JPA 2.0 specification.
        Parameters:
        aMetamodel -
        Since:
        Java Persistence 2.0
      • isLoaded

        public boolean isLoaded​(java.lang.Object entity,
                                java.lang.String attributeName)
        Determine the load state of a given persistent attribute of an entity belonging to the persistence unit.
        Specified by:
        isLoaded in interface javax.persistence.PersistenceUnitUtil
        Specified by:
        isLoaded in interface javax.persistence.PersistenceUtil
        Parameters:
        entity - containing the attribute
        attributeName - name of attribute whose load state is to be determined
        Returns:
        false if entity's state has not been loaded or if the attribute state has not been loaded, otherwise true
      • isLoaded

        public boolean isLoaded​(java.lang.Object entity)
        Determine the load state of an entity belonging to the persistence unit. This method can be used to determine the load state of an entity passed as a reference. An entity is considered loaded if all attributes for which FetchType EAGER has been specified have been loaded. The isLoaded(Object, String) method should be used to determine the load state of an attribute. Not doing so might lead to unintended loading of state.
        Specified by:
        isLoaded in interface javax.persistence.PersistenceUnitUtil
        Specified by:
        isLoaded in interface javax.persistence.PersistenceUtil
        Parameters:
        entity - whose load state is to be determined
        Returns:
        false if the entity has not been loaded, else true.
      • getIdentifier

        public java.lang.Object getIdentifier​(java.lang.Object entity)
        Returns the id of the entity. A generated id is not guaranteed to be available until after the database insert has occurred. Returns null if the entity does not yet have an id
        Specified by:
        getIdentifier in interface javax.persistence.PersistenceUnitUtil
        Parameters:
        entity -
        Returns:
        id of the entity
        Throws:
        java.lang.IllegalArgumentException - if the entity is found not to be an entity.
      • getCommitOrder

        public org.eclipse.persistence.sessions.UnitOfWork.CommitOrderType getCommitOrder()
        Return if updates should be ordered by primary key, to avoid potential database deadlocks.
      • setCommitOrder

        public void setCommitOrder​(org.eclipse.persistence.sessions.UnitOfWork.CommitOrderType commitOrder)
        Set update ordering by primary key, to avoid potential database deadlocks.
      • addNamedQuery

        public void addNamedQuery​(java.lang.String name,
                                  javax.persistence.Query query)
        Specified by:
        addNamedQuery in interface javax.persistence.EntityManagerFactory
      • unwrap

        public <T> T unwrap​(java.lang.Class<T> cls)
        Specified by:
        unwrap in interface javax.persistence.EntityManagerFactory
      • addNamedEntityGraph

        public <T> void addNamedEntityGraph​(java.lang.String graphName,
                                            javax.persistence.EntityGraph<T> entityGraph)
        Specified by:
        addNamedEntityGraph in interface javax.persistence.EntityManagerFactory