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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintGets the number of columns in this row.Returns the value of thecolumnIndexMaprecord component.@Nullable Object[]Returns the value of thecolumnsByIndexrecord component.Returns the value of thecolumnsByNamerecord component.final booleanIndicates whether some other object is "equal to" this one.@Nullable BooleangetBooleanByName(String columnName) Gets a column value as a Boolean by name.@Nullable ObjectgetByIndex(int index) Gets a column value by index (0-based).@Nullable ObjectGets a column value by name.@Nullable StringgetColumnNameByIndex(int index) Gets the name of a column by its index.@Nullable DoublegetDoubleByName(String columnName) Gets a column value as a Double by name.@Nullable IntegergetIntByName(String columnName) Gets a column value as an Integer by name.@Nullable LonggetLongByName(String columnName) Gets a column value as a Long by name.@Nullable StringgetStringByName(String columnName) Gets a column value as a String by name.final inthashCode()Returns a hash code value for this object.static SqlRowCreates a new SqlRow from a map of column name → value.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
SqlRow
public SqlRow(Map<String, @Nullable Object> columnsByName, @Nullable Object[] columnsByIndex, Map<String, Integer> columnIndexMap) Creates an instance of aSqlRowrecord class.- Parameters:
columnsByName- the value for thecolumnsByNamerecord componentcolumnsByIndex- the value for thecolumnsByIndexrecord componentcolumnIndexMap- the value for thecolumnIndexMaprecord component
-
-
Method Details
-
of
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 nullIllegalArgumentException- if columns is empty
-
getByName
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
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
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
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 nullClassCastException- if the value is not a Number
-
getLongByName
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 nullClassCastException- if the value is not a Number
-
getDoubleByName
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 nullClassCastException- if the value is not a Number
-
getBooleanByName
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 nullClassCastException- 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
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
-
hashCode
-
equals
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 withObjects::equals(Object,Object). -
columnsByName
Returns the value of thecolumnsByNamerecord component.- Returns:
- the value of the
columnsByNamerecord component
-
columnsByIndex
Returns the value of thecolumnsByIndexrecord component.- Returns:
- the value of the
columnsByIndexrecord component
-
columnIndexMap
Returns the value of thecolumnIndexMaprecord component.- Returns:
- the value of the
columnIndexMaprecord component
-