Package org.datanucleus.api.jpa
Class JPAEntityManagerFactory
- java.lang.Object
-
- org.datanucleus.api.jpa.JPAEntityManagerFactory
-
- All Implemented Interfaces:
Serializable,AutoCloseable,javax.persistence.EntityManagerFactory,javax.persistence.PersistenceUnitUtil,javax.persistence.PersistenceUtil,JPAEntityGraphRegistrationListener
public class JPAEntityManagerFactory extends Object implements javax.persistence.EntityManagerFactory, javax.persistence.PersistenceUnitUtil, JPAEntityGraphRegistrationListener, 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 JPAEntityManagerFactory(String unitName, Map overridingProps)Constructor when working in a JavaSE environment.JPAEntityManagerFactory(javax.persistence.spi.PersistenceUnitInfo unitInfo, Map overridingProps)Constructor when working in a JavaEE environment.JPAEntityManagerFactory(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, javax.persistence.EntityGraph<T> graph)voidaddNamedQuery(String name, javax.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.javax.persistence.EntityManagercreateEntityManager()Method to create an (application-managed) entity manager.javax.persistence.EntityManagercreateEntityManager(Map overridingProps)Method to create an (application-managed) entity manager with the specified properties.javax.persistence.EntityManagercreateEntityManager(javax.persistence.SynchronizationType syncType)Create a new JTA application-managed EntityManager with the specified synchronization type.javax.persistence.EntityManagercreateEntityManager(javax.persistence.SynchronizationType syncType, Map overridingProps)Create a new JTA application-managed EntityManager with the specified synchronization type and Map of properties.voidderegisterEntityGraph(String graphName)voidentityGraphRegistered(JPAEntityGraph eg)javax.persistence.CachegetCache()Accessor for the second level cache.javax.persistence.criteria.CriteriaBuildergetCriteriaBuilder()StringgetDefinedEntityGraphName()Set<String>getEntityGraphNames()<T> List<javax.persistence.EntityGraph<? super T>>getEntityGraphsByType(Class<T> entityClass)ObjectgetIdentifier(Object entity)javax.persistence.metamodel.MetamodelgetMetamodel()StringgetName()javax.persistence.EntityGraphgetNamedEntityGraph(String graphName)org.datanucleus.NucleusContextgetNucleusContext()javax.persistence.PersistenceUnitUtilgetPersistenceUnitUtil()Map<String,Object>getProperties()Get the properties and associated values that are in effect for the entity manager factory.JPAQueryCachegetQueryCache()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 javax.persistence.EntityManagernewEntityManager(org.datanucleus.PersistenceNucleusContext nucleusCtx, javax.persistence.PersistenceContextType contextType, javax.persistence.SynchronizationType syncType)Creates anEntityManager.voidregisterEntityGraph(JPAEntityGraph 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
-
JPAEntityManagerFactory
public JPAEntityManagerFactory(javax.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"
-
JPAEntityManagerFactory
public JPAEntityManagerFactory(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 interfacejavax.persistence.EntityManagerFactory
-
isOpen
public boolean isOpen()
Accessor for whether the factory is open- Specified by:
isOpenin interfacejavax.persistence.EntityManagerFactory- Returns:
- Whether it is open
-
getQueryCache
public JPAQueryCache 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, javax.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 interfacejavax.persistence.EntityManagerFactory- Parameters:
query- The query whose definition we save as named
-
createEntityManager
public javax.persistence.EntityManager createEntityManager()
Method to create an (application-managed) entity manager.- Specified by:
createEntityManagerin interfacejavax.persistence.EntityManagerFactory- Returns:
- The Entity Manager
-
createEntityManager
public javax.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 interfacejavax.persistence.EntityManagerFactory- Parameters:
overridingProps- Properties to use for this manager- Returns:
- The Entity Manager
-
createEntityManager
public javax.persistence.EntityManager createEntityManager(javax.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 interfacejavax.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- Since:
- JPA2.1
-
createEntityManager
public javax.persistence.EntityManager createEntityManager(javax.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 interfacejavax.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- Since:
- JPA2.1
-
newEntityManager
protected javax.persistence.EntityManager newEntityManager(org.datanucleus.PersistenceNucleusContext nucleusCtx, javax.persistence.PersistenceContextType contextType, javax.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 interfacejavax.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 javax.persistence.Cache getCache()
Accessor for the second level cache.- Specified by:
getCachein interfacejavax.persistence.EntityManagerFactory- Returns:
- Level 2 cache
-
getMetamodel
public javax.persistence.metamodel.Metamodel getMetamodel()
- Specified by:
getMetamodelin interfacejavax.persistence.EntityManagerFactory
-
getCriteriaBuilder
public javax.persistence.criteria.CriteriaBuilder getCriteriaBuilder()
- Specified by:
getCriteriaBuilderin interfacejavax.persistence.EntityManagerFactory
-
getPersistenceUnitUtil
public javax.persistence.PersistenceUnitUtil getPersistenceUnitUtil()
- Specified by:
getPersistenceUnitUtilin interfacejavax.persistence.EntityManagerFactory
-
getIdentifier
public Object getIdentifier(Object entity)
- Specified by:
getIdentifierin interfacejavax.persistence.PersistenceUnitUtil
-
isLoaded
public boolean isLoaded(Object entity, String attrName)
- Specified by:
isLoadedin interfacejavax.persistence.PersistenceUnitUtil- Specified by:
isLoadedin interfacejavax.persistence.PersistenceUtil
-
isLoaded
public boolean isLoaded(Object entity)
- Specified by:
isLoadedin interfacejavax.persistence.PersistenceUnitUtil- Specified by:
isLoadedin interfacejavax.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 interfacejavax.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:
javax.persistence.PersistenceException- if the provider does not support the call.
-
getNamedEntityGraph
public javax.persistence.EntityGraph getNamedEntityGraph(String graphName)
-
getEntityGraphsByType
public <T> List<javax.persistence.EntityGraph<? super T>> getEntityGraphsByType(Class<T> entityClass)
-
addNamedEntityGraph
public <T> void addNamedEntityGraph(String graphName, javax.persistence.EntityGraph<T> graph)
- Specified by:
addNamedEntityGraphin interfacejavax.persistence.EntityManagerFactory
-
registerEntityGraph
public void registerEntityGraph(JPAEntityGraph eg, String graphName)
-
deregisterEntityGraph
public void deregisterEntityGraph(String graphName)
-
getDefinedEntityGraphName
public String getDefinedEntityGraphName()
-
entityGraphRegistered
public void entityGraphRegistered(JPAEntityGraph eg)
- Specified by:
entityGraphRegisteredin interfaceJPAEntityGraphRegistrationListener
-
-