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

DataReadQuery

public class DataReadQuery extends ReadQuery

Purpose: Concrete class to perform read using raw SQL.

Responsibilities: Execute a selecting raw SQL string. This returns a Collection of the DatabaseRows representing the result set.

author
Yvon Lavoie
since
TOPLink/Java 1.0

Fields Summary
protected ContainerPolicy
containerPolicy
protected boolean
useAbstractRecord
Constructors Summary
public DataReadQuery()
PUBLIC: Initialize the state of the query.


                
      
        super();
        this.shouldMaintainCache = false;
        useAbstractRecord = true;
        setContainerPolicy(ContainerPolicy.buildPolicyFor(ClassConstants.Vector_class));
    
public DataReadQuery(String sqlString)
PUBLIC: Initialize the query to use the specified SQL string.

        this();
        setSQLString(sqlString);
    
public DataReadQuery(Call call)
PUBLIC: Initialize the query to use the specified call.

        this();
        setCall(call);
    
Methods Summary
public java.lang.Objectclone()
INTERNAL: Clone the query.

        DataReadQuery cloneQuery = (DataReadQuery)super.clone();
        cloneQuery.setContainerPolicy(getContainerPolicy().clone(cloneQuery));
        return cloneQuery;
    
public java.lang.ObjectexecuteDatabaseQuery()
INTERNAL: Execute the query. Perform the work to execute the SQL string.

exception
DatabaseException an error has occurred on the database
return
a collection or cursor of DatabaseRows representing the result set

        if (getContainerPolicy().overridesRead()) {
            return getContainerPolicy().execute();
        }
        return executeNonCursor();
    
protected java.lang.ObjectexecuteNonCursor()
INTERNAL: The results are *not* in a cursor, build the collection.

        Vector rows = getQueryMechanism().executeSelect();
        if (useAbstractRecord ){
            Object results = getContainerPolicy().buildContainerFromVector(rows, getSession());
            return results;
        }
        ContainerPolicy containerPolicy = getContainerPolicy();
        Object reportResults = containerPolicy.containerInstance(rows.size());
        for (Iterator rowsEnum = rows.iterator(); rowsEnum.hasNext();) {
            containerPolicy.addInto( ((AbstractRecord)rowsEnum.next()).getValues()  , reportResults, getSession());
        }
        return reportResults;
    
public oracle.toplink.essentials.internal.queryframework.ContainerPolicygetContainerPolicy()
PUBLIC: Return the query's ContainerPolicy.

return
oracle.toplink.essentials.internal.queryframework.ContainerPolicy

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

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

        super.prepare();
        getContainerPolicy().prepare(this, getSession());
        if (getContainerPolicy().overridesRead()) {
            return;
        }
        getQueryMechanism().prepareExecuteSelect();
    
public voidprepareForExecution()
INTERNAL: Prepare the receiver for execution in a session.

        super.prepareForExecution();
        getContainerPolicy().prepareForExecution();
    
public voidsetContainerPolicy(oracle.toplink.essentials.internal.queryframework.ContainerPolicy containerPolicy)
PUBLIC: Set the container policy.

        // Fix for BUG 3337003 - TopLink OX will try to set this to null if
        // it is not set in the deployment XML. So don't allow it to do that.
        if (containerPolicy == null) {
            return;
        }

        this.containerPolicy = containerPolicy;
    
public voidsetUseAbstractRecord(boolean useAbstractRecord)
INTERNAL: Allow changing the default behaviour so that AbstractRecords are not returned as query results.

        this.useAbstractRecord = useAbstractRecord;
    
public voiduseCollectionClass(java.lang.Class concreteClass)
PUBLIC: Configure the query to use an instance of the specified container class to hold the target objects. The container class must implement (directly or indirectly) the Collection interface.

        setContainerPolicy(ContainerPolicy.buildPolicyFor(concreteClass));