Class SqmSelectStatement<T>

All Implemented Interfaces:
AbstractQuery<T>, CommonAbstractCriteria, CriteriaQuery<T>, Serializable, JpaCriteriaBase, JpaCriteriaNode, JpaCriteriaQuery<T>, JpaCteContainer, JpaQueryableCriteria<T>, JpaSelectCriteria<T>, ParameterCollector, SqmCteContainer, SqmSelectQuery<T>, SqmNode, SqmQuery<T>, SqmStatement<T>, SqmVisitableNode

public class SqmSelectStatement<T> extends AbstractSqmSelectQuery<T> implements JpaCriteriaQuery<T>, SqmStatement<T>, ParameterCollector
Author:
Steve Ebersole
See Also:
  • Constructor Details

  • Method Details

    • copy

      public SqmSelectStatement<T> copy(SqmCopyContext context)
      Specified by:
      copy in interface SqmNode
      Specified by:
      copy in interface SqmQuery<T>
      Specified by:
      copy in interface SqmSelectQuery<T>
      Specified by:
      copy in interface SqmStatement<T>
    • validateResultType

      public void validateResultType(Class<?> resultType)
    • getQuerySource

      public SqmQuerySource getQuerySource()
      Specified by:
      getQuerySource in interface SqmStatement<T>
    • getQuerySpec

      public SqmQuerySpec<T> getQuerySpec()
      Description copied from interface: JpaSelectCriteria
      The query structure. See JpaQueryStructure for details
      Specified by:
      getQuerySpec in interface JpaSelectCriteria<T>
      Specified by:
      getQuerySpec in interface SqmSelectQuery<T>
      Overrides:
      getQuerySpec in class AbstractSqmSelectQuery<T>
    • producesUniqueResults

      public boolean producesUniqueResults()
    • containsCollectionFetches

      public boolean containsCollectionFetches()
    • usesDistinct

      public boolean usesDistinct()
    • getSqmParameters

      public Set<SqmParameter<?>> getSqmParameters()
      Description copied from interface: SqmStatement
      Access to the (potentially still growing) collection of parameters for the statement.
      Specified by:
      getSqmParameters in interface SqmStatement<T>
    • resolveParameters

      public SqmStatement.ParameterResolutions resolveParameters()
      Specified by:
      resolveParameters in interface SqmStatement<T>
    • accept

      public <X> X accept(SemanticQueryWalker<X> walker)
      Description copied from interface: SqmVisitableNode
      Accept the walker per visitation
      Specified by:
      accept in interface SqmVisitableNode
    • addParameter

      public void addParameter(SqmParameter<?> parameter)
      Specified by:
      addParameter in interface ParameterCollector
    • distinct

      public SqmSelectStatement<T> distinct(boolean distinct)
      Description copied from interface: AbstractQuery
      Specify whether duplicate query results will be eliminated. A true value will cause duplicates to be eliminated. A false value will cause duplicates to be retained. If distinct has not been specified, duplicate results must be retained.
      Specified by:
      distinct in interface AbstractQuery<T>
      Specified by:
      distinct in interface CriteriaQuery<T>
      Specified by:
      distinct in interface JpaCriteriaQuery<T>
      Specified by:
      distinct in interface JpaSelectCriteria<T>
      Specified by:
      distinct in interface SqmSelectQuery<T>
      Overrides:
      distinct in class AbstractSqmSelectQuery<T>
      Parameters:
      distinct - boolean value specifying whether duplicate results must be eliminated from the query result or whether they must be retained
      Returns:
      the modified query
    • getParameters

      public Set<ParameterExpression<?>> getParameters()
      Description copied from interface: JpaCriteriaQuery
      Return the parameters of the query. Returns empty set if there are no parameters. Modifications to the set do not affect the query.
      Specified by:
      getParameters in interface CriteriaQuery<T>
      Specified by:
      getParameters in interface JpaCriteriaQuery<T>
      Returns:
      the query parameters
    • select

      public SqmSelectStatement<T> select(Selection<? extends T> selection)
      Description copied from interface: CriteriaQuery
      Specify the item that is to be returned in the query result. Replaces the previously specified selection(s), if any.

      Note: Applications using the string-based API may need to specify the type of the select item when it results from a get or join operation and the query result type is specified.

           For example:
      
           CriteriaQuery<String> q = cb.createQuery(String.class);
           Root<Order> order = q.from(Order.class);
           q.select(order.get("shippingAddress").<String>get("state"));
       
           CriteriaQuery<Product> q2 = cb.createQuery(Product.class);
           q2.select(q2.from(Order.class)
                       .join("items")
                       .<Item,Product>join("product"));
       
       
      Specified by:
      select in interface CriteriaQuery<T>
      Specified by:
      select in interface JpaCriteriaQuery<T>
      Parameters:
      selection - selection specifying the item that is to be returned in the query result
      Returns:
      the modified query
    • multiselect

      public SqmSelectStatement<T> multiselect(Selection<?>... selections)
      Description copied from interface: CriteriaQuery
      Specify the selection items that are to be returned in the query result. Replaces the previously specified selection(s), if any. The type of the result of the query execution depends on the specification of the type of the criteria query object created as well as the arguments to the multiselect method.

      An argument to the multiselect method must not be a tuple- or array-valued compound selection item.

      The semantics of this method are as follows:

      • If the type of the criteria query is CriteriaQuery<Tuple> (i.e., a criteria query object created by either the createTupleQuery method or by passing a Tuple class argument to the createQuery method), a Tuple object corresponding to the arguments of the multiselect method, in the specified order, will be instantiated and returned for each row that results from the query execution.
      • If the type of the criteria query is CriteriaQuery<X> for some user-defined class X (i.e., a criteria query object created by passing a X class argument to the createQuery method), the arguments to the multiselect method will be passed to the X constructor and an instance of type X will be returned for each row.
      • If the type of the criteria query is CriteriaQuery<X[]> for some class X, an instance of type X[] will be returned for each row. The elements of the array will correspond to the arguments of the multiselect method, in the specified order.
      • If the type of the criteria query is CriteriaQuery<Object> or if the criteria query was created without specifying a type, and only a single argument is passed to the multiselect method, an instance of type Object will be returned for each row.
      • If the type of the criteria query is CriteriaQuery<Object> or if the criteria query was created without specifying a type, and more than one argument is passed to the multiselect method, an instance of type Object[] will be instantiated and returned for each row. The elements of the array will correspond to the arguments to the multiselect method, in the specified order.
      Specified by:
      multiselect in interface CriteriaQuery<T>
      Specified by:
      multiselect in interface JpaCriteriaQuery<T>
      Parameters:
      selections - selection items corresponding to the results to be returned by the query
      Returns:
      the modified query
    • multiselect

      public SqmSelectStatement<T> multiselect(List<Selection<?>> selectionList)
      Description copied from interface: CriteriaQuery
      Specify the selection items that are to be returned in the query result. Replaces the previously specified selection(s), if any.

      The type of the result of the query execution depends on the specification of the type of the criteria query object created as well as the argument to the multiselect method. An element of the list passed to the multiselect method must not be a tuple- or array-valued compound selection item.

      The semantics of this method are as follows:

      • If the type of the criteria query is CriteriaQuery<Tuple> (i.e., a criteria query object created by either the createTupleQuery method or by passing a Tuple class argument to the createQuery method), a Tuple object corresponding to the elements of the list passed to the multiselect method, in the specified order, will be instantiated and returned for each row that results from the query execution.
      • If the type of the criteria query is CriteriaQuery<X> for some user-defined class X (i.e., a criteria query object created by passing a X class argument to the createQuery method), the elements of the list passed to the multiselect method will be passed to the X constructor and an instance of type X will be returned for each row.
      • If the type of the criteria query is CriteriaQuery<X[]> for some class X, an instance of type X[] will be returned for each row. The elements of the array will correspond to the elements of the list passed to the multiselect method, in the specified order.
      • If the type of the criteria query is CriteriaQuery<Object> or if the criteria query was created without specifying a type, and the list passed to the multiselect method contains only a single element, an instance of type Object will be returned for each row.
      • If the type of the criteria query is CriteriaQuery<Object> or if the criteria query was created without specifying a type, and the list passed to the multiselect method contains more than one element, an instance of type Object[] will be instantiated and returned for each row. The elements of the array will correspond to the elements of the list passed to the multiselect method, in the specified order.
      Specified by:
      multiselect in interface CriteriaQuery<T>
      Specified by:
      multiselect in interface JpaCriteriaQuery<T>
      Parameters:
      selectionList - list of selection items corresponding to the results to be returned by the query
      Returns:
      the modified query
    • orderBy

      public SqmSelectStatement<T> orderBy(Order... orders)
      Description copied from interface: CriteriaQuery
      Specify the ordering expressions that are used to order the query results. Replaces the previous ordering expressions, if any. If no ordering expressions are specified, the previous ordering, if any, is simply removed, and results will be returned in no particular order. The left-to-right sequence of the ordering expressions determines the precedence, whereby the leftmost has highest precedence.
      Specified by:
      orderBy in interface CriteriaQuery<T>
      Specified by:
      orderBy in interface JpaCriteriaQuery<T>
      Parameters:
      orders - zero or more ordering expressions
      Returns:
      the modified query
    • orderBy

      public SqmSelectStatement<T> orderBy(List<Order> orders)
      Description copied from interface: CriteriaQuery
      Specify the ordering expressions that are used to order the query results. Replaces the previous ordering expressions, if any. If no ordering expressions are specified, the previous ordering, if any, is simply removed, and results will be returned in no particular order. The order of the ordering expressions in the list determines the precedence, whereby the first element in the list has highest precedence.
      Specified by:
      orderBy in interface CriteriaQuery<T>
      Specified by:
      orderBy in interface JpaCriteriaQuery<T>
      Parameters:
      orders - list of zero or more ordering expressions
      Returns:
      the modified query
    • subquery

      public <U> SqmSubQuery<U> subquery(Class<U> type)
      Description copied from interface: CommonAbstractCriteria
      Create a subquery of the query.
      Specified by:
      subquery in interface CommonAbstractCriteria
      Specified by:
      subquery in interface JpaCriteriaBase
      Parameters:
      type - the subquery result type
      Returns:
      subquery
    • where

      public SqmSelectStatement<T> where(Expression<Boolean> restriction)
      Description copied from interface: AbstractQuery
      Modify the query to restrict the query results according to the specified boolean expression. Replaces the previously added restriction(s), if any.
      Specified by:
      where in interface AbstractQuery<T>
      Specified by:
      where in interface CriteriaQuery<T>
      Specified by:
      where in interface JpaCriteriaQuery<T>
      Specified by:
      where in interface JpaSelectCriteria<T>
      Overrides:
      where in class AbstractSqmSelectQuery<T>
      Parameters:
      restriction - a simple or compound boolean expression
      Returns:
      the modified query
    • where

      public SqmSelectStatement<T> where(Predicate... restrictions)
      Description copied from interface: AbstractQuery
      Modify the query to restrict the query results according to the conjunction of the specified restriction predicates. Replaces the previously added restriction(s), if any. If no restrictions are specified, any previously added restrictions are simply removed.
      Specified by:
      where in interface AbstractQuery<T>
      Specified by:
      where in interface CriteriaQuery<T>
      Specified by:
      where in interface JpaCriteriaQuery<T>
      Specified by:
      where in interface JpaSelectCriteria<T>
      Overrides:
      where in class AbstractSqmSelectQuery<T>
      Parameters:
      restrictions - zero or more restriction predicates
      Returns:
      the modified query
    • groupBy

      public SqmSelectStatement<T> groupBy(Expression<?>... expressions)
      Description copied from interface: AbstractQuery
      Specify the expressions that are used to form groups over the query results. Replaces the previous specified grouping expressions, if any. If no grouping expressions are specified, any previously added grouping expressions are simply removed.
      Specified by:
      groupBy in interface AbstractQuery<T>
      Specified by:
      groupBy in interface CriteriaQuery<T>
      Specified by:
      groupBy in interface JpaCriteriaQuery<T>
      Specified by:
      groupBy in interface JpaSelectCriteria<T>
      Overrides:
      groupBy in class AbstractSqmSelectQuery<T>
      Parameters:
      expressions - zero or more grouping expressions
      Returns:
      the modified query
    • groupBy

      public SqmSelectStatement<T> groupBy(List<Expression<?>> grouping)
      Description copied from interface: AbstractQuery
      Specify the expressions that are used to form groups over the query results. Replaces the previous specified grouping expressions, if any. If no grouping expressions are specified, any previously added grouping expressions are simply removed.
      Specified by:
      groupBy in interface AbstractQuery<T>
      Specified by:
      groupBy in interface CriteriaQuery<T>
      Specified by:
      groupBy in interface JpaCriteriaQuery<T>
      Specified by:
      groupBy in interface JpaSelectCriteria<T>
      Overrides:
      groupBy in class AbstractSqmSelectQuery<T>
      Parameters:
      grouping - list of zero or more grouping expressions
      Returns:
      the modified query
    • having

      public SqmSelectStatement<T> having(Expression<Boolean> booleanExpression)
      Description copied from interface: AbstractQuery
      Specify a restriction over the groups of the query. Replaces the previous having restriction(s), if any.
      Specified by:
      having in interface AbstractQuery<T>
      Specified by:
      having in interface CriteriaQuery<T>
      Specified by:
      having in interface JpaCriteriaQuery<T>
      Specified by:
      having in interface JpaSelectCriteria<T>
      Overrides:
      having in class AbstractSqmSelectQuery<T>
      Parameters:
      booleanExpression - a simple or compound boolean expression
      Returns:
      the modified query
    • having

      public SqmSelectStatement<T> having(Predicate... predicates)
      Description copied from interface: AbstractQuery
      Specify restrictions over the groups of the query according the conjunction of the specified restriction predicates. Replaces the previously having added restriction(s), if any. If no restrictions are specified, any previously added restrictions are simply removed.
      Specified by:
      having in interface AbstractQuery<T>
      Specified by:
      having in interface CriteriaQuery<T>
      Specified by:
      having in interface JpaCriteriaQuery<T>
      Specified by:
      having in interface JpaSelectCriteria<T>
      Overrides:
      having in class AbstractSqmSelectQuery<T>
      Parameters:
      predicates - zero or more restriction predicates
      Returns:
      the modified query
    • getOffset

      public JpaExpression<Number> getOffset()
      Specified by:
      getOffset in interface JpaCriteriaQuery<T>
    • offset

      public JpaCriteriaQuery<T> offset(JpaExpression<? extends Number> offset)
      Specified by:
      offset in interface JpaCriteriaQuery<T>
    • offset

      public JpaCriteriaQuery<T> offset(Number offset)
      Specified by:
      offset in interface JpaCriteriaQuery<T>
    • getFetch

      public JpaExpression<Number> getFetch()
      Specified by:
      getFetch in interface JpaCriteriaQuery<T>
    • fetch

      public JpaCriteriaQuery<T> fetch(JpaExpression<? extends Number> fetch)
      Specified by:
      fetch in interface JpaCriteriaQuery<T>
    • fetch

      public JpaCriteriaQuery<T> fetch(JpaExpression<? extends Number> fetch, FetchClauseType fetchClauseType)
      Specified by:
      fetch in interface JpaCriteriaQuery<T>
    • fetch

      public JpaCriteriaQuery<T> fetch(Number fetch)
      Specified by:
      fetch in interface JpaCriteriaQuery<T>
    • fetch

      public JpaCriteriaQuery<T> fetch(Number fetch, FetchClauseType fetchClauseType)
      Specified by:
      fetch in interface JpaCriteriaQuery<T>
    • getFetchClauseType

      public FetchClauseType getFetchClauseType()
      Specified by:
      getFetchClauseType in interface JpaCriteriaQuery<T>
    • createCountQuery

      public SqmSelectStatement<Long> createCountQuery()
      Description copied from interface: JpaCriteriaQuery
      A query that returns the number of results of this query.
      Specified by:
      createCountQuery in interface JpaCriteriaQuery<T>
      See Also: