Search in sources :

Example 81 with ContainerPolicy

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

the class AggregateCollectionMapping method loadAll.

/**
 * Force instantiation of all indirections.
 */
@Override
public void loadAll(Object object, AbstractSession session, IdentityHashSet loaded) {
    instantiateAttribute(object, session);
    Object value = getRealAttributeValueFromObject(object, session);
    ContainerPolicy cp = this.containerPolicy;
    for (Object iterator = cp.iteratorFor(value); cp.hasNext(iterator); ) {
        Object wrappedObject = cp.nextEntry(iterator, session);
        Object nestedObject = cp.unwrapIteratorResult(wrappedObject);
        getReferenceDescriptor(nestedObject.getClass(), session).getObjectBuilder().loadAll(nestedObject, session, loaded);
    }
}
Also used : ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy)

Example 82 with ContainerPolicy

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

the class AggregateCollectionMapping method cascadeDiscoverAndPersistUnregisteredNewObjects.

/**
 * INTERNAL:
 * Cascade discover and persist new objects during commit.
 */
@Override
public void cascadeDiscoverAndPersistUnregisteredNewObjects(Object object, Map newObjects, Map unregisteredExistingObjects, Map visitedObjects, UnitOfWorkImpl uow, Set cascadeErrors) {
    // aggregate objects are not registered but their mappings should be.
    Object cloneAttribute = null;
    cloneAttribute = getAttributeValueFromObject(object);
    if ((cloneAttribute == null) || (!getIndirectionPolicy().objectIsInstantiated(cloneAttribute))) {
        return;
    }
    ObjectBuilder builder = null;
    ContainerPolicy cp = getContainerPolicy();
    Object cloneObjectCollection = null;
    cloneObjectCollection = getRealCollectionAttributeValueFromObject(object, uow);
    Object cloneIter = cp.iteratorFor(cloneObjectCollection);
    while (cp.hasNext(cloneIter)) {
        Object wrappedObject = cp.nextEntry(cloneIter, uow);
        Object nextObject = cp.unwrapIteratorResult(wrappedObject);
        if (nextObject != null) {
            builder = getReferenceDescriptor(nextObject.getClass(), uow).getObjectBuilder();
            builder.cascadeDiscoverAndPersistUnregisteredNewObjects(nextObject, newObjects, unregisteredExistingObjects, visitedObjects, uow, cascadeErrors);
            cp.cascadeDiscoverAndPersistUnregisteredNewObjects(wrappedObject, newObjects, unregisteredExistingObjects, visitedObjects, uow, cascadeErrors);
        }
    }
}
Also used : ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) ObjectBuilder(org.eclipse.persistence.internal.descriptors.ObjectBuilder)

Example 83 with ContainerPolicy

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

the class AggregateCollectionMapping method buildBackupCloneForPartObject.

/**
 * INTERNAL:
 * Used during building the backup shallow copy to copy the vector without re-registering the target objects.
 */
@Override
public Object buildBackupCloneForPartObject(Object attributeValue, Object clone, Object backup, UnitOfWorkImpl unitOfWork) {
    ContainerPolicy containerPolicy = getContainerPolicy();
    if (attributeValue == null) {
        return containerPolicy.containerInstance(1);
    }
    Object clonedAttributeValue = containerPolicy.containerInstance(containerPolicy.sizeFor(attributeValue));
    if (isSynchronizeOnMerge) {
        synchronized (attributeValue) {
            for (Object valuesIterator = containerPolicy.iteratorFor(attributeValue); containerPolicy.hasNext(valuesIterator); ) {
                Object wrappedElement = containerPolicy.nextEntry(valuesIterator, unitOfWork);
                Object cloneValue = buildElementBackupClone(containerPolicy.unwrapIteratorResult(wrappedElement), unitOfWork);
                containerPolicy.addInto(containerPolicy.keyFromIterator(valuesIterator), cloneValue, clonedAttributeValue, unitOfWork);
            }
        }
    } else {
        for (Object valuesIterator = containerPolicy.iteratorFor(attributeValue); containerPolicy.hasNext(valuesIterator); ) {
            Object wrappedElement = containerPolicy.nextEntry(valuesIterator, unitOfWork);
            Object cloneValue = buildElementBackupClone(containerPolicy.unwrapIteratorResult(wrappedElement), unitOfWork);
            containerPolicy.addInto(containerPolicy.keyFromIterator(valuesIterator), cloneValue, clonedAttributeValue, unitOfWork);
        }
    }
    return clonedAttributeValue;
}
Also used : ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy)

Example 84 with ContainerPolicy

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

the class AggregateCollectionMapping method buildCloneForPartObject.

