public interface Query<E extends Entity>
Fluent interface for DAO queries. This interface is immutable - new objects are always returned - so it is safe to save partial queries and use them to build up more sophisticated queries.
An implementation on top of the base DAO methods is used by AbstractDataAccessObject
. Other DAO implementations can reimplement this interface in other ways, for example to generate SQL queries.
Modifier and Type | Method and Description |
---|---|
<V extends Entity> |
asType(Class<V> type)
View results as a different type.
|
int |
count()
Get the number of results the query would return.
|
List<E> |
get()
Get the results of this query as a list.
|
GroupedQuery<E> |
groupBy(String name)
Group the results of this query by an attribute.
|
GroupedQuery<E> |
groupBy(TypedName<Long> name)
Group the results of this query by an attribute.
|
Query<E> |
orderBy(TypedName<? extends Comparable<?>> name)
Sort the query results by a field.
|
Query<E> |
orderBy(TypedName<? extends Comparable<?>> name,
SortOrder order)
Sort the query results by a field.
|
ObjectStream<E> |
stream()
Stream the results of this query.
|
LongSet |
valueSet(TypedName<Long> attr)
Get the set of values from an attribute in the entities in this query.
|
<T> Query<E> |
withAttribute(TypedName<T> name,
T value)
Add an attribute value condition to the query.
|
<T> Query<E> withAttribute(TypedName<T> name, T value)
Add an attribute value condition to the query.
name
- The attribute name.value
- The attribute value.T
- The attribute type.Query<E> orderBy(TypedName<? extends Comparable<?>> name)
Sort the query results by a field.
name
- The field name.Query<E> orderBy(TypedName<? extends Comparable<?>> name, SortOrder order)
Sort the query results by a field.
name
- The field name.order
- The sort order.<V extends Entity> Query<V> asType(Class<V> type)
View results as a different type.
type
- The entity view type.V
- The entity view type.GroupedQuery<E> groupBy(TypedName<Long> name)
Group the results of this query by an attribute.
name
- The attribute name to group by.GroupedQuery<E> groupBy(String name)
Group the results of this query by an attribute.
name
- The attribute name to group by.ObjectStream<E> stream()
Stream the results of this query.
List<E> get()
Get the results of this query as a list.
int count()
Get the number of results the query would return.
LongSet valueSet(TypedName<Long> attr)
Get the set of values from an attribute in the entities in this query. Use this to do things like get the set of items referenced in a user’s ratings:
dao.query(Rating.class)
.withAttribute(CommonAttributes.USER_ID, user)
.valueSet(CommonAttributes.ITEM_ID);
attr
- The attribute name to select.attribute
takes on in the query.