Class QueryComposer<T>
- java.lang.Object
-
- google.registry.persistence.transaction.QueryComposer<T>
-
public abstract class QueryComposer<T> extends java.lang.Object
Creates queries that can be used JPA.Example usage:
tm().createQueryComposer(EntityType.class) .where("fieldName", Comparator.EQ, "value") .orderBy("fieldName") .stream()
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
QueryComposer.Comparator
Enum used to specify comparison operations, e.g.protected static class
QueryComposer.WhereClause<U extends java.lang.Comparable<? super U>>
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.Class<T>
entityClass
protected java.lang.String
orderBy
protected java.util.List<QueryComposer.WhereClause<?>>
predicates
-
Constructor Summary
Constructors Modifier Constructor Description protected
QueryComposer(java.lang.Class<T> entityClass)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract long
count()
Returns the number of results of the query.static <U extends java.lang.Comparable<? super U>>
CriteriaQueryBuilder.WhereOperator<U>equal(javax.persistence.criteria.CriteriaBuilder criteriaBuilder)
abstract java.util.Optional<T>
first()
Returns the first result of the query or an empty optional if there is none.abstract T
getSingleResult()
Returns the one and only result of a query.static <U extends java.lang.Comparable<? super U>>
CriteriaQueryBuilder.WhereOperator<U>greaterThan(javax.persistence.criteria.CriteriaBuilder criteriaBuilder)
static <U extends java.lang.Comparable<? super U>>
CriteriaQueryBuilder.WhereOperator<U>greaterThanOrEqualTo(javax.persistence.criteria.CriteriaBuilder criteriaBuilder)
static <U extends java.lang.Comparable<? super U>>
CriteriaQueryBuilder.WhereOperator<U>lessThan(javax.persistence.criteria.CriteriaBuilder criteriaBuilder)
static <U extends java.lang.Comparable<? super U>>
CriteriaQueryBuilder.WhereOperator<U>lessThanOrEqualTo(javax.persistence.criteria.CriteriaBuilder criteriaBuilder)
static CriteriaQueryBuilder.WhereOperator<java.lang.String>
like(javax.persistence.criteria.CriteriaBuilder criteriaBuilder)
abstract com.google.common.collect.ImmutableList<T>
list()
Returns the results of the query as a list.QueryComposer<T>
orderBy(java.lang.String fieldName)
Order the query results by the value of the specified field.abstract java.util.stream.Stream<T>
stream()
Returns the results of the query as a stream.<U extends java.lang.Comparable<? super U>>
QueryComposer<T>where(java.lang.String fieldName, QueryComposer.Comparator comparator, U value)
Introduce a "where" clause to the query.QueryComposer<T>
withFetchSize(int fetchSize)
AppliesfetchSize
to the JDBC statement (by callingStatement.setFetchSize(int)
) if the query result is accessed by thestream()
method.
-
-
-
Field Detail
-
entityClass
protected java.lang.Class<T> entityClass
-
orderBy
@Nullable protected java.lang.String orderBy
-
predicates
protected java.util.List<QueryComposer.WhereClause<?>> predicates
-
-
Constructor Detail
-
QueryComposer
protected QueryComposer(java.lang.Class<T> entityClass)
-
-
Method Detail
-
where
public <U extends java.lang.Comparable<? super U>> QueryComposer<T> where(java.lang.String fieldName, QueryComposer.Comparator comparator, U value)
Introduce a "where" clause to the query.Causes the query to return only results where the field and value have the relationship specified by the comparator. For example, "field EQ value", "field GT value" etc.
-
orderBy
public QueryComposer<T> orderBy(java.lang.String fieldName)
Order the query results by the value of the specified field.TODO: add the ability to do descending sort order.
-
withFetchSize
public QueryComposer<T> withFetchSize(int fetchSize)
AppliesfetchSize
to the JDBC statement (by callingStatement.setFetchSize(int)
) if the query result is accessed by thestream()
method. Calling this method is optional. Children of this class will apply a default positive fetch size if the user does not provide one.With many JDBC drivers, including Postgresql, a positive fetch size is required for streaming large result sets. A zero value, often the drivers' default setting, requires that the entire result set is buffered.
The fetch size value, the default as well as the user-provided one, will be applied if and only if the underlying query implementor supports it. The Hibernate implementations do support this.
-
first
public abstract java.util.Optional<T> first()
Returns the first result of the query or an empty optional if there is none.
-
getSingleResult
public abstract T getSingleResult()
Returns the one and only result of a query.Throws a
NonUniqueResultException
if there is more than one result, throwsNoResultException
if no results are found.
-
stream
public abstract java.util.stream.Stream<T> stream()
Returns the results of the query as a stream.
-
count
public abstract long count()
Returns the number of results of the query.
-
list
public abstract com.google.common.collect.ImmutableList<T> list()
Returns the results of the query as a list.
-
equal
public static <U extends java.lang.Comparable<? super U>> CriteriaQueryBuilder.WhereOperator<U> equal(javax.persistence.criteria.CriteriaBuilder criteriaBuilder)
-
lessThan
public static <U extends java.lang.Comparable<? super U>> CriteriaQueryBuilder.WhereOperator<U> lessThan(javax.persistence.criteria.CriteriaBuilder criteriaBuilder)
-
lessThanOrEqualTo
public static <U extends java.lang.Comparable<? super U>> CriteriaQueryBuilder.WhereOperator<U> lessThanOrEqualTo(javax.persistence.criteria.CriteriaBuilder criteriaBuilder)
-
greaterThanOrEqualTo
public static <U extends java.lang.Comparable<? super U>> CriteriaQueryBuilder.WhereOperator<U> greaterThanOrEqualTo(javax.persistence.criteria.CriteriaBuilder criteriaBuilder)
-
greaterThan
public static <U extends java.lang.Comparable<? super U>> CriteriaQueryBuilder.WhereOperator<U> greaterThan(javax.persistence.criteria.CriteriaBuilder criteriaBuilder)
-
like
public static CriteriaQueryBuilder.WhereOperator<java.lang.String> like(javax.persistence.criteria.CriteriaBuilder criteriaBuilder)
-
-