Package org.apache.commons.dbutils
Class ResultSetIterator
- java.lang.Object
-
- org.apache.commons.dbutils.ResultSetIterator
-
- All Implemented Interfaces:
java.util.Iterator<java.lang.Object[]>
public class ResultSetIterator extends java.lang.Object implements java.util.Iterator<java.lang.Object[]>
Wraps a
ResultSet
in anIterator<Object[]>
. 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.
-
-
Field Summary
Fields Modifier and Type Field Description private RowProcessor
convert
The processor to use when converting a row into an Object[].private java.sql.ResultSet
rs
The wrappedResultSet
.
-
Constructor Summary
Constructors Constructor Description ResultSetIterator(java.sql.ResultSet rs)
Constructor for ResultSetIterator.ResultSetIterator(java.sql.ResultSet rs, RowProcessor convert)
Constructor for ResultSetIterator.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
hasNext()
Returns true if there are more rows in the ResultSet.static java.lang.Iterable<java.lang.Object[]>
iterable(java.sql.ResultSet rs)
Generates anIterable
, suitable for use in for-each loops.java.lang.Object[]
next()
Returns the next row as anObject[]
.void
remove()
Deletes the current row from theResultSet
.protected void
rethrow(java.sql.SQLException e)
Rethrow the SQLException as a RuntimeException.
-
-
-
Field Detail
-
rs
private final java.sql.ResultSet rs
The wrappedResultSet
.
-
convert
private final RowProcessor convert
The processor to use when converting a row into an Object[].
-
-
Constructor Detail
-
ResultSetIterator
public ResultSetIterator(java.sql.ResultSet rs)
Constructor for ResultSetIterator.- Parameters:
rs
- Wrap thisResultSet
in anIterator
.
-
ResultSetIterator
public ResultSetIterator(java.sql.ResultSet rs, RowProcessor convert)
Constructor for ResultSetIterator.- Parameters:
rs
- Wrap thisResultSet
in anIterator
.convert
- The processor to use when converting a row into anObject[]
. Defaults to aBasicRowProcessor
.
-
-
Method Detail
-
hasNext
public boolean hasNext()
Returns true if there are more rows in the ResultSet.- Specified by:
hasNext
in interfacejava.util.Iterator<java.lang.Object[]>
- Returns:
- boolean
true
if there are more rows - Throws:
java.lang.RuntimeException
- if an SQLException occurs.
-
next
public java.lang.Object[] next()
Returns the next row as anObject[]
.- Specified by:
next
in interfacejava.util.Iterator<java.lang.Object[]>
- Returns:
- An
Object[]
with the same number of elements as columns in theResultSet
. - Throws:
java.lang.RuntimeException
- if an SQLException occurs.- See Also:
Iterator.next()
-
remove
public void remove()
Deletes the current row from theResultSet
.- Specified by:
remove
in interfacejava.util.Iterator<java.lang.Object[]>
- Throws:
java.lang.RuntimeException
- if an SQLException occurs.- See Also:
Iterator.remove()
-
rethrow
protected void rethrow(java.sql.SQLException e)
Rethrow the SQLException as a RuntimeException. This implementation creates a new RuntimeException with the SQLException's error message.- Parameters:
e
- SQLException to rethrow- Since:
- DbUtils 1.1
-
iterable
public static java.lang.Iterable<java.lang.Object[]> iterable(java.sql.ResultSet rs)
Generates anIterable
, suitable for use in for-each loops.- Parameters:
rs
- Wrap thisResultSet
in anIterator
.- Returns:
- an
Iterable
, suitable for use in for-each loops.
-
-