Module storm.java

Interface SubqueryTemplate

All Known Subinterfaces:
ORMTemplate, QueryTemplate
All Known Implementing Classes:
WhereBuilder

public interface SubqueryTemplate
SubqueryTemplate relies on preview features of the Java platform:
  • SubqueryTemplate refers to one or more preview APIs: StringTemplate.
Programs can only use SubqueryTemplate when preview features are enabled.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
Provides factory methods for constructing subqueries that can be correlated with or embedded in an outer query.

Unlike regular queries created by QueryTemplate, subqueries only select fields from the primary table; fields from nested (foreign key) records are not included. Subqueries cannot be directly executed -- they must be passed as a QueryBuilder object to the outer query (e.g., via WhereBuilder.exists(QueryBuilder) or Templates.subquery(QueryBuilder, boolean)).

Example: EXISTS subquery


 List<User> usersWithOrders = userRepository
         .select()
         .where(predicate -> predicate.exists(
             predicate.subquery(Order.class)
                 .where(Order_.userId, EQUALS, User_.id)))
         .getResultList();
 
Since:
1.1
See Also:
  • Method Details

    • subquery

      default <T extends Data> QueryBuilder<T,?,?> subquery(@Nonnull Class<T> fromType)
      Create a subquery for the given table.
      Type Parameters:
      T - the table type to select from.
      Parameters:
      fromType - the table to create the subquery for.
      Returns:
      the subquery builder.
    • subquery

      default <T extends Data, R extends Data> QueryBuilder<T,?,?> subquery(@Nonnull Class<T> fromType, @Nonnull Class<R> selectType)
      Create a subquery for the given table and select type.
      Type Parameters:
      T - the table type to select from.
      R - the result type.
      Parameters:
      fromType - the table to create the subquery for.
      selectType - the type to select.
      Returns:
      the subquery builder.
    • subquery

      <T extends Data> QueryBuilder<T,?,?> subquery(@Nonnull Class<T> fromType, @Nonnull StringTemplatePREVIEW template)
      Create a subquery for the given table and select type using the given template.
      Type Parameters:
      T - the table type to select from.
      Parameters:
      fromType - the table to create the subquery for.
      template - the select clause template.
      Returns:
      the subquery builder.