/**
 * INTERNAL:
 * Require for cloning, the part must be cloned.
 * Ignore the objects, use the attribute value.
 * this is identical to the super class except that the element must be added to the new
 * aggregates collection so that the referenced objects will be cloned correctly
 */
@Override
public Object buildCloneForPartObject(Object attributeValue, Object original, CacheKey cacheKey, Object clone, AbstractSession cloningSession, Integer refreshCascade, boolean isExisting, boolean isFromSharedCache) {
    ContainerPolicy containerPolicy = getContainerPolicy();
    if (attributeValue == null) {
        return containerPolicy.containerInstance(1);
    }
    Object clonedAttributeValue = containerPolicy.containerInstance(containerPolicy.sizeFor(attributeValue));
    Object temporaryCollection = null;
    if (isSynchronizeOnMerge) {
        // I will use a temporary collection to help speed up the process
        synchronized (attributeValue) {
            temporaryCollection = containerPolicy.cloneFor(attributeValue);
        }
    } else {
        temporaryCollection = attributeValue;
    }
    for (Object valuesIterator = containerPolicy.iteratorFor(temporaryCollection); containerPolicy.hasNext(valuesIterator); ) {
        Object wrappedElement = containerPolicy.nextEntry(valuesIterator, cloningSession);
        Object originalElement = containerPolicy.unwrapIteratorResult(wrappedElement);
        // need to add to aggregate list in the case that there are related objects.
        if (cloningSession.isUnitOfWork() && ((UnitOfWorkImpl) cloningSession).isOriginalNewObject(original)) {
            ((UnitOfWorkImpl) cloningSession).addNewAggregate(originalElement);
        }
        Object cloneValue = buildElementClone(originalElement, clone, cacheKey, refreshCascade, cloningSession, isExisting, isFromSharedCache);
        Object clonedKey = containerPolicy.buildCloneForKey(containerPolicy.keyFromIterator(valuesIterator), clone, cacheKey, refreshCascade, cloningSession, isExisting, isFromSharedCache);
        containerPolicy.addInto(clonedKey, cloneValue, clonedAttributeValue, cloningSession);
    }
    if (temporaryCollection instanceof IndirectList) {
        ((IndirectList) clonedAttributeValue).setIsListOrderBrokenInDb(((IndirectList) temporaryCollection).isListOrderBrokenInDb());
    }
    return clonedAttributeValue;
}
Also used : ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) UnitOfWorkImpl(org.eclipse.persistence.internal.sessions.UnitOfWorkImpl) IndirectList(org.eclipse.persistence.indirection.IndirectList)

Example 85 with ContainerPolicy

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

the class AggregateCollectionMapping method preDelete.

/**
 * INTERNAL:
 * Delete privately owned parts
 */
@Override
public void preDelete(DeleteObjectQuery query) throws DatabaseException, OptimisticLockException {
    if (isReadOnly()) {
        return;
    }
    AbstractSession session = query.getSession();
    // If privately owned parts have their privately own parts, delete those one by one
    // else delete everything in one shot.
    int index = 0;
    if (mustDeleteReferenceObjectsOneByOne()) {
        Object objects = getRealCollectionAttributeValueFromObject(query.getObject(), query.getSession());
        ContainerPolicy cp = getContainerPolicy();
        if (this.isCascadeOnDeleteSetOnDatabase && session.isUnitOfWork()) {
            for (Object iterator = cp.iteratorFor(objects); cp.hasNext(iterator); ) {
                Object wrappedObject = cp.nextEntry(iterator, session);
                Object object = cp.unwrapIteratorResult(wrappedObject);
                ((UnitOfWorkImpl) session).getCascadeDeleteObjects().add(object);
            }
        }
        for (Object iter = cp.iteratorFor(objects); cp.hasNext(iter); ) {
            Object wrappedObject = cp.nextEntry(iter, session);
            DeleteObjectQuery deleteQuery = new DeleteObjectQuery();
            deleteQuery.setIsExecutionClone(true);
            Map extraData = null;
            if (this.listOrderField != null) {
                extraData = new DatabaseRecord(1);
                extraData.put(this.listOrderField, index++);
            }
            prepareModifyQueryForDelete(query, deleteQuery, wrappedObject, extraData);
            session.executeQuery(deleteQuery, deleteQuery.getTranslationRow());
            cp.propogatePreDelete(query, wrappedObject);
        }
        if (!session.isUnitOfWork()) {
            // This deletes any objects on the database, as the collection in memory may has been changed.
            // This is not required for unit of work, as the update would have already deleted these objects,
            // and the backup copy will include the same objects causing double deletes.
            verifyDeleteForUpdate(query);
        }
    } else {
        deleteAll(query, session);
    }
}
Also used : ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord) DeleteObjectQuery(org.eclipse.persistence.queries.DeleteObjectQuery) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

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