Module org.eclipse.persistence.jpa
Class EntityManagerFactoryImpl
- java.lang.Object
-
- org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl
-
- All Implemented Interfaces:
jakarta.persistence.EntityManagerFactory,jakarta.persistence.PersistenceUnitUtil,jakarta.persistence.PersistenceUtil,AutoCloseable,JpaEntityManagerFactory
public class EntityManagerFactoryImpl extends Object implements jakarta.persistence.EntityManagerFactory, jakarta.persistence.PersistenceUnitUtil, JpaEntityManagerFactory
Wraps our implementation of EntityManagerFactory Most operations are forwarded to the delegate. This wrapper is used to enable the refreshMetadata functionality which allows you to switch the underlying metadata for an EMF after deploy time.- Author:
- tware
-
-
Field Summary
Fields Modifier and Type Field Description protected EntityManagerFactoryDelegatedelegate
-
Constructor Summary
Constructors Constructor Description EntityManagerFactoryImpl(String persistenceUnitName, Map<String,Object> properties, List<ClassDescriptor> descriptors)Create a dynamic persistence unit which does not use the persistence.xml.EntityManagerFactoryImpl(EntityManagerSetupImpl setupImpl, Map properties)EntityManagerFactoryImpl(AbstractSession serverSession)Will return an instance of the Factory.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> voidaddNamedEntityGraph(String graphName, jakarta.persistence.EntityGraph<T> entityGraph)voidaddNamedQuery(String name, jakarta.persistence.Query query)voidclose()Closes this factory, releasing any resources that might be held by this factory.jakarta.persistence.EntityManagercreateEntityManager()PUBLIC: Returns an EntityManager for this deployment.jakarta.persistence.EntityManagercreateEntityManager(jakarta.persistence.SynchronizationType synchronizationType)jakarta.persistence.EntityManagercreateEntityManager(jakarta.persistence.SynchronizationType synchronizationType, Map map)jakarta.persistence.EntityManagercreateEntityManager(Map properties)PUBLIC: Returns an EntityManager for this deployment.protected EntityManagerImplcreateEntityManagerImpl(Map properties, jakarta.persistence.SynchronizationType syncType)booleangetBeginEarlyTransaction()Return default join existing transaction property, allows reading through write connection.jakarta.persistence.CachegetCache()Access the cache that is associated with the entity manager factory (the "second level cache").booleangetCloseOnCommit()Return default property to avoid resuming unit of work if going to be closed on commit anyway.UnitOfWork.CommitOrderTypegetCommitOrder()Return if updates should be ordered by primary key to avoid possible database deadlocks.booleangetCommitWithoutPersistRules()Return default property to avoid discover new objects in unit of work if application always uses persist.jakarta.persistence.criteria.CriteriaBuildergetCriteriaBuilder()DatabaseSessionImplgetDatabaseSession()Returns the DatabaseSession that the Factory will be using and initializes it if it is not available.StringgetFlushClearCache()Return the default FlashClearCache mode to be used.jakarta.persistence.FlushModeTypegetFlushMode()Return default property, allows flush before query to be avoided.ObjectgetIdentifier(Object entity)Returns the id of the entity.static ObjectgetIdentifier(Object entity, AbstractSession session)Returns the id of the entity.jakarta.persistence.metamodel.MetamodelgetMetamodel()Return an instance of Metamodel interface for access to the metamodel of the persistence unit.jakarta.persistence.PersistenceUnitUtilgetPersistenceUnitUtil()Return interface providing access to utility methods for the persistence unit.booleangetPersistOnCommit()Return default property to avoid discover new objects in unit of work if application always uses persist.Map<String,Object>getProperties()ObjectgetProperty(String name)The method return user defined property passed in from EntityManagerFactory.ReferenceModegetReferenceMode()Return default property, allows weak unit of work references.ServerSessiongetServerSession()INTERNAL: Returns the ServerSession that the Factory will be using and initializes it if it is not available.SessionBrokergetSessionBroker()INTERNAL: Returns the SessionBroker that the Factory will be using and initializes it if it is not available.booleanisLoaded(Object entity)Determine the load state of an entity belonging to the persistence unit.booleanisLoaded(Object entity, String attributeName)Determine the load state of a given persistent attribute of an entity belonging to the persistence unit.static BooleanisLoaded(Object entity, String attributeName, AbstractSession session)Determine the load state of a given persistent attribute of an entity belonging to the persistence unit.static booleanisLoaded(Object entity, String attributeName, DatabaseMapping mapping)Check whether a named attribute on a given entity with a given mapping has been loaded.static BooleanisLoaded(Object entity, AbstractSession session)Determine the load state of an entity belonging to the persistence unit.booleanisOpen()Indicates whether or not this factory is open.voidrefreshMetadata(Map<String,Object> properties)ADVANCED: Re-bootstrap this factory.voidsetBeginEarlyTransaction(boolean beginEarlyTransaction)Set default join existing transaction property, allows reading through write connection.voidsetCloseOnCommit(boolean closeOnCommit)Set default property to avoid resuming unit of work if going to be closed on commit anyway.voidsetCommitOrder(UnitOfWork.CommitOrderType commitOrder)Set updates should be ordered by primary key to avoid possible database deadlocks.voidsetCommitWithoutPersistRules(boolean commitWithoutPersistRules)Set default property to avoid discover new objects in unit of work if application always uses persist.voidsetFlushClearCache(String flushClearCache)Set the default FlashClearCache mode to be used.voidsetFlushMode(jakarta.persistence.FlushModeType flushMode)Set default property, allows flush before query to be avoided.voidsetMetamodel(jakarta.persistence.metamodel.Metamodel aMetamodel)INTERNAL: Convenience function to allow us to reset the Metamodel in the possible case that we want to regenerate it.voidsetPersistOnCommit(boolean persistOnCommit)Set default property to avoid discover new objects in unit of work if application always uses persist.voidsetReferenceMode(ReferenceMode referenceMode)Set default property, allows weak unit of work references.voidsetShouldValidateExistence(boolean shouldValidateExistence)Set the default to determine if does-exist should be performed on persist.booleanshouldValidateExistence()Return the default to determine if does-exist should be performed on persist.EntityManagerFactoryDelegateunwrap()Gets the underlying implementation of the EntityManagerFactory.<T> Tunwrap(Class<T> cls)protected voidverifyOpen()
-
-
-
Field Detail
-
delegate
protected EntityManagerFactoryDelegate delegate
-
-
Constructor Detail
-
EntityManagerFactoryImpl
public EntityManagerFactoryImpl(AbstractSession serverSession)
Will return an instance of the Factory. Should only be called by EclipseLink.
-
EntityManagerFactoryImpl
public EntityManagerFactoryImpl(EntityManagerSetupImpl setupImpl, Map properties)
-
EntityManagerFactoryImpl
public EntityManagerFactoryImpl(String persistenceUnitName, Map<String,Object> properties, List<ClassDescriptor> descriptors)
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
-
getIdentifier
public static Object getIdentifier(Object entity, AbstractSession session)
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- Returns:
- id of the entity
- Throws:
IllegalArgumentException- if the entity is found not to be an entity.
-
isLoaded
public static Boolean isLoaded(Object entity, AbstractSession session)
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.- Parameters:
entity- whose load state is to be determined- Returns:
- false if the entity has not been loaded, else true.
-
isLoaded
public static Boolean isLoaded(Object entity, String attributeName, AbstractSession session)
Determine the load state of a given persistent attribute of an entity belonging to the persistence unit.- Parameters:
entity- containing the attributeattributeName- 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 static boolean isLoaded(Object entity, String attributeName, DatabaseMapping mapping)
Check whether a named attribute on a given entity with a given mapping has been loaded. This method will check the valueholder or indirect collection for LAZY ForeignReferenceMappings to see if has been instantiated and otherwise check the fetch group.
-
refreshMetadata
public void refreshMetadata(Map<String,Object> 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.- Specified by:
refreshMetadatain interfaceJpaEntityManagerFactory
-
getSessionBroker
public 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:
getSessionBrokerin interfaceJpaEntityManagerFactory
-
getServerSession
public 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- Specified by:
getServerSessionin interfaceJpaEntityManagerFactory
-
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 anIllegalStateException, except forisOpen(), which will returnfalse.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfacejakarta.persistence.EntityManagerFactory
-
isOpen
public boolean isOpen()
Indicates whether or not this factory is open. Returnstrueuntil a call toclose()is made.- Specified by:
isOpenin interfacejakarta.persistence.EntityManagerFactory
-
createEntityManager
public jakarta.persistence.EntityManager createEntityManager()
PUBLIC: Returns an EntityManager for this deployment.- Specified by:
createEntityManagerin interfacejakarta.persistence.EntityManagerFactory
-
createEntityManager
public jakarta.persistence.EntityManager createEntityManager(Map properties)
PUBLIC: Returns an EntityManager for this deployment.- Specified by:
createEntityManagerin interfacejakarta.persistence.EntityManagerFactory
-
createEntityManager
public jakarta.persistence.EntityManager createEntityManager(jakarta.persistence.SynchronizationType synchronizationType)
- Specified by:
createEntityManagerin interfacejakarta.persistence.EntityManagerFactory
-
createEntityManager
public jakarta.persistence.EntityManager createEntityManager(jakarta.persistence.SynchronizationType synchronizationType, Map map)- Specified by:
createEntityManagerin interfacejakarta.persistence.EntityManagerFactory
-
createEntityManagerImpl
protected EntityManagerImpl createEntityManagerImpl(Map properties, jakarta.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:
unwrapin interfaceJpaEntityManagerFactory
-
verifyOpen
protected void verifyOpen()
-
getProperty
public Object getProperty(String name)
The method return user defined property passed in from EntityManagerFactory.
-
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 jakarta.persistence.FlushModeType getFlushMode()
Return default property, allows flush before query to be avoided.
-
setFlushMode
public void setFlushMode(jakarta.persistence.FlushModeType flushMode)
Set default property, allows flush before query to be avoided.
-
getReferenceMode
public ReferenceMode getReferenceMode()
Return default property, allows weak unit of work references.
-
setReferenceMode
public void setReferenceMode(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 jakarta.persistence.PersistenceUnitUtil getPersistenceUnitUtil()
Return interface providing access to utility methods for the persistence unit.- Specified by:
getPersistenceUnitUtilin interfacejakarta.persistence.EntityManagerFactory- Returns:
- PersistenceUnitUtil interface
- Throws:
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 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(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 jakarta.persistence.Cache getCache()
Access the cache that is associated with the entity manager factory (the "second level cache").- Specified by:
getCachein interfacejakarta.persistence.EntityManagerFactory- Returns:
- instance of the
Cacheinterface - Throws:
IllegalStateException- if the entity manager factory has been closed- Since:
- Java Persistence 2.0
- See Also:
EntityManagerFactory.getCache()
-
getProperties
public Map<String,Object> getProperties()
- Specified by:
getPropertiesin interfacejakarta.persistence.EntityManagerFactory- Since:
- Java Persistence API 2.0
- See Also:
EntityManagerFactory.getProperties()
-
getDatabaseSession
public DatabaseSessionImpl getDatabaseSession()
Description copied from interface:JpaEntityManagerFactoryReturns the DatabaseSession that the Factory will be using and initializes it if it is not available.- Specified by:
getDatabaseSessionin interfaceJpaEntityManagerFactory
-
getCriteriaBuilder
public jakarta.persistence.criteria.CriteriaBuilder getCriteriaBuilder()
- Specified by:
getCriteriaBuilderin interfacejakarta.persistence.EntityManagerFactory- Since:
- Java Persistence 2.0
- See Also:
EntityManagerFactory.getCriteriaBuilder()
-
getMetamodel
public jakarta.persistence.metamodel.Metamodel getMetamodel()
Return an instance of Metamodel interface for access to the metamodel of the persistence unit.- Specified by:
getMetamodelin interfacejakarta.persistence.EntityManagerFactory- Returns:
- Metamodel instance
- Throws:
IllegalStateException- if the entity manager factory has been closed.- Since:
- Java Persistence 2.0
- See Also:
EntityManagerFactory.getMetamodel()
-
setMetamodel
public void setMetamodel(jakarta.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.- Since:
- Java Persistence 2.0
-
isLoaded
public boolean isLoaded(Object entity, String attributeName)
Determine the load state of a given persistent attribute of an entity belonging to the persistence unit.- Specified by:
isLoadedin interfacejakarta.persistence.PersistenceUnitUtil- Specified by:
isLoadedin interfacejakarta.persistence.PersistenceUtil- Parameters:
entity- containing the attributeattributeName- 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(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:
isLoadedin interfacejakarta.persistence.PersistenceUnitUtil- Specified by:
isLoadedin interfacejakarta.persistence.PersistenceUtil- Parameters:
entity- whose load state is to be determined- Returns:
- false if the entity has not been loaded, else true.
-
getIdentifier
public Object getIdentifier(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:
getIdentifierin interfacejakarta.persistence.PersistenceUnitUtil- Returns:
- id of the entity
- Throws:
IllegalStateException- if the entity is found not to be an entity.
-
getCommitOrder
public UnitOfWork.CommitOrderType getCommitOrder()
Return if updates should be ordered by primary key to avoid possible database deadlocks.
-
setCommitOrder
public void setCommitOrder(UnitOfWork.CommitOrderType commitOrder)
Set updates should be ordered by primary key to avoid possible database deadlocks.
-
addNamedQuery
public void addNamedQuery(String name, jakarta.persistence.Query query)
- Specified by:
addNamedQueryin interfacejakarta.persistence.EntityManagerFactory
-
unwrap
public <T> T unwrap(Class<T> cls)
- Specified by:
unwrapin interfacejakarta.persistence.EntityManagerFactory
-
addNamedEntityGraph
public <T> void addNamedEntityGraph(String graphName, jakarta.persistence.EntityGraph<T> entityGraph)
- Specified by:
addNamedEntityGraphin interfacejakarta.persistence.EntityManagerFactory
-
-