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

ObjectLevelReadQuery

public abstract class ObjectLevelReadQuery extends ObjectBuildingQuery

Purpose: Abstract class for all read queries using objects.

Description: Contains common behavior for all read queries using objects.

author
Yvon Lavoie
since
TOPLink/Java 1.0

Fields Summary
protected ExpressionBuilder
defaultBuilder
Provide a default builder so that it's easier to be consistent
protected boolean
shouldRefreshIdentityMapResult
Allows for the resulting objects to be refresh with the data from the database.
protected int
cacheUsage
Allow for the cache usage to be specified to enable in-memory querying.
public static final int
UseDescriptorSetting
public static final int
DoNotCheckCache
public static final int
CheckCacheByExactPrimaryKey
public static final int
CheckCacheByPrimaryKey
public static final int
CheckCacheThenDatabase
public static final int
CheckCacheOnly
public static final int
ConformResultsInUnitOfWork
protected boolean
shouldRegisterResultsInUnitOfWork
INTERNAL: for bug 2612601 allow ability not to register results in UOW.
protected Vector
additionalFields
Allow for additional fields to be selected, used for m-m batch reading.
protected boolean
shouldIncludeData
Allow for a complex result to be return including the rows and objects, used for m-m batch reading.
protected boolean
shouldProcessResultsInUnitOfWork
CMP only. Allow users to configure whether finder should be executed in a uow or not.
protected short
distinctState
Indicates if distinct should be used or not.
public static final short
UNCOMPUTED_DISTINCT
public static final short
USE_DISTINCT
public static final short
DONT_USE_DISTINCT
protected InMemoryQueryIndirectionPolicy
inMemoryQueryIndirectionPolicy
CR 3677 Used to determine behaviour of indirection in InMemoryQuerying This should have been just a constant similar to distinct locking, etc. instead of an object that just has the state and no behavoir, the object instantiation adds un-needed overhead, but too late now.
protected long
executionTime
Used to set the read time on objects that use this query. Should be set to the time the query returned from the database.
public static final String
LOCK_RESULT_PROPERTY
INTERNAL: This is the key for accessing unregistered and locked result in the query's properties. The uow and QueryBaseValueHolder use this property to record amd to retreive the result respectively.
protected FetchGroup
fetchGroup
Allow for a query level fetch group to be set.
protected String
fetchGroupName
The pre-defined fetch group name.
protected boolean
shouldUseDefaultFetchGroup
Flag to turn on/off the use of the default fetch group.
protected boolean
wasDefaultLockMode
PERF: Store if the query originally used the default lock mode.
protected Vector
nonFetchJoinAttributeExpressions
Stores the non fetchjoin attributes, these are joins that will be represented in the where clause but not in the select
protected JoinedAttributeManager
joinedAttributeManager
Stores the helper object for dealing with joined attributes
Constructors Summary
public ObjectLevelReadQuery()
INTERNAL: Initialize the state of the query

    
                
      
        this.shouldRefreshIdentityMapResult = false;
        this.distinctState = UNCOMPUTED_DISTINCT;
        this.joinedAttributeManager = new JoinedAttributeManager(getDescriptor(), getExpressionBuilder(), this);
        this.additionalFields = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(1);
        this.cacheUsage = UseDescriptorSetting;
        this.shouldIncludeData = false;
        this.inMemoryQueryIndirectionPolicy = new InMemoryQueryIndirectionPolicy();
    
Methods Summary
public voidacquireLocks()
PUBLIC: Set the query to lock, this will also turn refreshCache on.

        setLockMode(LOCK);
        //Bug2804042 Must un-prepare if prepared as the SQL may change.
        setIsPrepared(false);
    
public voidacquireLocksWithoutWaiting()
PUBLIC: Set the query to lock without waiting (blocking), this will also turn refreshCache on.

        setLockMode(LOCK_NOWAIT);
        //Bug2804042 Must un-prepare if prepared as the SQL may change.
        setIsPrepared(false);
    
public voidaddAdditionalField(oracle.toplink.essentials.internal.helper.DatabaseField field)
INTERNAL: Additional fields can be added to a query. This is used in m-m bacth reading to bring back the key from the join table.

        getAdditionalFields().addElement(field);
        //Bug2804042 Must un-prepare if prepared as the SQL may change.
        setIsPrepared(false);
    
public voidaddAdditionalField(oracle.toplink.essentials.expressions.Expression fieldExpression)
INTERNAL: Additional fields can be added to a query. This is used in m-m bacth reading to bring back the key from the join table.

        getAdditionalFields().addElement(fieldExpression);
        //Bug2804042 Must un-prepare if prepared as the SQL may change.
        setIsPrepared(false);
    
public voidaddJoinedAttribute(java.lang.String attributeName)
PUBLIC: Specify the one-to-one mapped attribute to be optimized in this query. The query will join the object(s) being read with the one-to-one attribute, this allows all of the data required for the object(s) to be read in a single query instead of (n) queries. This should be used when the application knows that it requires the part for all of the objects being read. This can be used only for one-to-one mappings where the target is not the same class as the source, either directly or through inheritance. Also two joins cannot be done to the same class.

Note: This cannot be used for objects where it is possible not to have a part, as these objects will be ommited from the result set, unless an outer join is used through passing and expression using "getAllowingNull".

Example: query.addJoinedAttribute("address")

see
#addJoinedAttribute(Expression)

        addJoinedAttribute(getExpressionBuilder().get(attributeName));
    
public voidaddJoinedAttribute(oracle.toplink.essentials.expressions.Expression attributeExpression)
PUBLIC: Specify the to-one or to-many mapped attribute to be optimized in this query. The query will join the object(s) being read with the specified attribute, this allows all of the data required for the object(s) to be read in a single query instead of (n) queries. This should be used when the application knows that it requires the part for all of the objects being read.

Note: This cannot be used for objects where it is possible not to have a part, as these objects will be ommited from the result set, unless an outer join is used through passing and expression using "getAllowingNull".

Example: The following will fetch along with Employee(s) "Jones" all projects they participate in along with teamLeaders and their addresses, teamMembers and their phones. query.setSelectionCriteria(query.getExpressionBuilder().get("lastName").equal("Jones")); Expression projects = query.getExpressionBuilder().anyOf("projects"); query.addJoinedAttribute(projects); Expression teamLeader = projects.get("teamLeader"); query.addJoinedAttribute(teamLeader); Expression teamLeaderAddress = teamLeader.getAllowingNull("address"); query.addJoinedAttribute(teamLeaderAddress); Expression teamMembers = projects.anyOf("teamMembers"); query.addJoinedAttribute(teamMembers); Expression teamMembersPhones = teamMembers.anyOfAllowingNone("phoneNumbers"); query.addJoinedAttribute(teamMembersPhones); Note that: the order is essential: an expression should be added before any expression derived from it; the object is built once - it won't be rebuilt if it to be read again as a joined attribute: in the example the query won't get phones for "Jones" - even though they are among teamMembers (for whom phones are read).

        getJoinedAttributeManager().addJoinedAttributeExpression(attributeExpression);
        //Bug2804042 Must un-prepare if prepared as the SQL may change.
        // Joined attributes are now calculated in prePrepare.
        setIsPrePrepared(false);
    
