PrefetchSelectQuery (cayenne-doc: Cayenne Documentation 5.0-M2 API)
Description: declaration: package: org.apache.cayenne.query, class: PrefetchSelectQuery

# Class PrefetchSelectQuery<T>

java.lang.Object
org.apache.cayenne.query.CacheableQuery
org.apache.cayenne.query.AbstractQuery
org.apache.cayenne.query.FluentSelect<T, ObjectSelect<T>>
org.apache.cayenne.query.ObjectSelect<T>
org.apache.cayenne.query.PrefetchSelectQuery<T>

All Implemented Interfaces:
  `Serializable, ParameterizedQuery, Query, Select<T>`

public class PrefetchSelectQuery<T> extends ObjectSelect<T>
A SelectQuery to perform a prefetch based on another query. Used internally by Cayenne and is normally never used directly.

Since:
  4.2 this query extends `ObjectSelect`
See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected ObjRelationship`
  `lastPrefetchHint`
  Stores the last ObjRelationship in the prefetch path.
  `protected CayennePath`
  `prefetchPath`
  The relationship path from root objects to the objects being prefetched.
  `protected Collection<ASTPath>`
  `resultPaths`

  ### Fields inherited from class FluentSelect

  `dbEntityName, distinct, entityName, entityType, having, havingExpressionIsActive, metaData, orderings, where`
  Modifier and Type
  Field
  Description
  `protected String`
  `dbEntityName`
  `protected boolean`
  `distinct`
  `protected String`
  `entityName`
  `protected Class<?>`
  `entityType`
  `protected Expression`
  `having`
  `protected boolean`
  `havingExpressionIsActive`
  `protected org.apache.cayenne.query.ObjectSelectMetadata`
  `metaData`
  `protected Collection<Ordering>`
  `orderings`
  `protected Expression`
  `where`

  ### Fields inherited from class AbstractQuery

  `root`
  Modifier and Type
  Field
  Description
  `protected Object`
  `root`
  The root object this query.

  ### Fields inherited from class CacheableQuery

  `logger`
  Modifier and Type
  Field
  Description
  `protected static final org.slf4j.Logger`
  `logger`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `PrefetchSelectQuery(CayennePath prefetchPath, ObjRelationship lastPrefetchHint)`
  Creates a new disjoint prefetch select query.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addResultPath(String path)`
  Configures an "extra" path that will resolve to an extra column (or columns) in the result set.
  `void`
  `addResultPath(Expression path)`
  Configures an "extra" path that will resolve to an extra column (or columns) in the result set.
  `ObjRelationship`
  `getLastPrefetchHint()`
  Returns last incoming ObjRelationship in the prefetch relationship chain.
  `CayennePath`
  `getPrefetchPath()`
  Returns the prefetchPath.
  `Collection<ASTPath>`
  `getResultPaths()`
  Returns extra result paths.
  `void`
  `removeResultPath(String path)`
  Removes an extra result path.
  `void`
  `removeResultPath(CayennePath path)`
  Removes an extra result path.
  `protected void`
  `routePrefetches(QueryRouter router, EntityResolver resolver)`
  `void`
  `setLastPrefetchHint(ObjRelationship relationship)`
  `void`
  `setPrefetchPath(String prefetchPath)`
  Sets the prefetchPath.
  `void`
  `setPrefetchPath(CayennePath prefetchPath)`
  Sets the prefetchPath.
  `void`
  `setPrefetchTree(PrefetchTreeNode prefetch)`
  Clean set of the prefetch tree without any merge with existing nodes.

  ### Methods inherited from class ObjectSelect

  `aggregate, avg, column, columnQuery, columnQuery, columns, count, count, createMetadata, createQuery, dataRowQuery, dataRowQuery, dbQuery, dbQuery, distinct, fetchDataRows, getBaseMetaData, getMetaData, having, having, max, max, min, min, query, query, query, query, selectCount, selectFirst, sum`
  Modifier and Type
  Method
  Description
  `<E> ColumnSelect<E>`
  `aggregate(BaseProperty<E> property, String function, Class<E> type)`
  Select result of some function, that aggregates values.
  `<E extends Number>
  ColumnSelect<E>`
  `avg(NumericProperty<E> property)`
  Select average value of property
  `<E> ColumnSelect<E>`
  `column(Property<E> property)`
  Select one specific property.
  `static ColumnSelect<Object[]>`
  `columnQuery(Class<?> entityType, Property<?>... columns)`
  Creates a ColumnSelect that will fetch multiple columns of a given `ObjEntity`
  `static <E> ColumnSelect<E>`
  `columnQuery(Class<?> entityType, Property<E> column)`
  Creates a ColumnSelect that will fetch single property that can be resolved against a given `ObjEntity` class.
  `ColumnSelect<Object[]>`
  `columns(Property<?>... properties)`
  Select only specific properties.
  `ColumnSelect<Long>`
  `count()`
  Select COUNT(*)
  `ColumnSelect<Long>`
  `count(BaseProperty<?> property)`
  Select COUNT(property)
  `protected org.apache.cayenne.query.ObjectSelectMetadata`
  `createMetadata()`
  `Query`
  `createQuery(Map<String,?> parameters)`
  This method is intended for internal use in a `MappedSelect`.
  `static ObjectSelect<DataRow>`
  `dataRowQuery(Class<?> entityType)`
  Creates a ObjectSelect that fetches data for an `ObjEntity` determined from a provided class.
  `static ObjectSelect<DataRow>`
  `dataRowQuery(Class<?> entityType, Expression expression)`
  Creates a ObjectSelect that fetches data for an `ObjEntity` determined from a provided class and uses provided expression for its qualifier.
  `static ObjectSelect<DataRow>`
  `dbQuery(String dbEntityName)`
  Creates a ObjectSelect that fetches DataRows for a `DbEntity` determined from provided "dbEntityName".
  `static ObjectSelect<DataRow>`
  `dbQuery(String dbEntityName, Expression expression)`
  Creates a ObjectSelect that fetches DataRows for a `DbEntity` determined from provided "dbEntityName" and uses provided expression for its qualifier.
  `ObjectSelect<T>`
  `distinct()`
  `ObjectSelect<DataRow>`
  `fetchDataRows()`
  Forces query to fetch DataRows.
  `protected org.apache.cayenne.query.ObjectSelectMetadata`
  `getBaseMetaData()`
  `QueryMetadata`
  `getMetaData(EntityResolver resolver)`
  Returns default select parameters.
  `ObjectSelect<T>`
  `having(String expressionString, Object... parameters)`
  Appends a having qualifier expression of this query, using provided expression String and an array of position parameters.
  `ObjectSelect<T>`
  `having(Expression expression)`
  Appends a having qualifier expression of this query.
  `<E> ColumnSelect<E>`
  `max(ComparableProperty<E> property)`
  Select maximum value of property
  `<E extends Number>
  ColumnSelect<E>`
  `max(NumericProperty<E> property)`
  Select maximum value of property
  `<E> ColumnSelect<E>`
  `min(ComparableProperty<E> property)`
  Select minimum value of property
  `<E extends Number>
  ColumnSelect<E>`
  `min(NumericProperty<E> property)`
  Select minimum value of property
  `static <T> ObjectSelect<T>`
  `query(Class<T> entityType)`
  Creates a ObjectSelect that selects objects of a given persistent class.
  `static <T> ObjectSelect<T>`
  `query(Class<T> resultType, String entityName)`
  Creates a ObjectSelect that fetches data for `ObjEntity` determined from provided "entityName", but fetches the result of a provided type.
  `static <T> ObjectSelect<T>`
  `query(Class<T> entityType, Expression expression)`
  Creates a ObjectSelect that selects objects of a given persistent class and uses provided expression for its qualifier.
  `static <T> ObjectSelect<T>`
  `query(Class<T> entityType, Expression expression, List<Ordering> orderings)`
  Creates a ObjectSelect that selects objects of a given persistent class and uses provided expression for its qualifier.
  `long`
  `selectCount(ObjectContext context)`
  Quick way to select count of records
  `T`
  `selectFirst(ObjectContext context)`
  Selects a single object using provided context.
  `<E extends Number>
  ColumnSelect<E>`
  `sum(NumericProperty<E> property)`
  Select sum of values

  ### Methods inherited from class FluentSelect

  `and, and, batchIterator, cacheGroup, cacheStrategy, cacheStrategy, castSelf, createSQLAction, dbEntityName, entityName, entityType, getActiveExpression, getColumns, getDbEntityName, getEntityName, getEntityType, getHaving, getLimit, getOffset, getOrderings, getPageSize, getPrefetches, getQueryTimeout, getStatementFetchSize, getWhere, initWithProperties, isDistinct, isFetchingDataRows, iterate, iterator, joinExpression, limit, localCache, localCache, offset, or, or, orderBy, orderBy, orderBy, orderBy, pageSize, prefetch, prefetch, queryTimeout, resolveRoot, route, select, selectOne, setActiveExpression, sharedCache, sharedCache, statementFetchSize, where, where`
  Modifier and Type
  Method
  Description
  `ObjectSelect<T>`
  `and(Collection<Expression> expressions)`
  AND's provided expressions to the existing WHERE clause expression.
  `ObjectSelect<T>`
  `and(Expression... expressions)`
  AND's provided expressions to the existing WHERE clause expression.
  `ResultBatchIterator<T>`
  `batchIterator(ObjectContext context, int size)`
  Creates a ResultBatchIterator based on the provided context and batch size.
  `ObjectSelect<T>`
  `cacheGroup(String cacheGroup)`
  `ObjectSelect<T>`
  `cacheStrategy(QueryCacheStrategy strategy)`
  `ObjectSelect<T>`
  `cacheStrategy(QueryCacheStrategy strategy, String cacheGroup)`
  `protected <E> E`
  `castSelf()`
  Utility method to perform (re)cast this type, doesn't perform any checks, so use with caution.
  `SQLAction`
  `createSQLAction(SQLActionVisitor visitor)`
  A callback method invoked by Cayenne during the final execution phase of the query run.
  `ObjectSelect<T>`
  `dbEntityName(String dbEntityName)`
  Sets the `DbEntity` name to fetch without changing the return type of the query.
  `ObjectSelect<T>`
  `entityName(String entityName)`
  Sets the `ObjEntity` name to fetch without changing the return type of the query.
  `ObjectSelect<T>`
  `entityType(Class<?> entityType)`
  Sets the type of the entity to fetch without changing the return type of the query.
  `protected Expression`
  `getActiveExpression()`
  `Collection<Property<?>>`
  `getColumns()`
  `String`
  `getDbEntityName()`
  `String`
  `getEntityName()`
  `Class<?>`
  `getEntityType()`
  `Expression`
  `getHaving()`
  Returns a HAVING clause Expression of this query.
  `int`
  `getLimit()`
  `int`
  `getOffset()`
  `Collection<Ordering>`
  `getOrderings()`
  `int`
  `getPageSize()`
  `PrefetchTreeNode`
  `getPrefetches()`
  `int`
  `getQueryTimeout()`
  `int`
  `getStatementFetchSize()`
  `Expression`
  `getWhere()`
  Returns a WHERE clause Expression of this query.
  `void`
  `initWithProperties(Map<String,String> properties)`
  `boolean`
  `isDistinct()`
  `boolean`
  `isFetchingDataRows()`
  `void`
  `iterate(ObjectContext context, ResultIteratorCallback<T> callback)`
  Creates a ResultIterator based on the provided context and passes it to a callback for processing.
  `ResultIterator<T>`
  `iterator(ObjectContext context)`
  Creates a ResultIterator based on the provided context.
  `protected ObjectSelect<T>`
  `joinExpression(Collection<Expression> expressions, Function<Collection<Expression>, Expression> joiner)`
  `ObjectSelect<T>`
  `limit(int fetchLimit)`
  Resets query fetch limit - a parameter that defines max number of objects that should be ever be fetched from the database.
  `ObjectSelect<T>`
  `localCache()`
  Instructs Cayenne to look for query results in the "local" cache when running the query.
  `ObjectSelect<T>`
  `localCache(String cacheGroup)`
  Instructs Cayenne to look for query results in the "local" cache when running the query.
  `ObjectSelect<T>`
  `offset(int fetchOffset)`
  Resets query fetch offset - a parameter that defines how many objects should be skipped when reading data from the database.
  `ObjectSelect<T>`
  `or(Collection<Expression> expressions)`
  OR's provided expressions to the existing WHERE clause expression.
  `ObjectSelect<T>`
  `or(Expression... expressions)`
  OR's provided expressions to the existing WHERE clause expression.
  `ObjectSelect<T>`
  `orderBy(String property)`
  Add an ascending ordering on the given property.
  `ObjectSelect<T>`
  `orderBy(String property, SortOrder sortOrder)`
  Add an ordering on the given property.
  `ObjectSelect<T>`
  `orderBy(Collection<Ordering> orderings)`
  Adds a list of orderings to this query.
  `ObjectSelect<T>`
  `orderBy(Ordering... orderings)`
  Add one or more orderings to this query.
  `ObjectSelect<T>`
  `pageSize(int pageSize)`
  Resets query page size.
  `ObjectSelect<T>`
  `prefetch(String path, int semantics)`
  Merges a prefetch path with specified semantics into the query prefetch tree.
  `ObjectSelect<T>`
  `prefetch(PrefetchTreeNode prefetch)`
  Merges prefetch into the query prefetch tree.
  `ObjectSelect<T>`
  `queryTimeout(int timeout)`
  Sets query timeout of PreparedStatement generated for this query.
  `protected Object`
  `resolveRoot(EntityResolver resolver)`
  `void`
  `route(QueryRouter router, EntityResolver resolver, Query substitutedQuery)`
  Implements default routing mechanism relying on the EntityResolver to find DataMap based on the query root.
  `List<T>`
  `select(ObjectContext context)`
  Selects objects using provided context.
  `T`
  `selectOne(ObjectContext context)`
  Selects a single object using provided context.
  `protected void`
  `setActiveExpression(Expression exp)`
  `ObjectSelect<T>`
  `sharedCache()`
  Instructs Cayenne to look for query results in the "shared" cache when running the query.
  `ObjectSelect<T>`
  `sharedCache(String cacheGroup)`
  Instructs Cayenne to look for query results in the "shared" cache when running the query.
  `ObjectSelect<T>`
  `statementFetchSize(int size)`
  Sets fetch size of the PreparedStatement generated for this query.
  `ObjectSelect<T>`
  `where(String expressionString, Object... parameters)`
  Appends a qualifier expression of this query, using provided expression String and an array of position parameters.
  `ObjectSelect<T>`
  `where(Expression expression)`
  Appends a qualifier expression of this query.

  ### Methods inherited from class AbstractQuery

  `getRoot, setRoot, toString`
  Modifier and Type
  Method
  Description
  `Object`
  `getRoot()`
  Returns the root of this query.
  `void`
  `setRoot(Object value)`
  Sets the root of the query
  `String`
  `toString()`

  ### Methods inherited from class CacheableQuery

  `getCacheGroup, getCacheStrategy, setCacheGroup, setCacheStrategy, useLocalCache, useLocalCache, useSharedCache, useSharedCache`
  Modifier and Type
  Method
  Description
  `String`
  `getCacheGroup()`
  `QueryCacheStrategy`
  `getCacheStrategy()`
  `void`
  `setCacheGroup(String cacheGroup)`
  `void`
  `setCacheStrategy(QueryCacheStrategy strategy)`
  `void`
  `useLocalCache()`
  Instructs Cayenne to look for query results in the "local" cache when running the query.
  `void`
  `useLocalCache(String cacheGroup)`
  Instructs Cayenne to look for query results in the "local" cache when running the query.
  `void`
  `useSharedCache()`
  Instructs Cayenne to look for query results in the "shared" cache when running the query.
  `void`
  `useSharedCache(String cacheGroup)`
  Instructs Cayenne to look for query results in the "shared" cache when running the query.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### prefetchPath

    protected CayennePath prefetchPath
    The relationship path from root objects to the objects being prefetched.

  - ### lastPrefetchHint

    protected ObjRelationship lastPrefetchHint
    Stores the last ObjRelationship in the prefetch path.

  - ### resultPaths

    protected Collection<ASTPath> resultPaths

