Module storm.java

Interface Model<E extends Data,ID>

Type Parameters:
E - the type of the entity or projection.
ID - the type of the primary key, or Void in case of a projection without a primary key.

public interface Model<E extends Data,ID>
Provides metadata about an entity or projection type, including its table name, primary key type, and column definitions.

The Model is obtained via QueryTemplate.model(Class) or from a repository's model() method. It can be used to introspect the database mapping of a record type, access column metadata, check primary key defaults, and extract column values from record instances.

Example


 Model<User, Integer> model = orm.model(User.class);
 String tableName = model.name();
 List<Column> columns = model.columns();
 
See Also:
  • Method Details

    • schema

      String schema()
      Returns the schema, or an empty String if the schema is not specified.
      Returns:
      the schema, or an empty String if the schema is not specified.
    • name

      String name()
      Returns the name of the table or view.
      Returns:
      the name of the table or view.
    • type

      Class<E> type()
      Returns the type of the entity or projection.
      Returns:
      the type of the entity or projection.
    • primaryKeyType

      Class<ID> primaryKeyType()
      Returns the type of the primary key.
      Returns:
      the type of the primary key.
    • columns

      List<Column> columns()
      Returns all columns of this model, including columns of expanded relationships.

      The returned list is deterministic and stable. Declared columns are processed in declaration order. Foreign relationships are expanded depth-first at the position of the foreign-key column.

      Expanded columns always correspond to physical columns of the parent record. Join keys come from the parent row, not the referenced row.

      Returns:
      all columns of this model, including expanded relations.
      Since:
      1.7
    • declaredColumns

      List<Column> declaredColumns()
      Returns the columns declared directly on this model.

      Relationship expansion is not applied. The returned list preserves declared order.

      Index semantics: Column.index() refers to the index in columns(), not in this list.

      Returns:
      the declared columns of this model.
      Since:
      1.8
    • isDefaultPrimaryKey

      boolean isDefaultPrimaryKey(@Nullable ID pk)

      This method is used to check if the primary key of the entity is a default value. This is useful when determining if the entity is new or has been persisted before.

      Parameters:
      pk - primary key to check.
      Returns:
      {code true} if the specified primary key represents a default value, false otherwise.
      Since:
      1.2
    • forEachValue

      void forEachValue(@Nonnull List<Column> columns, @Nonnull E record, @Nonnull BiConsumer<Column,Object> consumer) throws st.orm.core.template.SqlTemplateException
      Iterates over the values of the given columns for the supplied record.

      Values are JDBC-ready. Conversions have already been applied.

      Ordering requirement: columns must be ordered according to the model's column order (usually columns() or declaredColumns()).

      Parameters:
      columns - the columns to extract values for, ordered in model column order.
      record - the record to extract values from.
      consumer - receives each column and its extracted value.
      Throws:
      st.orm.core.template.SqlTemplateException - if extraction fails.
      Since:
      1.8
    • values

      default SequencedMap<Column,Object> values(@Nonnull List<Column> columns, @Nonnull E record) throws st.orm.core.template.SqlTemplateException
      Collects column values into an ordered map.

      Ordering requirement: columns must be ordered according to the model's column order (usually columns() or declaredColumns()).

      Parameters:
      columns - the columns to extract values for.
      record - the record to extract values from.
      Returns:
      a map of columns to extracted values.
      Throws:
      st.orm.core.template.SqlTemplateException - if extraction fails.
      Since:
      1.8
    • values

      default SequencedMap<Column,Object> values(@Nonnull E record) throws st.orm.core.template.SqlTemplateException
      Collects all column values into an ordered map.

      This method is equivalent to values(List, Data) with columns().

      Parameters:
      record - the record to extract values from.
      Returns:
      a map of columns to extracted values.
      Throws:
      st.orm.core.template.SqlTemplateException - if extraction fails.
      Since:
      1.8