- All Known Subinterfaces:
ORMTemplate,QueryTemplate
- All Known Implementing Classes:
WhereBuilder
public interface SubqueryTemplate
SubqueryTemplate relies on preview features of the Java platform:
SubqueryTemplaterefers to one or more preview APIs:StringTemplate.
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 Summary
Modifier and TypeMethodDescriptiondefault <T extends Data>
QueryBuilder<T, ?, ?> Create a subquery for the given table.default <T extends Data,R extends Data>
QueryBuilder<T, ?, ?> Create a subquery for the given table and select type.<T extends Data>
QueryBuilder<T, ?, ?> subquery(Class<T> fromType, StringTemplatePREVIEW template) Create a subquery for the given table and select type using the giventemplate.
-
Method Details
-
subquery
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 giventemplate.- 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.
-
SubqueryTemplatewhen preview features are enabled.