public voidaddNonFetchJoinedAttribute(java.lang.String attributeName)
PUBLIC: Specify the one-to-one mapped attribute to be optimized in this query. The query will join the object(s) being read with the one-to-one attribute. The difference between this and a joined attribute is that it allows data to be retrieved based on a join, but will not populate the joined attribute. It also allows all of the data required for the object(s) to be read in a single query instead of (n) queries. This should be used when the application knows that it requires the part for all of the objects being read. This can be used only for one-to-one mappings where the target is not the same class as the source, either directly or through inheritance. Also two joins cannot be done to the same class.

Note: This cannot be used for objects where it is possible not to have a part, as these objects will be ommited from the result set, unless an outer join is used through passing and expression using "getAllowingNull".

Example: query.addNonFetchJoinedAttribute("address")

see
#addNonFetchJoinedAttribute(Expression)

        addNonFetchJoinedAttribute(getExpressionBuilder().get(attributeName));
    
public voidaddNonFetchJoinedAttribute(oracle.toplink.essentials.expressions.Expression attributeExpression)
PUBLIC: Specify the one-to-one mapped attribute to be optimized in this query. The query will join the object(s) being read with the one-to-one attribute. The difference between this and a joined attribute is that it allows data to be retrieved based on a join, but will not populate the joined attribute. It also allows all of the data required for the object(s) to be read in a single query instead of (n) queries. This should be used when the application knows that it requires the part for all of the objects being read. This can be used only for one-to-one mappings where the target is not the same class as the source, either directly or through inheritance. Also two joins cannot be done to the same class.

Note: This cannot be used for objects where it is possible not to have a part, as these objects will be ommited from the result set, unless an outer join is used through passing and expression using "getAllowingNull".

Example: query.addNonFetchJoinedAttribute(query.getExpressionBuilder().get("teamLeader").get("address"))

see
#addNonFetchJoinedAttribute(Expression)

        getNonFetchJoinAttributeExpressions().add(attributeExpression);
        
        // Bug 2804042 Must un-prepare if prepared as the SQL may change.
        // Joined attributes are now calculated in prePrepare.
        setIsPrePrepared(false);
    
protected voidaddSelectionFieldsForJoinedExpressions(java.util.List fields, java.util.List joinedExpressions)
INTERNAL: Iterate through a list of joined expressions and add the fields they represent to a list of fields.

        for (int index = 0; index < joinedExpressions.size(); index++) {
            ObjectExpression objectExpression = (ObjectExpression)joinedExpressions.get(index);

            // Expression may not have been initialized.
            objectExpression.getBuilder().setSession(getSession().getRootSession(null));
            objectExpression.getBuilder().setQueryClass(getReferenceClass());
            ClassDescriptor descriptor = objectExpression.getMapping().getReferenceDescriptor();
            fields.addAll(descriptor.getFields());
        }
    
public java.lang.ObjectbuildObject(oracle.toplink.essentials.internal.sessions.AbstractRecord row)
INTERNAL: Called by CursoredStream to construct objects from rows. Subclasses which build other results objects (ReportQuery, & PartialObjects) may override

        return getDescriptor().getObjectBuilder().buildObject(this, row, this.getJoinedAttributeManager());
    
public voidchangeDescriptor(oracle.toplink.essentials.internal.sessions.AbstractSession theSession)
INTERNAL: The reference class has been changed, need to reset the descriptor. Null out the current descriptor and call checkDescriptor Added Feb 27, 2001 JED for EJBQL feature

        setDescriptor(null);
        checkDescriptor(theSession);
    
public voidcheckCacheOnly()
PUBLIC: The cache will checked completely, if the object is not found null will be returned or an error if the query is too complex. Queries can be configured to use the cache at several levels. Other caching option are available.

see
#setCacheUsage(int)

        setCacheUsage(CheckCacheOnly);
    
public voidcheckDescriptor(oracle.toplink.essentials.internal.sessions.AbstractSession session)
INTERNAL: Ensure that the descriptor has been set.

        if (getReferenceClass() == null) {
            throw QueryException.referenceClassMissing(this);
        }

        if (getDescriptor() == null) {
            ClassDescriptor referenceDescriptor = session.getDescriptor(getReferenceClass());
            if (referenceDescriptor == null) {
                throw QueryException.descriptorIsMissing(getReferenceClass(), this);
            }
            setDescriptor(referenceDescriptor);
        }
    
public java.lang.ObjectcheckEarlyReturn(oracle.toplink.essentials.internal.sessions.AbstractSession session, oracle.toplink.essentials.internal.sessions.AbstractRecord translationRow)
INTERNAL: Check to see if this query already knows the return vale without preforming any further work.

        // For bug 3136413/2610803 building the selection criteria from an EJBQL string or
        // an example object is done just in time.
        // Also calls checkDescriptor here.
        //buildSelectionCriteria(session);
        checkPrePrepare(session);

        if (!session.isUnitOfWork()) {
            return checkEarlyReturnImpl(session, translationRow);
        }
        UnitOfWorkImpl unitOfWork = (UnitOfWorkImpl)session;

        // The cache check must happen on the UnitOfWork in these cases either
        // to access transient state or for pessimistic locking, as only the 
        // UOW knows which objects it has locked.
        if (shouldCheckCacheOnly() || shouldConformResultsInUnitOfWork() || getDescriptor().shouldAlwaysConformResultsInUnitOfWork() || (getLockMode() != ObjectBuildingQuery.NO_LOCK)) {
            Object result = checkEarlyReturnImpl(unitOfWork, translationRow);
            if (result != null) {
                return result;
            }
        }

        // don't bother trying to get a cache hit on the parent session
        // as if not in UnitOfWork it is not yet pessimistically locked
        // on the database for sure.
        // Note for ReadObjectQueries we totally ignore shouldCheckCacheOnly.
        if (isReadObjectQuery() && isLockQuery()) {
            return null;
        }

        // follow the execution path in looking for the object.
        AbstractSession parentSession = unitOfWork.getParentIdentityMapSession(this);

        // assert parentSession != unitOfWork;
        Object result = checkEarlyReturn(parentSession, translationRow);

        if (result != null) {
            // Optimization: If find deleted object by exact primary key
            // treat this as cache hit but return null.  Bug 2782991.
            if (result == InvalidObject.instance) {
                return result;
            }
            return registerResultInUnitOfWork(result, unitOfWork, translationRow, false);
        } else {
            return null;
        }
    
protected abstract java.lang.ObjectcheckEarlyReturnImpl(oracle.toplink.essentials.internal.sessions.AbstractSession session, oracle.toplink.essentials.internal.sessions.AbstractRecord translationRow)
INTERNAL: Contains the body of the check early return call, implemented by subclasses.

