Top Description Inners Fields Constructors Methods
org.eclipse.persistence.queries

public Class ReadAllQuery

extends ObjectLevelReadQuery
Class Inheritance
Known Direct Subclasses
org.eclipse.persistence.queries.ReportQuery
Imports
java.sql.ResultSet, .ResultSetMetaData, .SQLException, .Statement, java.util.ArrayList, .Collection, .IdentityHashMap, .Iterator, .List, .Map, .Vector, org.eclipse.persistence.exceptions.DatabaseException, .QueryException, org.eclipse.persistence.expressions.Expression, .ExpressionBuilder, org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor, .DatabaseCall, .DatabasePlatform, org.eclipse.persistence.internal.descriptors.ObjectBuilder, org.eclipse.persistence.internal.expressions.QueryKeyExpression, org.eclipse.persistence.internal.helper.ClassConstants, .DatabaseField, .InvalidObject, .ThreadCursoredList, org.eclipse.persistence.internal.queries.ContainerPolicy, .DatasourceCallQueryMechanism, org.eclipse.persistence.internal.sessions.AbstractRecord, .AbstractSession, .ResultSetRecord, .SimpleResultSetRecord, .UnitOfWorkImpl, org.eclipse.persistence.internal.sessions.remote.RemoteSessionController, .Transporter, org.eclipse.persistence.mappings.DatabaseMapping, .OneToManyMapping, org.eclipse.persistence.sessions.DatabaseRecord, .SessionProfiler, org.eclipse.persistence.sessions.remote.DistributedSession, org.eclipse.persistence.tools.profiler.QueryMonitor

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

Author
Yvon Lavoie
Since
TOPLink/Java 1.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
ReadAllQuery.Direction

Specifies the direction in which the hierarchy is traversed in a hierarchical query.

Field Summary

Modifier and TypeField and Description
protected Expression
protected ContainerPolicy
containerPolicy

Used for collection and stream support.

protected ReadAllQuery.Direction
protected List<Expression>
protected Expression
startWithExpression

Used for Oracle HierarchicalQuery support

Inherited from org.eclipse.persistence.queries.ObjectLevelReadQuery:
additionalFieldsaggregateQueriesbatchFetchPolicycacheUsageCheckCacheByExactPrimaryKeyCheckCacheByPrimaryKeyCheckCacheOnlyCheckCacheThenDatabaseconcreteSubclassCallsconcreteSubclassJoinedMappingIndexesconcreteSubclassQueriesConformResultsInUnitOfWorkdefaultBuilderdistinctStateDoNotCheckCacheDONT_USE_DISTINCTfetchGroupfetchGroupNameinMemoryQueryIndirectionPolicyisCachedExpressionQueryisPrePreparedisReadOnlyisReferenceClassLockedisResultSetAccessOptimizedQueryisResultSetAccessOptimizedQueryDefaultisResultSetOptimizedQueryjoinedAttributeManagerloadGrouplockModeTypeNONEnonFetchJoinAttributeExpressionsOPTIMISTICOPTIMISTIC_FORCE_INCREMENTorderByExpressionspartialAttributeExpressionsPESSIMISTIC_PESSIMISTIC_FORCE_INCREMENTPESSIMISTIC_READPESSIMISTIC_WRITEREADshouldExtendPessimisticLockScopeshouldIncludeDatashouldOuterJoinSubclassesshouldUseDefaultFetchGroupshouldUseSerializedObjectPolicyshouldUseSerializedObjectPolicyDefaultUNCOMPUTED_DISTINCTunionExpressionsUSE_DISTINCTUseDescriptorSettingusesResultSetAccessOptimizationwaitTimeoutwaitTimeoutUnitWRITE

Constructor Summary

AccessConstructor and Description
public
ReadAllQuery()

PUBLIC: Return a new read all query.

public
ReadAllQuery(Class<?> classToRead)

PUBLIC: Return a new read all query.

