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

DatabaseQuery

public abstract class DatabaseQuery extends Object implements Serializable, Cloneable, FalseUndefinedTrue

Purpose: Abstract class for all database query objects. DatabaseQuery is a visible class to the TopLink user. Users create an appropriate query by creating an instance of a concrete subclasses of DatabaseQuery.

Responsibilities:

  • Provide a common protocol for query objects.
  • Defines a generic execution interface.
  • Provides query property values
  • Holds arguments to the query
author
Yvon Lavoie
since
TOPLink/Java 1.0

Fields Summary
protected String
name
Queries can be given a name and registered with a descriptor to allow common queries to be reused.
protected Vector
arguments
Arguments can be given and specified to predefined queries to allow reuse.
protected Vector
argumentValues
Arguments values can be given and specified to predefined queries to allow reuse.
protected Vector
argumentTypes
Needed to differentiate queries with the same name.
protected Vector
argumentTypeNames
Used to build a list of argumentTypes by name pre-initialization
protected transient ClassDescriptor
descriptor
The descriptor cached on the prepare for object level queries.
protected DatabaseQueryMechanism
queryMechanism
The query mechanism determines the mechanism on how the database will be accessed.
protected boolean
shouldMaintainCache
Flag used for a query to bypass the identitymap and unit of work.
protected Hashtable
properties
Internallay used by the mappings as a temporary store.
protected transient AbstractSession
session
Only used after the query is prepared to store the session under which the query was executed.
protected transient Accessor
accessor
Connection to use for database access, required for server session connection pooling.
protected AbstractRecord
translationRow
Mappings and the descriptor use parameterized mechanisms that will be translated with the data from the row.
protected boolean
isUserDefined
Internal flag used to bypass user define queries when executing one for custom sql/query support.
protected int
cascadePolicy
Policy that determines how the query will cascade to its object's parts.
protected String
sessionName
Used to override the default session in the session broker.
protected boolean
isPrepared
Queries prepare common stated in themselves.
protected boolean
shouldCloneCall
Used to indicate whether or not the call needs to be cloned.
protected boolean
shouldPrepare
Allow for the prepare of queries to be turned off, this allow for dynamic non-pre SQL generated queries.
protected int
shouldBindAllParameters
Bind all arguments to the SQL statement.
protected int
shouldCacheStatement
Cache the prepared statement, this requires full parameter binding as well.
protected boolean
shouldUseWrapperPolicy
Use the WrapperPolicy for the objects returned by the query
public static final int
NoCascading
public static final int
CascadePrivateParts
public static final int
CascadeAllParts
public static final int
CascadeDependentParts
public static final int
CascadeAggregateDelete
public static final int
CascadeByMapping
protected Boolean
flushOnExecute
Constructors Summary
public DatabaseQuery()
PUBLIC: Initialize the state of the query


                
      
        this.shouldMaintainCache = true;
        // bug 3524620: lazy-init query mechanism
        //this.queryMechanism = new ExpressionQueryMechanism(this);
        this.isUserDefined = false;
        this.cascadePolicy = NoCascading;
        this.isPrepared = false;
        this.shouldUseWrapperPolicy = true;
        this.shouldPrepare = true;
        this.shouldBindAllParameters = Undefined;
        this.shouldCacheStatement = Undefined;
        this.shouldCloneCall = false;
    
Methods Summary
public voidaddArgument(java.lang.String argumentName)
PUBLIC: Add the argument named argumentName. This will cause the translation of references of argumentName in the receiver's expression, with the value of the argument as supplied to the query in order from executeQuery()

        // CR#3545 - Changed the default argument type to make argument types work more consistently
        // with the SDK
        addArgument(argumentName, java.lang.Object.class);
    
public voidaddArgument(java.lang.String argumentName, java.lang.Class type)
PUBLIC: Add the argument named argumentName and its class type. This will cause the translation of references of argumentName in the receiver's expression, with the value of the argument as supplied to the query in order from executeQuery(). Specifying the class type is important if identically named queries are used but with different argument lists.

        getArguments().addElement(argumentName);
        getArgumentTypes().addElement(type);
        getArgumentTypeNames().addElement(type.getName());
    
public voidaddArgument(java.lang.String argumentName, java.lang.String typeAsString)
PUBLIC: Add the argument named argumentName and its class type. This will cause the translation of references of argumentName in the receiver's expression, with the value of the argument as supplied to the query in order from executeQuery(). Specifying the class type is important if identically named queries are used but with different argument lists.

        getArguments().addElement(argumentName);
        //bug 3197587
        getArgumentTypes().addElement(Helper.getObjectClass(ConversionManager.loadClass(typeAsString)));
        getArgumentTypeNames().addElement(typeAsString);
    
public voidaddArgumentByTypeName(java.lang.String argumentName, java.lang.String typeAsString)
INTERNAL: Add an argument to the query, but do not resovle the class yet. This is useful for building a query without putting the domain classes on the classpath for the Mapping Workbench.

        getArguments().addElement(argumentName);
        getArgumentTypeNames().addElement(typeAsString);
    
public voidaddArgumentValue(java.lang.Object argumentValue)
PUBLIC: Add the argumentValue. Argument values must be added in the same order the arguments are defined.

        getArgumentValues().addElement(argumentValue);
    
public voidaddArgumentValues(java.util.Vector theArgumentValues)
PUBLIC: Add the argumentValues to the query. Argument values must be added in the same order the arguments are defined.

        setArgumentValues(theArgumentValues);
    
public voidaddCall(oracle.toplink.essentials.queryframework.Call call)
PUBLIC: Used to define a store procedure or SQL query. This may be used for multiple SQL executions to be mapped to a single query. This cannot be used for cursored selects, delete alls or does exists.

        setQueryMechanism(call.buildQueryMechanism(this, getQueryMechanism()));
        // Must un-prepare is prepare as the SQL may change.
        setIsPrepared(false);
    
public voidaddStatement(oracle.toplink.essentials.internal.expressions.SQLStatement statement)
PUBLIC: Used to define a statement level query. This may be used for multiple SQL executions to be mapped to a single query. This cannot be used for cursored selects, delete alls or does exists.

        // bug 3524620: lazy-init query mechanism
        if (!hasQueryMechanism()) {
            setQueryMechanism(new StatementQueryMechanism(this));
        } else if (!getQueryMechanism().isStatementQueryMechanism()) {
            setQueryMechanism(new StatementQueryMechanism(this));
        }
        ((StatementQueryMechanism)getQueryMechanism()).getSQLStatements().addElement(statement);
        // Must un-prepare is prepare as the SQL may change.
        setIsPrepared(false);
    
public voidbindAllParameters()
PUBLIC: Bind all arguments to any SQL statement.

        setShouldBindAllParameters(true);
    
protected voidbuildSelectionCriteria(oracle.toplink.essentials.internal.sessions.AbstractSession session)
INTERNAL: In the case of EJBQL, an expression needs to be generated. Build the required expression.

        this.getQueryMechanism().buildSelectionCriteria(session);
    
public voidcacheStatement()
PUBLIC: Cache the prepared statements, this requires full parameter binding as well.

        setShouldCacheStatement(true);
    
public voidcascadeAllParts()
PUBLIC: Cascade the query and its properties on the queries object(s) and all objects related to the queries object(s). This includes private and independent relationships, but not read-only relationships. This will still stop on uninstantiated indirection objects except for deletion. Great caution should be used in using the property as the query may effect a large number of objects. This policy is used by the unit of work to ensure persistence by reachability.

        setCascadePolicy(CascadeAllParts);
    
public voidcascadeByMapping()
PUBLIC: Cascade the query and its properties on the queries object(s) and all related objects where the mapping has been set to cascade the merge.

        setCascadePolicy(CascadeByMapping);
    
public voidcascadeOnlyDependentParts()
INTERNAL: Used by unit of work, only cascades constraint dependecies.

        setCascadePolicy(CascadeDependentParts);
    
public voidcascadePrivateParts()
PUBLIC: Cascade the query and its properties on the queries object(s) and all privately owned objects related to the queries object(s). This is the default for write and delete queries. This policy should normally be used for refreshing, otherwise you could refresh half of any object.

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

    
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.

        return null;
    
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.

        return null;
    
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.

        // This query is first prepared for global common state, this must be synced.
        if (!isPrepared()) {// Avoid the monitor is already prepare, must check again for concurrency.
            // Prepared queries cannot be custom as then they would never have been prepared.
            synchronized (this) {
                if (!isPrepared()) {
                    // When custom SQL is used there is a possibility that the SQL contains the # token.
                    // Avoid this by telling the call if this is custom SQL with parameters.
                    // This must not be called for SDK calls.
                    if ((isReadQuery() || isDataModifyQuery()) && isCallQuery() && (getQueryMechanism() instanceof CallQueryMechanism) && ((translationRow == null) || translationRow.isEmpty())) {
                        // Must check for read object queries as the row will be empty until the prepare.
                        if (isReadObjectQuery() || isUserDefined()) {
                            ((CallQueryMechanism)getQueryMechanism()).setCallHasCustomSQLArguments();
                        }
                    } else if (isCallQuery() && (getQueryMechanism() instanceof CallQueryMechanism)) {
                        ((CallQueryMechanism)getQueryMechanism()).setCallHasCustomSQLArguments();
                    }
                    setSession(session);// Session is required for some init stuff.
                    prepare();
                    setSession(null);
                    setIsPrepared(true);// MUST not set prepare until done as other thread may hit before finihsing the prepare.
                }
            }
        }
    
public java.lang.Objectclone()
INTERNAL: Clone the query

        try {
            DatabaseQuery cloneQuery = (DatabaseQuery)super.clone();

            // partial fix for 3054240 
            // need to pay attention to other components of the query, too  MWN
            if (cloneQuery.properties != null) {
                if (cloneQuery.properties.isEmpty()) {
                    cloneQuery.setProperties(null);
                } else {
                    cloneQuery.setProperties((Hashtable)getProperties().clone());
                }
            }

            // bug 3524620: now that the query mechanism is lazy-init'd,
            // only clone the query mechanism if we have one.
            if (hasQueryMechanism()) {
                cloneQuery.setQueryMechanism(getQueryMechanism().clone(cloneQuery));
            }
            cloneQuery.setIsPrepared(isPrepared());// Setting some things will trigger unprepare.
            return cloneQuery;
        } catch (CloneNotSupportedException e) {
            return null;
        }
    
protected voidclonedQueryExecutionComplete(oracle.toplink.essentials.queryframework.DatabaseQuery query, oracle.toplink.essentials.internal.sessions.AbstractSession session)
INTERNAL Used to give the subclasses oportunity to copy aspects of the cloned query to the original query.

        //no-op for this class
    
public voidconvertClassNamesToClasses(java.lang.ClassLoader classLoader)
INTERNAL: Convert all the class-name-based settings in this query to actual class-based settings This method is implemented by subclasses as necessary.

param
classLoader

        // note: normally we would fix the argument types here, but they are already
        // lazily instantiated
    
public voiddeploymentSetShouldMaintainCache(int maintainCache)
INTERNAL: Added for backwards compatibility. shouldMaintainCache used to be tri-state and was converted to boolean. This method is used by deployment XML to properly convert the tri-state variable to a boolean Added for Bug 4034159

        // FalseUndefinedTrue.Undefined is intentionally left ignored so it will map to the default.
        if (maintainCache == FalseUndefinedTrue.True) {
            setShouldMaintainCache(true);
        } else if (maintainCache == FalseUndefinedTrue.False) {
            setShouldMaintainCache(false);
        }
    
public intdeploymentShouldMaintainCache()
INTERNAL: Added for backwards compatibility. shouldMaintainCache used to be tri-state and was converted to boolean. This method is used by deployment XML to properly convert the tri-state variable to a boolean Added for Bug 4034159

        if (shouldMaintainCache()) {
            return FalseUndefinedTrue.True;
        } else {
            return FalseUndefinedTrue.False;
        }
    
public voiddontBindAllParameters()
PUBLIC: Do not Bind all arguments to any SQL statement.

        setShouldBindAllParameters(false);
    
public voiddontCacheStatement()
PUBLIC: Dont cache the prepared statements, this requires full parameter binding as well.

        setShouldCacheStatement(false);
    
public voiddontCascadeParts()
PUBLIC: Do not cascade the query and its properties on the queries object(s) relationships. This does not effect the queries private parts but only the object(s) direct row-level attributes. This is the default for read queries and can be used in writting if it is known that only row-level attributes changed, or to resolve circular foreign key dependencies.

        setCascadePolicy(NoCascading);
    
