org.datanucleus
Class MultithreadedObjectManager

java.lang.Object
  extended by org.datanucleus.ObjectManagerImpl
      extended by org.datanucleus.MultithreadedObjectManager
All Implemented Interfaces:
ExecutionContext, TransactionEventListener

public class MultithreadedObjectManager
extends ObjectManagerImpl

ObjectManager for handling the multithreaded PM/EM cases. Locks various methods in an attempt to prevent conflicting thread updates. Note we could have just put this code in ObjectManagerImpl. TODO Evaluate all of the places we currently lock (when multithreaded) to find corner cases not caught.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.datanucleus.store.ExecutionContext
ExecutionContext.LifecycleListener
 
Field Summary
 
Fields inherited from class org.datanucleus.ObjectManagerImpl
cache, LOCALISER, lock
 
Constructor Summary
MultithreadedObjectManager(NucleusContext ctx, Object owner, String userName, String password)
           
 
Method Summary
 void addObjectProvider(ObjectProvider op)
          Method to add the object managed by the specified ObjectProvider to the (L1) cache.
 void attachObject(ObjectProvider ownerOP, Object pc, boolean sco)
          Method to attach a persistent detached object.
 Object attachObjectCopy(ObjectProvider ownerOP, Object pc, boolean sco)
          Method to attach a persistent detached object returning an attached copy of the object.
 void clearDirty()
          Method to clear all objects marked as dirty (whether directly or indirectly).
 void clearDirty(ObjectProvider op)
          Method to clear an object from the list of dirty objects.
 void close()
          Method to close the Object Manager.
 void deleteObject(Object obj)
          Method to delete an object from the datastore.
 void deleteObjects(Object[] objs)
          Method to delete an array of objects from the datastore.
 void detachObject(Object obj, FetchPlanState state)
          Method to detach a persistent object without making a copy.
 Object detachObjectCopy(Object pc, FetchPlanState state)
          Detach a copy of the passed persistent object using the provided detach state.
 void enlistInTransaction(ObjectProvider sm)
          Method to enlist the specified ObjectProvider in the current transaction.
 void evictAllObjects()
          Method to evict all current objects from L1 cache.
 void evictFromTransaction(ObjectProvider sm)
          Method to evict the specified ObjectProvider from the current transaction.
 void evictObject(Object obj)
          Internal method to evict an object from L1 cache.
 ObjectProvider findObjectProvider(Object pc)
          Method to find the ObjectProvider for an object.
 void flush()
          Method callable from external APIs for user-management of flushing.
 void flushInternal(boolean flushToDatastore)
          This method flushes all dirty, new, and deleted instances to the datastore.
 Extent getExtent(Class pcClass, boolean subclasses)
          Extents are collections of datastore objects managed by the datastore, not by explicit user operations on collections.
 boolean getMultithreaded()
          Accessor for whether the object manager is multithreaded.
 void hereIsObjectProvider(ObjectProvider sm, Object pc)
          Method to add the ObjectProvider for an object to this ObjectManager's list.
 void makeObjectTransactional(Object obj)
          Method to make an object transactional.
 void makeObjectTransient(Object obj, FetchPlanState state)
          Method to migrate an object to transient state.
 void markDirty(ObjectProvider op, boolean directUpdate)
          Method to mark an object (ObjectProvider) as dirty.
 Query newQuery()
          Construct an empty query instance.
 Object persistObject(Object obj, boolean merging)
          Method to make an object persistent.
 Object[] persistObjects(Object[] objs)
          Method to persist an array of objects to the datastore.
 void processNontransactionalUpdate()
          Method called when a non-tx update has been performed (via setter call on the persistable object, or via use of mutator methods of a field).
 void refreshObject(Object obj)
          Method to do a refresh of an object, updating it from its datastore representation.
 void removeObjectProvider(ObjectProvider op)
          Method to remove the object managed by the specified ObjectProvider from the cache.
 void replaceObjectId(Object pc, Object oldID, Object newID)
          Replace the previous object id for a persistable object with a new one.
 void retrieveObject(Object obj, boolean fgOnly)
          Method to retrieve an object.
 
