Oracle Fusion Middleware Java API Reference for Oracle TopLink
11g Release 1 (11.1.1)

B32476-03

oracle.toplink.queryframework
Class ReadAllQuery

java.lang.Object
  extended by oracle.toplink.queryframework.DatabaseQuery
      extended by oracle.toplink.queryframework.ReadQuery
          extended by oracle.toplink.queryframework.ObjectBuildingQuery
              extended by oracle.toplink.queryframework.ObjectLevelReadQuery
                  extended by oracle.toplink.queryframework.ReadAllQuery
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, oracle.toplink.internal.helper.FalseUndefinedTrue
Direct Known Subclasses:
ReportQuery

public class ReadAllQuery
extends ObjectLevelReadQuery

Purpose: Concrete class for all read queries involving a collection of objects.

Responsibilities: Return a container of the objects generated by the query. Implements the inheritance feature when dealing with abstract descriptors

Since:
TOPLink/Java 1.0
See Also:
Serialized Form

Field Summary
 
Fields inherited from class oracle.toplink.queryframework.ObjectLevelReadQuery
CheckCacheByExactPrimaryKey, CheckCacheByPrimaryKey, CheckCacheOnly, CheckCacheThenDatabase, ConformResultsInUnitOfWork, DoNotCheckCache, DONT_USE_DISTINCT, UNCOMPUTED_DISTINCT, USE_DISTINCT, UseDescriptorSetting
 
Fields inherited from class oracle.toplink.queryframework.ObjectBuildingQuery
DEFAULT_LOCK_MODE, LOCK, LOCK_NOWAIT, NO_LOCK
 
Fields inherited from class oracle.toplink.queryframework.DatabaseQuery
CascadeAggregateDelete, CascadeAllParts, CascadeByMapping, CascadeDependentParts, CascadePrivateParts, NoCascading
 
Constructor Summary
ReadAllQuery()
          Return a new read all query.
ReadAllQuery(Call call)
          Create a read all query with the database call.
ReadAllQuery(java.lang.Class classToRead)
          Return a new read all query.
ReadAllQuery(java.lang.Class classToRead, Call call)
          Return a new read all query.
ReadAllQuery(java.lang.Class classToRead, Expression selectionCriteria)
          Return a new read all query for the class and the selection criteria.
ReadAllQuery(java.lang.Class classToRead, ExpressionBuilder builder)
          Return a new read all query for the class.
ReadAllQuery(ExpressionBuilder builder)
          The expression builder should be provide on creation to ensure only one is used.
ReadAllQuery(java.lang.Object exampleObject, QueryByExamplePolicy policy)
          Return a query by example query to find all objects matching the attributes of the example object.
 
Method Summary
 void addAscendingOrdering(java.lang.String queryKeyName)
          Order the query results by the object's attribute or query key name.
 void addBatchReadAttribute(Expression attributeExpression)
          Specify the foreign-reference mapped attribute to be optimized in this query.
 void addBatchReadAttribute(java.lang.String attributeName)
          Specify the foreign-reference mapped attribute to be optimized in this query.
 void addDescendingOrdering(java.lang.String queryKeyName)
          Order the query results by the object's attribute or query key name.
 void addOrdering(Expression orderingExpression)
          Add the ordering expression.
 Expression getConnectByExpression()
          
 java.util.Vector getOrderSiblingsByExpressions()
          
 Expression getStartWithExpression()
          
 boolean isReadAllQuery()
          Return if this is a read all query.
 void setContainerPolicy(oracle.toplink.internal.queryframework.ContainerPolicy containerPolicy)
          Set the container policy.
 void setHierarchicalQueryClause(Expression startWith, Expression connectBy, java.util.Vector orderSiblingsExpressions)
          Set the Hierarchical Query Clause for the query Example: Expression startWith = builder.get("id").equal(new Integer(100)); //can be any expression which identifies a set of employees Expression connectBy = builder.get("managedEmployees"); //indicated the relationship that the hierarchy is based on, must be self-referential Vector orderBy = new Vector(); orderBy.addElement(builder.get("startDate")); readAllQuery.setHierarchicalQueryClause(startWith, connectBy, orderBy); This query would generate SQL like this: SELECT * FROM EMPLOYEE START WITH ID=100 CONNECT BY PRIOR ID = MANAGER_ID ORDER SIBLINGS BY START_DATE
 void useCollectionClass(java.lang.Class concreteClass)
          Configure the mapping to use an instance of the specified container class to hold the target objects.
 void useCursoredStream()
          Use a CursoredStream as the result collection.
 void useCursoredStream(int initialReadSize, int pageSize)
          Use a CursoredStream as the result collection.
 void useCursoredStream(int initialReadSize, int pageSize, ValueReadQuery sizeQuery)
          Use a CursoredStream as the result collection.
 void useMapClass(java.lang.Class concreteClass, java.lang.String methodName)
          Configure the query to use an instance of the specified container class to hold the result objects.
 void useScrollableCursor()
          Use a ScrollableCursor as the result collection.
 void useScrollableCursor(int pageSize)
          Use a ScrollableCursor as the result collection.
 void useScrollableCursor(ScrollableCursorPolicy policy)
          Use a ScrollableCursor as the result collection.
 
