Top Description Methods
org.jooq

public Interface Cursor<R extends org.jooq.Record>

extends Fields, Iterable<R extends Record>, Formattable, AutoCloseable
Known Direct Implementers
org.jooq.impl.AbstractCursor
Annotations
@Blocking
Type Parameters
<R>
The cursor's record type
Imports
java.sql.PreparedStatement, .ResultSet, .Statement, java.util.Iterator, .List, .Optional, java.util.function.Consumer, java.util.stream.Collector, .Stream, org.jooq.conf.Settings, org.jooq.exception.DataAccessException, .MappingException, org.jooq.impl.DefaultRecordMapper, org.jetbrains.annotations.Blocking, .NotNull, .Nullable

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

The cursor can be consumed in two ways:

Note

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

Author
Lukas Eder

Method Summary

Modifier and TypeMethod and Description
public void
close()

Redeclares java.lang.AutoCloseable.close.

Explicitly close the underlying PreparedStatement and ResultSet.
public <X, A> X

Returns:

The result of the collection.
collect
(Collector<? super R, A, X>
The collector that collects all records and accumulates them into a result type.
collector
)

Reduce the execution results of this query using a Collector.

public @NotNull Result<R>
fetch()

Fetch all remaining records as a result.

public @NotNull Result<R>
fetch(int number)

