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(java.lang.Class<V> type)
View results as a different type.
|
int |
count()
Get the number of results the query would return.
|
java.util.List<E> |
get()
Get the results of this query as a list.
|
GroupedQuery<E> |
groupBy(java.lang.String name)
Group the results of this query by an attribute.
|
GroupedQuery<E> |
groupBy(TypedName<java.lang.Long> name)
Group the results of this query by an attribute.
|
Query<E> |
orderBy(TypedName<? extends java.lang.Comparable<?>> name)
Sort the query results by a field.
|
Query<E> |
orderBy(TypedName<? extends java.lang.Comparable<?>> name,
SortOrder order)
Sort the query results by a field.
|
ObjectStream<E> |
stream()
Stream the results of this query.
|
LongSet |
valueSet(TypedName<java.lang.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 java.lang.Comparable<?>> name)
Sort the query results by a field.
name
- The field name.Query<E> orderBy(TypedName<? extends java.lang.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(java.lang.Class<V> type)
View results as a different type.
type
- The entity view type.V
- The entity view type.GroupedQuery<E> groupBy(TypedName<java.lang.Long> name)
Group the results of this query by an attribute.
name
- The attribute name to group by.GroupedQuery<E> groupBy(java.lang.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.
java.util.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<java.lang.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.