protected voidcheckPrePrepare(oracle.toplink.essentials.internal.sessions.AbstractSession session)
INTERNAL: ObjectLevelReadQueries now have an explicit pre-prepare stage, which is for checking for pessimistic locking, and computing any joined attributes declared on the descriptor.

        checkDescriptor(session);
        // This query is first prepared for global common state, this must be synced.
        if (!isPrePrepared()) {// Avoid the monitor is already prePrepare, must check again for concurrency.
            synchronized (this) {
                if (!isPrePrepared()) {
                    AbstractSession alreadySetSession = getSession();
                    setSession(session);// Session is required for some init stuff.
                    prePrepare();
                    setSession(alreadySetSession);
                    setIsPrePrepared(true);// MUST not set prepare until done as other thread may hit before finishing the prePrepare.
                }
            }
        }
    
public voidcheckPrepare(oracle.toplink.essentials.internal.sessions.AbstractSession session, oracle.toplink.essentials.internal.sessions.AbstractRecord translationRow)
INTERNAL: Check to see if this query needs to be prepare and prepare it. The prepare is done on the original query to ensure that the work is not repeated.

        // CR#3823735 For custom queries the prePrepare may not have been called yet.
        checkPrePrepare(session);
        super.checkPrepare(session, translationRow);
    
public java.lang.Objectclone()
INTERNAL: Clone the query

        ObjectLevelReadQuery cloneQuery = (ObjectLevelReadQuery)super.clone();

        //CR#... must also clone the joined expressions as always joined attribute will be added
        // don't use setters as this will trigger unprepare.
        cloneQuery.joinedAttributeManager = (JoinedAttributeManager)cloneQuery.getJoinedAttributeManager().clone();
        if (hasNonFetchJoinedAttributeExpressions()){
            cloneQuery.setNonFetchJoinAttributeExpressions((Vector)this.nonFetchJoinAttributeExpressions.clone());
        }
        cloneQuery.joinedAttributeManager.setBaseQuery(cloneQuery);
        return cloneQuery;
    
protected java.lang.ObjectconformIndividualResult(java.lang.Object result, oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl unitOfWork, oracle.toplink.essentials.internal.sessions.AbstractRecord arguments, oracle.toplink.essentials.expressions.Expression selectionCriteriaClone, oracle.toplink.essentials.internal.helper.IdentityHashtable alreadyReturned, boolean buildDirectlyFromRows)
INTERNAL: Conforms and registers an individual result. This instance could be one of the elements returned from a read all query, the result of a Read Object query, or an element read from a cursor.

A result needs to be registered before it can be conformed, so registerIndividualResult is called here.

Conforming on a result from the database is lenient. Since the object matched the query on the database we assume it matches here unless we can determine for sure that it was changed in this UnitOfWork not to conform.

param
result may be an original, or a raw database row
param
arguments the parameters this query was executed with
param
selectionCriteriaClone the expression to conform to. If was a selection object or key, null (which all conform to) is used
param
alreadyReturned a hashtable of objects already found by scanning the UnitOfWork cache for conforming instances. Prevents duplicates.
param
buildDirectlyFromRows whether result is an original or a raw database row
return
a clone, or null if result does not conform.

        // First register the object.  Since object is presently unwrapped the
        // exact objects stored in the cache will be returned.
        // The object is known to exist.
        Object clone = registerIndividualResult(result, unitOfWork, buildDirectlyFromRows, null);

        if (getDescriptor().hasWrapperPolicy() && getDescriptor().getWrapperPolicy().isWrapped(clone)) {
            // The only time the clone could be wrapped is if we are not registering
            // results in the unitOfWork and we are ready to return a final
            // (unregistered) result now.  Any further processing may accidently
            // cause it to get registered.
            return clone;
        }
        //bug 4459976 in order to maintain backward compatibility on ordering
        // lets use the result as a guild for the final result not the hashtable
        // of found objects.
        if (unitOfWork.isObjectDeleted(clone) ) {
            return null;
        }
        if (!isExpressionQuery() || (selectionCriteriaClone == null)) {
            if (alreadyReturned != null) {
                alreadyReturned.remove(clone);
            }
            return clone;
        }
        try {
            // pass in the policy to assume that the object conforms if indirection is not triggered.  This
            // is valid because the query returned the object and we should trust the query that the object
            // matches the selection criteria, and because the indirection is not triggered then the customer
            //has not changed the value.
            // bug 2637555
            // unless for bug 3568141 use the painstaking shouldTriggerIndirection if set
            InMemoryQueryIndirectionPolicy policy = getInMemoryQueryIndirectionPolicy();
            if (!policy.shouldTriggerIndirection()) {
                policy = new InMemoryQueryIndirectionPolicy(InMemoryQueryIndirectionPolicy.SHOULD_IGNORE_EXCEPTION_RETURN_CONFORMED);
            }
            if (selectionCriteriaClone.doesConform(clone, unitOfWork, arguments, policy)) {
                 if (alreadyReturned != null) {
                    alreadyReturned.remove(clone);
                }
               return clone;
            }
        } catch (QueryException exception) {
            // bug 3570561: mask all-pervasive valueholder exceptions while conforming
            if ((unitOfWork.getShouldThrowConformExceptions() == UnitOfWorkImpl.THROW_ALL_CONFORM_EXCEPTIONS) && (exception.getErrorCode() != QueryException.MUST_INSTANTIATE_VALUEHOLDERS)) {
                throw exception;
            }
            if (alreadyReturned != null) {
                alreadyReturned.remove(clone);
            }
            return clone;
        }
        return null;
    
public voidconformResultsInUnitOfWork()
PUBLIC: The cache will checked completely, if the object is not found the database will be queried, and the database result will be verified with what is in the cache and/or unit of work including new objects. This can lead to poor performance so it is recomended that only the database be queried in most cases. Queries can be configured to use the cache at several levels. Other caching option are available.

see
#setCacheUsage(int)

        setCacheUsage(ConformResultsInUnitOfWork);
    
public java.lang.ObjectdeepClone()
INTERNAL: Clone the query, including its selection criteria.

Normally selection criteria are not cloned here as they are cloned later on during prepare.

        ObjectLevelReadQuery clone = (ObjectLevelReadQuery)clone();
        if (getSelectionCriteria() != null) {
            clone.setSelectionCriteria((Expression)getSelectionCriteria().clone());
        } else if (defaultBuilder != null) {
            clone.defaultBuilder = (ExpressionBuilder)defaultBuilder.clone();
        }
        return clone;
    
public voiddontAcquireLocks()
PUBLIC: Set the query not to lock.

        setLockMode(NO_LOCK);
        //Bug2804042 Must un-prepare if prepared as the SQL may change.
        setIsPrepared(false);
    
public voiddontCheckCache()
PUBLIC: This can be used to explicitly disable the cache hit. The cache hit may not be desired in some cases, such as stored procedures that accept the primary key but do not query on it.

        setCacheUsage(DoNotCheckCache);
    
public voiddontRefreshIdentityMapResult()
PUBLIC: When unset means perform read normally and dont do refresh.

        setShouldRefreshIdentityMapResult(false);
    
