org.jooq
Interface Cursor<R extends Record>

Type Parameters:
R - The cursor's record type
All Superinterfaces:
FieldProvider, Iterable<R>

public interface Cursor<R extends Record>
extends FieldProvider, Iterable<R>

Cursors allow for lazy, sequential access to an underlying JDBC ResultSet. Unlike Result, data can only be accessed sequentially, using an Iterator, or the cursor's hasNext() and fetch() methods.

Client code must close this Cursor in order to close the underlying PreparedStatement and ResultSet

Note: Unlike usual implementations of Iterable, a Cursor can only provide one Iterator!

Author:
Lukas Eder

Method Summary
 void close()
          Explicitly close the underlying PreparedStatement and ResultSet If you fetch all records from the underlying ResultSet, jOOQ Cursor implementations will close themselves for you.
 Result<R> fetch()
          Fetch all remaining records as a result.
 Result<R> fetch(int number)
          Fetch the next couple of records from the cursor.
<E> List<E>
fetchInto(Class<? extends E> type)
          Map resulting records onto a custom type.
<H extends RecordHandler<R>>
H
fetchInto(H handler)
          Fetch results into a custom handler callback The resulting records are attached to the original Configuration by default.
<Z extends Record>
Result<Z>
fetchInto(Table<Z> table)
          Map resulting records onto a custom record.
 R fetchOne()
          Fetch the next record from the cursor This will conveniently close the Cursor, after the last Record was fetched.
<E> E
fetchOneInto(Class<? extends E> type)
          Map the next resulting record onto a custom type.
<H extends RecordHandler<R>>
H
fetchOneInto(H handler)
          Fetch the next record into a custom handler callback This will conveniently close the Cursor, after the last Record was fetched.
<Z extends Record>
Z
fetchOneInto(Table<Z> table)
          Map the next resulting record onto a custom record.
 boolean hasNext()
          Check whether this cursor has a next record This will conveniently close the Cursor, after the last Record was fetched.
 boolean isClosed()
          Check whether this Cursor has been explicitly or "conveniently" closed.
 ResultSet resultSet()
          Get the Cursor's underlying ResultSet If you modify the underlying ResultSet, the Cursor may be affected and in some cases, rendered unusable.
 
Methods inherited from interface org.jooq.FieldProvider
getField, getField, getField, getFields, getIndex
 
Methods inherited from interface java.lang.Iterable
iterator
 

Method Detail

hasNext

boolean hasNext()
                throws DataAccessException
Check whether this cursor has a next record

This will conveniently close the Cursor, after the last Record was fetched.

Throws:
DataAccessException - if something went wrong executing the query

fetch

Result<R> fetch()
                               throws DataAccessException
Fetch all remaining records as a result.

This will conveniently close the Cursor, after the last Record was fetched.

The result and its contained records are attached to the original Configuration by default. Use Settings.isAttachRecords() to override this behaviour.

Throws:
DataAccessException - if something went wrong executing the query

fetch

Result<R> fetch(int number)
                               throws DataAccessException
Fetch the next couple of records from the cursor.

This will conveniently close the Cursor, after the last Record was fetched.

The result and its contained records are attached to the original Configuration by default. Use Settings.isAttachRecords() to override this behaviour.

Parameters:
number - The number of records to fetch. If this is 0 or negative an empty list is returned, the cursor is untouched. If this is greater than the number of remaining records, then all remaining records are returned.
Throws:
DataAccessException - if something went wrong executing the query

fetchOne

R fetchOne()
                          throws DataAccessException
Fetch the next record from the cursor

This will conveniently close the Cursor, after the last Record was fetched.

The resulting record is attached to the original Configuration by default. Use Settings.isAttachRecords() to override this behaviour.

Returns:
The next record from the cursor, or null if there is no next record.
Throws:
DataAccessException - if something went wrong executing the query

fetchOneInto

<H extends RecordHandler<R>> H fetchOneInto(H handler)
                                        throws DataAccessException
Fetch the next record into a custom handler callback

This will conveniently close the Cursor, after the last Record was fetched.

The resulting record is attached to the original Configuration by default. Use Settings.isAttachRecords() to override this behaviour.

Parameters:
handler - The handler callback
Returns:
Convenience result, returning the parameter handler itself
Throws:
DataAccessException - if something went wrong executing the query

fetchInto

<H extends RecordHandler<R>> H fetchInto(H handler)
                                     throws DataAccessException
Fetch results into a custom handler callback

The resulting records are attached to the original Configuration by default. Use Settings.isAttachRecords() to override this behaviour.

Parameters:
handler - The handler callback
Returns:
Convenience result, returning the parameter handler itself
Throws:
DataAccessException - if something went wrong executing the query

fetchOneInto

<E> E fetchOneInto(Class<? extends E> type)
               throws DataAccessException,
                      MappingException
Map the next resulting record onto a custom type.

This is the same as calling fetchOne().into(type). See Record.into(Class) for more details

Type Parameters:
E - The generic entity type.
Parameters:
type - The entity type.
Throws:
DataAccessException - if something went wrong executing the query
MappingException - wrapping any reflection or data type conversion exception that might have occurred while mapping records
See Also:
Record.into(Class), Result.into(Class)

fetchInto

<E> List<E> fetchInto(Class<? extends E> type)
                  throws DataAccessException,
                         MappingException
Map resulting records onto a custom type.

This is the same as calling fetch().into(type). See Record.into(Class) for more details

Type Parameters:
E - The generic entity type.
Parameters:
type - The entity type.
Throws:
DataAccessException - if something went wrong executing the query
MappingException - wrapping any reflection or data type conversion exception that might have occurred while mapping records
See Also:
Record.into(Class), Result.into(Class)

fetchOneInto

<Z extends Record> Z fetchOneInto(Table<Z> table)
                              throws DataAccessException,
                                     MappingException
Map the next resulting record onto a custom record.

This is the same as calling fetchOne().into(table). See Record.into(Class) for more details

The resulting record is attached to the original Configuration by default. Use Settings.isAttachRecords() to override this behaviour.

Type Parameters:
Z - The generic table record type.
Parameters:
table - The table type.
Throws:
DataAccessException - if something went wrong executing the query
MappingException - wrapping any reflection or data type conversion exception that might have occurred while mapping records
See Also:
Record.into(Class), Result.into(Class)

fetchInto

<Z extends Record> Result<Z> fetchInto(Table<Z> table)
                                   throws DataAccessException,
                                          MappingException
Map resulting records onto a custom record.

This is the same as calling fetch().into(table). See Record.into(Class) for more details

The result and its contained records are attached to the original Configuration by default. Use Settings.isAttachRecords() to override this behaviour.

Type Parameters:
Z - The generic table record type.
Parameters:
table - The table type.
Throws:
DataAccessException - if something went wrong executing the query
MappingException - wrapping any reflection or data type conversion exception that might have occurred while mapping records
See Also:
Record.into(Class), Result.into(Class)

close

void close()
           throws DataAccessException
Explicitly close the underlying PreparedStatement and ResultSet

If you fetch all records from the underlying ResultSet, jOOQ Cursor implementations will close themselves for you. Calling close() again will have no effect.

Throws:
DataAccessException - if something went wrong executing the query

isClosed

boolean isClosed()
Check whether this Cursor has been explicitly or "conveniently" closed.

Explicit closing can be achieved by calling close() from client code. "Convenient" closing is done by any of the other methods, when the last record was fetched.


resultSet

ResultSet resultSet()
Get the Cursor's underlying ResultSet

If you modify the underlying ResultSet, the Cursor may be affected and in some cases, rendered unusable.

Returns:
The underlying ResultSet. May be null, for instance when the Cursor is closed.


Copyright © 2012. All Rights Reserved.