Search in sources :

Example 91 with ContainerPolicy

use of org.eclipse.persistence.internal.queries.ContainerPolicy in project eclipselink by eclipse-ee4j.

the class ArrayCollectionMappingHelper 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
    Vector cloneVector = cp.vectorFor(cloneCollection, session);
    // "clone" it so we can clear out the slots
    Vector backupVector = cp.vectorFor(backupCollection, session);
    EISOrderedCollectionChangeRecord changeRecord = new EISOrderedCollectionChangeRecord(owner, getAttributeName(), this.getDatabaseMapping());
    for (int i = 0; i < cloneVector.size(); i++) {
        Object cloneElement = cloneVector.elementAt(i);
        boolean found = false;
        for (int j = 0; j < backupVector.size(); j++) {
            if (this.compareElementsForChange(cloneElement, backupVector.elementAt(j), session)) {
                // the clone element was found in the backup collection
                found = true;
                // clear out the matching backup element
                backupVector.setElementAt(XXX, j);
                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.elementAt(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) EISOrderedCollectionChangeRecord(org.eclipse.persistence.eis.EISOrderedCollectionChangeRecord) Vector(java.util.Vector)

Example 92 with ContainerPolicy

use of org.eclipse.persistence.internal.queries.ContainerPolicy in project eclipselink by eclipse-ee4j.

the class NestedTableMapping method verifyDeleteForUpdate.

/**
 * INTERNAL:
 * Verifying deletes make sure that all the records privately owned by this mapping are
 * actually removed. If such records are found then those are all read and removed one
 * by one taking their privately owned parts into account.
 */
protected void verifyDeleteForUpdate(DeleteObjectQuery query) throws DatabaseException, OptimisticLockException {
    Object objects = readPrivateOwnedForObject(query);
    // Delete all objects one by one.
    ContainerPolicy cp = getContainerPolicy();
    for (Object iter = cp.iteratorFor(objects); cp.hasNext(iter); ) {
        query.getSession().deleteObject(cp.next(iter, query.getSession()));
    }
}
Also used : ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy)

Example 93 with ContainerPolicy

use of org.eclipse.persistence.internal.queries.ContainerPolicy in project eclipselink by eclipse-ee4j.

the class NestedTableMapping method preInsert.

/**
 * INTERNAL:
 * Insert privately owned parts
 */
@Override
public void preInsert(WriteObjectQuery query) throws DatabaseException, OptimisticLockException {
    if (!shouldObjectModifyCascadeToParts(query)) {
        return;
    }
    Object objects = getRealCollectionAttributeValueFromObject(query.getObject(), query.getSession());
    // insert each object one by one
    ContainerPolicy cp = getContainerPolicy();
    for (Object iter = cp.iteratorFor(objects); cp.hasNext(iter); ) {
        Object object = cp.next(iter, query.getSession());
        if (isPrivateOwned()) {
            InsertObjectQuery insertQuery = new InsertObjectQuery();
            insertQuery.setIsExecutionClone(true);
            insertQuery.setObject(object);
            insertQuery.setCascadePolicy(query.getCascadePolicy());
            query.getSession().executeQuery(insertQuery);
        } else {
            // Avoid cycles by checking commit manager, this is allowed because there is no dependency.
            if (!query.getSession().getCommitManager().isCommitInPreModify(object)) {
                ObjectChangeSet changeSet = null;
                UnitOfWorkChangeSet uowChangeSet = null;
                if (query.getSession().isUnitOfWork() && (((UnitOfWorkImpl) query.getSession()).getUnitOfWorkChangeSet() != null)) {
                    uowChangeSet = (UnitOfWorkChangeSet) ((UnitOfWorkImpl) query.getSession()).getUnitOfWorkChangeSet();
                    changeSet = (ObjectChangeSet) uowChangeSet.getObjectChangeSetForClone(object);
                }
                WriteObjectQuery writeQuery = new WriteObjectQuery();
                writeQuery.setIsExecutionClone(true);
                writeQuery.setObject(object);
                writeQuery.setObjectChangeSet(changeSet);
                writeQuery.setCascadePolicy(query.getCascadePolicy());
                query.getSession().executeQuery(writeQuery);
            }
        }
    }
}
Also used : ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) WriteObjectQuery(org.eclipse.persistence.queries.WriteObjectQuery) UnitOfWorkChangeSet(org.eclipse.persistence.internal.sessions.UnitOfWorkChangeSet) ObjectChangeSet(org.eclipse.persistence.internal.sessions.ObjectChangeSet) UnitOfWorkImpl(org.eclipse.persistence.internal.sessions.UnitOfWorkImpl) InsertObjectQuery(org.eclipse.persistence.queries.InsertObjectQuery)

Example 94 with ContainerPolicy

use of org.eclipse.persistence.internal.queries.ContainerPolicy in project eclipselink by eclipse-ee4j.

the class NestedTableMapping method writeFromObjectIntoRowWithChangeRecord.

/**
 * INTERNAL:
 * Get a value from the object and set that in the respective field of the row.
 */
@Override
public void writeFromObjectIntoRowWithChangeRecord(ChangeRecord changeRecord, AbstractRecord record, AbstractSession session, WriteType writeType) {
    if (isReadOnly()) {
        return;
    }
    Object object = ((ObjectChangeSet) changeRecord.getOwner()).getUnitOfWorkClone();
    Object values = getRealAttributeValueFromObject(object, session);
    ContainerPolicy containterPolicy = getContainerPolicy();
    if (values == null) {
        values = containterPolicy.containerInstance(1);
    }
    Object[] fields = new Object[containterPolicy.sizeFor(values)];
    Object valuesIterator = containterPolicy.iteratorFor(values);
    for (int index = 0; index < containterPolicy.sizeFor(values); index++) {
        Object value = containterPolicy.next(valuesIterator, session);
        fields[index] = ((ObjectRelationalDataTypeDescriptor) getReferenceDescriptor()).getRef(value, session);
    }
    java.sql.Array array;
    try {
        session.getAccessor().incrementCallCount(session);
        java.sql.Connection connection = session.getAccessor().getConnection();
        array = session.getPlatform().createArray(getStructureName(), fields, session, connection);
    } catch (java.sql.SQLException exception) {
        throw DatabaseException.sqlException(exception, session.getAccessor(), session, false);
    } finally {
        session.getAccessor().decrementCallCount();
    }
    record.put(getField(), array);
}
Also used : ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) ObjectChangeSet(org.eclipse.persistence.internal.sessions.ObjectChangeSet)

Example 95 with ContainerPolicy

use of org.eclipse.persistence.internal.queries.ContainerPolicy in project eclipselink by eclipse-ee4j.

the class ArrayCollectionMappingHelper method compareAttributeValuesWithoutOrder.

/**
 * Compare the attributes. Return true if they are alike.
 * Ignore the order of the elements.
 */
private boolean compareAttributeValuesWithoutOrder(Object collection1, Object collection2, AbstractSession session) {
    ContainerPolicy cp = this.getContainerPolicy();
    // "clone" it so we can clear out the slots
    Vector vector2 = cp.vectorFor(collection2, session);
    for (Object iter1 = cp.iteratorFor(collection1); cp.hasNext(iter1); ) {
        Object element1 = cp.next(iter1, session);
        boolean found = false;
        for (int i = 0; i < vector2.size(); i++) {
            if (this.compareElements(element1, vector2.elementAt(i), session)) {
                found = true;
                // clear out the matching element
                vector2.setElementAt(XXX, i);
                // matching element found - skip the rest of them
                break;
            }
        }
        if (!found) {
            return false;
        }
    }
    // look for elements that were not in collection1
    for (Enumeration stream = vector2.elements(); stream.hasMoreElements(); ) {
        if (stream.nextElement() != XXX) {
            return false;
        }
    }
    return true;
}
Also used : ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) Enumeration(java.util.Enumeration) Vector(java.util.Vector)

Aggregations

ContainerPolicy (org.eclipse.persistence.internal.queries.ContainerPolicy)119 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)28 AbstractRecord (org.eclipse.persistence.internal.sessions.AbstractRecord)17 XMLRecord (org.eclipse.persistence.oxm.record.XMLRecord)17 List (java.util.List)14 Vector (java.util.Vector)14 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)14 XMLField (org.eclipse.persistence.oxm.XMLField)14 ArrayList (java.util.ArrayList)13 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)13 Collection (java.util.Collection)12 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)10 CollectionContainerPolicy (org.eclipse.persistence.internal.queries.CollectionContainerPolicy)9 InstanceVariableAttributeAccessor (org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor)8 MethodAttributeAccessor (org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor)8 AttributeAccessor (org.eclipse.persistence.mappings.AttributeAccessor)8 HashMap (java.util.HashMap)7 VirtualAttributeAccessor (org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor)7 CustomAccessorAttributeAccessor (org.eclipse.persistence.internal.jaxb.CustomAccessorAttributeAccessor)7 JAXBSetMethodAttributeAccessor (org.eclipse.persistence.internal.jaxb.JAXBSetMethodAttributeAccessor)7