-
- All Superinterfaces:
ExecutionContextReference
- All Known Implementing Classes:
ExecutionContextImpl
,ExecutionContextThreadedImpl
public interface ExecutionContext extends ExecutionContextReference
Context of execution for persistence operations. This equates to the work of a PersistenceManager/EntityManager. An ExecutionContext is responsible for- persist, merge, find and delete of persistable objects from the defined StoreManager
- have a set of properties defining behaviour over and above the default configuration of the parent NucleusContext
- provide an interface to querying of the persistable objects in the StoreManager
- provide a way of managing persistable objects using StateManagers
- have a cache of currently managed objects (the "Level 1" cache), and make use of the cache of the parent NucleusContext when not available in its cache
- have a single "current" transaction. This transaction can be local, or JTA
An ExecutionContext can be started with a series of options that affect its behaviour thereafter. These are defined by the "OPTION_{YYY}" static Strings.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
ExecutionContext.EmbeddedOwnerRelation
static interface
ExecutionContext.LifecycleListener
Interface to be implemented by a listener for the closure of the ExecutionContext.
-
Field Summary
Fields Modifier and Type Field Description static String
OPTION_JTA_AUTOJOIN
Startup option setting whether, when using JTA, to do auto-join of transactions.static String
OPTION_PASSWORD
Startup option overriding the default (PMF/EMF) password for the connectionURL.static String
OPTION_USERNAME
Startup option overriding the default (PMF/EMF) username for the connectionURL.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description void
addInternalFetchGroup(FetchGroup grp)
Method to add an internal fetch group to this ExecutionContext.void
addOperationToQueue(Operation oper)
Method to add an operation to the queue.void
addStateManagerToCache(DNStateManager sm)
Method to add the object managed by the specified StateManager to the cache.void
assertClassPersistable(Class cls)
Convenience method to assert if the passed class is not persistable.void
attachObject(DNStateManager sm, Object pc, boolean sco)
Method to attach the passed object (and related objects).<T> T
attachObjectCopy(DNStateManager sm, T pc, boolean sco)
Method to attach a copy of the passed object (and related objects).void
clearDirty()
Method to mark as clean all StateManagers of dirty objects.void
clearDirty(DNStateManager sm)
Mark the specified StateManager as clean.void
close()
Method to close the execution context.void
closeCallbackHandler()
Close the callback handler, and disconnect any registered instance listeners.boolean
containsStateManagerAssociatedValue(DNStateManager sm, Object key)
void
deleteObject(Object obj)
Method to delete an object from the datastore.void
deleteObjectInternal(Object pc)
Method to delete the passed object (internally).void
deleteObjects(Object... objs)
Method to delete an array of objects from the datastore.void
deregisterEmbeddedRelation(ExecutionContext.EmbeddedOwnerRelation rel)
Method to deregister the specified embedded relation (e.g when the embedded object is disconnected).void
deregisterExecutionContextListener(ExecutionContextListener listener)
Deregister a listener from calling when this ExecutionContext is closing.void
detachAll()
Method to detach all managed objects.void
detachObject(FetchPlanState state, Object pc)
Method to detach the passed object.<T> T
detachObjectCopy(FetchPlanState state, T pc)
Method to detach a copy of the passed object using the provided state.void
detachObjects(FetchPlanState state, Object... pcs)
Method to detach the passed object(s).void
enlistInTransaction(DNStateManager sm)
Method to enlist the specified StateManager in the current transaction.void
evictAllObjects()
Method to evict all L1 cache objectsvoid
evictFromTransaction(DNStateManager sm)
Method to evict the specified StateManager from the current transaction.void
evictObject(Object pc)
Method to evict the passed object.void
evictObjects(Class cls, boolean subclasses)
Method to evict all objects of the specified type (and optionaly its subclasses).boolean
exists(Object obj)
Method to return if the specified object exists in the datastore.<T> T
findObject(Class<T> cls, Object key)
Accessor for an object of the specified type with the provided id "key".Persistable
findObject(Object id, boolean validate)
Shortcut to calling "findObject(id, validate, validate, null)".Persistable
findObject(Object id, boolean validate, boolean checkInheritance, String objectClassName)
Accessor for an object given the object id.Persistable
findObject(Object id, FieldValues fv, Class pcClass, boolean ignoreCache, boolean checkInheritance)
Accessor for an object given the object id.<T> T
findObjectByUnique(Class<T> cls, String[] fieldNames, Object[] fieldValues)
Accessor for an object of the specified type with the provided values for a unique key.<T> List<T>
findObjects(Class<T> cls, List keys)
Accessor for objects of the specified type, with the provided id "key"s.Persistable[]
findObjectsById(Object[] ids, boolean validate)
Accessor for persistable objects with the specified identities.DNStateManager
findStateManager(Object pc)
Method to find StateManager for the passed persistable object when it is managed by this manager.DNStateManager
findStateManager(Object pc, boolean persist)
Method to find StateManager for the passed persistable object when it is managed by this manager, and if not yet persistent to persist it and return the assigned StateManager.DNStateManager
findStateManagerForEmbedded(Object value, DNStateManager owner, AbstractMemberMetaData mmd, PersistableObjectType objectType)
Method to find StateManager for the passed embedded persistable object.DNStateManager
findStateManagerOfOwnerForAttachingObject(Object pc)
void
flush()
Method callable from external APIs for user-management of flushing.void
flushInternal(boolean flushToDatastore)
Method to flushes all dirty, new, and deleted instances to the datastore.void
flushOperationsForBackingStore(Store backingStore, DNStateManager sm)
Method to flush all queued operations for the specified backing store (if any).default ApiAdapter
getApiAdapter()
Accessor for the API adapter.Object
getAttachDetachReferencedObject(DNStateManager sm)
Access a referenced object for this StateManager during the attach/detach process.Object
getAttachedObjectForId(Object id)
Convenience method to return the attached object for the specified id if one exists.Boolean
getBooleanProperty(String name)
Accessor for a boolean property value.CallbackHandler
getCallbackHandler()
Retrieve the callback handler for this ExecutionContext.ClassLoaderResolver
getClassLoaderResolver()
Accessor for the ClassLoader resolver to use in class loading issues.String
getCurrentUser()
Accessor for the current user, for this ExecutionContext.List<ExecutionContext.EmbeddedOwnerRelation>
getEmbeddedInformationForOwner(DNStateManager ownerSM)
Accessor for the relations for the specified embedded StateManager where it is embedded.<T> Extent<T>
getExtent(Class<T> candidateClass, boolean includeSubclasses)
Accessor for the Extent for a class (and optionally its subclasses).Set<FetchGroup>
getFetchGroupsWithName(String name)
Accessor for the fetch groups for the specified name.FetchPlan
getFetchPlan()
Acessor for the current FetchPlanFlushMode
getFlushMode()
Accessor for the flush mode.FetchGroup
getInternalFetchGroup(Class cls, String name)
Accessor for an internal fetch group for the specified class.Integer
getIntProperty(String name)
Accessor for an int property value.Level1Cache
getLevel1Cache()
LockManager
getLockManager()
Accessor for the lock manager for objects in this execution context.Set
getManagedObjects()
Accessor for the currently managed objects for the current transaction.Set
getManagedObjects(Class[] classes)
Accessor for the currently managed objects for the current transaction.Set
getManagedObjects(String[] states)
Accessor for the currently managed objects for the current transaction.Set
getManagedObjects(String[] states, Class[] classes)
Accessor for the currently managed objects for the current transaction.boolean
getManageRelations()
Whether managed relations are supported by this execution context.default MetaDataManager
getMetaDataManager()
Accessor for the MetaData Manager.boolean
getMultithreaded()
Accessor for whether this context is multithreaded.PersistenceNucleusContext
getNucleusContext()
Accessor for the context in which this execution context is running.Persistable
getObjectFromCache(Object id)
Convenience method to access an object in the cache.Persistable[]
getObjectsFromCache(Object[] ids)
Convenience method to access objects in the cache.List<DNStateManager>
getObjectsToBeFlushed()
Convenience method to inspect the list of objects with outstanding changes to flush.OperationQueue
getOperationQueue()
Accessor for the operation queue.DNStateManager
getOwnerForEmbeddedStateManager(DNStateManager embSM)
Accessor for the owner StateManager for the provided embedded StateManager.ExecutionContext.EmbeddedOwnerRelation
getOwnerInformationForEmbedded(DNStateManager embSM)
Accessor for the owner relation for the specified embedded StateManager where it is embedded.Map<String,Object>
getProperties()
Accessor for the defined properties.Object
getProperty(String name)
Accessor for a property.RelationshipManager
getRelationshipManager(DNStateManager sm)
Accessor for the RelationshipManager for the provided StateManager.boolean
getSerializeReadForClass(String className)
Convenience method to return the setting for serialize read for the current transaction for the specified class name.Object
getStateManagerAssociatedValue(DNStateManager sm, Object key)
ManagerStatistics
getStatistics()
Accessor for any statistics-gathering object.default StoreManager
getStoreManager()
Accessor for the Store Manager.String
getStringProperty(String name)
Accessor for a String property value.Set<String>
getSupportedProperties()
Accessor for the supported property names.String
getTenantId()
Accessor for the tenant id, for this ExecutionContext.Transaction
getTransaction()
Accessor for the current transaction for this execution context.default TypeManager
getTypeManager()
Convenience accessor for the type manager for this persistence context (from NucleusContext).boolean
hasIdentityInCache(Object id)
Whether an object with the specified identity exists in the cache(s).boolean
hasPersistenceInformationForClass(Class cls)
Utility method to check if the specified class has reachable metadata or annotations.void
initialise(Object owner, Map<String,Object> options)
boolean
isClosed()
Accessor for whether this execution context is closed.boolean
isDelayDatastoreOperationsEnabled()
Whether the datastore operations are delayed until commit.boolean
isEnlistedInTransaction(Object id)
Method to return if an object is enlisted in the current transaction.boolean
isFlushing()
Accessor for whether the ExecutionContext is flushing changes to the datastore.boolean
isInserting(Object pc)
Tests whether this persistable object is being inserted.boolean
isManagingRelations()
Returns whether this ExecutionContext is currently performing the manage relationships task.boolean
isObjectModifiedInTransaction(Object id)
Accessor for whether the object with this identity is modified in the current transaction.boolean
isRunningDetachAllOnCommit()
Accessor for whether this ExecutionContext is currently running detachAllOnCommit.void
makeObjectNontransactional(Object pc)
Method to make the passed object nontransactional.void
makeObjectTransactional(Object pc)
Method to make the passed object transactional.void
makeObjectTransient(Object pc, FetchPlanState state)
Method to make transient the passed object.void
markDirty(DNStateManager sm, boolean directUpdate)
Mark the specified StateManager as dirtyvoid
markFieldsForUpdateInLevel2Cache(Object id, boolean[] fields)
Method to mark the object with specifed id to have the supplied fields updated in the L2 cache at commit.<T> T
newInstance(Class<T> cls)
Method to generate an instance of an interface, abstract class, or concrete PC class.Object
newObjectId(Class pcClass, Object key)
This method returns an object id instance corresponding to the pcClass and key arguments.Object
newObjectId(String className, Object pc)
This method returns an object id instance corresponding to the class name, and the passed object (when using app identity).boolean
operationQueueIsActive()
Accessor for whether the operation queue is currently active.<T> T
persistObject(T pc, boolean merging)
Method to persist the passed object.<T> T
persistObjectInternal(T pc, DNStateManager ownerSM, int ownerFieldNum, PersistableObjectType objectType)
Method to persist the passed object (internally).default <T> T
persistObjectInternal(T pc, FieldValues preInsertChanges, PersistableObjectType objectType)
Method to persist the passed object (internally).<T> T
persistObjectInternal(T pc, FieldValues preInsertChanges, DNStateManager ownerSM, int ownerFieldNum, PersistableObjectType objectType)
Method to persist the passed object (internally).Object[]
persistObjects(Object... pcs)
Method to persist the passed object(s).void
processNontransactionalUpdate()
Method to process any outstanding non-transactional updates that are queued.void
putObjectIntoLevel1Cache(DNStateManager sm)
Method to put a Persistable object associated to StateManager into the L1 cache.void
refreshAllObjects()
Method to refresh all L1 cache objectsvoid
refreshObject(Object pc)
Method to refresh the passed object.ExecutionContext.EmbeddedOwnerRelation
registerEmbeddedRelation(DNStateManager ownerSM, int ownerMemberNum, PersistableObjectType objectType, DNStateManager embSM)
Method to register an embedded relation for the specified member of the owner StateManager where the embedded StateManager is stored.void
registerExecutionContextListener(ExecutionContextListener listener)
Register a listener to be called when this ExecutionContext is closing.void
removeEmbeddedOwnerRelation(DNStateManager ownerSM, int ownerFieldNum, DNStateManager embSM)
Convenience method to remove the EmbeddedOwnerRelation between the specified StateManagers.void
removeObjectFromLevel1Cache(Object id)
Method to remove an object from the L1 cache.void
removeObjectFromLevel2Cache(Object id)
Method to remove an object from the L2 cache.void
removeStateManagerAssociatedValue(DNStateManager sm, Object key)
void
removeStateManagerFromCache(DNStateManager sm)
Method to remove the object managed by the specified StateManager from the cache.void
replaceObjectId(Persistable pc, Object oldID, Object newID)
Replace the previous object id for a PC object to a newvoid
retrieveObjects(boolean useFetchPlan, Object... pcs)
Method to retrieve the (fields of the) passed object(s).void
setAttachDetachReferencedObject(DNStateManager sm, Object obj)
Register a referenced object against this StateManager for the attach/detach process.void
setProperties(Map props)
Method to set properties on the execution context.void
setProperty(String name, Object value)
Method to set a property on the execution contextvoid
setStateManagerAssociatedValue(DNStateManager sm, Object key, Object value)
default void
threadLock()
Method to lock this ExecutionContext for threadingdefault void
threadUnlock()
Method to unlock this ExecutionContext for threading-
Methods inherited from interface org.datanucleus.enhancement.ExecutionContextReference
getOwner
-
-
-
-
Field Detail
-
OPTION_USERNAME
static final String OPTION_USERNAME
Startup option overriding the default (PMF/EMF) username for the connectionURL.- See Also:
- Constant Field Values
-
OPTION_PASSWORD
static final String OPTION_PASSWORD
Startup option overriding the default (PMF/EMF) password for the connectionURL.- See Also:
- Constant Field Values
-
OPTION_JTA_AUTOJOIN
static final String OPTION_JTA_AUTOJOIN
Startup option setting whether, when using JTA, to do auto-join of transactions.- See Also:
- Constant Field Values
-
-
Method Detail
-
getLevel1Cache
Level1Cache getLevel1Cache()
-
getTransaction
Transaction getTransaction()
Accessor for the current transaction for this execution context.- Returns:
- The current transaction
-
getStoreManager
default StoreManager getStoreManager()
Accessor for the Store Manager.- Returns:
- Store Manager
-
getMetaDataManager
default MetaDataManager getMetaDataManager()
Accessor for the MetaData Manager.- Returns:
- The MetaData Manager
-
getNucleusContext
PersistenceNucleusContext getNucleusContext()
Accessor for the context in which this execution context is running.- Returns:
- Returns the context.
-
getApiAdapter
default ApiAdapter getApiAdapter()
Accessor for the API adapter.- Returns:
- API adapter.
-
getFetchPlan
FetchPlan getFetchPlan()
Acessor for the current FetchPlan- Returns:
- FetchPlan
-
getClassLoaderResolver
ClassLoaderResolver getClassLoaderResolver()
Accessor for the ClassLoader resolver to use in class loading issues.- Returns:
- The ClassLoader resolver
-
getLockManager
LockManager getLockManager()
Accessor for the lock manager for objects in this execution context.- Returns:
- The lock manager
-
getStatistics
ManagerStatistics getStatistics()
Accessor for any statistics-gathering object.- Returns:
- The statistics for this manager
-
setProperties
void setProperties(Map props)
Method to set properties on the execution context.- Parameters:
props
- The properties
-
setProperty
void setProperty(String name, Object value)
Method to set a property on the execution context- Parameters:
name
- Name of the propertyvalue
- Value to set
-
getProperty
Object getProperty(String name)
Accessor for a property.- Parameters:
name
- Name of the property- Returns:
- The value
-
getBooleanProperty
Boolean getBooleanProperty(String name)
Accessor for a boolean property value.- Parameters:
name
- Name of the property- Returns:
- the value
-
getIntProperty
Integer getIntProperty(String name)
Accessor for an int property value.- Parameters:
name
- Name of the property- Returns:
- the value
-
getStringProperty
String getStringProperty(String name)
Accessor for a String property value.- Parameters:
name
- Name of the property- Returns:
- The value
-
getProperties
Map<String,Object> getProperties()
Accessor for the defined properties.- Returns:
- Properties for this execution context
-
getSupportedProperties
Set<String> getSupportedProperties()
Accessor for the supported property names.- Returns:
- Set of names
-
getTypeManager
default TypeManager getTypeManager()
Convenience accessor for the type manager for this persistence context (from NucleusContext).- Returns:
- The type manager
-
close
void close()
Method to close the execution context.
-
isClosed
boolean isClosed()
Accessor for whether this execution context is closed.- Returns:
- Whether this manager is closed.
-
findStateManager
DNStateManager findStateManager(Object pc)
Method to find StateManager for the passed persistable object when it is managed by this manager.- Parameters:
pc
- The persistable object- Returns:
- StateManager
-
findStateManager
DNStateManager findStateManager(Object pc, boolean persist)
Method to find StateManager for the passed persistable object when it is managed by this manager, and if not yet persistent to persist it and return the assigned StateManager.- Parameters:
pc
- The persistable objectpersist
- Whether to persist if not yet persistent- Returns:
- StateManager
-
findStateManagerForEmbedded
DNStateManager findStateManagerForEmbedded(Object value, DNStateManager owner, AbstractMemberMetaData mmd, PersistableObjectType objectType)
Method to find StateManager for the passed embedded persistable object. Will create one if not already registered, and tie it to the specified owner.- Parameters:
value
- The embedded objectowner
- The owner StateManager (if known).mmd
- Metadata for the field of the ownerobjectType
- Type of persistable object being stored- Returns:
- StateManager for the embedded object
-
findStateManagerOfOwnerForAttachingObject
DNStateManager findStateManagerOfOwnerForAttachingObject(Object pc)
-
addStateManagerToCache
void addStateManagerToCache(DNStateManager sm)
Method to add the object managed by the specified StateManager to the cache.- Parameters:
sm
- StateManager
-
removeStateManagerFromCache
void removeStateManagerFromCache(DNStateManager sm)
Method to remove the object managed by the specified StateManager from the cache.- Parameters:
sm
- StateManager
-
evictObject
void evictObject(Object pc)
Method to evict the passed object.- Parameters:
pc
- The object
-
evictObjects
void evictObjects(Class cls, boolean subclasses)
Method to evict all objects of the specified type (and optionaly its subclasses).- Parameters:
cls
- Type of persistable objectsubclasses
- Whether to include subclasses
-
evictAllObjects
void evictAllObjects()
Method to evict all L1 cache objects
-
retrieveObjects
void retrieveObjects(boolean useFetchPlan, Object... pcs)
Method to retrieve the (fields of the) passed object(s).- Parameters:
useFetchPlan
- Whether to retrieve the current fetch planpcs
- The objects
-
persistObject
<T> T persistObject(T pc, boolean merging)
Method to persist the passed object.- Type Parameters:
T
- Type of the persistable object- Parameters:
pc
- The objectmerging
- Whether this object (and dependents) is being merged- Returns:
- The persisted object
-
persistObjects
Object[] persistObjects(Object... pcs)
Method to persist the passed object(s).- Parameters:
pcs
- The objects to persist- Returns:
- The persisted objects
-
persistObjectInternal
<T> T persistObjectInternal(T pc, FieldValues preInsertChanges, DNStateManager ownerSM, int ownerFieldNum, PersistableObjectType objectType)
Method to persist the passed object (internally).- Type Parameters:
T
- Type of the persistable object- Parameters:
pc
- The objectpreInsertChanges
- Changes to be made before insertingownerSM
- StateManager of the owner when embeddedownerFieldNum
- Field number in the owner where this is embedded (or -1 if not embedded)objectType
- Type of object- Returns:
- The persisted object
-
persistObjectInternal
<T> T persistObjectInternal(T pc, DNStateManager ownerSM, int ownerFieldNum, PersistableObjectType objectType)
Method to persist the passed object (internally).- Type Parameters:
T
- Type of the persistable object- Parameters:
pc
- The objectownerSM
- StateManager of the owner when embeddedownerFieldNum
- Field number in the owner where this is embedded (or -1 if not embedded)objectType
- Type of object- Returns:
- The persisted object
-
persistObjectInternal
default <T> T persistObjectInternal(T pc, FieldValues preInsertChanges, PersistableObjectType objectType)
Method to persist the passed object (internally).- Type Parameters:
T
- Type of the persistable object- Parameters:
pc
- The objectpreInsertChanges
- Changes to be made before insertingobjectType
- Type of object- Returns:
- The persisted object
-
makeObjectTransient
void makeObjectTransient(Object pc, FetchPlanState state)
Method to make transient the passed object.- Parameters:
pc
- The objectstate
- Object containing the state of the fetchplan processing
-
makeObjectTransactional
void makeObjectTransactional(Object pc)
Method to make the passed object transactional.- Parameters:
pc
- The object
-
makeObjectNontransactional
void makeObjectNontransactional(Object pc)
Method to make the passed object nontransactional.- Parameters:
pc
- The object
-
exists
boolean exists(Object obj)
Method to return if the specified object exists in the datastore.- Parameters:
obj
- The (persistable) object- Returns:
- Whether it exists
-
getManagedObjects
Set getManagedObjects()
Accessor for the currently managed objects for the current transaction. If the transaction is not active this returns null.- Returns:
- Collection of managed objects enlisted in the current transaction
-
getManagedObjects
Set getManagedObjects(Class[] classes)
Accessor for the currently managed objects for the current transaction. If the transaction is not active this returns null.- Parameters:
classes
- Classes that we want the objects for- Returns:
- Collection of managed objects enlisted in the current transaction
-
getManagedObjects
Set getManagedObjects(String[] states)
Accessor for the currently managed objects for the current transaction. If the transaction is not active this returns null.- Parameters:
states
- States that we want the objects for- Returns:
- Collection of managed objects enlisted in the current transaction
-
getManagedObjects
Set getManagedObjects(String[] states, Class[] classes)
Accessor for the currently managed objects for the current transaction. If the transaction is not active this returns null.- Parameters:
states
- States that we want the objects forclasses
- Classes that we want the objects for- Returns:
- Collection of managed objects enlisted in the current transaction
-
deleteObject
void deleteObject(Object obj)
Method to delete an object from the datastore.- Parameters:
obj
- The object
-
deleteObjects
void deleteObjects(Object... objs)
Method to delete an array of objects from the datastore.- Parameters:
objs
- The objects to delete
-
deleteObjectInternal
void deleteObjectInternal(Object pc)
Method to delete the passed object (internally).- Parameters:
pc
- The object
-
detachObject
void detachObject(FetchPlanState state, Object pc)
Method to detach the passed object.- Parameters:
state
- State for the detachment process.pc
- The object to detach
-
detachObjects
void detachObjects(FetchPlanState state, Object... pcs)
Method to detach the passed object(s).- Parameters:
state
- State for the detachment process.pcs
- The object(s) to detach
-
detachObjectCopy
<T> T detachObjectCopy(FetchPlanState state, T pc)
Method to detach a copy of the passed object using the provided state.- Type Parameters:
T
- Type of the persistable object- Parameters:
state
- State for the detachment processpc
- The object- Returns:
- The detached copy of the object
-
detachAll
void detachAll()
Method to detach all managed objects.
-
attachObject
void attachObject(DNStateManager sm, Object pc, boolean sco)
Method to attach the passed object (and related objects). Throws an exception if another (persistent) object with the same id exists in the L1 cache already.- Parameters:
sm
- StateManager of the owning object that has this in a field causing its attachpc
- The (detached) objectsco
- Whether the object has no identity (embedded or serialised)
-
attachObjectCopy
<T> T attachObjectCopy(DNStateManager sm, T pc, boolean sco)
Method to attach a copy of the passed object (and related objects).- Type Parameters:
T
- Type of the persistable object- Parameters:
sm
- StateManager of the owning object that has this in a field causing its attachpc
- The objectsco
- Whether it has no identity (second-class object)- Returns:
- The attached copy of the input object
-
getAttachedObjectForId
Object getAttachedObjectForId(Object id)
Convenience method to return the attached object for the specified id if one exists.- Parameters:
id
- The id- Returns:
- The attached object
-
refreshObject
void refreshObject(Object pc)
Method to refresh the passed object.- Parameters:
pc
- The object
-
refreshAllObjects
void refreshAllObjects()
Method to refresh all L1 cache objects
-
enlistInTransaction
void enlistInTransaction(DNStateManager sm)
Method to enlist the specified StateManager in the current transaction.- Parameters:
sm
- StateManager
-
isEnlistedInTransaction
boolean isEnlistedInTransaction(Object id)
Method to return if an object is enlisted in the current transaction.- Parameters:
id
- Identity for the object- Returns:
- Whether it is enlisted in the current transaction
-
evictFromTransaction
void evictFromTransaction(DNStateManager sm)
Method to evict the specified StateManager from the current transaction.- Parameters:
sm
- StateManager
-
markDirty
void markDirty(DNStateManager sm, boolean directUpdate)
Mark the specified StateManager as dirty- Parameters:
sm
- StateManagerdirectUpdate
- Whether the object has had a direct update made on it (if known)
-
clearDirty
void clearDirty(DNStateManager sm)
Mark the specified StateManager as clean.- Parameters:
sm
- StateManager
-
clearDirty
void clearDirty()
Method to mark as clean all StateManagers of dirty objects.
-
processNontransactionalUpdate
void processNontransactionalUpdate()
Method to process any outstanding non-transactional updates that are queued. If "datanucleus.nontx.atomic" is false, or currently in a transaction then returns immediately. Otherwise will flush any updates that are outstanding (updates to an object), will perform detachAllOnCommit if enabled (so user always has detached objects), update objects in any L2 cache, and migrates any objects through lifecycle changes. Is similar in content to "flush"+"preCommit"+"postCommit"
-
findObject
<T> T findObject(Class<T> cls, Object key)
Accessor for an object of the specified type with the provided id "key". With datastore id or single-field id the "key" is the key of the id, and with composite ids the "key" is the toString() of the id.- Type Parameters:
T
- Type of the persistable- Parameters:
cls
- Class of the persistablekey
- Value of the key field for SingleFieldIdentity, or the string value of the key otherwise- Returns:
- The object meeting this requirement
-
findObjects
<T> List<T> findObjects(Class<T> cls, List keys)
Accessor for objects of the specified type, with the provided id "key"s. With datastore id or single-field id the "key" is the key of the id, and with composite ids the "key" is the toString() of the id.- Type Parameters:
T
- Type of the persistable- Parameters:
cls
- Class of the persistablekeys
- Values of the key field for SingleFieldIdentity, or the string value of the keys otherwise- Returns:
- The objects meeting this requirement
-
findObjectByUnique
<T> T findObjectByUnique(Class<T> cls, String[] fieldNames, Object[] fieldValues)
Accessor for an object of the specified type with the provided values for a unique key. Alternative would be to have an intermediate class and do thisec.findObjectByUnique(cls).for("field1", val1).for("field2", val2).find();
- Type Parameters:
T
- Type of the persistable- Parameters:
cls
- Class of the persistablefieldNames
- Name(s) of the field(s) forming the unique keyfieldValues
- Value(s) of the field(s) forming the unique key- Returns:
- The object meeting this requirement
-
findObject
Persistable findObject(Object id, boolean validate)
Shortcut to calling "findObject(id, validate, validate, null)". Note: This is used by the bytecode enhancement contract indnCopyKeyFieldsFromObjectId
- Specified by:
findObject
in interfaceExecutionContextReference
- Parameters:
id
- The id of the objectvalidate
- Whether to validate the id- Returns:
- The object
-
findObjectsById
Persistable[] findObjectsById(Object[] ids, boolean validate)
Accessor for persistable objects with the specified identities.- Parameters:
ids
- Ids of the object(s).validate
- Whether to validate the object state- Returns:
- The persistable objects with these ids (same order)
- Throws:
NucleusObjectNotFoundException
- if an object doesn't exist in the datastore
-
findObject
Persistable findObject(Object id, boolean validate, boolean checkInheritance, String objectClassName)
Accessor for an object given the object id.- Parameters:
id
- Id of the object.validate
- Whether to validate the object statecheckInheritance
- Whether look to the database to determine which class this object is. This parameter is a hint. Set false, if it's already determined the correct pcClass for this pc "object" in a certain level in the hierarchy. Set to true and it will look to the database.objectClassName
- Class name for the object with this id (if known, optional)- Returns:
- The Object
-
findObject
Persistable findObject(Object id, FieldValues fv, Class pcClass, boolean ignoreCache, boolean checkInheritance)
Accessor for an object given the object id. Typically used after a query to apply the retrieved values to an object.- Parameters:
id
- Id of the object.fv
- FieldValues to apply to the object (optional)pcClass
- the type which the object is. This type will be used to instantiate the objectignoreCache
- true if the cache is ignoredcheckInheritance
- Whether to check the inheritance of this object- Returns:
- the Object
-
getExtent
<T> Extent<T> getExtent(Class<T> candidateClass, boolean includeSubclasses)
Accessor for the Extent for a class (and optionally its subclasses).- Type Parameters:
T
- Type of the persistable object- Parameters:
candidateClass
- The classincludeSubclasses
- Whether to include subclasses- Returns:
- The Extent
-
putObjectIntoLevel1Cache
void putObjectIntoLevel1Cache(DNStateManager sm)
Method to put a Persistable object associated to StateManager into the L1 cache.- Parameters:
sm
- StateManager
-
getObjectFromCache
Persistable getObjectFromCache(Object id)
Convenience method to access an object in the cache. Firstly looks in the L1 cache for this ExecutionContext, and if not found looks in the L2 cache.- Parameters:
id
- Id of the object- Returns:
- Persistable object (with connected StateManager).
-
getObjectsFromCache
Persistable[] getObjectsFromCache(Object[] ids)
Convenience method to access objects in the cache. Firstly looks in the L1 cache, and if not found looks in the L2 cache.- Parameters:
ids
- Ids of the objects- Returns:
- Persistable objects (with connected StateManager).
-
removeObjectFromLevel1Cache
void removeObjectFromLevel1Cache(Object id)
Method to remove an object from the L1 cache.- Parameters:
id
- The id of the object
-
removeObjectFromLevel2Cache
void removeObjectFromLevel2Cache(Object id)
Method to remove an object from the L2 cache.- Parameters:
id
- The id of the object
-
markFieldsForUpdateInLevel2Cache
void markFieldsForUpdateInLevel2Cache(Object id, boolean[] fields)
Method to mark the object with specifed id to have the supplied fields updated in the L2 cache at commit.- Parameters:
id
- Id of the objectfields
- The fields to update
-
hasIdentityInCache
boolean hasIdentityInCache(Object id)
Whether an object with the specified identity exists in the cache(s). Used as a check on identity (inheritance-level) validity- Parameters:
id
- The identity- Returns:
- Whether it exists
-
newObjectId
Object newObjectId(Class pcClass, Object key)
This method returns an object id instance corresponding to the pcClass and key arguments. Operates in 2 modes :-- The class uses SingleFieldIdentity and the key is the value of the key field
- In all other cases the key is the String form of the object id instance
- Parameters:
pcClass
- Class of the persistable object to create the identity forkey
- Value of the key for SingleFieldIdentity (or the toString value)- Returns:
- The new object-id instance
-
newObjectId
Object newObjectId(String className, Object pc)
This method returns an object id instance corresponding to the class name, and the passed object (when using app identity).- Parameters:
className
- Name of the class of the object.pc
- The persistable object. Used for application-identity- Returns:
- A new object ID.
-
getSerializeReadForClass
boolean getSerializeReadForClass(String className)
Convenience method to return the setting for serialize read for the current transaction for the specified class name. Returns the setting for the transaction (if set), otherwise falls back to the setting for the class, otherwise returns false.- Parameters:
className
- Name of the class- Returns:
- Setting for serialize read
-
assertClassPersistable
void assertClassPersistable(Class cls)
Convenience method to assert if the passed class is not persistable.- Parameters:
cls
- The class of which we want to persist objects- Throws:
ClassNotPersistableException
- When the class is not persistableNoPersistenceInformationException
- When the class has no available persistence information
-
hasPersistenceInformationForClass
boolean hasPersistenceInformationForClass(Class cls)
Utility method to check if the specified class has reachable metadata or annotations.- Parameters:
cls
- The class to check- Returns:
- Whether the class has reachable metadata or annotations
-
isInserting
boolean isInserting(Object pc)
Tests whether this persistable object is being inserted.- Parameters:
pc
- the object to verify the status- Returns:
- true if this instance is inserting.
-
isFlushing
boolean isFlushing()
Accessor for whether the ExecutionContext is flushing changes to the datastore.- Returns:
- Whether it is currently flushing
-
getFlushMode
FlushMode getFlushMode()
Accessor for the flush mode. Whether to auto-commit, or whether to delay flushing.- Returns:
- The flush mode.
-
isDelayDatastoreOperationsEnabled
boolean isDelayDatastoreOperationsEnabled()
Whether the datastore operations are delayed until commit. In optimistic transactions this is automatically enabled.- Returns:
- true if datastore operations are delayed until commit
-
isRunningDetachAllOnCommit
boolean isRunningDetachAllOnCommit()
Accessor for whether this ExecutionContext is currently running detachAllOnCommit.- Returns:
- Whether running detachAllOnCommit
-
flush
void flush()
Method callable from external APIs for user-management of flushing. Called by JDO PM.flush, or JPA EM.flush(). Performs management of relations, prior to performing internal flush of all dirty/new/deleted instances to the datastore.
-
flushInternal
void flushInternal(boolean flushToDatastore)
Method to flushes all dirty, new, and deleted instances to the datastore. It has no effect if a transaction is not active. If a datastore transaction is active, this method synchronizes the cache with the datastore and reports any exceptions. If an optimistic transaction is active, this method obtains a datastore connection and synchronizes the cache with the datastore using this connection. The connection obtained by this method is held until the end of the transaction.- Parameters:
flushToDatastore
- Whether to ensure any changes reach the datastore Otherwise they will be flushed to the datastore manager and leave it to decide the opportune moment to actually flush them to teh datastore- Throws:
NucleusOptimisticException
- when optimistic locking error(s) occur
-
getOperationQueue
OperationQueue getOperationQueue()
Accessor for the operation queue. The queue can be null if there are no operations queued (txn not active, not optimistic, no ops arrived yet).- Returns:
- The operation queue (typically for collections/maps)
-
operationQueueIsActive
boolean operationQueueIsActive()
Accessor for whether the operation queue is currently active. Will return false if not delaying flush, or not in a transaction, or flushing.- Returns:
- Whether the operation queue is active for adding operations
-
addOperationToQueue
void addOperationToQueue(Operation oper)
Method to add an operation to the queue.- Parameters:
oper
- The operation to add
-
flushOperationsForBackingStore
void flushOperationsForBackingStore(Store backingStore, DNStateManager sm)
Method to flush all queued operations for the specified backing store (if any).- Parameters:
backingStore
- The backing storesm
- StateManager
-
getObjectsToBeFlushed
List<DNStateManager> getObjectsToBeFlushed()
Convenience method to inspect the list of objects with outstanding changes to flush.- Returns:
- StateManagers for the objects to be flushed.
-
getMultithreaded
boolean getMultithreaded()
Accessor for whether this context is multithreaded.- Returns:
- Whether multithreaded (and hence needing locking)
-
getManageRelations
boolean getManageRelations()
Whether managed relations are supported by this execution context.- Returns:
- Supporting managed relations
-
getRelationshipManager
RelationshipManager getRelationshipManager(DNStateManager sm)
Accessor for the RelationshipManager for the provided StateManager.- Parameters:
sm
- StateManager- Returns:
- The RelationshipManager
-
isManagingRelations
boolean isManagingRelations()
Returns whether this ExecutionContext is currently performing the manage relationships task.- Returns:
- Whether in the process of managing relations
-
getCallbackHandler
CallbackHandler getCallbackHandler()
Retrieve the callback handler for this ExecutionContext.- Returns:
- the callback handler
-
getInternalFetchGroup
FetchGroup getInternalFetchGroup(Class cls, String name)
Accessor for an internal fetch group for the specified class.- Parameters:
cls
- The classname
- Name of the group- Returns:
- The FetchGroup
-
addInternalFetchGroup
void addInternalFetchGroup(FetchGroup grp)
Method to add an internal fetch group to this ExecutionContext.- Parameters:
grp
- The internal fetch group
-
getFetchGroupsWithName
Set<FetchGroup> getFetchGroupsWithName(String name)
Accessor for the fetch groups for the specified name.- Parameters:
name
- Name of the group- Returns:
- The FetchGroup
-
getTenantId
String getTenantId()
Accessor for the tenant id, for this ExecutionContext.- Returns:
- The tenant id for this context.
-
getCurrentUser
String getCurrentUser()
Accessor for the current user, for this ExecutionContext.- Returns:
- The current user for this context
-
threadLock
default void threadLock()
Method to lock this ExecutionContext for threading
-
threadUnlock
default void threadUnlock()
Method to unlock this ExecutionContext for threading
-
newInstance
<T> T newInstance(Class<T> cls)
Method to generate an instance of an interface, abstract class, or concrete PC class.- Type Parameters:
T
- Type of the persistable object- Parameters:
cls
- The class of the interface or abstract class, or concrete class defined in MetaData- Returns:
- The instance of this type
-
isObjectModifiedInTransaction
boolean isObjectModifiedInTransaction(Object id)
Accessor for whether the object with this identity is modified in the current transaction.- Parameters:
id
- The identity.- Returns:
- Whether it is modified/new/deleted in this transaction
-
replaceObjectId
void replaceObjectId(Persistable pc, Object oldID, Object newID)
Replace the previous object id for a PC object to a new- Parameters:
pc
- The Persistable objectoldID
- the old idnewID
- the new id
-
getAttachDetachReferencedObject
Object getAttachDetachReferencedObject(DNStateManager sm)
Access a referenced object for this StateManager during the attach/detach process. When attaching and this is the detached object this returns the newly attached object. When attaching and this is the newly attached object this returns the detached object. When detaching and this is the newly detached object this returns the attached object. When detaching and this is the attached object this returns the newly detached object.- Parameters:
sm
- StateManager- Returns:
- The referenced object (if any)
-
setAttachDetachReferencedObject
void setAttachDetachReferencedObject(DNStateManager sm, Object obj)
Register a referenced object against this StateManager for the attach/detach process.- Parameters:
sm
- StateManagerobj
- The referenced object (or null to clear out any reference)
-
registerEmbeddedRelation
ExecutionContext.EmbeddedOwnerRelation registerEmbeddedRelation(DNStateManager ownerSM, int ownerMemberNum, PersistableObjectType objectType, DNStateManager embSM)
Method to register an embedded relation for the specified member of the owner StateManager where the embedded StateManager is stored.- Parameters:
ownerSM
- Owner StateManagerownerMemberNum
- Member number that is embeddedobjectType
- Type of object being persistedembSM
- StateManager of the embedded object- Returns:
- The EmbeddedOwnerRelation
-
deregisterEmbeddedRelation
void deregisterEmbeddedRelation(ExecutionContext.EmbeddedOwnerRelation rel)
Method to deregister the specified embedded relation (e.g when the embedded object is disconnected).- Parameters:
rel
- The embedded relation
-
getEmbeddedInformationForOwner
List<ExecutionContext.EmbeddedOwnerRelation> getEmbeddedInformationForOwner(DNStateManager ownerSM)
Accessor for the relations for the specified embedded StateManager where it is embedded.- Parameters:
ownerSM
- StateManager that owns the embedded- Returns:
- The List of embedded relations involving this StateManager as owner
-
getOwnerInformationForEmbedded
ExecutionContext.EmbeddedOwnerRelation getOwnerInformationForEmbedded(DNStateManager embSM)
Accessor for the owner relation for the specified embedded StateManager where it is embedded.- Parameters:
embSM
- StateManager that is embedded- Returns:
- The embedded relation info involving this (embedded) StateManager
-
getOwnerForEmbeddedStateManager
DNStateManager getOwnerForEmbeddedStateManager(DNStateManager embSM)
Accessor for the owner StateManager for the provided embedded StateManager.- Parameters:
embSM
- StateManager that is embedded- Returns:
- The owner StateManager that have this object embedded.
-
removeEmbeddedOwnerRelation
void removeEmbeddedOwnerRelation(DNStateManager ownerSM, int ownerFieldNum, DNStateManager embSM)
Convenience method to remove the EmbeddedOwnerRelation between the specified StateManagers.- Parameters:
ownerSM
- Owner StateManagerownerFieldNum
- Field in ownerembSM
- Embedded StateManager
-
setStateManagerAssociatedValue
void setStateManagerAssociatedValue(DNStateManager sm, Object key, Object value)
-
getStateManagerAssociatedValue
Object getStateManagerAssociatedValue(DNStateManager sm, Object key)
-
removeStateManagerAssociatedValue
void removeStateManagerAssociatedValue(DNStateManager sm, Object key)
-
containsStateManagerAssociatedValue
boolean containsStateManagerAssociatedValue(DNStateManager sm, Object key)
-
registerExecutionContextListener
void registerExecutionContextListener(ExecutionContextListener listener)
Register a listener to be called when this ExecutionContext is closing.- Parameters:
listener
- The listener
-
deregisterExecutionContextListener
void deregisterExecutionContextListener(ExecutionContextListener listener)
Deregister a listener from calling when this ExecutionContext is closing.- Parameters:
listener
- The listener
-
closeCallbackHandler
void closeCallbackHandler()
Close the callback handler, and disconnect any registered instance listeners. Used by JCA.
-
-