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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Level2Cache
Level 2 Cache, caching across ExecutionContexts.private CDIHandler
private boolean
Flag for whether we have initialised the CDIHandler.private CurrentUserProvider
private ExecutionContextPool
Pool for ExecutionContexts.private List
<ExecutionContext.LifecycleListener> private boolean
private FetchGroupManager
Manager for dynamic fetch groups defined on the PMF/EMF.private IdentityManager
Manager for object identities.private ImplementationCreator
ImplementationCreator for any persistent interfaces.private boolean
Flag defining if this is running within the JDO JCA adaptor.private ManagementManager
Manager for JMX features.private JTASyncRegistry
JTA Synchronization Registry (if using JTA 1.1 and supported).private TransactionManager
JTA Transaction Manager (if using JTA).private MultiTenancyProvider
private static final long
private StateManagerFactory
Factory for StateManagers for managing persistable objects.private AutoStartMechanism
Auto-Start Mechanism for loading classes into the StoreManager (if enabled).private FactoryStatistics
Statistics gathering object.private StoreManager
Manager for the datastore used by this PMF/EMF.private ResourcedTransactionManager
ResourcedTransaction Manager.private Object
Factory for validation.private boolean
Flag 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
ConstructorsConstructorDescriptionPersistenceNucleusContextImpl
(String apiName, Map startupProps) Constructor for the context.PersistenceNucleusContextImpl
(String apiName, Map startupProps, PluginManager pluginMgr) Constructor for the context. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Register a new Listener for ExecutionContext events.void
Method to add a dynamic FetchGroup for use by this OMF.void
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.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 String
getDatastoreScriptForResourceName
(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.boolean
void
Method to initialise the context for use.protected void
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
Convenience method to return if objects of this type are cached for this NucleusContext.boolean
Convenience method to return if the supplied id is of an object that is cacheable in the L2 cache.boolean
Return whether we are managing a federated context (i.e a primary StoreManager, with some secondary StoreManager(s)).boolean
Accessor for the JCA mode.protected void
Convenience method so that extending implementations can log their own configuration.private void
processDatastoreScript
(String scriptResourceName) void
Unregister a Listener from ExecutionContext events.void
Method to remove a dynamic FetchGroup from use by this OMF.void
setJcaMode
(boolean jca) Mutator for whether we are in JCA mode.boolean
Accessor for whether statistics gathering is enabled.boolean
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 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
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
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: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
- Specified by:
getAutoStartMechanism
in 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
Method to load the contents of a file given a resource name.- Parameters:
scriptResourceName
- The resource name (filename?)- Returns:
- The contents
-
getExecutionContextPool
- Specified by:
getExecutionContextPool
in interfacePersistenceNucleusContext
-
getStateManagerFactory
- Specified by:
getStateManagerFactory
in interfacePersistenceNucleusContext
-
getExecutionContext
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
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
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
- Specified by:
getStatistics
in interfacePersistenceNucleusContext
-
getImplementationCreator
- Specified by:
getImplementationCreator
in interfacePersistenceNucleusContext
-
getResourcedTransactionManager
- Specified by:
getResourcedTransactionManager
in interfacePersistenceNucleusContext
-
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
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
- Specified by:
getStoreManager
in interfacePersistenceNucleusContext
-
supportsORMMetaData
public boolean supportsORMMetaData()- Specified by:
supportsORMMetaData
in interfaceNucleusContext
- Overrides:
supportsORMMetaData
in classAbstractNucleusContext
-
getBeanValidationHandler
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
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
- Specified by:
getLevel2Cache
in interfacePersistenceNucleusContext
-
getExecutionContextListeners
Description copied from interface:PersistenceNucleusContext
Object the array of registered ExecutionContext listeners.- Specified by:
getExecutionContextListeners
in interfacePersistenceNucleusContext
- Returns:
- array of
ExecutionContext.LifecycleListener
-
addExecutionContextListener
Description copied from interface:PersistenceNucleusContext
Register a new Listener for ExecutionContext events.- Specified by:
addExecutionContextListener
in interfacePersistenceNucleusContext
- Parameters:
listener
- the listener to register
-
removeExecutionContextListener
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
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
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
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
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
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
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
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
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
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
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
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.
-