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);
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
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);
}
Aggregations