Module storm.java

Interface QueryTemplate

All Superinterfaces:
SubqueryTemplate
All Known Subinterfaces:
ORMTemplate

public interface QueryTemplate extends SubqueryTemplate
QueryTemplate relies on preview features of the Java platform:
Programs can only use QueryTemplate when preview features are enabled.
Preview features may be removed in a future release, or upgraded to permanent features of the Java platform.
Provides methods for constructing SQL queries and query builders using String Templates or the fluent API.

QueryTemplate is the core interface for interacting with the Storm SQL template engine. It offers two complementary approaches to database access:

This interface also provides utility methods for accessing the SqlDialect, creating BindVars for batch operations, and retrieving Model metadata for entity types.

Example: Query with String Template


 Query query = orm.query(RAW."""
         SELECT \{User.class}
         FROM \{User.class}
         WHERE \{User_.name} = \{"Alice"}""");
 List<User> users = query.getResultList(User.class);
 

Example: Query with QueryBuilder


 List<User> users = orm.selectFrom(User.class)
         .where(User_.name, EQUALS, "Alice")
         .getResultList();
 
See Also:
  • Method Details

    • dialect

      st.orm.core.template.SqlDialect dialect()
      Get the SQL dialect for this template.

      This method is aware of any registered SqlInterceptor instances and returns the SQL dialect used by the underlying SQL template. The dialect is determined based on the SQL template's configuration and the interceptors that have been applied to it.

      Returns:
      the SQL dialect.
      Since:
      1.2
    • createBindVars

      BindVars createBindVars()
      Create a new bind variables instance that can be used to add bind variables to a batch.
      Returns:
      a new bind variables instance.
      See Also:
    • ref

      <T extends Data, ID> Ref<T> ref(@Nonnull Class<T> type, @Nonnull ID id)
      Creates a ref instance for the specified record type and pk. This method can be used to generate ref instances for entities, projections and regular records.
      Type Parameters:
      T - table type.
      ID - primary key type.
      Parameters:
      type - record type.
      id - primary key.
      Returns:
      ref instance.
      Since:
      1.3
    • ref

      <T extends Data, ID> Ref<T> ref(@Nonnull T record, @Nonnull ID id)
      Creates a ref instance for the specified record type and id. This method can be used to generate ref instances for entities, projections and regular records. The object returned by this method already contains the fetched record.
      Type Parameters:
      T - table type.
      ID - primary key type.
      Parameters:
      id - primary key.
      Returns:
      ref instance.
      Since:
      1.3
    • model

      default <T extends Data, ID> Model<T,ID> model(@Nonnull Class<T> type)
      Get the model for the specified record type. The model provides information about the type's database name, primary keys and columns.
      Type Parameters:
      T - table type.
      ID - primary key type.
      Parameters:
      type - record type.
      Returns:
      the model.
    • model

      <T extends Data, ID> Model<T,ID> model(@Nonnull Class<T> type, boolean requirePrimaryKey)
      Get the model for the specified record type. The model provides information about the type's database name, primary keys and columns.
      Type Parameters:
      T - table type.
      ID - primary key type.
      Parameters:
      type - record type.
      requirePrimaryKey - whether to require a primary key.
      Returns:
      the model.
      Since:
      1.3
    • selectFrom

      default <T extends Data> QueryBuilder<T,T,?> selectFrom(@Nonnull Class<T> fromType)
      Creates a query builder for the specified table.
      Type Parameters:
      T - the table type to select from.
      Parameters:
      fromType - the table to select from.
      Returns:
      the query builder.
    • selectFrom

      default <T extends Data, R> QueryBuilder<T,R,?> selectFrom(@Nonnull Class<T> fromType, @Nonnull Class<R> selectType)
      Creates a query builder for the specified table and select type.
      Type Parameters:
      T - the table type to select from.
      R - the result type.
      Parameters:
      fromType - the table to select from.
      selectType - the result type of the query.
      Returns:
      the query builder.
    • selectFrom

      <T extends Data, R> QueryBuilder<T,R,?> selectFrom(@Nonnull Class<T> fromType, @Nonnull Class<R> selectType, @Nonnull StringTemplatePREVIEW template)
      Creates a query builder for the specified table and select type using the given template.
      Type Parameters:
      T - the table type to select from.
      R - the result type.
      Parameters:
      fromType - the table to select from.
      selectType - the result type of the query.
      template - the select clause template.
      Returns:
      the query builder.
    • deleteFrom

      <T extends Data> QueryBuilder<T,?,?> deleteFrom(@Nonnull Class<T> fromType)
      Creates a query builder for the specified table to delete from.
      Type Parameters:
      T - the table type to delete from.
      Parameters:
      fromType - the table to delete from.
      Returns:
      the query builder.
    • query

      Query query(@Nonnull String query)
      Creates a query for the specified query string.
      Parameters:
      query - the query.
      Returns:
      the query.
    • query

      Query query(@Nonnull StringTemplatePREVIEW template)
      Creates a query for the specified query template.
      Parameters:
      template - the query template.
      Returns:
      the query.