Package org.datanucleus.api.jakarta
Class JakartaEntityManagerFactory
- java.lang.Object
-
- org.datanucleus.api.jakarta.JakartaEntityManagerFactory
-
- All Implemented Interfaces:
jakarta.persistence.EntityManagerFactory,jakarta.persistence.PersistenceUnitUtil,jakarta.persistence.PersistenceUtil,Serializable,AutoCloseable,JakartaEntityGraphRegistrationListener
public class JakartaEntityManagerFactory extends Object implements jakarta.persistence.EntityManagerFactory, jakarta.persistence.PersistenceUnitUtil, JakartaEntityGraphRegistrationListener, Serializable
EntityManagerFactory implementation. Caches the "persistence-unit" MetaData information when encountered, in JavaSE mode.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static org.datanucleus.util.NucleusLoggerLOGGERLogger for enhancing.
-
Constructor Summary
Constructors Constructor Description JakartaEntityManagerFactory(jakarta.persistence.spi.PersistenceUnitInfo unitInfo, Map overridingProps)Constructor when working in a JavaEE environment.JakartaEntityManagerFactory(String unitName, Map overridingProps)Constructor when working in a JavaSE environment.JakartaEntityManagerFactory(org.datanucleus.metadata.PersistenceUnitMetaData pumd, Map overridingProps)Convenience constructor to allow for dynamic persistence-unit creation in JavaSE.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> voidaddNamedEntityGraph(String graphName, jakarta.persistence.EntityGraph<T> graph)voidaddNamedQuery(String name, jakarta.persistence.Query query)Method to save the specified query under the provided name, so it can be used as a named query.protected voidassertIsClosed()voidclose()Method to close the factory.jakarta.persistence.EntityManagercreateEntityManager()Method to create an (application-managed) entity manager.jakarta.persistence.EntityManagercreateEntityManager(jakarta.persistence.SynchronizationType syncType)Create a new JTA application-managed EntityManager with the specified synchronization type.jakarta.persistence.EntityManagercreateEntityManager(jakarta.persistence.SynchronizationType syncType, Map overridingProps)Create a new JTA application-managed EntityManager with the specified synchronization type and Map of properties.jakarta.persistence.EntityManagercreateEntityManager(Map overridingProps)Method to create an (application-managed) entity manager with the specified properties.voidderegisterEntityGraph(String graphName)voidentityGraphRegistered(JakartaEntityGraph eg)jakarta.persistence.CachegetCache()Accessor for the second level cache.jakarta.persistence.criteria.CriteriaBuildergetCriteriaBuilder()StringgetDefinedEntityGraphName()Set<String>getEntityGraphNames()<T> List<jakarta.persistence.EntityGraph<? super T>>getEntityGraphsByType(Class<T> entityClass)ObjectgetIdentifier(Object entity)jakarta.persistence.metamodel.MetamodelgetMetamodel()StringgetName()jakarta.persistence.EntityGraphgetNamedEntityGraph(String graphName)org.datanucleus.NucleusContextgetNucleusContext()jakarta.persistence.PersistenceUnitUtilgetPersistenceUnitUtil()Map<String,Object>getProperties()Get the properties and associated values that are in effect for the entity manager factory.JakartaQueryCachegetQueryCache()Accessor for the query results cache.org.datanucleus.store.query.cache.QueryDatastoreCompilationCachegetQueryDatastoreCompilationCache()Accessor for the query datastore compilation cache.org.datanucleus.store.query.cache.QueryCompilationCachegetQueryGenericCompilationCache()Accessor for the query generic compilation cache.Set<String>getSupportedProperties()Get the names of the properties that are supported for use with the entity manager factory.protected org.datanucleus.PersistenceNucleusContextinitialiseNucleusContext(org.datanucleus.metadata.PersistenceUnitMetaData unitMetaData, Map overridingProps, org.datanucleus.plugin.PluginManager pluginMgr)Method to initialise a PersistenceManagerFactory that will control the persistence.booleanisContainerManaged()Accessor for whether the EMF is managed by a container (JavaEE).booleanisLoaded(Object entity)booleanisLoaded(Object entity, String attrName)booleanisOpen()Accessor for whether the factory is openprotected jakarta.persistence.EntityManagernewEntityManager(org.datanucleus.PersistenceNucleusContext nucleusCtx, jakarta.persistence.PersistenceContextType contextType, jakarta.persistence.SynchronizationType syncType)Creates anEntityManager.voidregisterEntityGraph(JakartaEntityGraph eg, String graphName)<T> Tunwrap(Class<T> cls)Return an object of the specified type to allow access to the provider-specific API.
-
-
-
Constructor Detail
-
JakartaEntityManagerFactory
public JakartaEntityManagerFactory(jakarta.persistence.spi.PersistenceUnitInfo unitInfo, Map overridingProps)Constructor when working in a JavaEE environment.- Parameters:
unitInfo- The "persistent-unit" infooverridingProps- factory properties overriding those in the "persistence-unit"
-
JakartaEntityManagerFactory
public JakartaEntityManagerFactory(org.datanucleus.metadata.PersistenceUnitMetaData pumd, Map overridingProps)Convenience constructor to allow for dynamic persistence-unit creation in JavaSE.- Parameters:
pumd- Persistence unit metadataoverridingProps- Properties overriding those defined for this unit
-
-
Method Detail
-
getNucleusContext
public org.datanucleus.NucleusContext getNucleusContext()
-
isContainerManaged
public boolean isContainerManaged()
Accessor for whether the EMF is managed by a container (JavaEE).- Returns:
- Whether managed by a container
-
getName
public String getName()
-
close
public void close()
Method to close the factory.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfacejakarta.persistence.EntityManagerFactory
-
isOpen
public boolean isOpen()
Accessor for whether the factory is open- Specified by:
isOpenin interfacejakarta.persistence.EntityManagerFactory- Returns:
- Whether it is open
-
getQueryCache
public JakartaQueryCache getQueryCache()
Accessor for the query results cache.- Returns:
- Query results cache
-
getQueryGenericCompilationCache
public org.datanucleus.store.query.cache.QueryCompilationCache getQueryGenericCompilationCache()
Accessor for the query generic compilation cache.- Returns:
- Query generic compilation cache
-
getQueryDatastoreCompilationCache
public org.datanucleus.store.query.cache.QueryDatastoreCompilationCache getQueryDatastoreCompilationCache()
Accessor for the query datastore compilation cache.- Returns:
- Query datastore compilation cache
-
addNamedQuery
public void addNamedQuery(String name, jakarta.persistence.Query query)
Method to save the specified query under the provided name, so it can be used as a named query. If there is already a named query of this name it is overwritten.- Specified by:
addNamedQueryin interfacejakarta.persistence.EntityManagerFactory- Parameters:
query- The query whose definition we save as named
-
createEntityManager
public jakarta.persistence.EntityManager createEntityManager()
Method to create an (application-managed) entity manager.- Specified by:
createEntityManagerin interfacejakarta.persistence.EntityManagerFactory- Returns:
- The Entity Manager
-
createEntityManager
public jakarta.persistence.EntityManager createEntityManager(Map overridingProps)
Method to create an (application-managed) entity manager with the specified properties. This creates a new underlying context since each EMF is locked when created to stop config changes.- Specified by:
createEntityManagerin interfacejakarta.persistence.EntityManagerFactory- Parameters:
overridingProps- Properties to use for this manager- Returns:
- The Entity Manager
-
createEntityManager
public jakarta.persistence.EntityManager createEntityManager(jakarta.persistence.SynchronizationType syncType)
Create a new JTA application-managed EntityManager with the specified synchronization type. This method returns a new EntityManager instance each time it is invoked. The isOpen method will return true on the returned instance.- Specified by:
createEntityManagerin interfacejakarta.persistence.EntityManagerFactory- Parameters:
syncType- how and when the entity manager should be synchronized with the current JTA transaction- Returns:
- entity manager instance
- Throws:
IllegalStateException- if the entity manager factory has been configured for resource-local entity managers or has been closed
-
createEntityManager
public jakarta.persistence.EntityManager createEntityManager(jakarta.persistence.SynchronizationType syncType, Map overridingProps)Create a new JTA application-managed EntityManager with the specified synchronization type and Map of properties. This method returns a new EntityManager instance each time it is invoked. The isOpen method will return true on the returned instance.- Specified by:
createEntityManagerin interfacejakarta.persistence.EntityManagerFactory- Parameters:
syncType- how and when the entity manager should be synchronized with the current JTA transactionoverridingProps- properties for entity manager; may be null- Returns:
- entity manager instance
- Throws:
IllegalStateException- if the entity manager factory has been configured for resource-local entity managers or has been closed
-
newEntityManager
protected jakarta.persistence.EntityManager newEntityManager(org.datanucleus.PersistenceNucleusContext nucleusCtx, jakarta.persistence.PersistenceContextType contextType, jakarta.persistence.SynchronizationType syncType)Creates anEntityManager. Override if you want to return a different type that implements this interface.- Parameters:
nucleusCtx- Nucleus ContextcontextType- The persistence context typesyncType- Synchronization type- Returns:
- The EntityManager
-
initialiseNucleusContext
protected org.datanucleus.PersistenceNucleusContext initialiseNucleusContext(org.datanucleus.metadata.PersistenceUnitMetaData unitMetaData, Map overridingProps, org.datanucleus.plugin.PluginManager pluginMgr)Method to initialise a PersistenceManagerFactory that will control the persistence. If the unitMetaData is null will simply create a default context without initialising any MetaData etc. If there is a unitMetaData then all metadata for that unit will be loaded/initialised.- Parameters:
unitMetaData- The "persistence-unit" metadata (if any)overridingProps- Properties to override all otherspluginMgr- Plugin Manager- Returns:
- The PersistenceManagerFactory
-
getProperties
public Map<String,Object> getProperties()
Get the properties and associated values that are in effect for the entity manager factory. Changing the contents of the map does not change the configuration in effect.- Specified by:
getPropertiesin interfacejakarta.persistence.EntityManagerFactory- Returns:
- properties
-
getSupportedProperties
public Set<String> getSupportedProperties()
Get the names of the properties that are supported for use with the entity manager factory. These correspond to properties that may be passed to the methods of the EntityManagerFactory interface that take a properties argument. These include all standard properties as well as vendor-specific properties supported by the provider. These properties may or may not currently be in effect.- Returns:
- properties and hints
-
assertIsClosed
protected void assertIsClosed()
-
getCache
public jakarta.persistence.Cache getCache()
Accessor for the second level cache.- Specified by:
getCachein interfacejakarta.persistence.EntityManagerFactory- Returns:
- Level 2 cache
-
getMetamodel
public jakarta.persistence.metamodel.Metamodel getMetamodel()
- Specified by:
getMetamodelin interfacejakarta.persistence.EntityManagerFactory
-
getCriteriaBuilder
public jakarta.persistence.criteria.CriteriaBuilder getCriteriaBuilder()
- Specified by:
getCriteriaBuilderin interfacejakarta.persistence.EntityManagerFactory
-
getPersistenceUnitUtil
public jakarta.persistence.PersistenceUnitUtil getPersistenceUnitUtil()
- Specified by:
getPersistenceUnitUtilin interfacejakarta.persistence.EntityManagerFactory
-
getIdentifier
public Object getIdentifier(Object entity)
- Specified by:
getIdentifierin interfacejakarta.persistence.PersistenceUnitUtil
-
isLoaded
public boolean isLoaded(Object entity, String attrName)
- Specified by:
isLoadedin interfacejakarta.persistence.PersistenceUnitUtil- Specified by:
isLoadedin interfacejakarta.persistence.PersistenceUtil
-
isLoaded
public boolean isLoaded(Object entity)
- Specified by:
isLoadedin interfacejakarta.persistence.PersistenceUnitUtil- Specified by:
isLoadedin interfacejakarta.persistence.PersistenceUtil
-
unwrap
public <T> T unwrap(Class<T> cls)
Return an object of the specified type to allow access to the provider-specific API. If the provider's EntityManagerFactory implementation does not support the specified class, the PersistenceException is thrown.- Specified by:
unwrapin interfacejakarta.persistence.EntityManagerFactory- Parameters:
cls- the class of the object to be returned. This is normally either the underlying EntityManagerFactory implementation class or an interface that it implements.- Returns:
- an instance of the specified class
- Throws:
jakarta.persistence.PersistenceException- if the provider does not support the call.
-
getNamedEntityGraph
public jakarta.persistence.EntityGraph getNamedEntityGraph(String graphName)
-
getEntityGraphsByType
public <T> List<jakarta.persistence.EntityGraph<? super T>> getEntityGraphsByType(Class<T> entityClass)
-
addNamedEntityGraph
public <T> void addNamedEntityGraph(String graphName, jakarta.persistence.EntityGraph<T> graph)
- Specified by:
addNamedEntityGraphin interfacejakarta.persistence.EntityManagerFactory
-
registerEntityGraph
public void registerEntityGraph(JakartaEntityGraph eg, String graphName)
-
deregisterEntityGraph
public void deregisterEntityGraph(String graphName)
-
getDefinedEntityGraphName
public String getDefinedEntityGraphName()
-
entityGraphRegistered
public void entityGraphRegistered(JakartaEntityGraph eg)
- Specified by:
entityGraphRegisteredin interfaceJakartaEntityGraphRegistrationListener
-
-