Package org.eclipse.persistence.internal.sessions

Examples of org.eclipse.persistence.internal.sessions.ObjectChangeSet$ObjectChangeSetComparator


            } else if ((backupValue == null) && (firstValue != null)) {//the object was not in the backup
                return true;
            } else {
                ObjectBuilder builder = getReferenceDescriptor(firstValue.getClass(), session).getObjectBuilder();

                ObjectChangeSet changes = builder.compareForChange(firstValue, backupValue, uowComparisonChangeSet, session);
                if (changes != null) {
                        return true;
                } else {
                    originalKeyValues.remove(firstKey);
                }
View Full Code Here


        while (cp.hasNext(cloneIter)) {
            Object entry = cp.nextEntry(cloneIter, session);
            Object aggregateObject = cp.unwrapIteratorResult(entry);
            // For CR#2258 quietly ignore nulls inserted into a collection.
            if (aggregateObject != null) {
                ObjectChangeSet changes = getReferenceDescriptor(aggregateObject.getClass(), session).getObjectBuilder().compareForChange(aggregateObject, null, (UnitOfWorkChangeSet)owner.getUOWChangeSet(), session);
                changes.setNewKey(cp.keyFromIterator(cloneIter));
                collectionChanges.addElement(changes);
            }
        }

        //cr 3013 Removed if collection is empty return null block, which prevents recording clear() change
View Full Code Here

        // iterate over the changes and merge the collections
        Vector aggregateObjects = ((AggregateCollectionChangeRecord)changeRecord).getChangedValues();
        int size = aggregateObjects.size();
        valueOfTarget = containerPolicy.containerInstance(size);
        // Next iterate over the changes and add them to the container
        ObjectChangeSet objectChanges = null;
        for (int index = 0; index < size; ++index) {
            objectChanges = (ObjectChangeSet)aggregateObjects.elementAt(index);
            Class localClassType = objectChanges.getClassType(session);
            sourceAggregate = objectChanges.getUnitOfWorkClone();

            // cr 4155 Load the target from the UnitOfWork.  This will be the original
            // aggregate object that has the original indirection in it.
            Object targetAggregate = ((UnitOfWorkImpl)mergeManager.getSession()).getCloneToOriginals().get(sourceAggregate);

            if (targetAggregate == null) {
                targetAggregate = getReferenceDescriptor(localClassType, session).getObjectBuilder().buildNewInstance();
            }
            getReferenceDescriptor(localClassType, session).getObjectBuilder().mergeChangesIntoObject(targetAggregate, objectChanges, sourceAggregate, mergeManager, targetSession);
            containerPolicy.addInto(objectChanges.getNewKey(), targetAggregate, valueOfTarget, session);
        }
        setRealAttributeValueInObject(target, valueOfTarget);
    }
View Full Code Here

    public void postCalculateChanges(org.eclipse.persistence.sessions.changesets.ChangeRecord changeRecord, UnitOfWorkImpl uow) {
        // targets are added to and/or removed to/from the source.
        CollectionChangeRecord collectionChangeRecord = (CollectionChangeRecord)changeRecord;
        Iterator it = collectionChangeRecord.getAddObjectList().values().iterator();
        while(it.hasNext()) {
            ObjectChangeSet change = (ObjectChangeSet)it.next();
            if(!change.hasChanges()) {
                change.setShouldModifyVersionField(Boolean.TRUE);
                ((org.eclipse.persistence.internal.sessions.UnitOfWorkChangeSet)change.getUOWChangeSet()).addObjectChangeSet(change, uow, false);
            }
        }
        // in the mapping is privately owned then the target will be deleted - no need to modify target version.
        it = collectionChangeRecord.getRemoveObjectList().values().iterator();
        while(it.hasNext()) {
            ObjectChangeSet change = (ObjectChangeSet)it.next();
            if (!isPrivateOwned()){
                if(!change.hasChanges()) {
                    change.setShouldModifyVersionField(Boolean.TRUE);
                    ((org.eclipse.persistence.internal.sessions.UnitOfWorkChangeSet)change.getUOWChangeSet()).addObjectChangeSet(change, uow, false);
                }
            }else{
                containerPolicy.postCalculateChanges(change, referenceDescriptor, this, uow);
            }
        }
View Full Code Here

        Object col = getRealCollectionAttributeValueFromObject(deletedObject, uow);
        if (col != null) {
            Object iterator = this.containerPolicy.iteratorFor(col);
            while (this.containerPolicy.hasNext(iterator)) {
                Object target = this.containerPolicy.next(iterator, uow);
                ObjectChangeSet change = this.referenceDescriptor.getObjectBuilder().createObjectChangeSet(target, uowChangeSet, uow);
                if (!change.hasChanges()) {
                    change.setShouldModifyVersionField(Boolean.TRUE);
                    ((org.eclipse.persistence.internal.sessions.UnitOfWorkChangeSet)change.getUOWChangeSet()).addObjectChangeSet(change, uow, false);
                }
            }
        }
    }