public voiddontMaintainCache()
PUBLIC: Set for the identity map (cache) to be ignored completely. The cache check will be skipped and the result will not be put into the identity map. This can be used to retreive the exact state of an object on the database. By default the identity map is always maintained.

        setShouldMaintainCache(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.

        DatabaseQuery queryToExecute = this;

        // Profile the query preparation time.
        session.startOperationProfile(SessionProfiler.QUERY_PREPARE);

        // This allows the query to check the cache or return early without doing any work.
        Object earlyReturn = queryToExecute.checkEarlyReturn(session, translationRow);
        if ((earlyReturn != null) || (isReadObjectQuery() && ((ReadObjectQuery)this).shouldCheckCacheOnly())) {
            // Profile the query preparation time.
            session.endOperationProfile(SessionProfiler.QUERY_PREPARE);
            return earlyReturn;
        }

        boolean hasCustomQuery = false;
        if (!isPrepared() && shouldPrepare()) {
            // Prepared queries cannot be custom as then they would never have been prepared.
            DatabaseQuery customQuery = checkForCustomQuery(session, translationRow);
            if (customQuery != null) {
                hasCustomQuery = true;
                // The custom query will be used not the original.
                queryToExecute = customQuery;
            }
        }

        // Sometimes a session will clone the query and mutate the clone.  If so
        // don't need to clone again.
        // All queries on a HistoricalSession become historical queries.
        // On a ServerSession bean-level pessimistic locking queries need to 
        // be replaced with non-locking versions.
        boolean alreadyClonedQuery = false;
        DatabaseQuery sessionPreparedQuery = session.prepareDatabaseQuery(queryToExecute);
        if (sessionPreparedQuery != queryToExecute) {
            queryToExecute = sessionPreparedQuery;
            alreadyClonedQuery = true;
        }

        if (queryToExecute.shouldPrepare()) {
            queryToExecute.checkPrepare(session, translationRow);
        }

        // Then cloned for concurrency and repeatable execution.
        if (!alreadyClonedQuery) {
            queryToExecute = (DatabaseQuery)queryToExecute.clone();
        }
        queryToExecute.setTranslationRow(translationRow);
        // If the prepare has been disbale the clone is prepare dynamically to not parameterize the SQL.
        if (!queryToExecute.shouldPrepare()) {
            queryToExecute.checkPrepare(session, translationRow);
        }
        queryToExecute.setSession(session);
        if (hasCustomQuery) {
            prepareCustomQuery(queryToExecute);
        }
        queryToExecute.prepareForExecution();

        // Profile the query preparation time.
        session.endOperationProfile(SessionProfiler.QUERY_PREPARE);

        // Then executed.
        Object result = queryToExecute.executeDatabaseQuery();

        //give the subclasses the oportunity to retreive aspects of the cloned query
        clonedQueryExecutionComplete(queryToExecute, session);
        return result;
    
public abstract java.lang.ObjectexecuteDatabaseQuery()
INTERNAL: Execute the query

exception
DatabaseException - an error has occurred on the database.
exception
OptimisticLockException - an error has occurred using the optimistic lock feature.
return
- the result of executing the query.

public java.lang.ObjectexecuteInUnitOfWork(oracle.toplink.essentials.internal.sessions.UnitOfWorkImpl unitOfWork, oracle.toplink.essentials.internal.sessions.AbstractRecord translationRow)
INTERNAL: Override query execution where Session is a UnitOfWork.

If there are objects in the cache return the results of the cache lookup.

param
unitOfWork - the session in which the receiver will be executed.
param
translationRow - the arguments
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.

        return execute(unitOfWork, translationRow);
    
public oracle.toplink.essentials.internal.databaseaccess.AccessorgetAccessor()
INTERNAL: Return the accessor.

        return accessor;
    
public java.util.VectorgetArgumentTypeNames()
INTERNAL: Return the argumentTypeNames for use with the pre-defined query option These are used pre-initialization to construct the argumentTypes list.

        if (argumentTypeNames == null) {
            argumentTypeNames = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance();
        }
        return argumentTypeNames;
    
public java.util.VectorgetArgumentTypes()
INTERNAL: Return the argumentTypes for use with the pre-defined query option

        if ((argumentTypes == null) || argumentTypes.isEmpty()) {
            argumentTypes = new Vector();
            // Bug 3256198 - lazily initialize the argument types from their class names
            if (argumentTypeNames != null) {
                Iterator args = argumentTypeNames.iterator();
                while (args.hasNext()) {
                    String argumentTypeName = (String)args.next();
                    argumentTypes.addElement(Helper.getObjectClass(ConversionManager.loadClass(argumentTypeName)));
                }
            }
        }
        return argumentTypes;
    
public java.util.VectorgetArgumentValues()
INTERNAL: Return the argumentValues for use with the pre-defined query option

        if (argumentValues == null) {
            argumentValues = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance();
        }
        return argumentValues;
    
public java.util.VectorgetArguments()
INTERNAL: Return the arguments for use with the pre-defined query option

        if (arguments == null) {
            arguments = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance();
        }
        return arguments;
    
public oracle.toplink.essentials.internal.databaseaccess.DatabaseCallgetCall()
INTERNAL: Return the call for this query. This call contains the SQL and argument list.

see
#getDatasourceCall()

        Call call = getDatasourceCall();
        if (call instanceof DatabaseCall) {
            return (DatabaseCall)call;
        } else {
            return null;
        }
    
public intgetCascadePolicy()
INTERNAL: Return the cascade policy.

        return cascadePolicy;
    
public oracle.toplink.essentials.queryframework.CallgetDatasourceCall()
ADVANCED: Return the call for this query. This call contains the SQL and argument list.

see
#prepareCall(Session, DatabaseRow);

        Call call = null;
        if (getQueryMechanism() instanceof DatasourceCallQueryMechanism) {
            DatasourceCallQueryMechanism mechanism = (DatasourceCallQueryMechanism)getQueryMechanism();
            call = mechanism.getCall();
            // If has multiple calls return the first one.
            if (mechanism.hasMultipleCalls()) {
                call = (Call)mechanism.getCalls().get(0);
            }
        }
        if ((call == null) && getQueryMechanism().isEJBQLCallQueryMechanism()) {
            call = ((EJBQLCallQueryMechanism)getQueryMechanism()).getEJBQLCall();
        }
        return call;
    
public java.util.ListgetDatasourceCalls()
ADVANCED: Return the calls for this query. This method can be called for queries with multiple calls This call contains the SQL and argument list.

see
#prepareCall(Session, DatabaseRow);

        List calls = new Vector();
        if (getQueryMechanism() instanceof DatasourceCallQueryMechanism) {
            DatasourceCallQueryMechanism mechanism = (DatasourceCallQueryMechanism)getQueryMechanism();

            // If has multiple calls return the first one.
            if (mechanism.hasMultipleCalls()) {
                calls = mechanism.getCalls();
            } else {
                calls.add(mechanism.getCall());
            }
        }
        if ((calls.isEmpty()) && getQueryMechanism().isEJBQLCallQueryMechanism()) {
            calls.add(((EJBQLCallQueryMechanism)getQueryMechanism()).getEJBQLCall());
        }
        return calls;
    
public oracle.toplink.essentials.descriptors.ClassDescriptorgetDescriptor()
INTERNAL: Return the descriptor assigned with the reference class

        return descriptor;
    
public java.lang.StringgetEJBQLString()
PUBLIC: Return the SQL string of the query. This can be used for SQL queries. ADVANCED: This can also be used for normal queries if they have been prepared, (i.e. query.prepareCall()).

see
#prepareCall(Session, DatabaseRow)

        if (!(getQueryMechanism().isEJBQLCallQueryMechanism())) {
            return null;
        }
        EJBQLCall call = (EJBQLCall)((EJBQLCallQueryMechanism)getQueryMechanism()).getEJBQLCall();
        return call.getEjbqlString();
    
public java.lang.BooleangetFlushOnExecute()
PUBLIC: If executed against a RepeatableWriteUnitOfWork if this attribute is true TopLink will write changes to the database before executing the query.

        return this.flushOnExecute;
    
public java.lang.StringgetName()
PUBLIC: Return the name of the query

        return name;
    
public java.util.HashtablegetProperties()
INTERNAL: Property support for use by mappings.

        if (properties == null) {//Lazy initialize to conserve space and allocation time.
            properties = new Hashtable(5);
        }
        return properties;
    
public synchronized java.lang.ObjectgetProperty(java.lang.Object property)
INTERNAL: Property support used by mappings to stach temporary stuff in the query.

        if (properties == null) {
            return null;
        }
        return getProperties().get(property);
    
public oracle.toplink.essentials.internal.queryframework.DatabaseQueryMechanismgetQueryMechanism()
INTERNAL: Return the mechanism assigned to the query

        // Bug 3524620 - lazy init
        if (queryMechanism == null) {
            queryMechanism = new ExpressionQueryMechanism(this);
        }
        return queryMechanism;
    
public java.lang.ClassgetReferenceClass()
PUBLIC: Return the domain class associated with this query. By default this is null, but should be overridden in subclasses.

        return null;
    
public java.lang.StringgetReferenceClassName()
INTERNAL: return the name of the reference class. Added for Mapping Workbench removal of classpath dependancy. Overriden by subclasses.

        return null;
    
public oracle.toplink.essentials.internal.expressions.SQLStatementgetSQLStatement()
PUBLIC: Return the SQL statement of the query. This can only be used with statement queries.

        return ((StatementQueryMechanism)getQueryMechanism()).getSQLStatement();
    
public java.lang.StringgetSQLString()
PUBLIC: Return the SQL string of the query. This can be used for SQL queries. ADVANCED: This can also be used for normal queries if they have been prepared, (i.e. query.prepareCall()).

see
#prepareCall(Session, DatabaseRow)

        Call call = getDatasourceCall();
        if (call == null) {
            return null;
        }
        if (!(call instanceof SQLCall)) {
            return null;
        }

        return ((SQLCall)call).getSQLString();
    
public java.util.ListgetSQLStrings()
PUBLIC: Return the SQL strings of the query. Used for queries with multiple calls This can be used for SQL queries. ADVANCED: This can also be used for normal queries if they have been prepared, (i.e. query.prepareCall()).

see
#prepareCall(Session, DatabaseRow)

        List calls = getDatasourceCalls();
        if ((calls == null) || calls.isEmpty()) {
            return null;
        }
        Vector returnSQL = new Vector(calls.size());
        Iterator iterator = calls.iterator();
        while (iterator.hasNext()) {
            Call call = (Call)iterator.next();
            if (!(call instanceof SQLCall)) {
                return null;
            }
            returnSQL.addElement(((SQLCall)call).getSQLString());
        }
        return returnSQL;
    
public oracle.toplink.essentials.expressions.ExpressiongetSelectionCriteria()
PUBLIC: Return the selection criteria of the query. This should only be used with expression queries, null will be returned for others.

        return getQueryMechanism().getSelectionCriteria();
    
public oracle.toplink.essentials.internal.sessions.AbstractSessiongetSession()
INTERNAL: Return the current session.

        return session;
    
public java.lang.StringgetSessionName()
PUBLIC: Return the name of the session that the query should be executed under. This can be with the session broker to override the default session.

        return sessionName;
    
public intgetShouldBindAllParameters()
INTERNAL: Returns the internal tri-state calue of shouldBindParameters used far cascading these settings

        return this.shouldBindAllParameters;
    
public java.lang.StringgetTranslatedSQLString(oracle.toplink.essentials.sessions.Session session, oracle.toplink.essentials.sessions.Record translationRow)
ADVANCED: This can be used to access a queries translated SQL if they have been prepared, (i.e. query.prepareCall()). The Record argument is one of (DatabaseRow, XMLRecord) that contains the query arguments.

see
#prepareCall(oracle.toplink.essentials.sessions.Session, Record)

        //CR#2859559 fix to use Session and Record interfaces not impl classes.
        CallQueryMechanism queryMechanism = (CallQueryMechanism)getQueryMechanism();
        if (queryMechanism.getCall() == null) {
            return null;
        }
        SQLCall call = (SQLCall)queryMechanism.getCall().clone();
        call.translate((AbstractRecord)translationRow, queryMechanism.getModifyRow(), (AbstractSession)session);
        return call.getSQLString();
    
public java.util.ListgetTranslatedSQLStrings(oracle.toplink.essentials.sessions.Session session, oracle.toplink.essentials.sessions.Record translationRow)
ADVANCED: This can be used to access a queries translated SQL if they have been prepared, (i.e. query.prepareCall()). This method can be used for queries with multiple calls.

see
#prepareCall(Session, DatabaseRow)

        CallQueryMechanism queryMechanism = (CallQueryMechanism)getQueryMechanism();
        if ((queryMechanism.getCalls() == null) || queryMechanism.getCalls().isEmpty()) {
            return null;
        }
        Vector calls = new Vector(queryMechanism.getCalls().size());
        Iterator iterator = queryMechanism.getCalls().iterator();
        while (iterator.hasNext()) {
            SQLCall call = (SQLCall)iterator.next();
            call = (SQLCall)call.clone();
            call.translate((AbstractRecord)translationRow, queryMechanism.getModifyRow(), (AbstractSession)session);
            calls.addElement(call.getSQLString());
        }
        return calls;
    
public oracle.toplink.essentials.internal.sessions.AbstractRecordgetTranslationRow()
INTERNAL: Return the row for translation

        return translationRow;
    
public booleanhasAccessor()
INTERNAL: returns true if the accessor has already been set. The getAccessor() will attempt to lazily initialzie it.

        return accessor != null;
    
public booleanhasProperties()
INTERNAL: Return if any properties exist in the query.

        return (properties != null) && (!properties.isEmpty());
    
public booleanhasQueryMechanism()
INTERNAL: Check if the mechanism has been set yet, used for lazy init.

        return (queryMechanism != null);
    
public booleanhasSessionName()
PUBLIC: Return if a name of the session that the query should be executed under has been specified. This can be with the session broker to override the default session.

        return sessionName != null;
    
public voidignoreBindAllParameters()
PUBLIC: Session's shouldBindAllParameters() defines whether to bind or not (default setting)

        this.shouldBindAllParameters = Undefined;
    
public voidignoreCacheStatement()
PUBLIC: Session's shouldCacheAllStatements() defines whether to cache or not (default setting)

        this.shouldCacheStatement = Undefined;
    
public booleanisCallQuery()
PUBLIC: Return true if this query uses an SQL or stored procedure, or SDK call.

        return getQueryMechanism().isCallQueryMechanism();
    
public booleanisCascadeOfAggregateDelete()
INTERNAL: Returns true if this query has been created as the result of cascading a delete of an aggregate collection in a UnitOfWork CR 2811

        return getCascadePolicy() == CascadeAggregateDelete;
    
public booleanisDataModifyQuery()
PUBLIC: Return if this is a data modify query.

        return false;
    
public booleanisDataReadQuery()
PUBLIC: Return if this is a data read query.

        return false;
    
public booleanisDeleteAllQuery()
PUBLIC: Return if this is a delete all query.

        return false;
    
public booleanisDeleteObjectQuery()
PUBLIC: Return if this is a delete object query.

        return false;
    
public booleanisExpressionQuery()
PUBLIC: Return true if this query uses an expression query mechanism

        return getQueryMechanism().isExpressionQueryMechanism();
    
public booleanisInsertObjectQuery()
PUBLIC: Return true if this is an insert object query.

        return false;
    
public booleanisModifyAllQuery()
PUBLIC: Return true if this is a modify all query.

        return false;
    
public booleanisModifyQuery()
PUBLIC: Return true if this is a modify query.

        return false;
    
public booleanisObjectBuildingQuery()
PUBLIC: Return if this is an object building query.

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

        return false;
    
public booleanisObjectLevelReadQuery()
PUBLIC: Return true if this is an object level read query.

        return false;
    
public booleanisPrepared()
INTERNAL: Queries are prepared when they are executed and then do not need to be prepared on subsequent executions. This method returns true if this query has been prepared. Updating the settings on a query will 'un-prepare' the query.

        return isPrepared;
    
public booleanisReadAllQuery()
PUBLIC: Return true if this is a read all query.

        return false;
    
public booleanisReadObjectQuery()
PUBLIC: Return ture if this is a read object query.

        return false;
    
public booleanisReadQuery()
PUBLIC: Return true if this is a read query.

        return false;
    
public booleanisReportQuery()
PUBLIC: Return true if this is a report query.

        return false;
    
public booleanisSQLCallQuery()
PUBLIC: Return true if this query uses an SQL query mechanism .

        // BUG#2669342 CallQueryMechanism and isCallQueryMechanism have different meaning as SDK return true but isn't.
        Call call = getDatasourceCall();
        return (call != null) && (call instanceof SQLCall);
    
public booleanisUpdateAllQuery()
PUBLIC: Return true if this is an update all query.

        return false;
    
public booleanisUpdateObjectQuery()
PUBLIC: Return true if this is an update object query.

        return false;
    
public booleanisUserDefined()
INTERNAL: Return true if the query is a custom user defined query.

        return isUserDefined;
    
public booleanisWriteObjectQuery()
PUBLIC: Return true if this is a write object query.

        return false;
    
public voidmaintainCache()
PUBLIC: Set for the identity map (cache) to be maintained. This is the default.

        setShouldMaintainCache(true);
    
protected voidprepare()
INTERNAL: This is different from 'prepareForExecution' in that this is called on the original query, and the other is called on the copy of the query. This query is copied for concurrency so this prepare can only setup things that will apply to any future execution of this query. Resolve the queryTimeout using the DescriptorQueryManager if required.

         getQueryMechanism().prepare();
    
public voidprepareCall(oracle.toplink.essentials.sessions.Session session, oracle.toplink.essentials.sessions.Record translationRow)
ADVANCED: Pre-generate the call/SQL for the query. This method takes a Session and an implementor of Record (DatebaseRow or XMLRecord). This can be used to access the SQL for a query without executing it. To access the call use, query.getCall(), or query.getSQLString() for the SQL. Note the SQL will have argument markers in it (i.e. "?"). To translate these use query.getTranslatedSQLString(session, translationRow).

see
#getCall()
see
#getSQLString()
see
#getTranslatedSQLString(oracle.toplink.essentials.sessions.Session, Record)

        //CR#2859559 fix to use Session and Record interfaces not impl classes.
        checkPrepare((AbstractSession)session, (AbstractRecord)translationRow);
    
protected voidprepareCustomQuery(oracle.toplink.essentials.queryframework.DatabaseQuery customQuery)
INTERNAL: Set the properties needed to be cascaded into the custom query.

        // Nothing by default.
    
public voidprepareForExecution()
INTERNAL: Prepare the receiver for execution in a session. In particular, set the descriptor of the receiver to the Descriptor for the appropriate class for the receiver's object.

        getQueryMechanism().prepareForExecution();
    
protected voidprepareForRemoteExecution()

        ;
    
public voidremoveProperty(java.lang.Object property)
INTERNAL: Property support used by mappings.

        getProperties().remove(property);
    
public oracle.toplink.essentials.internal.sessions.AbstractRecordrowFromArguments(java.util.Vector argumentValues)
INTERNAL: Translate argumentValues into a database row.

        Vector argumentNames = getArguments();

        if (argumentNames.size() != argumentValues.size()) {
            throw QueryException.argumentSizeMismatchInQueryAndQueryDefinition(this);
        }

        AbstractRecord row = new DatabaseRecord();
        for (int index = 0; index < argumentNames.size(); index++) {
            String argumentName = (String)argumentNames.elementAt(index);
            Object argumentValue = argumentValues.elementAt(index);
            row.put(new DatabaseField(argumentName), argumentValue);
        }

        return row;
    
public voidsetAccessor(oracle.toplink.essentials.internal.databaseaccess.Accessor accessor)
INTERNAL: Set the accessor, the query must always use the same accessor for database access. This is required to support connection pooling.

        this.accessor = accessor;
    
public voidsetArgumentTypeNames(java.util.Vector argumentTypeNames)
INTERNAL: Set the argumentTypes for use with the pre-defined query option

        this.argumentTypeNames = argumentTypeNames;
    
public voidsetArgumentTypes(java.util.Vector argumentTypes)
INTERNAL: Set the argumentTypes for use with the pre-defined query option

        this.argumentTypes = argumentTypes;
        // bug 3256198 - ensure the list of type names matches the argument types.
        getArgumentTypeNames().clear();
        Iterator types = argumentTypes.iterator();
        while (types.hasNext()) {
            argumentTypeNames.addElement(((Class)types.next()).getName());
        }
    
public voidsetArgumentValues(java.util.Vector theArgumentValues)
INTERNAL: Return the argumentValues for use with the pre-defined query option

        argumentValues = theArgumentValues;
    
public voidsetArguments(java.util.Vector arguments)
INTERNAL: Set the arguments for use with the pre-defined query option. Maintain the argumentTypes as well.

        for (Enumeration enumtr = arguments.elements(); enumtr.hasMoreElements();) {
            // Maintain the argumentTypes as well
            addArgument((String)enumtr.nextElement());
        }
    
public voidsetCall(oracle.toplink.essentials.queryframework.Call call)
PUBLIC: Used to define a store procedure or SQL query.

        setDatasourceCall(call);
    
public voidsetCascadePolicy(int policyConstant)
INTERNAL: Set the cascade policy.

        cascadePolicy = policyConstant;
    
public voidsetDatasourceCall(oracle.toplink.essentials.queryframework.Call call)
PUBLIC: Used to define a store procedure or SQL query.

        if (call == null) {
            return;
        }
        setQueryMechanism(call.buildNewQueryMechanism(this));
    
public voidsetDescriptor(oracle.toplink.essentials.descriptors.ClassDescriptor descriptor)
INTERNAL: Set the descriptor for the query.

        // If the descriptor changed must unprepare as the SQL may change.
        if (this.descriptor != descriptor) {
            setIsPrepared(false);
        }
        this.descriptor = descriptor;
    
public voidsetEJBQLString(java.lang.String ejbqlString)
PUBLIC: To any user of this object. Set the EJBQL string of the query. If arguments are required in the string they will be preceeded by "?" then the argument number.

        //Added the check for when we are building the query from the deployment XML
        if ((ejbqlString != null) && (!ejbqlString.equals(""))) {
            EJBQLCallQueryMechanism mechanism = new EJBQLCallQueryMechanism(this, new EJBQLCall(ejbqlString));
            setQueryMechanism(mechanism);
        }
    
public voidsetFlushOnExecute(java.lang.Boolean flushMode)
PUBLIC: If executed against a RepeatableWriteUnitOfWork if this attribute is true TopLink will write changes to the database before executing the query.

        this.flushOnExecute = flushMode;
    
public voidsetIsPrepared(boolean isPrepared)
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.

        this.isPrepared = isPrepared;
    
public voidsetIsUserDefined(boolean isUserDefined)
INTERNAL: Set if the query is a custom user defined query.

        this.isUserDefined = isUserDefined;
    
public voidsetName(java.lang.String queryName)
PUBLIC: Set the query's name. Queries can be named and added to a descriptor or the session and then referenced by name.

        name = queryName;
    
public voidsetProperties(java.util.Hashtable properties)
INTERNAL: Property support used by mappings.

        this.properties = properties;
    
public synchronized voidsetProperty(java.lang.Object property, java.lang.Object value)
INTERNAL: Property support used by mappings to stache temporary stuff.

        getProperties().put(property, value);
    
protected voidsetQueryMechanism(oracle.toplink.essentials.internal.queryframework.DatabaseQueryMechanism queryMechanism)
Set the query mechanism for the query.

        this.queryMechanism = queryMechanism;
        // Must un-prepare is prepare as the SQL may change.
        setIsPrepared(false);
    
public voidsetSQLStatement(oracle.toplink.essentials.internal.expressions.SQLStatement sqlStatement)
PUBLIC: To any user of this object. Set the SQL statement of the query. This method should only be used when dealing with statement objects.

        setQueryMechanism(new StatementQueryMechanism(this, sqlStatement));
    
public voidsetSQLString(java.lang.String sqlString)
PUBLIC: To any user of this object. Set the SQL string of the query. This method should only be used when dealing with user defined SQL strings. If arguments are required in the string they will be preceeded by "#" then the argument name.

        //Added the check for when we are building the query from the deployment XML
        if ((sqlString != null) && (!sqlString.equals(""))) {
            setCall(new SQLCall(sqlString));
        }
    
public voidsetSelectionCriteria(oracle.toplink.essentials.expressions.Expression expression)
PUBLIC: To any user of this object. Set the selection criteria of the query. This method be used when dealing with expressions.

        // Do not overwrite the call if the expression is null.
        if ((expression == null) && (!getQueryMechanism().isExpressionQueryMechanism())) {
            return;
        }
        if (!getQueryMechanism().isExpressionQueryMechanism()) {
            setQueryMechanism(new ExpressionQueryMechanism(this, expression));
        } else {
            ((ExpressionQueryMechanism)getQueryMechanism()).setSelectionCriteria(expression);
        }

        // Must un-prepare is prepare as the SQL may change.
        setIsPrepared(false);
    
public voidsetSession(oracle.toplink.essentials.internal.sessions.AbstractSession session)
INTERNAL: Set the session for the query

        this.session = session;
    
public voidsetSessionName(java.lang.String sessionName)
PUBLIC: Set the name of the session that the query should be executed under. This can be with the session broker to override the default session.

        this.sessionName = sessionName;
    
public voidsetShouldBindAllParameters(boolean shouldBindAllParameters)
PUBLIC: Bind all arguments to any SQL statement.

        if (shouldBindAllParameters) {
            this.shouldBindAllParameters = True;
        } else {
            this.shouldBindAllParameters = False;
        }
        setIsPrepared(false);
    
public voidsetShouldBindAllParameters(int bindAllParams)
INTERNAL: Sets the internal tri-state value of shouldBindAllParams Used to cascade this value to alther queries

        this.shouldBindAllParameters = bindAllParams;
    
public voidsetShouldCacheStatement(boolean shouldCacheStatement)
PUBLIC: Cache the prepared statements, this requires full parameter binding as well.

        if (shouldCacheStatement) {
            this.shouldCacheStatement = True;
        } else {
            this.shouldCacheStatement = False;
        }
        setIsPrepared(false);
    
public voidsetShouldMaintainCache(boolean shouldMaintainCache)
PUBLIC: Set if the identity map (cache) should be used or not. If not the cache check will be skipped and the result will not be put into the identity map. By default the identity map is always maintained.

        this.shouldMaintainCache = shouldMaintainCache;
    
public voidsetShouldPrepare(boolean shouldPrepare)
PUBLIC: Set if the query should be prepared. TopLink automatically prepares queries to generate their SQL only once, one each execution of the query the SQL does not need to be generated again only the arguments need to be translated. This option is provide to disable this optimization as in can cause problems with certain types of queries that require dynamic SQL basd on their arguments.

These queries include:

  • Expressions that make use of 'equal' where the argument value has the potential to be null, this can cause problems on databases that require IS NULL, instead of = NULL.
  • Expressions that make use of 'in' and that use parameter binding, this will cause problems as the in values must be bound individually.

        this.shouldPrepare = shouldPrepare;
        setIsPrepared(false);
    
public voidsetShouldUseWrapperPolicy(boolean shouldUseWrapperPolicy)
ADVANCED: The wrapper policy can be enable on a query.

        this.shouldUseWrapperPolicy = shouldUseWrapperPolicy;
    
public voidsetTranslationRow(oracle.toplink.essentials.internal.sessions.AbstractRecord translationRow)
INTERNAL: Set the row for translation

        this.translationRow = translationRow;
    
public booleanshouldBindAllParameters()
PUBLIC: Bind all arguments to any SQL statement.

        return shouldBindAllParameters == True;
    
public booleanshouldCacheStatement()
PUBLIC: Cache the prepared statements, this requires full parameter binding as well.

        return shouldCacheStatement == True;
    
public booleanshouldCascadeAllParts()
PUBLIC: Flag used to determine if all parts should be cascaded

        return getCascadePolicy() == CascadeAllParts;
    
public booleanshouldCascadeByMapping()
PUBLIC: Mappings should be checked to determined if the current operation should be cascaded to the objects referenced.

        return getCascadePolicy() == CascadeByMapping;
    
public booleanshouldCascadeOnlyDependentParts()
INTERNAL: Flag used for unit of works cascade policy.

        return getCascadePolicy() == CascadeDependentParts;
    
public booleanshouldCascadeParts()
PUBLIC: Flag used to determine if any parts should be cascaded

        return getCascadePolicy() != NoCascading;
    
public booleanshouldCascadePrivateParts()
PUBLIC: Flag used to determine if any private parts should be cascaded

        return (getCascadePolicy() == CascadePrivateParts) || (getCascadePolicy() == CascadeAllParts);
    
public booleanshouldCloneCall()
INTERNAL: Flag used to determine if the call needs to be cloned.

        return shouldCloneCall;
    
public booleanshouldIgnoreBindAllParameters()
PUBLIC: Local shouldBindAllParameters() should be ignored, Session's shouldBindAllParameters() should be used.

        return shouldBindAllParameters == Undefined;
    
public booleanshouldIgnoreCacheStatement()
PUBLIC: Local shouldCacheStatement() should be ignored, Session's shouldCacheAllStatements() should be used.

        return shouldCacheStatement == Undefined;
    
public booleanshouldMaintainCache()
PUBLIC: Return if the identity map (cache) should be used or not. If not the cache check will be skipped and the result will not be put into the identity map. By default the identity map is always maintained.

        return shouldMaintainCache;
    
public booleanshouldPrepare()
PUBLIC: Return if the query should be prepared. TopLink automatically prepares queries to generate their SQL only once, one each execution of the query the SQL does not need to be generated again only the arguments need to be translated. This option is provide to disable this optimization as in can cause problems with certain types of queries that require dynamic SQL basd on their arguments.

These queries include:

  • Expressions that make use of 'equal' where the argument value has the potential to be null, this can cause problems on databases that require IS NULL, instead of = NULL.
  • Expressions that make use of 'in' and that use parameter binding, this will cause problems as the in values must be bound individually.

        return shouldPrepare;
    
public booleanshouldUseWrapperPolicy()
ADVANCED: The wrapper policy can be enabled on a query.

        return shouldUseWrapperPolicy;
    
public java.lang.StringtoString()

        return Helper.getShortClassName(getClass()) + "()";