Package org.datanucleus
Class PersistenceNucleusContextImpl
- java.lang.Object
-
- org.datanucleus.AbstractNucleusContext
-
- org.datanucleus.PersistenceNucleusContextImpl
-
- All Implemented Interfaces:
Serializable
,NucleusContext
,PersistenceNucleusContext
public class PersistenceNucleusContextImpl extends AbstractNucleusContext implements Serializable, PersistenceNucleusContext
Extends the basic DataNucleus context, adding on services for- creating ExecutionContext objects to handle persistence. Uses a pool of ExecutionContext objects, reusing them as required.
- providing a cache across ExecutionContext objects (the "Level 2" cache).
- provides a factory for creating StateManagers. This factory makes use of pooling, allowing reuse.
- provides access to the datastore via a StoreManager
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class org.datanucleus.AbstractNucleusContext
apiAdapter, classLoaderResolverClassName, classLoaderResolverMap, config, defaultCLR, metaDataManager, pluginManager, STARTUP_PROPERTIES, typeManager
-
-
Constructor Summary
Constructors Constructor Description PersistenceNucleusContextImpl(String apiName, Map startupProps)
Constructor for the context.PersistenceNucleusContextImpl(String apiName, Map startupProps, PluginManager pluginMgr)
Constructor for the context.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addExecutionContextListener(ExecutionContext.LifecycleListener listener)
Register a new Listener for ExecutionContext events.void
addInternalFetchGroup(FetchGroup grp)
Method to add a dynamic FetchGroup for use by this OMF.void
applyDefaultProperties(Configuration conf)
Method called when initialising the Configuration to load up defaults for the properties appropriate for this NucleusContext.void
close()
Clear out resources for the supported services.FetchGroup
createInternalFetchGroup(Class cls, String name)
Method to create a new internal fetch group for the class+name.AutoStartMechanism
getAutoStartMechanism()
BeanValidationHandler
getBeanValidationHandler(ExecutionContext ec)
Method to return a handler for bean validation (JSR303).CDIHandler
getCDIHandler()
Accessor for the handler for CDI (JSR346) if in an environment that provides one.String
getCurrentUser(ExecutionContext ec)
Accessor for the current user for the supplied ExecutionContext.ExecutionContext
getExecutionContext(Object owner, Map<String,Object> options)
Method to return an ExecutionContext for use in persistence.ExecutionContext.LifecycleListener[]
getExecutionContextListeners()
Object the array of registered ExecutionContext listeners.ExecutionContextPool
getExecutionContextPool()
FetchGroupManager
getFetchGroupManager()
Convenience accessor for the FetchGroupManager.Set<FetchGroup>
getFetchGroupsWithName(String name)
Accessor for the fetch groups for the specified name.IdentityManager
getIdentityManager()
Accessor for a manager for identities.ImplementationCreator
getImplementationCreator()
FetchGroup
getInternalFetchGroup(Class cls, String name, boolean createIfNotPresent)
Accessor for an internal fetch group for the specified class.ManagementManager
getJMXManager()
Accessor for the JMX manager (if required).JTASyncRegistry
getJtaSyncRegistry()
Accessor for the JTA Synchronization registry, when using JTA.javax.transaction.TransactionManager
getJtaTransactionManager()
Accessor for the JTA transaction manager, when using JTA.Level2Cache
getLevel2Cache()
ResourcedTransactionManager
getResourcedTransactionManager()
StateManagerFactory
getStateManagerFactory()
FactoryStatistics
getStatistics()
StoreManager
getStoreManager()
String
getTenantId(ExecutionContext ec)
Accessor for the tenant id for the ExecutionContext.String[]
getTenantReadIds(ExecutionContext ec)
Accessor for the ids of the tenants that should be included in any read operations.boolean
hasLevel2Cache()
void
initialise()
Method to initialise the context for use.protected void
initialiseNamedQueries(ClassLoaderResolver clr)
Method to compile all registered named queries (when the user has initialised using a persistence-unit).protected void
initialiseSchema(String generateModeStr, boolean generateScripts)
Method to handle generation (create, drop, drop+create) of a schema at initialisation.boolean
isClassCacheable(AbstractClassMetaData cmd)
Convenience method to return if objects of this type are cached for this NucleusContext.boolean
isClassWithIdentityCacheable(Object id)
Convenience method to return if the supplied id is of an object that is cacheable in the L2 cache.boolean
isFederated()
Return whether we are managing a federated context (i.e a primary StoreManager, with some secondary StoreManager(s)).boolean
isJcaMode()
Accessor for the JCA mode.protected void
logConfigurationDetails()
Convenience method so that extending implementations can log their own configuration.void
removeExecutionContextListener(ExecutionContext.LifecycleListener listener)
Unregister a Listener from ExecutionContext events.void
removeInternalFetchGroup(FetchGroup grp)
Method to remove a dynamic FetchGroup from use by this OMF.void
setJcaMode(boolean jca)
Mutator for whether we are in JCA mode.boolean
statisticsEnabled()
Accessor for whether statistics gathering is enabled.boolean
supportsORMMetaData()
-
Methods inherited from class org.datanucleus.AbstractNucleusContext
getApiAdapter, getApiName, getClassLoaderResolver, getConfiguration, getMetaDataManager, getPluginManager, getTypeManager, logConfiguration
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.datanucleus.NucleusContext
getApiAdapter, getApiName, getClassLoaderResolver, getConfiguration, getMetaDataManager, getPluginManager, getTypeManager
-
-
-
-
Constructor Detail
-
PersistenceNucleusContextImpl
public PersistenceNucleusContextImpl(String apiName, Map startupProps)
Constructor for the context.- Parameters:
apiName
- Name of the API that we need a context for (JDO, JPA, etc)startupProps
- Any properties that could define behaviour of this context (plugin registry, class loading etc)
-
PersistenceNucleusContextImpl
public PersistenceNucleusContextImpl(String apiName, Map startupProps, PluginManager pluginMgr)
Constructor for the context.- Parameters:
apiName
- Name of the API that we need a context for (JDO, JPA, etc)startupProps
- Any properties that could define behaviour of this context (plugin registry, class loading etc)pluginMgr
- Plugin Manager (or null if wanting it to be created)
-
-
Method Detail
-
applyDefaultProperties
public void applyDefaultProperties(Configuration conf)
Description copied from interface:NucleusContext
Method called when initialising the Configuration to load up defaults for the properties appropriate for this NucleusContext.- Specified by:
applyDefaultProperties
in interfaceNucleusContext
- Overrides:
applyDefaultProperties
in classAbstractNucleusContext
- Parameters:
conf
- The configuration
-
initialise
public void initialise()
Description copied from interface:NucleusContext
Method to initialise the context for use. If any services are considered essential for operation then they will be enabled here, otherwise left for lazy initialisation.- Specified by:
initialise
in interfaceNucleusContext
- Overrides:
initialise
in classAbstractNucleusContext
-
close
public void close()
Description copied from interface:NucleusContext
Clear out resources for the supported services.- Specified by:
close
in interfaceNucleusContext
- Overrides:
close
in classAbstractNucleusContext
-
logConfigurationDetails
protected void logConfigurationDetails()
Description copied from class:AbstractNucleusContext
Convenience method so that extending implementations can log their own configuration.- Specified by:
logConfigurationDetails
in classAbstractNucleusContext
-
isFederated
public boolean isFederated()
Description copied from interface:PersistenceNucleusContext
Return whether we are managing a federated context (i.e a primary StoreManager, with some secondary StoreManager(s)).- Specified by:
isFederated
in interfacePersistenceNucleusContext
- Returns:
- Whether this is federated
-
getAutoStartMechanism
public AutoStartMechanism getAutoStartMechanism()
- Specified by:
getAutoStartMechanism
in interfacePersistenceNucleusContext
-
initialiseNamedQueries
protected void initialiseNamedQueries(ClassLoaderResolver clr)
Method to compile all registered named queries (when the user has initialised using a persistence-unit).- Parameters:
clr
- ClassLoader resolver
-
initialiseSchema
protected void initialiseSchema(String generateModeStr, boolean generateScripts)
Method to handle generation (create, drop, drop+create) of a schema at initialisation. Will generate the schema for all classes that have had their metadata loaded at this point, which typically means the persistence-unit.- Parameters:
generateModeStr
- Generate "mode"generateScripts
- Whether to generate
-
getExecutionContextPool
public ExecutionContextPool getExecutionContextPool()
- Specified by:
getExecutionContextPool
in interfacePersistenceNucleusContext
-
getStateManagerFactory
public StateManagerFactory getStateManagerFactory()
- Specified by:
getStateManagerFactory
in interfacePersistenceNucleusContext
-
getExecutionContext
public ExecutionContext getExecutionContext(Object owner, Map<String,Object> options)
Description copied from interface:PersistenceNucleusContext
Method to return an ExecutionContext for use in persistence.- Specified by:
getExecutionContext
in interfacePersistenceNucleusContext
- Parameters:
owner
- The owner object for the context. PersistenceManager/EntityManager typically.options
- Any options affecting startup- Returns:
- The ExecutionContext
-
getIdentityManager
public IdentityManager getIdentityManager()
Description copied from interface:PersistenceNucleusContext
Accessor for a manager for identities.- Specified by:
getIdentityManager
in interfacePersistenceNucleusContext
- Returns:
- The identity manager to use
-
statisticsEnabled
public boolean statisticsEnabled()
Description copied from interface:PersistenceNucleusContext
Accessor for whether statistics gathering is enabled.- Specified by:
statisticsEnabled
in interfacePersistenceNucleusContext
- Returns:
- Whether the user has enabled statistics or JMX management is enabled
-
getJMXManager
public ManagementManager getJMXManager()
Description copied from interface:PersistenceNucleusContext
Accessor for the JMX manager (if required). Does nothing if the property "datanucleus.jmxType" is unset.- Specified by:
getJMXManager
in interfacePersistenceNucleusContext
- Returns:
- The JMX manager
-
getStatistics
public FactoryStatistics getStatistics()
- Specified by:
getStatistics
in interfacePersistenceNucleusContext
-
getImplementationCreator
public ImplementationCreator getImplementationCreator()
- Specified by:
getImplementationCreator
in interfacePersistenceNucleusContext
-
getResourcedTransactionManager
public ResourcedTransactionManager getResourcedTransactionManager()
- Specified by:
getResourcedTransactionManager
in interfacePersistenceNucleusContext
-
getJtaTransactionManager
public javax.transaction.TransactionManager getJtaTransactionManager()
Description copied from interface:PersistenceNucleusContext
Accessor for the JTA transaction manager, when using JTA.- Specified by:
getJtaTransactionManager
in interfacePersistenceNucleusContext
- Returns:
- the JTA Transaction Manager
-
getJtaSyncRegistry
public JTASyncRegistry getJtaSyncRegistry()
Description copied from interface:PersistenceNucleusContext
Accessor for the JTA Synchronization registry, when using JTA.- Specified by:
getJtaSyncRegistry
in interfacePersistenceNucleusContext
- Returns:
- The JTASyncRegistry (or null if not using JTA)
-
getStoreManager
public StoreManager getStoreManager()
- Specified by:
getStoreManager
in interfacePersistenceNucleusContext
-
supportsORMMetaData
public boolean supportsORMMetaData()
- Specified by:
supportsORMMetaData
in interfaceNucleusContext
- Overrides:
supportsORMMetaData
in classAbstractNucleusContext
-
getBeanValidationHandler
public BeanValidationHandler getBeanValidationHandler(ExecutionContext ec)
Description copied from interface:PersistenceNucleusContext
Method to return a handler for bean validation (JSR303).- Specified by:
getBeanValidationHandler
in interfacePersistenceNucleusContext
- Parameters:
ec
- The ExecutionContext that the handler is for.- Returns:
- The bean validation handler (or null if not supported on this PMF/EMF, or no validator present)
-
getCDIHandler
public CDIHandler getCDIHandler()
Description copied from interface:PersistenceNucleusContext
Accessor for the handler for CDI (JSR346) if in an environment that provides one.- Specified by:
getCDIHandler
in interfacePersistenceNucleusContext
- Returns:
- The CDI Handler
-
hasLevel2Cache
public boolean hasLevel2Cache()
- Specified by:
hasLevel2Cache
in interfacePersistenceNucleusContext
-
getLevel2Cache
public Level2Cache getLevel2Cache()
- Specified by:
getLevel2Cache
in interfacePersistenceNucleusContext
-
getExecutionContextListeners
public ExecutionContext.LifecycleListener[] getExecutionContextListeners()
Description copied from interface:PersistenceNucleusContext
Object the array of registered ExecutionContext listeners.- Specified by:
getExecutionContextListeners
in interfacePersistenceNucleusContext
- Returns:
- array of
ExecutionContext.LifecycleListener
-
addExecutionContextListener
public void addExecutionContextListener(ExecutionContext.LifecycleListener listener)
Description copied from interface:PersistenceNucleusContext
Register a new Listener for ExecutionContext events.- Specified by:
addExecutionContextListener
in interfacePersistenceNucleusContext
- Parameters:
listener
- the listener to register
-
removeExecutionContextListener
public void removeExecutionContextListener(ExecutionContext.LifecycleListener listener)
Description copied from interface:PersistenceNucleusContext
Unregister a Listener from ExecutionContext events.- Specified by:
removeExecutionContextListener
in interfacePersistenceNucleusContext
- Parameters:
listener
- the listener to unregister
-
setJcaMode
public void setJcaMode(boolean jca)
Description copied from interface:PersistenceNucleusContext
Mutator for whether we are in JCA mode.- Specified by:
setJcaMode
in interfacePersistenceNucleusContext
- Parameters:
jca
- true if using JCA connector
-
isJcaMode
public boolean isJcaMode()
Description copied from interface:PersistenceNucleusContext
Accessor for the JCA mode.- Specified by:
isJcaMode
in interfacePersistenceNucleusContext
- Returns:
- true if using JCA connector.
-
getFetchGroupManager
public FetchGroupManager getFetchGroupManager()
Description copied from interface:PersistenceNucleusContext
Convenience accessor for the FetchGroupManager. Creates it if not yet existing.- Specified by:
getFetchGroupManager
in interfacePersistenceNucleusContext
- Returns:
- The FetchGroupManager
-
addInternalFetchGroup
public void addInternalFetchGroup(FetchGroup grp)
Description copied from interface:PersistenceNucleusContext
Method to add a dynamic FetchGroup for use by this OMF.- Specified by:
addInternalFetchGroup
in interfacePersistenceNucleusContext
- Parameters:
grp
- The group
-
removeInternalFetchGroup
public void removeInternalFetchGroup(FetchGroup grp)
Description copied from interface:PersistenceNucleusContext
Method to remove a dynamic FetchGroup from use by this OMF.- Specified by:
removeInternalFetchGroup
in interfacePersistenceNucleusContext
- Parameters:
grp
- The group
-
createInternalFetchGroup
public FetchGroup createInternalFetchGroup(Class cls, String name)
Description copied from interface:PersistenceNucleusContext
Method to create a new internal fetch group for the class+name.- Specified by:
createInternalFetchGroup
in interfacePersistenceNucleusContext
- Parameters:
cls
- Class that it applies toname
- Name of group- Returns:
- The group
-
getInternalFetchGroup
public FetchGroup getInternalFetchGroup(Class cls, String name, boolean createIfNotPresent)
Description copied from interface:PersistenceNucleusContext
Accessor for an internal fetch group for the specified class.- Specified by:
getInternalFetchGroup
in interfacePersistenceNucleusContext
- Parameters:
cls
- The classname
- Name of the groupcreateIfNotPresent
- Whether to create the fetch group if not present- Returns:
- The FetchGroup
-
getFetchGroupsWithName
public Set<FetchGroup> getFetchGroupsWithName(String name)
Description copied from interface:PersistenceNucleusContext
Accessor for the fetch groups for the specified name.- Specified by:
getFetchGroupsWithName
in interfacePersistenceNucleusContext
- Parameters:
name
- Name of the group- Returns:
- The FetchGroup
-
isClassWithIdentityCacheable
public boolean isClassWithIdentityCacheable(Object id)
Description copied from interface:PersistenceNucleusContext
Convenience method to return if the supplied id is of an object that is cacheable in the L2 cache.- Specified by:
isClassWithIdentityCacheable
in interfacePersistenceNucleusContext
- Parameters:
id
- The identity- Returns:
- Whether the object it refers to is considered cacheable
-
isClassCacheable
public boolean isClassCacheable(AbstractClassMetaData cmd)
Description copied from interface:PersistenceNucleusContext
Convenience method to return if objects of this type are cached for this NucleusContext. Uses the "cacheable" flag of the class, and the cache-mode to determine whether to cache- Specified by:
isClassCacheable
in interfacePersistenceNucleusContext
- Parameters:
cmd
- MetaData for the class- Returns:
- Whether it is cacheable
-
getTenantId
public String getTenantId(ExecutionContext ec)
Description copied from interface:PersistenceNucleusContext
Accessor for the tenant id for the ExecutionContext. Returns the MultiTenancyProvider id (if specified) or relays to the ExecutionContext "tenantId" property (or global tenantId if that is not defined).- Specified by:
getTenantId
in interfacePersistenceNucleusContext
- Parameters:
ec
- ExecutionContext- Returns:
- The tenant id for this context.
-
getTenantReadIds
public String[] getTenantReadIds(ExecutionContext ec)
Description copied from interface:PersistenceNucleusContext
Accessor for the ids of the tenants that should be included in any read operations. Defaults to just the current tenant id unless specified.- Specified by:
getTenantReadIds
in interfacePersistenceNucleusContext
- Parameters:
ec
- ExecutionContext- Returns:
- The tenant id(s) for use when reading
-
getCurrentUser
public String getCurrentUser(ExecutionContext ec)
Description copied from interface:PersistenceNucleusContext
Accessor for the current user for the supplied ExecutionContext.- Specified by:
getCurrentUser
in interfacePersistenceNucleusContext
- Parameters:
ec
- ExecutionContext- Returns:
- The current user for this context.
-
-