org.opengts.dbtools
Class DBRecordIterator<DBR extends DBRecord>

java.lang.Object
  extended by org.opengts.dbtools.DBRecordIterator<DBR>

public class DBRecordIterator<DBR extends DBRecord>
extends java.lang.Object

DBRecordIterator is used to iterate through a DBRecord selection.
This DBRecordIterator currently uses the SQL DB provider OFFSET/LIMIT keywords to iterate through a selection, and thus is only supported by DB providers that support these keywords. This method has the disadvantage that record insertions/deletions occurring while this DBRecordIterator is in use may cause this iterator to possibly miss some records, or produce duplicate records.


Field Summary
static long DEFAULT_LIMIT
           
 
Constructor Summary
DBRecordIterator(DBR[] records)
          Constructor
DBRecordIterator(DBSelect<DBR> dbSel)
          Constructor
DBRecordIterator(java.lang.Iterable<DBR> iterable)
          Constructor
DBRecordIterator(java.util.Iterator<DBR> iterator)
          Constructor
 
Method Summary
protected  java.util.Iterator<DBR> fetch()
          Preloads the next block of records to return.
protected  DBSelect<DBR> getDBSelect()
           
 long getLimit()
          Gets the block size limit
 boolean hasNext()
          Returns true if another DBRecord is available from the iterator
 DBR next()
          Returns the next object from the iterator
 void setLimit(long limit)
          Sets the limit block size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_LIMIT

public static final long DEFAULT_LIMIT
See Also:
Constant Field Values
Constructor Detail

DBRecordIterator

public DBRecordIterator(DBR[] records)
Constructor

Parameters:
records - An array of DBRecord

DBRecordIterator

public DBRecordIterator(java.lang.Iterable<DBR> iterable)
Constructor

Parameters:
iterable - An Iterable

DBRecordIterator

public DBRecordIterator(java.util.Iterator<DBR> iterator)
Constructor

Parameters:
iterator - An iterator

DBRecordIterator

public DBRecordIterator(DBSelect<DBR> dbSel)
                 throws DBException
Constructor

Parameters:
dbSel - The DBSelect instance
Throws:
DBException - if the DBProvider does not support offset/limit.
Method Detail

getLimit

public long getLimit()
Gets the block size limit

Returns:
The block size limit

setLimit

public void setLimit(long limit)
Sets the limit block size

Parameters:
limit - The block size limit

hasNext

public boolean hasNext()
                throws DBException
Returns true if another DBRecord is available from the iterator

Returns:
True if another DBRecord is available from the iterator
Throws:
DBException - if a DB access error occurs.

next

public DBR next()
                          throws DBException,
                                 DBNotFoundException
Returns the next object from the iterator

Returns:
The next object
Throws:
DBException - if a DB access error occurs.
DBNotFoundException - if there ore no more DBRecords to return

getDBSelect

protected DBSelect<DBR> getDBSelect()

fetch

protected java.util.Iterator<DBR> fetch()
                                                  throws DBException,
                                                         DBNotFoundException
Preloads the next block of records to return.

Returns:
The DBRecord iterator
Throws:
DBException
DBNotFoundException