com.j256.ormlite.stmt
Class SelectIterator<T,ID>

java.lang.Object
  extended by com.j256.ormlite.stmt.SelectIterator<T,ID>
All Implemented Interfaces:
CloseableIterator<T>, Iterator<T>

public class SelectIterator<T,ID>
extends Object
implements CloseableIterator<T>

Internal iterator so we can page through the class. This is used by the Dao.iterator() methods.

Author:
graywatson

Constructor Summary
SelectIterator(Class<?> dataClass, Dao<T,ID> classDao, GenericRowMapper<T> rowMapper, ConnectionSource connectionSource, DatabaseConnection connection, CompiledStatement compiledStmt, String statement, ObjectCache objectCache)
          If the statement parameter is null then this won't log information
 
Method Summary
 void close()
          Close any underlying SQL statements.
 void closeQuietly()
          Close any underlying SQL statements but swallow any SQLExceptions.
 T current()
          Return the current result object that we have accessed or null if none.
 T first()
          Move to the first result and return it or null if none.
 DatabaseResults getRawResults()
          Return the underlying database results object if any.
 boolean hasNext()
          Returns whether or not there are any remaining objects in the table.
 boolean hasNextThrow()
          Returns whether or not there are any remaining objects in the table.
 T moveRelative(int offset)
          Move a relative position in the list and return that result or null if none.
 void moveToNext()
          Move to the next item in the iterator without calling Iterator.next().
 T next()
          Returns the next object in the table.
 T nextThrow()
          Returns the Iterator.next() object in the table or null if none.
 T previous()
          Moves to the previous result and return it or null if none.
 void remove()
          Removes the last object returned by next() by calling delete on the dao associated with the object.
 void removeThrow()
          Removes the last object returned by next() by calling delete on the dao associated with the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SelectIterator

public SelectIterator(Class<?> dataClass,
                      Dao<T,ID> classDao,
                      GenericRowMapper<T> rowMapper,
                      ConnectionSource connectionSource,
                      DatabaseConnection connection,
                      CompiledStatement compiledStmt,
                      String statement,
                      ObjectCache objectCache)
               throws SQLException
If the statement parameter is null then this won't log information

Throws:
SQLException
Method Detail

hasNextThrow

public boolean hasNextThrow()
                     throws SQLException
Returns whether or not there are any remaining objects in the table. Can be called before next().

Throws:
SQLException - If there was a problem getting more results via SQL.

hasNext

public boolean hasNext()
Returns whether or not there are any remaining objects in the table. Can be called before next().

Specified by:
hasNext in interface Iterator<T>
Throws:
IllegalStateException - If there was a problem getting more results via SQL.

first

public T first()
        throws SQLException
Description copied from interface: CloseableIterator
Move to the first result and return it or null if none. This may not work with the default iterator depending on your database.

Specified by:
first in interface CloseableIterator<T>
Throws:
SQLException

previous

public T previous()
           throws SQLException
Description copied from interface: CloseableIterator
Moves to the previous result and return it or null if none. This may not work with the default iterator depending on your database.

Specified by:
previous in interface CloseableIterator<T>
Throws:
SQLException

current

public T current()
          throws SQLException
Description copied from interface: CloseableIterator
Return the current result object that we have accessed or null if none.

Specified by:
current in interface CloseableIterator<T>
Throws:
SQLException

nextThrow

public T nextThrow()
            throws SQLException
Description copied from interface: CloseableIterator
Returns the Iterator.next() object in the table or null if none.

Specified by:
nextThrow in interface CloseableIterator<T>
Throws:
SQLException - Throws a SQLException on error since Iterator.next() cannot throw because it is part of the Iterator definition. It will not throw if there is no next.

next

public T next()
Returns the next object in the table.

Specified by:
next in interface Iterator<T>
Throws:
IllegalStateException - If there was a problem extracting the object from SQL.

moveRelative

public T moveRelative(int offset)
               throws SQLException
Description copied from interface: CloseableIterator
Move a relative position in the list and return that result or null if none. Moves forward (positive value) or backwards (negative value) the list of results. moveRelative(1) should be the same as Iterator.next(). moveRelative(-1) is the same as CloseableIterator.previous() result. This may not work with the default iterator depending on your database.

Specified by:
moveRelative in interface CloseableIterator<T>
Parameters:
offset - Number of rows to move. Positive moves forward in the results. Negative moves backwards.
Throws:
SQLException

removeThrow

public void removeThrow()
                 throws SQLException
Removes the last object returned by next() by calling delete on the dao associated with the object.

Throws:
IllegalStateException - If there was no previous next() call.
SQLException - If the delete failed.

remove

public void remove()
Removes the last object returned by next() by calling delete on the dao associated with the object.

Specified by:
remove in interface Iterator<T>
Throws:
IllegalStateException - If there was no previous next() call or if delete() throws a SQLException (set as the cause).

close

public void close()
           throws SQLException
Description copied from interface: CloseableIterator
Close any underlying SQL statements.

Specified by:
close in interface CloseableIterator<T>
Throws:
SQLException

closeQuietly

public void closeQuietly()
Description copied from interface: CloseableIterator
Close any underlying SQL statements but swallow any SQLExceptions.

Specified by:
closeQuietly in interface CloseableIterator<T>

getRawResults

public DatabaseResults getRawResults()
Description copied from interface: CloseableIterator
Return the underlying database results object if any. May return null. This should not be used unless you know what you are doing.

Specified by:
getRawResults in interface CloseableIterator<T>

moveToNext

public void moveToNext()
Description copied from interface: CloseableIterator
Move to the next item in the iterator without calling Iterator.next().

Specified by:
moveToNext in interface CloseableIterator<T>


This documentation is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.