Package st.orm

Record Class Metamodel.KeyDelegate<T extends Data,E>

java.lang.Object
java.lang.Record
st.orm.Metamodel.KeyDelegate<T,E>
Type Parameters:
T - the root table type.
E - the field type.
All Implemented Interfaces:
Metamodel<T,E>, Metamodel.Key<T,E>
Enclosing interface:
Metamodel<T extends Data,E>

public static record Metamodel.KeyDelegate<T extends Data,E>(@Nonnull Metamodel<T extends Data,E> delegate) extends Record implements Metamodel.Key<T,E>
Delegating wrapper that adds the Metamodel.Key marker to an existing Metamodel instance.

Equality and hash code are delegated to the wrapped metamodel. Because AbstractMetamodel.equals(java.lang.Object) checks instanceof Metamodel, a KeyDelegate compares equal to its wrapped metamodel when the wrapped metamodel is an AbstractMetamodel.

  • Nested Class Summary

    Nested classes/interfaces inherited from interface st.orm.Metamodel

    Metamodel.Key<T extends Data,E>, Metamodel.KeyDelegate<T extends Data,E>
  • Constructor Summary

    Constructors
    Constructor
    Description
    KeyDelegate(Metamodel<T,E> delegate)
    Creates an instance of a KeyDelegate record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the value of the delegate record component.
    boolean
    Indicates whether some other object is "equal to" this one.
    Returns the field name.
    Returns the field type of the designated element.
    Returns a flat list of leaf metamodels for this metamodel.
    getValue(T record)
    Extracts the value from the given record as specified by this metamodel.
    int
    Returns a hash code value for this object.
    boolean
    Returns true if the metamodel corresponds to a database column, returns false otherwise, for example, if the metamodel refers to the root metamodel or an inline record.
    boolean
    isIdentical(T a, T b)
    Checks whether the value extracted from a is identical to the value extracted from b.
    boolean
    Returns true if the metamodel corresponds to an inline record, returns false otherwise.
    boolean
    Returns true if this key field allows NULL values with standard SQL distinct-NULL semantics, meaning the UNIQUE constraint does not prevent multiple NULLs.
    boolean
    isSame(T a, T b)
    Checks whether the value extracted from a is the same as the value extracted from b.
    Returns the path to the database table.
    Returns the root metamodel.
    Metamodel<T,? extends Data>
    Returns the table that holds the column to which this metamodel is pointing.
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface st.orm.Metamodel

    canonical, fieldPath, tableType
  • Constructor Details

    • KeyDelegate

      public KeyDelegate(@Nonnull Metamodel<T,E> delegate)
      Creates an instance of a KeyDelegate record class.
      Parameters:
      delegate - the value for the delegate record component
  • Method Details

    • isColumn

      public boolean isColumn()
      Description copied from interface: Metamodel
      Returns true if the metamodel corresponds to a database column, returns false otherwise, for example, if the metamodel refers to the root metamodel or an inline record.

      Note that a column can also be a table, for example, in the case of a foreign key.

      Specified by:
      isColumn in interface Metamodel<T extends Data,E>
      Returns:
      true if this metamodel maps to a column, false otherwise.
    • isInline

      public boolean isInline()
      Description copied from interface: Metamodel
      Returns true if the metamodel corresponds to an inline record, returns false otherwise.
      Specified by:
      isInline in interface Metamodel<T extends Data,E>
      Returns:
      true if this metamodel maps to an inline record, false otherwise.
    • root

      public Class<T> root()
      Description copied from interface: Metamodel
      Returns the root metamodel. This is typically the table specified in the FROM clause of a query.
      Specified by:
      root in interface Metamodel<T extends Data,E>
      Returns:
      the root metamodel.
    • table

      public Metamodel<T,? extends Data> table()
      Description copied from interface: Metamodel
      Returns the table that holds the column to which this metamodel is pointing. If the metamodel points to an inline record, the table is the parent table of the inline record. If the metamodel is a root metamodel, the root table is returned.
      Specified by:
      table in interface Metamodel<T extends Data,E>
      Returns:
      the table that holds the column to which this metamodel is pointing.
    • path

      public String path()
      Description copied from interface: Metamodel
      Returns the path to the database table.
      Specified by:
      path in interface Metamodel<T extends Data,E>
      Returns:
      path to the database table.
    • fieldType

      public Class<E> fieldType()
      Description copied from interface: Metamodel
      Returns the field type of the designated element.
      Specified by:
      fieldType in interface Metamodel<T extends Data,E>
      Returns:
      the field type of the designated element.
    • field

      public String field()
      Description copied from interface: Metamodel
      Returns the field name.
      Specified by:
      field in interface Metamodel<T extends Data,E>
      Returns:
      field name.
    • getValue

      public Object getValue(@Nonnull T record)
      Description copied from interface: Metamodel
      Extracts the value from the given record as specified by this metamodel.

      The returned value may be null if this metamodel represents a nullable field or if any parent metamodel in the access path resolves to null (for example, when navigating through an optional or nullable nested record).

      Implementations may return a non-null value, but callers must not rely on that unless they statically know they are using a non-null metamodel variant.

      Specified by:
      getValue in interface Metamodel<T extends Data,E>
      Parameters:
      record - the root record from which the value is extracted.
      Returns:
      the extracted value, or null if the value cannot be resolved.
    • isIdentical

      public boolean isIdentical(@Nonnull T a, @Nonnull T b)
      Description copied from interface: Metamodel
      Checks whether the value extracted from a is identical to the value extracted from b.

      Semantics: This method performs an identity comparison on the extracted field value. It returns true if and only if both extracted values refer to the same object instance.

      This operation is only meaningful for reference-typed fields. It is not defined for primitive-typed fields.

      Performance guarantees:

      • No boxing or unboxing is performed.
      • No value coercion or conversion is performed.
      • No equals(...) or comparator logic is used.
      Specified by:
      isIdentical in interface Metamodel<T extends Data,E>
      Parameters:
      a - the instance from which the left-hand value is extracted, must not be null.
      b - the instance from which the right-hand value is extracted, must not be null.
      Returns:
      true if both extracted values are the same object instance.
    • isSame

      public boolean isSame(@Nonnull T a, @Nonnull T b)
      Description copied from interface: Metamodel
      Checks whether the value extracted from a is the same as the value extracted from b.

      Semantics: This method performs a value comparison on the extracted field value. The comparison is defined by the field type:

      • For primitive-typed fields, values are compared using ==.
      • For reference-typed fields, values are compared using their defined value semantics (for example equals(...) or an equivalent comparator).

      Performance guarantees:

      • No boxing or unboxing is performed.
      • No identity comparison is performed.
      • The comparison operates directly on the extracted values.
      Specified by:
      isSame in interface Metamodel<T extends Data,E>
      Parameters:
      a - the instance from which the left-hand value is extracted, must not be null.
      b - the instance from which the right-hand value is extracted, must not be null.
      Returns:
      true if both extracted values are equal by value.
    • flatten

      public List<Metamodel<T,?>> flatten()
      Description copied from interface: Metamodel
      Returns a flat list of leaf metamodels for this metamodel. If this metamodel is not an inline record, it returns a singleton list containing this. If it is an inline record, it recursively expands all nested inline records and returns the individual column metamodels.

      This method is useful for operations like ORDER BY and GROUP BY, where inline records need to be expanded into their individual columns.

      Specified by:
      flatten in interface Metamodel<T extends Data,E>
      Returns:
      a list of leaf metamodels.
    • isNullable

      public boolean isNullable()
      Description copied from interface: Metamodel.Key
      Returns true if this key field allows NULL values with standard SQL distinct-NULL semantics, meaning the UNIQUE constraint does not prevent multiple NULLs.

      A nullable key is unsafe for keyset pagination because WHERE key > cursor silently excludes NULL rows. The scroll methods check this flag and throw a PersistenceException if the key is nullable.

      Specified by:
      isNullable in interface Metamodel.Key<T extends Data,E>
      Returns:
      true if this key allows duplicate NULLs (nullable with nullsDistinct = true), false otherwise.
      See Also:
    • equals

      public 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.
    • hashCode

      public 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
    • toString

      public 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
    • delegate

      @Nonnull public Metamodel<T,E> delegate()
      Returns the value of the delegate record component.
      Returns:
      the value of the delegate record component