public class SelectQuery<T> extends AbstractQuery implements ParameterizedQuery, XMLSerializable, Select<T>
| Modifier and Type | Field and Description | 
|---|---|
| protected boolean | canReturnScalarValueFlag that indicates whether this query can return single value or
 it should always return some complex data (Object[] for now) | 
| protected Collection<Property<?>> | columns | 
| protected boolean | distinct | 
| static boolean | DISTINCT_DEFAULT | 
| static String | DISTINCT_PROPERTY | 
| protected Expression | havingQualifier | 
| protected List<Ordering> | orderings | 
| protected Expression | qualifier | 
dataMap, name, rootlogger| Constructor and Description | 
|---|
| SelectQuery()Creates an empty SelectQuery. | 
| SelectQuery(Class<T> rootClass)Creates a SelectQuery that selects all objects of a given persistent
 class. | 
| SelectQuery(Class<T> rootClass,
           Expression qualifier)Creates a SelectQuery that selects objects of a given persistent class
 that match supplied qualifier. | 
| SelectQuery(Class<T> rootClass,
           Expression qualifier,
           List<? extends Ordering> orderings)Creates a SelectQuery that selects objects of a given persistent class
 that match supplied qualifier. | 
| SelectQuery(DbEntity root)Creates a SelectQuery for the specified DbEntity. | 
| SelectQuery(DbEntity root,
           Expression qualifier)Creates a SelectQuery for the specified DbEntity with the given
 qualifier. | 
| SelectQuery(DbEntity root,
           Expression qualifier,
           List<? extends Ordering> orderings)Creates a SelectQuery for the specified DbEntity with the given qualifier
 and orderings. | 
| SelectQuery(ObjEntity root)Creates a SelectQuery with null qualifier, for the specifed ObjEntity | 
| SelectQuery(ObjEntity root,
           Expression qualifier)Creates a SelectQuery for the specified ObjEntity with the given
 qualifier. | 
| SelectQuery(ObjEntity root,
           Expression qualifier,
           List<? extends Ordering> orderings)Creates a SelectQuery for the specified ObjEntity with the given
 qualifier and orderings. | 
| SelectQuery(String objEntityName)Creates SelectQuery with  objEntityNameparameter. | 
| SelectQuery(String objEntityName,
           Expression qualifier)Creates SelectQuery with  objEntityNameandqualifierparameters. | 
| SelectQuery(String objEntityName,
           Expression qualifier,
           List<? extends Ordering> orderings)Creates a SelectQuery that selects objects of a given persistent class
 that match supplied qualifier. | 
| Modifier and Type | Method and Description | 
|---|---|
| void | addOrdering(Ordering ordering)Adds ordering specification to this query orderings. | 
| void | addOrdering(String sortPathSpec,
           SortOrder order)Adds ordering specification to this query orderings. | 
| void | addOrderings(Collection<? extends Ordering> orderings)Adds a list of orderings. | 
| void | addPrefetch(PrefetchTreeNode prefetchElement)Adds a prefetch with specified relationship path to the query. | 
| PrefetchTreeNode | addPrefetch(String prefetchPath)Adds a prefetch with specified relationship path to the query. | 
| void | aliasPathSplits(String path,
               String... aliases)Adds one or more aliases for the qualifier expression path. | 
| void | andHavingQualifier(Expression e)Adds specified HAVING qualifier to the existing HAVING qualifier joining it using "AND". | 
| void | andQualifier(Expression e)Adds specified qualifier to the existing qualifier joining it using
 "AND". | 
| ResultBatchIterator<T> | batchIterator(ObjectContext context,
             int size)Creates a ResultBatchIterator based on the provided context and batch
 size. | 
| boolean | canReturnScalarValue() | 
| void | clearOrderings()Clears all configured orderings. | 
| void | clearPrefetches()Clears all stored prefetch paths. | 
| SelectQuery<T> | createQuery(Map<String,?> parameters)Creates and returns a new SelectQuery built using this query as a
 prototype and substituting qualifier parameters with the values from the
 map. | 
| SQLAction | createSQLAction(SQLActionVisitor visitor)Calls "makeSelect" on the visitor. | 
| static SelectQuery<DataRow> | dataRowQuery(Class<?> rootClass) | 
| static SelectQuery<DataRow> | dataRowQuery(Class<?> rootClass,
            Expression qualifier)Creates a SelectQuery that selects DataRows that correspond to a given
 persistent class that match supplied qualifier. | 
