Module storm

Record Class ModelImpl<E extends Record,ID>

java.lang.Object
java.lang.Record
st.orm.template.impl.ModelImpl<E,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.
Record Components:
tableName - the name of the table or view.
type - the type of the entity or projection.
primaryKeyType - the type of the primary key.
columns - an immutable list of columns in the entity or projection.
All Implemented Interfaces:
Model<E,ID>

public record ModelImpl<E extends Record,ID>(@Nonnull TableName tableName, @Nonnull Class<E extends Record> type, @Nonnull Class<ID> primaryKeyType, @Nonnull List<Column> columns) extends Record implements Model<E,ID>
Represents the model of an entity or projection.
  • Constructor Details

    • ModelImpl

      public ModelImpl(@Nonnull TableName tableName, @Nonnull Class<E> type, @Nonnull Class<ID> primaryKeyType, @Nonnull List<Column> columns)
      Creates an instance of a ModelImpl record class.
      Parameters:
      tableName - the value for the tableName record component
      type - the value for the type record component
      primaryKeyType - the value for the primaryKeyType record component
      columns - the value for the columns record component
  • Method Details

    • schema

      public String schema()
      Returns the schema, or empty String if the schema is not specified.
      Specified by:
      schema in interface Model<E extends Record,ID>
      Returns:
      the schema, or empty String if the schema is not specified.
    • name

      public String name()
      Returns the name of the table or view.
      Specified by:
      name in interface Model<E extends Record,ID>
      Returns:
      the name of the table or view.
    • qualifiedName

      public String qualifiedName(@Nonnull SqlDialect dialect)
      Returns the qualified name of the table or view, including the schema and escape characters where necessary.
      Specified by:
      qualifiedName in interface Model<E extends Record,ID>
      Returns:
      the qualified name of the table or view, including the schema and escape characters where necessary.
    • isDefaultPrimaryKey

      public boolean isDefaultPrimaryKey(@Nullable ID pk)
      Returns {code true} if the specified primary key represents a default value, false otherwise.

      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.

      Specified by:
      isDefaultPrimaryKey in interface Model<E extends Record,ID>
      Parameters:
      pk - primary key to check.
      Returns:
      {code true} if the specified primary key represents a default value, false otherwise.
      Since:
      1.2
    • getValues

      public SequencedMap<Column,Object> getValues(@Nonnull E record)
      Extracts the values from the given record and maps them to the columns of the entity or projection.
      Specified by:
      getValues in interface Model<E extends Record,ID>
      Parameters:
      record - the record to extract the values from.
      Returns:
      the values from the given record mapped to the columns of the entity or projection.
      Throws:
      PersistenceException - if an error occurs while extracting the values.
      Since:
      1.2
    • getValue

      public Object getValue(@Nonnull Column column, @Nonnull E record)
      Extracts the value for the specified column from the given record.
      Specified by:
      getValue in interface Model<E extends Record,ID>
      Parameters:
      column - the column to extract the value for.
      record - the record to extract the value from.
      Returns:
      the value for the specified column from the given record.
      Throws:
      PersistenceException - if an error occurs while extracting the values.
      Since:
      1.2
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • tableName

      @Nonnull public TableName tableName()
      Returns the value of the tableName record component.
      Returns:
      the value of the tableName record component
    • type

      @Nonnull public Class<E> type()
      Returns the value of the type record component.
      Specified by:
      type in interface Model<E extends Record,ID>
      Returns:
      the value of the type record component
    • primaryKeyType

      @Nonnull public Class<ID> primaryKeyType()
      Returns the value of the primaryKeyType record component.
      Specified by:
      primaryKeyType in interface Model<E extends Record,ID>
      Returns:
      the value of the primaryKeyType record component
    • columns

      @Nonnull public List<Column> columns()
      Returns the value of the columns record component.
      Specified by:
      columns in interface Model<E extends Record,ID>
      Returns:
      the value of the columns record component