Package io.github.connellite.jdbc
Class AbstractResultSetIterator<V>
java.lang.Object
io.github.connellite.jdbc.AbstractResultSetIterator<V>
- Type Parameters:
V- map value type
- All Implemented Interfaces:
AutoCloseable,Iterator<Map<String,V>>
- Direct Known Subclasses:
ResultSetIterator,ResultSetStringIterator
public abstract class AbstractResultSetIterator<V>
extends Object
implements Iterator<Map<String,V>>, AutoCloseable
Forward-only iterator over JDBC query rows. Subclasses map the current
ResultSet row.
This type implements only Iterator (not Iterable) so APIs with overloads for both
(for example org.jooq.lambda.Seq.seq) remain unambiguous when passed this instance.
For enhanced for-loops use asIterable(); it is single-pass and delegates to this iterator.
Closing releases the result set and statement from construction.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionExecutes a boundNamedPreparedStatementand prepares iteration over rows.AbstractResultSetIterator(Connection conn, String query, Object... params) Executesqueryonconnand prepares forward-only iteration over rows.AbstractResultSetIterator(ResultSet resultSet) Wraps an already openedResultSetand prepares iteration over current/remaining rows. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining, remove
-
Field Details
-
resultSet
-
columnNames
-
hasNextValue
protected boolean hasNextValue
-
-
Constructor Details
-
AbstractResultSetIterator
public AbstractResultSetIterator(Connection conn, String query, Object... params) throws SQLException Executesqueryonconnand prepares forward-only iteration over rows.- Throws:
SQLException
-
AbstractResultSetIterator
Executes a boundNamedPreparedStatementand prepares iteration over rows. All named parameters must be bound before execution; seeNamedPreparedStatement.executeQuery(). Closing the iterator closes only the returnedResultSet; the named statement lifecycle is external.- Throws:
SQLException
-
AbstractResultSetIterator
Wraps an already openedResultSetand prepares iteration over current/remaining rows.- Throws:
SQLException
-
-
Method Details
-
asIterable
Single-passIterableview for enhanced for-loops.Iterable.iterator()returnsthis; one traversal consumes theResultSet. -
hasNext
public boolean hasNext() -
next
-
close
Closes underlyingResultSet.- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-