2.17.2: 2011-06-17

net.sf.basedb.core
Class DynamicResultIterator

java.lang.Object
  extended by net.sf.basedb.core.DynamicResultIterator
All Implemented Interfaces:
Iterator<SqlResult>, QueryResult, ResultIterator<SqlResult>, SqlResultIterator

public class DynamicResultIterator
extends Object
implements SqlResultIterator

An iterator view of the result of an AbstractSqlQuery.

Version:
2.0
Author:
Nicklas
See Also:
AbstractSqlQuery.iterate(DbControl)
Last modified
$Date: 2009-04-06 14:52:39 +0200 (Mon, 06 Apr 2009) $

Nested Class Summary
private  class DynamicResultIterator.SqlResultImpl
          Implements the SqlResult interface.
 
Field Summary
private  boolean checkNext
           
private  boolean hasNext
           
private  boolean isClosed
           
private  int limit
           
private static Logger log
          Logger.
private  ResultSet results
          The results of the query.
private  int returnedRows
           
private  SqlResult sqlResult
           
private  long totalCount
          The total number of items.
 
Constructor Summary
DynamicResultIterator(ResultSet results, long totalCount, int limit)
          Create a new result iterator.
 
Method Summary
 void close()
          From the ResultIterator interface ---------------------------------
 int getIndex(String name)
          Get the index number of a selected column.
 long getTotalCount()
          From the QueryResult interface ---------------------------------
 boolean hasNext()
           
 boolean isClosed()
          Check if the iterator has been closed.
 SqlResult next()
          Get the results in the next row.
 void remove()
          Not supported.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final Logger log
Logger.


results

private final ResultSet results
The results of the query.


totalCount

private final long totalCount
The total number of items.


limit

private final int limit

returnedRows

private int returnedRows

sqlResult

private final SqlResult sqlResult

hasNext

private boolean hasNext

checkNext

private boolean checkNext

isClosed

private boolean isClosed
Constructor Detail

DynamicResultIterator

DynamicResultIterator(ResultSet results,
                      long totalCount,
                      int limit)
Create a new result iterator.

Parameters:
results - The ResultSet object containing the results
totalCount - The total number of rows
limit - The maximum numbre of rows that was specified for the query
Method Detail

getTotalCount

public long getTotalCount()
From the QueryResult interface ---------------------------------

Specified by:
getTotalCount in interface QueryResult
Returns:
The total number of items, or -1 if not known
See Also:
Query.setReturnTotalCount(boolean)

close

public void close()
From the ResultIterator interface ---------------------------------

Specified by:
close in interface ResultIterator<SqlResult>

isClosed

public boolean isClosed()
Description copied from interface: ResultIterator
Check if the iterator has been closed.

Specified by:
isClosed in interface ResultIterator<SqlResult>

hasNext

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

next

public SqlResult next()
Get the results in the next row. The actual SqlResult object is always the same object. It just changes the underlying pointer to the next row in the result set. If you need to store data from a previous row you must copy the values to another place.

Specified by:
next in interface Iterator<SqlResult>
Returns:
A SqlResult object
Throws:
NoSuchElementException - If there are no more results

remove

public void remove()
Not supported.

Specified by:
remove in interface Iterator<SqlResult>
Throws:
UnsupportedOperationException - Always

getIndex

public int getIndex(String name)
             throws SQLException
Description copied from interface: SqlResultIterator
Get the index number of a selected column. Use this method to find the index of a column and then use the SqlResult.getXxx(index) methods to get the value of that column.

Specified by:
getIndex in interface SqlResultIterator
Parameters:
name - The name of a selected column
Returns:
The index number
Throws:
SQLException - If there is an error

2.17.2: 2011-06-17