Record Class SqlRow

java.lang.Object
java.lang.Record
com.loomcache.server.query.SqlRow
Record Components:
columnsByName - map of column names to values (values may be null for SQL NULL)
columnsByIndex - array of values indexed by column position (elements may be null)
columnIndexMap - map of column names to their index positions (non-null)

public record SqlRow(Map<String, @Nullable Object> columnsByName, @Nullable Object[] columnsByIndex, Map<String,Integer> columnIndexMap) extends Record
Represents a single row in a SQL result set.

Holds column values accessible by both name and index with type-safe getters. Immutable record suitable for safe sharing between threads.

Thread-safe: All operations are read-only after construction.

  • Constructor Details

    • SqlRow

      public SqlRow(Map<String, @Nullable Object> columnsByName, @Nullable Object[] columnsByIndex, Map<String,Integer> columnIndexMap)
      Creates an instance of a SqlRow record class.
      Parameters:
      columnsByName - the value for the columnsByName record component
      columnsByIndex - the value for the columnsByIndex record component
      columnIndexMap - the value for the columnIndexMap record component
  • Method Details

    • of

      public static SqlRow of(Map<String, @Nullable Object> columns)
      Creates a new SqlRow from a map of column name → value.

      Builds both the index array and index map from the provided column map. Column order is preserved from the input map if it's an ordered map.

      Parameters:
      columns - map of column names to values (non-null, non-empty)
      Returns:
      a new SqlRow with indexed access
      Throws:
      NullPointerException - if columns is null
      IllegalArgumentException - if columns is empty
    • getByName

      public @Nullable Object getByName(String columnName)
      Gets a column value by name.
      Parameters:
      columnName - the column name (non-null)
      Returns:
      the column value (may be null if that's what's stored in the row)
      Throws:
      NullPointerException - if columnName is null
    • getByIndex

      public @Nullable Object getByIndex(int index)
      Gets a column value by index (0-based).
      Parameters:
      index - the column index (0-based, must be in range)
      Returns:
      the column value (may be null)
      Throws:
      IndexOutOfBoundsException - if index is out of bounds
    • getStringByName

      public @Nullable String getStringByName(String columnName)
      Gets a column value as a String by name.

      Returns null if the column is not found or its value is null. Otherwise calls toString() on the value.

      Parameters:
      columnName - the column name (non-null)
      Returns:
      the string representation of the column value, or null
      Throws:
      NullPointerException - if columnName is null
    • getIntByName

      public @Nullable Integer getIntByName(String columnName)
      Gets a column value as an Integer by name.

      Accepts Integer values directly or coerces Number values via intValue().

      Parameters:
      columnName - the column name (non-null)
      Returns:
      the integer value, or null if not found or is null
      Throws:
      NullPointerException - if columnName is null
      ClassCastException - if the value is not a Number
    • getLongByName

      public @Nullable Long getLongByName(String columnName)
      Gets a column value as a Long by name.

      Accepts Long values directly or coerces Number values via longValue().

      Parameters:
      columnName - the column name (non-null)
      Returns:
      the long value, or null if not found or is null
      Throws:
      NullPointerException - if columnName is null
      ClassCastException - if the value is not a Number
    • getDoubleByName

      public @Nullable Double getDoubleByName(String columnName)
      Gets a column value as a Double by name.

      Accepts Double values directly or coerces Number values via doubleValue().

      Parameters:
      columnName - the column name (non-null)
      Returns:
      the double value, or null if not found or is null
      Throws:
      NullPointerException - if columnName is null
      ClassCastException - if the value is not a Number
    • getBooleanByName

      public @Nullable Boolean getBooleanByName(String columnName)
      Gets a column value as a Boolean by name.
      Parameters:
      columnName - the column name (non-null)
      Returns:
      the boolean value, or null if not found or is null
      Throws:
      NullPointerException - if columnName is null
      ClassCastException - if the value is not a Boolean
    • columnCount

      public int columnCount()
      Gets the number of columns in this row.
      Returns:
      the column count (always > 0)
    • getColumnNameByIndex

      public @Nullable String getColumnNameByIndex(int index)
      Gets the name of a column by its index.
      Parameters:
      index - the column index (0-based)
      Returns:
      the column name if found, null otherwise
    • 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.
    • columnsByName

      public Map<String, @Nullable Object> columnsByName()
      Returns the value of the columnsByName record component.
      Returns:
      the value of the columnsByName record component
    • columnsByIndex

      public @Nullable Object[] columnsByIndex()
      Returns the value of the columnsByIndex record component.
      Returns:
      the value of the columnsByIndex record component
    • columnIndexMap

      public Map<String,Integer> columnIndexMap()
      Returns the value of the columnIndexMap record component.
      Returns:
      the value of the columnIndexMap record component