org.datanucleus.jpa
Class EntityManagerFactoryImpl

java.lang.Object
  extended by org.datanucleus.jpa.EntityManagerFactoryImpl
All Implemented Interfaces:
javax.persistence.EntityManagerFactory, javax.persistence.PersistenceUnitUtil, javax.persistence.PersistenceUtil

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

EntityManagerFactory implementation. Caches the "persistence-unit" MetaData information when encountered (in J2SE mode). TODO Change to extend ObjectManagerFactoryImpl and remove PMF reference.


Field Summary
protected static org.datanucleus.util.Localiser LOCALISER
          Localiser for messages.
static org.datanucleus.util.NucleusLogger LOGGER
          Logger for enhancing.
protected  org.datanucleus.jdo.JDOPersistenceManagerFactory pmf
          Underlying PersistenceManagerFactory that provides the persistence functionality.
 
Constructor Summary
EntityManagerFactoryImpl()
          Constructor.
EntityManagerFactoryImpl(javax.persistence.spi.PersistenceUnitInfo unitInfo, java.util.Map overridingProps)
          Constructor when working in a J2EE environment.
EntityManagerFactoryImpl(java.lang.String unitName, java.util.Map overridingProps)
          Constructor when working in a J2SE environment.
 
Method Summary
protected  void assertIsClosed()
           
 void close()
          Method to close the factory.
 javax.persistence.EntityManager createEntityManager()
          Method to create an entity manager.
 javax.persistence.EntityManager createEntityManager(java.util.Map overridingProps)
          Method to create an entity manager with the specified properties.
 javax.persistence.Cache getCache()
          Accessor for the second level cache.
 javax.persistence.criteria.CriteriaBuilder getCriteriaBuilder()
           
 java.lang.Object getIdentifier(java.lang.Object entity)
           
 javax.persistence.metamodel.Metamodel getMetamodel()
           
 javax.persistence.PersistenceUnitUtil getPersistenceUnitUtil()
           
 java.util.Map<java.lang.String,java.lang.Object> getProperties()
          Get the properties and associated values that are in effect for the entity manager factory.
 JPAQueryCache getQueryCache()
          Accessor for the query results cache.
 org.datanucleus.store.query.cache.QueryDatastoreCompilationCache getQueryDatastoreCompilationCache()
          Accessor for the query datastore compilation cache.
 org.datanucleus.query.cache.QueryCompilationCache getQueryGenericCompilationCache()
          Accessor for the query generic compilation cache.
 java.util.Set<java.lang.String> getSupportedProperties()
          Get the names of the properties that are supported for use with the entity manager factory.
protected  org.datanucleus.jdo.JDOPersistenceManagerFactory initialisePMF(org.datanucleus.metadata.PersistenceUnitMetaData unitMetaData, java.util.Map overridingProps)
          Method to initialise a PersistenceManagerFactory that will control the persistence.
 boolean isContainerManaged()
          Accessor for whether the EMF is managed by a container.
 boolean isLoaded(java.lang.Object entity)
           
 boolean isLoaded(java.lang.Object entity, java.lang.String attrName)
           
 boolean isOpen()
          Accessor for whether the factory is open
protected  javax.persistence.EntityManager newEntityManager(javax.persistence.PersistenceContextType contextType, javax.jdo.PersistenceManagerFactory pmf)
          Creates an EntityManager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCALISER

protected static final org.datanucleus.util.Localiser LOCALISER
Localiser for messages.


LOGGER

public static final org.datanucleus.util.NucleusLogger LOGGER
Logger for enhancing.


pmf

protected org.datanucleus.jdo.JDOPersistenceManagerFactory pmf
Underlying PersistenceManagerFactory that provides the persistence functionality.

Constructor Detail

EntityManagerFactoryImpl

public EntityManagerFactoryImpl()
Constructor.


EntityManagerFactoryImpl