public voiddontUseDistinct()
ADVANCED: If a distinct has been set the DISTINCT clause will be printed. This is used internally by TopLink for batch reading but may also be used directly for advanced queries or report queries.

        setDistinctState(DONT_USE_DISTINCT);
        //Bug2804042 Must un-prepare if prepared as the SQL may change.
        setIsPrepared(false);
    
public java.lang.Objectexecute(oracle.toplink.essentials.internal.sessions.AbstractSession session, oracle.toplink.essentials.internal.sessions.AbstractRecord translationRow)
INTERNAL: Execute the query. If there are objects in the cache return the results of the cache lookup.

param
session - the session in which the receiver will be executed.
exception
DatabaseException - an error has occurred on the database.
exception
OptimisticLockException - an error has occurred using the optimistic lock feature.
return
An object, the result of executing the query.

        //Bug#2839852  Refreshing is not possible if the query uses checkCacheOnly.
        if (shouldRefreshIdentityMapResult() && shouldCheckCacheOnly()) {
            throw QueryException.refreshNotPossibleWithCheckCacheOnly(this);
        }
        return super.execute(session, translationRow);
    
public java.lang.ObjectexecuteDatabaseQuery()

        if (getSession().isUnitOfWork()) {
            UnitOfWorkImpl unitOfWork = (UnitOfWorkImpl)getSession();

            // Note if a nested unit of work this will recursively start a
            // transaction early on the parent also.
            if (isLockQuery()) {
                if ((!unitOfWork.getCommitManager().isActive()) && (!unitOfWork.wasTransactionBegunPrematurely())) {
                    unitOfWork.beginTransaction();
                    unitOfWork.setWasTransactionBegunPrematurely(true);
                }
            }
            if (unitOfWork.isNestedUnitOfWork()) {
                UnitOfWorkImpl nestedUnitOfWork = (UnitOfWorkImpl)getSession();
                setSession(nestedUnitOfWork.getParent());
                Object result = executeDatabaseQuery();
                setSession(nestedUnitOfWork);
                return registerResultInUnitOfWork(result, nestedUnitOfWork, getTranslationRow(), false);
            }
        }
        session.validateQuery(this);// this will update the query with any settings

        if (getQueryId() == 0) {
            setQueryId(getSession().getNextQueryId());
        }

        return executeObjectLevelReadQuery();
    
public java.lang.ObjectexecuteInUnitOfWork(oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl unitOfWork, oracle.toplink.essentials.internal.sessions.AbstractRecord translationRow)
INTERNAL: At this point only the code has been copied over from UnitOfWork internalExecuteQuery. No work has been done.

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

        if (!shouldMaintainCache()) {
            return unitOfWork.getParent().executeQuery(this, translationRow);
        }
        Object result = execute(unitOfWork, translationRow);

        // Optimization: If find deleted object on uow by exact primary key
        // treat this as cache hit but return null.  Bug 2782991.
        if (result == InvalidObject.instance) {
            return null;
        }
        return result;
    
protected abstract java.lang.ObjectexecuteObjectLevelReadQuery()

public java.util.VectorgetAdditionalFields()
INTERNAL: Additional fields can be added to a query. This is used in m-m bacth reading to bring back the key from the join table.

        return additionalFields;
    
public intgetCacheUsage()
PUBLIC: Return the cache usage. By default only primary key read object queries will first check the cache before accessing the database. Any query can be configure to query against the cache completely, by key or ignore the cache check.

Valid values are:

  • DoNotCheckCache
  • CheckCacheByExactPrimaryKey
  • CheckCacheByPrimaryKey
  • CheckCacheThenDatabase
  • CheckCacheOnly
  • ConformResultsInUnitOfWork
  • UseDescriptorSetting Note: UseDescriptorSetting functions like CheckCacheByPrimaryKey, except checks the appropriate descriptor's shouldDisableCacheHits setting when querying on the cache.

            return cacheUsage;
        
public shortgetDistinctState()
ADVANCED: If a distinct has been set the DISTINCT clause will be printed. This is used internally by TopLink for batch reading but may also be used directly for advanced queries or report queries.

        return distinctState;
    
public longgetExecutionTime()
INTERNAL: Return the time this query actually went to the database

        return executionTime;
    
public oracle.toplink.essentials.expressions.ExpressionBuildergetExpressionBuilder()
REQUIRED: Get the expression builder which should be used for this query. This expression builder should be used to build all expressions used by this query.

        if (defaultBuilder == null) {
            initializeDefaultBuilder();
        }

        return defaultBuilder;
    
public oracle.toplink.essentials.queryframework.FetchGroupgetFetchGroup()
Return the fetch group set in the query. If a fetch group is not explicitly set in the query, default fetch group optionally defined in the decsiptor would be used, unless the user explicitly calls query.setShouldUseDefaultFetchGroup(false).

        return fetchGroup;
    
public java.lang.StringgetFetchGroupName()
Return the fetch group name set in the query.

        return fetchGroupName;
    
public oracle.toplink.essentials.queryframework.InMemoryQueryIndirectionPolicygetInMemoryQueryIndirectionPolicy()
PUBLIC: Returns the InMemoryQueryIndirectionPolicy for this query

        return this.inMemoryQueryIndirectionPolicy;
    
public oracle.toplink.essentials.internal.queryframework.JoinedAttributeManagergetJoinedAttributeManager()
INTERNAL: Set the list of expressions that represent elements that are joined because of their mapping for this query.

        return this.joinedAttributeManager;
    
public oracle.toplink.essentials.descriptors.ClassDescriptorgetLeafDescriptorFor(oracle.toplink.essentials.expressions.Expression expression, oracle.toplink.essentials.descriptors.ClassDescriptor rootDescriptor)
INTERNAL: Lookup the descriptor for this item by traversing its expression recursively.

param
expression
param
rootDescriptor
return
throws
oracle.toplink.essentials.exceptions.QueryException

        // The base case
        if (expression.isExpressionBuilder()) {
            // The following special case is where there is a parallel builder
            // which has a different reference class as the primary builder.
            Class queryClass = ((ExpressionBuilder)expression).getQueryClass();
            if ((queryClass != null) && (queryClass != getReferenceClass())) {
                return getSession().getDescriptor(queryClass);
            }
            return rootDescriptor;
        }
        Expression baseExpression = ((QueryKeyExpression)expression).getBaseExpression();
        ClassDescriptor baseDescriptor = getLeafDescriptorFor(baseExpression, rootDescriptor);
        ClassDescriptor descriptor = null;
        String attributeName = expression.getName();

        DatabaseMapping mapping = baseDescriptor.getMappingForAttributeName(attributeName);

        if (mapping == null) {
            QueryKey queryKey = baseDescriptor.getQueryKeyNamed(attributeName);
            if (queryKey != null) {
                if (queryKey.isForeignReferenceQueryKey()) {
                    descriptor = getSession().getDescriptor(((ForeignReferenceQueryKey)queryKey).getReferenceClass());
                } else// if (queryKey.isDirectQueryKey())
                 {
                    descriptor = queryKey.getDescriptor();
                }
            }
            if (descriptor == null) {
                throw QueryException.invalidExpressionForQueryItem(expression, this);
            }
        } else if (mapping.isAggregateObjectMapping()) {
            descriptor = ((AggregateObjectMapping)mapping).getReferenceDescriptor();
        } else if (mapping.isForeignReferenceMapping()) {
            descriptor = ((ForeignReferenceMapping)mapping).getReferenceDescriptor();
        }
        return descriptor;
    