public
ReadAllQuery(Class<?> classToRead, Expression selectionCriteria)

PUBLIC: Return a new read all query for the class and the selection criteria.

public
ReadAllQuery(Class<?> classToRead, ExpressionBuilder builder)

PUBLIC: Return a new read all query for the class.

public
ReadAllQuery(Class<?> classToRead, Call call)

PUBLIC: Return a new read all query.

public
ReadAllQuery(Object exampleObject, QueryByExamplePolicy policy)

PUBLIC: Return a query by example query to find all objects matching the attributes of the example object.

public
ReadAllQuery(ExpressionBuilder builder)

PUBLIC: The expression builder should be provide on creation to ensure only one is used.

public
ReadAllQuery(Call call)

PUBLIC: Create a read all query with the database call.

Method Summary

Modifier and TypeMethod and Description
public void
addAscendingOrdering(String queryKeyName)

PUBLIC: Order the query results by the object's attribute or query key name.

public void
cacheResult(Object unwrappedOriginal)

Implements abstract org.eclipse.persistence.queries.ReadQuery.cacheResult.

INTERNAL:

This method is called by the object builder when building an original.

protected Boolean

Returns:

Current custom query flag. Value will never be null.
checkCustomQueryFlag
(final AbstractSession
Current session (not used).
session
,
final AbstractRecord
Database record (not used).
translationRow
)

Implements abstract org.eclipse.persistence.queries.ObjectLevelReadQuery.checkCustomQueryFlag.

INTERNAL: Check and return custom query flag.
protected Object
checkEarlyReturnLocal(AbstractSession session, AbstractRecord translationRow)

Implements abstract org.eclipse.persistence.queries.ObjectLevelReadQuery.checkEarlyReturnLocal.

INTERNAL: The cache check is done before the prepare as a hit will not require the work to be done.
public Object

Returns:

A clone of this instance.
clone
()

Overrides org.eclipse.persistence.queries.ObjectLevelReadQuery.clone.

INTERNAL: Creates and returns a copy of this query.
protected Object
conformResult(Object result, UnitOfWorkImpl unitOfWork, AbstractRecord arguments, boolean buildDirectlyFromRows)

INTERNAL: Conform the result if specified.

public boolean
equals(Object
the reference object with which to compare.
object
)

Overrides org.eclipse.persistence.queries.ObjectLevelReadQuery.equals.

INTERNAL: Return if the query is equal to the other.
public Object

Returns:

An object or vector, the result of executing the query.
execute
(AbstractSession
- the session in which the receiver will be executed.
session
,
AbstractRecord row)

Overrides org.eclipse.persistence.queries.ObjectLevelReadQuery.execute.

INTERNAL: Execute the query.
protected Object

Returns:

java.lang.Object collection of objects resulting from execution of query.
executeObjectLevelReadQuery
()

Implements abstract org.eclipse.persistence.queries.ObjectLevelReadQuery.executeObjectLevelReadQuery.

INTERNAL: Execute the query.
protected Object

Returns:

an ArrayList of the resulting objects.
executeObjectLevelReadQueryFromResultSet
()

Implements abstract org.eclipse.persistence.queries.ObjectLevelReadQuery.executeObjectLevelReadQueryFromResultSet.

INTERNAL: Execute the query building the objects directly from the database result-set.
public Object
extractRemoteResult(Transporter transporter)

Overrides org.eclipse.persistence.queries.DatabaseQuery.extractRemoteResult.

INTERNAL: Extract the correct query result from the transporter.
public Expression

Returns:

Expression - the connect by expression used to generate the hierarchical query caluse in Oracle
getConnectByExpression
()

PUBLIC:

public ContainerPolicy
getContainerPolicy()

INTERNAL: Return the query's container policy.

protected QueryRedirector
getDefaultRedirector()

Overrides org.eclipse.persistence.queries.DatabaseQuery.getDefaultRedirector.

INTERNAL: Returns the specific default redirector for this query type.
public ReadAllQuery.Direction

