Class SqlResult
java.lang.Object
com.loomcache.server.query.SqlResult
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionSqlResult(List<String> columnNames, List<SqlColumnType> columnTypes, Iterator<SqlRow> rowIterator, int estimatedRowCount) Creates a new SqlResult.SqlResult(List<String> columnNames, List<SqlColumnType> columnTypes, Iterator<SqlRow> rowIterator, int estimatedRowCount, boolean truncated) Creates a new SqlResult. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this result set, releasing any associated resources.intGets the number of columns.Gets the list of column names in order.Gets the list of column types in order.iterator()Returns an iterator over the result rows.toList()Consumes all remaining rows and returns them as a list.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
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 nullIllegalArgumentException- 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 nullIllegalArgumentException- if columnNames or columnTypes are empty
-
-
Method Details
-
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
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
-
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:
closein interfaceAutoCloseable
-