Methods inherited from class org.datanucleus.ObjectManagerImpl
acquireThreadContextInfo, addInternalFetchGroup, addListener, assertActiveTransaction, assertClassPersistable, assertDetachable, assertHasImplementationCreator, assertIsOpen, assertNotDetached, deleteObjectInternal, detachAll, disconnectLifecycleListener, disconnectObjectProvidersFromCache, evictObjects, exists, findObject, findObject, findObjectProvider, findObjectProviderForEmbedded, findObjects, flushInternalNonReferential, flushInternalWithOrdering, getApiAdapter, getAttachedObjectForId, getBooleanProperty, getCallbackHandler, getClassLoaderResolver, getCopyOnAttach, getDatastoreReadTimeoutMillis, getDatastoreWriteTimeoutMillis, getDetachAllOnCommit, getDetachAllOnRollback, getDetachOnClose, getFetchGroupManager, getFetchGroupsWithName, getFetchPlan, getIgnoreCache, getInternalFetchGroup, getIntProperty, getL2CacheableObject, getLock, getLockManager, getManagedObjects, getManagedObjects, getManagedObjects, getManagedObjects, getManageRelations, getManageRelationsChecks, getMetaDataManager, getNucleusContext, getObjectFromCache, getObjectFromLevel1Cache, getObjectFromLevel2Cache, getObjectsFromLevel2Cache, getObjectsToBeFlushed, getOwner, getProperties, getProperty, getReachabilityAtCommit, getRelationshipManager, getSerializeReadForClass, getStatistics, getStoreManager, getSupportedProperties, getThreadContextInfo, getTransaction, getTypeManager, hasIdentityInCache, hasPersistenceInformationForClass, initialiseLevel1Cache, isClosed, isDelayDatastoreOperationsEnabled, isEnlistedInTransaction, isFlushing, isInserting, isManagingRelations, isObjectModifiedInTransaction, isRunningDetachAllOnCommit, makeObjectNontransactional, newInstance, newObjectId, newObjectId, newObjectProviderForCachedPC, newObjectProviderForDetached, newObjectProviderForEmbedded, newObjectProviderForEmbedded, newObjectProviderForHollow, newObjectProviderForHollowPopulated, newObjectProviderForHollowPopulatedAppId, newObjectProviderForHollowPreConstructed, newObjectProviderForPersistentClean, newObjectProviderForPersistentNew, newObjectProviderForPNewToBeDeleted, newObjectProviderForTransactionalTransient, performManagedRelationships, persistObjectInternal, persistObjectInternal, persistObjectInternal, postBegin, postCommit, postRollback, preCommit, preRollback, processNontransactionalAtomicChanges, putObjectIntoLevel1Cache, putObjectIntoLevel2Cache, putObjectIntoLevel2CacheInternal, putObjectsIntoLevel2Cache, refreshAllObjects, releaseThreadContextInfo, removeAllInstanceLifecycleListeners, removeInternalFetchGroup, removeListener, removeObjectFromLevel1Cache, removeObjectFromLevel2Cache, setProperties, setProperty, transactionCommitted, transactionEnded, transactionFlushed, transactionPreCommit, transactionPreFlush, transactionPreRollBack, transactionRolledBack, transactionStarted
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultithreadedObjectManager

public MultithreadedObjectManager(NucleusContext ctx,
                                  Object owner,
                                  String userName,
                                  String password)
Parameters:
ctx - NucleusContext
owner - Owner object (PM, EM)
userName - Username for the datastore
password - Password for the datastore
Method Detail

getMultithreaded

public boolean getMultithreaded()
Accessor for whether the object manager is multithreaded.

Specified by:
getMultithreaded in interface ExecutionContext
Overrides:
getMultithreaded in class ObjectManagerImpl
Returns:
Whether to run multithreaded.

processNontransactionalUpdate

public void processNontransactionalUpdate()
Description copied from class: ObjectManagerImpl
Method called when a non-tx update has been performed (via setter call on the persistable object, or via use of mutator methods of a field). Only hands the update across to be "committed" if not part of an owning persist/delete call.

Specified by:
processNontransactionalUpdate in interface ExecutionContext
Overrides:
processNontransactionalUpdate in class ObjectManagerImpl

enlistInTransaction

public void enlistInTransaction(ObjectProvider sm)
Description copied from class: ObjectManagerImpl
Method to enlist the specified ObjectProvider in the current transaction.

Specified by:
enlistInTransaction in interface ExecutionContext
Overrides:
enlistInTransaction in class ObjectManagerImpl
Parameters:
sm - The ObjectProvider

evictFromTransaction

public void evictFromTransaction(ObjectProvider sm)
Description copied from class: ObjectManagerImpl
Method to evict the specified ObjectProvider from the current transaction.

Specified by:
evictFromTransaction in interface ExecutionContext
Overrides:
evictFromTransaction in class ObjectManagerImpl
Parameters:
sm - The ObjectProvider

addObjectProvider

public void addObjectProvider(ObjectProvider op)
Description copied from class: ObjectManagerImpl
Method to add the object managed by the specified ObjectProvider to the (L1) cache.

Specified by:
addObjectProvider in interface ExecutionContext
Overrides:
addObjectProvider in class ObjectManagerImpl
Parameters:
op - The ObjectProvider

