java.lang.Object
org.eclipse.persistence.internal.sessions.ObjectChangeSet
All Implemented Interfaces:
Serializable, Comparable<ObjectChangeSet>, ObjectChangeSet
Direct Known Subclasses:
AggregateObjectChangeSet

public class ObjectChangeSet extends Object implements Serializable, Comparable<ObjectChangeSet>, ObjectChangeSet

Purpose: Hold the Records of change for a particular instance of an object.

Description: This class uses the Primary Keys of the Object it represents, and the class.

See Also:
  • Field Details

    • changes

      protected List<ChangeRecord> changes
      This is the collection of changes
    • attributesToChanges

      protected transient Map<String,ChangeRecord> attributesToChanges
    • shouldBeDeleted

      protected boolean shouldBeDeleted
    • id

      protected Object id
    • classType

      protected transient Class<?> classType
    • className

      protected String className
    • isNew

      protected boolean isNew
    • isAggregate

      protected boolean isAggregate
    • oldKey

      protected Object oldKey
    • newKey

      protected Object newKey
    • protectedForeignKeys

      protected AbstractRecord protectedForeignKeys
    • unitOfWorkChangeSet

      protected transient UnitOfWorkChangeSet unitOfWorkChangeSet
      This member variable holds the reference to the parent UnitOfWork Change Set
    • optimisticLockingPolicy

      protected transient OptimisticLockingPolicy optimisticLockingPolicy
      Used in mergeObjectChanges method for writeLock and initialWriteLock comparison of the merged change sets
    • initialWriteLockValue

      protected Object initialWriteLockValue
    • writeLockValue

      protected Object writeLockValue
    • isInvalid

      protected boolean isInvalid
      Invalid change set shouldn't be merged into object in cache, rather the object should be invalidated
    • cloneObject

      protected transient Object cloneObject
    • hasVersionChange

      protected boolean hasVersionChange
    • shouldModifyVersionField

      protected Boolean shouldModifyVersionField
      Contains optimisticReadLockObject corresponding to the clone, non-null indicates forced changes
    • hasCmpPolicyForcedUpdate

      protected transient boolean hasCmpPolicyForcedUpdate
      For CMP only: indicates that the object should be force updated (whether it has OptimisticLocking or not): getCmpPolicy().getForcedUpdate()==true
    • hasChangesFromCascadeLocking

      protected transient boolean hasChangesFromCascadeLocking
    • deferredSet

      protected transient Set<String> deferredSet
      This is used during attribute level change tracking when a particular change was detected but that change can not be tracked (ie customer set entire collection in object).
    • cacheSynchronizationType

      protected int cacheSynchronizationType
      Used to store the type of cache synchronization used for this object This variable is set just before the change set is serialized.
    • activeCacheKey

      protected transient CacheKey activeCacheKey
      PERF: Cache the session cacheKey during the merge to avoid duplicate lookups.
    • descriptor

      protected transient ClassDescriptor descriptor
      Cache the descriptor as it is useful and required in some places.
    • shouldRecalculateAfterUpdateEvent

      protected transient boolean shouldRecalculateAfterUpdateEvent
      return whether this change set should be recalculated after an event changes the object
    • MAX_TRIES

      public static final int MAX_TRIES
      See Also:
  • Constructor Details

    • ObjectChangeSet

      public ObjectChangeSet()
      The default constructor.
    • ObjectChangeSet

      public ObjectChangeSet(Object primaryKey, ClassDescriptor descriptor, Object cloneObject, UnitOfWorkChangeSet parent, boolean isNew)
      This constructor is used to create an ObjectChangeSet that represents a regular object.
  • Method Details

    • getDescriptor

      public ClassDescriptor getDescriptor()
    • setDescriptor

      public void setDescriptor(ClassDescriptor descriptor)
    • clear

      public void clear(boolean clearKeys)
      INTERNAL: This method will clear the changerecords from a changeSet
    • addChange

      public void addChange(ChangeRecord changeRecord)
      Add the attribute change record.
    • deferredDetectionRequiredOn

      public void deferredDetectionRequiredOn(String attributeName)
      INTERNAL: This method is used during attribute level change tracking when a particular change was detected but that change can not be tracked (ie customer set entire collection in object). In this case flag this attribute for deferred change detection at commit time.
    • containsChangesFromSynchronization

      public boolean containsChangesFromSynchronization()
      INTERNAL: Convenience method used to query this change set after it has been sent by cache synchronization.
      Returns:
      true if this change set should contain all change information, false if only the identity information should be available.
    • equals

      public boolean equals(Object object)
      Ensure change sets with the same primary key are equal.
      Specified by:
      equals in interface ObjectChangeSet
      Overrides:
      equals in class Object
    • equals

      public boolean equals(ObjectChangeSet objectChange)
      Ensure change sets with the same primary key are equal.
    • compareTo

      public int compareTo(ObjectChangeSet changeSet)
      Determine if the receiver is greater or less than the change set.
      Specified by:
      compareTo in interface Comparable<ObjectChangeSet>
    • getAttributesToChanges

      public Map getAttributesToChanges()
      INTERNAL: stores the change records indexed by the attribute names
    • getChangesForAttributeNamed

      public ChangeRecord getChangesForAttributeNamed(String attributeName)
      INTERNAL: returns the change record for the specified attribute name
      Specified by:
      getChangesForAttributeNamed in interface ObjectChangeSet
    • getChangedAttributeNames

      public List<String> getChangedAttributeNames()
      ADVANCED: This method will return a collection of the attributes changed in the object.
      Specified by:
      getChangedAttributeNames in interface ObjectChangeSet
    • getChanges

      public List<ChangeRecord> getChanges()
      INTERNAL: This method returns a reference to the collection of changes within this changeSet.
      Specified by:
      getChanges in interface ObjectChangeSet
    • getClassType

      public Class<?> getClassType()
      INTERNAL: This method returns the class type that this changeSet represents. The class type must be initialized, before this method is called.
      Returns:
      java.lang.Class or null if the class type isn't initialized.
    • getClassType

      public Class<?> getClassType(Session session)
      ADVANCE: This method returns the class type that this changeSet Represents. This requires the session to reload the class on serialization.
      Specified by:
      getClassType in interface ObjectChangeSet
    • getClassName

      public String getClassName()
      ADVANCE: This method returns the class type that this changeSet Represents. The class type should be used if the class is desired.
      Specified by:
      getClassName in interface ObjectChangeSet
    • getInitialWriteLockValue

      public Object getInitialWriteLockValue()
      INTERNAL: This method is used to return the initial lock value of the object this changeSet represents.
    • getOldKey

      public Object getOldKey()
      This method returns the key value that this object was stored under in it's Respective hashmap.
      Specified by:
      getOldKey in interface ObjectChangeSet
    • getNewKey

      public Object getNewKey()
      This method returns the key value that this object will be stored under in it's Respective hashmap.
      Specified by:
      getNewKey in interface ObjectChangeSet
    • getId

      public Object getId()
      ADVANCED: This method returns the primary key for the object that this change set represents.
      Specified by:
      getId in interface ObjectChangeSet
    • getOldValue

      public Object getOldValue()
    • getOldValue

      public Object getOldValue(AbstractSession session)
    • getSynchronizationType

      public int getSynchronizationType()
    • getTargetVersionOfSourceObject

      public Object getTargetVersionOfSourceObject(MergeManager mergeManager, AbstractSession session)
      INTERNAL: This method is used to return the complex object specified within the change record. The object is collected from the session which, in this case, is the unit of work. The object's changed attributes will be merged and added to the identity map.
    • getTargetVersionOfSourceObject

      public Object getTargetVersionOfSourceObject(MergeManager mergeManager, AbstractSession targetSession, boolean shouldRead)
      INTERNAL: This method is used to return the complex object specified within the change record. The object is collected from the session which, in this case, is the unit of work. The object's changed attributes will be merged and added to the identity map
      Parameters:
      shouldRead - boolean if the object can not be found should it be read in from the database.
    • getObjectForMerge

      protected Object getObjectForMerge(MergeManager mergeManager, AbstractSession session, Object primaryKey, ClassDescriptor descriptor)
      INTERNAL: For use within the distributed merge process, this method will get an object from the shared cache using a readlock. If a readlock is unavailable then the merge manager will be transitioned to deferred locks and a deferred lock will be used.
    • getUnitOfWorkClone

      public Object getUnitOfWorkClone()
      INTERNAL: Returns the UnitOfWork Clone that this ChangeSet was built for.
    • setUnitOfWorkClone

      public void setUnitOfWorkClone(Object cloneObject)
      INTERNAL: Sets the UnitOfWork Clone that this ChangeSet was built for.
    • getUOWChangeSet

      public UnitOfWorkChangeSet getUOWChangeSet()
      ADVANCED: This method is used to return the parent UnitOfWorkChangeSet.
      Specified by:
      getUOWChangeSet in interface ObjectChangeSet
    • getWriteLockValue

      public Object getWriteLockValue()
      INTERNAL: This method is used to return the lock value of the object this changeSet represents.
      Specified by:
      getWriteLockValue in interface ObjectChangeSet
    • hasChangeFor

      public boolean hasChangeFor(String attributeName)
      ADVANCED: This method will return true if the specified attribute has been changed.
      Specified by:
      hasChangeFor in interface ObjectChangeSet
      Parameters:
      attributeName - the name of the attribute to search for.
    • hasChanges

      public boolean hasChanges()
      ADVANCED: Returns true if this particular changeSet has changes.
      Specified by:
      hasChanges in interface ObjectChangeSet
    • hasForcedChanges

      public boolean hasForcedChanges()
      INTERNAL: Returns true if this particular changeSet has forced SQL changes. This is true whenever CMPPolicy.getForceUpdate() == true or if the object has been marked for opt. read lock (uow.forceUpdateToVersionField). Kept separate from 'hasChanges' because we don't want to merge or cache sync. a change set that has no 'real' changes.
    • setShouldModifyVersionField

      public void setShouldModifyVersionField(Boolean shouldModifyVersionField)
      INTERNAL: Holds a Boolean indicating whether version field should be modified. This Boolean is set by forcedUpdate into uow.getOptimisticReadLockObjects() for the clone object and copied here (so don't need to search for it again in uow.getOptimisticReadLockObjects()).
    • shouldModifyVersionField

      public Boolean shouldModifyVersionField()
      INTERNAL: Holds a Boolean indicating whether version field should be modified.
    • setHasCmpPolicyForcedUpdate

      public void setHasCmpPolicyForcedUpdate(boolean hasCmpPolicyForcedUpdate)
      INTERNAL:
    • hasCmpPolicyForcedUpdate

      public boolean hasCmpPolicyForcedUpdate()
      INTERNAL:
    • hasForcedChangesFromCascadeLocking

      public boolean hasForcedChangesFromCascadeLocking()
      INTERNAL: Returns true if this particular changeSet has forced SQL changes because of a cascade optimistic locking policy.
    • setHasForcedChangesFromCascadeLocking

      public void setHasForcedChangesFromCascadeLocking(boolean newValue)
      INTERNAL: Used by calculateChanges to mark this ObjectChangeSet as having to be flushed to the db stemming from a cascade optimistic locking policy.
    • hashCode

      public int hashCode()
      This method overrides the hashcode method. If this set has a cacheKey then return the hashcode of the cache key, otherwise return the identity hashcode of this object.
      Overrides:
      hashCode in class Object
    • hasKeys

      public boolean hasKeys()
      INTERNAL: Returns true if this particular changeSet has a Key.
    • isAggregate

      public boolean isAggregate()
      INTERNAL: Used to determine if the object change set represents an aggregate object.
    • isNew

      public boolean isNew()
      ADVANCED: Returns true if this ObjectChangeSet represents a new object.
      Specified by:
      isNew in interface ObjectChangeSet
    • isInvalid

      public boolean isInvalid()
      INTERNAL: Indicates whether the change set is invalid.
    • mergeObjectChanges

      public void mergeObjectChanges(ObjectChangeSet changeSetToMergeFrom, UnitOfWorkChangeSet mergeToChangeSet, UnitOfWorkChangeSet mergeFromChangeSet)
      INTERNAL: This method will be used to merge changes from a supplied ObjectChangeSet into this changeSet.
    • readCompleteChangeSet

      public void readCompleteChangeSet(ObjectInputStream stream) throws IOException, ClassNotFoundException
      INTERNAL: Helper method used by readObject to read a completely serialized change set from the stream.
      Throws:
      IOException
      ClassNotFoundException
    • readIdentityInformation

      public void readIdentityInformation(ObjectInputStream stream) throws IOException, ClassNotFoundException
      INTERNAL: Helper method used by readObject to read just the information about object identity from a serialized stream.
      Throws:
      IOException
      ClassNotFoundException
    • setId

      public void setId(Object id)
      Set the id of the object for this change set.
    • setChanges

      public void setChanges(List changesList)
      Set the changes.
    • setClassType

      public void setClassType(Class<?> newValue)
      Set the class type.
    • setClassName

      public void setClassName(String newValue)
      INTERNAL: Set the class name. The name is used for serialization with cache coordination.
    • setIsAggregate

      public void setIsAggregate(boolean isAggregate)
      INTERNAL: Set if this object change Set represents an aggregate
      Parameters:
      isAggregate - boolean true if the ChangeSet represents an aggregate
    • setIsNew

      public void setIsNew(boolean newIsNew)
      INTERNAL: Set whether this ObjectChanges represents a new Object
      Parameters:
      newIsNew - boolean true if this ChangeSet represents a new object
    • setOldKey

      public void setOldKey(Object key)
      This method is used to set the value that this object was stored under in its respected map collection
    • setNewKey

      public void setNewKey(Object key)
      This method is used to set the value that this object will be stored under in its respected map collection
    • setShouldBeDeleted

      public void setShouldBeDeleted(boolean newValue)
      This method was created in VisualAge.
      Parameters:
      newValue - boolean
    • setSynchronizationType

      public void setSynchronizationType(int type)
    • setUOWChangeSet

      public void setUOWChangeSet(UnitOfWorkChangeSet newUnitOfWorkChangeSet)
      INTERNAL: Used to set the parent change Set.
    • setOptimisticLockingPolicyAndInitialWriteLockValue

      public void setOptimisticLockingPolicyAndInitialWriteLockValue(OptimisticLockingPolicy optimisticLockingPolicy, AbstractSession session)
      INTERNAL: This method should ONLY be used to set the initial writeLock value for an ObjectChangeSet when it is first built.
    • setWriteLockValue

      public void setWriteLockValue(Object newWriteLockValue)
      ADVANCED: This method is used to set the writeLock value for an ObjectChangeSet Any changes to the write lock value should to through setWriteLockValue(Object obj) so that the change set is marked as being dirty.
    • setInitialWriteLockValue

      public void setInitialWriteLockValue(Object initialWriteLockValue)
      ADVANCED: This method is used to set the initial writeLock value for an ObjectChangeSet. The initial value will only be set once, and can not be overwritten.
    • shouldBeDeleted

      public boolean shouldBeDeleted()
      Mark change set for a deleted object.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • updateChangeRecordForAttribute

      public void updateChangeRecordForAttribute(String attributeName, Object value)
      INTERNAL: Used to update a changeRecord that is stored in the CHangeSet with a new value.
    • updateChangeRecordForAttributeWithMappedObject

      public void updateChangeRecordForAttributeWithMappedObject(String attributeName, Object value, AbstractSession session)
      ADVANCED: Used to update a changeRecord that is stored in the CHangeSet with a new value. Used when the new value is a mapped object.
    • updateChangeRecordForAttribute

      public void updateChangeRecordForAttribute(DatabaseMapping mapping, Object value, AbstractSession session, Object oldValue)
      INTERNAL: Used to update a changeRecord that is stored in the CHangeSet with a new value.
    • updateReferences

      public void updateReferences(UnitOfWorkChangeSet localChangeSet, UnitOfWorkChangeSet mergingChangeSet)
      INTERNAL: This method will be used when merging changesets into other changesets. It will fix references within a changeSet so that it's records point to changesets within this UOWChangeSet.
    • writeIdentityInformation

      public void writeIdentityInformation(ObjectOutputStream stream) throws IOException
      INTERNAL: Helper method to writeObject. Write only the information necessary to identify this ObjectChangeSet to the stream
      Throws:
      IOException
    • writeCompleteChangeSet

      public void writeCompleteChangeSet(ObjectOutputStream stream) throws IOException
      INTERNAL: Helper method to readObject. Completely write this ObjectChangeSet to the stream
      Throws:
      IOException
    • postSerialize

      public void postSerialize(Object clone, UnitOfWorkChangeSet uowChangeSet, AbstractSession session)
      INTERNAL: Reset the change set's transient variables after serialization.
    • getDeferredSet

      public Set<String> getDeferredSet()
      This set contains the list of attributes that must be calculated at commit time.
    • hasDeferredAttributes

      public boolean hasDeferredAttributes()
      Check to see if there are any attributes that must be calculated at commit time.
    • dirtyUOWChangeSet

      protected void dirtyUOWChangeSet()
    • updateUOWChangeSet

      protected void updateUOWChangeSet()
    • rebuildWriteLockValueFromUserFormat

      protected void rebuildWriteLockValueFromUserFormat(ClassDescriptor descriptor, AbstractSession session)
      Rebuild writeLockValue to the expected type from user format i.e XML change set has all values as String.
    • removeChange

      public void removeChange(String attributeName)
      INTERNAL: Remove the change. Used by the event mechanism to reset changes after client has updated the object within an event.
    • removeFromIdentityMap

      protected void removeFromIdentityMap(AbstractSession session)
      Remove object represent this change set from identity map. If change set is in XML format, rebuild pk to the correct class type from String
    • shouldInvalidateObject

      public boolean shouldInvalidateObject(Object original, AbstractSession session)
      INTERNAL: Indicates whether the object in session cache should be invalidated.
      Parameters:
      original - Object is from session's cache into which the changes are about to be merged, non null.
      session - AbstractSession into which the changes are about to be merged;
    • getActiveCacheKey

      public CacheKey getActiveCacheKey()
      INTERNAL: PERF: Return the session cache-key, cached during the merge.
    • setActiveCacheKey

      public void setActiveCacheKey(CacheKey activeCacheKey)
      INTERNAL: PERF: Set the session cache-key, cached during the merge.
    • shouldRecalculateAfterUpdateEvent

      public boolean shouldRecalculateAfterUpdateEvent()
      ADVANCED Returns true if this ObjectChangeSet should be recalculated after changes in event
      Specified by:
      shouldRecalculateAfterUpdateEvent in interface ObjectChangeSet
    • setShouldRecalculateAfterUpdateEvent

      public void setShouldRecalculateAfterUpdateEvent(boolean shouldRecalculateAfterUpdateEvent)
      ADVANCED Set whether this ObjectChangeSet should be recalculated after changes in event
      Specified by:
      setShouldRecalculateAfterUpdateEvent in interface ObjectChangeSet
    • hasVersionChange

      public boolean hasVersionChange()
    • setHasVersionChange

      public void setHasVersionChange(boolean hasVersionChange)
    • getCacheSynchronizationType

      public int getCacheSynchronizationType()
    • setCacheSynchronizationType

      public void setCacheSynchronizationType(int cacheSynchronizationType)
    • setIsInvalid

      public void setIsInvalid(boolean isInvalid)
    • getProtectedForeignKeys

      public AbstractRecord getProtectedForeignKeys()
    • setProtectedForeignKeys

      public void setProtectedForeignKeys(AbstractRecord protectedForeignKeys)
    • hasProtectedForeignKeys

      public boolean hasProtectedForeignKeys()