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