public EntityManagerFactoryImpl(javax.persistence.spi.PersistenceUnitInfo unitInfo,
                                java.util.Map overridingProps)
Constructor when working in a J2EE environment.

Parameters:
unitInfo - The "persistent-unit" info
overridingProps - factory properties overriding those in the "persistence-unit"

EntityManagerFactoryImpl

public EntityManagerFactoryImpl(java.lang.String unitName,
                                java.util.Map overridingProps)
Constructor when working in a J2SE environment.

Parameters:
unitName - Name of the "persistent-unit" to use
overridingProps - factory properties overriding those in the "persistence-unit"
Method Detail

isContainerManaged

public boolean isContainerManaged()
Accessor for whether the EMF is managed by a container.

Returns:
Whether managed by a container

close

public void close()
Method to close the factory.

Specified by:
close in interface javax.persistence.EntityManagerFactory

isOpen

public boolean isOpen()
Accessor for whether the factory is open

Specified by:
isOpen in interface javax.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.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

createEntityManager

public javax.persistence.EntityManager createEntityManager()
Method to create an entity manager.

Specified by:
createEntityManager in interface javax.persistence.EntityManagerFactory
Returns:
The Entity Manager

createEntityManager

public javax.persistence.EntityManager createEntityManager(java.util.Map overridingProps)
Method to create an entity manager with the specified properties. This creates a new underlying PersistenceManagerFactory since each PMF is locked when created to stop config changes.

Specified by:
createEntityManager in interface javax.persistence.EntityManagerFactory
Parameters:
overridingProps - Properties to use for this manager
Returns:
The Entity Manager

newEntityManager

protected javax.persistence.EntityManager newEntityManager(javax.persistence.PersistenceContextType contextType,
                                                           javax.jdo.PersistenceManagerFactory pmf)
Creates an EntityManager. Override if you want to return a different type that implements this interface.

Parameters:
contextType - The persistence context type
pmf - The Underlying PMF

initialisePMF

protected org.datanucleus.jdo.JDOPersistenceManagerFactory initialisePMF(org.datanucleus.metadata.PersistenceUnitMetaData unitMetaData,
                                                                         java.util.Map overridingProps)
Method to initialise a PersistenceManagerFactory that will control the persistence. If the unitMetaData is null will simply create a default PMF 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 others
Returns:
The PersistenceManagerFactory

getProperties

public java.util.Map<java.lang.String,java.lang.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 interface javax.persistence.EntityManagerFactory
Returns:
properties

getSupportedProperties

public java.util.Set<java.lang.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:
getCache in interface javax.persistence.EntityManagerFactory
Returns:
Level 2 cache

getMetamodel

public javax.persistence.metamodel.Metamodel getMetamodel()
Specified by:
getMetamodel in interface javax.persistence.EntityManagerFactory

getCriteriaBuilder

public javax.persistence.criteria.CriteriaBuilder getCriteriaBuilder()
Specified by:
getCriteriaBuilder in interface javax.persistence.EntityManagerFactory

getPersistenceUnitUtil

public javax.persistence.PersistenceUnitUtil getPersistenceUnitUtil()
Specified by:
getPersistenceUnitUtil in interface javax.persistence.EntityManagerFactory

getIdentifier

public java.lang.Object getIdentifier(java.lang.Object entity)
Specified by:
getIdentifier in interface javax.persistence.PersistenceUnitUtil

isLoaded

public boolean isLoaded(java.lang.Object entity,
                        java.lang.String attrName)
Specified by:
isLoaded in interface javax.persistence.PersistenceUnitUtil
Specified by:
isLoaded in interface javax.persistence.PersistenceUtil

isLoaded

public boolean isLoaded(java.lang.Object entity)
Specified by:
isLoaded in interface javax.persistence.PersistenceUnitUtil
Specified by:
isLoaded in interface javax.persistence.PersistenceUtil


Copyright © 2011. All Rights Reserved.