-
- Type Parameters:
R
- The cursor's record type
- All Superinterfaces:
java.lang.AutoCloseable
,Formattable
,java.lang.Iterable<R>
public interface Cursor<R extends Record> extends java.lang.Iterable<R>, Formattable, java.lang.AutoCloseable
Cursors allow for lazy, sequential access to an underlying JDBCResultSet
. UnlikeResult
, data can only be accessed sequentially, using anIterator
, or the cursor'shasNext()
andfetch()
methods.Client code must close this
Cursor
in order to close the underlyingPreparedStatement
andResultSet
The cursor can be consumed in two ways:
- Record by record: Such methods can be recognised by the term "Next" in
the method name, e.g.
fetchNext(int)
. - Completely in one go: Such methods do not have the term "Next" in their
method names, e.g.
fetch()
.
Note: Unlike usual implementations of
Iterable
, aCursor
can only provide oneIterator
!- Author:
- Lukas Eder
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description void
close()
Explicitly close the underlyingPreparedStatement
andResultSet
.<X,A>
Xcollect(java.util.stream.Collector<? super R,A,X> collector)
Reduce the execution results of this query using aCollector
.Result<R>
fetch()
Fetch all remaining records as a result.Result<R>
fetch(int number)
Deprecated.- 3.10 - [#6363] - UsefetchNext(int)
instead.<E> java.util.List<E>
fetch(RecordMapper<? super R,E> mapper)
Fetch results into a custom mapper callback.<H extends RecordHandler<? super R>>
HfetchInto(H handler)
Fetch results into a custom handler callback.<E> java.util.List<E>
fetchInto(java.lang.Class<? extends E> type)
Map resulting records onto a custom type.<Z extends Record>
Result<Z>fetchInto(Table<Z> table)
Map resulting records onto a custom record.R
fetchNext()
Fetch the next record from the cursor.Result<R>
fetchNext(int number)
Fetch the next couple of records from the cursor.<E> E
fetchNext(RecordMapper<? super R,E> mapper)
Fetch the next record into a custom mapper callback.<H extends RecordHandler<? super R>>
HfetchNextInto(H handler)
Fetch the next record into a custom handler callback.<E> E
fetchNextInto(java.lang.Class<? extends E> type)
Map the next resulting record onto a custom type.<Z extends Record>
ZfetchNextInto(Table<Z> table)
Map the next resulting record onto a custom record.java.util.Optional<R>
fetchNextOptional()
Fetch the next record from the cursor.<E> java.util.Optional<E>
fetchNextOptional(RecordMapper<? super R,E> mapper)
Fetch the next record into a custom mapper callback.<E> java.util.Optional<E>
fetchNextOptionalInto(java.lang.Class<? extends E> type)
Map the next resulting record onto a custom type.<Z extends Record>
java.util.Optional<Z>fetchNextOptionalInto(Table<Z> table)
Map the next resulting record onto a custom record.R
fetchOne()
Deprecated.- 3.10 - [#6363] - UsefetchNext()
instead.<E> E
fetchOne(RecordMapper<? super R,E> mapper)
Deprecated.- 3.10 - [#6363] - UsefetchNext(RecordMapper)
instead.<H extends RecordHandler<? super R>>
HfetchOneInto(H handler)
Deprecated.- 3.10 - [#6363] - UsefetchNextInto(RecordHandler)
instead.<E> E
fetchOneInto(java.lang.Class<? extends E> type)
Deprecated.- 3.10 - [#6363] - UsefetchNextInto(Class)
instead.<Z extends Record>
ZfetchOneInto(Table<Z> table)
Deprecated.- 3.10 - [#6363] - UsefetchNextInto(Table)
instead.java.util.Optional<R>
fetchOptional()
Deprecated.- 3.10 - [#6363] - UsefetchNextOptional()
instead.<E> java.util.Optional<E>
fetchOptional(RecordMapper<? super R,E> mapper)
Deprecated.- 3.10 - [#6363] - UsefetchNextOptional(RecordMapper)
instead.<E> java.util.Optional<E>
fetchOptionalInto(java.lang.Class<? extends E> type)
Deprecated.- 3.10 - [#6363] - UsefetchNextOptionalInto(Class)
instead.<Z extends Record>
java.util.Optional<Z>fetchOptionalInto(Table<Z> table)
Deprecated.- 3.10 - [#6363] - UsefetchNextOptionalInto(Table)
instead.Field<?>
field(int index)
Get a specific field from this Cursor.Field<?>
field(java.lang.String name)
Get a specific field from this Cursor.<T> Field<T>
field(Field<T> field)
Get a specific field from this Cursor.Field<?>
field(Name name)
Get a specific qualified field from this Cursor.Field<?>[]
fields()
Get all fields from this Cursor.Field<?>[]
fields(int... fieldIndexes)
Get all fields from this Cursor, providing some field indexes.Field<?>[]
fields(java.lang.String... fieldNames)
Get all fields from this Cursor, providing some field names.Field<?>[]
fields(Field<?>... fields)
Get all fields from this Cursor, providing some fields.Field<?>[]
fields(Name... fieldNames)
Get all fields from this Cursor, providing some field names.Row
fieldsRow()
Get this cursor's fields as aRow
.boolean
hasNext()
Check whether this cursor has a next record.int
indexOf(java.lang.String fieldName)
Get a field's index from this cursor.int
indexOf(Field<?> field)
Get a field's index from this cursor.int
indexOf(Name fieldName)
Get a field's index from this cursor.boolean
isClosed()
Check whether thisCursor
has been explicitly or "conveniently" closed.RecordType<R>
recordType()
Get this cursor's row type.java.sql.ResultSet
resultSet()
Get theCursor
's underlyingResultSet
.java.util.stream.Stream<R>
stream()
Turn thisCursor
into aStream
.-
Methods inherited from interface org.jooq.Formattable
format, format, format, format, format, format, format, format, format, formatChart, formatChart, formatChart, formatChart, formatChart, formatChart, formatCSV, formatCSV, formatCSV, formatCSV, formatCSV, formatCSV, formatCSV, formatCSV, formatCSV, formatCSV, formatCSV, formatCSV, formatCSV, formatCSV, formatCSV, formatCSV, formatCSV, formatCSV, formatCSV, formatCSV, formatCSV, formatHTML, formatHTML, formatHTML, formatInsert, formatInsert, formatInsert, formatInsert, formatInsert, formatInsert, formatJSON, formatJSON, formatJSON, formatJSON, formatJSON, formatJSON, formatXML, formatXML, formatXML, formatXML, formatXML, formatXML, intoXML, intoXML, intoXML, intoXML
-
-
-
-
Method Detail
-
recordType
RecordType<R> recordType()
Get this cursor's row type.
-
field
<T> Field<T> field(Field<T> field)
Get a specific field from this Cursor.This will return:
- A field that is the same as the argument field (by identity comparison).
- A field that is equal to the argument field (exact matching fully qualified name).
- A field that is equal to the argument field (partially matching qualified name).
- A field whose name is equal to the name of the argument field.
null
otherwise.
- See Also:
Row.field(Field)
-
field
Field<?> field(java.lang.String name)
Get a specific field from this Cursor.- See Also:
Row.field(String)
-
field
Field<?> field(Name name)
Get a specific qualified field from this Cursor.- See Also:
Row.field(Name)
-
field
Field<?> field(int index)
Get a specific field from this Cursor.- See Also:
Row.field(int)
-
fields
Field<?>[] fields()
Get all fields from this Cursor.- See Also:
Row.fields()
-
fields
Field<?>[] fields(Field<?>... fields)
Get all fields from this Cursor, providing some fields.- Returns:
- All available fields
- See Also:
Row.fields(Field...)
-
fields
Field<?>[] fields(java.lang.String... fieldNames)
Get all fields from this Cursor, providing some field names.- Returns:
- All available fields
- See Also:
Row.fields(String...)
-
fields
Field<?>[] fields(Name... fieldNames)
Get all fields from this Cursor, providing some field names.- Returns:
- All available fields
- See Also:
Row.fields(Name...)
-
fields
Field<?>[] fields(int... fieldIndexes)
Get all fields from this Cursor, providing some field indexes.- Returns:
- All available fields
- See Also:
Row.fields(int...)
-
indexOf
int indexOf(Field<?> field)
Get a field's index from this cursor.- Parameters:
field
- The field to look for- Returns:
- The field's index or
-1
if the field is not contained in this cursor.
-
indexOf
int indexOf(java.lang.String fieldName)
Get a field's index from this cursor.- Parameters:
fieldName
- The field name to look for- Returns:
- The field's index or
-1
if the field is not contained in this cursor.
-
indexOf
int indexOf(Name fieldName)
Get a field's index from this cursor.- Parameters:
fieldName
- The field name to look for- Returns:
- The field's index or
-1
if the field is not contained in this cursor
-
hasNext
boolean hasNext() throws DataAccessException
Check whether this cursor has a next record.This will conveniently close the
Cursor
, after the lastRecord
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 lastRecord
was fetched.The result and its contained records are attached to the original
Configuration
by default. UseSettings.isAttachRecords()
to override this behaviour.- Throws:
DataAccessException
- if something went wrong executing the query
-
fetch
@Deprecated Result<R> fetch(int number) throws DataAccessException
Deprecated.- 3.10 - [#6363] - UsefetchNext(int)
instead.- Throws:
DataAccessException
-
fetchNext
Result<R> fetchNext(int number) throws DataAccessException
Fetch the next couple of records from the cursor.This will conveniently close the
Cursor
, after the lastRecord
was fetched.The result and its contained records are attached to the original
Configuration
by default. UseSettings.isAttachRecords()
to override this behaviour.- Parameters:
number
- The number of records to fetch. If this is0
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
-
fetchInto
<H extends RecordHandler<? super 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. UseSettings.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
-
fetch
<E> java.util.List<E> fetch(RecordMapper<? super R,E> mapper) throws DataAccessException
Fetch results into a custom mapper callback.- Parameters:
mapper
- The mapper callback- Returns:
- The custom mapped records
- Throws:
DataAccessException
- if something went wrong executing the query
-
fetchInto
<E> java.util.List<E> fetchInto(java.lang.Class<? extends E> type) throws DataAccessException, MappingException
Map resulting records onto a custom type.This is the same as calling
fetch().into(type)
. SeeRecord.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 queryMappingException
- wrapping any reflection or data type conversion exception that might have occurred while mapping records- See Also:
Record.into(Class)
,Result.into(Class)
,DefaultRecordMapper
-
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)
. SeeRecord.into(Class)
for more detailsThe result and its contained records are attached to the original
Configuration
by default. UseSettings.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 queryMappingException
- wrapping any reflection or data type conversion exception that might have occurred while mapping records- See Also:
Record.into(Class)
,Result.into(Class)
-
fetchOne
@Deprecated R fetchOne() throws DataAccessException
Deprecated.- 3.10 - [#6363] - UsefetchNext()
instead.- Throws:
DataAccessException
-
fetchOneInto
@Deprecated <H extends RecordHandler<? super R>> H fetchOneInto(H handler) throws DataAccessException
Deprecated.- 3.10 - [#6363] - UsefetchNextInto(RecordHandler)
instead.- Throws:
DataAccessException
-
fetchOne
@Deprecated <E> E fetchOne(RecordMapper<? super R,E> mapper) throws DataAccessException
Deprecated.- 3.10 - [#6363] - UsefetchNext(RecordMapper)
instead.- Throws:
DataAccessException
-
fetchOneInto
@Deprecated <Z extends Record> Z fetchOneInto(Table<Z> table) throws DataAccessException, MappingException
Deprecated.- 3.10 - [#6363] - UsefetchNextInto(Table)
instead.- Throws:
DataAccessException
MappingException
-
fetchNext
R fetchNext() throws DataAccessException
Fetch the next record from the cursor.This will conveniently close the
Cursor
, after the lastRecord
was fetched.The resulting record is attached to the original
Configuration
by default. UseSettings.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
-
fetchNextInto
<H extends RecordHandler<? super R>> H fetchNextInto(H handler) throws DataAccessException
Fetch the next record into a custom handler callback.This will conveniently close the
Cursor
, after the lastRecord
was fetched.The resulting record is attached to the original
Configuration
by default. UseSettings.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
@Deprecated <E> E fetchOneInto(java.lang.Class<? extends E> type) throws DataAccessException, MappingException
Deprecated.- 3.10 - [#6363] - UsefetchNextInto(Class)
instead.- Throws:
DataAccessException
MappingException
-
fetchNextInto
<E> E fetchNextInto(java.lang.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)
. SeeRecord.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 queryMappingException
- wrapping any reflection or data type conversion exception that might have occurred while mapping records- See Also:
Record.into(Class)
,Result.into(Class)
,DefaultRecordMapper
-
fetchNext
<E> E fetchNext(RecordMapper<? super R,E> mapper) throws DataAccessException
Fetch the next record into a custom mapper callback.This will conveniently close the
Cursor
, after the lastRecord
was fetched.- Parameters:
mapper
- The mapper callback- Returns:
- The custom mapped record
- Throws:
DataAccessException
- if something went wrong executing the query
-
fetchNextInto
<Z extends Record> Z fetchNextInto(Table<Z> table) throws DataAccessException, MappingException
Map the next resulting record onto a custom record.This is the same as calling
fetchOne().into(table)
. SeeRecord.into(Class)
for more detailsThe resulting record is attached to the original
Configuration
by default. UseSettings.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 queryMappingException
- wrapping any reflection or data type conversion exception that might have occurred while mapping records- See Also:
Record.into(Class)
,Result.into(Class)
-
fetchOptional
@Deprecated java.util.Optional<R> fetchOptional() throws DataAccessException
Deprecated.- 3.10 - [#6363] - UsefetchNextOptional()
instead.- Throws:
DataAccessException
-
fetchOptionalInto
@Deprecated <E> java.util.Optional<E> fetchOptionalInto(java.lang.Class<? extends E> type) throws DataAccessException, MappingException
Deprecated.- 3.10 - [#6363] - UsefetchNextOptionalInto(Class)
instead.- Throws:
DataAccessException
MappingException
-
fetchOptional
@Deprecated <E> java.util.Optional<E> fetchOptional(RecordMapper<? super R,E> mapper) throws DataAccessException
Deprecated.- 3.10 - [#6363] - UsefetchNextOptional(RecordMapper)
instead.- Throws:
DataAccessException
-
fetchOptionalInto
@Deprecated <Z extends Record> java.util.Optional<Z> fetchOptionalInto(Table<Z> table) throws DataAccessException, MappingException
Deprecated.- 3.10 - [#6363] - UsefetchNextOptionalInto(Table)
instead.- Throws:
DataAccessException
MappingException
-
fetchNextOptional
java.util.Optional<R> fetchNextOptional() throws DataAccessException
Fetch the next record from the cursor.This will conveniently close the
Cursor
, after the lastRecord
was fetched.The resulting record is attached to the original
Configuration
by default. UseSettings.isAttachRecords()
to override this behaviour.- Returns:
- The next record from the cursor
- Throws:
DataAccessException
- if something went wrong executing the query
-
fetchNextOptionalInto
<E> java.util.Optional<E> fetchNextOptionalInto(java.lang.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)
. SeeRecord.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 queryMappingException
- wrapping any reflection or data type conversion exception that might have occurred while mapping records- See Also:
Record.into(Class)
,Result.into(Class)
,DefaultRecordMapper
-
fetchNextOptional
<E> java.util.Optional<E> fetchNextOptional(RecordMapper<? super R,E> mapper) throws DataAccessException
Fetch the next record into a custom mapper callback.This will conveniently close the
Cursor
, after the lastRecord
was fetched.- Parameters:
mapper
- The mapper callback- Returns:
- The custom mapped record
- Throws:
DataAccessException
- if something went wrong executing the query
-
fetchNextOptionalInto
<Z extends Record> java.util.Optional<Z> fetchNextOptionalInto(Table<Z> table) throws DataAccessException, MappingException
Map the next resulting record onto a custom record.This is the same as calling
fetchOne().into(table)
. SeeRecord.into(Class)
for more detailsThe resulting record is attached to the original
Configuration
by default. UseSettings.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 queryMappingException
- wrapping any reflection or data type conversion exception that might have occurred while mapping records- See Also:
Record.into(Class)
,Result.into(Class)
-
stream
java.util.stream.Stream<R> stream() throws DataAccessException
Turn thisCursor
into aStream
.- Throws:
DataAccessException
- if something went wrong executing the query
-
collect
<X,A> X collect(java.util.stream.Collector<? super R,A,X> collector) throws DataAccessException
Reduce the execution results of this query using aCollector
.This works in the same way as calling the following code:
cursor.stream().collect(collector);
- Parameters:
collector
- The collector that collects all records and accumulates them into a result type.- Returns:
- The result of the collection.
- Throws:
DataAccessException
- if something went wrong executing the query
-
close
void close() throws DataAccessException
Explicitly close the underlyingPreparedStatement
andResultSet
.If you fetch all records from the underlying
ResultSet
, jOOQCursor
implementations will close themselves for you. Callingclose()
again will have no effect.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Throws:
DataAccessException
- if something went wrong executing the query
-
isClosed
boolean isClosed()
Check whether thisCursor
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
java.sql.ResultSet resultSet()
Get theCursor
's underlyingResultSet
.This will return a
ResultSet
wrapping the JDBC driver'sResultSet
. Closing thisResultSet
may close the producingStatement
orPreparedStatement
, depending on your setting forResultQuery.keepStatement(boolean)
.Modifying this
ResultSet
will affect thisCursor
.- Returns:
- The underlying
ResultSet
. May benull
, for instance when theCursor
is closed.
-
-