com.hp.hpl.mesa.rdf.jena.rdb
Class ResultSetIterator

java.lang.Object
  |
  +--com.hp.hpl.mesa.rdf.jena.rdb.ResultSetIterator
All Implemented Interfaces:
ClosableIterator, java.util.Iterator
Direct Known Subclasses:
ResultSetResourceIterator, ResultSetStatementIterator, ResultSetStringIterator

public class ResultSetIterator
extends java.lang.Object
implements java.util.Iterator, ClosableIterator

Iterates over an SQL result set returning each row as an ArrayList of objects. The returned array is shared at each iteration so calling next() or even hasNext() changes the array contents. When the iterator terminates the resources are cleaned up and the underlying SQL PreparedStatement is returned to the SQLCache pool from whence it came.

Override the extractRow and getRow methods in subclasses to return an object collection derived from the row contents instead of the raw row contents.

Version:
$Revision: 1.2 $ on $Date: 2001/11/26 18:20:10 $
Author:
Dave Reynolds

Constructor Summary
ResultSetIterator()
          Create an empty iterator.
ResultSetIterator(java.sql.ResultSet resultSet, java.sql.PreparedStatement sourceStatement)
          Iterate over the results of a PreparedStatement, close the statement when finished.
ResultSetIterator(java.sql.ResultSet resultSet, java.sql.PreparedStatement sourceStatement, SQLCache cache, java.lang.String opname)
          Iterate over the results of a PreparedStatement generated by an SQLCache
 
Method Summary
 void close()
          Clean up the allocated resources - result set and statement.
 java.lang.Object getSingleton()
          Get a singleton result (single column from single row) and close the iterator.
 boolean hasNext()
          Test if there is a next result to return
 java.lang.Object next()
          Return the current row
 void remove()
          Delete the current row entry
 void reset(java.sql.ResultSet resultSet, java.sql.PreparedStatement sourceStatement, SQLCache cache, java.lang.String opname)
          Reset an existing iterator to scan a new result set.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResultSetIterator

public ResultSetIterator()
Create an empty iterator. Needs to be initialized by {@list #reset reset} before it can be accessed. Useful to allow generic functions like {@link SQLCache#runSQLQuery runSQLQuery} to return different iterator types to the client.

ResultSetIterator

public ResultSetIterator(java.sql.ResultSet resultSet,
                         java.sql.PreparedStatement sourceStatement,
                         SQLCache cache,
                         java.lang.String opname)
Iterate over the results of a PreparedStatement generated by an SQLCache
Parameters:
resultSet - the result set being iterated over
sourceStatement - The source Statement to be cleaned up when the iterator finishes - return it to cache or close it if no cache
cache - The originating SQLcache to return the statement to, can be null
opname - The name of the original operation that lead to this statement, can be null if SQLCache is null

ResultSetIterator

public ResultSetIterator(java.sql.ResultSet resultSet,
                         java.sql.PreparedStatement sourceStatement)
Iterate over the results of a PreparedStatement, close the statement when finished.
Parameters:
resultSet - the result set being iterated over
sourceStatement - The source Statement to be closed when the iterator finishes
Method Detail

reset

public void reset(java.sql.ResultSet resultSet,
                  java.sql.PreparedStatement sourceStatement,
                  SQLCache cache,
                  java.lang.String opname)
Reset an existing iterator to scan a new result set.
Parameters:
resultSet - the result set being iterated over
sourceStatement - The source Statement to be cleaned up when the iterator finishes - return it to cache or close it if no cache
cache - The originating SQLcache to return the statement to, can be null
opname - The name of the original operation that lead to this statement, can be null if SQLCache is null

hasNext

public boolean hasNext()
Test if there is a next result to return
Specified by:
hasNext in interface java.util.Iterator

next

public java.lang.Object next()
Return the current row
Specified by:
next in interface java.util.Iterator

remove

public void remove()
Delete the current row entry
Specified by:
remove in interface java.util.Iterator

close

public void close()
Clean up the allocated resources - result set and statement. If we know of an SQLCache return the statement there, otherwise close it.
Specified by:
close in interface ClosableIterator

getSingleton

public java.lang.Object getSingleton()
                              throws java.sql.SQLException
Get a singleton result (single column from single row) and close the iterator. This may be too specialized but seems to come up a lot - rethink.


Copyright © 2001 Hewlett-Packard. All Rights Reserved.