Returns:

Direction - the direction in which the hierarchy is traversed
getDirection
()

PUBLIC:

public List<Expression>

Returns:

List<Expression> - the ordering expressions used to generate the hierarchical query clause in Oracle
getOrderSiblingsByExpressions
()

PUBLIC:

protected ObjectLevelReadQuery

Returns:

Custom all read query from query manager.
getReadQuery
()

Implements abstract org.eclipse.persistence.queries.ObjectLevelReadQuery.getReadQuery.

INTERNAL: Get custom all read query from query manager.
public Expression

Returns:

Expression - the start with expression used to generated the hierarchical query clause in Oracle
getStartWithExpression
()

PUBLIC:

public boolean
hasHierarchicalExpressions()

INTERNAL: Verify that we have hierarchical query expressions

public boolean
isDefaultPropertiesQuery()

Overrides org.eclipse.persistence.queries.ObjectLevelReadQuery.isDefaultPropertiesQuery.

INTERNAL: Return true if the query uses default properties.
public boolean
isReadAllQuery()

Overrides org.eclipse.persistence.queries.DatabaseQuery.isReadAllQuery.

PUBLIC: Return if this is a read all query.
protected void
prepare()

Overrides org.eclipse.persistence.queries.ObjectLevelReadQuery.prepare.

INTERNAL: Prepare the receiver for execution in a session.
protected void
prepareCustomQuery(DatabaseQuery customQuery)

Overrides org.eclipse.persistence.queries.ObjectBuildingQuery.prepareCustomQuery.

INTERNAL: Set the properties needed to be cascaded into the custom query.
public void
prepareForExecution()

Overrides org.eclipse.persistence.queries.ReadQuery.prepareForExecution.

INTERNAL: Prepare the receiver for execution in a session.
public void
prepareFromQuery(DatabaseQuery query)

Overrides org.eclipse.persistence.queries.ObjectLevelReadQuery.prepareFromQuery.

INTERNAL: Prepare the query from the prepared query.
protected void
prepareSelectAllRows()

INTERNAL: Prepare the mechanism.

public Object

Returns:

the final (conformed, refreshed, wrapped) UnitOfWork query result
registerResultInUnitOfWork
(Object
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.
result
,
UnitOfWorkImpl
the unitOfWork the result is being registered in.
unitOfWork
,
AbstractRecord
the original arguments/parameters passed to the query execution. Used by conforming
arguments
,
boolean
If in transaction must construct a registered result from raw database rows.
buildDirectlyFromRows
)

Implements abstract org.eclipse.persistence.queries.ObjectLevelReadQuery.registerResultInUnitOfWork.

INTERNAL: All objects queried via a UnitOfWork get registered here.
public Object

Returns:

the final (conformed, refreshed, wrapped) UnitOfWork query result
registerResultSetInUnitOfWork
(ResultSet resultSet, Vector<E> fields, DatabaseField[] fieldsArray, UnitOfWorkImpl unitOfWork, AbstractRecord arguments)

INTERNAL: Version of the previous method for ResultSet optimization.

public Object
remoteExecute()

Overrides org.eclipse.persistence.queries.DatabaseQuery.remoteExecute.

INTERNAL: Execute the query through remote session.
public Map<K, V>
replaceValueHoldersIn(Object object, RemoteSessionController controller)

Overrides org.eclipse.persistence.queries.DatabaseQuery.replaceValueHoldersIn.

INTERNAL: replace the value holders in the specified result object(s)
public void
setContainerPolicy(ContainerPolicy containerPolicy)

PUBLIC: Set the container policy.

public void
setHierarchicalQueryClause(Expression
Describes the START WITH clause of the query - null if not needed
startWith
,
Expression
This should be a query key expression which indicates an attribute who's mapping describes the hierarchy
connectBy
,
List<Expression>
Contains expressions which indicate fields to be included in the ORDER SIBLINGS BY clause - null if not required
orderSiblingsExpressions
)