Methods inherited from class oracle.toplink.queryframework.ObjectLevelReadQuery
acquireLocks, acquireLocksWithoutWaiting, addJoinedAttribute, addJoinedAttribute, addNonFetchJoinedAttribute, addNonFetchJoinedAttribute, addPartialAttribute, addPartialAttribute, checkCacheOnly, conformResultsInUnitOfWork, dontAcquireLocks, dontCheckCache, dontRefreshIdentityMapResult, dontRefreshRemoteIdentityMapResult, dontUseDistinct, getAsOfClause, getCacheUsage, getDistinctState, getExampleObject, getExpressionBuilder, getFetchGroup, getFetchGroupName, getInMemoryQueryIndirectionPolicy, getInMemoryQueryIndirectionPolicyState, getLockMode, getQueryByExamplePolicy, getReferenceClass, hasAsOfClause, hasFetchGroup, isLockQuery, isLockQuery, isObjectLevelReadQuery, isReadOnly, isResultSetOptimizedQuery, refreshIdentityMapResult, refreshRemoteIdentityMapResult, resetDistinct, setAsOfClause, setCacheUsage, setDistinctState, setEJBQLString, setExampleObject, setFetchGroup, setFetchGroupName, setInMemoryQueryIndirectionPolicy, setInMemoryQueryIndirectionPolicyState, setIsReadOnly, setIsResultSetOptimizedQuery, setLockMode, setQueryByExamplePolicy, setReferenceClass, setSelectionCriteria, setShouldFilterDuplicates, setShouldOuterJoinSubclasses, setShouldProcessResultsInUnitOfWork, setShouldRefreshIdentityMapResult, setShouldRefreshRemoteIdentityMapResult, setShouldUseDefaultFetchGroup, shouldCheckCacheOnly, shouldCheckDescriptorForCacheUsage, shouldConformResultsInUnitOfWork, shouldFilterDuplicates, shouldOuterJoinSubclasses, shouldProcessResultsInUnitOfWork, shouldRefreshIdentityMapResult, shouldRefreshRemoteIdentityMapResult, shouldUseDefaultFetchGroup, toString, useDistinct
 
Methods inherited from class oracle.toplink.queryframework.ObjectBuildingQuery
isObjectBuildingQuery, setShouldUseExclusiveConnection, shouldUseExclusiveConnection
 
Methods inherited from class oracle.toplink.queryframework.ReadQuery
cacheQueryResults, clearQueryResults, clearQueryResults, doNotCacheQueryResults, getFetchSize, getFirstResult, getMaxRows, getQueryResultsCachePolicy, isReadQuery, setFetchSize, setFirstResult, setMaxRows, setQueryResultsCachePolicy, setShouldCacheQueryResults, shouldCacheQueryResults
 
Methods inherited from class oracle.toplink.queryframework.DatabaseQuery
addArgument, addArgument, addArgument, addArgumentValue, addArgumentValues, addCall, addStatement, bindAllParameters, cacheStatement, cascadeAllParts, cascadeByMapping, cascadePrivateParts, dontBindAllParameters, dontCacheStatement, dontCascadeParts, dontMaintainCache, getCall, getCalls, getDatasourceCall, getDatasourceCalls, getEJBQLString, getFlushOnExecute, getHintString, getJPQLString, getName, getQueryTimeout, getRedirector, getSelectionCriteria, getSessionName, getSQLStatement, getSQLString, getSQLStrings, getTranslatedSQLString, getTranslatedSQLStrings, hasSessionName, ignoreBindAllParameters, ignoreCacheStatement, isCallQuery, isDataModifyQuery, isDataReadQuery, isDeleteAllQuery, isDeleteObjectQuery, isDirectReadQuery, isExpressionQuery, isInsertObjectQuery, isModifyAllQuery, isModifyQuery, isNativeConnectionRequired, isObjectLevelModifyQuery, isReadObjectQuery, isReportQuery, isSQLCallQuery, isUpdateAllQuery, isUpdateObjectQuery, isValueReadQuery, isWriteObjectQuery, maintainCache, prepareCall, setCall, setDatasourceCall, setFlushOnExecute, setHintString, setIsNativeConnectionRequired, setJPQLString, setName, setQueryTimeout, setRedirector, setSessionName, setShouldBindAllParameters, setShouldCacheStatement, setShouldMaintainCache, setShouldPrepare, setShouldUseWrapperPolicy, setSQLStatement, setSQLString, shouldBindAllParameters, shouldCacheStatement, shouldCascadeAllParts, shouldCascadeByMapping, shouldCascadeParts, shouldCascadePrivateParts, shouldIgnoreBindAllParameters, shouldIgnoreCacheStatement, shouldMaintainCache, shouldPrepare, shouldUseWrapperPolicy
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ReadAllQuery

public ReadAllQuery()
Return a new read all query. A reference class must be specified before execution. It is better to provide the class and expression builder on construction to esnure a single expression builder is used. If no selection criteria is specified this will read all objects of the class from the database.


ReadAllQuery

public ReadAllQuery(java.lang.Class classToRead)
Return a new read all query. It is better to provide the class and expression builder on construction to esnure a single expression builder is used. If no selection criteria is specified this will read all objects of the class from the database.


ReadAllQuery

public ReadAllQuery(java.lang.Class classToRead,
                    Expression selectionCriteria)
Return a new read all query for the class and the selection criteria.


ReadAllQuery

public ReadAllQuery(java.lang.Class classToRead,
                    ExpressionBuilder builder)
Return a new read all query for the class. The expression builder must be used for all associated expressions used with the query.


ReadAllQuery

public ReadAllQuery(java.lang.Class classToRead,
                    Call call)
Return a new read all query. The call represents a database interaction such as SQL, Stored Procedure.


ReadAllQuery

public ReadAllQuery(java.lang.Object exampleObject,
                    QueryByExamplePolicy policy)
Return a query by example query to find all objects matching the attributes of the example object.


ReadAllQuery

public ReadAllQuery(ExpressionBuilder builder)
The expression builder should be provide on creation to ensure only one is used.


ReadAllQuery

public ReadAllQuery(Call call)
Create a read all query with the database call.

Method Detail

addAscendingOrdering

public void addAscendingOrdering(java.lang.String queryKeyName)
Order the query results by the object's attribute or query key name.


addBatchReadAttribute

public void addBatchReadAttribute(java.lang.String attributeName)
Specify the foreign-reference mapped attribute to be optimized in this query. The query will execute normally, however when any of the batched parts is accessed, the parts will all be read in a single query, this allows all of the data required for the parts 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 for one-to-one, one-to-many, many-to-many and direct collection mappings. The use of the expression allows for nested batch reading to be expressed.

Example: query.addBatchReadAttribute("phoneNumbers")

See Also:
addBatchReadAttribute(Expression), ObjectLevelReadQuery.addJoinedAttribute(String)

addBatchReadAttribute

public void addBatchReadAttribute(Expression attributeExpression)
Specify the foreign-reference mapped attribute to be optimized in this query. The query will execute normally, however when any of the batched parts is accessed, the parts will all be read in a single query, this allows all of the data required for the parts 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 for one-to-one, one-to-many, many-to-many and direct collection mappings. The use of the expression allows for nested batch reading to be expressed.

Example: query.addBatchReadAttribute(query.getExpressionBuilder().get("policies").get("claims"))

See Also:
ObjectLevelReadQuery.addJoinedAttribute(String)

addDescendingOrdering

public void addDescendingOrdering(java.lang.String queryKeyName)
Order the query results by the object's attribute or query key name.


addOrdering

public void addOrdering(Expression orderingExpression)
Add the ordering expression. This allows for ordering across relationships or functions. Example: readAllQuery.addOrdering(expBuilder.get("address").get("city").toUpperCase().descending())


getStartWithExpression

public Expression getStartWithExpression()

Returns:
Expression - the start with expression used to generated the hierarchical query clause in Oracle

getConnectByExpression

public Expression getConnectByExpression()

Returns:
Expression - the connect by expression used to generate the hierarchical query caluse in Oracle

getOrderSiblingsByExpressions

public java.util.Vector getOrderSiblingsByExpressions()

Returns:
Vector - the ordering expressions used to generate the hierarchical query clause in Oracle

isReadAllQuery

public boolean isReadAllQuery()
Return if this is a read all query.

Overrides:
isReadAllQuery in class DatabaseQuery

setContainerPolicy

public void setContainerPolicy(oracle.toplink.internal.queryframework.ContainerPolicy containerPolicy)
Set the container policy. Used to support different containers (e.g. Collections, Maps).


setHierarchicalQueryClause

public void setHierarchicalQueryClause(Expression startWith,
                                       Expression connectBy,
                                       java.util.Vector orderSiblingsExpressions)
Set the Hierarchical Query Clause for the query

Example:

Expression startWith = builder.get("id").equal(new Integer(100)); //can be any expression which identifies a set of employees

Expression connectBy = builder.get("managedEmployees"); //indicated the relationship that the hierarchy is based on, must be self-referential

Vector orderBy = new Vector();

orderBy.addElement(builder.get("startDate"));

readAllQuery.setHierarchicalQueryClause(startWith, connectBy, orderBy);

This query would generate SQL like this:

SELECT * FROM EMPLOYEE START WITH ID=100 CONNECT BY PRIOR ID = MANAGER_ID ORDER SIBLINGS BY START_DATE

Parameters:
startWith - Describes the START WITH clause of the query - null if not needed
connectBy - This should be a query key expression which indicates an attribute who's mapping describes the hierarchy
orderSiblingsExpressions - Contains expressions which indicate fields to be included in the ORDER SIBLINGS BY clause - null if not required

useCollectionClass

public void useCollectionClass(java.lang.Class concreteClass)
Configure the mapping to use an instance of the specified container class to hold the target objects.

jdk1.2.x: The container class must implement (directly or indirectly) the Collection interface.

jdk1.1.x: The container class must be a subclass of Vector.


useCursoredStream

public void useCursoredStream()
Use a CursoredStream as the result collection. The initial read size is 10 and page size is 5.


useCursoredStream

public void useCursoredStream(int initialReadSize,
                              int pageSize)
Use a CursoredStream as the result collection.

Parameters:
initialReadSize - the initial number of objects to read
pageSize - the number of objects to read when more objects are needed from the database

useCursoredStream

public void useCursoredStream(int initialReadSize,
                              int pageSize,
                              ValueReadQuery sizeQuery)
Use a CursoredStream as the result collection.

Parameters:
initialReadSize - the initial number of objects to read
pageSize - the number of objects to read when more objects are needed from the database
sizeQuery - a query that will return the size of the result set; this must be set if an expression is not used (i.e. custom SQL)

useMapClass

public void useMapClass(java.lang.Class concreteClass,
                        java.lang.String methodName)
Configure the query to use an instance of the specified container class to hold the result objects. The key used to index the value in the Map is the value returned by a call to the specified zero-argument method. The method must be implemented by the class (or a superclass) of the value to be inserted into the Map.

jdk1.2.x: The container class must implement (directly or indirectly) the Map interface.

jdk1.1.x: The container class must be a subclass of Hashtable.

The referenceClass must set before calling this method.


useScrollableCursor

public void useScrollableCursor()
Use a ScrollableCursor as the result collection.


useScrollableCursor

public void useScrollableCursor(int pageSize)
Use a ScrollableCursor as the result collection.

Parameters:
pageSize - the number of elements to be read into a the cursor when more elements are needed from the database.

useScrollableCursor

public void useScrollableCursor(ScrollableCursorPolicy policy)
Use a ScrollableCursor as the result collection.

Parameters:
policy - the scrollable cursor policy allows for additional result set options. Example:

ScrollableCursorPolicy policy = new ScrollableCursorPolicy()

policy.setResultSetType(ScrollableCursorPolicy.TYPE_SCROLL_INSENSITIVE);

query.useScrollableCursor(policy);


Copyright © 1998, 2010, Oracle. All Rights Reserved.