public class ResultSetIterator
extends java.lang.Object
implements java.util.Iterator
Wraps a ResultSet
in an Iterator
. This is useful
when you want to present a non-database application layer with domain
neutral data.
This implementation requires the ResultSet.isLast()
method
to be implemented.
Modifier and Type | Field and Description |
---|---|
private RowProcessor |
convert
The processor to use when converting a row into an Object[].
|
private java.sql.ResultSet |
rs
The wrapped
ResultSet . |
Constructor and Description |
---|
ResultSetIterator(java.sql.ResultSet rs)
Constructor for ResultSetIterator.
|
ResultSetIterator(java.sql.ResultSet rs,
RowProcessor convert)
Constructor for ResultSetIterator.
|
Modifier and Type | Method and Description |
---|---|
boolean |
hasNext()
Returns true if there are more rows in the ResultSet.
|
java.lang.Object |
next()
Returns the next row as an
Object[] . |
void |
remove()
Deletes the current row from the
ResultSet . |
protected void |
rethrow(java.sql.SQLException e)
Rethrow the SQLException as a RuntimeException.
|
private java.sql.ResultSet rs
ResultSet
.private RowProcessor convert
public ResultSetIterator(java.sql.ResultSet rs)
rs
- Wrap this ResultSet
in an Iterator
.public ResultSetIterator(java.sql.ResultSet rs, RowProcessor convert)
rs
- Wrap this ResultSet
in an Iterator
.convert
- The processor to use when converting a row into an
Object[]
. Defaults to a
BasicRowProcessor
.public boolean hasNext()
hasNext
in interface java.util.Iterator
true
if there are more rowsjava.lang.RuntimeException
- if an SQLException occurs.public java.lang.Object next()
Object[]
.next
in interface java.util.Iterator
Object[]
with the same number of elements as
columns in the ResultSet
.java.lang.RuntimeException
- if an SQLException occurs.Iterator.next()
public void remove()
ResultSet
.remove
in interface java.util.Iterator
java.lang.RuntimeException
- if an SQLException occurs.Iterator.remove()
protected void rethrow(java.sql.SQLException e)
e
- SQLException to rethrow