Vector removedList = new Vector();
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.getSession());
//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
Vector key = ((org.eclipse.persistence.internal.sessions.ObjectChangeSet)changeRecord.getOwner()).getPrimaryKeys();
parentSession.getIdentityMapAccessor().invalidateObject(key, changeRecord.getOwner().getClassType(parentSession));
return;
}
} else{
removeFrom(objectToRemove, valueOfTarget, parentSession);
}
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, parentSession);
}
if (object == null) {
// Retrieve the object to be added to the collection.
object = objectChanges.getTargetVersionOfSourceObject(mergeManager.getSession());
}
// 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, mergeManager.getSession());
}
}
}
} else {
//Deferred change tracking merge behavior