public oracle.toplink.essentials.mappings.DatabaseMappinggetLeafMappingFor(oracle.toplink.essentials.expressions.Expression expression, oracle.toplink.essentials.descriptors.ClassDescriptor rootDescriptor)
INTERNAL: Lookup the mapping for this item by traversing its expression recursively. If an aggregate of foreign mapping is found it is traversed.

        // Check for database field expressions or place holder
        if ((expression == null) || (expression.isFieldExpression())) {
            return null;
        }

        if (!(expression.isQueryKeyExpression())) {
            return null;
        }

        QueryKeyExpression qkExpression = (QueryKeyExpression)expression;
        Expression baseExpression = qkExpression.getBaseExpression();

        ClassDescriptor descriptor = getLeafDescriptorFor(baseExpression, rootDescriptor);
        return descriptor.getMappingForAttributeName(qkExpression.getName());
    
public shortgetLockMode()
PUBLIC: Return the current locking mode.

        if (lockingClause == null) {
            return DEFAULT_LOCK_MODE;
        } else {
            return lockingClause.getLockMode();
        }
    
public oracle.toplink.essentials.internal.expressions.ForUpdateClausegetLockingClause()
INTERNAL: It is not exactly as simple as a query being either locking or not. Any combination of the reference class object and joined attributes may be locked.

        return lockingClause;
    
public java.util.VectorgetNonFetchJoinAttributeExpressions()
INTERNAL: Return the attributes that must be joined, but not fetched, that is, do not trigger the value holder.

        if (this.nonFetchJoinAttributeExpressions == null){
            this.nonFetchJoinAttributeExpressions = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance();
        }
        return nonFetchJoinAttributeExpressions;
    
public java.lang.ClassgetReferenceClass()
PUBLIC: Return the reference class of the query.

        return super.getReferenceClass();
    
public java.lang.StringgetReferenceClassName()
INTERNAL: Return the reference class of the query.

        return super.getReferenceClassName();
    
public java.util.VectorgetSelectionFields()
INTERNAL: Return the fields selected by the query. This includes the partial or joined fields. This is used for custom SQL executions.

        if ((!hasPartialAttributeExpressions()) && (!getJoinedAttributeManager().hasJoinedAttributes()) && (!hasFetchGroupAttributeExpressions())) {
            return getDescriptor().getAllFields();
        }
        Vector fields;
        if (hasFetchGroupAttributeExpressions()) {//fetch group support
            List fetchGroupAttrExps = getFetchGroup().getFetchGroupAttributeExpressions();
            fields = new Vector(fetchGroupAttrExps.size());
            for (int index = 0; index < fetchGroupAttrExps.size(); index++) {
                Expression expression = (Expression)fetchGroupAttrExps.get(index);

                // Expression may not have been initialized.
                expression.getBuilder().setSession(getSession().getRootSession(null));
                expression.getBuilder().setQueryClass(getReferenceClass());
                Helper.addAllToVector(fields, expression.getFields());
            }
        } else {
            fields = new Vector(getDescriptor().getAllFields().size() + getJoinedAttributeManager().getJoinedAttributeExpressions().size() + getJoinedAttributeManager().getJoinedMappingExpressions().size());
            Helper.addAllToVector(fields, getDescriptor().getAllFields());
            addSelectionFieldsForJoinedExpressions(fields, getJoinedAttributeManager().getJoinedAttributeExpressions());
            addSelectionFieldsForJoinedExpressions(fields, getJoinedAttributeManager().getJoinedMappingExpressions());
        }
        return fields;
    
public booleanhasAsOfClause()
PUBLIC: Answers if the domain objects are to be read as of a past time.

see
#getAsOfClause()

        return ((defaultBuilder != null) && defaultBuilder.hasAsOfClause());
    
public booleanhasFetchGroupAttributeExpressions()
INTERNAL: Return if fetch group attributes.

        return (getFetchGroup() != null) && (getFetchGroup().hasFetchGroupAttributeExpressions());
    
public booleanhasNonFetchJoinedAttributeExpressions()
INTERNAL: Return the attributes that must be joined.

        return this.nonFetchJoinAttributeExpressions != null && !this.nonFetchJoinAttributeExpressions.isEmpty();
    
public booleanhasPartialAttributeExpressions()
INTERNAL: Return if partial attributes.

        return false;
    
protected voidinitializeDefaultBuilder()
Initialize the expression builder which should be used for this query. If there is a where clause, use its expression builder, otherwise generate one and cache it. This helps avoid unnecessary rebuilds.

        DatabaseQueryMechanism mech = getQueryMechanism();
        if (mech.isExpressionQueryMechanism() && ((ExpressionQueryMechanism)mech).getExpressionBuilder() != null) {
            this.defaultBuilder = ((ExpressionQueryMechanism)mech).getExpressionBuilder();
            return;
        }
        this.defaultBuilder = new ExpressionBuilder();
    
public voidinitializeFetchGroup()
INTERNAL: Initialize fetch group

        if (fetchGroup != null) {
            //fetch group already set.
            return;
        }

        //not explicitly set dynamically fetch group
        if (fetchGroupName != null) {//set pre-defined named group
            fetchGroup = getDescriptor().getFetchGroupManager().getFetchGroup(fetchGroupName);
            if (fetchGroup == null) {
                //named fetch group is not defined in the descriptor
                throw QueryException.fetchGroupNotDefinedInDescriptor(fetchGroupName);
            }
        } else {//not set fecth group at all
            //use the default fetch group if not explicitly turned off
            if (shouldUseDefaultFetchGroup()) {
                fetchGroup = getDescriptor().getDefaultFetchGroup();
            }
        }
    
public booleanisClonePessimisticLocked(java.lang.Object clone, oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl uow)
INTERNAL: Helper method that checks if clone has been locked with uow.

        return false;
    
public booleanisDefaultLock()
INTERNAL: Helper method to determine the default mode. If true and quey has a pessimistic locking policy, locking will be configured according to the pessimistic locking policy.

        return (lockingClause == null);
    
public booleanisDistinctComputed()
INTERNAL: return true if this query has computed its distinct value already

        return getDistinctState() != UNCOMPUTED_DISTINCT;
    
public booleanisFetchGroupAttribute(java.lang.String attributeName)
INTERNAL: Return if fetch group attribute.

        if (getFetchGroup() == null) {
            //every attribute is fetched already
            return true;
        }
        return getFetchGroup().getAttributes().contains(attributeName);
    
