Class MergeManager
- java.lang.Object
-
- org.eclipse.persistence.internal.sessions.MergeManager
-
public class MergeManager extends Object
Purpose: Used to manage the merge of two objects in a unit of work.
- Since:
- TOPLink/Java 1.1
- Author:
- James Sutherland
-
-
Field Summary
Fields Modifier and Type Field Description protected ArrayList<CacheKey>
acquiredLocks
Used to store the list of locks that this merge manager has acquired for this mergestatic int
CASCADE_ALL_PARTS
static int
CASCADE_BY_MAPPING
static int
CASCADE_PRIVATE_PARTS
protected int
cascadePolicy
Policy that determines how the merge will cascade to its object's parts.protected static int
CHANGES_INTO_DISTRIBUTED_CACHE
protected static int
CLONE_INTO_WORKING_COPY
protected static int
CLONE_WITH_REFS_INTO_WORKING_COPY
protected boolean
forceCascade
Force cascade merge even if a clone is already registeredprotected boolean
isForRefresh
records that this merge process is for a refreshprotected boolean
isTransitionedToDeferredLocks
records that deferred locks have been employed for the merge processstatic boolean
LOCK_ON_MERGE
Backdoor to disable merge locks.protected Thread
lockThread
save the currentThread for later comparison to the activeThread in case they don't matchprotected IdentityHashMap
mergedNewObjects
Used to keep track of merged new objects.protected int
mergePolicy
Policy that determines merge type (i.e.static int
NO_CASCADE
protected Map
objectDescriptors
Used only while refreshing objects on remote sessionprotected Map<AbstractSession,Map<Object,Object>>
objectsAlreadyMerged
Used to unravel recursion.protected static int
ORIGINAL_INTO_WORKING_COPY
protected LinkedNode
queueNode
Stores the node that holds this mergemanager within the WriteLocksManager queueprotected static int
REFRESH_REMOTE_OBJECT
protected AbstractSession
session
The unit of work merging for.protected long
systemTime
Stored so that all objects merged by a merge manager can have the same readTime.protected static int
WORKING_COPY_INTO_ORIGINAL
protected static int
WORKING_COPY_INTO_REMOTE
protected Object
writeLockQueued
If this variable is not null then the mergemanager is waiting on a particular primary key
-
Constructor Summary
Constructors Constructor Description MergeManager(AbstractSession session)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cascadeAllParts()
Cascade all parts, this is the default for the merge.void
cascadePrivateParts()
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
dontCascadeParts()
Merge only direct parts, this can be used to merge clone when using RMI.ArrayList<CacheKey>
getAcquiredLocks()
int
getCascadePolicy()
Thread
getLockThread()
INTERNAL:IdentityHashMap
getMergedNewObjects()
INTERNAL: Used to return a map containing new objects found through the registerObjectForMergeCloneIntoWorkingCopy method.Object
getMergedObject(Object key, AbstractSession targetSession)
protected int
getMergePolicy()
Map
getObjectDescriptors()
Map
getObjectsAlreadyMerged()
Object
getObjectToMerge(Object sourceValue, ClassDescriptor descriptor, AbstractSession targetSession)
LinkedNode
getQueueNode()
INTENRAL: Used to get the node that this merge manager is stored in, within the WriteLocksManager write lockers queueAbstractSession
getSession()
long
getSystemTime()
Get the stored value of the current time.Object
getTargetVersionOfSourceObject(Object source, ClassDescriptor descriptor, AbstractSession targetSession)
Return the corresponding value that should be assigned to the target object for the source object.Object
getWriteLockQueued()
INTENRAL: Used to get the object that the merge manager is waiting on, in order to acquire locksboolean
isAlreadyMerged(Object object, AbstractSession targetSession)
boolean
isForRefresh()
boolean
isTransitionedToDeferredLocks()
INTERNAL: Will return if the merge process has transitioned the active merge locks to deferred locks for readlock deadlock avoidance.Object
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
mergeChangesOfOriginalIntoWorkingCopy(Object clone)
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.Object
mergeChangesOfWorkingCopyIntoRemote(Object clone)
Recursively merge changes in the object dependent on the merge policy.void
mergeCloneIntoWorkingCopy()
This can be used by the user for merging clones from RMI into the unit of work.void
mergeCloneWithReferencesIntoWorkingCopy()
This is used during the merge of dependent objects referencing independent objects, where you want the independent objects merged as well.void
mergeIntoDistributedCache()
This is used during cache synchronization to merge the changes into the distributed cache.Object
mergeNewObjectIntoCache(ObjectChangeSet changeSet)
Merge a change set for a new object into the cache.void
mergeOriginalIntoWorkingCopy()
This is used to revert changes to objects, or during refreshes.void
mergeWorkingCopyIntoOriginal()
This is used during the unit of work commit to merge changes into the parent.void
mergeWorkingCopyIntoRemote()
This is used during the unit of work commit to merge changes into the parent.void
recordMerge(Object key, Object value, AbstractSession targetSession)
void
refreshRemoteObject()
INTERNAL: This is used to refresh remote session objectObject
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.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 objectDescriptors)
protected void
setObjectsAlreadyMerged(Map 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
shouldCascadeAllParts()
Flag used to determine if all parts should be cascadedboolean
shouldCascadeByMapping()
Flag used to determine that the mappings should be checked for cascade requirements.boolean
shouldCascadeParts()
Flag used to determine if any parts should be cascadedboolean
shouldCascadePrivateParts()
Flag used to determine if any private parts should be cascadedboolean
shouldCascadeReferences()
Refreshes are based on the objects row, so all attributes of the object must be refreshed.boolean
shouldForceCascade()
This is used to cascade merge even if a clone is already registered.boolean
shouldMergeChangesIntoDistributedCache()
INTERNAL: This happens when changes from an UnitOfWork is propagated to a distributed class.boolean
shouldMergeCloneIntoWorkingCopy()
This can be used by the user for merging clones from RMI into the unit of work.boolean
shouldMergeCloneWithReferencesIntoWorkingCopy()
This can be used by the user for merging remote EJB objects into the unit of work.boolean
shouldMergeOriginalIntoWorkingCopy()
This is used to revert changes to objects, or during refreshes.boolean
shouldMergeWorkingCopyIntoOriginal()
This is used during the unit of work commit to merge changes into the parent.boolean
shouldMergeWorkingCopyIntoRemote()
INTERNAL: This happens when serialized remote unit of work has to be merged with local remote unit of work.boolean
shouldRefreshRemoteObject()
INTERNAL: This is used to refresh objects on the remote sessionvoid
transitionToDeferredLocks()
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 Detail
-
session
protected AbstractSession session
The unit of work merging for.
-
objectDescriptors
protected Map objectDescriptors
Used only while refreshing objects on remote session
-
objectsAlreadyMerged
protected Map<AbstractSession,Map<Object,Object>> objectsAlreadyMerged
Used to unravel recursion.
-
mergedNewObjects
protected IdentityHashMap mergedNewObjects
Used to keep track of merged new objects.
-
acquiredLocks
protected ArrayList<CacheKey> acquiredLocks
Used to store the list of locks that this merge manager has acquired for this merge
-
writeLockQueued
protected Object writeLockQueued
If this variable is not null then the mergemanager is waiting on a particular primary key
-
queueNode
protected LinkedNode queueNode
Stores the node that holds this mergemanager within the WriteLocksManager queue
-
mergePolicy
protected int mergePolicy
Policy 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:
- Constant Field Values
-
ORIGINAL_INTO_WORKING_COPY
protected static final int ORIGINAL_INTO_WORKING_COPY
- See Also:
- Constant Field Values
-
CLONE_INTO_WORKING_COPY
protected static final int CLONE_INTO_WORKING_COPY
- See Also:
- Constant Field Values
-
WORKING_COPY_INTO_REMOTE
protected static final int WORKING_COPY_INTO_REMOTE
- See Also:
- Constant Field Values
-
REFRESH_REMOTE_OBJECT
protected static final int REFRESH_REMOTE_OBJECT
- See Also:
- Constant Field Values
-
CHANGES_INTO_DISTRIBUTED_CACHE
protected static final int CHANGES_INTO_DISTRIBUTED_CACHE
- See Also:
- Constant Field Values
-
CLONE_WITH_REFS_INTO_WORKING_COPY
protected static final int CLONE_WITH_REFS_INTO_WORKING_COPY
- See Also:
- Constant Field Values
-
cascadePolicy
protected int cascadePolicy
Policy that determines how the merge will cascade to its object's parts.
-
NO_CASCADE
public static final int NO_CASCADE
- See Also:
- Constant Field Values
-
CASCADE_PRIVATE_PARTS
public static final int CASCADE_PRIVATE_PARTS
- See Also:
- Constant Field Values
-
CASCADE_ALL_PARTS
public static final int CASCADE_ALL_PARTS
- See Also:
- Constant Field Values
-
CASCADE_BY_MAPPING
public static final int CASCADE_BY_MAPPING
- See Also:
- Constant Field Values
-
LOCK_ON_MERGE
public static boolean LOCK_ON_MERGE
Backdoor to disable merge locks.
-
systemTime
protected long systemTime
Stored so that all objects merged by a merge manager can have the same readTime.
-
forceCascade
protected boolean forceCascade
Force cascade merge even if a clone is already registered
-
isTransitionedToDeferredLocks
protected boolean isTransitionedToDeferredLocks
records that deferred locks have been employed for the merge process
-
lockThread
protected Thread lockThread
save the currentThread for later comparison to the activeThread in case they don't match
-
isForRefresh
protected boolean isForRefresh
records that this merge process is for a refresh
-
-
Constructor Detail
-
MergeManager
public MergeManager(AbstractSession session)
-
-
Method Detail
-
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.
-
getCascadePolicy
public int getCascadePolicy()
-
getMergePolicy
protected int getMergePolicy()
-
getObjectDescriptors
public Map getObjectDescriptors()
-
getObjectsAlreadyMerged
public Map getObjectsAlreadyMerged()
-
getObjectToMerge
public Object getObjectToMerge(Object sourceValue, ClassDescriptor descriptor, AbstractSession targetSession)
-
getQueueNode
public LinkedNode getQueueNode()
INTENRAL: Used to get the node that this merge manager is stored in, within the WriteLocksManager write lockers queue
-
getSession
public AbstractSession 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
public Object 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
public void recordMerge(Object key, Object value, AbstractSession targetSession)
-
isAlreadyMerged
public boolean isAlreadyMerged(Object object, AbstractSession targetSession)
-
getMergedObject
public Object getMergedObject(Object key, AbstractSession targetSession)
-
mergeChangesForRefreshingRemoteObject
protected Object mergeChangesForRefreshingRemoteObject(Object serverSideDomainObject)
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
public void mergeChangesFromChangeSet(UnitOfWorkChangeSet uowChangeSet)
INTERNAL: Merge the changes to all objects to session's cache.
-
mergeChangesIntoDistributedCache
protected Object mergeChangesIntoDistributedCache(Object original, ObjectChangeSet changeSet)
Merge the changes specified within the changeSet into the cache. The object passed in is the original object from the cache.
-
mergeChangesOfCloneIntoWorkingCopy
protected Object mergeChangesOfCloneIntoWorkingCopy(Object rmiClone)
Recursively merge to rmi clone into the unit of work working copy. The map is used to resolve recursion.
-
mergeChangesOfOriginalIntoWorkingCopy
protected Object mergeChangesOfOriginalIntoWorkingCopy(Object clone)
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
public Object mergeChangesOfWorkingCopyIntoRemote(Object clone) throws ValidationException
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
public Object mergeNewObjectIntoCache(ObjectChangeSet changeSet)
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
public 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. 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
public void setObjectDescriptors(Map objectDescriptors)
-
setObjectsAlreadyMerged
protected void setObjectsAlreadyMerged(Map objectsAlreadyMerged)
-
setQueueNode
public void setQueueNode(LinkedNode node)
INTENRAL: Used to set the node that this merge manager is stored in, within the WriteLocksManager write lockers queue
-
setSession
protected void setSession(AbstractSession session)
-
setWriteLockQueued
public 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.
-
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
public IdentityHashMap 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
public Thread getLockThread()
INTERNAL:- Returns:
- lockThread
-
setLockThread
public void setLockThread(Thread lockThread)
INTERNAL: Save the currentThread for later comparison to the activeThread in case they don't match- Parameters:
lockThread
-
-
-