Class SqlResult

java.lang.Object
com.loomcache.server.query.SqlResult
All Implemented Interfaces:
AutoCloseable, Iterable<SqlRow>

public class SqlResult extends Object implements AutoCloseable, Iterable<SqlRow>
Represents a SQL query result set. Provides iteration over rows, metadata about columns, and resource management.

Result sets must be closed after use to release any associated resources. Implements AutoCloseable for try-with-resources usage.

Thread-safe after construction only if the underlying row iterator is thread-safe.

  • Constructor Details

    • SqlResult

      public SqlResult(List<String> columnNames, List<SqlColumnType> columnTypes, Iterator<SqlRow> rowIterator, int estimatedRowCount)
      Creates a new SqlResult.
      Parameters:
      columnNames - ordered list of column names (non-null, non-empty)
      columnTypes - types of each column, parallel to columnNames (non-null)
      rowIterator - iterator over result rows (non-null)
      estimatedRowCount - estimated total row count (-1 if unknown)
      Throws:
      NullPointerException - if any non-null parameter is null
      IllegalArgumentException - if columnNames or columnTypes are empty
    • SqlResult

      public SqlResult(List<String> columnNames, List<SqlColumnType> columnTypes, Iterator<SqlRow> rowIterator, int estimatedRowCount, boolean truncated)
      Creates a new SqlResult.
      Parameters:
      columnNames - ordered list of column names (non-null, non-empty)
      columnTypes - types of each column, parallel to columnNames (non-null)
      rowIterator - iterator over result rows (non-null)
      estimatedRowCount - estimated total row count (-1 if unknown)
      truncated - true when a safety cap truncated the result set
      Throws:
      NullPointerException - if any non-null parameter is null
      IllegalArgumentException - if columnNames or columnTypes are empty
  • Method Details

    • getColumnNames

      public List<String> getColumnNames()
      Gets the list of column names in order.
      Returns:
      unmodifiable list of column names (non-empty)
      Throws:
      IllegalStateException - if the result set is closed
    • getColumnTypes

      public List<SqlColumnType> getColumnTypes()
      Gets the list of column types in order.
      Returns:
      unmodifiable list of column types, parallel to column names
      Throws:
      IllegalStateException - if the result set is closed
    • getColumnCount

      public int getColumnCount()
      Gets the number of columns.
      Returns:
      the column count (greater than 0)
      Throws:
      IllegalStateException - if the result set is closed
    • iterator

      public Iterator<SqlRow> iterator()
      Returns an iterator over the result rows.
      Specified by:
      iterator in interface Iterable<SqlRow>
      Returns:
      an iterator over remaining rows
      Throws:
      IllegalStateException - if the result set is closed
    • toList

      public List<SqlRow> toList()
      Consumes all remaining rows and returns them as a list.
      Returns:
      list of all remaining rows (may be empty)
      Throws:
      IllegalStateException - if the result set is closed
    • close

      public void close()
      Closes this result set, releasing any associated resources.

      After closing, attempts to iterate or access columns will throw IllegalStateException. This method is idempotent and safe to call multiple times.

      Specified by:
      close in interface AutoCloseable