Deprecated for removal since 3.10. - 3.10 - [#6363] - Use fetchNext(int) instead.
public <E> @NotNull List<E>

Returns:

The custom mapped records
fetch
(RecordMapper<? super R, E>
The mapper callback
mapper
)

Fetch results into a custom mapper callback.

public <H extends RecordHandler<? super R>> H

Returns:

Convenience result, returning the parameter handler itself
fetchInto
(H
The handler callback
handler
)

Deprecated for removal since 3.15. - 3.15.0 - [#11902] - Use Iterable#forEach(Consumer) based methods, instead.
Fetch results into a custom handler callback.
public <
The generic entity type.
E
>
@NotNull List<E>
fetchInto(Class<? extends E>
The entity type.
type
)

Map resulting records onto a custom type.

public <
The generic table record type.
Z extends Record
>
@NotNull Result<Z>
fetchInto(Table<Z>
The table type.
table
)

Map resulting records onto a custom record.

public @NotNull Result<R>
fetchNext(int
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.
number
)

Fetch the next couple of records from the cursor.

public R

Returns:

The next record from the cursor, or null if there is no next record.
fetchNext
()

Fetch the next record from the cursor.

public <E> E

Returns:

The custom mapped record
fetchNext
(RecordMapper<? super R, E>
The mapper callback
mapper
)

Fetch the next record into a custom mapper callback.

public <H extends RecordHandler<? super R>> H

Returns:

Convenience result, returning the parameter handler itself
fetchNextInto
(H
The handler callback
handler
)

Deprecated for removal since 3.15. - 3.15.0 - [#11902] - Use Iterable#forEach(Consumer) based methods, instead.
Fetch the next record into a custom handler callback.
public <
The generic entity type.
E
>
E
fetchNextInto(Class<? extends E>
The entity type.
type
)

Map the next resulting record onto a custom type.

public <
The generic table record type.
Z extends Record
>
Z
fetchNextInto(Table<Z>
The table type.
table
)

Map the next resulting record onto a custom record.

public @NotNull Optional<R>

Returns:

The next record from the cursor
fetchNextOptional
()

Fetch the next record from the cursor.

public <E> @NotNull Optional<E>

Returns:

The custom mapped record
fetchNextOptional
(RecordMapper<? super R, E>
The mapper callback
mapper
)

Fetch the next record into a custom mapper callback.

public <
The generic entity type.
E
>
@NotNull Optional<E>
fetchNextOptionalInto(Class<? extends E>
The entity type.
type
)

Map the next resulting record onto a custom type.

public <
The generic table record type.
Z extends Record
>
@NotNull Optional<Z>
fetchNextOptionalInto(Table<Z>
The table type.
table
)

Map the next resulting record onto a custom record.

public R
fetchOne()

Deprecated for removal since 3.10. - 3.10 - [#6363] - Use fetchNext() instead.
public <E> E
fetchOne(RecordMapper<? super R, E> mapper)

Deprecated for removal since 3.10. - 3.10 - [#6363] - Use fetchNext(RecordMapper) instead.
public <H extends RecordHandler<? super R>> H
fetchOneInto(H handler)

Deprecated for removal since 3.10. - 3.10 - [#6363] - Use fetchNextInto(RecordHandler) instead.
Deprecated for removal since 3.10. - 3.15.0 - [#11902] - Use Iterable#forEach(Consumer) based methods, instead.
public <Z extends Record> Z
fetchOneInto(Table<Z> table)

Deprecated for removal since 3.10. - 3.10 - [#6363] - Use fetchNextInto(Table) instead.
public <E> E
fetchOneInto(Class<? extends E> type)

Deprecated for removal since 3.10. - 3.10 - [#6363] - Use fetchNextInto(Class) instead.
public @NotNull Optional<R>
fetchOptional()

Deprecated for removal since 3.10. - 3.10 - [#6363] - Use fetchNextOptional() instead.
public <E> @NotNull Optional<E>
fetchOptional(RecordMapper<? super R, E> mapper)

Deprecated for removal since 3.10. - 3.10 - [#6363] - Use fetchNextOptional(RecordMapper) instead.
public <E> @NotNull Optional<E>
fetchOptionalInto(Class<? extends E> type)

Deprecated for removal since 3.10. - 3.10 - [#6363] - Use fetchNextOptionalInto(Class) instead.
public <Z extends Record> @NotNull Optional<Z>
fetchOptionalInto(Table<Z> table)

Deprecated for removal since 3.10. - 3.10 - [#6363] - Use fetchNextOptionalInto(Table) instead.
public boolean
hasNext()

Check whether this cursor has a next record.

public boolean
isClosed()

Check whether this Cursor has been explicitly or "conveniently" closed.

public @NotNull RecordType<R>
recordType()

Get this cursor's row type.

public @Nullable ResultSet

Returns:

The underlying ResultSet. May be null, for instance when the Cursor is closed.
resultSet
()

Get the Cursor's underlying ResultSet.

public @NotNull Stream<R>
stream()

Turn this Cursor into a Stream.

Inherited from java.lang.Iterable:
forEachiteratorspliterator
Inherited from org.jooq.Fields:
dataTypedataTypedataTypedataTypesfieldfieldfieldfieldfieldfieldfieldfieldfieldfieldfieldsfieldsfieldsfieldsfieldsfieldsRowfieldStreamindexOfindexOfindexOftypetypetypetypes
Inherited from org.jooq.Formattable:
formatformatformatformatformatformatformatformatformatformatChartformatChartformatChartformatChartformatChartformatChartformatCSVformatCSVformatCSVformatCSVformatCSVformatCSVformatCSVformatCSVformatCSVformatCSVformatCSVformatCSVformatCSVformatCSVformatCSVformatCSVformatCSVformatCSVformatCSVformatCSVformatCSVformatHTMLformatHTMLformatHTMLformatInsertformatInsertformatInsertformatInsertformatInsertformatInsertformatJSONformatJSONformatJSONformatJSONformatJSONformatJSONformatXMLformatXMLformatXMLformatXMLformatXMLformatXMLintoXMLintoXMLintoXMLintoXML

Method Detail

closeback to summary
public void close() throws DataAccessException

Redeclares java.lang.AutoCloseable.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. Calling close() again will have no effect.

Annotations
@Override
Exceptions
DataAccessException:
if something went wrong executing the query
collectback to summary
public <X, A> X collect(Collector<? super R, A, X> collector) throws DataAccessException

Reduce the execution results of this query using a Collector.

This works in the same way as calling the following code:


cursor.stream().collect(collector);

Parameters
collector:Collector<? super R, A, X>

The collector that collects all records and accumulates them into a result type.

Returns:X

The result of the collection.

Exceptions
DataAccessException:
if something went wrong executing the query
fetchback to summary
public @NotNull 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.

Annotations
@NotNull
Exceptions
DataAccessException:
if something went wrong executing the query
fetchback to summary
public @NotNull Result<R> fetch(int number) throws DataAccessException

Deprecated

for removal since 3.10.

- 3.10 - [#6363] - Use fetchNext(int) instead.

Annotations
@NotNull
@Deprecated
forRemoval:true
since:3.10
fetchback to summary
public <E> @NotNull List<E> fetch(RecordMapper<? super R, E> mapper) throws DataAccessException

Fetch results into a custom mapper callback.

Parameters
mapper:RecordMapper<? super R, E>

The mapper callback

Returns:@NotNull List<E>

The custom mapped records

Annotations
@NotNull
Exceptions
DataAccessException:
if something went wrong executing the query
fetchIntoback to summary
public <H extends RecordHandler<? super R>> H fetchInto(H handler) throws DataAccessException

Deprecated

for removal since 3.15.

- 3.15.0 - [#11902] - Use Iterable#forEach(Consumer) based methods, instead.

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:H

The handler callback

Returns:H

Convenience result, returning the parameter handler itself

Annotations
@Deprecated
forRemoval:true
since:3.15
@NotNull
Exceptions
DataAccessException:
if something went wrong executing the query
fetchIntoback to summary
public <E> @NotNull 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

Parameters
<E>
The generic entity type.
type:Class<? extends E>

The entity type.

Annotations
@NotNull
Exceptions
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), DefaultRecordMapper
fetchIntoback to summary
public <Z extends Record> @NotNull 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.

Parameters
<Z>
The generic table record type.
table:Table<Z>

The table type.

Annotations
@NotNull
Exceptions
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)
fetchNextback to summary
public @NotNull Result<R> fetchNext(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:int

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.

Annotations
@NotNull
Exceptions
DataAccessException:
if something went wrong executing the query
fetchNextback to summary
public R fetchNext() 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:R

The next record from the cursor, or null if there is no next record.

Annotations
@Nullable
Exceptions
DataAccessException:
if something went wrong executing the query
fetchNextback to summary
public <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 last Record was fetched.

Parameters
mapper:RecordMapper<? super R, E>

The mapper callback

Returns:E

The custom mapped record

Annotations
@Nullable
Exceptions
DataAccessException:
if something went wrong executing the query
fetchNextIntoback to summary
public <H extends RecordHandler<? super R>> H fetchNextInto(H handler) throws DataAccessException

Deprecated

for removal since 3.15.

- 3.15.0 - [#11902] - Use Iterable#forEach(Consumer) based methods, instead.

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:H

The handler callback

Returns:H

Convenience result, returning the parameter handler itself

Annotations
@Deprecated
forRemoval:true
since:3.15
@NotNull
Exceptions
DataAccessException:
if something went wrong executing the query
fetchNextIntoback to summary
public <E> E fetchNextInto(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

Parameters
<E>
The generic entity type.
type:Class<? extends E>

The entity type.

Annotations
@Nullable
Exceptions
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), DefaultRecordMapper
fetchNextIntoback to summary
public <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). 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.

Parameters
<Z>
The generic table record type.
table:Table<Z>

The table type.

Annotations
@Nullable
Exceptions
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)
fetchNextOptionalback to summary
public @NotNull Optional<R> fetchNextOptional() 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:@NotNull Optional<R>

The next record from the cursor

Annotations
@NotNull
Exceptions
DataAccessException:
if something went wrong executing the query
fetchNextOptionalback to summary
public <E> @NotNull 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 last Record was fetched.

Parameters
mapper:RecordMapper<? super R, E>

The mapper callback

Returns:@NotNull Optional<E>

The custom mapped record

Annotations
@NotNull
Exceptions
DataAccessException:
if something went wrong executing the query
fetchNextOptionalIntoback to summary
public <E> @NotNull Optional<E> fetchNextOptionalInto(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

Parameters
<E>
The generic entity type.
type:Class<? extends E>

The entity type.

Annotations
@NotNull
Exceptions
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), DefaultRecordMapper
fetchNextOptionalIntoback to summary
public <Z extends Record> @NotNull 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). 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.

Parameters
<Z>
The generic table record type.
table:Table<Z>

The table type.

Annotations
@NotNull
Exceptions
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)
fetchOneback to summary
public R fetchOne() throws DataAccessException

Deprecated

for removal since 3.10.

- 3.10 - [#6363] - Use fetchNext() instead.

Annotations
@Nullable
@Deprecated
forRemoval:true
since:3.10
fetchOneback to summary
public <E> E fetchOne(RecordMapper<? super R, E> mapper) throws DataAccessException

Deprecated

for removal since 3.10.

- 3.10 - [#6363] - Use fetchNext(RecordMapper) instead.

Annotations
@Nullable
@Deprecated
forRemoval:true
since:3.10
fetchOneIntoback to summary
public <H extends RecordHandler<? super R>> H fetchOneInto(H handler) throws DataAccessException

Deprecated

for removal since 3.10.

- 3.10 - [#6363] - Use fetchNextInto(RecordHandler) instead.

Deprecated

for removal since 3.10.

- 3.15.0 - [#11902] - Use Iterable#forEach(Consumer) based methods, instead.

Annotations
@NotNull
@Deprecated
forRemoval:true
since:3.10
fetchOneIntoback to summary
public <Z extends Record> Z fetchOneInto(Table<Z> table) throws DataAccessException, MappingException

Deprecated

for removal since 3.10.

- 3.10 - [#6363] - Use fetchNextInto(Table) instead.

Annotations
@Nullable
@Deprecated
forRemoval:true
since:3.10
fetchOneIntoback to summary
public <E> E fetchOneInto(Class<? extends E> type) throws DataAccessException, MappingException

Deprecated

for removal since 3.10.

- 3.10 - [#6363] - Use fetchNextInto(Class) instead.

Annotations
@Nullable
@Deprecated
forRemoval:true
since:3.10
fetchOptionalback to summary
public @NotNull Optional<R> fetchOptional() throws DataAccessException

Deprecated

for removal since 3.10.

- 3.10 - [#6363] - Use fetchNextOptional() instead.

Annotations
@NotNull
@Deprecated
forRemoval:true
since:3.10
fetchOptionalback to summary
public <E> @NotNull Optional<E> fetchOptional(RecordMapper<? super R, E> mapper) throws DataAccessException

Deprecated

for removal since 3.10.

- 3.10 - [#6363] - Use fetchNextOptional(RecordMapper) instead.

Annotations
@NotNull
@Deprecated
forRemoval:true
since:3.10
fetchOptionalIntoback to summary
public <E> @NotNull Optional<E> fetchOptionalInto(Class<? extends E> type) throws DataAccessException, MappingException

Deprecated

for removal since 3.10.

- 3.10 - [#6363] - Use fetchNextOptionalInto(Class) instead.

Annotations
@NotNull
@Deprecated
forRemoval:true
since:3.10
fetchOptionalIntoback to summary
public <Z extends Record> @NotNull Optional<Z> fetchOptionalInto(Table<Z> table) throws DataAccessException, MappingException

Deprecated

for removal since 3.10.

- 3.10 - [#6363] - Use fetchNextOptionalInto(Table) instead.

Annotations
@NotNull
@Deprecated
forRemoval:true
since:3.10
hasNextback to summary
public boolean hasNext() throws DataAccessException

Check whether this cursor has a next record.

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

Exceptions
DataAccessException:
if something went wrong executing the query
isClosedback to summary
public 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.

recordTypeback to summary
public @NotNull RecordType<R> recordType()

Get this cursor's row type.

Annotations
@NotNull
resultSetback to summary
public @Nullable ResultSet resultSet()

Get the 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.

Returns:@Nullable ResultSet

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

Annotations
@Nullable
streamback to summary
public @NotNull Stream<R> stream() throws DataAccessException

Turn this Cursor into a Stream.

Annotations
@NotNull
Exceptions
DataAccessException:
if something went wrong executing the query