use of org.eclipse.persistence.queries.DeleteObjectQuery in project eclipselink by eclipse-ee4j.
the class ObjectReferenceMapping method postDelete.
/**
* INTERNAL:
* Delete privately owned parts
*/
@Override
public void postDelete(DeleteObjectQuery query) throws DatabaseException, OptimisticLockException {
// Deletion takes place only if it has privately owned parts and mapping is not read only.
if (!shouldObjectModifyCascadeToParts(query)) {
return;
}
Object object = query.getProperty(this);
// The object is stored in the query by preDeleteForObjectUsing(...).
if (isForeignKeyRelationship()) {
if (object != null) {
query.removeProperty(this);
AbstractSession session = query.getSession();
// CR 2811
if (query.isCascadeOfAggregateDelete()) {
session.getCommitManager().addObjectToDelete(object);
} else {
// PERF: Avoid query execution if already deleted.
if (session.getCommitManager().isCommitCompletedInPostOrIgnore(object)) {
return;
}
if (this.isCascadeOnDeleteSetOnDatabase && !hasRelationTableMechanism() && session.isUnitOfWork()) {
((UnitOfWorkImpl) session).getCascadeDeleteObjects().add(object);
}
DeleteObjectQuery deleteQuery = new DeleteObjectQuery();
deleteQuery.setIsExecutionClone(true);
deleteQuery.setObject(object);
deleteQuery.setCascadePolicy(query.getCascadePolicy());
session.executeQuery(deleteQuery);
}
}
}
}
use of org.eclipse.persistence.queries.DeleteObjectQuery in project eclipselink by eclipse-ee4j.
the class OneToManyMapping method preDelete.
/**
* INTERNAL:
* Delete the reference objects.
*/
@Override
public void preDelete(DeleteObjectQuery query) throws DatabaseException, OptimisticLockException {
if (!shouldObjectModifyCascadeToParts(query)) {
if (this.listOrderField != null) {
updateTargetRowPreDeleteSource(query);
}
return;
}
AbstractSession session = query.getSession();
// else delete everything in one shot.
if (mustDeleteReferenceObjectsOneByOne()) {
Object objects = getRealCollectionAttributeValueFromObject(query.getObject(), session);
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);
}
}
int cascade = query.getCascadePolicy();
for (Object iterator = cp.iteratorFor(objects); cp.hasNext(iterator); ) {
Object wrappedObject = cp.nextEntry(iterator, session);
Object object = cp.unwrapIteratorResult(wrappedObject);
// PERF: Avoid query execution if already deleted.
if (!session.getCommitManager().isCommitCompletedInPostOrIgnore(object) || this.containerPolicy.propagatesEventsToCollection()) {
if (session.isUnitOfWork() && ((UnitOfWorkImpl) session).isObjectNew(object)) {
session.getCommitManager().markIgnoreCommit(object);
} else {
DeleteObjectQuery deleteQuery = new DeleteObjectQuery();
deleteQuery.setIsExecutionClone(true);
deleteQuery.setObject(object);
deleteQuery.setCascadePolicy(cascade);
session.executeQuery(deleteQuery);
this.containerPolicy.propogatePreDelete(deleteQuery, wrappedObject);
}
}
}
if (!session.isUnitOfWork()) {
// This deletes any objects on the database, as the collection in memory may have 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.
deleteReferenceObjectsLeftOnDatabase(query);
}
} else {
deleteAll(query, session);
}
}
use of org.eclipse.persistence.queries.DeleteObjectQuery in project eclipselink by eclipse-ee4j.
the class DirectCollectionMapping method postUpdate.
/**
* INTERNAL:
* Update private owned part.
*/
@Override
public void postUpdate(WriteObjectQuery writeQuery) throws DatabaseException {
if (isReadOnly()) {
return;
}
if (writeQuery.getObjectChangeSet() != null) {
if (this.listOrderField != null) {
postUpdateWithChangeSetListOrder(writeQuery);
} else {
postUpdateWithChangeSet(writeQuery);
}
return;
}
// If objects are not instantiated that means they are not changed.
if (!isAttributeValueInstantiatedOrChanged(writeQuery.getObject())) {
return;
}
if (writeQuery.getSession().isUnitOfWork()) {
if (compareObjects(writeQuery.getObject(), writeQuery.getBackupClone(), writeQuery.getSession())) {
// Nothing has changed, no work required
return;
}
}
DeleteObjectQuery deleteQuery = new DeleteObjectQuery();
deleteQuery.setObject(writeQuery.getObject());
deleteQuery.setSession(writeQuery.getSession());
deleteQuery.setTranslationRow(writeQuery.getTranslationRow());
if (writeQuery.shouldCascadeOnlyDependentParts()) {
// Hey I might actually want to use an inner class here... ok array for now.
Object[] event = new Object[3];
event[0] = DeleteAll;
event[1] = deleteQuery;
writeQuery.getSession().getCommitManager().addDataModificationEvent(this, event);
} else {
preDelete(deleteQuery);
}
postInsert(writeQuery);
}
use of org.eclipse.persistence.queries.DeleteObjectQuery in project eclipselink by eclipse-ee4j.
the class AggregateCollectionMapping method objectRemovedDuringUpdate.
/**
* INTERNAL:
* An object was removed to the collection during an update, delete it if private.
*/
@Override
protected void objectRemovedDuringUpdate(ObjectLevelModifyQuery query, Object objectDeleted, Map extraData) throws DatabaseException, OptimisticLockException {
// Delete must not be done for uow or cascaded queries and we must cascade to cascade policy.
DeleteObjectQuery deleteQuery = new DeleteObjectQuery();
deleteQuery.setIsExecutionClone(true);
prepareModifyQueryForDelete(query, deleteQuery, objectDeleted, extraData);
ContainerPolicy.copyMapDataToRow(extraData, deleteQuery.getTranslationRow());
query.getSession().executeQuery(deleteQuery, deleteQuery.getTranslationRow());
if (containerPolicy.shouldIncludeKeyInDeleteEvent()) {
query.getSession().deleteObject(containerPolicy.keyFromEntry(objectDeleted));
}
}
use of org.eclipse.persistence.queries.DeleteObjectQuery in project eclipselink by eclipse-ee4j.
the class DescriptorQueryManager method setDeleteSQLString.
/**
* ADVANCED:
* Set the receiver's delete SQL string.
* This allows the user to override the SQL generated by EclipseLink, with their own SQL or procedure call.
* The arguments are translated from the fields of the source row,
* through replacing the field names marked by '#' with the values for those fields.
* Warning: Allowing an unverified SQL string to be passed into this
* method makes your application vulnerable to SQL injection attacks.
* <p>
* Example, "delete from EMPLOYEE where EMPLOYEE_ID = #EMPLOYEE_ID".
*/
public void setDeleteSQLString(String sqlString) {
if (sqlString == null) {
return;
}
DeleteObjectQuery query = new DeleteObjectQuery();
query.setSQLString(sqlString);
setDeleteQuery(query);
}
Aggregations