}
synchronized (synchronizedValueOfTarget) {
if (!changeRecord.getOrderedChangeObjectList().isEmpty()) {
Iterator objects =changeRecord.getOrderedChangeObjectList().iterator();
while (objects.hasNext()){
OrderedChangeObject changeObject = (OrderedChangeObject)objects.next();
objectChanges = changeObject.getChangeSet();
if (changeObject.getChangeType() == CollectionChangeEvent.REMOVE){
boolean objectRemoved = changeRecord.getRemoveObjectList().containsKey(objectChanges);
Object objectToRemove = objectChanges.getTargetVersionOfSourceObject(mergeManager, targetSession);
//if objectToRemove is null, we can't look it up in the collection.
// This should not happen unless identity is lost.
if (objectToRemove != null) {
Integer index = changeObject.getIndex();
if (index!=null){
if (objectToRemove.equals(get(index, valueOfTarget, mergeManager.getSession()))) {
removeFromAtIndex(index, valueOfTarget);
} else {
// Object is in the cache, but the collection doesn't have it at the location we expect
// Collection is invalid with respect to these changes, so invalidate the parent and abort
Object key = changeRecord.getOwner().getId();
targetSession.getIdentityMapAccessor().invalidateObject(key, changeRecord.getOwner().getClassType(targetSession));
return;
}
} else {
removeFrom(objectToRemove, valueOfTarget, targetSession);
}
if ((! mergeManager.shouldMergeChangesIntoDistributedCache()) && changeRecord.getMapping().isPrivateOwned()) {
// Check that the object was actually removed and not moved.
if (objectRemoved) {
mergeManager.registerRemovedNewObjectIfRequired(objectChanges.getUnitOfWorkClone());
}
}
}
} else { //getChangeType == add
boolean objectAdded = changeRecord.getAddObjectList().containsKey(objectChanges);
Object object = null;
// The object was actually added and not moved.
if (objectAdded && shouldMergeCascadeParts) {
object = mergeCascadeParts(objectChanges, mergeManager, targetSession);
}
if (object == null) {
// Retrieve the object to be added to the collection.
object = objectChanges.getTargetVersionOfSourceObject(mergeManager, targetSession);
}
// Assume at this point the above merge will have created a new
// object if required and that the object was actually added and
// not moved.
if (objectAdded && mergeManager.shouldMergeChangesIntoDistributedCache()) {
// Bugs 4458089 & 4454532 - check if collection contains new item before adding
// during merge into distributed cache
if (! contains(object, valueOfTarget, mergeManager.getSession())) {
addIntoAtIndex(changeObject.getIndex(), object, valueOfTarget, mergeManager.getSession());
}
} else {
addIntoAtIndex(changeObject.getIndex(), object, valueOfTarget, targetSession);
}
}
}
} else {
//Deferred change tracking merge behavior