Class QueryComposer<T>

java.lang.Object
google.registry.persistence.transaction.QueryComposer<T>

public abstract class QueryComposer<T> extends Object
Creates queries that can be used JPA.

Example usage:

    tm().createQueryComposer(EntityType.class)
        .where("fieldName", Comparator.EQ, "value")
        .orderBy("fieldName")
        .stream()
 
  • Field Details

  • Constructor Details

    • QueryComposer

      protected QueryComposer(Class<T> entityClass)
  • Method Details

    • where

      public <U extends Comparable<? super U>> QueryComposer<T> where(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(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)
      Applies fetchSize to the JDBC statement (by calling Statement.setFetchSize(int)) if the query result is accessed by the stream() 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 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, throws NoResultException if no results are found.

    • stream

      public abstract 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 Comparable<? super U>> CriteriaQueryBuilder.WhereOperator<U> equal(javax.persistence.criteria.CriteriaBuilder criteriaBuilder)
    • lessThan

      public static <U extends Comparable<? super U>> CriteriaQueryBuilder.WhereOperator<U> lessThan(javax.persistence.criteria.CriteriaBuilder criteriaBuilder)
    • lessThanOrEqualTo

      public static <U extends Comparable<? super U>> CriteriaQueryBuilder.WhereOperator<U> lessThanOrEqualTo(javax.persistence.criteria.CriteriaBuilder criteriaBuilder)
    • greaterThanOrEqualTo

      public static <U extends Comparable<? super U>> CriteriaQueryBuilder.WhereOperator<U> greaterThanOrEqualTo(javax.persistence.criteria.CriteriaBuilder criteriaBuilder)
    • greaterThan

      public static <U extends Comparable<? super U>> CriteriaQueryBuilder.WhereOperator<U> greaterThan(javax.persistence.criteria.CriteriaBuilder criteriaBuilder)
    • like

      public static CriteriaQueryBuilder.WhereOperator<String> like(javax.persistence.criteria.CriteriaBuilder criteriaBuilder)