use of org.eclipse.persistence.internal.queries.ContainerPolicy in project eclipselink by eclipse-ee4j.
the class XMLVariableXPathCollectionMapping method writeFromObjectIntoRow.
@Override
public void writeFromObjectIntoRow(Object object, AbstractRecord row, AbstractSession session, WriteType writeType) throws DescriptorException {
if (this.isReadOnly()) {
return;
}
Object attributeValue = this.getAttributeValueFromObject(object);
ContainerPolicy cp = this.getContainerPolicy();
Object iter = cp.iteratorFor(attributeValue);
if (null != iter) {
while (cp.hasNext(iter)) {
Object element = cp.next(iter, session);
// convert the value - if necessary
element = convertObjectValueToDataValue(element, session, ((XMLRecord) row).getMarshaller());
if (element != null) {
XMLField variableField = new XMLField();
XMLRecord xmlRow = (XMLRecord) row;
// variableField.setXPathFragment(getXPathFragmentForValue(element,(XMLRecord)row));
variableField.setXPathFragment(getXPathFragmentForValue(element, xmlRow.getNamespaceResolver(), xmlRow.isNamespaceAware(), xmlRow.getNamespaceSeparator()));
row.put(variableField, buildCompositeRow(variableField, element, session, row, writeType));
}
}
}
}
use of org.eclipse.persistence.internal.queries.ContainerPolicy in project eclipselink by eclipse-ee4j.
the class EISOneToManyMapping method postInsert.
/**
* INTERNAL:
* Insert the reference objects.
*/
@Override
public void postInsert(WriteObjectQuery query) throws DatabaseException, OptimisticLockException {
if (isForeignKeyRelationship()) {
return;
}
if (!this.shouldObjectModifyCascadeToParts(query)) {
return;
}
// only cascade dependents in UOW
if (query.shouldCascadeOnlyDependentParts()) {
return;
}
Object objects = this.getRealCollectionAttributeValueFromObject(query.getObject(), query.getSession());
// insert each object one by one
ContainerPolicy cp = this.getContainerPolicy();
for (Object iter = cp.iteratorFor(objects); cp.hasNext(iter); ) {
Object object = cp.next(iter, query.getSession());
if (this.isPrivateOwned()) {
// no need to set changeSet as insert is a straight copy
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)) {
WriteObjectQuery writeQuery = new WriteObjectQuery();
writeQuery.setIsExecutionClone(true);
writeQuery.setObject(object);
writeQuery.setCascadePolicy(query.getCascadePolicy());
query.getSession().executeQuery(writeQuery);
}
}
}
}
use of org.eclipse.persistence.internal.queries.ContainerPolicy in project eclipselink by eclipse-ee4j.
the class EISOneToManyMapping method preInsert.
/**
* INTERNAL:
* Insert privately owned parts
*/
@Override
public void preInsert(WriteObjectQuery query) throws DatabaseException, OptimisticLockException {
if (!this.isForeignKeyRelationship()) {
return;
}
if (!this.shouldObjectModifyCascadeToParts(query)) {
return;
}
// only cascade dependents in UOW
if (query.shouldCascadeOnlyDependentParts()) {
return;
}
Object objects = this.getRealCollectionAttributeValueFromObject(query.getObject(), query.getSession());
// insert each object one by one
ContainerPolicy cp = this.getContainerPolicy();
for (Object iter = cp.iteratorFor(objects); cp.hasNext(iter); ) {
Object object = cp.next(iter, query.getSession());
if (this.isPrivateOwned()) {
// no need to set changeset here as insert is just a copy of the object anyway
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)) {
WriteObjectQuery writeQuery = new WriteObjectQuery();
writeQuery.setIsExecutionClone(true);
if (query.getSession().isUnitOfWork()) {
UnitOfWorkChangeSet uowChangeSet = (UnitOfWorkChangeSet) ((UnitOfWorkImpl) query.getSession()).getUnitOfWorkChangeSet();
if (uowChangeSet != null) {
writeQuery.setObjectChangeSet((ObjectChangeSet) uowChangeSet.getObjectChangeSetForClone(object));
}
}
writeQuery.setObject(object);
writeQuery.setCascadePolicy(query.getCascadePolicy());
query.getSession().executeQuery(writeQuery);
}
}
}
}
use of org.eclipse.persistence.internal.queries.ContainerPolicy in project eclipselink by eclipse-ee4j.
the class EISOneToManyMapping method valueFromRow.
/**
* INTERNAL:
* Return the value of the reference attribute or a value holder.
* Check whether the mapping's attribute should be optimized through batch and joining.
*/
@Override
public Object valueFromRow(AbstractRecord row, JoinedAttributeManager joinManager, ObjectBuildingQuery sourceQuery, CacheKey cacheKey, AbstractSession executionSession, boolean isTargetProtected, Boolean[] wasCacheUsed) throws DatabaseException {
if (this.descriptor.getCachePolicy().isProtectedIsolation()) {
if (this.isCacheable && isTargetProtected && cacheKey != null) {
// cachekey will be null when isolating to uow
// used cached collection
Object cached = cacheKey.getObject();
if (cached != null) {
if (wasCacheUsed != null) {
wasCacheUsed[0] = Boolean.TRUE;
}
// the indirection object is responsible for cloning the value.
return getAttributeValueFromObject(cached);
}
} else if (!this.isCacheable && !isTargetProtected && cacheKey != null) {
return this.indirectionPolicy.buildIndirectObject(new ValueHolder<>(null));
}
}
if (((EISDescriptor) this.getDescriptor()).isXMLFormat()) {
((XMLRecord) row).setSession(executionSession);
}
ReadQuery targetQuery = getSelectionQuery();
if (!this.isForeignKeyRelationship) {
// if the source query is cascading then the target query must use the same settings
if (targetQuery.isObjectLevelReadQuery() && (sourceQuery.shouldCascadeAllParts() || (sourceQuery.shouldCascadePrivateParts() && isPrivateOwned()) || (sourceQuery.shouldCascadeByMapping() && this.cascadeRefresh))) {
targetQuery = (ObjectLevelReadQuery) targetQuery.clone();
((ObjectLevelReadQuery) targetQuery).setShouldRefreshIdentityMapResult(sourceQuery.shouldRefreshIdentityMapResult());
targetQuery.setCascadePolicy(sourceQuery.getCascadePolicy());
// CR #4365
targetQuery.setQueryId(sourceQuery.getQueryId());
// For queries that have turned caching off, such as aggregate collection, leave it off.
if (targetQuery.shouldMaintainCache()) {
targetQuery.setShouldMaintainCache(sourceQuery.shouldMaintainCache());
}
}
return getIndirectionPolicy().valueFromQuery(targetQuery, row, sourceQuery.getSession());
} else {
if (getIndirectionPolicy().usesIndirection()) {
EISOneToManyQueryBasedValueHolder valueholder = new EISOneToManyQueryBasedValueHolder(this, targetQuery, row, sourceQuery.getSession());
return getIndirectionPolicy().buildIndirectObject(valueholder);
} else {
Vector<AbstractRecord> subRows = getForeignKeyRows(row, executionSession);
if (subRows == null) {
return null;
}
ContainerPolicy cp = this.getContainerPolicy();
Object results = cp.containerInstance(subRows.size());
for (int i = 0; i < subRows.size(); i++) {
XMLRecord subRow = (XMLRecord) subRows.elementAt(i);
subRow.setSession(executionSession);
Object object = getIndirectionPolicy().valueFromQuery(targetQuery, subRow, sourceQuery.getSession());
if (object instanceof Collection) {
java.util.Iterator<?> iter = ((Collection<?>) object).iterator();
while (iter.hasNext()) {
cp.addInto(iter.next(), results, executionSession);
}
} else if (object instanceof java.util.Map) {
java.util.Iterator<?> iter = ((java.util.Map<?, ?>) object).values().iterator();
while (iter.hasNext()) {
cp.addInto(iter.next(), results, executionSession);
}
} else {
cp.addInto(object, results, executionSession);
}
}
if (cp.sizeFor(results) == 0) {
return null;
}
return results;
}
}
}
use of org.eclipse.persistence.internal.queries.ContainerPolicy in project eclipselink by eclipse-ee4j.
the class EISOneToManyMapping method deleteReferenceObjectsLeftOnDatabase.
/**
* This method will 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 along with their privately owned parts.
*/
protected void deleteReferenceObjectsLeftOnDatabase(DeleteObjectQuery query) throws DatabaseException, OptimisticLockException {
Object objects = this.readPrivateOwnedForObject(query);
// delete all these objects one by one
ContainerPolicy cp = this.getContainerPolicy();
for (Object iter = cp.iteratorFor(objects); cp.hasNext(iter); ) {
query.getSession().deleteObject(cp.next(iter, query.getSession()));
}
}
Aggregations