com.ibm.pdq.runtime.data.handlers
Class BaseResultIterator<T>

java.lang.Object
  extended by com.ibm.pdq.runtime.data.handlers.BaseResultIterator<T>
All Implemented Interfaces:
ResultIterator<T>, Iterator<T>
Direct Known Subclasses:
CallResultIterator, PagingResultIterator

public class BaseResultIterator<T>
extends Object
implements ResultIterator<T>

The BaseResultIterator<T> class allows the contents of the results of an SQL statement to be processed as an Iterator in which each row will be returned in a specified format. The format in which each row will be returned is specified in the call to the constructor. The class has appropriate methods for returning the contents of the results. These methods include hasNext(), which indicates if a "next" result row is available, next(), which returns the formatted contents of the "next" row, and close(), which closes the ResultIterator, along with freeing all associated data source resources.


Constructor Summary

Constructor Summary
Constructor and Description
BaseResultIterator(ResultSet resultSet, RowHandler<T> singleRowHandler)
Constructs an instance of BaseResultIterator<T> which allows the contents of the results of an SQL statement to be processed as an Iterator in which each row will be returned in a specified format.

Method Summary

Method Summary
Return Data TypeMethod Name and Description
void close()
Closes this instance of ResultIterator<T> and closes the ResultSet associated with the ResultIterator, along with the Statement that created the ResultSet (if possible), freeing all associated data source resources.
boolean hasNext()
Returns true if there is a "next" row available in the query results and false otherwise.
T next()
When there is a "next" row available in the query results, returns contents of that row in the format that was specified when the constructor was called.
void remove()
The remove() operation is not supported for this implementation of Iterator.

Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail

BaseResultIterator

public BaseResultIterator(ResultSet resultSet,
                          RowHandler<T> singleRowHandler)
Constructs an instance of BaseResultIterator<T> which allows the contents of the results of an SQL statement to be processed as an Iterator in which each row will be returned in a specified format. The format in which each row will be returned is indicated by singleRowHandler.
Parameters:
resultSet - A ResultSet representing the results from an SQL statement.
singleRowHandler - The instance of RowHandler that will be used to process each row from resultSet.

Method Detail

close

public void close()
Closes this instance of ResultIterator<T> and closes the ResultSet associated with the ResultIterator, along with the Statement that created the ResultSet (if possible), freeing all associated data source resources. No Exception will occur if the ResultSet and/or the Statement is already closed.
Specified by:
close in interface ResultIterator<T>
See Also:
ResultSet.close(), Statement.close()

hasNext

public boolean hasNext()
Returns true if there is a "next" row available in the query results and false otherwise. hasNext() should be called before calling next().
Specified by:
hasNext in interface Iterator<T>
Returns:
true if there is a "next" row available in the query results and false otherwise.

next

public T next()
When there is a "next" row available in the query results, returns contents of that row in the format that was specified when the constructor was called.

A NoSuchElementException will be thrown if this is called when no "next" row is available. Therefore, hasNext() should be called before next() is called to determine that there is a "next" row.

Specified by:
next in interface Iterator<T>
Returns:
Contents of the "next" row of the query results in the format that was specified when the constructor was called.

remove

public void remove()
The remove() operation is not supported for this implementation of Iterator.
Specified by:
remove in interface Iterator<T>