Search in sources :

Example 1 with EISOrderedCollectionChangeRecord

use of org.eclipse.persistence.eis.EISOrderedCollectionChangeRecord in project eclipselink by eclipse-ee4j.

the class EISOneToManyMappingHelper method simpleRemoveFromCollectionChangeRecordWithOrder.

/**
 * Remove stuff from an ordered collection.
 */
private void simpleRemoveFromCollectionChangeRecordWithOrder(Object referenceKey, Object changeSetToRemove, ObjectChangeSet changeSet, AbstractSession session) {
    EISOrderedCollectionChangeRecord changeRecord = (EISOrderedCollectionChangeRecord) changeSet.getChangesForAttributeNamed(this.getAttributeName());
    if (changeRecord == null) {
        changeRecord = new EISOrderedCollectionChangeRecord(changeSet, this.getAttributeName(), this.getDatabaseMapping());
        changeSet.addChange(changeRecord);
    }
    changeRecord.simpleRemoveChangeSet(changeSetToRemove);
}
Also used : EISOrderedCollectionChangeRecord(org.eclipse.persistence.eis.EISOrderedCollectionChangeRecord)

Example 2 with EISOrderedCollectionChangeRecord

use of org.eclipse.persistence.eis.EISOrderedCollectionChangeRecord in project eclipselink by eclipse-ee4j.

the class EISOneToManyMappingHelper method mergeChangesIntoObjectWithOrder.

/**
 * Merge changes from the source to the target object.
 * Simply replace the entire target collection.
 */
private void mergeChangesIntoObjectWithOrder(Object target, ChangeRecord changeRecord, Object source, MergeManager mergeManager, AbstractSession targetSession) {
    ContainerPolicy cp = this.getContainerPolicy();
    AbstractSession session = mergeManager.getSession();
    List changes = ((EISOrderedCollectionChangeRecord) changeRecord).getNewCollection();
    Object targetCollection = cp.containerInstance(changes.size());
    for (Object changed : changes) {
        Object targetElement = buildAddedElementFromChangeSet(changed, mergeManager, targetSession);
        cp.addInto(targetElement, targetCollection, session);
    }
    // reset the attribute to allow for set method to re-morph changes if the collection is not being stored directly
    this.setRealAttributeValueInObject(target, targetCollection);
}
Also used : ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) List(java.util.List) EISOrderedCollectionChangeRecord(org.eclipse.persistence.eis.EISOrderedCollectionChangeRecord) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

Example 3 with EISOrderedCollectionChangeRecord

use of org.eclipse.persistence.eis.EISOrderedCollectionChangeRecord in project eclipselink by eclipse-ee4j.

the class EISOneToManyMappingHelper method compareAttributeValuesForChangeWithOrder.

/**
 * Build and return the change record that results
 * from comparing the two collection attributes.
 * The order of the elements is significant.
 */
private ChangeRecord compareAttributeValuesForChangeWithOrder(Object cloneCollection, Object backupCollection, ObjectChangeSet owner, AbstractSession session) {
    ContainerPolicy cp = this.getContainerPolicy();
    // convert it to a Vector so we can preserve the order and use indexes
    List cloneVector = cp.vectorFor(cloneCollection, session);
    // "clone" it so we can clear out the slots
    List backupVector = cp.vectorFor(backupCollection, session);
    EISOrderedCollectionChangeRecord changeRecord = new EISOrderedCollectionChangeRecord(owner, this.getAttributeName(), this.getDatabaseMapping());
    for (int i = 0; i < cloneVector.size(); i++) {
        Object cloneElement = cloneVector.get(i);
        boolean found = false;
        for (int j = 0; j < backupVector.size(); j++) {
            if (this.compareElementsForChange(cloneElement, backupVector.get(j), session)) {
                // the clone element was found in the backup collection
                found = true;
                // clear out the matching backup element
                backupVector.set(j, XXX);
                changeRecord.addMovedChangeSet(this.buildChangeSet(cloneElement, owner, session), j, i);
                // matching backup element found - skip the rest of them
                break;
            }
        }
        if (!found) {
            // the clone element was not found, so it must have been added
            changeRecord.addAddedChangeSet(this.buildChangeSet(cloneElement, owner, session), i);
        }
    }
    for (int i = 0; i < backupVector.size(); i++) {
        Object backupElement = backupVector.get(i);
        if (backupElement != XXX) {
            // the backup element was not in the clone collection, so it must have been removed
            changeRecord.addRemovedChangeSet(this.buildChangeSet(backupElement, owner, session), i);
        }
    }
    if (changeRecord.hasChanges()) {
        return changeRecord;
    } else {
        return null;
    }
}
Also used : ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) List(java.util.List) EISOrderedCollectionChangeRecord(org.eclipse.persistence.eis.EISOrderedCollectionChangeRecord)

Example 4 with EISOrderedCollectionChangeRecord

use of org.eclipse.persistence.eis.EISOrderedCollectionChangeRecord in project eclipselink by eclipse-ee4j.

the class ArrayCollectionMappingHelper method mergeChangesIntoObjectWithOrder.

/**
 * Merge changes from the source to the target object.
 * Simply replace the entire target collection.
 */
private void mergeChangesIntoObjectWithOrder(Object target, ChangeRecord changeRecord, Object source, MergeManager mergeManager, AbstractSession targetSession) {
    ContainerPolicy cp = getContainerPolicy();
    AbstractSession session = mergeManager.getSession();
    List changes = ((EISOrderedCollectionChangeRecord) changeRecord).getNewCollection();
    Object targetCollection = cp.containerInstance(changes.size());
    for (Object changed : changes) {
        Object targetElement = buildAddedElementFromChangeSet(changed, mergeManager, targetSession);
        cp.addInto(targetElement, targetCollection, session);
    }
    // reset the attribute to allow for set method to re-morph changes if the collection is not being stored directly
    this.setRealAttributeValueInObject(target, targetCollection);
}
Also used : ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) List(java.util.List) EISOrderedCollectionChangeRecord(org.eclipse.persistence.eis.EISOrderedCollectionChangeRecord) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

Example 5 with EISOrderedCollectionChangeRecord

use of org.eclipse.persistence.eis.EISOrderedCollectionChangeRecord in project eclipselink by eclipse-ee4j.

the class ArrayCollectionMappingHelper method simpleRemoveFromCollectionChangeRecordWithOrder.

/**
 * Remove stuff from an ordered collection.
 */
private void simpleRemoveFromCollectionChangeRecordWithOrder(Object referenceKey, Object changeSetToRemove, ObjectChangeSet changeSet, AbstractSession session) {
    EISOrderedCollectionChangeRecord changeRecord = (EISOrderedCollectionChangeRecord) changeSet.getChangesForAttributeNamed(getAttributeName());
    if (changeRecord == null) {
        changeRecord = new EISOrderedCollectionChangeRecord(changeSet, getAttributeName(), getDatabaseMapping());
        changeSet.addChange(changeRecord);
    }
    changeRecord.simpleRemoveChangeSet(changeSetToRemove);
}
Also used : EISOrderedCollectionChangeRecord(org.eclipse.persistence.eis.EISOrderedCollectionChangeRecord)

Aggregations

EISOrderedCollectionChangeRecord (org.eclipse.persistence.eis.EISOrderedCollectionChangeRecord)8 ContainerPolicy (org.eclipse.persistence.internal.queries.ContainerPolicy)4 List (java.util.List)3 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)2 Vector (java.util.Vector)1