- 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, 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 voidaddExecutionContextListener(ExecutionContext.LifecycleListener listener)Register a new Listener for ExecutionContext events.voidaddInternalFetchGroup(FetchGroup grp)Method to add a dynamic FetchGroup for use by this OMF.voidapplyDefaultProperties(Configuration conf)Method called when initialising the Configuration to load up defaults for the properties appropriate for this NucleusContext.voidclose()Clear out resources for the supported services.FetchGroupcreateInternalFetchGroup(Class cls, String name)Method to create a new internal fetch group for the class+name.AutoStartMechanismgetAutoStartMechanism()BeanValidationHandlergetBeanValidationHandler(ExecutionContext ec)Method to return a handler for bean validation (JSR303).CDIHandlergetCDIHandler()Accessor for the handler for CDI (JSR346) if in an environment that provides one.StringgetCurrentUser(ExecutionContext ec)Accessor for the current user for the supplied ExecutionContext.ExecutionContextgetExecutionContext(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.ExecutionContextPoolgetExecutionContextPool()FetchGroupManagergetFetchGroupManager()Convenience accessor for the FetchGroupManager.Set<FetchGroup>getFetchGroupsWithName(String name)Accessor for the fetch groups for the specified name.IdentityManagergetIdentityManager()Accessor for a manager for identities.ImplementationCreatorgetImplementationCreator()FetchGroupgetInternalFetchGroup(Class cls, String name, boolean createIfNotPresent)Accessor for an internal fetch group for the specified class.ManagementManagergetJMXManager()Accessor for the JMX manager (if required).JTASyncRegistrygetJtaSyncRegistry()Accessor for the JTA Synchronization registry, when using JTA.javax.transaction.TransactionManagergetJtaTransactionManager()Accessor for the JTA transaction manager, when using JTA.Level2CachegetLevel2Cache()ResourcedTransactionManagergetResourcedTransactionManager()StateManagerFactorygetStateManagerFactory()FactoryStatisticsgetStatistics()StoreManagergetStoreManager()StringgetTenantId(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.booleanhasLevel2Cache()voidinitialise()Method to initialise the context for use.protected voidinitialiseNamedQueries(ClassLoaderResolver clr)Method to compile all registered named queries (when the user has initialised using a persistence-unit).protected voidinitialiseSchema(String generateModeStr, boolean generateScripts)Method to handle generation (create, drop, drop+create) of a schema at initialisation.booleanisClassCacheable(AbstractClassMetaData cmd)Convenience method to return if objects of this type are cached for this NucleusContext.booleanisClassWithIdentityCacheable(Object id)Convenience method to return if the supplied id is of an object that is cacheable in the L2 cache.booleanisFederated()Return whether we are managing a federated context (i.e a primary StoreManager, with some secondary StoreManager(s)).booleanisJcaMode()Accessor for the JCA mode.protected voidlogConfigurationDetails()Convenience method so that extending implementations can log their own configuration.voidremoveExecutionContextListener(ExecutionContext.LifecycleListener listener)Unregister a Listener from ExecutionContext events.voidremoveInternalFetchGroup(FetchGroup grp)Method to remove a dynamic FetchGroup from use by this OMF.voidsetJcaMode(boolean jca)Mutator for whether we are in JCA mode.booleanstatisticsEnabled()Accessor for whether statistics gathering is enabled.booleansupportsORMMetaData()-
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:NucleusContextMethod called when initialising the Configuration to load up defaults for the properties appropriate for this NucleusContext.- Specified by:
applyDefaultPropertiesin interfaceNucleusContext- Overrides:
applyDefaultPropertiesin classAbstractNucleusContext- Parameters:
conf- The configuration
-
initialise
public void initialise()
Description copied from interface:NucleusContextMethod 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:
initialisein interfaceNucleusContext- Overrides:
initialisein classAbstractNucleusContext
-
close
public void close()
Description copied from interface:NucleusContextClear out resources for the supported services.- Specified by:
closein interfaceNucleusContext- Overrides:
closein classAbstractNucleusContext
-
logConfigurationDetails
protected void logConfigurationDetails()
Description copied from class:AbstractNucleusContextConvenience method so that extending implementations can log their own configuration.- Specified by:
logConfigurationDetailsin classAbstractNucleusContext
-
isFederated
public boolean isFederated()
Description copied from interface:PersistenceNucleusContextReturn whether we are managing a federated context (i.e a primary StoreManager, with some secondary StoreManager(s)).- Specified by:
isFederatedin interfacePersistenceNucleusContext- Returns:
- Whether this is federated
-
getAutoStartMechanism
public AutoStartMechanism getAutoStartMechanism()
- Specified by:
getAutoStartMechanismin 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:
getExecutionContextPoolin interfacePersistenceNucleusContext
-
getStateManagerFactory
public StateManagerFactory getStateManagerFactory()
- Specified by:
getStateManagerFactoryin interfacePersistenceNucleusContext
-
getExecutionContext
public ExecutionContext getExecutionContext(Object owner, Map<String,Object> options)
Description copied from interface:PersistenceNucleusContextMethod to return an ExecutionContext for use in persistence.- Specified by:
getExecutionContextin 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:PersistenceNucleusContextAccessor for a manager for identities.- Specified by:
getIdentityManagerin interfacePersistenceNucleusContext- Returns:
- The identity manager to use
-
statisticsEnabled
public boolean statisticsEnabled()
Description copied from interface:PersistenceNucleusContextAccessor for whether statistics gathering is enabled.- Specified by:
statisticsEnabledin interfacePersistenceNucleusContext- Returns:
- Whether the user has enabled statistics or JMX management is enabled
-
getJMXManager
public ManagementManager getJMXManager()
Description copied from interface:PersistenceNucleusContextAccessor for the JMX manager (if required). Does nothing if the property "datanucleus.jmxType" is unset.- Specified by:
getJMXManagerin interfacePersistenceNucleusContext- Returns:
- The JMX manager
-
getStatistics
public FactoryStatistics getStatistics()
- Specified by:
getStatisticsin interfacePersistenceNucleusContext
-
getImplementationCreator
public ImplementationCreator getImplementationCreator()
- Specified by:
getImplementationCreatorin interfacePersistenceNucleusContext
-
getResourcedTransactionManager
public ResourcedTransactionManager getResourcedTransactionManager()
- Specified by:
getResourcedTransactionManagerin interfacePersistenceNucleusContext
-
getJtaTransactionManager
public javax.transaction.TransactionManager getJtaTransactionManager()
Description copied from interface:PersistenceNucleusContextAccessor for the JTA transaction manager, when using JTA.- Specified by:
getJtaTransactionManagerin interfacePersistenceNucleusContext- Returns:
- the JTA Transaction Manager
-
getJtaSyncRegistry
public JTASyncRegistry getJtaSyncRegistry()
Description copied from interface:PersistenceNucleusContextAccessor for the JTA Synchronization registry, when using JTA.- Specified by:
getJtaSyncRegistryin interfacePersistenceNucleusContext- Returns:
- The JTASyncRegistry (or null if not using JTA)
-
getStoreManager
public StoreManager getStoreManager()
- Specified by:
getStoreManagerin interfacePersistenceNucleusContext
-
supportsORMMetaData
public boolean supportsORMMetaData()
- Specified by:
supportsORMMetaDatain interfaceNucleusContext- Overrides:
supportsORMMetaDatain classAbstractNucleusContext
-
getBeanValidationHandler
public BeanValidationHandler getBeanValidationHandler(ExecutionContext ec)
Description copied from interface:PersistenceNucleusContextMethod to return a handler for bean validation (JSR303).- Specified by:
getBeanValidationHandlerin 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:PersistenceNucleusContextAccessor for the handler for CDI (JSR346) if in an environment that provides one.- Specified by:
getCDIHandlerin interfacePersistenceNucleusContext- Returns:
- The CDI Handler
-
hasLevel2Cache
public boolean hasLevel2Cache()
- Specified by:
hasLevel2Cachein interfacePersistenceNucleusContext
-
getLevel2Cache
public Level2Cache getLevel2Cache()
- Specified by:
getLevel2Cachein interfacePersistenceNucleusContext
-
getExecutionContextListeners
public ExecutionContext.LifecycleListener[] getExecutionContextListeners()
Description copied from interface:PersistenceNucleusContextObject the array of registered ExecutionContext listeners.- Specified by:
getExecutionContextListenersin interfacePersistenceNucleusContext- Returns:
- array of
ExecutionContext.LifecycleListener
-
addExecutionContextListener
public void addExecutionContextListener(ExecutionContext.LifecycleListener listener)
Description copied from interface:PersistenceNucleusContextRegister a new Listener for ExecutionContext events.- Specified by:
addExecutionContextListenerin interfacePersistenceNucleusContext- Parameters:
listener- the listener to register
-
removeExecutionContextListener
public void removeExecutionContextListener(ExecutionContext.LifecycleListener listener)
Description copied from interface:PersistenceNucleusContextUnregister a Listener from ExecutionContext events.- Specified by:
removeExecutionContextListenerin interfacePersistenceNucleusContext- Parameters:
listener- the listener to unregister
-
setJcaMode
public void setJcaMode(boolean jca)
Description copied from interface:PersistenceNucleusContextMutator for whether we are in JCA mode.- Specified by:
setJcaModein interfacePersistenceNucleusContext- Parameters:
jca- true if using JCA connector
-
isJcaMode
public boolean isJcaMode()
Description copied from interface:PersistenceNucleusContextAccessor for the JCA mode.- Specified by:
isJcaModein interfacePersistenceNucleusContext- Returns:
- true if using JCA connector.
-
getFetchGroupManager
public FetchGroupManager getFetchGroupManager()
Description copied from interface:PersistenceNucleusContextConvenience accessor for the FetchGroupManager. Creates it if not yet existing.- Specified by:
getFetchGroupManagerin interfacePersistenceNucleusContext- Returns:
- The FetchGroupManager
-
addInternalFetchGroup
public void addInternalFetchGroup(FetchGroup grp)
Description copied from interface:PersistenceNucleusContextMethod to add a dynamic FetchGroup for use by this OMF.- Specified by:
addInternalFetchGroupin interfacePersistenceNucleusContext- Parameters:
grp- The group
-
removeInternalFetchGroup
public void removeInternalFetchGroup(FetchGroup grp)
Description copied from interface:PersistenceNucleusContextMethod to remove a dynamic FetchGroup from use by this OMF.- Specified by:
removeInternalFetchGroupin interfacePersistenceNucleusContext- Parameters:
grp- The group
-
createInternalFetchGroup
public FetchGroup createInternalFetchGroup(Class cls, String name)
Description copied from interface:PersistenceNucleusContextMethod to create a new internal fetch group for the class+name.- Specified by:
createInternalFetchGroupin 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:PersistenceNucleusContextAccessor for an internal fetch group for the specified class.- Specified by:
getInternalFetchGroupin 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:PersistenceNucleusContextAccessor for the fetch groups for the specified name.- Specified by:
getFetchGroupsWithNamein interfacePersistenceNucleusContext- Parameters:
name- Name of the group- Returns:
- The FetchGroup
-
isClassWithIdentityCacheable
public boolean isClassWithIdentityCacheable(Object id)
Description copied from interface:PersistenceNucleusContextConvenience method to return if the supplied id is of an object that is cacheable in the L2 cache.- Specified by:
isClassWithIdentityCacheablein 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:PersistenceNucleusContextConvenience 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:
isClassCacheablein interfacePersistenceNucleusContext- Parameters:
cmd- MetaData for the class- Returns:
- Whether it is cacheable
-
getTenantId
public String getTenantId(ExecutionContext ec)
Description copied from interface:PersistenceNucleusContextAccessor 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:
getTenantIdin interfacePersistenceNucleusContext- Parameters:
ec- ExecutionContext- Returns:
- The tenant id for this context.
-
getTenantReadIds
public String[] getTenantReadIds(ExecutionContext ec)
Description copied from interface:PersistenceNucleusContextAccessor 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:
getTenantReadIdsin interfacePersistenceNucleusContext- Parameters:
ec- ExecutionContext- Returns:
- The tenant id(s) for use when reading
-
getCurrentUser
public String getCurrentUser(ExecutionContext ec)
Description copied from interface:PersistenceNucleusContextAccessor for the current user for the supplied ExecutionContext.- Specified by:
getCurrentUserin interfacePersistenceNucleusContext- Parameters:
ec- ExecutionContext- Returns:
- The current user for this context.
-
-