Class ColumnSelect<T>
- All Implemented Interfaces:
Serializable, Query, Select<T>
A helper builder for queries selecting individual properties based on the root object.
It can be used to select properties of the object itself, properties of related entities or some function calls (including aggregate functions).
Usage examples:
// select list of names:
List<String> names = ObjectSelect.columnQuery(Artist.class, Artist.ARTIST_NAME).select(context);
// select count:
long count = ObjectSelect.columnQuery(Artist.class, PropertyFactory.COUNT).selectOne();
// select only required properties of an entity:
List<Object[]> data = ObjectSelect.columnQuery(Artist.class, Artist.ARTIST_NAME, Artist.DATE_OF_BIRTH)
.where(Artist.ARTIST_NAME.like("Picasso%))
.select(context);
Note: this class can't be instantiated directly. Use ObjectSelect.
- Since:
- 4.0
- See Also:
-
Field Summary
FieldsFields inherited from class FluentSelect
dbEntityName, distinct, entityName, entityType, having, havingExpressionIsActive, metaData, orderings, whereModifier and TypeFieldDescriptionprotected Stringprotected booleanprotected Stringprotected Class<?> protected Expressionprotected booleanprotected org.apache.cayenne.query.ObjectSelectMetadataprotected Collection<Ordering> protected ExpressionFields inherited from class AbstractQuery
rootFields inherited from class CacheableQuery
logger -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedprotectedColumnSelect(ObjectSelect<T> select) Copy constructor to convert ObjectSelect to ColumnSelect -
Method Summary
Modifier and TypeMethodDescription<E> ColumnSelect<Object[]> aggregate(BaseProperty<E> property, String function, Class<E> type) Select result of some function, that aggregates values.avg(NumericProperty<?> property) Select average value of propertyprotected <E> ColumnSelect<E> columns(Collection<Property<?>> properties) Add properties to select.Add properties to select.count()Shortcut forcolumns(Property[])columns}(Property.COUNT)count(BaseProperty<?> property) Select COUNT(property)protected org.apache.cayenne.query.ColumnSelectMetadatadistinct()Explicitly request distinct in query.protected org.apache.cayenne.query.ColumnSelectMetadataCollection<Property<?>> getMetaData(EntityResolver resolver) Returns default select parameters.Appends a having qualifier expression of this query, using provided expression String and an array of position parameters.having(Expression expression) Appends a having qualifier expression of this query.<E> ColumnSelect<E> Maps result of this query by processing with a given function.max(ComparableProperty<?> property) Select maximum value of propertymin(ComparableProperty<?> property) Select minimum value of propertyselectFirst(ObjectContext context) Selects a single object using provided context.<E extends Number>
ColumnSelect<Object[]> sum(NumericProperty<E> property) Select sum of valuesExplicitly suppress distinct in query.Methods inherited from class FluentSelect
and, and, batchIterator, cacheGroup, cacheStrategy, cacheStrategy, castSelf, createSQLAction, dbEntityName, entityName, entityType, getActiveExpression, 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, routePrefetches, select, selectOne, setActiveExpression, sharedCache, sharedCache, statementFetchSize, where, whereModifier and TypeMethodDescriptionand(Collection<Expression> expressions) AND's provided expressions to the existing WHERE clause expression.and(Expression... expressions) AND's provided expressions to the existing WHERE clause expression.batchIterator(ObjectContext context, int size) Creates a ResultBatchIterator based on the provided context and batch size.cacheGroup(String cacheGroup) cacheStrategy(QueryCacheStrategy strategy) cacheStrategy(QueryCacheStrategy strategy, String cacheGroup) protected <E> EcastSelf()Utility method to perform (re)cast this type, doesn't perform any checks, so use with caution.createSQLAction(SQLActionVisitor visitor) A callback method invoked by Cayenne during the final execution phase of the query run.dbEntityName(String dbEntityName) Sets theDbEntityname to fetch without changing the return type of the query.entityName(String entityName) Sets theObjEntityname to fetch without changing the return type of the query.entityType(Class<?> entityType) Sets the type of the entity to fetch without changing the return type of the query.protected ExpressionClass<?> Returns a HAVING clause Expression of this query.intgetLimit()intintintintgetWhere()Returns a WHERE clause Expression of this query.voidinitWithProperties(Map<String, String> properties) booleanbooleanvoiditerate(ObjectContext context, ResultIteratorCallback<T> callback) Creates a ResultIterator based on the provided context and passes it to a callback for processing.iterator(ObjectContext context) Creates a ResultIterator based on the provided context.protected ColumnSelect<T> joinExpression(Collection<Expression> expressions, Function<Collection<Expression>, Expression> joiner) limit(int fetchLimit) Resets query fetch limit - a parameter that defines max number of objects that should be ever be fetched from the database.Instructs Cayenne to look for query results in the "local" cache when running the query.localCache(String cacheGroup) Instructs Cayenne to look for query results in the "local" cache when running the query.offset(int fetchOffset) Resets query fetch offset - a parameter that defines how many objects should be skipped when reading data from the database.or(Collection<Expression> expressions) OR's provided expressions to the existing WHERE clause expression.or(Expression... expressions) OR's provided expressions to the existing WHERE clause expression.Add an ascending ordering on the given property.Add an ordering on the given property.orderBy(Collection<Ordering> orderings) Adds a list of orderings to this query.Add one or more orderings to this query.pageSize(int pageSize) Resets query page size.Merges a prefetch path with specified semantics into the query prefetch tree.prefetch(PrefetchTreeNode prefetch) Merges prefetch into the query prefetch tree.queryTimeout(int timeout) Sets query timeout of PreparedStatement generated for this query.protected ObjectresolveRoot(EntityResolver resolver) voidroute(QueryRouter router, EntityResolver resolver, Query substitutedQuery) Implements default routing mechanism relying on the EntityResolver to find DataMap based on the query root.protected voidroutePrefetches(QueryRouter router, EntityResolver resolver) select(ObjectContext context) Selects objects using provided context.selectOne(ObjectContext context) Selects a single object using provided context.protected voidInstructs Cayenne to look for query results in the "shared" cache when running the query.sharedCache(String cacheGroup) Instructs Cayenne to look for query results in the "shared" cache when running the query.statementFetchSize(int size) Sets fetch size of the PreparedStatement generated for this query.Appends a qualifier expression of this query, using provided expression String and an array of position parameters.where(Expression expression) Appends a qualifier expression of this query.Methods inherited from class AbstractQuery
getRoot, setRoot, toStringMethods inherited from class CacheableQuery
getCacheGroup, getCacheStrategy, setCacheGroup, setCacheStrategy, useLocalCache, useLocalCache, useSharedCache, useSharedCacheModifier and TypeMethodDescriptionvoidsetCacheGroup(String cacheGroup) voidsetCacheStrategy(QueryCacheStrategy strategy) voidInstructs Cayenne to look for query results in the "local" cache when running the query.voiduseLocalCache(String cacheGroup) Instructs Cayenne to look for query results in the "local" cache when running the query.voidInstructs Cayenne to look for query results in the "shared" cache when running the query.voiduseSharedCache(String cacheGroup) Instructs Cayenne to look for query results in the "shared" cache when running the query.
-
Field Details
-
columns
-
singleColumn
protected boolean singleColumn
-
-
Constructor Details
-
ColumnSelect
protected ColumnSelect() -
ColumnSelect
Copy constructor to convert ObjectSelect to ColumnSelect
-
-
Method Details
-
createMetadata
protected org.apache.cayenne.query.ColumnSelectMetadata createMetadata()- Specified by:
createMetadatain classFluentSelect<T, ColumnSelect<T>>
-
columns
Add properties to select.
Can be any properties that can be resolved against root entity type (root entity properties, function call expressions, properties of relationships, etc).
List<Object[]> columns = ObjectSelect.columnQuery(Artist.class, Artist.ARTIST_NAME) .columns(Artist.ARTIST_SALARY, Artist.DATE_OF_BIRTH) .select(context);- Parameters:
properties- array of properties to select- See Also:
-
columns
Add properties to select.
Can be any properties that can be resolved against root entity type (root entity properties, function call expressions, properties of relationships, etc).
- Parameters:
properties- collection of properties, must contain at least one element- See Also:
-
column
-
count
Shortcut for
columns(Property[])columns}(Property.COUNT) -
count
Select COUNT(property)
Can return different result than COUNT(*) as it will count only non null values
- See Also:
-
min
Select minimum value of property
- See Also:
-
max
Select maximum value of property
- See Also:
-
avg
Select average value of property
- See Also:
-
sum
Select sum of values
- See Also:
-
aggregate
public <E> ColumnSelect<Object[]> aggregate(BaseProperty<E> property, String function, Class<E> type) Select result of some function, that aggregates values.
- Since:
- 5.0
- See Also:
-
having
Appends a having qualifier expression of this query. An equivalent toFluentSelect.and(Expression...)that can be used a syntactic sugar.- Returns:
- this object
-
having
Appends a having qualifier expression of this query, using provided expression String and an array of position parameters. This is an equivalent to calling "and".- Returns:
- this object
-
distinct
Explicitly request distinct in query. -
suppressDistinct
Explicitly suppress distinct in query. -
getColumns
- Overrides:
getColumnsin classFluentSelect<T, ColumnSelect<T>>
-
selectFirst
Description copied from interface:SelectSelects a single object using provided context. The query itself can match any number of objects, but will return only the first one. It returns null if no objects were matched.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.
-
getMetaData
Description copied from class:AbstractQueryReturns default select parameters.- Specified by:
getMetaDatain interfaceQuery- Overrides:
getMetaDatain classAbstractQuery
-
getBaseMetaData
protected org.apache.cayenne.query.ColumnSelectMetadata getBaseMetaData()- Specified by:
getBaseMetaDatain classCacheableQuery
-
map
Maps result of this query by processing with a given function.
Could be used to map plain Object[] to some domain-specific object.
Note: this method could be called multiple time, result will be mapped by all functions in the call order.- Type Parameters:
E- new result type- Parameters:
mapper- function that maps result to the required type.- Returns:
- this query with changed result type
- Since:
- 4.2
-