org.castor.persist
Class ObjectTracker

java.lang.Object
  extended by org.castor.persist.ObjectTracker

public final class ObjectTracker
extends java.lang.Object

A transaction records all objects accessed during the lifetime of the transaction in this record (queries and created). This information, stored on a per-object basis within the ObjectTracker, covers the database engine used to persist the object, the object's OID, the object itself, and whether the object has been deleted in this transaction, created in this transaction. Sidenote: Objects identified as read only are not updated when the transaction commits.

Since:
0.9.9
Version:
$Revision: 7951 $ $Date: 2006-04-29 09:15:50 -0600 (Sat, 29 Apr 2006) $
Author:
Ralf Joachim, Werner Guttmann, Gregory Block

Constructor Summary
ObjectTracker()
           
 
Method Summary
 java.lang.String allObjectStates()
           
 void clear()
          Reset ObjectTracker's state.
 ClassMolder getMolderForObject(java.lang.Object o)
          Retrieve the ClassMolder associated with a specific object.
 java.lang.Object getObjectForOID(LockEngine engine, OID oid, boolean allowReadOnly)
          Retrieve the object for a given OID.
 java.util.Collection getObjectsWithCreatingStateSortedByLowestMolderPriority()
          Retrieve the list of 'creating' objects (to be created), sorted in the order they should be created.
 java.util.Collection getObjectsWithDeletedStateSortedByHighestMolderPriority()
          Retrieve the list of 'deleted' objects, sorted in the order they should be deleted.
 java.util.Collection getObjectsWithUpdateCacheNeededState()
           
 OID getOIDForObject(java.lang.Object o)
           
 java.util.Collection getReadOnlyObjects()
          Retrieve the list of all read-only objects being tracked.
 java.util.Collection getReadWriteObjects()
          Retrieve the list of all read-write objects being tracked.
 boolean isCreated(java.lang.Object o)
           
 boolean isCreating(java.lang.Object o)
           
 boolean isDeleted(java.lang.Object o)
           
 boolean isReadOnly(java.lang.Object o)
           
 boolean isReadWrite(java.lang.Object object)
          Returns true if the specified object is tracked as a read-write object.
 boolean isTracking(java.lang.Object object)
          Determine whether an object is being tracked within this tracking manager.
 boolean isUpdateCacheNeeded(java.lang.Object object)
          Returns true if the cache needs to be updated for the given object.
 boolean isUpdatePersistNeeded(java.lang.Object object)
          Returns true if the given object needs to be written to the persistence store.
 void markCreated(java.lang.Object object)
           
 void markCreating(java.lang.Object object)
           
 void markDeleted(java.lang.Object object)
           
 void markReadOnly(java.lang.Object o)
           
 void markUpdateCacheNeeded(java.lang.Object object)
           
 void markUpdatePersistNeeded(java.lang.Object object)
           
 java.lang.String objectStateToString(java.lang.Object obj)
          Returns the object's state.
 int readOnlySize()
           
 int readWriteSize()
           
 void removeOIDForObject(LockEngine engine, OID oid)
          For a given lockengine and OID, remove references to an object in the maps.
 void setOIDForObject(java.lang.Object obj, LockEngine engine, OID oid)
          For a given lockengine and OID, set the object in the maps.
 void trackObject(ClassMolder molder, OID oid, java.lang.Object object)
           
 void trackOIDChange(java.lang.Object obj, LockEngine engine, OID oldoid, OID newoid)
          Record changes to an OID by re-tracking the OID information.
 void unmarkAllDeleted()
           
 void unmarkDeleted(java.lang.Object object)
           
 void unmarkReadOnly(java.lang.Object o)
           
 void unmarkUpdateCacheNeeded(java.lang.Object object)
           
 void unmarkUpdatePersistNeeded(java.lang.Object object)
           
 void untrackObject(java.lang.Object object)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectTracker

public ObjectTracker()
Method Detail

getObjectForOID

public java.lang.Object getObjectForOID(LockEngine engine,
                                        OID oid,
                                        boolean allowReadOnly)
Retrieve the object for a given OID.

Parameters:
engine - Lock engine mapped to oid
oid - Object id specified
allowReadOnly - Allow (or ignore, if false) read-only objects to be returned.
Returns:
The object associated with this oid.

isReadWrite

public boolean isReadWrite(java.lang.Object object)
Returns true if the specified object is tracked as a read-write object.

Parameters:
object - Object instance for which it should be determined whether it's tracked as read-write object
Returns:
True if the specified object is tracked as a read-write object

unmarkAllDeleted

public void unmarkAllDeleted()

clear

public void clear()
Reset ObjectTracker's state.


isUpdateCacheNeeded

public boolean isUpdateCacheNeeded(java.lang.Object object)
Returns true if the cache needs to be updated for the given object.

