net.darkmist.alib.db
Class ResultSetIterator<E>

java.lang.Object
  extended by net.darkmist.alib.db.ResultSetIterator<E>
All Implemented Interfaces:
Iterator<E>
Direct Known Subclasses:
ResultSetLongIterator

public class ResultSetIterator<E>
extends Object
implements Iterator<E>

Iterator interface to a ResultSet.


Nested Class Summary
static interface ResultSetIterator.Row2Obj<E>
          ResultSet to Object conversion interface.
 
Constructor Summary
protected ResultSetIterator(Connection db, String sql)
           
protected ResultSetIterator(PreparedStatement stmt)
           
protected ResultSetIterator(PreparedStatement stmt, boolean exclusive)
           
  ResultSetIterator(PreparedStatement stmt, ResultSetIterator.Row2Obj<E> converter)
          Create a ResultSetIterator from a PreparedStatement.
  ResultSetIterator(PreparedStatement stmt, ResultSetIterator.Row2Obj<E> converter, boolean exclusive)
           
protected ResultSetIterator(ResultSet rs)
           
protected ResultSetIterator(ResultSet rs, boolean exclusive)
           
  ResultSetIterator(ResultSet rs, ResultSetIterator.Row2Obj<E> converter)
          Create a ResultSetIterator from a ResultSet.
 
Method Summary
 void close()
           
 boolean hasNext()
          More data to retrieve?
 E next()
          Return the next result.
 void remove()
          Unsupported remove operation.
protected  void setConverter(ResultSetIterator.Row2Obj<E> converter)
           
 ResultSetIterator<E> setExclusive()
           
 ResultSetIterator<E> setExclusive(boolean exclusive)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResultSetIterator

public ResultSetIterator(ResultSet rs,
                         ResultSetIterator.Row2Obj<E> converter)
                  throws SQLException
Create a ResultSetIterator from a ResultSet.

Parameters:
rs - The result set to iterate through.
converter - The ResultSetIterator.Row2Obj to convert rows to objects with.
Throws:
SQLException - if the ResultSet does when calling ResultSet.next().

ResultSetIterator

public ResultSetIterator(PreparedStatement stmt,
                         ResultSetIterator.Row2Obj<E> converter)
                  throws SQLException
Create a ResultSetIterator from a PreparedStatement.

Parameters:
stmt - The query PreparedStatement to execute and use results from.
converter - The ResultSetIterator.Row2Obj to convert rows to objects with.
Throws:
SQLException - if calling PreparedStatement.executeQuery() on stmt does or if calling ResultSet.next() on the resulting ResultSet does.

ResultSetIterator

public ResultSetIterator(PreparedStatement stmt,
                         ResultSetIterator.Row2Obj<E> converter,
                         boolean exclusive)
                  throws SQLException
Throws:
SQLException

ResultSetIterator

protected ResultSetIterator(ResultSet rs,
                            boolean exclusive)
                     throws SQLException
Throws:
SQLException

ResultSetIterator

protected ResultSetIterator(ResultSet rs)
                     throws SQLException
Throws:
SQLException

ResultSetIterator

protected ResultSetIterator(PreparedStatement stmt)
                     throws SQLException
Throws:
SQLException

ResultSetIterator

protected ResultSetIterator(PreparedStatement stmt,
                            boolean exclusive)
                     throws SQLException
Throws:
SQLException

ResultSetIterator

protected ResultSetIterator(Connection db,
                            String sql)
                     throws SQLException
Throws:
SQLException
Method Detail

setConverter

protected void setConverter(ResultSetIterator.Row2Obj<E> converter)
                     throws SQLException
Throws:
SQLException

close

public void close()
           throws SQLException
Throws:
SQLException

setExclusive

public ResultSetIterator<E> setExclusive(boolean exclusive)
                                  throws SQLException
Throws:
SQLException

setExclusive

public ResultSetIterator<E> setExclusive()
                                  throws SQLException
Throws:
SQLException

hasNext

public boolean hasNext()
More data to retrieve?

Specified by:
hasNext in interface Iterator<E>
Returns:
true if there is more data to retrieve.

next

public E next()
       throws NoSuchElementException
Return the next result.

Specified by:
next in interface Iterator<E>
Returns:
Result of converting the next row to an object using converter's ResultSetIterator.Row2Obj.resultSetIteratorRow2Obj(ResultSet) method.
Throws:
NoSuchElementException - if there are no more results.
IllegalStateException - For other exceptions caught from ResultSetIterator.Row2Obj.resultSetIteratorRow2Obj(ResultSet) or an SQLException from ResultSet.next().

remove

public void remove()
            throws UnsupportedOperationException
Unsupported remove operation.

Specified by:
remove in interface Iterator<E>
Throws:
UnsupportedOperationException - always


Copyright © 2012. All Rights Reserved.