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.NucleusLogger
LOGGER
Logger 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> void
addNamedEntityGraph(String graphName, jakarta.persistence.EntityGraph<T> graph)
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.protected void
assertIsClosed()
void
close()
Method to close the factory.jakarta.persistence.EntityManager
createEntityManager()
Method to create an (application-managed) entity manager.jakarta.persistence.EntityManager
createEntityManager(jakarta.persistence.SynchronizationType syncType)
Create a new JTA application-managed EntityManager with the specified synchronization type.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.jakarta.persistence.EntityManager
createEntityManager(Map overridingProps)
Method to create an (application-managed) entity manager with the specified properties.void
deregisterEntityGraph(String graphName)
void
entityGraphRegistered(JakartaEntityGraph eg)
jakarta.persistence.Cache
getCache()
Accessor for the second level cache.jakarta.persistence.criteria.CriteriaBuilder
getCriteriaBuilder()
String
getDefinedEntityGraphName()
Set<String>
getEntityGraphNames()
<T> List<jakarta.persistence.EntityGraph<? super T>>
getEntityGraphsByType(Class<T> entityClass)
Object
getIdentifier(Object entity)
jakarta.persistence.metamodel.Metamodel
getMetamodel()
String
getName()
jakarta.persistence.EntityGraph
getNamedEntityGraph(String graphName)
org.datanucleus.NucleusContext
getNucleusContext()
jakarta.persistence.PersistenceUnitUtil
getPersistenceUnitUtil()
Map<String,Object>
getProperties()
Get the properties and associated values that are in effect for the entity manager factory.JakartaQueryCache
getQueryCache()
Accessor for the query results cache.org.datanucleus.store.query.cache.QueryDatastoreCompilationCache
getQueryDatastoreCompilationCache()
Accessor for the query datastore compilation cache.org.datanucleus.store.query.cache.QueryCompilationCache
getQueryGenericCompilationCache()
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.PersistenceNucleusContext
initialiseNucleusContext(org.datanucleus.metadata.PersistenceUnitMetaData unitMetaData, Map overridingProps, org.datanucleus.plugin.PluginManager pluginMgr)
Method to initialise a PersistenceManagerFactory that will control the persistence.boolean
isContainerManaged()
Accessor for whether the EMF is managed by a container (JavaEE).boolean
isLoaded(Object entity)
boolean
isLoaded(Object entity, String attrName)
boolean
isOpen()
Accessor for whether the factory is openprotected jakarta.persistence.EntityManager
newEntityManager(org.datanucleus.PersistenceNucleusContext nucleusCtx, jakarta.persistence.PersistenceContextType contextType, jakarta.persistence.SynchronizationType syncType)
Creates anEntityManager
.void
registerEntityGraph(JakartaEntityGraph eg, String graphName)
<T> T
unwrap(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:
close
in interfaceAutoCloseable
- Specified by:
close
in interfacejakarta.persistence.EntityManagerFactory
-
isOpen
public boolean isOpen()
Accessor for whether the factory is open- Specified by:
isOpen
in 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:
addNamedQuery
in 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:
createEntityManager
in 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:
createEntityManager
in 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:
createEntityManager
in 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:
createEntityManager
in 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:
getProperties
in 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:
getCache
in interfacejakarta.persistence.EntityManagerFactory
- Returns:
- Level 2 cache
-
getMetamodel
public jakarta.persistence.metamodel.Metamodel getMetamodel()
- Specified by:
getMetamodel
in interfacejakarta.persistence.EntityManagerFactory
-
getCriteriaBuilder
public jakarta.persistence.criteria.CriteriaBuilder getCriteriaBuilder()
- Specified by:
getCriteriaBuilder
in interfacejakarta.persistence.EntityManagerFactory
-
getPersistenceUnitUtil
public jakarta.persistence.PersistenceUnitUtil getPersistenceUnitUtil()
- Specified by:
getPersistenceUnitUtil
in interfacejakarta.persistence.EntityManagerFactory
-
getIdentifier
public Object getIdentifier(Object entity)
- Specified by:
getIdentifier
in interfacejakarta.persistence.PersistenceUnitUtil
-
isLoaded
public boolean isLoaded(Object entity, String attrName)
- Specified by:
isLoaded
in interfacejakarta.persistence.PersistenceUnitUtil
- Specified by:
isLoaded
in interfacejakarta.persistence.PersistenceUtil
-
isLoaded
public boolean isLoaded(Object entity)
- Specified by:
isLoaded
in interfacejakarta.persistence.PersistenceUnitUtil
- Specified by:
isLoaded
in 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:
unwrap
in 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:
addNamedEntityGraph
in 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:
entityGraphRegistered
in interfaceJakartaEntityGraphRegistrationListener
-
-