- ## Constructor Details

  - ### PrefetchSelectQuery

    public PrefetchSelectQuery(CayennePath prefetchPath, ObjRelationship lastPrefetchHint)
    Creates a new disjoint prefetch select query.
    Since:
      3.1

- ## Method Details

  - ### routePrefetches

    protected void routePrefetches(QueryRouter router, EntityResolver resolver)
    Overrides:
      `routePrefetches` in class `FluentSelect<T, ObjectSelect<T>>`

  - ### getPrefetchPath

    public CayennePath getPrefetchPath()
    Returns the prefetchPath.
    Since:
      5.0 returns `CayennePath` instead of a plain `String`

  - ### setPrefetchPath

    public void setPrefetchPath(String prefetchPath)
    Sets the prefetchPath.
    Parameters:
      `prefetchPath` - The prefetchPath to set
    See Also:
      - `setPrefetchPath(CayennePath)`

  - ### setPrefetchPath

    public void setPrefetchPath(CayennePath prefetchPath)
    Sets the prefetchPath.
    Parameters:
      `prefetchPath` - The prefetchPath to set
    Since:
      5.0

  - ### setPrefetchTree

    public void setPrefetchTree(PrefetchTreeNode prefetch)
    Clean set of the prefetch tree without any merge with existing nodes.
    Parameters:
      `prefetch` - prefetch tree
    Since:
      4.2

  - ### getLastPrefetchHint

    public ObjRelationship getLastPrefetchHint()
    Returns last incoming ObjRelationship in the prefetch relationship chain.
    Since:
      1.1

  - ### setLastPrefetchHint

    public void setLastPrefetchHint(ObjRelationship relationship)
    Since:
      1.1

  - ### addResultPath

    public void addResultPath(String path)
    Configures an "extra" path that will resolve to an extra column (or columns) in the result set.
    Parameters:
      `path` - A valid path expression. E.g. "abc" or "db:ABC" or "abc.xyz".
    Since:
      1.2

  - ### addResultPath

    public void addResultPath(Expression path)
    Configures an "extra" path that will resolve to an extra column (or columns) in the result set.
    Parameters:
      `path` - a path expression
    Since:
      5.0

  - ### removeResultPath

    public void removeResultPath(String path)
    Removes an extra result path. Note that this method doesn't check for expression invariants, as it doesn't have a proper context to do so. E.g. for the purpose of this method "db:ARTIST_NAME" and "obj:artistName" are not the same, though both will resolve to the same column name.
    See Also:
      - `removeResultPath(CayennePath)`

  - ### removeResultPath

    public void removeResultPath(CayennePath path)
    Removes an extra result path. Note that this method doesn't check for expression invariants, as it doesn't have a proper context to do so. E.g. for the purpose of this method "db:ARTIST_NAME" and "obj:artistName" are not the same, though both will resolve to the same column name.
    Since:
      5.0

  - ### getResultPaths

    public Collection<ASTPath> getResultPaths()
    Returns extra result paths.
    Since:
      1.2, 5.0 returns collection of `CayennePath`