| static SelectQuery<DataRow> | dataRowQuery(Class<?> rootClass,
            Expression qualifier,
            List<Ordering> orderings) | 
| void | encodeAsXML(XMLEncoder encoder)Prints itself as XML to the provided PrintWriter. | 
| protected org.apache.cayenne.query.BaseQueryMetadata | getBaseMetaData() | 
| Collection<Property<?>> | getColumns() | 
| int | getFetchLimit()Returns the fetchLimit. | 
| int | getFetchOffset()Returns the fetchOffset. | 
| Expression | getHavingQualifier()Returns query HAVING qualifier. | 
| QueryMetadata | getMetaData(EntityResolver resolver)Returns default select parameters. | 
| List<Ordering> | getOrderings()Returns a list of orderings used by this query. | 
| int | getPageSize()Returns  pageSizeproperty. | 
| PrefetchTreeNode | getPrefetchTree() | 
| Expression | getQualifier()Returns query qualifier. | 
| int | getStatementFetchSize() | 
| void | initWithProperties(Map<String,?> properties)Initializes query parameters using a set of properties. | 
| boolean | isDistinct()Returns true if this query returns distinct rows. | 
| boolean | isFetchingDataRows()Returns  trueif this query should produce a list of data
 rows as opposed to DataObjects,falsefor DataObjects. | 
| 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. | 
| void | orHavingQualifier(Expression e)Adds specified HAVING qualifier to the existing HAVING qualifier joining it using "OR". | 
| void | orQualifier(Expression e)Adds specified qualifier to the existing qualifier joining it using "OR". | 
| static <T> SelectQuery<T> | query(Class<T> rootClass)Creates a SelectQuery that selects objects of a given persistent class. | 
| static <T> SelectQuery<T> | query(Class<T> rootClass,
     Expression qualifier)Creates a SelectQuery that selects objects of a given persistent class
 that match supplied qualifier. | 
| static <T> SelectQuery<T> | query(Class<T> rootClass,
     Expression qualifier,
     List<? extends Ordering> orderings)Creates a SelectQuery that selects objects of a given persistent class
 that match supplied qualifier. | 
| SelectQuery<T> | queryWithParameters(Map<String,?> parameters)A shortcut for  queryWithParameters(Map, boolean)that prunes
 parts of qualifier that have no parameter value set. | 
| SelectQuery<T> | queryWithParameters(Map<String,?> parameters,
                   boolean pruneMissing)Returns a query built using this query as a prototype, using a set of
 parameters to build the qualifier. | 
| void | removeOrdering(Ordering ordering)Removes ordering. | 
| void | removePrefetch(String prefetchPath)Removes prefetch. | 
| void | route(QueryRouter router,
     EntityResolver resolver,
     Query substitutedQuery)Routes itself and if there are any prefetches configured, creates
 prefetch queries and routes them as well. | 
| List<T> | select(ObjectContext context)Selects objects using provided context. | 
| T | selectFirst(ObjectContext context)Selects a single object using provided context. | 
| T | selectOne(ObjectContext context)Selects a single object using provided context. | 
| void | setCanReturnScalarValue(boolean canReturnScalarValue)Flag that indicates whether this query can return single  value or
 it should always return some complex data (Object[] for now) | 
| void | setColumns(Collection<Property<?>> columns) | 
| void | setColumns(Property<?>... columns) | 
| void | setDistinct(boolean distinct)Sets  distinctproperty that determines whether this query
 returns distinct row. | 
| void | setFetchingDataRows(boolean flag)Deprecated. 
 since 4.0, use  dataRowQuery(Class, Expression)to
             create DataRow query instead. | 
| void | setFetchLimit(int fetchLimit)Sets the fetchLimit. | 
| void | setFetchOffset(int fetchOffset) | 
| void | setHavingQualifier(Expression qualifier)Sets new query HAVING qualifier. | 
| void | setPageSize(int pageSize)Sets  pageSizeproperty. | 
| void | setPrefetchTree(PrefetchTreeNode prefetchTree) | 
| void | setQualifier(Expression qualifier)Sets new query qualifier. | 
| void | setStatementFetchSize(int size)Sets statement's fetch size (0 for default size) | 
| void | setSuppressDistinct(boolean suppressDistinct)Sets  distinctproperty that determines whether this query
 returns distinct row. | 
