Search in sources :

Example 11 with DeleteObjectQuery

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);
    }
}
Also used : ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) DeleteObjectQuery(org.eclipse.persistence.queries.DeleteObjectQuery)

Example 12 with DeleteObjectQuery

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);
}
Also used : ObjectReferenceChangeRecord(org.eclipse.persistence.internal.sessions.ObjectReferenceChangeRecord) DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord) Actor(org.eclipse.persistence.testing.models.interfaces.Actor) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) UnitOfWorkChangeSet(org.eclipse.persistence.internal.sessions.UnitOfWorkChangeSet) ObjectChangeSet(org.eclipse.persistence.internal.sessions.ObjectChangeSet) DeleteObjectQuery(org.eclipse.persistence.queries.DeleteObjectQuery) Vector(java.util.Vector)

Example 13 with DeleteObjectQuery

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));
    }
}
Also used : ReadObjectQuery(org.eclipse.persistence.queries.ReadObjectQuery) DatabaseRecord(org.eclipse.persistence.sessions.DatabaseRecord) DeleteObjectQuery(org.eclipse.persistence.queries.DeleteObjectQuery) InsertObjectQuery(org.eclipse.persistence.queries.InsertObjectQuery)

Example 14 with DeleteObjectQuery

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);
}
Also used : DeleteObjectQuery(org.eclipse.persistence.queries.DeleteObjectQuery)

Example 15 with DeleteObjectQuery

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);
}
Also used : DeleteObjectQuery(org.eclipse.persistence.queries.DeleteObjectQuery)

Aggregations

DeleteObjectQuery (org.eclipse.persistence.queries.DeleteObjectQuery)20 DatabaseRecord (org.eclipse.persistence.sessions.DatabaseRecord)6 ContainerPolicy (org.eclipse.persistence.internal.queries.ContainerPolicy)5 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Map (java.util.Map)2 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)2 DescriptorIterator (org.eclipse.persistence.internal.descriptors.DescriptorIterator)2 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)2 ObjectChangeSet (org.eclipse.persistence.internal.sessions.ObjectChangeSet)2 HashSet (java.util.HashSet)1 IdentityHashMap (java.util.IdentityHashMap)1 Set (java.util.Set)1 TreeMap (java.util.TreeMap)1 Vector (java.util.Vector)1 Expression (org.eclipse.persistence.expressions.Expression)1 IndirectList (org.eclipse.persistence.indirection.IndirectList)1