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

ObjectLevelModifyQuery

public abstract class ObjectLevelModifyQuery extends ModifyQuery

Purpose: Abstract class for all object modify queries.

Responsibilities:

  • Stores & retrieves the object to modify.
  • Stores & retrieves the primary key of the objects.
author
Yvon Lavoie
since
TOPLink/Java 1.0

Fields Summary
protected Vector
primaryKey
protected Object
object
protected ObjectChangeSet
objectChangeSet
protected Object
backupClone
Constructors Summary
public ObjectLevelModifyQuery()
PUBLIC: Initialize the state of the query.

        this.cascadePolicy = CascadePrivateParts;
    
Methods Summary
public voidcheckDescriptor(oracle.toplink.essentials.internal.sessions.AbstractSession session)
INTERNAL: Ensure that the descriptor has been set.

        if (getDescriptor() == null) {
            if (getObject() == null) {
                throw QueryException.objectToModifyNotSpecified(this);
            }

            //Bug#3947714  Pass the object instead of class in case object is proxy            
            ClassDescriptor referenceDescriptor = session.getDescriptor(getObject());
            if (referenceDescriptor == null) {
                throw QueryException.descriptorIsMissing(getObject().getClass(), this);
            }
            setDescriptor(referenceDescriptor);
        }
    
public java.lang.ObjectexecuteInUnitOfWork(oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl unitOfWork, oracle.toplink.essentials.internal.sessions.AbstractRecord translationRow)
INTERNAL: All have done is move code from UnitOfWork.internalExecuteQuery

        if (unitOfWork.isAfterWriteChangesButBeforeCommit()) {
            throw ValidationException.illegalOperationForUnitOfWorkLifecycle(unitOfWork.getLifecycle(), "executeQuery(ObjectLevelModifyQuery)");
        }
        return executeInUnitOfWorkObjectLevelModifyQuery(unitOfWork, translationRow);
    
protected java.lang.ObjectexecuteInUnitOfWorkObjectLevelModifyQuery(oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl unitOfWork, oracle.toplink.essentials.internal.sessions.AbstractRecord translationRow)
INTERNAL: This code was moved from UnitOfWork.internalExecuteQuery

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

        if (!unitOfWork.getCommitManager().isActive()) {
            throw QueryException.invalidQuery(this);
        }

        if ((getObject() != null) && (unitOfWork.isClassReadOnly(getObject().getClass()))) {
            return getObject();
        }

        // CR#3216 - Apply check to ObjectLevelModifyQuery not just WriteObjectQuery
        if (unitOfWork.shouldPerformNoValidation() && unitOfWork.getUnregisteredExistingObjects().containsKey(getObject())) {
            //if the object is an unregistered existing object then skip it.  This
            // Will only be in the collection if validation is turned off
            return null;
        }

        return super.executeInUnitOfWork(unitOfWork, translationRow);
    
public java.lang.ObjectgetBackupClone()
INTERNAL: Return the backup clone of the object from the unit of work.

        // PERF: A backup clone is only required for the old commit,
        // So avoid its creation for normal commit.	
        if ((backupClone == null) && getSession().isUnitOfWork()) {
            setBackupClone(((UnitOfWorkImpl)getSession()).getBackupCloneForCommit(getObject()));
        }
        return backupClone;
    
public java.lang.ObjectgetObject()
PUBLIC: Return the object required for modification.

        return object;
    
public oracle.toplink.essentials.internal.sessions.ObjectChangeSetgetObjectChangeSet()
PUBLIC: Return the ObjectChangeSet representing the object being changed

        return this.objectChangeSet;
    
public java.util.VectorgetPrimaryKey()
INTERNAL: Get the primary key for the query

        return primaryKey;
    
public java.lang.ClassgetReferenceClass()
Return the domain class associated with this query.

        return getObject().getClass();
    
public java.lang.StringgetReferenceClassName()
INTERNAL: Return the reference class for a query Note: Although the API is designed to avoid classpath dependancies for the MW, since the object is specified at runtime, this will not be an issue.

        return getReferenceClass().getName();
    
public booleanisObjectLevelModifyQuery()
PUBLIC: Return if this is an object level modify query.

        return true;
    
protected voidprepare()
INTERNAL: Prepare the receiver for execution in a session. In particular check that the tables on the descriptor are set.

        checkDescriptor(getSession());

        if (getObject() != null) {// Prepare can be called without the object set yet.
            setObject(getDescriptor().getObjectBuilder().unwrapObject(getObject(), getSession()));
        }

        if (getDescriptor().isAggregateDescriptor()) {
            throw QueryException.aggregateObjectCannotBeDeletedOrWritten(getDescriptor(), this);
        }

        super.prepare();
    
public voidprepareForExecution()
INTERNAL: Prepare the receiver for execution in a session. In particular check that the tables on the descriptor are set.

        super.prepareForExecution();

        if (getObject() == null) {
            throw QueryException.objectToModifyNotSpecified(this);
        }

        setObject(getDescriptor().getObjectBuilder().unwrapObject(getObject(), getSession()));

        if (getPrimaryKey() == null) {
            if (getObjectChangeSet() != null) {
                setPrimaryKey(getObjectChangeSet().getPrimaryKeys());
            } else {
                setPrimaryKey(getSession().keyFromObject(getObject()));
            }
        }
    
public voidsetBackupClone(java.lang.Object backupClone)
INTERNAL: Set the backup clone of the object from the unit of work.

        this.backupClone = backupClone;
    
public voidsetObject(java.lang.Object object)
PUBLIC (REQUIRED): Set the object required for modification.

        this.object = object;
    
public voidsetObjectChangeSet(oracle.toplink.essentials.internal.sessions.ObjectChangeSet changeSet)
INTERNAL: Set the ObjectChangeSet representing the object to be written

        this.objectChangeSet = changeSet;
    
public voidsetPrimaryKey(java.util.Vector primaryKey)
INTERNAL: Set the primary key for the query.

        this.primaryKey = primaryKey;
    
public java.lang.StringtoString()

        return Helper.getShortClassName(getClass()) + "(" + String.valueOf(getObject()) + ")";