View Full Code Here

    protected void createChangeSetForKeys(Map originalKeyValues, CollectionChangeRecord changeRecord, AbstractSession session, ClassDescriptor referenceDescriptor){
        Iterator originalKeyValuesIterator = originalKeyValues.values().iterator();
        while (originalKeyValuesIterator.hasNext()){
            Association association = (Association)originalKeyValuesIterator.next();
            Object object = association.getValue();
            ObjectChangeSet changeSet = referenceDescriptor.getObjectBuilder().createObjectChangeSet(object, (UnitOfWorkChangeSet) changeRecord.getOwner().getUOWChangeSet(), session);
            changeSet.setOldKey(association.getKey());
        }
    }
View Full Code Here

            ClassDescriptor tempValueDescriptor = session.getDescriptor(value.getClass());
            if (tempValueDescriptor != null){
                valueDescriptor = tempValueDescriptor;
            }
        }
        ObjectChangeSet changeSet = valueDescriptor.getObjectBuilder().createObjectChangeSet(value, uowChangeSet, session);
        Object key = ((Map.Entry)object).getKey();
        changeSet.setNewKey(key);
    }
View Full Code Here

     * Merge changes from the source to the target object. Because this is a
     * collection mapping, values are added to or removed from the collection
     * based on the change set.
     */
    public void mergeChanges(CollectionChangeRecord changeRecord, Object valueOfTarget, boolean shouldMergeCascadeParts, MergeManager mergeManager, AbstractSession parentSession) {
        ObjectChangeSet objectChanges;
        // Ensure the collection is synchronized while changes are being made,
        // clone also synchronizes on collection (does not have cache key read-lock for indirection).
        // Must synchronize of the real collection as the clone does so.
        Object synchronizedValueOfTarget = valueOfTarget;
        if (valueOfTarget instanceof IndirectCollection) {
            synchronizedValueOfTarget = ((IndirectCollection)valueOfTarget).getDelegateObject();
        }
        synchronized (synchronizedValueOfTarget) {
            if (!changeRecord.getOrderedChangeObjectList().isEmpty()){
                //Attribute change tracking merge behavior
                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
                // Step 1 - iterate over the removed changes and remove them from the container.
                Vector removedIndices = changeRecord.getOrderedRemoveObjectIndices();
   
                if (removedIndices.isEmpty()) {
                    // Check if we have removed objects via a
                    // simpleRemoveFromCollectionChangeRecord API call.
                    Iterator removedObjects = changeRecord.getRemoveObjectList().keySet().iterator();
               
                    while (removedObjects.hasNext()) {
                        objectChanges = (ObjectChangeSet) removedObjects.next();
                        removeFrom(objectChanges.getOldKey(), objectChanges.getTargetVersionOfSourceObject(mergeManager.getSession()), valueOfTarget, parentSession);
                        registerRemoveNewObjectIfRequired(objectChanges, mergeManager);
                    }
                } else {
                    for (int i = removedIndices.size() - 1; i >= 0; i--) {
                        Integer index = ((Integer) removedIndices.elementAt(i)).intValue();
                        objectChanges = (ObjectChangeSet) changeRecord.getOrderedRemoveObject(index);
                        Object objectToRemove = objectChanges.getTargetVersionOfSourceObject(mergeManager.getSession());
                        if ( (objectToRemove!=null) &&
                                    (objectToRemove.equals(get(index, valueOfTarget, mergeManager.getSession()) )) ) {
                            removeFromAtIndex(index, valueOfTarget);
                            // The object was actually removed and not moved.
                            if (changeRecord.getRemoveObjectList().containsKey(objectChanges)) {
                                registerRemoveNewObjectIfRequired(objectChanges, mergeManager);
                            }
                        } else {
                       
                            //Object is either not in the cache, or not 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;
                        }
                    }
                }
               
                // Step 2 - iterate over the added changes and add them to the container.
                Enumeration addObjects = changeRecord.getOrderedAddObjects().elements();
                while (addObjects.hasMoreElements()) {
                    objectChanges =  (ObjectChangeSet) addObjects.nextElement();
                    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.
View Full Code Here

                                backUpVersion = firstObject;
                            } else {
                                backUpVersion = ((UnitOfWorkImpl)session).getBackupClone(firstObject, referenceDescriptor);
                            }
                           
                            ObjectChangeSet changeSet = referenceDescriptor.getObjectBuilder().createObjectChangeSet(firstObject, (UnitOfWorkChangeSet) changeRecord.getOwner().getUOWChangeSet(), session);
                            changeSet.setOldKey(keyFrom(backUpVersion, session));
                            changeSet.setNewKey(keyFrom(firstObject, session));
                            cloneKeyValues.put(firstObject, firstObject);
                        }
                    } else {
                        // Place it in the add collection
                        cloneKeyValues.put(firstObject, firstObject);
View Full Code Here

     * Merge changes from the source to the target object. Because this is a
     * collection mapping, values are added to or removed from the collection
     * based on the change set.
     */
    public void mergeChanges(CollectionChangeRecord changeRecord, Object valueOfTarget, boolean shouldMergeCascadeParts, MergeManager mergeManager, AbstractSession parentSession) {
        ObjectChangeSet objectChanges;       
        // Step 1 - iterate over the removed changes and remove them from the container.
        Iterator removeObjects = changeRecord.getRemoveObjectList().keySet().iterator();
        // Ensure the collection is synchronized while changes are being made,
        // clone also synchronizes on collection (does not have cache key read-lock for indirection).
        // Must synchronize of the real collection as the clone does so.
        Object synchronizedValueOfTarget = valueOfTarget;
        if (valueOfTarget instanceof IndirectCollection) {
            synchronizedValueOfTarget = ((IndirectCollection)valueOfTarget).getDelegateObject();
        }
        synchronized (synchronizedValueOfTarget) {
            while (removeObjects.hasNext()) {
                objectChanges = (ObjectChangeSet) removeObjects.next();               
                removeFrom(objectChanges.getOldKey(), objectChanges.getTargetVersionOfSourceObject(mergeManager.getSession()), valueOfTarget, parentSession);
                if (!mergeManager.shouldMergeChangesIntoDistributedCache()) {
                    mergeManager.registerRemovedNewObjectIfRequired(objectChanges.getUnitOfWorkClone());
                }
            }
           
            // Step 2 - iterate over the added changes and add them to the container.
            Iterator addObjects = changeRecord.getAddObjectList().keySet().iterator();               
            while (addObjects.hasNext()) {
                objectChanges = (ObjectChangeSet) addObjects.next();
                Object object = null;                   
                if (shouldMergeCascadeParts) {
                    object = mergeCascadeParts(objectChanges, mergeManager, parentSession);
                }                   
                if (object == null) {
                    // Retrieve the object to be added to the collection.
                    object = objectChanges.getTargetVersionOfSourceObject(mergeManager.getSession(), false);
                }
                // I am assuming that at this point the above merge will have created a new object if required
                if (mergeManager.shouldMergeChangesIntoDistributedCache()) {
                    //bug#4458089 and 4454532- check if collection contains new item before adding during merge into distributed cache         
                    if (!contains(object, valueOfTarget, mergeManager.getSession())) {
                        addInto(objectChanges.getNewKey(), object, valueOfTarget, mergeManager.getSession());
                    }
                } else {
                    addInto(objectChanges.getNewKey(), object, valueOfTarget, mergeManager.getSession());   
                }
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.eclipse.persistence.internal.sessions.ObjectChangeSet$ObjectChangeSetComparator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.