R
- The cursor's record typepublic interface Cursor<R extends Record> extends Iterable<R>, Formattable, AutoCloseable
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
The cursor can be consumed in two ways:
fetchNext(int)
.fetch()
.
Note: Unlike usual implementations of Iterable
, a Cursor
can only provide one Iterator
!
Modifier and Type | Method and Description |
---|---|
void |
close()
Explicitly close the underlying
PreparedStatement and
ResultSet . |
<X,A> X |
collect(Collector<? super R,A,X> collector)
Reduce the execution results of this query using a
Collector . |
Result<R> |
fetch()
Fetch all remaining records as a result.
|
Result<R> |
fetch(int number)
Deprecated.
- 3.10 - [#6363] - Use
fetchNext(int) instead. |
<E> List<E> |
fetch(RecordMapper<? super R,E> mapper)
Fetch results into a custom mapper callback.
|
<E> List<E> |
fetchInto(Class<? extends E> type)
Map resulting records onto a custom type.
|
<H extends RecordHandler<? super R>> |
fetchInto(H handler)
Fetch results into a custom handler callback.
|
<Z extends Record> |
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.
|
<E> E |
fetchNextInto(Class<? extends E> type)
Map the next resulting record onto a custom type.
|
<H extends RecordHandler<? super R>> |
fetchNextInto(H handler)
Fetch the next record into a custom handler callback.
|
<Z extends Record> |
fetchNextInto(Table<Z> table)
Map the next resulting record onto a custom record.
|
Optional<R> |
fetchNextOptional()
Fetch the next record from the cursor.
|
<E> Optional<E> |
fetchNextOptional(RecordMapper<? super R,E> mapper)
Fetch the next record into a custom mapper callback.
|
<E> Optional<E> |
fetchNextOptionalInto(Class<? extends E> type)
Map the next resulting record onto a custom type.
|
<Z extends Record> |
fetchNextOptionalInto(Table<Z> table)
Map the next resulting record onto a custom record.
|
R |
fetchOne()
Deprecated.
- 3.10 - [#6363] - Use
fetchNext() instead. |
<E> E |
fetchOne(RecordMapper<? super R,E> mapper)
Deprecated.
- 3.10 - [#6363] - Use
fetchNext(RecordMapper) instead. |
<E> E |
fetchOneInto(Class<? extends E> type)
Deprecated.
- 3.10 - [#6363] - Use
fetchNextInto(Class) instead. |
<H extends RecordHandler<? super R>> |
fetchOneInto(H handler)
Deprecated.
- 3.10 - [#6363] - Use
fetchNextInto(RecordHandler) instead. |
<Z extends Record> |
fetchOneInto(Table<Z> table)
Deprecated.
- 3.10 - [#6363] - Use
fetchNextInto(Table) instead. |
Optional<R> |
fetchOptional()
Deprecated.
- 3.10 - [#6363] - Use
fetchNextOptional() instead. |
<E> Optional<E> |
fetchOptional(RecordMapper<? super R,E> mapper)
Deprecated.
- 3.10 - [#6363] - Use
fetchNextOptional(RecordMapper) instead. |
<E> Optional<E> |
fetchOptionalInto(Class<? extends E> type)
Deprecated.
- 3.10 - [#6363] - Use
fetchNextOptionalInto(Class) instead. |
<Z extends Record> |
fetchOptionalInto(Table<Z> table)
Deprecated.
- 3.10 - [#6363] - Use
fetchNextOptionalInto(Table) instead. |
<T> Field<T> |
field(Field<T> field)
Get a specific field from this Cursor.
|
Field<?> |
field(int index)
Get a specific field from this Cursor.
|
Field<?> |
field(Name name)
Get a specific qualified field from this Cursor.
|
Field<?> |
field(String name)
Get a specific field from this Cursor.
|
Field<?>[] |
fields()
Get all fields from this Cursor.
|
Field<?>[] |
fields(Field<?>... fields)
Get all fields from this Cursor, providing some fields.
|
Field<?>[] |
fields(int... fieldIndexes)
Get all fields from this Cursor, providing some field indexes.
|
Field<?>[] |
fields(Name... fieldNames)
Get all fields from this Cursor, providing some field names.
|
Field<?>[] |
fields(String... fieldNames)
Get all fields from this Cursor, providing some field names.
|
Row |
fieldsRow()
Get this cursor's fields as a
Row . |
boolean |
hasNext()
Check whether this cursor has a next record.
|
boolean |
isClosed()
Check whether this
Cursor has been explicitly or
"conveniently" closed. |
RecordType<R> |
recordType()
Get this cursor's row type.
|
ResultSet |
resultSet()
Get the
Cursor 's underlying ResultSet . |
Stream<R> |
stream()
Turn this
Cursor into a Stream . |
forEach, iterator, spliterator
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
RecordType<R> recordType()
<T> Field<T> field(Field<T> field)
This will return:
null
otherwise.
Row.field(Field)
Field<?> field(String name)
Row.field(String)
Field<?> field(Name name)
Row.field(Name)
Field<?> field(int index)
Row.field(int)
Field<?>[] fields()
Row.fields()
Field<?>[] fields(Field<?>... fields)
Row.fields(Field...)
Field<?>[] fields(String... fieldNames)
Row.fields(String...)
Field<?>[] fields(Name... fieldNames)
Row.fields(Name...)
Field<?>[] fields(int... fieldIndexes)
Row.fields(int...)
boolean hasNext() throws DataAccessException
This will conveniently close the Cursor
, after the last
Record
was fetched.
DataAccessException
- if something went wrong executing the queryResult<R> fetch() throws DataAccessException
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.
DataAccessException
- if something went wrong executing the query@Deprecated Result<R> fetch(int number) throws DataAccessException
fetchNext(int)
instead.DataAccessException
Result<R> fetchNext(int number) throws DataAccessException
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.
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.DataAccessException
- if something went wrong executing the query<H extends RecordHandler<? super R>> H fetchInto(H handler) throws DataAccessException
The resulting records are attached to the original Configuration
by default. Use Settings.isAttachRecords()
to override this
behaviour.
handler
- The handler callbackDataAccessException
- if something went wrong executing the query<E> List<E> fetch(RecordMapper<? super R,E> mapper) throws DataAccessException
mapper
- The mapper callbackDataAccessException
- if something went wrong executing the query<E> List<E> fetchInto(Class<? extends E> type) throws DataAccessException, MappingException
This is the same as calling fetch().into(type)
. See
Record.into(Class)
for more details
E
- The generic entity type.type
- The entity type.DataAccessException
- if something went wrong executing the queryMappingException
- wrapping any reflection or data type conversion
exception that might have occurred while mapping recordsRecord.into(Class)
,
Result.into(Class)
,
DefaultRecordMapper
<Z extends Record> Result<Z> fetchInto(Table<Z> table) throws DataAccessException, MappingException
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.
Z
- The generic table record type.table
- The table type.DataAccessException
- if something went wrong executing the queryMappingException
- wrapping any reflection or data type conversion
exception that might have occurred while mapping recordsRecord.into(Class)
,
Result.into(Class)
@Deprecated R fetchOne() throws DataAccessException
fetchNext()
instead.DataAccessException
@Deprecated <H extends RecordHandler<? super R>> H fetchOneInto(H handler) throws DataAccessException
fetchNextInto(RecordHandler)
instead.DataAccessException
@Deprecated <E> E fetchOne(RecordMapper<? super R,E> mapper) throws DataAccessException
fetchNext(RecordMapper)
instead.DataAccessException
@Deprecated <Z extends Record> Z fetchOneInto(Table<Z> table) throws DataAccessException, MappingException
fetchNextInto(Table)
instead.DataAccessException
MappingException
R fetchNext() throws DataAccessException
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.
null
if there is
no next record.DataAccessException
- if something went wrong executing the query<H extends RecordHandler<? super R>> H fetchNextInto(H handler) throws DataAccessException
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.
handler
- The handler callbackDataAccessException
- if something went wrong executing the query@Deprecated <E> E fetchOneInto(Class<? extends E> type) throws DataAccessException, MappingException
fetchNextInto(Class)
instead.DataAccessException
MappingException
<E> E fetchNextInto(Class<? extends E> type) throws DataAccessException, MappingException
This is the same as calling fetchOne().into(type)
. See
Record.into(Class)
for more details
E
- The generic entity type.type
- The entity type.DataAccessException
- if something went wrong executing the queryMappingException
- wrapping any reflection or data type conversion
exception that might have occurred while mapping recordsRecord.into(Class)
,
Result.into(Class)
,
DefaultRecordMapper
<E> E fetchNext(RecordMapper<? super R,E> mapper) throws DataAccessException
This will conveniently close the Cursor
, after the last
Record
was fetched.
mapper
- The mapper callbackDataAccessException
- if something went wrong executing the query<Z extends Record> Z fetchNextInto(Table<Z> table) throws DataAccessException, MappingException
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.
Z
- The generic table record type.table
- The table type.DataAccessException
- if something went wrong executing the queryMappingException
- wrapping any reflection or data type conversion
exception that might have occurred while mapping recordsRecord.into(Class)
,
Result.into(Class)
@Deprecated Optional<R> fetchOptional() throws DataAccessException
fetchNextOptional()
instead.DataAccessException
@Deprecated <E> Optional<E> fetchOptionalInto(Class<? extends E> type) throws DataAccessException, MappingException
fetchNextOptionalInto(Class)
instead.DataAccessException
MappingException
@Deprecated <E> Optional<E> fetchOptional(RecordMapper<? super R,E> mapper) throws DataAccessException
fetchNextOptional(RecordMapper)
instead.DataAccessException
@Deprecated <Z extends Record> Optional<Z> fetchOptionalInto(Table<Z> table) throws DataAccessException, MappingException
fetchNextOptionalInto(Table)
instead.DataAccessException
MappingException
Optional<R> fetchNextOptional() throws DataAccessException
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.
DataAccessException
- if something went wrong executing the query<E> Optional<E> fetchNextOptionalInto(Class<? extends E> type) throws DataAccessException, MappingException
This is the same as calling fetchOne().into(type)
. See
Record.into(Class)
for more details
E
- The generic entity type.type
- The entity type.DataAccessException
- if something went wrong executing the queryMappingException
- wrapping any reflection or data type conversion
exception that might have occurred while mapping recordsRecord.into(Class)
,
Result.into(Class)
,
DefaultRecordMapper
<E> Optional<E> fetchNextOptional(RecordMapper<? super R,E> mapper) throws DataAccessException
This will conveniently close the Cursor
, after the last
Record
was fetched.
mapper
- The mapper callbackDataAccessException
- if something went wrong executing the query<Z extends Record> Optional<Z> fetchNextOptionalInto(Table<Z> table) throws DataAccessException, MappingException
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.
Z
- The generic table record type.table
- The table type.DataAccessException
- if something went wrong executing the queryMappingException
- wrapping any reflection or data type conversion
exception that might have occurred while mapping recordsRecord.into(Class)
,
Result.into(Class)
Stream<R> stream() throws DataAccessException
Cursor
into a Stream
.DataAccessException
- if something went wrong executing the query<X,A> X collect(Collector<? super R,A,X> collector) throws DataAccessException
Collector
.
This works in the same way as calling the following code:
cursor.stream().collect(collector);
collector
- The collector that collects all records and accumulates
them into a result type.DataAccessException
- if something went wrong executing the queryvoid close() throws DataAccessException
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.
close
in interface AutoCloseable
DataAccessException
- if something went wrong executing the queryboolean isClosed()
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()
Cursor
's underlying ResultSet
.
This will return a ResultSet
wrapping the JDBC driver's
ResultSet
. Closing this ResultSet
may close the
producing Statement
or PreparedStatement
, depending on
your setting for ResultQuery.keepStatement(boolean)
.
Modifying this ResultSet
will affect this
Cursor
.
ResultSet
. May be null
,
for instance when the Cursor
is closed.Copyright © 2019. All rights reserved.