removeObjectProvider

public void removeObjectProvider(ObjectProvider op)
Description copied from class: ObjectManagerImpl
Method to remove the object managed by the specified ObjectProvider from the cache.

Specified by:
removeObjectProvider in interface ExecutionContext
Overrides:
removeObjectProvider in class ObjectManagerImpl
Parameters:
op - The ObjectProvider

findObjectProvider

public ObjectProvider findObjectProvider(Object pc)
Description copied from class: ObjectManagerImpl
Method to find the ObjectProvider for an object.

Specified by:
findObjectProvider in interface ExecutionContext
Overrides:
findObjectProvider in class ObjectManagerImpl
Parameters:
pc - The object we are checking
Returns:
The ObjectProvider, null if not found.

hereIsObjectProvider

public void hereIsObjectProvider(ObjectProvider sm,
                                 Object pc)
Description copied from class: ObjectManagerImpl
Method to add the ObjectProvider for an object to this ObjectManager's list.

Specified by:
hereIsObjectProvider in interface ExecutionContext
Overrides:
hereIsObjectProvider in class ObjectManagerImpl
Parameters:
sm - The ObjectProvider
pc - The object managed by the ObjectProvider

close

public void close()
Description copied from class: ObjectManagerImpl
Method to close the Object Manager.

Specified by:
close in interface ExecutionContext
Overrides:
close in class ObjectManagerImpl

evictObject

public void evictObject(Object obj)
Description copied from class: ObjectManagerImpl
Internal method to evict an object from L1 cache.

Specified by:
evictObject in interface ExecutionContext
Overrides:
evictObject in class ObjectManagerImpl
Parameters:
obj - The object

refreshObject

public void refreshObject(Object obj)
Description copied from class: ObjectManagerImpl
Method to do a refresh of an object, updating it from its datastore representation. Also updates the object in the L1/L2 caches.

Specified by:
refreshObject in interface ExecutionContext
Overrides:
refreshObject in class ObjectManagerImpl
Parameters:
obj - The Object

retrieveObject

public void retrieveObject(Object obj,
                           boolean fgOnly)
Description copied from class: ObjectManagerImpl
Method to retrieve an object.

Specified by:
retrieveObject in interface ExecutionContext
Overrides:
retrieveObject in class ObjectManagerImpl
Parameters:
obj - The object
fgOnly - Whether to retrieve the current fetch group fields only

persistObject

public Object persistObject(Object obj,
                            boolean merging)
Description copied from class: ObjectManagerImpl
Method to make an object persistent. NOT to be called by internal DataNucleus methods. Only callable by external APIs (JDO/JPA).

Specified by:
persistObject in interface ExecutionContext
Overrides:
persistObject in class ObjectManagerImpl
Parameters:
obj - The object
merging - Whether this object (and dependents) is being merged
Returns:
The persisted object

persistObjects

public Object[] persistObjects(Object[] objs)
Description copied from class: ObjectManagerImpl
Method to persist an array of objects to the datastore.

Specified by:
persistObjects in interface ExecutionContext
Overrides:
persistObjects in class ObjectManagerImpl
Parameters:
objs - The objects to persist
Returns:
The persisted objects

deleteObject

public void deleteObject(Object obj)
Description copied from class: ObjectManagerImpl
Method to delete an object from the datastore. NOT to be called by internal methods. Only callable by external APIs (JDO/JPA).

Specified by:
deleteObject in interface ExecutionContext
Overrides:
deleteObject in class ObjectManagerImpl
Parameters:
obj - The object

deleteObjects

public void deleteObjects(Object[] objs)
Description copied from class: ObjectManagerImpl
Method to delete an array of objects from the datastore.

Specified by:
deleteObjects in interface ExecutionContext
Overrides:
deleteObjects in class ObjectManagerImpl
Parameters:
objs - The objects

makeObjectTransient

public void makeObjectTransient(Object obj,
                                FetchPlanState state)
Description copied from class: ObjectManagerImpl
Method to migrate an object to transient state.

Specified by:
makeObjectTransient in interface ExecutionContext
Overrides:
makeObjectTransient in class ObjectManagerImpl
Parameters:
obj - The object
state - Object containing the state of the fetch plan process (if any)

makeObjectTransactional

public void makeObjectTransactional(Object obj)
Description copied from class: ObjectManagerImpl
Method to make an object transactional.

Specified by:
makeObjectTransactional in interface ExecutionContext
Overrides:
makeObjectTransactional in class ObjectManagerImpl
Parameters:
obj - The object

attachObject

public void attachObject(ObjectProvider ownerOP,
                         Object pc,
                         boolean sco)
