FileDocCategorySizeDatePackage
DeleteObjectQuery.javaAPI DocGlassfish v2 API7099Tue May 22 16:54:50 BST 2007oracle.toplink.essentials.queryframework

DeleteObjectQuery

public class DeleteObjectQuery extends WriteObjectQuery

Purpose: Used for deleting objects.

Responsibilities: Extract primary key from object and delete it.

author
Yvon Lavoie
since
TOPLink/Java 1.0

Fields Summary
Constructors Summary
public DeleteObjectQuery()

        super();
    
public DeleteObjectQuery(Object objectToDelete)

        this();
        setObject(objectToDelete);
    
public DeleteObjectQuery(Call call)

        this();
        setCall(call);
    
Methods Summary
protected oracle.toplink.essentials.queryframework.DatabaseQuerycheckForCustomQuery(oracle.toplink.essentials.internal.sessions.AbstractSession session, oracle.toplink.essentials.internal.sessions.AbstractRecord translationRow)
INTERNAL: Check to see if a custom query should be used for this query. This is done before the query is copied and prepared/executed. null means there is none.

        checkDescriptor(session);

        // check if user defined a custom query
        DescriptorQueryManager queryManager = getDescriptor().getQueryManager();
        if ((!isCallQuery())// this is not a hand-coded (custom SQL, SDK etc.) call
                 &&(!isUserDefined())// and this is not a user-defined query (in the query manager)
                 &&queryManager.hasDeleteQuery()) {// and there is a user-defined query (in the query manager)
            return queryManager.getDeleteQuery();
        }

        return null;
    
public voidexecuteCommit()
INTERNAL: Perform a delete.

        // object will only be null if the transaction is being commited directly from a changeset
        if (getObject() != null) {
            // if the object is not null then it is more effecient to build the row from the
            // object then the changeSet.
            getQueryMechanism().deleteObjectForWrite();
        } else {
            // TODO: Must this case be implemented?
            // has a changeSet so we must use it in the case that there is no object
//            getQueryMechanism().deleteObjectForWriteWithChangeSet();
        }
    
protected java.lang.ObjectexecuteInUnitOfWorkObjectLevelModifyQuery(oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl unitOfWork, oracle.toplink.essentials.internal.sessions.AbstractRecord translationRow)
INTERNAL: Code was moved from UnitOfWork.internalExecuteQuery

param
unitOfWork
param
translationRow
return
throws
oracle.toplink.essentials.exceptions.DatabaseException
throws
oracle.toplink.essentials.exceptions.OptimisticLockException

        Object result = unitOfWork.processDeleteObjectQuery(this);
        if (result != null) {
            // if the above method returned something then the unit of work
            //was not writing so the object has been stored to delete later
            //so return the object.  See the above method for the cases
            //where this object will be returned.
            return result;
        }
        return super.executeInUnitOfWorkObjectLevelModifyQuery(unitOfWork, translationRow);
    
public voidexecuteShallowWrite()
INTERNAL: Perform a shallow delete.

        getQueryMechanism().shallowDeleteObjectForWrite(getObject(), this, getSession().getCommitManager());
    
public booleanisDeleteObjectQuery()
PUBLIC: Return if this is a delete object query.

        return true;
    
protected voidprepare()
INTERNAL: Prepare the receiver for execution in a session.

        super.prepare();

        getQueryMechanism().prepareDeleteObject();
    
protected voidprepareCustomQuery(oracle.toplink.essentials.queryframework.DatabaseQuery customQuery)
INTERNAL: Set the properties needed to be cascaded into the custom query.

        DeleteObjectQuery customDeleteQuery = (DeleteObjectQuery)customQuery;
        customDeleteQuery.setObject(getObject());
        customDeleteQuery.setObjectChangeSet(getObjectChangeSet());
        customDeleteQuery.setCascadePolicy(getCascadePolicy());
        customDeleteQuery.setShouldMaintainCache(shouldMaintainCache());
        customDeleteQuery.setTranslationRow(customDeleteQuery.getDescriptor().getObjectBuilder().buildRow(getObject(), customDeleteQuery.getSession()));
    
public voidprepareForExecution()
INTERNAL: Prepare the receiver for execution in a session. In particular, verify that the object is not null and contains a valid primary key.

        super.prepareForExecution();

        // Add the write lock field if required		
        if (getDescriptor().usesOptimisticLocking()) {
            getDescriptor().getOptimisticLockingPolicy().addLockValuesToTranslationRow(this);
        }