Search in sources :

Example 26 with ContainerPolicy

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

the class AggregateCollectionMapping method postInsert.

/**
 * INTERNAL:
 * Insert privately owned parts
 */
@Override
public void postInsert(WriteObjectQuery query) throws DatabaseException, OptimisticLockException {
    if (isReadOnly()) {
        return;
    }
    Object objects = getRealCollectionAttributeValueFromObject(query.getObject(), query.getSession());
    int index = 0;
    // insert each object one by one
    ContainerPolicy cp = getContainerPolicy();
    for (Object iter = cp.iteratorFor(objects); cp.hasNext(iter); ) {
        Object wrappedObject = cp.nextEntry(iter, query.getSession());
        Object object = cp.unwrapIteratorResult(wrappedObject);
        InsertObjectQuery insertQuery = getAndPrepareModifyQueryForInsert(query, object);
        ContainerPolicy.copyMapDataToRow(cp.getKeyMappingDataForWriteQuery(wrappedObject, query.getSession()), insertQuery.getModifyRow());
        if (this.listOrderField != null) {
            insertQuery.getModifyRow().add(this.listOrderField, index++);
        }
        query.getSession().executeQuery(insertQuery, insertQuery.getTranslationRow());
        cp.propogatePostInsert(query, wrappedObject);
    }
}
Also used : ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) InsertObjectQuery(org.eclipse.persistence.queries.InsertObjectQuery)

Example 27 with ContainerPolicy

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

the class AggregateCollectionMapping method cascadeRegisterNewIfRequired.

/**
 * INTERNAL:
 * Cascade registerNew for Create through mappings that require the cascade
 */
@Override
public void cascadeRegisterNewIfRequired(Object object, UnitOfWorkImpl uow, Map visitedObjects) {
    // Aggregate objects are not registered but their mappings should be.
    Object attributeValue = getAttributeValueFromObject(object);
    if ((attributeValue == null) || // Also check if the source is new, then must always cascade.
    (!this.indirectionPolicy.objectIsInstantiated(attributeValue) && !uow.isCloneNewObject(object))) {
        return;
    }
    ObjectBuilder builder = null;
    ContainerPolicy cp = this.containerPolicy;
    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 && (!visitedObjects.containsKey(nextObject))) {
            visitedObjects.put(nextObject, nextObject);
            builder = getReferenceDescriptor(nextObject.getClass(), uow).getObjectBuilder();
            builder.cascadeRegisterNewForCreate(nextObject, uow, visitedObjects);
            cp.cascadeRegisterNewIfRequired(wrappedObject, uow, visitedObjects);
        }
    }
}
Also used : ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) ObjectBuilder(org.eclipse.persistence.internal.descriptors.ObjectBuilder)

Example 28 with ContainerPolicy

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

the class AggregateCollectionMapping method load.

/**
 * Force instantiation of the load group.
 */
@Override
public void load(final Object object, AttributeItem item, final AbstractSession session, final boolean fromFetchGroup) {
    instantiateAttribute(object, session);
    if (item.getGroup() != null && (!fromFetchGroup || session.isUnitOfWork())) {
        // if UOW make sure the nested attributes are loaded as the clones will not be instantiated
        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().load(nestedObject, item.getGroup(nestedObject.getClass()), session, fromFetchGroup);
        }
    }
}
Also used : ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy)

Example 29 with ContainerPolicy

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

the class AggregateCollectionMapping method preInsert.

/**
 * INTERNAL:
 * The message is passed to its reference class descriptor.
 */
@Override
public void preInsert(WriteObjectQuery query) throws DatabaseException, OptimisticLockException {
    if (isReadOnly()) {
        return;
    }
    Object objects = getRealCollectionAttributeValueFromObject(query.getObject(), query.getSession());
    int index = 0;
    // pre-insert each object one by one
    ContainerPolicy cp = getContainerPolicy();
    for (Object iter = cp.iteratorFor(objects); cp.hasNext(iter); ) {
        Object wrappedObject = cp.nextEntry(iter, query.getSession());
        Object object = cp.unwrapIteratorResult(wrappedObject);
        InsertObjectQuery insertQuery = getAndPrepareModifyQueryForInsert(query, object);
        ContainerPolicy.copyMapDataToRow(cp.getKeyMappingDataForWriteQuery(wrappedObject, query.getSession()), insertQuery.getModifyRow());
        if (this.listOrderField != null) {
            insertQuery.getModifyRow().add(this.listOrderField, index++);
        }
        // aggregates do not actually use a query to write to the database so the pre-write must be called here
        executeEvent(DescriptorEventManager.PreWriteEvent, insertQuery);
        executeEvent(DescriptorEventManager.PreInsertEvent, insertQuery);
        getReferenceDescriptor(object.getClass(), query.getSession()).getQueryManager().preInsert(insertQuery);
        cp.propogatePreInsert(query, wrappedObject);
    }
}
Also used : ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) InsertObjectQuery(org.eclipse.persistence.queries.InsertObjectQuery)

Example 30 with ContainerPolicy

use of org.eclipse.persistence.internal.queries.ContainerPolicy 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)

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