getDataMap, getName, getRoot, setDataMap, setName, setRoot, toStringgetCacheGroup, getCacheGroups, getCacheStrategy, setCacheGroup, setCacheGroups, setCacheStrategy, useLocalCache, useLocalCache, useLocalCache, useSharedCache, useSharedCache, useSharedCacheclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitgetDataMap, getNamepublic static final String DISTINCT_PROPERTY
public static final boolean DISTINCT_DEFAULT
protected Expression qualifier
protected boolean distinct
protected Collection<Property<?>> columns
protected Expression havingQualifier
protected boolean canReturnScalarValue
Flag that indicates whether this query can return single value or it should always return some complex data (Object[] for now)
Default value is true
public SelectQuery()
public SelectQuery(ObjEntity root)
root - the ObjEntity this SelectQuery is for.public SelectQuery(ObjEntity root, Expression qualifier)
root - the ObjEntity this SelectQuery is for.qualifier - an Expression indicating which objects should be fetchedpublic SelectQuery(ObjEntity root, Expression qualifier, List<? extends Ordering> orderings)
root - the ObjEntity this SelectQuery is for.qualifier - an Expression indicating which objects should be fetched.orderings - defines how to order the results, may be null.public SelectQuery(Class<T> rootClass)
rootClass - the Class of objects fetched by this query.public SelectQuery(Class<T> rootClass, Expression qualifier)
rootClass - the Class of objects fetched by this query.qualifier - an Expression indicating which objects should be fetched.public SelectQuery(Class<T> rootClass, Expression qualifier, List<? extends Ordering> orderings)
rootClass - the Class of objects fetched by this query.qualifier - an Expression indicating which objects should be fetched.orderings - defines how to order the results, may be null.public SelectQuery(DbEntity root)
root - the DbEntity this SelectQuery is for.public SelectQuery(DbEntity root, Expression qualifier)
root - the DbEntity this SelectQuery is for.qualifier - an Expression indicating which objects should be fetched.public SelectQuery(DbEntity root, Expression qualifier, List<? extends Ordering> orderings)
root - the DbEntity this SelectQuery is for.qualifier - an Expression indicating which objects should be fetched.orderings - defines how to order the results, may be null.public SelectQuery(String objEntityName)
objEntityName parameter.public SelectQuery(String objEntityName, Expression qualifier)
objEntityName and
 qualifier parameters.public SelectQuery(String objEntityName, Expression qualifier, List<? extends Ordering> orderings)
objEntityName - the name of the ObjEntity to fetch from.qualifier - an Expression indicating which objects should be fetched.orderings - defines how to order the results, may be null.public static <T> SelectQuery<T> query(Class<T> rootClass)
rootClass - the Class of objects fetched by this query.public static <T> SelectQuery<T> query(Class<T> rootClass, Expression qualifier)
rootClass - the Class of objects fetched by this query.qualifier - an Expression indicating which objects should be fetched.public static <T> SelectQuery<T> query(Class<T> rootClass, Expression qualifier, List<? extends Ordering> orderings)
rootClass - the Class of objects fetched by this query.qualifier - an Expression indicating which objects should be fetched.orderings - defines how to order the results, may be null.public static SelectQuery<DataRow> dataRowQuery(Class<?> rootClass)
public static SelectQuery<DataRow> dataRowQuery(Class<?> rootClass, Expression qualifier)
rootClass - the Class of objects that correspond to DataRows entity.qualifier - an Expression indicating which objects should be fetched.public static SelectQuery<DataRow> dataRowQuery(Class<?> rootClass, Expression qualifier, List<Ordering> orderings)
public List<T> select(ObjectContext context)
SelectEssentially the inversion of "ObjectContext.select(Select)".
public T selectOne(ObjectContext context)
SelectCayenneRuntimeException is thrown.
 Essentially the inversion of "ObjectContext.selectOne(Select)".
public T selectFirst(ObjectContext context)
Select
 If it matched more than one object, the first object from the list is
 returned. This makes 'selectFirst' different from
 Select.selectOne(ObjectContext), which would throw in this situation.
 'selectFirst' is useful e.g. when the query is ordered and we only want
 to see the first object (e.g. "most recent news article"), etc.
 
Selecting the first object via "Select.selectFirst(ObjectContext)" is more comprehensible than selecting via "ObjectContext.selectFirst(Select)", because implementations of "Select" set fetch size limit to one.
selectFirst in interface Select<T>public void iterate(ObjectContext context, ResultIteratorCallback<T> callback)
SelectEssentially the inversion of "ObjectContext.iterate(Select, ResultIteratorCallback)".
public ResultIterator<T> iterator(ObjectContext context)
SelectSelect.iterate(ObjectContext, ResultIteratorCallback) as an
 alternative.
 Essentially the inversion of "ObjectContext.iterator(Select)".
