use of org.eclipse.persistence.queries.DeleteObjectQuery in project eclipselink by eclipse-ee4j.
the class NestedTableMapping method preDelete.
/**
* INTERNAL:
* Delete privately owned parts
*/
@Override
public void preDelete(DeleteObjectQuery query) throws DatabaseException, OptimisticLockException {
if (!shouldObjectModifyCascadeToParts(query)) {
return;
}
Object objects = getRealCollectionAttributeValueFromObject(query.getObject(), query.getSession());
ContainerPolicy containerPolicy = getContainerPolicy();
Object objectsIterator = containerPolicy.iteratorFor(objects);
// delete parts one by one
while (containerPolicy.hasNext(objectsIterator)) {
DeleteObjectQuery deleteQuery = new DeleteObjectQuery();
deleteQuery.setIsExecutionClone(true);
deleteQuery.setObject(containerPolicy.next(objectsIterator, query.getSession()));
deleteQuery.setCascadePolicy(query.getCascadePolicy());
query.getSession().executeQuery(deleteQuery);
}
if (!query.getSession().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);
}
}
use of org.eclipse.persistence.queries.DeleteObjectQuery in project eclipselink by eclipse-ee4j.
the class VariableOneToOneMappingIsNotDefinedProperlyTest method setup.
@Override
protected void setup() {
descriptor = getSession().getDescriptor(Actor.class);
mapping = (VariableOneToOneMapping) descriptor.getMappingForAttributeName("program");
sourceField = new DatabaseField("ACTOR.PROGRAM_ID");
targetQueryKeyName = (String) mapping.getSourceToTargetQueryKeyNames().get(sourceField);
mapping.addForeignQueryKeyName("ACTOR.PROGRAM_ID", "name2");
mapping.getForeignKeyFields().removeElement(sourceField);
actor = Actor.example4();
databaseRow = new DatabaseRecord();
if (testMode == 0) {
// nothing extra needed
} else if (testMode == 1) {
ObjectChangeSet changeSet = new ObjectChangeSet(new Vector(), descriptor, actor, new UnitOfWorkChangeSet(), true);
changeRecord = new ObjectReferenceChangeRecord(changeSet);
changeRecord.setNewValue(changeSet);
} else if (testMode == 2) {
deleteObjectQuery = new DeleteObjectQuery(actor);
deleteObjectQuery.setSession((AbstractSession) getSession());
}
expectedException = DescriptorException.variableOneToOneMappingIsNotDefinedProperly(mapping, descriptor, targetQueryKeyName);
}
use of org.eclipse.persistence.queries.DeleteObjectQuery in project eclipselink by eclipse-ee4j.
the class ClassDescriptor method initialize.
/**
* INTERNAL:
* Initialize the query manager specific to the descriptor type.
*/
public void initialize(DescriptorQueryManager queryManager, AbstractSession session) {
// PERF: set read-object query to cache generated SQL.
if (!queryManager.hasReadObjectQuery()) {
// Prepare static read object query always.
ReadObjectQuery readObjectQuery = new ReadObjectQuery();
readObjectQuery.setSelectionCriteria(getObjectBuilder().getPrimaryKeyExpression());
queryManager.setReadObjectQuery(readObjectQuery);
}
queryManager.getReadObjectQuery().setName("read" + getJavaClass().getSimpleName());
if (!queryManager.hasInsertQuery()) {
// Prepare insert query always.
queryManager.setInsertQuery(new InsertObjectQuery());
}
queryManager.getInsertQuery().setModifyRow(getObjectBuilder().buildTemplateInsertRow(session));
if (!usesFieldLocking()) {
// do not reset the query if we are using field locking
if (!queryManager.hasDeleteQuery()) {
// Prepare delete query always.
queryManager.setDeleteQuery(new DeleteObjectQuery());
}
queryManager.getDeleteQuery().setModifyRow(new DatabaseRecord());
}
if (queryManager.hasUpdateQuery()) {
// Do not prepare to update by default to allow minimal update.
queryManager.getUpdateQuery().setModifyRow(getObjectBuilder().buildTemplateUpdateRow(session));
}
}
use of org.eclipse.persistence.queries.DeleteObjectQuery in project eclipselink by eclipse-ee4j.
the class DescriptorQueryManager method setDeleteCall.
/**
* ADVANCED:
* Set the receiver's delete call.
* This allows the user to override the delete operation.
*/
public void setDeleteCall(Call call) {
if (call == null) {
return;
}
DeleteObjectQuery query = new DeleteObjectQuery();
query.setCall(call);
setDeleteQuery(query);
}
use of org.eclipse.persistence.queries.DeleteObjectQuery in project eclipselink by eclipse-ee4j.
the class AbstractSession method deleteObject.
/**
* PUBLIC:
* Delete the object and all of its privately owned parts from the database.
* The delete operation can be customized through using a delete query.
*
* @exception DatabaseException if an error occurs on the database,
* these include constraint violations, security violations and general database errors.
* An database error is not raised if the object is already deleted or no rows are effected.
* @exception OptimisticLockException if the object's descriptor is using optimistic locking and
* the object has been updated or deleted by another user since it was last read.
*
* @see DeleteObjectQuery
*/
public Object deleteObject(Object domainObject) throws DatabaseException, OptimisticLockException {
DeleteObjectQuery query = new DeleteObjectQuery();
query.setObject(domainObject);
query.setIsExecutionClone(true);
return executeQuery(query);
}
Aggregations