public booleanisLockQuery()
PUBLIC: Answers if the query lock mode is known to be LOCK or LOCK_NOWAIT. In the case of DEFAULT_LOCK_MODE and the query reference class being a CMP entity bean, at execution time LOCK, LOCK_NOWAIT, or NO_LOCK will be decided.

If a single joined attribute was configured for pessimistic locking then this will return true (after first execution) as the SQL contained a FOR UPDATE OF clause.

        return getLockMode() > NO_LOCK;
    
public booleanisLockQuery(oracle.toplink.essentials.sessions.Session session)
ADVANCED: Answers if this query will issue any pessimistic locks.

If the lock mode is not known (DEFAULT_LOCK_MODE / descriptor specified fine-grained locking) the lock mode will be determined now, to be either LOCK, LOCK_NOWAIT, or NO_LOCK.

see
#isLockQuery()

        checkPrePrepare((AbstractSession)session);
        return isLockQuery();
    
public booleanisObjectLevelReadQuery()
PUBLIC: Return if this is an object level read query.

        return true;
    
protected booleanisPrePrepared()
PUBLIC: Queries prepare common stated in themselves.

        return isPrePrepared;
    
protected booleanisRegisteringResults()
INTERNAL: Answers if we are executing through a UnitOfWork and registering results. This is only ever false if using the conforming without registering feature.

        return ((shouldRegisterResultsInUnitOfWork() && getDescriptor().shouldRegisterResultsInUnitOfWork()) || isLockQuery());
    
protected voidprePrepare()
INTERNAL: Prepare the receiver for execution in a session.

        // For bug 3136413/2610803 building the selection criteria from an EJBQL string or
        // an example object is done just in time.
        buildSelectionCriteria(session);
        checkDescriptor(session);

        // Add mapping joined attributes.
        if (getQueryMechanism().isExpressionQueryMechanism()) {
            getJoinedAttributeManager().processJoinedMappings();
        }

        // modify query for locking only if locking has not been configured
        if (isDefaultLock()) {
            setWasDefaultLockMode(true);
            ForUpdateOfClause lockingClause = null;
            if (getJoinedAttributeManager().hasJoinedExpressions()) {
                lockingClause = getJoinedAttributeManager().setupLockingClauseForJoinedExpressions(lockingClause, getSession());
            }
            if (lockingClause == null) {
                this.lockingClause = ForUpdateClause.newInstance(NO_LOCK);
            } else {
                this.lockingClause = lockingClause;
                // SPECJ: Locking not compatible with distinct for batch reading.
                dontUseDistinct();
            }
        } else if (getLockMode() == NO_LOCK) {
            setWasDefaultLockMode(true);            
        }
    
protected voidprepare()
INTERNAL: Prepare the receiver for execution in a session.

        super.prepare();
        prepareQuery();
    
public oracle.toplink.essentials.queryframework.DatabaseQueryprepareOutsideUnitOfWork(oracle.toplink.essentials.internal.sessions.AbstractSession session)
INTERNAL: There is a very special case where a query may be a bean-level pessimistic locking query.

If that is so, only queries executed inside of a UnitOfWork should have a locking clause. In the extremely rare case that we execute a locking query outside of a UnitOfWork, must disable locking so that we do not get a fetch out of sequence error.

        // Implementation is complicated because: if locking refresh will be
        // auto set to true preventing cache hit.
        // Must prepare this query from scratch if outside uow but locking
        // Must not reprepare this query as a NO_LOCK, but create a clone first
        // Must not cloneAndUnPrepare unless really have to
        if (isLockQuery(session) && getLockingClause().isForUpdateOfClause()) {
            ObjectLevelReadQuery clone = (ObjectLevelReadQuery)clone();
            clone.dontAcquireLocks();
            clone.setIsPrepared(false);
            clone.checkPrePrepare(session);
            return clone;
        }
        return this;
    
protected voidprepareQuery()
INTERNAL: Prepare the receiver for execution in a session.

        if ((!shouldMaintainCache()) && shouldRefreshIdentityMapResult() && (!descriptor.isAggregateCollectionDescriptor())) {
            throw QueryException.refreshNotPossibleWithoutCache(this);
        }
        if (shouldMaintainCache() && hasPartialAttributeExpressions()) {
            throw QueryException.cannotCachePartialObjects(this);
        }

        if (descriptor.isAggregateDescriptor()) {
            // Not allowed
            throw QueryException.aggregateObjectCannotBeDeletedOrWritten(descriptor, this);
        }

        // If fetch group manager is not set in the descriptor and the user attempts to use fetch group in the query dynamiclly, throw exception here.
        if ((!getDescriptor().hasFetchGroupManager()) && ((getFetchGroup() != null) || (getFetchGroupName() != null))) {
            throw QueryException.fetchGroupValidOnlyIfFetchGroupManagerInDescriptor(getDescriptor().getJavaClassName(), getName());
        }

        // Prepare fetch group if applied.
        if (getDescriptor().hasFetchGroupManager()) {
            getDescriptor().getFetchGroupManager().prepareQueryWithFetchGroup(this);
        }

        // Validate and prepare join expressions.			
        if (getJoinedAttributeManager().hasJoinedExpressions()) {
            getJoinedAttributeManager().prepareJoinExpressions(getSession());
        } else {
            // If the query is being re-prepared must clear possible old cached data.
            getJoinedAttributeManager().reset();
        }  
    
public voidrecordCloneForPessimisticLocking(java.lang.Object clone, oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl uow)
INTERNAL: Helper method that records clone with uow if query is pessimistic locking.

        if ((isLockQuery()) && lockingClause.isReferenceClassLocked()) {
            uow.addPessimisticLockedClone(clone);
        }
    
public voidrefreshIdentityMapResult()
PUBLIC: Refresh the attributes of the object(s) resulting from the query. If cascading is used the private parts of the objects will also be refreshed.

        setShouldRefreshIdentityMapResult(true);
    
public abstract java.lang.ObjectregisterResultInUnitOfWork(java.lang.Object result, oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl unitOfWork, oracle.toplink.essentials.internal.sessions.AbstractRecord arguments, boolean buildDirectlyFromRows)
INTERNAL: All objects queried via a UnitOfWork get registered here. If the query went to the database.

Involves registering the query result individually and in totality, and hence refreshing / conforming is done here.

param
result may be collection (read all) or an object (read one), or even a cursor. If in transaction the shared cache will be bypassed, meaning the result may not be originals from the parent but raw database rows.
param
unitOfWork the unitOfWork the result is being registered in.
param
arguments the original arguments/parameters passed to the query execution. Used by conforming
param
buildDirectlyFromRows If in transaction must construct a registered result from raw database rows.
return
the final (conformed, refreshed, wrapped) UnitOfWork query result

public voidresetDistinct()
ADVANCED: If a distinct has been set the DISTINCT clause will be printed. This is used internally by TopLink for batch reading but may also be used directly for advanced queries or report queries.

        setDistinctState(UNCOMPUTED_DISTINCT);
        //Bug2804042 Must un-prepare if prepared as the SQL may change.
        setIsPrepared(false);
    
