Class QueryComposer<T>


  • public abstract class QueryComposer<T>
    extends java.lang.Object
    Creates queries that can be used both for objectify and JPA.

    Example usage:

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

      • entityClass

        protected java.lang.Class<T> entityClass
      • orderBy

        @Nullable
        protected java.lang.String orderBy
    • 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(mmuller): 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 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, throws NoResultException 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)