Record Class QueryResult

java.lang.Object
java.lang.Record
org.approvej.database.jdbc.QueryResult
Record Components:
columnNames - the column headers
rows - each row as a list of string-rendered cell values

@NullMarked public record QueryResult(List<String> columnNames, List<List<String>> rows) extends Record
Represents the result of a database query as column names and row data.

Use of(ResultSet) to create an instance from a JDBC ResultSet, or construct one directly for testing purposes.

  • Constructor Details

    • QueryResult

      public QueryResult(List<String> columnNames, List<List<String>> rows)
      Compact constructor to ensure immutability.
  • Method Details

    • of

      public static QueryResult of(ResultSet resultSet) throws SQLException
      Materializes the given ResultSet into a QueryResult.

      The result set is consumed from its current position to the end. It is not closed by this method.

      Parameters:
      resultSet - the result set to read
      Returns:
      the materialized query result
      Throws:
      SQLException - if a database access error occurs
    • 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.
    • columnNames

      public List<String> columnNames()
      Returns the value of the columnNames record component.
      Returns:
      the value of the columnNames record component
    • rows

      public List<List<String>> rows()
      Returns the value of the rows record component.
      Returns:
      the value of the rows record component