PUBLIC: Set the Hierarchical Query Clause for the query

Example:

Expression startWith = builder.get("id").equal(Integer.valueOf(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

public void
setHierarchicalQueryClause(Expression
Describes the START WITH clause of the query - null if not needed
startWith
,
Expression
This should be a query key expression which indicates an attribute who's mapping describes the hierarchy
connectBy
,
List<Expression>
Contains expressions which indicate fields to be included in the ORDER SIBLINGS BY clause - null if not required
orderSiblingsExpressions
,
ReadAllQuery.Direction
The direction in which the hierarchy is traversed; if not specified, CHILD_TO_PARENT is used for OneToOne relationships and PARENT_TO_CHILD is used for collections
direction
)

PUBLIC: Set the Hierarchical Query Clause for the query, specifying the hierarchy traversal direction

Example:

Expression startWith = builder.get("id").equal(Integer.valueOf(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, Direction.CHILD_TO_PARENT);

This query would generate SQL like this:

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

public boolean
public boolean
public void
useCollectionClass(Class<?> concreteClass)

PUBLIC: Configure the mapping to use an instance of the specified container class to hold the target objects.

public void
useCursoredStream()

PUBLIC: Use a CursoredStream as the result collection.

public void
useCursoredStream(int
the initial number of objects to read
initialReadSize
,
int
the number of objects to read when more objects are needed from the database
pageSize
)

PUBLIC: Use a CursoredStream as the result collection.

public void
useCursoredStream(int
the initial number of objects to read
initialReadSize
,
int
the number of objects to read when more objects are needed from the database
pageSize
,
ValueReadQuery
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)
sizeQuery
)

PUBLIC: Use a CursoredStream as the result collection.

public void
useMapClass(Class<?> concreteClass, String methodName)

PUBLIC: Configure the query to use an instance of the specified container class to hold the result objects.

public void
useScrollableCursor()

PUBLIC: Use a ScrollableCursor as the result collection.

public void
useScrollableCursor(int
the number of elements to be read into a the cursor when more elements are needed from the database.
pageSize
)

PUBLIC: Use a ScrollableCursor as the result collection.

public void
useScrollableCursor(ScrollableCursorPolicy
the scrollable cursor policy allows for additional result set options. Example:

ScrollableCursorPolicy policy = new ScrollableCursorPolicy()

policy.setResultSetType(ScrollableCursorPolicy.TYPE_SCROLL_INSENSITIVE);

query.useScrollableCursor(policy);

policy
)

PUBLIC: Use a ScrollableCursor as the result collection.

Inherited from org.eclipse.persistence.queries.ObjectLevelReadQuery:
acquireLocksacquireLocksWithoutWaitingaddAdditionalFieldaddAdditionalFieldaddBatchReadAttributeaddBatchReadAttributeaddDescendingOrderingaddJoinedAttributeaddJoinedAttributeaddJoinSelectionFieldsaddNonFetchJoinaddNonFetchJoinedAttributeaddNonFetchJoinedAttributeaddOrderingaddPartialAttributeaddPartialAttributeaddSelectionFieldsForJoinedExpressionaddUnionExpressionbuildObjectchangeDescriptorcheckCacheOnlycheckDescriptorcheckEarlyReturncheckForCustomQuerycheckPreparecheckPrePrepareclearIsResultSetOptimizedQueryclearUsesResultSetAccessOptimizationcomputeBatchReadAttributescomputeBatchReadMappingQueriescomputeNestedQueriesForBatchReadExpressionsconformIndividualResultconformResultsInUnitOfWorkcopyFromQuerydeepClonedontAcquireLocksdontCheckCachedontRefreshIdentityMapResultdontRefreshRemoteIdentityMapResultdontUseDistinctexceptexecuteDatabaseQueryexecuteInUnitOfWorkextendPessimisticLockScopegetAdditionalFieldsgetAggregateQueriesgetAggregateQuerygetAsOfClausegetBatchFetchPolicygetBatchObjectsgetBatchReadAttributeExpressionsgetCacheUsagegetConcreteSubclassCallsgetConcreteSubclassJoinedMappingIndexesgetConcreteSubclassQueriesgetDistinctStategetExampleObjectgetExecutionFetchGroupgetExecutionFetchGroupgetExpressionBuildergetFetchGroupgetFetchGroupNamegetFetchGroupNonNestedFieldsSetgetFetchGroupNonNestedFieldsSetgetFetchGroupSelectionFieldsgetFetchGroupSelectionFieldsgetInMemoryQueryIndirectionPolicygetInMemoryQueryIndirectionPolicyStategetJoinedAttributeExpressionsgetJoinedAttributeManagergetLoadGroupgetLockingClausegetLockModeTypegetNonFetchJoinAttributeExpressionsgetOrderByExpressionsgetPartialAttributeExpressionsgetPartialAttributeSelectionFieldsgetQueryByExamplePolicygetReferenceClassgetReferenceClassNamegetSelectionFieldsgetUnionExpressionsgetWaitTimeoutgetWaitTimeoutUnithasAdditionalFieldshasAsOfClausehasBatchReadAttributeshasDefaultBuilderhasExecutionFetchGrouphasFetchGrouphashCodehasJoininghasNonFetchJoinedAttributeExpressionshasOrderByExpressionshasPartialAttributeExpressionshasUnionExpressionsinitializeDefaultBuilderintersectisAttributeBatchReadisCachedExpressionQueryisClonePessimisticLockedisDefaultLockisDistinctComputedisLockQueryisLockQueryisObjectLevelReadQueryisPartialAttributeisPrePreparedisPrimaryKeyQueryisReadOnlyisReferenceClassLockedisResultSetAccessOptimizedQueryisResultSetOptimizedQueryprepareFetchGroupprepareForRemoteExecutionprepareFromCachedQueryprepareOutsideUnitOfWorkprepareQueryprepareResultSetAccessOptimizationprePreparerecordCloneForPessimisticLockingrefreshIdentityMapResultrefreshRemoteIdentityMapResultresetDistinctsetAdditionalFieldssetAggregateQuerysetAsOfClausesetBatchFetchPolicysetBatchFetchSizesetBatchFetchTypesetBatchObjectssetBatchReadAttributeExpressionssetCacheUsagesetDescriptorsetDistinctStatesetEJBQLStringsetExampleObjectsetExpressionBuildersetFetchGroupsetFetchGroupNamesetInMemoryQueryIndirectionPolicysetInMemoryQueryIndirectionPolicyStatesetIsPreparedsetIsPreparedKeepingSubclassDatasetIsPrePreparedsetIsReadOnlysetIsResultSetAccessOptimizedQuerysetIsResultSetOptimizedQuerysetJoinedAttributeExpressionssetJoinedAttributeManagersetLoadGroupsetLockingClausesetLockModesetLockModeTypesetNonFetchJoinAttributeExpressionssetOrderByExpressionssetPartialAttributeExpressionssetQueryByExamplePolicysetReferenceClasssetReferenceClassNamesetSelectionCriteriasetShouldExtendPessimisticLockScopesetShouldFilterDuplicatessetShouldIncludeDatasetShouldOuterJoinSubclassessetShouldUseDefaultFetchGroupsetShouldUseSerializedObjectPolicysetUnionExpressionssetWaitTimeoutsetWaitTimeoutUnitshouldCheckCacheshouldCheckCacheOnlyshouldCheckDescriptorForCacheUsageshouldConformResultsInUnitOfWorkshouldDistinctBeUsedshouldExtendPessimisticLockScopeshouldFilterDuplicatesshouldIncludeDatashouldOuterJoinSubclassesshouldReadAllMappingsshouldReadMappingshouldUseDefaultFetchGroupshouldUseSerializedObjectPolicytoStringunionuseDistinctusesResultSetAccessOptimization