public ResultBatchIterator<T> batchIterator(ObjectContext context, int size)
SelectbatchIterator in interface Select<T>public QueryMetadata getMetaData(EntityResolver resolver)
AbstractQuerygetMetaData in interface QuerygetMetaData in class AbstractQuerypublic void route(QueryRouter router, EntityResolver resolver, Query substitutedQuery)
route in interface Queryroute in class AbstractQuerypublic SQLAction createSQLAction(SQLActionVisitor visitor)
createSQLAction in interface QuerycreateSQLAction in class AbstractQuerypublic void initWithProperties(Map<String,?> properties)
public void encodeAsXML(XMLEncoder encoder)
encodeAsXML in interface XMLSerializablepublic SelectQuery<T> queryWithParameters(Map<String,?> parameters)
queryWithParameters(Map, boolean)that prunes
 parts of qualifier that have no parameter value set.public SelectQuery<T> queryWithParameters(Map<String,?> parameters, boolean pruneMissing)
parameter substitution.public SelectQuery<T> createQuery(Map<String,?> parameters)
createQuery in interface ParameterizedQuerypublic void addOrdering(Ordering ordering)
public void addOrderings(Collection<? extends Ordering> orderings)
public void addOrdering(String sortPathSpec, SortOrder order)
public void removeOrdering(Ordering ordering)
public void clearOrderings()
public boolean isDistinct()
public void setDistinct(boolean distinct)
distinct property that determines whether this query
 returns distinct row.public void setSuppressDistinct(boolean suppressDistinct)
distinct property that determines whether this query
 returns distinct row.public void aliasPathSplits(String path, String... aliases)
ExpressionFactory.matchAllExp(String, Object...).public PrefetchTreeNode getPrefetchTree()
public void setPrefetchTree(PrefetchTreeNode prefetchTree)
public void addPrefetch(PrefetchTreeNode prefetchElement)
public PrefetchTreeNode addPrefetch(String prefetchPath)
public void clearPrefetches()
public void removePrefetch(String prefetchPath)
public boolean isFetchingDataRows()
true if this query should produce a list of data
 rows as opposed to DataObjects, false for DataObjects. This
 is a hint to QueryEngine executing this query.public void setFetchingDataRows(boolean flag)
dataRowQuery(Class, Expression) to
             create DataRow query instead.flag parameter is
 true, then results will be in the form of data rows.
 
 Note that if the root of this query is a DbEntity, this
 setting has no effect, and data rows are always fetched. 
 
public int getFetchOffset()
public int getFetchLimit()
public void setFetchLimit(int fetchLimit)
public void setFetchOffset(int fetchOffset)
public int getPageSize()
pageSize property. See setPageSize for more details.public void setPageSize(int pageSize)
pageSize property.
 
 By setting a page size, the Collection returned by performing a query
 will return hollow DataObjects. This is considerably faster and
 uses a tiny fraction of the memory compared to a non-paged query when
 large numbers of objects are returned in the result. When a hollow
 DataObject is accessed all DataObjects on the same page will be faulted
 into memory. There will be a small delay when faulting objects while the
 data is fetched from the data source, but otherwise you do not need to do
 anything special to access data in hollow objects. The first page is
 always faulted into memory immediately.pageSize - The pageSize to setpublic void setStatementFetchSize(int size)
public int getStatementFetchSize()
public void setQualifier(Expression qualifier)
public Expression getQualifier()
public void andQualifier(Expression e)
public void orQualifier(Expression e)
public void setColumns(Collection<Property<?>> columns)
setCanReturnScalarValue(boolean)public void setColumns(Property<?>... columns)
public void setCanReturnScalarValue(boolean canReturnScalarValue)
Flag that indicates whether this query can return single value or it should always return some complex data (Object[] for now)
Default value is true
canReturnScalarValue - can this query return single valuesetColumns(java.util.Collection<org.apache.cayenne.exp.Property<?>>)public boolean canReturnScalarValue()
public Collection<Property<?>> getColumns()
public void setHavingQualifier(Expression qualifier)
public Expression getHavingQualifier()
public void andHavingQualifier(Expression e)
public void orHavingQualifier(Expression e)
protected org.apache.cayenne.query.BaseQueryMetadata getBaseMetaData()
getBaseMetaData in class CacheableQueryCopyright © 2001–2023 Apache Cayenne. All rights reserved.