Module org.eclipse.persistence.core
Class MergeManager
java.lang.Object
org.eclipse.persistence.internal.sessions.MergeManager
Purpose: Used to manage the merge of two objects in a unit of work.
- Since:
- TOPLink/Java 1.1
-
Field Summary
Modifier and TypeFieldDescriptionUsed to store the list of locks that this merge manager has acquired for this mergestatic final int
static final int
static final int
protected int
Policy that determines how the merge will cascade to its object's parts.protected static final int
protected static final int
protected static final int
protected boolean
Force cascade merge even if a clone is already registeredprotected boolean
records that this merge process is for a refreshprotected boolean
records that deferred locks have been employed for the merge processstatic boolean
Backdoor to disable merge locks.protected Thread
save the currentThread for later comparison to the activeThread in case they don't matchprotected IdentityHashMap
<Object, Object> Used to keep track of merged new objects.protected int
Policy that determines merge type (i.e.static final int
protected Map
<Object, ObjectDescriptor> Used only while refreshing objects on remote sessionprotected Map
<AbstractSession, Map<Object, Object>> Used to unravel recursion.protected static final int
protected LinkedNode
Stores the node that holds this mergemanager within the WriteLocksManager queueprotected static final int
protected AbstractSession
The unit of work merging for.protected long
Stored so that all objects merged by a merge manager can have the same readTime.protected static final int
protected static final int
protected Object
If this variable is not null then the mergemanager is waiting on a particular primary key -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Cascade all parts, this is the default for the merge.void
Cascade private parts, this can be used to merge clone when using RMI.void
checkNewObjectLockVersion
(Object clone, Object primaryKey, ClassDescriptor descriptor, UnitOfWorkImpl unitOfWork) Check if the new object's version has been set, if so, then it was an existing object that was deleted.void
Merge only direct parts, this can be used to merge clone when using RMI.int
INTERNAL:INTERNAL: Used to return a map containing new objects found through the registerObjectForMergeCloneIntoWorkingCopy method.getMergedObject
(Object key, AbstractSession targetSession) protected int
getObjectToMerge
(Object sourceValue, ClassDescriptor descriptor, AbstractSession targetSession) INTENRAL: Used to get the node that this merge manager is stored in, within the WriteLocksManager write lockers queuelong
Get the stored value of the current time.getTargetVersionOfSourceObject
(Object source, ClassDescriptor descriptor, AbstractSession targetSession) Return the corresponding value that should be assigned to the target object for the source object.INTENRAL: Used to get the object that the merge manager is waiting on, in order to acquire locksboolean
isAlreadyMerged
(Object object, AbstractSession targetSession) boolean
boolean
INTERNAL: Will return if the merge process has transitioned the active merge locks to deferred locks for readlock deadlock avoidance.mergeChanges
(Object object, ObjectChangeSet objectChangeSet, AbstractSession targetSession) Recursively merge changes in the object dependent on the merge policy.protected Object
mergeChangesForRefreshingRemoteObject
(Object serverSideDomainObject) Recursively merge the RMI clone from the server into the client unit of work working copy.void
mergeChangesFromChangeSet
(UnitOfWorkChangeSet uowChangeSet) INTERNAL: Merge the changes to all objects to session's cache.protected Object
mergeChangesIntoDistributedCache
(Object original, ObjectChangeSet changeSet) Merge the changes specified within the changeSet into the cache.protected Object
mergeChangesOfCloneIntoWorkingCopy
(Object rmiClone) Recursively merge to rmi clone into the unit of work working copy.protected Object
Recursively merge to original from its parent into the clone.protected Object
mergeChangesOfWorkingCopyIntoOriginal
(Object clone, ObjectChangeSet objectChangeSet) Recursively merge to clone into the original in its parent.protected CacheKey
mergeChangesOfWorkingCopyIntoOriginal
(Object clone, ObjectChangeSet objectChangeSet, ClassDescriptor descriptor, AbstractSession targetSession, UnitOfWorkImpl unitOfWork) Recursively merge to clone into the original in its parent.Recursively merge changes in the object dependent on the merge policy.void
This can be used by the user for merging clones from RMI into the unit of work.void
This is used during the merge of dependent objects referencing independent objects, where you want the independent objects merged as well.void
This is used during cache synchronization to merge the changes into the distributed cache.mergeNewObjectIntoCache
(ObjectChangeSet changeSet) Merge a change set for a new object into the cache.void
This is used to revert changes to objects, or during refreshes.void
This is used during the unit of work commit to merge changes into the parent.void
This is used during the unit of work commit to merge changes into the parent.void
recordMerge
(Object key, Object value, AbstractSession targetSession) void
INTERNAL: This is used to refresh remote session objectregisterExistingObjectOfReadOnlyClassInNestedTransaction
(Object source, ClassDescriptor descriptor, AbstractSession targetSession) INTERNAL: Used to register an existing object used in nested unit of work with read-only class in root unit of work.protected Object
registerObjectForMergeCloneIntoWorkingCopy
(Object clone, boolean shouldForceCascade) INTERNAL: When merging from a clone when the cache cannot be guaranteed the object must be first read if it is existing and not in the cache.void
registerRemovedNewObjectIfRequired
(Object removedObject) Determine if the object is a registered new object, and that this is a nested unit of work merge into the parent.void
setCascadePolicy
(int cascadePolicy) void
setForceCascade
(boolean forceCascade) void
setForRefresh
(boolean isforRefresh) void
setLockThread
(Thread lockThread) INTERNAL: Save the currentThread for later comparison to the activeThread in case they don't matchprotected void
setMergePolicy
(int mergePolicy) void
setObjectDescriptors
(Map<Object, ObjectDescriptor> objectDescriptors) protected void
setObjectsAlreadyMerged
(Map<AbstractSession, Map<Object, Object>> objectsAlreadyMerged) void
setQueueNode
(LinkedNode node) INTENRAL: Used to set the node that this merge manager is stored in, within the WriteLocksManager write lockers queueprotected void
setSession
(AbstractSession session) void
setWriteLockQueued
(Object primaryKey) INTENRAL: Used to set the object that the merge manager is waiting on, in order to acquire locks If this value is null then the merge manager is not waiting on any locks.boolean
Flag used to determine if all parts should be cascadedboolean
Flag used to determine that the mappings should be checked for cascade requirements.boolean
Flag used to determine if any parts should be cascadedboolean
Flag used to determine if any private parts should be cascadedboolean
Refreshes are based on the objects row, so all attributes of the object must be refreshed.boolean
This is used to cascade merge even if a clone is already registered.boolean
INTERNAL: This happens when changes from an UnitOfWork is propagated to a distributed class.boolean
This can be used by the user for merging clones from RMI into the unit of work.boolean
This can be used by the user for merging remote EJB objects into the unit of work.boolean
This is used to revert changes to objects, or during refreshes.boolean
This is used during the unit of work commit to merge changes into the parent.boolean
INTERNAL: This happens when serialized remote unit of work has to be merged with local remote unit of work.boolean
INTERNAL: This is used to refresh objects on the remote sessionvoid
INTERNAL: Records that this merge manager has transitioned to use deferred locks during the merge.protected void
updateCacheKeyProperties
(UnitOfWorkImpl unitOfWork, CacheKey cacheKey, Object original, Object clone, ObjectChangeSet objectChangeSet, ClassDescriptor descriptor) INTERNAL: Update CacheKey properties with new information.
-
Field Details
-
session
The unit of work merging for. -
objectDescriptors
Used only while refreshing objects on remote session -
objectsAlreadyMerged
Used to unravel recursion. -
mergedNewObjects
Used to keep track of merged new objects. -
acquiredLocks
Used to store the list of locks that this merge manager has acquired for this merge -
writeLockQueued
If this variable is not null then the mergemanager is waiting on a particular primary key -
queueNode
Stores the node that holds this mergemanager within the WriteLocksManager queue -
mergePolicy
protected int mergePolicyPolicy that determines merge type (i.e. merge is used for several usages). -
WORKING_COPY_INTO_ORIGINAL
protected static final int WORKING_COPY_INTO_ORIGINAL- See Also:
-
ORIGINAL_INTO_WORKING_COPY
protected static final int ORIGINAL_INTO_WORKING_COPY- See Also:
-
CLONE_INTO_WORKING_COPY
protected static final int CLONE_INTO_WORKING_COPY- See Also:
-
WORKING_COPY_INTO_REMOTE
protected static final int WORKING_COPY_INTO_REMOTE- See Also:
-
REFRESH_REMOTE_OBJECT
protected static final int REFRESH_REMOTE_OBJECT- See Also:
-
CHANGES_INTO_DISTRIBUTED_CACHE
protected static final int CHANGES_INTO_DISTRIBUTED_CACHE- See Also:
-
CLONE_WITH_REFS_INTO_WORKING_COPY
protected static final int CLONE_WITH_REFS_INTO_WORKING_COPY- See Also:
-
cascadePolicy
protected int cascadePolicyPolicy that determines how the merge will cascade to its object's parts. -
NO_CASCADE
public static final int NO_CASCADE- See Also:
-
CASCADE_PRIVATE_PARTS
public static final int CASCADE_PRIVATE_PARTS- See Also:
-
CASCADE_ALL_PARTS
public static final int CASCADE_ALL_PARTS- See Also:
-
CASCADE_BY_MAPPING
public static final int CASCADE_BY_MAPPING- See Also:
-
LOCK_ON_MERGE
public static boolean LOCK_ON_MERGEBackdoor to disable merge locks. -
systemTime
protected long systemTimeStored so that all objects merged by a merge manager can have the same readTime. -
forceCascade
protected boolean forceCascadeForce cascade merge even if a clone is already registered -
isTransitionedToDeferredLocks
protected boolean isTransitionedToDeferredLocksrecords that deferred locks have been employed for the merge process -
lockThread
save the currentThread for later comparison to the activeThread in case they don't match -
isForRefresh
protected boolean isForRefreshrecords that this merge process is for a refresh
-
-
Constructor Details
-
MergeManager
-
-
Method Details
-
cascadeAllParts
public void cascadeAllParts()Cascade all parts, this is the default for the merge. -
cascadePrivateParts
public void cascadePrivateParts()Cascade private parts, this can be used to merge clone when using RMI. -
dontCascadeParts
public void dontCascadeParts()Merge only direct parts, this can be used to merge clone when using RMI. -
getAcquiredLocks
-
getCascadePolicy
public int getCascadePolicy() -
getMergePolicy
protected int getMergePolicy() -
getObjectDescriptors
-
getObjectsAlreadyMerged
-
getObjectToMerge
public Object getObjectToMerge(Object sourceValue, ClassDescriptor descriptor, AbstractSession targetSession) -
getQueueNode
INTENRAL: Used to get the node that this merge manager is stored in, within the WriteLocksManager write lockers queue -
getSession
-
getSystemTime
public long getSystemTime()Get the stored value of the current time. This method lazily initializes so that read times for the same merge manager can all be set to the same read time -
getTargetVersionOfSourceObject
public Object getTargetVersionOfSourceObject(Object source, ClassDescriptor descriptor, AbstractSession targetSession) Return the corresponding value that should be assigned to the target object for the source object. This value must be local to the targets object space. -
registerExistingObjectOfReadOnlyClassInNestedTransaction
public Object registerExistingObjectOfReadOnlyClassInNestedTransaction(Object source, ClassDescriptor descriptor, AbstractSession targetSession) INTERNAL: Used to register an existing object used in nested unit of work with read-only class in root unit of work. -
getWriteLockQueued
INTENRAL: Used to get the object that the merge manager is waiting on, in order to acquire locks -
isForRefresh
public boolean isForRefresh()- Returns:
- the isForMerge
-
setForRefresh
public void setForRefresh(boolean isforRefresh) - Parameters:
isforRefresh
- the isForMerge to set
-
isTransitionedToDeferredLocks
public boolean isTransitionedToDeferredLocks()INTERNAL: Will return if the merge process has transitioned the active merge locks to deferred locks for readlock deadlock avoidance. -
mergeChanges
public Object mergeChanges(Object object, ObjectChangeSet objectChangeSet, AbstractSession targetSession) throws ValidationException Recursively merge changes in the object dependent on the merge policy. The map is used to resolve recursion.- Throws:
ValidationException
-
recordMerge
-
isAlreadyMerged
-
getMergedObject
-
mergeChangesForRefreshingRemoteObject
Recursively merge the RMI clone from the server into the client unit of work working copy. This will only be called if the working copy exists. -
mergeChangesFromChangeSet
INTERNAL: Merge the changes to all objects to session's cache. -
mergeChangesIntoDistributedCache
Merge the changes specified within the changeSet into the cache. The object passed in is the original object from the cache. -
mergeChangesOfCloneIntoWorkingCopy
Recursively merge to rmi clone into the unit of work working copy. The map is used to resolve recursion. -
mergeChangesOfOriginalIntoWorkingCopy
Recursively merge to original from its parent into the clone. The map is used to resolve recursion. -
mergeChangesOfWorkingCopyIntoOriginal
protected Object mergeChangesOfWorkingCopyIntoOriginal(Object clone, ObjectChangeSet objectChangeSet) Recursively merge to clone into the original in its parent. The map is used to resolve recursion. -
mergeChangesOfWorkingCopyIntoOriginal
protected CacheKey mergeChangesOfWorkingCopyIntoOriginal(Object clone, ObjectChangeSet objectChangeSet, ClassDescriptor descriptor, AbstractSession targetSession, UnitOfWorkImpl unitOfWork) Recursively merge to clone into the original in its parent. The map is used to resolve recursion. This is used to merge objects from the unit of work into the shared (or isolated) cache. -
mergeChangesOfWorkingCopyIntoRemote
Recursively merge changes in the object dependent on the merge policy. This merges changes from a remote unit of work back from the server into the original remote unit of work. This is meant to merge server-side changes such as sequence numbers, version numbers or events triggered changes.- Throws:
ValidationException
-
mergeCloneIntoWorkingCopy
public void mergeCloneIntoWorkingCopy()This can be used by the user for merging clones from RMI into the unit of work. -
mergeCloneWithReferencesIntoWorkingCopy
public void mergeCloneWithReferencesIntoWorkingCopy()This is used during the merge of dependent objects referencing independent objects, where you want the independent objects merged as well. -
mergeIntoDistributedCache
public void mergeIntoDistributedCache()This is used during cache synchronization to merge the changes into the distributed cache. -
mergeNewObjectIntoCache
Merge a change set for a new object into the cache. This method will create a shell for the new object and then merge the changes from the change set into the object. The newly merged object will then be added to the cache. -
mergeOriginalIntoWorkingCopy
public void mergeOriginalIntoWorkingCopy()This is used to revert changes to objects, or during refreshes. -
mergeWorkingCopyIntoOriginal
public void mergeWorkingCopyIntoOriginal()This is used during the unit of work commit to merge changes into the parent. -
mergeWorkingCopyIntoRemote
public void mergeWorkingCopyIntoRemote()This is used during the unit of work commit to merge changes into the parent. -
refreshRemoteObject
public void refreshRemoteObject()INTERNAL: This is used to refresh remote session object -
registerObjectForMergeCloneIntoWorkingCopy
protected Object registerObjectForMergeCloneIntoWorkingCopy(Object clone, boolean shouldForceCascade) INTERNAL: When merging from a clone when the cache cannot be guaranteed the object must be first read if it is existing and not in the cache. Otherwise no changes will be detected as the original state is missing. -
checkNewObjectLockVersion
public void checkNewObjectLockVersion(Object clone, Object primaryKey, ClassDescriptor descriptor, UnitOfWorkImpl unitOfWork) Check if the new object's version has been set, if so, then it was an existing object that was deleted. Raise an error instead of reincarnating the object. -
registerRemovedNewObjectIfRequired
Determine if the object is a registered new object, and that this is a nested unit of work merge into the parent. In this case private mappings will register the object as being removed. -
setCascadePolicy
public void setCascadePolicy(int cascadePolicy) -
setMergePolicy
protected void setMergePolicy(int mergePolicy) -
setForceCascade
public void setForceCascade(boolean forceCascade) -
setObjectDescriptors
-
setObjectsAlreadyMerged
protected void setObjectsAlreadyMerged(Map<AbstractSession, Map<Object, Object>> objectsAlreadyMerged) -
setQueueNode
INTENRAL: Used to set the node that this merge manager is stored in, within the WriteLocksManager write lockers queue -
setSession
-
setWriteLockQueued
INTENRAL: Used to set the object that the merge manager is waiting on, in order to acquire locks If this value is null then the merge manager is not waiting on any locks. -
shouldCascadeByMapping
public boolean shouldCascadeByMapping()Flag used to determine that the mappings should be checked for cascade requirements. -
shouldCascadeAllParts
public boolean shouldCascadeAllParts()Flag used to determine if all parts should be cascaded -
shouldCascadeParts
public boolean shouldCascadeParts()Flag used to determine if any parts should be cascaded -
shouldCascadePrivateParts
public boolean shouldCascadePrivateParts()Flag used to determine if any private parts should be cascaded -
shouldCascadeReferences
public boolean shouldCascadeReferences()Refreshes are based on the objects row, so all attributes of the object must be refreshed. However merging from RMI, normally reference are made transient, so should not be merge unless specified. -
shouldMergeChangesIntoDistributedCache
public boolean shouldMergeChangesIntoDistributedCache()INTERNAL: This happens when changes from an UnitOfWork is propagated to a distributed class. -
shouldMergeCloneIntoWorkingCopy
public boolean shouldMergeCloneIntoWorkingCopy()This can be used by the user for merging clones from RMI into the unit of work. -
shouldMergeCloneWithReferencesIntoWorkingCopy
public boolean shouldMergeCloneWithReferencesIntoWorkingCopy()This can be used by the user for merging remote EJB objects into the unit of work. -
shouldMergeOriginalIntoWorkingCopy
public boolean shouldMergeOriginalIntoWorkingCopy()This is used to revert changes to objects, or during refreshes. -
shouldMergeWorkingCopyIntoOriginal
public boolean shouldMergeWorkingCopyIntoOriginal()This is used during the unit of work commit to merge changes into the parent. -
shouldMergeWorkingCopyIntoRemote
public boolean shouldMergeWorkingCopyIntoRemote()INTERNAL: This happens when serialized remote unit of work has to be merged with local remote unit of work. -
shouldRefreshRemoteObject
public boolean shouldRefreshRemoteObject()INTERNAL: This is used to refresh objects on the remote session -
shouldForceCascade
public boolean shouldForceCascade()This is used to cascade merge even if a clone is already registered. -
getMergedNewObjects
INTERNAL: Used to return a map containing new objects found through the registerObjectForMergeCloneIntoWorkingCopy method.- Returns:
- Map
-
transitionToDeferredLocks
public void transitionToDeferredLocks()INTERNAL: Records that this merge manager has transitioned to use deferred locks during the merge. -
updateCacheKeyProperties
protected void updateCacheKeyProperties(UnitOfWorkImpl unitOfWork, CacheKey cacheKey, Object original, Object clone, ObjectChangeSet objectChangeSet, ClassDescriptor descriptor) INTERNAL: Update CacheKey properties with new information. This method is called if this code actually merges -
getLockThread
INTERNAL:- Returns:
- lockThread
-
setLockThread
INTERNAL: Save the currentThread for later comparison to the activeThread in case they don't match
-