public class ObjectSelect<T> extends IndirectQuery implements Select<T>
SelectQuery
when you want to use a fluent API. For example, the following
is a convenient way to return a record:
Artist a = ObjectSelect
.query(Artist.class)
.where(Artist.NAME.eq("Picasso"))
.selectOne(context);
dataMap, lastResolver, name, replacementQuery
Modifier | Constructor and Description |
---|---|
protected |
ObjectSelect() |
Modifier and Type | Method and 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> |
cacheGroups(Collection<String> cacheGroups) |
ObjectSelect<T> |
cacheGroups(String... cacheGroups) |
ObjectSelect<T> |
cacheStrategy(QueryCacheStrategy strategy,
String... cacheGroups) |
protected Query |
createReplacementQuery(EntityResolver resolver)
Translates self to a SelectQuery.
|
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. |
ObjectSelect<T> |
dbEntityName(String dbEntityName)
Sets the
DbEntity name to fetch without changing the return type
of the query. |
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> |
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.
|
ObjectSelect<DataRow> |
fetchDataRows()
Forces query to fetch DataRows.
|
String[] |
getCacheGroups() |
QueryCacheStrategy |
getCacheStrategy() |
String |
getDbEntityName() |
String |
getEntityName() |
Class<?> |
getEntityType() |
int |
getLimit() |
int |
getOffset() |
Collection<Ordering> |
getOrderings() |
int |
getPageSize() |
PrefetchTreeNode |
getPrefetches() |
int |
getStatementFetchSize() |
Expression |
getWhere()
Returns a WHERE clause Expression of this query.
|
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.
|
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(String... cacheGroups)
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(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> |
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> |
pageSize(int pageSize)
Resets query page size.
|
ObjectSelect<T> |
prefetch(PrefetchTreeNode prefetch)
Merges prefetch into the query prefetch tree.
|
ObjectSelect<T> |
prefetch(String path,
int semantics)
Merges a prefetch path with specified semantics into the query prefetch
tree.
|
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> 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.
|
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. |
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.
|
ObjectSelect<T> |
sharedCache(String... cacheGroups)
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(Expression expression)
Appends a qualifier expression of 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.
|
createSQLAction, getDataMap, getMetaData, getName, getReplacementQuery, route, setDataMap, setName
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
createSQLAction, getDataMap, getMetaData, getName, route
public static <T> ObjectSelect<T> query(Class<T> entityType)
public static <T> ObjectSelect<T> query(Class<T> entityType, Expression expression)
public static <T> ObjectSelect<T> query(Class<T> entityType, Expression expression, List<Ordering> orderings)
public static ObjectSelect<DataRow> dataRowQuery(Class<?> entityType)
ObjEntity
determined from a provided class.public static ObjectSelect<DataRow> dataRowQuery(Class<?> entityType, Expression expression)
ObjEntity
determined from a provided class and uses provided expression for its
qualifier.public static <T> ObjectSelect<T> query(Class<T> resultType, String entityName)
ObjEntity
determined
from provided "entityName", but fetches the result of a provided type.
This factory method is most often used with generic classes that by
themselves are not enough to resolve the entity to fetch.public static ObjectSelect<DataRow> dbQuery(String dbEntityName)
DbEntity
determined from provided "dbEntityName".public static ObjectSelect<DataRow> dbQuery(String dbEntityName, Expression expression)
DbEntity
determined from provided "dbEntityName" and uses provided expression for
its qualifier.protected Query createReplacementQuery(EntityResolver resolver)
createReplacementQuery
in class IndirectQuery
public ObjectSelect<T> entityType(Class<?> entityType)
public ObjectSelect<T> entityName(String entityName)
ObjEntity
name to fetch without changing the return type
of the query. This form is most often used for generic entities that
don't map to a distinct class.public ObjectSelect<T> dbEntityName(String dbEntityName)
DbEntity
name to fetch without changing the return type
of the query. This form is most often used for generic entities that
don't map to a distinct class.public ObjectSelect<DataRow> fetchDataRows()
public ObjectSelect<T> where(Expression expression)
and(Expression...)
that can be used a syntactic sugar.public ObjectSelect<T> where(String expressionString, Object... parameters)
public ObjectSelect<T> and(Expression... expressions)
public ObjectSelect<T> and(Collection<Expression> expressions)
public ObjectSelect<T> or(Expression... expressions)
public ObjectSelect<T> or(Collection<Expression> expressions)
public ObjectSelect<T> orderBy(String property)
property
- the property to sort onpublic ObjectSelect<T> orderBy(String property, SortOrder sortOrder)
property
- the property to sort onsortOrder
- the direction of the orderingpublic ObjectSelect<T> orderBy(Ordering... orderings)
public ObjectSelect<T> orderBy(Collection<Ordering> orderings)
public ObjectSelect<T> prefetch(PrefetchTreeNode prefetch)
public ObjectSelect<T> prefetch(String path, int semantics)
public ObjectSelect<T> limit(int fetchLimit)
public ObjectSelect<T> offset(int fetchOffset)
public ObjectSelect<T> pageSize(int pageSize)
public ObjectSelect<T> statementFetchSize(int size)
Statement.setFetchSize(int)
public ObjectSelect<T> cacheStrategy(QueryCacheStrategy strategy, String... cacheGroups)
public ObjectSelect<T> cacheGroups(String... cacheGroups)
public ObjectSelect<T> cacheGroups(Collection<String> cacheGroups)
public ObjectSelect<T> localCache(String... cacheGroups)
query.cacheStrategy(QueryCacheStrategy.LOCAL_CACHE, cacheGroups);
public ObjectSelect<T> sharedCache(String... cacheGroups)
query.cacheStrategy(QueryCacheStrategy.SHARED_CACHE, cacheGroups);
public String[] getCacheGroups()
public QueryCacheStrategy getCacheStrategy()
public int getStatementFetchSize()
public int getPageSize()
public int getLimit()
public int getOffset()
public boolean isFetchingDataRows()
public Class<?> getEntityType()
public String getEntityName()
public String getDbEntityName()
public Expression getWhere()
public Collection<Ordering> getOrderings()
public PrefetchTreeNode getPrefetches()
public List<T> select(ObjectContext context)
Select
Essentially the inversion of "ObjectContext.select(Select)".
public T selectOne(ObjectContext context)
Select
CayenneRuntimeException
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)
Select
Essentially the inversion of "ObjectContext.iterate(Select, ResultIteratorCallback)".
public ResultIterator<T> iterator(ObjectContext context)
Select
Select.iterate(ObjectContext, ResultIteratorCallback)
as an
alternative.
Essentially the inversion of "ObjectContext.iterator(Select)".
public ResultBatchIterator<T> batchIterator(ObjectContext context, int size)
Select
batchIterator
in interface Select<T>
Copyright © 2001–2016 Apache Cayenne. All rights reserved.