Package org.datanucleus
Interface ExecutionContext
- All Superinterfaces:
ExecutionContextReference
- All Known Implementing Classes:
ExecutionContextImpl
,ExecutionContextThreadedImpl
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 ClassesModifier and TypeInterfaceDescriptionstatic class
static interface
Interface to be implemented by a listener for the closure of the ExecutionContext. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Startup option setting whether, when using JTA, to do auto-join of transactions.static final String
Startup option overriding the default (PMF/EMF) password for the connectionURL.static final String
Startup option overriding the default (PMF/EMF) username for the connectionURL. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Method to add an internal fetch group to this ExecutionContext.void
addOperationToQueue
(Operation oper) Method to add an operation to the queue.void
Method to add the object managed by the specified StateManager to the cache.void
Convenience method to assert if the passed class is not persistable.<T> void
attachObject
(DNStateManager ownerSM, T pc, boolean sco) Method to attach a persistent detached object.<T> T
attachObjectCopy
(DNStateManager ownerSM, T pc, boolean sco) Method to attach a persistent detached object returning an attached copy of the object.void
Method to mark as clean all StateManagers of dirty objects.void
Mark the specified StateManager as clean.void
close()
Method to close the execution context.void
Close the callback handler, and disconnect any registered instance listeners.boolean
void
deleteObject
(Object obj) Method to delete an object from the datastore.void
Method to delete an object from persistence which should be called from internal calls only.void
deleteObjects
(Object... objs) Method to delete an array of objects from the datastore.void
Method to deregister the specified embedded relation (e.g when the embedded object is disconnected).void
Deregister a listener from calling when this ExecutionContext is closing.void
Method to detach all objects in the context.<T> void
detachObject
(FetchPlanState state, T pc) Method to detach a persistent object without making a copy.<T> T
detachObjectCopy
(FetchPlanState state, T pc) Detach a copy of the passed persistent object using the provided detach state.void
detachObjects
(FetchPlanState state, Object... pcs) Method to detach the passed object(s).void
Method to enlist the specified StateManager in the current transaction.void
Method to evict all L1 cache objectsvoid
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
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".findObject
(Object id, boolean validate) Shortcut to calling "findObject(id, validate, validate, null)".findObject
(Object id, boolean validate, boolean checkInheritance, String objectClassName) Accessor for an object given the object id.findObject
(Object id, FieldValues fv, Class pcClass, boolean ignoreCache, boolean checkInheritance) Accessor for an object given the object id and a set of field values to apply to it.<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<Object> keys) Accessor for objects of the specified type, with the provided id "key"s.findObjectsById
(Object[] ids, boolean validate) Accessor for objects with the specified identities.Method to find StateManager for the passed persistable object when it is managed by this manager.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.findStateManagerForEmbedded
(Object value, DNStateManager owner, AbstractMemberMetaData mmd, PersistableObjectType objectType) Method to find StateManager for the passed embedded persistable object.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
Accessor for the API adapter.Access a referenced object for this StateManager during the attach/detach process.Convenience method to return the attached object for the specified id if one exists.getBooleanProperty
(String name) Accessor for a boolean property value.Retrieve the callback handler for this ExecutionContext.Accessor for the ClassLoader resolver to use in class loading issues.Accessor for the current user, for this ExecutionContext.Accessor for the relations for the specified embedded StateManager where it is embedded.<T> Extent
<T> Accessor for the Extent for a class (and optionally its subclasses).getFetchGroupsWithName
(String name) Accessor for the fetch groups for the specified name.Acessor for the current FetchPlanAccessor for the flush mode.getInternalFetchGroup
(Class cls, String name) Accessor for an internal fetch group for the specified class.getIntProperty
(String name) Accessor for an int property value.Accessor for the lock manager for objects in this execution context.Accessor for the currently managed objects for the current transaction.getManagedObjects
(Class[] classes) Accessor for the currently managed objects for the current transaction.getManagedObjects
(String[] states) Accessor for the currently managed objects for the current transaction.getManagedObjects
(String[] states, Class[] classes) Accessor for the currently managed objects for the current transaction.boolean
Whether managed relations are supported by this execution context.default MetaDataManager
Accessor for the MetaData Manager.boolean
Accessor for whether this context is multithreaded.Accessor for the context in which this execution context is running.Convenience method to access an object in the cache.getObjectsFromCache
(Object[] ids) Convenience method to access objects in the cache.Convenience method to inspect the list of objects with outstanding changes to flush.Accessor for the operation queue.Accessor for the owner StateManager for the provided embedded StateManager.Accessor for the owner relation for the specified embedded StateManager where it is embedded.Accessor for the defined properties.getProperty
(String name) Accessor for a property.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.Accessor for any statistics-gathering object.default StoreManager
Accessor for the Store Manager.getStringProperty
(String name) Accessor for a String property value.Accessor for the supported property names.Accessor for the tenant id, for this ExecutionContext.Accessor for the current transaction for this execution context.default TypeManager
Convenience accessor for the type manager for this persistence context (from NucleusContext).boolean
Whether an object with the specified identity exists in the cache(s).boolean
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
Whether the datastore operations are delayed until commit/flush.boolean
Method to return if an object is enlisted in the current transaction.boolean
Accessor for whether the ExecutionContext is flushing changes to the datastore.boolean
isInserting
(Object pc) Tests whether this persistable object is being inserted.boolean
Returns whether this ExecutionContext is currently performing the manage relationships task.boolean
Accessor for whether the object with this identity is modified in the current transaction.boolean
Accessor for whether this ExecutionContext is currently running detachAllOnCommit.void
Method to make the passed object nontransactional.void
Method to make an object transactional.void
makeObjectTransient
(Object pc, FetchPlanState state) Method to migrate an object to transient state.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.newObjectId
(Class pcClass, Object key) This method returns an object id instance corresponding to the pcClass and key arguments.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
Accessor for whether the operation queue is currently active.<T> T
persistObject
(T pc, boolean merging) Method to make an object persistent.default <T> T
persistObjectInternal
(T pc, FieldValues preInsertChanges, PersistableObjectType objectType) Method to make an object persistent which should be called from INTERNAL (DataNucleus) calls only.<T> T
persistObjectInternal
(T pc, FieldValues preInsertChanges, PersistableObjectType objectType, DNStateManager ownerSM, int ownerFieldNum) Method to make an object persistent which should be called from INTERNAL (DataNucleus) calls only.Object[]
persistObjects
(Object... pcs) Method to persist an array of objects to the datastore.void
Method to process any outstanding non-transactional updates that are queued.void
Method to put a Persistable object associated to StateManager into the L1 cache.void
putObjectIntoLevel2Cache
(DNStateManager sm, boolean updateIfPresent) Method to add/update the managed object into the L2 cache as long as it isn't modified in the current transaction.void
Method to do a refresh of all objects.void
refreshObject
(Object pc) Method to do a refresh of an object, updating it from its datastore representation.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
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
Method to remove an object from the L1 cache.void
Method to remove an object from the L2 cache.void
void
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
Register a referenced object against this StateManager for the attach/detach process.void
setProperties
(Map<String, Object> 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
Method to lock this ExecutionContext for threadingdefault void
Method to unlock this ExecutionContext for threadingMethods inherited from interface org.datanucleus.enhancement.ExecutionContextReference
getOwner
-
Field Details
-
OPTION_USERNAME
Startup option overriding the default (PMF/EMF) username for the connectionURL.- See Also:
-
OPTION_PASSWORD
Startup option overriding the default (PMF/EMF) password for the connectionURL.- See Also:
-
OPTION_JTA_AUTOJOIN
Startup option setting whether, when using JTA, to do auto-join of transactions.- See Also:
-
-
Method Details
-
initialise
-
getLevel1Cache
Level1Cache getLevel1Cache() -
getTransaction
Transaction getTransaction()Accessor for the current transaction for this execution context.- Returns:
- The current transaction
-
getStoreManager
Accessor for the Store Manager.- Returns:
- Store Manager
-
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
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
Method to set properties on the execution context.- Parameters:
props
- The properties
-
setProperty
Method to set a property on the execution context- Parameters:
name
- Name of the propertyvalue
- Value to set
-
getProperty
Accessor for a property.- Parameters:
name
- Name of the property- Returns:
- The value
-
getBooleanProperty
Accessor for a boolean property value.- Parameters:
name
- Name of the property- Returns:
- the value
-
getIntProperty
Accessor for an int property value.- Parameters:
name
- Name of the property- Returns:
- the value
-
getStringProperty
Accessor for a String property value.- Parameters:
name
- Name of the property- Returns:
- The value
-
getProperties
Accessor for the defined properties.- Returns:
- Properties for this execution context
-
getSupportedProperties
Accessor for the supported property names.- Returns:
- Set of names
-
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
Method to find StateManager for the passed persistable object when it is managed by this manager. TODO Change the signature to use generics- Parameters:
pc
- The persistable object- Returns:
- StateManager
-
findStateManager
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
-
addStateManagerToCache
Method to add the object managed by the specified StateManager to the cache.- Parameters:
sm
- StateManager
-
removeStateManagerFromCache
Method to remove the object managed by the specified StateManager from the cache.- Parameters:
sm
- StateManager
-
evictObject
Method to evict the passed object.- Parameters:
pc
- The object
-
evictObjects
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
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 make an object persistent. Should be called by EXTERNAL APIs (JDO/JPA) only. All INTERNAL (DataNucleus) calls should go via persistObjectInternal(...).- Type Parameters:
T
- Type of the persistable object- Parameters:
pc
- The objectmerging
- Whether this object (and dependents) is being merged- Returns:
- The persisted object
- Throws:
NucleusUserException
- if the object is managed by a different manager
-
persistObjects
Method to persist an array of objects to the datastore. Should be called by EXTERNAL APIs (JDO/JPA) only.- Parameters:
pcs
- The objects to persist- Returns:
- The persisted objects
- Throws:
NucleusUserException
- Thrown if an error occurs during the persist process. Any exception could have several nested exceptions for each failed object persist
-
persistObjectInternal
default <T> T persistObjectInternal(T pc, FieldValues preInsertChanges, PersistableObjectType objectType) Method to make an object persistent which should be called from INTERNAL (DataNucleus) calls only. All EXTERNAL (PM/EM) calls should go via persistObject(Object pc). To be used when not providing the owner object details that this is part of (embedded).- 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
- Throws:
NucleusUserException
- if the object is managed by a different context
-
persistObjectInternal
<T> T persistObjectInternal(T pc, FieldValues preInsertChanges, PersistableObjectType objectType, DNStateManager ownerSM, int ownerFieldNum) Method to make an object persistent which should be called from INTERNAL (DataNucleus) calls only. All EXTERNAL (PM/EM) calls should go via persistObject(Object pc). To be used when providing the owner object details that this is part of (embedded).- Type Parameters:
T
- Type of the persistable object- Parameters:
pc
- The objectpreInsertChanges
- Any changes to make before insertingobjectType
- Type of objectownerSM
- StateManager of the owner when embedded (or attached?) (null if not embedded)ownerFieldNum
- Field number in the owner where this is embedded (or attached?) (-1 if not embedded)- Returns:
- The persisted object
- Throws:
NucleusUserException
- if the object is managed by a different context
-
makeObjectTransient
Method to migrate an object to transient state.- Parameters:
pc
- The objectstate
- Object containing the state of the fetch plan process (if any)- Throws:
NucleusException
- When an error occurs in making the object transient
-
makeObjectTransactional
Method to make an object transactional.- Parameters:
pc
- The object- Throws:
NucleusException
- Thrown when an error occurs
-
makeObjectNontransactional
Method to make the passed object nontransactional.- Parameters:
pc
- The object- Throws:
NucleusException
- Thrown when an error occurs
-
exists
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
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
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
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
Method to delete an object from the datastore. NOT to be called by internal methods. Only callable by external APIs (JDO/JPA).- Parameters:
obj
- The object
-
deleteObjects
Method to delete an array of objects from the datastore.- Parameters:
objs
- The objects to delete- Throws:
NucleusUserException
- Thrown if an error occurs during the deletion process. Any exception could have several nested exceptions for each failed object deletion
-
deleteObjectInternal
Method to delete an object from persistence which should be called from internal calls only. All PM/EM calls should go via deleteObject(Object obj).- Parameters:
pc
- Object to delete
-
detachObject
Method to detach a persistent object without making a copy. Note that also all the objects which are refered to from this object are detached. If the object is of class that is not detachable a ClassNotDetachableException will be thrown. If the object is not persistent a NucleusUserException is thrown.- Type Parameters:
T
- Type of the persistable object- Parameters:
state
- State for the detachment processpc
- The object
-
detachObjects
Method to detach the passed object(s).- Parameters:
state
- State for the detachment process.pcs
- The object(s) to detach
-
detachObjectCopy
Detach a copy of the passed persistent object using the provided detach state. If the object is of class that is not detachable it will be detached as transient. If it is not yet persistent it will be first persisted.- Type Parameters:
T
- Type of the persistable object- Parameters:
state
- State for the detachment processpc
- The object- Returns:
- The detached object
-
detachAll
void detachAll()Method to detach all objects in the context. Detaches all objects enlisted as well as all objects in the L1 cache. Of particular use with JPA when doing a clear of the persistence context. -
attachObject
Method to attach a persistent detached object. If a different object with the same identity as this object exists in the L1 cache then an exception will be thrown.- Type Parameters:
T
- Type of the persistable object- Parameters:
ownerSM
- StateManager of the owner object that has this in a field that causes this attachpc
- The persistable objectsco
- Whether the PC object is stored without an identity (embedded/serialised)
-
attachObjectCopy
Method to attach a persistent detached object returning an attached copy of the object. If the object is of class that is not detachable, a ClassNotDetachableException will be thrown.- Type Parameters:
T
- Type of the persistable object- Parameters:
ownerSM
- StateManager of the owner object that has this in a field that causes this attachpc
- The objectsco
- Whether it has no identity (second-class object)- Returns:
- The attached object
-
getAttachedObjectForId
Convenience method to return the attached object for the specified id if one exists. Returns null if there is no currently enlisted/cached object with the specified id.- Parameters:
id
- The id- Returns:
- The attached object
-
refreshObject
Method to do a refresh of an object, updating it from its datastore representation. Also updates the object in the L1/L2 caches.- Parameters:
pc
- The object
-
refreshAllObjects
void refreshAllObjects()Method to do a refresh of all objects.- Throws:
NucleusUserException
- thrown if instances could not be refreshed.
-
enlistInTransaction
Method to enlist the specified StateManager in the current transaction.- Parameters:
sm
- StateManager
-
evictFromTransaction
Method to evict the specified StateManager from the current transaction.- Parameters:
sm
- StateManager
-
isEnlistedInTransaction
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
-
markDirty
Mark the specified StateManager as dirty- Parameters:
sm
- StateManagerdirectUpdate
- Whether the object has had a direct update made on it (if known)
-
clearDirty
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
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 for this id.
-
findObjects
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
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
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
Accessor for objects with the specified identities.- Parameters:
ids
- Identities of the object(s).validate
- Whether to validate the object state- Returns:
- The 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 and a set of field values to apply to it. This is intended for use where we have done a query and have the id from the results, and we want to create the object, preferably using the cache, and then apply any field values to it.- Parameters:
id
- Id of the object.fv
- Field values for the object (to copy in)pcClass
- the type which the object is (optional). Used to instantiate the objectignoreCache
- true if it must ignore the cachecheckInheritance
- Whether to check the inheritance on the id of the object- Returns:
- The Object
-
getExtent
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
Method to put a Persistable object associated to StateManager into the L1 cache.- Parameters:
sm
- StateManager
-
putObjectIntoLevel2Cache
Method to add/update the managed object into the L2 cache as long as it isn't modified in the current transaction.- Parameters:
sm
- StateManager for the objectupdateIfPresent
- Whether to update it in the L2 cache if already present
-
getObjectFromCache
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
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
Method to remove an object from the L1 cache.- Parameters:
id
- The id of the object
-
removeObjectFromLevel2Cache
Method to remove an object from the L2 cache.- Parameters:
id
- The id of the object
-
markFieldsForUpdateInLevel2Cache
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
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
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
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
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
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
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
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/flush. In optimistic transactions this is automatically enabled. In datastore transactions there is a persistence property to enable it. If we are committing/flushing then will return false since the delay is no longer required.- 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
Method to add an operation to the queue.- Parameters:
oper
- The operation to add
-
flushOperationsForBackingStore
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
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
Accessor for an internal fetch group for the specified class.- Parameters:
cls
- The classname
- Name of the group- Returns:
- The FetchGroup
-
addInternalFetchGroup
Method to add an internal fetch group to this ExecutionContext.- Parameters:
grp
- The internal fetch group
-
getFetchGroupsWithName
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
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
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
Replace the previous object id for a PC object to a new- Parameters:
pc
- The Persistable objectoldID
- the old idnewID
- the new id
-
getAttachDetachReferencedObject
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
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
Method to deregister the specified embedded relation (e.g when the embedded object is disconnected).- Parameters:
rel
- The embedded relation
-
getEmbeddedInformationForOwner
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
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
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
Convenience method to remove the EmbeddedOwnerRelation between the specified StateManagers.- Parameters:
ownerSM
- Owner StateManagerownerFieldNum
- Field in ownerembSM
- Embedded StateManager
-
setStateManagerAssociatedValue
-
getStateManagerAssociatedValue
-
removeStateManagerAssociatedValue
-
containsStateManagerAssociatedValue
-
registerExecutionContextListener
Register a listener to be called when this ExecutionContext is closing.- Parameters:
listener
- The listener
-
deregisterExecutionContextListener
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.
-