Parameters:
object - An object instance
Returns:
true if the cache needs to be updated; false, otherwise.

isUpdatePersistNeeded

public boolean isUpdatePersistNeeded(java.lang.Object object)
Returns true if the given object needs to be written to the persistence store.

Parameters:
object - An object instance
Returns:
true if the object needs to be written to the persistence store

markUpdateCacheNeeded

public void markUpdateCacheNeeded(java.lang.Object object)

unmarkUpdateCacheNeeded

public void unmarkUpdateCacheNeeded(java.lang.Object object)

getObjectsWithUpdateCacheNeededState

public java.util.Collection getObjectsWithUpdateCacheNeededState()

markUpdatePersistNeeded

public void markUpdatePersistNeeded(java.lang.Object object)

unmarkUpdatePersistNeeded

public void unmarkUpdatePersistNeeded(java.lang.Object object)

markCreating

public void markCreating(java.lang.Object object)
                  throws PersistenceException
Throws:
PersistenceException

markCreated

public void markCreated(java.lang.Object object)

markDeleted

public void markDeleted(java.lang.Object object)

unmarkDeleted

public void unmarkDeleted(java.lang.Object object)

isTracking

public boolean isTracking(java.lang.Object object)
Determine whether an object is being tracked within this tracking manager.

Parameters:
object - The object for which it should be determined whether it is tracked.
Returns:
True if the object specified is tracked; false otherwise

trackOIDChange

public void trackOIDChange(java.lang.Object obj,
                           LockEngine engine,
                           OID oldoid,
                           OID newoid)
Record changes to an OID by re-tracking the OID information. When an object's OID can change, ensure that the object is retracked.

Parameters:
obj - The object to record a tracking change for.
engine - The engine which is responsible for the old and new OID
oldoid - The old oid.
newoid - The new oid.

setOIDForObject

public void setOIDForObject(java.lang.Object obj,
                            LockEngine engine,
                            OID oid)
For a given lockengine and OID, set the object in the maps. Note that an OID can only be accessed via the LockManager which manages it.

Parameters:
obj - The object to track
engine - The engine to which the OID belongs
oid - The OID of the object to track

removeOIDForObject

public void removeOIDForObject(LockEngine engine,
                               OID oid)
For a given lockengine and OID, remove references to an object in the maps. This eliminates both the engine->oid->object and the object->oid.

Parameters:
engine - The engine to stop tracking the OID for
oid - The oid of the object to stop tracking on.

isCreating

public boolean isCreating(java.lang.Object o)

isCreated

public boolean isCreated(java.lang.Object o)

isDeleted

public boolean isDeleted(java.lang.Object o)

getMolderForObject

public ClassMolder getMolderForObject(java.lang.Object o)
Retrieve the ClassMolder associated with a specific object.

Parameters:
o - Object instance the associated ClassMolder should be retrieved.
Returns:
The ClassMolder instance associated with the Object instance specified.

getReadWriteObjects

public java.util.Collection getReadWriteObjects()
Retrieve the list of all read-write objects being tracked.

Returns:
List of all read-write objects being currently tracked.

getReadOnlyObjects

public java.util.Collection getReadOnlyObjects()
Retrieve the list of all read-only objects being tracked.

Returns:
List of all read-only objects being currently tracked

getObjectsWithCreatingStateSortedByLowestMolderPriority

public java.util.Collection getObjectsWithCreatingStateSortedByLowestMolderPriority()
Retrieve the list of 'creating' objects (to be created), sorted in the order they should be created.

Returns:
List of objects to be created, sorted in the order they should be created.

getObjectsWithDeletedStateSortedByHighestMolderPriority

public java.util.Collection getObjectsWithDeletedStateSortedByHighestMolderPriority()
Retrieve the list of 'deleted' objects, sorted in the order they should be deleted.

Returns:
List of 'deleted' objects, sorted in the order they should be deleted.

trackObject

public void trackObject(ClassMolder molder,
                        OID oid,
                        java.lang.Object object)

untrackObject

public void untrackObject(java.lang.Object object)

getOIDForObject

public OID getOIDForObject(java.lang.Object o)

isReadOnly

public boolean isReadOnly(java.lang.Object o)

markReadOnly

public void markReadOnly(java.lang.Object o)

unmarkReadOnly

public void unmarkReadOnly(java.lang.Object o)

readOnlySize

public int readOnlySize()

readWriteSize

public int readWriteSize()

allObjectStates

public java.lang.String allObjectStates()

objectStateToString

public java.lang.String objectStateToString(java.lang.Object obj)
Returns the object's state.

Parameters:
obj - Object for which its state should be output.
Returns:
The state of the object specified


Intalio Inc. (C) 1999-2008. All rights reserved http://www.intalio.com