Description copied from class: ObjectManagerImpl
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.

Specified by:
attachObject in interface ExecutionContext
Overrides:
attachObject in class ObjectManagerImpl
Parameters:
ownerOP - ObjectProvider of the owner object that has this in a field that causes this attach
pc - The persistable object
sco - Whether the PC object is stored without an identity (embedded/serialised)

attachObjectCopy

public Object attachObjectCopy(ObjectProvider ownerOP,
                               Object pc,
                               boolean sco)
Description copied from class: ObjectManagerImpl
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.

Specified by:
attachObjectCopy in interface ExecutionContext
Overrides:
attachObjectCopy in class ObjectManagerImpl
Parameters:
ownerOP - ObjectProvider of the owner object that has this in a field that causes this attach
pc - The object
sco - Whether it has no identity (second-class object)
Returns:
The attached object

detachObject

public void detachObject(Object obj,
                         FetchPlanState state)
Description copied from class: ObjectManagerImpl
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. For internal use only

Specified by:
detachObject in interface ExecutionContext
Overrides:
detachObject in class ObjectManagerImpl
Parameters:
obj - The object
state - State for the detachment process

detachObjectCopy

public Object detachObjectCopy(Object pc,
                               FetchPlanState state)
Description copied from class: ObjectManagerImpl
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.

Specified by:
detachObjectCopy in interface ExecutionContext
Overrides:
detachObjectCopy in class ObjectManagerImpl
Parameters:
pc - The object
state - State for the detachment process
Returns:
The detached object

clearDirty

public void clearDirty(ObjectProvider op)
Description copied from class: ObjectManagerImpl
Method to clear an object from the list of dirty objects.

Specified by:
clearDirty in interface ExecutionContext
Overrides:
clearDirty in class ObjectManagerImpl
Parameters:
op - The ObjectProvider

clearDirty

public void clearDirty()
Description copied from class: ObjectManagerImpl
Method to clear all objects marked as dirty (whether directly or indirectly).

Specified by:
clearDirty in interface ExecutionContext
Overrides:
clearDirty in class ObjectManagerImpl

evictAllObjects

public void evictAllObjects()
Method to evict all current objects from L1 cache.

Specified by:
evictAllObjects in interface ExecutionContext
Overrides:
evictAllObjects in class ObjectManagerImpl

markDirty

public void markDirty(ObjectProvider op,
                      boolean directUpdate)
Description copied from class: ObjectManagerImpl
Method to mark an object (ObjectProvider) as dirty.

Specified by:
markDirty in interface ExecutionContext
Overrides:
markDirty in class ObjectManagerImpl
Parameters:
op - ObjectProvider
directUpdate - Whether the object has had a direct update made on it (if known)

flush

public void flush()
Description copied from class: ObjectManagerImpl
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.

Specified by:
flush in interface ExecutionContext
Overrides:
flush in class ObjectManagerImpl

flushInternal

public void flushInternal(boolean flushToDatastore)
Description copied from class: ObjectManagerImpl
This method flushes all dirty, new, and deleted instances to the datastore.

Specified by:
flushInternal in interface ExecutionContext
Overrides:
flushInternal in class ObjectManagerImpl
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 the datastore

replaceObjectId

public void replaceObjectId(Object pc,
                            Object oldID,
                            Object newID)
Description copied from class: ObjectManagerImpl
Replace the previous object id for a persistable object with a new one. This is used where we have already added the object to the cache(s) and/or enlisted it in the txn before its real identity was fixed (attributed in the datastore).

Specified by:
replaceObjectId in interface ExecutionContext
Overrides:
replaceObjectId in class ObjectManagerImpl
Parameters:
pc - The Persistable object
oldID - the old id it was known by
newID - the new id

getExtent

public Extent getExtent(Class pcClass,
                        boolean subclasses)
Description copied from class: ObjectManagerImpl
Extents are collections of datastore objects managed by the datastore, not by explicit user operations on collections. Extent capability is a boolean property of classes that are persistence capable. If an instance of a class that has a managed extent is made persistent via reachability, the instance is put into the extent implicitly.

Specified by:
getExtent in interface ExecutionContext
Overrides:
getExtent in class ObjectManagerImpl
Parameters:
pcClass - The class to query
subclasses - Whether to include subclasses in the query.
Returns:
returns an Extent that contains all of the instances in the parameter class, and if the subclasses flag is true, all of the instances of the parameter class and its subclasses.

newQuery

public Query newQuery()
Description copied from class: ObjectManagerImpl
Construct an empty query instance.

Specified by:
newQuery in interface ExecutionContext
Overrides:
newQuery in class ObjectManagerImpl
Returns:
The query


Copyright © 2012. All Rights Reserved.