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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Level2CacheLevel 2 Cache, caching across ExecutionContexts.private CDIHandlerprivate booleanFlag for whether we have initialised the CDIHandler.private CurrentUserProviderprivate ExecutionContextPoolPool for ExecutionContexts.private List<ExecutionContext.LifecycleListener> private booleanprivate FetchGroupManagerManager for dynamic fetch groups defined on the PMF/EMF.private IdentityManagerManager for object identities.private ImplementationCreatorImplementationCreator for any persistent interfaces.private booleanFlag defining if this is running within the JDO JCA adaptor.private ManagementManagerManager for JMX features.private JTASyncRegistryJTA Synchronization Registry (if using JTA 1.1 and supported).private TransactionManagerJTA Transaction Manager (if using JTA).private MultiTenancyProviderprivate static final longprivate StateManagerFactoryFactory for StateManagers for managing persistable objects.private AutoStartMechanismAuto-Start Mechanism for loading classes into the StoreManager (if enabled).private FactoryStatisticsStatistics gathering object.private StoreManagerManager for the datastore used by this PMF/EMF.private ResourcedTransactionManagerResourcedTransaction Manager.private ObjectFactory for validation.private booleanFlag for whether we have initialised the ValidatorFactory.Fields inherited from class AbstractNucleusContext
apiAdapter, classLoaderResolverClassName, classLoaderResolverMap, config, defaultCLR, metaDataManager, pluginManager, STARTUP_PROPERTIES, typeManager -
Constructor Summary
ConstructorsConstructorDescriptionPersistenceNucleusContextImpl(String apiName, Map startupProps) Constructor for the context.PersistenceNucleusContextImpl(String apiName, Map startupProps, PluginManager pluginMgr) Constructor for the context. -
Method Summary
Modifier and TypeMethodDescriptionvoidRegister a new Listener for ExecutionContext events.voidMethod to add a dynamic FetchGroup for use by this OMF.voidMethod called when initialising the Configuration to load up defaults for the properties appropriate for this NucleusContext.voidclose()Clear out resources for the supported services.createInternalFetchGroup(Class cls, String name) Method to create a new internal fetch group for the class+name.Method to return a handler for bean validation (JSR303).Accessor for the handler for CDI (JSR346) if in an environment that provides one.Accessor for the current user for the supplied ExecutionContext.private StringgetDatastoreScriptForResourceName(String scriptResourceName) Method to load the contents of a file given a resource name.getExecutionContext(Object owner, Map<String, Object> options) Method to return an ExecutionContext for use in persistence.Object the array of registered ExecutionContext listeners.Convenience accessor for the FetchGroupManager.getFetchGroupsWithName(String name) Accessor for the fetch groups for the specified name.Accessor for a manager for identities.getInternalFetchGroup(Class cls, String name, boolean createIfNotPresent) Accessor for an internal fetch group for the specified class.Accessor for the JMX manager (if required).Accessor for the JTA Synchronization registry, when using JTA.Accessor for the JTA transaction manager, when using JTA.Accessor for the tenant id for the ExecutionContext.String[]Accessor for the ids of the tenants that should be included in any read operations.booleanvoidMethod to initialise the context for use.protected voidMethod 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.booleanConvenience method to return if objects of this type are cached for this NucleusContext.booleanConvenience method to return if the supplied id is of an object that is cacheable in the L2 cache.booleanReturn whether we are managing a federated context (i.e a primary StoreManager, with some secondary StoreManager(s)).booleanAccessor for the JCA mode.protected voidConvenience method so that extending implementations can log their own configuration.private voidprocessDatastoreScript(String scriptResourceName) voidUnregister a Listener from ExecutionContext events.voidMethod to remove a dynamic FetchGroup from use by this OMF.voidsetJcaMode(boolean jca) Mutator for whether we are in JCA mode.booleanAccessor for whether statistics gathering is enabled.booleanMethods inherited from class AbstractNucleusContext
getApiAdapter, getApiName, getClassLoaderResolver, getConfiguration, getMetaDataManager, getPluginManager, getTypeManager, logConfigurationMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface NucleusContext
getApiAdapter, getApiName, getClassLoaderResolver, getConfiguration, getMetaDataManager, getPluginManager, getTypeManager
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
storeMgr
Manager for the datastore used by this PMF/EMF. -
federated
private boolean federated -
starter
Auto-Start Mechanism for loading classes into the StoreManager (if enabled). -
jca
private boolean jcaFlag defining if this is running within the JDO JCA adaptor. -
cache
Level 2 Cache, caching across ExecutionContexts. -
txManager
ResourcedTransaction Manager. -
jtaTxManager
JTA Transaction Manager (if using JTA). -
jtaSyncRegistry
JTA Synchronization Registry (if using JTA 1.1 and supported). -
jmxManager
Manager for JMX features. -
statistics
Statistics gathering object. -
identityManager
Manager for object identities. -
implCreator
ImplementationCreator for any persistent interfaces. -
executionContextListeners
-
fetchGrpMgr
Manager for dynamic fetch groups defined on the PMF/EMF. -
validatorFactory
Factory for validation. -
validatorFactoryInit
private transient boolean validatorFactoryInitFlag for whether we have initialised the ValidatorFactory. -
cdiHandler
-
cdiHandlerInit
private transient boolean cdiHandlerInitFlag for whether we have initialised the CDIHandler. -
ecPool
Pool for ExecutionContexts. -
smFactory
Factory for StateManagers for managing persistable objects. -
multiTenancyProvider
-
currentUserProvider
-
-
Constructor Details
-
PersistenceNucleusContextImpl
-
PersistenceNucleusContextImpl
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 Details
-
applyDefaultProperties
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
- Specified by:
getAutoStartMechanismin interfacePersistenceNucleusContext
-
initialiseNamedQueries
Method to compile all registered named queries (when the user has initialised using a persistence-unit).- Parameters:
clr- ClassLoader resolver
-
initialiseSchema
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
-
getDatastoreScriptForResourceName
-
getExecutionContextPool
- Specified by:
getExecutionContextPoolin interfacePersistenceNucleusContext
-
getStateManagerFactory
- Specified by:
getStateManagerFactoryin interfacePersistenceNucleusContext
-
getExecutionContext
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
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
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
- Specified by:
getStatisticsin interfacePersistenceNucleusContext
-
getImplementationCreator
- Specified by:
getImplementationCreatorin interfacePersistenceNucleusContext
-
getResourcedTransactionManager
- Specified by:
getResourcedTransactionManagerin interfacePersistenceNucleusContext
-
getJtaTransactionManager
Description copied from interface:PersistenceNucleusContextAccessor for the JTA transaction manager, when using JTA.- Specified by:
getJtaTransactionManagerin interfacePersistenceNucleusContext- Returns:
- the JTA Transaction Manager
-
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
- Specified by:
getStoreManagerin interfacePersistenceNucleusContext
-
supportsORMMetaData
public boolean supportsORMMetaData()- Specified by:
supportsORMMetaDatain interfaceNucleusContext- Overrides:
supportsORMMetaDatain classAbstractNucleusContext
-
getBeanValidationHandler
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
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
- Specified by:
getLevel2Cachein interfacePersistenceNucleusContext
-
getExecutionContextListeners
Description copied from interface:PersistenceNucleusContextObject the array of registered ExecutionContext listeners.- Specified by:
getExecutionContextListenersin interfacePersistenceNucleusContext- Returns:
- array of
ExecutionContext.LifecycleListener
-
addExecutionContextListener
Description copied from interface:PersistenceNucleusContextRegister a new Listener for ExecutionContext events.- Specified by:
addExecutionContextListenerin interfacePersistenceNucleusContext- Parameters:
listener- the listener to register
-
removeExecutionContextListener
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
Description copied from interface:PersistenceNucleusContextConvenience accessor for the FetchGroupManager. Creates it if not yet existing.- Specified by:
getFetchGroupManagerin interfacePersistenceNucleusContext- Returns:
- The FetchGroupManager
-
addInternalFetchGroup
Description copied from interface:PersistenceNucleusContextMethod to add a dynamic FetchGroup for use by this OMF.- Specified by:
addInternalFetchGroupin interfacePersistenceNucleusContext- Parameters:
grp- The group
-
removeInternalFetchGroup
Description copied from interface:PersistenceNucleusContextMethod to remove a dynamic FetchGroup from use by this OMF.- Specified by:
removeInternalFetchGroupin interfacePersistenceNucleusContext- Parameters:
grp- The group
-
createInternalFetchGroup
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
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
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
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
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
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
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
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.
-