public voidsetAdditionalFields(java.util.Vector additionalFields)
INTERNAL: Additional fields can be added to a query. This is used in m-m bacth reading to bring back the key from the join table.

        this.additionalFields = additionalFields;
    
public voidsetCacheUsage(int cacheUsage)
PUBLIC: Set the cache usage. By default only primary key read object queries will first check the cache before accessing the database. Any query can be configure to query against the cache completely, by key or ignore the cache check.

Valid values are:

  • DoNotCheckCache - The query does not check the cache but accesses the database, the cache will still be maintain.
  • CheckCacheByExactPrimaryKey - If the query is exactly and only on the object's primary key the cache will be checked.
  • CheckCacheByPrimaryKey - If the query contains the primary key and possible other values the cache will be checked.
  • CheckCacheThenDatabase - The whole cache will be checked to see if there is any object matching the query, if not the database will be accessed.
  • CheckCacheOnly - The whole cache will be checked to see if there is any object matching the query, if not null or an empty collection is returned.
  • ConformResultsAgainstUnitOfWork - The results will be checked againtst the changes within the unit of work and object no longer matching or deleted will be remove, matching new objects will also be added.
  • shouldCheckDescriptorForCacheUsage - This setting functions like CheckCacheByPrimaryKey, except checks the appropriate descriptor's shouldDisableCacheHits setting when querying on the cache.

            this.cacheUsage = cacheUsage;
        
public voidsetDescriptor(oracle.toplink.essentials.descriptors.ClassDescriptor descriptor)
INTERNAL: Set the descriptor for the query.

        super.setDescriptor(descriptor);
        if (this.joinedAttributeManager != null){
            this.joinedAttributeManager.setDescriptor(descriptor);
        }
    
public voidsetDistinctState(short distinctState)
ADVANCED: If a distinct has been set the DISTINCT clause will be printed. This is used internally by TopLink for batch reading but may also be used directly for advanced queries or report queries.

        this.distinctState = distinctState;
    
public voidsetEJBQLString(java.lang.String ejbqlString)

        super.setEJBQLString(ejbqlString);
        setIsPrePrepared(false);
    
public voidsetExecutionTime(long executionTime)
INTERNAL: Set the the time this query went to the database.

        this.executionTime = executionTime;
    
public voidsetExpressionBuilder(oracle.toplink.essentials.expressions.ExpressionBuilder builder)
INTERNAL Sets the default expression builder for this query.

        this.defaultBuilder = builder;
    
public voidsetFetchGroup(oracle.toplink.essentials.queryframework.FetchGroup newFetchGroup)
Set a dynamic (use case) fetch group to the query.

        fetchGroup = newFetchGroup;
    
public voidsetFetchGroupName(java.lang.String groupName)
Set a descriptor-level pre-defined named fetch group to the query.

        //nullify the fecth group refernce as one query can only has one fetch group.
        fetchGroup = null;
        fetchGroupName = groupName;
    
public voidsetInMemoryQueryIndirectionPolicy(oracle.toplink.essentials.queryframework.InMemoryQueryIndirectionPolicy inMemoryQueryIndirectionPolicy)
PUBLIC: Set the InMemoryQueryIndirectionPolicy for this query

        //Bug2862302 Backwards compatibility.  This makes sure 9.0.3 and any older version project xml don't break
        if (inMemoryQueryIndirectionPolicy != null) {
            this.inMemoryQueryIndirectionPolicy = inMemoryQueryIndirectionPolicy;
        }
    
protected voidsetIsPrePrepared(boolean isPrePrepared)
INTERNAL: If changes are made to the query that affect the derived SQL or Call parameters the query needs to be prepared again.

Automatically called internally.

The early phase of preparation is to check if this is a pessimistic locking query.

        // Only unprepare if was prepared to begin with, prevent unpreparing during prepare.
        if (this.isPrePrepared && !isPrePrepared) {
            setIsPrepared(false);
            this.getJoinedAttributeManager().reset();
        }
        this.isPrePrepared = isPrePrepared;
    
public voidsetLockMode(short lockMode)
PUBLIC: Sets whether this is a pessimistically locking query.
  • ObjectBuildingQuery.LOCK: SELECT .... FOR UPDATE issued.
  • ObjectBuildingQuery.LOCK_NOWAIT: SELECT .... FOR UPDATE NO WAIT issued.
  • ObjectBuildingQuery.NO_LOCK: no pessimistic locking.
  • ObjectBuildingQuery.DEFAULT_LOCK_MODE (default) and you have a CMP descriptor: fine grained locking will occur.

Fine Grained Locking: On execution the reference class and those of all joined attributes will be checked. If any of these have a PessimisticLockingPolicy set on their descriptor, they will be locked in a SELECT ... FOR UPDATE OF ... {NO WAIT}. Issues fewer locks and avoids setting the lock mode on each query.

Example:readAllQuery.setSelectionCriteria(employee.get("address").equal("Ottawa"));

  • LOCK: all employees in Ottawa and all referenced Ottawa addresses will be locked.
  • DEFAULT_LOCK_MODE: if address is a joined attribute, and only address has a pessimistic locking policy, only referenced Ottawa addresses will be locked.

see
oracle.toplink.essentials.descriptors.PessimisticLockingPolicy

        if ((lockMode == LOCK) || (lockMode == LOCK_NOWAIT)) {
            lockingClause = ForUpdateClause.newInstance(lockMode);
            setShouldRefreshIdentityMapResult(true);
        } else if (lockMode == NO_LOCK) {
            lockingClause = ForUpdateClause.newInstance(lockMode);
        } else {
            lockingClause = null;
            setIsPrePrepared(false);
        }
        setIsPrepared(false);
    
public voidsetLockingClause(oracle.toplink.essentials.internal.expressions.ForUpdateClause clause)
INTERNAL: The locking clause contains a list of expressions representing which objects are to be locked by the query.

Use for even finer grained control over what is and is not locked by a particular query.

        if (clause.isForUpdateOfClause()) {
            this.lockingClause = clause;
            setIsPrePrepared(false);
        } else {
            setLockMode(clause.getLockMode());
        }
    
protected voidsetNonFetchJoinAttributeExpressions(java.util.Vector nonFetchJoinExpressions)
INTERNAL: Return the attributes that must be joined, but not fetched, that is, do not trigger the value holder.

        this.nonFetchJoinAttributeExpressions = nonFetchJoinExpressions;
    
public voidsetReferenceClass(java.lang.Class aClass)
REQUIRED: Set the reference class for the query.

        super.setReferenceClass(aClass);
    
public voidsetReferenceClassName(java.lang.String aClass)
INTERNAL: Set the reference class for the query.

        super.setReferenceClassName(aClass);
    
