Interface Subquery<T>

Type Parameters:
T - the type of the selection item.
All Superinterfaces:
AbstractQuery<T>, CommonAbstractCriteria, Expression<T>, Selection<T>, TupleElement<T>

public interface Subquery<T> extends AbstractQuery<T>, Expression<T>
The Subquery interface defines functionality that is specific to subqueries.

A subquery has an expression as its selection item.

Since:
2.0
  • Method Details

    • select

      @Nonnull Subquery<T> select(@Nonnull Expression<T> expression)
      Specify the item that is to be returned as the subquery result. Replaces the previously specified selection, if any.
      Parameters:
      expression - expression specifying the item that is to be returned as the subquery result
      Returns:
      the modified subquery
    • where

      @Nonnull Subquery<T> where(@Nonnull Expression<Boolean> restriction)
      Modify the subquery to restrict the result according to the specified boolean expression. Replaces the previously added restriction(s), if any. This method only overrides the return type of the corresponding AbstractQuery method.
      Specified by:
      where in interface AbstractQuery<T>
      Parameters:
      restriction - a simple or compound boolean expression
      Returns:
      the modified subquery
    • where

      @Nonnull Subquery<T> where(@Nonnull BooleanExpression... restrictions)
      Modify the subquery to restrict the result 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. This method only overrides the return type of the corresponding AbstractQuery method.
      Specified by:
      where in interface AbstractQuery<T>
      Parameters:
      restrictions - zero or more restriction predicates
      Returns:
      the modified subquery
    • where

      @Nonnull Subquery<T> where(@Nonnull List<? extends Expression<Boolean>> restrictions)
      Modify the query to restrict the query result 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. This method only overrides the return type of the corresponding AbstractQuery method.
      Specified by:
      where in interface AbstractQuery<T>
      Parameters:
      restrictions - a list of zero or more restriction predicates
      Returns:
      the modified query
      Since:
      3.2
    • groupBy

      @Nonnull Subquery<T> groupBy(@Nonnull Expression<?>... grouping)
      Specify the expressions that are used to form groups over the subquery results. Replaces the previous specified grouping expressions, if any. If no grouping expressions are specified, any previously added grouping expressions are simply removed. This method only overrides the return type of the corresponding AbstractQuery method.
      Specified by:
      groupBy in interface AbstractQuery<T>
      Parameters:
      grouping - zero or more grouping expressions
      Returns:
      the modified subquery
    • groupBy

      @Nonnull Subquery<T> groupBy(@Nonnull List<Expression<?>> grouping)
      Specify the expressions that are used to form groups over the subquery results. Replaces the previous specified grouping expressions, if any. If no grouping expressions are specified, any previously added grouping expressions are simply removed. This method only overrides the return type of the corresponding AbstractQuery method.
      Specified by:
      groupBy in interface AbstractQuery<T>
      Parameters:
      grouping - list of zero or more grouping expressions
      Returns:
      the modified subquery
    • having

      @Nonnull Subquery<T> having(@Nonnull Expression<Boolean> restriction)
      Specify a restriction over the groups of the subquery. Replaces the previous having restriction(s), if any. This method only overrides the return type of the corresponding AbstractQuery method.
      Specified by:
      having in interface AbstractQuery<T>
      Parameters:
      restriction - a simple or compound boolean expression
      Returns:
      the modified subquery
    • having

      @Nonnull Subquery<T> having(@Nonnull BooleanExpression... restrictions)
      Specify restrictions over the groups of the subquery according the conjunction of the specified restriction predicates. Replaces the previously added having restriction(s), if any. If no restrictions are specified, any previously added restrictions are simply removed. This method only overrides the return type of the corresponding AbstractQuery method.
      Specified by:
      having in interface AbstractQuery<T>
      Parameters:
      restrictions - zero or more restriction predicates
      Returns:
      the modified subquery
    • having

      @Nonnull Subquery<T> having(@Nonnull List<? extends Expression<Boolean>> restrictions)
      Specify restrictions over the groups of the query according the conjunction of the specified restriction predicates. Replaces the previously added having restriction(s), if any. If no restrictions are specified, any previously added restrictions are simply removed. This method only overrides the return type of the corresponding AbstractQuery method.
      Specified by:
      having in interface AbstractQuery<T>
      Parameters:
      restrictions - a list of zero or more restriction predicates
      Returns:
      the modified query
      Since:
      3.2
    • distinct

      @Nonnull Subquery<T> distinct(boolean distinct)
      Specify whether duplicate query results are 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. This method only overrides the return type of the corresponding AbstractQuery method.
      Specified by:
      distinct in interface AbstractQuery<T>
      Parameters:
      distinct - boolean value specifying whether duplicate results must be eliminated from the subquery result or whether they must be retained
      Returns:
      the modified subquery.
    • correlate

      @Nonnull <X,Y> From<X,Y> correlate(@Nonnull From<X,Y> parent)
      Create a subquery root or join correlated to a root or join of the enclosing query.
      Type Parameters:
      X - the source type
      Y - the target type
      Parameters:
      parent - root or join of the containing query
      Returns:
      subquery from
      Since:
      4.0
    • correlate

      @Nonnull <Y> Root<Y> correlate(@Nonnull Root<Y> parentRoot)
      Create a subquery root correlated to a root of the enclosing query.
      Type Parameters:
      Y - the entity type
      Parameters:
      parentRoot - a root of the containing query
      Returns:
      subquery root
    • correlate

      @Nonnull <X,Y> Join<X,Y> correlate(@Nonnull Join<X,Y> parentJoin)
      Create a subquery join object correlated to a join object of the enclosing query.
      Type Parameters:
      X - the source type
      Y - the target type
      Parameters:
      parentJoin - join object of the containing query
      Returns:
      subquery join
    • correlate

      @Nonnull <X,Y> CollectionJoin<X,Y> correlate(@Nonnull CollectionJoin<X,Y> parentCollection)
      Create a subquery collection join object correlated to a collection join object of the enclosing query.
      Type Parameters:
      X - the source type
      Y - the element type
      Parameters:
      parentCollection - join object of the containing query
      Returns:
      subquery join
    • correlate

      @Nonnull <X,Y> SetJoin<X,Y> correlate(@Nonnull SetJoin<X,Y> parentSet)
      Create a subquery set join object correlated to a set join object of the enclosing query.
      Type Parameters:
      X - the source type
      Y - the element type
      Parameters:
      parentSet - join object of the containing query
      Returns:
      subquery join
    • correlate

      @Nonnull <X,Y> ListJoin<X,Y> correlate(@Nonnull ListJoin<X,Y> parentList)
      Create a subquery list join object correlated to a list join object of the enclosing query.
      Type Parameters:
      X - the source type
      Y - the element type
      Parameters:
      parentList - join object of the containing query
      Returns:
      subquery join
    • correlate

      @Nonnull <X,K,V> MapJoin<X,K,V> correlate(@Nonnull MapJoin<X,K,V> parentMap)
      Create a subquery map join object correlated to a map join object of the enclosing query.
      Type Parameters:
      X - the source type
      K - the key type
      V - the value type
      Parameters:
      parentMap - join object of the containing query
      Returns:
      subquery join
    • getParent

      @Nonnull AbstractQuery<?> getParent()
      Return the query of which this is a subquery. This must be a CriteriaQuery or a Subquery.
      Returns:
      the enclosing query or subquery
    • getContainingQuery

      @Nonnull CommonAbstractCriteria getContainingQuery()
      Return the query of which this is a subquery. This may be a CriteriaQuery, CriteriaUpdate, CriteriaDelete, or a Subquery.
      Returns:
      the enclosing query or subquery
      Since:
      2.1
    • getSelection

      @Nullable Expression<T> getSelection()
      Return the selection expression.
      Specified by:
      getSelection in interface AbstractQuery<T>
      Returns:
      the item to be returned in the subquery result
    • getCorrelatedJoins

      @Nonnull Set<Join<?,?>> getCorrelatedJoins()
      Return the correlated joins of the subquery. Returns empty set if the subquery has no correlated joins. Modifications to the set do not affect the query.
      Returns:
      the correlated joins of the subquery
    • exists

      @Nonnull Predicate exists()
      Create a predicate testing the existence of this subquery result.
      Returns:
      exists predicate
      Since:
      4.0
      See Also:
    • all

      @Nonnull Expression<T> all()
      Create an all expression over the subquery results.
      Returns:
      all expression
      Since:
      4.0
      See Also:
    • some

      @Nonnull Expression<T> some()
      Create a some expression over the subquery results. This expression is equivalent to an any expression.
      Returns:
      some expression
      Since:
      4.0
      See Also:
    • any

      @Nonnull Expression<T> any()
      Create an any expression over the subquery results. This expression is equivalent to a some expression.
      Returns:
      any expression
      Since:
      4.0
      See Also: