org.deegree.commons.jdbc
Class ResultSetIterator<T>

java.lang.Object
  extended by org.deegree.commons.jdbc.ResultSetIterator<T>
Type Parameters:
T - type of the iterated objects
All Implemented Interfaces:
Iterator<T>, CloseableIterator<T>

public abstract class ResultSetIterator<T>
extends Object
implements CloseableIterator<T>

Abstract base class for easy implementation of CloseableIterators that are backed by an SQL result set.

Version:
$Revision: 22129 $, $Date: 2010-01-21 19:03:13 +0100 (Thu, 21 Jan 2010) $
Author:
Markus Schneider, last edited by: $Author: mschneider $

Constructor Summary
protected ResultSetIterator(ResultSet rs, Connection conn, Statement stmt)
          Creates a new ResultSetIterator instance.
 
Method Summary
 void close()
          Frees all underlying resources, no other method calls are permitted after calling this.
protected abstract  T createElement(ResultSet rs)
          Invoked to create the next element in the iteration sequence from the ResultSet (usually from one row).
 Collection<T> getAsCollectionAndClose(Collection<T> collection)
          Copies the elements into the given Collection and closes the iterator.
 List<T> getAsListAndClose()
          Returns the elements as an easy accessible List and closes the iterator.
 boolean hasNext()
           
 T next()
           
 void remove()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResultSetIterator

protected ResultSetIterator(ResultSet rs,
                            Connection conn,
                            Statement stmt)
Creates a new ResultSetIterator instance.

Parameters:
rs - result set that the iterator uses to build the elements, must not be null
conn - connection that was used to obtain the result set, must not be null
stmt - statement that was used to obtain the result set, must not be null
Method Detail

close

public void close()
Description copied from interface: CloseableIterator
Frees all underlying resources, no other method calls are permitted after calling this.

Specified by:
close in interface CloseableIterator<T>

hasNext

public boolean hasNext()
Specified by:
hasNext in interface Iterator<T>

next

public T next()
Specified by:
next in interface Iterator<T>

createElement

protected abstract T createElement(ResultSet rs)
                            throws SQLException
Invoked to create the next element in the iteration sequence from the ResultSet (usually from one row).

Parameters:
rs - result set that is used to build the element, this is never null
Returns:
new element from the iteration sequence
Throws:
SQLException - if the accessing of the result set or element creation fails

remove

public void remove()
Specified by:
remove in interface Iterator<T>

getAsListAndClose

public List<T> getAsListAndClose()
Description copied from interface: CloseableIterator
Returns the elements as an easy accessible List and closes the iterator.

NOTE: This should only be used for small numbers of elements.

Specified by:
getAsListAndClose in interface CloseableIterator<T>
Returns:
list that contains all elements, never null

getAsCollectionAndClose

public Collection<T> getAsCollectionAndClose(Collection<T> collection)
Description copied from interface: CloseableIterator
Copies the elements into the given Collection and closes the iterator.

Specified by:
getAsCollectionAndClose in interface CloseableIterator<T>
Parameters:
collection - collection where the elements are copied, must not be null
Returns:
collection that contains all elements, same instance as the parameter


Copyright © 2011. All Rights Reserved.