public voidsetSelectionCriteria(oracle.toplink.essentials.expressions.Expression expression)

        super.setSelectionCriteria(expression);
        if ((expression != null) && (defaultBuilder != null)) {
            // For flashback: Must make sure expression and defaultBuilder always in sync.
            ExpressionBuilder newBuilder = expression.getBuilder();
            if ( (newBuilder != defaultBuilder) && (newBuilder.getQueryClass() == null || newBuilder.getQueryClass().equals(defaultBuilder.getQueryClass()) )){
                defaultBuilder = newBuilder;
            }
        }
    
public voidsetShouldIncludeData(boolean shouldIncludeData)
INTERNAL: Set if the rows for the result of the query should also be returned using a complex query result.

see
ComplexQueryResult

        this.shouldIncludeData = shouldIncludeData;
    
public voidsetShouldProcessResultsInUnitOfWork(boolean processResultsInUnitOfWork)
ADVANCED: Used for CMP only. This allows users to indicate whether cmp finders executed at the beginning of a transaction should always be run against a UnitOfWork. Defaults to true.

If set to false, then UnitOfWork allocation will be deferred until a business method (including creates/removes) or finder with shouldProcessResultsInUnitOfWork == true is invoked. Any finder executed before such a time, will do so against the underlying ServerSession. Forcing finder execution to always go through a UnitOfWork means the results will be cloned and cached in the UnitOfWork up front. This is desired when the results will be accessed in the same transaction.

Note that finders executed with an unspecified transaction context will never be executed against a UnitOfWork, even if this setting is true. This case may happen with the NotSupported, Never, and Supports attributes.

        this.shouldProcessResultsInUnitOfWork = processResultsInUnitOfWork;
    
public voidsetShouldRefreshIdentityMapResult(boolean shouldRefreshIdentityMapResult)
PUBLIC: Set if the attributes of the object(s) resulting from the query should be refreshed. If cascading is used the private parts of the objects will also be refreshed.

        this.shouldRefreshIdentityMapResult = shouldRefreshIdentityMapResult;
    
public voidsetShouldRegisterResultsInUnitOfWork(boolean shouldRegisterResultsInUnitOfWork)
INTERNAL: Set to false to have queries conform to a UnitOfWork without registering any additional objects not already in that UnitOfWork.

see
#shouldRegisterResultsInUnitOfWork
bug
2612601

        this.shouldRegisterResultsInUnitOfWork = shouldRegisterResultsInUnitOfWork;
    
public voidsetShouldUseDefaultFetchGroup(boolean shouldUseDefaultFetchGroup)
Set false if the user does not want to use the default fetch group defined in the descriptor level.

        this.shouldUseDefaultFetchGroup = shouldUseDefaultFetchGroup;
    
protected voidsetWasDefaultLockMode(boolean wasDefaultLockMode)
INTERNAL: Set if this query originally used the default lock mode.

        this.wasDefaultLockMode = wasDefaultLockMode;
    
public booleanshouldCheckCacheOnly()
PUBLIC: Return if cache should be checked.

        return getCacheUsage() == CheckCacheOnly;
    
public booleanshouldCheckDescriptorForCacheUsage()
PUBLIC: Return whether the descriptor's disableCacheHits setting should be checked prior to querying the cache.

        return getCacheUsage() == UseDescriptorSetting;
    
public booleanshouldConformResultsInUnitOfWork()
PUBLIC: Should the results will be checked against the changes within the unit of work and object no longer matching or deleted will be remove, matching new objects will also be added..

        return getCacheUsage() == ConformResultsInUnitOfWork;
    
public booleanshouldDistinctBeUsed()
INTERNAL: return true if this query should use a distinct

        return getDistinctState() == USE_DISTINCT;
    
public booleanshouldIncludeData()
INTERNAL: Return if the rows for the result of the query should also be returned using a complex query result.

see
ComplexQueryResult

        return shouldIncludeData;
    
public booleanshouldProcessResultsInUnitOfWork()
ADVANCED: Used for CMP only. Indicates whether cmp finders executed at the beginning of a transaction should always be run against a UnitOfWork. Defaults to true.

If set to false, then UnitOfWork allocation will be deferred until a business method (including creates/removes) or finder with shouldProcessResultsInUnitOfWork == true is invoked. Any finder executed before such a time, will do so against the underlying ServerSession. Forcing finder execution to always go through a UnitOfWork means the results will be cloned and cached in the UnitOfWork up front. This is desired when the results will be accessed in the same transaction.

Note that finders executed with an unspecified transaction context will never be executed against a UnitOfWork, even if this setting is true. This case may happen with the NotSupported, Never, and Supports attributes.

        return this.shouldProcessResultsInUnitOfWork;
    
public booleanshouldReadAllMappings()
INTERNAL: Return if this is a full object query, not partial nor fetch group.

        return (!hasPartialAttributeExpressions()) && (!hasFetchGroupAttributeExpressions());
    
public booleanshouldReadMapping(oracle.toplink.essentials.mappings.DatabaseMapping mapping)
INTERNAL: Check if the mapping is part of the partial attributes.

        if ((!hasPartialAttributeExpressions()) && (!hasFetchGroupAttributeExpressions())) {
            return true;
        }

        // bug 3659145
        if (hasFetchGroupAttributeExpressions()) {
            return isFetchGroupAttribute(mapping.getAttributeName());
        }

        return true;
    
public booleanshouldRefreshIdentityMapResult()
PUBLIC: Set to a boolean. When set means refresh the instance variables of referenceObject from the database.

        return shouldRefreshIdentityMapResult;
    
public booleanshouldRegisterResultsInUnitOfWork()
INTERNAL: Allows one to do conforming in a UnitOfWork without registering. Queries executed on a UnitOfWork will only return working copies for objects that have already been registered.

Extreme care should be taken in using this feature, for a user will get back a mix of registered and original (unregistered) objects.

Best used with a WrapperPolicy where invoking on an object will trigger its registration (CMP). Without a WrapperPolicy {@link oracle.toplink.essentials.sessions.UnitOfWork#registerExistingObject registerExistingObject} should be called on any object that you intend to change.

return
true by default.
see
#setShouldRegisterResultsInUnitOfWork(boolean)
see
oracle.toplink.essentials.publicinterface.Descriptor#shouldRegisterResultsInUnitOfWork()
bug
2612601

        return shouldRegisterResultsInUnitOfWork;
    
public booleanshouldUseDefaultFetchGroup()
Return false if the query does not use the default fetch group defined in the descriptor level.

        return shouldUseDefaultFetchGroup;
    
public java.lang.StringtoString()

        if (getReferenceClass() == null) {
            return super.toString();
        }
        return Helper.getShortClassName(getClass()) + "(" + getReferenceClass().getName() + ")";
    
public voiduseDistinct()
ADVANCED: If a distinct has been set the DISTINCT clause will be printed. This is used internally by TopLink for batch reading but may also be used directly for advanced queries or report queries.

        setDistinctState(USE_DISTINCT);
        //Bug2804042 Must un-prepare if prepared as the SQL may change.
        setIsPrepared(false);
    
protected booleanwasDefaultLockMode()
INTERNAL: Return if this query originally used the default lock mode.

        return wasDefaultLockMode;