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