Package org.datanucleus
Class PersistenceNucleusContextImpl
- java.lang.Object
-
- org.datanucleus.AbstractNucleusContext
-
- org.datanucleus.PersistenceNucleusContextImpl
-
- All Implemented Interfaces:
java.io.Serializable,NucleusContext,PersistenceNucleusContext
public class PersistenceNucleusContextImpl extends AbstractNucleusContext implements java.io.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 Modifier and Type Field Description private Level2CachecacheLevel 2 Cache, caching across ExecutionContexts.private CDIHandlercdiHandlerprivate booleancdiHandlerInitFlag for whether we have initialised the CDIHandler.private CurrentUserProvidercurrentUserProviderprivate ExecutionContextPoolecPoolPool for ExecutionContexts.private java.util.List<ExecutionContext.LifecycleListener>executionContextListenersprivate booleanfederatedprivate FetchGroupManagerfetchGrpMgrManager for dynamic fetch groups defined on the PMF/EMF.private IdentityManageridentityManagerManager for object identities.private ImplementationCreatorimplCreatorImplementationCreator for any persistent interfaces.private booleanjcaFlag defining if this is running within the JDO JCA adaptor.private ManagementManagerjmxManagerManager for JMX features.private JTASyncRegistryjtaSyncRegistryJTA Synchronization Registry (if using JTA 1.1 and supported).private javax.transaction.TransactionManagerjtaTxManagerJTA Transaction Manager (if using JTA).private MultiTenancyProvidermultiTenancyProviderprivate static longserialVersionUIDprivate StateManagerFactorysmFactoryFactory for StateManagers for managing persistable objects.private AutoStartMechanismstarterAuto-Start Mechanism for loading classes into the StoreManager (if enabled).private FactoryStatisticsstatisticsStatistics gathering object.private StoreManagerstoreMgrManager for the datastore used by this PMF/EMF.private ResourcedTransactionManagertxManagerResourcedTransaction Manager.private java.lang.ObjectvalidatorFactoryFactory for validation.private booleanvalidatorFactoryInitFlag for whether we have initialised the ValidatorFactory.-
Fields inherited from class org.datanucleus.AbstractNucleusContext
apiAdapter, classLoaderResolverClassName, classLoaderResolverMap, config, defaultCLR, metaDataManager, pluginManager, STARTUP_PROPERTIES, typeManager
-
-
Constructor Summary
Constructors Constructor Description PersistenceNucleusContextImpl(java.lang.String apiName, java.util.Map startupProps)Constructor for the context.PersistenceNucleusContextImpl(java.lang.String apiName, java.util.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(java.lang.Class cls, java.lang.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.java.lang.StringgetCurrentUser(ExecutionContext ec)Accessor for the current user for the supplied ExecutionContext.private java.lang.StringgetDatastoreScriptForResourceName(java.lang.String scriptResourceName)Method to load the contents of a file given a resource name.ExecutionContextgetExecutionContext(java.lang.Object owner, java.util.Map<java.lang.String,java.lang.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.java.util.Set<FetchGroup>getFetchGroupsWithName(java.lang.String name)Accessor for the fetch groups for the specified name.IdentityManagergetIdentityManager()Accessor for a manager for identities.ImplementationCreatorgetImplementationCreator()FetchGroupgetInternalFetchGroup(java.lang.Class cls, java.lang.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()java.lang.StringgetTenantId(ExecutionContext ec)Accessor for the tenant id for the ExecutionContext.java.lang.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(java.lang.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(java.lang.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.private voidprocessDatastoreScript(java.lang.String scriptResourceName)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
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
storeMgr
private transient StoreManager storeMgr
Manager for the datastore used by this PMF/EMF.
-
federated
private boolean federated
-
starter
private transient AutoStartMechanism starter
Auto-Start Mechanism for loading classes into the StoreManager (if enabled).
-
jca
private boolean jca
Flag defining if this is running within the JDO JCA adaptor.
-
cache
private Level2Cache cache
Level 2 Cache, caching across ExecutionContexts.
-
txManager
private transient ResourcedTransactionManager txManager
ResourcedTransaction Manager.
-
jtaTxManager
private transient javax.transaction.TransactionManager jtaTxManager
JTA Transaction Manager (if using JTA).
-
jtaSyncRegistry
private transient JTASyncRegistry jtaSyncRegistry
JTA Synchronization Registry (if using JTA 1.1 and supported).
-
jmxManager
private transient ManagementManager jmxManager
Manager for JMX features.
-
statistics
private transient FactoryStatistics statistics
Statistics gathering object.
-
identityManager
private IdentityManager identityManager
Manager for object identities.
-
implCreator
private ImplementationCreator implCreator
ImplementationCreator for any persistent interfaces.
-
executionContextListeners
private java.util.List<ExecutionContext.LifecycleListener> executionContextListeners
-
fetchGrpMgr
private transient FetchGroupManager fetchGrpMgr
Manager for dynamic fetch groups defined on the PMF/EMF.
-
validatorFactory
private transient java.lang.Object validatorFactory
Factory for validation.
-
validatorFactoryInit
private transient boolean validatorFactoryInit
Flag for whether we have initialised the ValidatorFactory.
-
cdiHandler
private transient CDIHandler cdiHandler
-
cdiHandlerInit
private transient boolean cdiHandlerInit
Flag for whether we have initialised the CDIHandler.
-
ecPool
private ExecutionContextPool ecPool
Pool for ExecutionContexts.
-
smFactory
private StateManagerFactory smFactory
Factory for StateManagers for managing persistable objects.
-
multiTenancyProvider
private MultiTenancyProvider multiTenancyProvider
-
currentUserProvider
private CurrentUserProvider currentUserProvider
-
-
Constructor Detail
-
PersistenceNucleusContextImpl
public PersistenceNucleusContextImpl(java.lang.String apiName, java.util.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(java.lang.String apiName, java.util.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(java.lang.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
-
processDatastoreScript
private void processDatastoreScript(java.lang.String scriptResourceName)
-
getDatastoreScriptForResourceName
private java.lang.String getDatastoreScriptForResourceName(java.lang.String scriptResourceName)
Method to load the contents of a file given a resource name.- Parameters:
scriptResourceName- The resource name (filename?)- Returns:
- The contents
-
getExecutionContextPool
public ExecutionContextPool getExecutionContextPool()
- Specified by:
getExecutionContextPoolin interfacePersistenceNucleusContext
-
getStateManagerFactory
public StateManagerFactory getStateManagerFactory()
- Specified by:
getStateManagerFactoryin interfacePersistenceNucleusContext
-
getExecutionContext
public ExecutionContext getExecutionContext(java.lang.Object owner, java.util.Map<java.lang.String,java.lang.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(java.lang.Class cls, java.lang.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(java.lang.Class cls, java.lang.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 java.util.Set<FetchGroup> getFetchGroupsWithName(java.lang.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(java.lang.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 java.lang.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 java.lang.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 java.lang.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.
-
-