[#2458] Add Cursor.closesAfterFetch() to indicate whether a Cursor
auto-closes the underlying ResultSet after it has fetched all records
This commit is contained in:
parent
8479ec8b17
commit
fdf8394796
@ -275,6 +275,15 @@ public interface Cursor<R extends Record> extends Iterable<R> {
|
||||
*/
|
||||
<Z extends Record> Result<Z> fetchInto(Table<Z> table) throws DataAccessException, MappingException;
|
||||
|
||||
/**
|
||||
* Whether this <code>Cursor</code> closes itself after fetching all data.
|
||||
* <p>
|
||||
* By default, a <code>Cursor</code> will close itself after fetching all
|
||||
* data. This behaviour can be overridden by
|
||||
* {@link ResultQuery#keepResultSet(KeepResultSetMode)}, though.
|
||||
*/
|
||||
boolean closesAfterFetch();
|
||||
|
||||
/**
|
||||
* Explicitly close the underlying {@link PreparedStatement} and
|
||||
* {@link ResultSet}.
|
||||
|
||||
@ -516,7 +516,9 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
|
||||
return c.fetchOne();
|
||||
}
|
||||
finally {
|
||||
c.close();
|
||||
if (c.closesAfterFetch()) {
|
||||
c.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -119,7 +119,8 @@ class CursorImpl<R extends Record> implements Cursor<R> {
|
||||
}
|
||||
}
|
||||
|
||||
final boolean closeAfterFetch() {
|
||||
@Override
|
||||
public final boolean closesAfterFetch() {
|
||||
return keepResultSetMode == null || keepResultSetMode == CLOSE_AFTER_FETCH;
|
||||
}
|
||||
|
||||
@ -186,7 +187,7 @@ class CursorImpl<R extends Record> implements Cursor<R> {
|
||||
// Before listener.resultStart(ctx)
|
||||
iterator();
|
||||
|
||||
ResultImpl<R> result = new ResultImpl<R>(ctx.configuration(), closeAfterFetch() ? null : rs, fields);
|
||||
ResultImpl<R> result = new ResultImpl<R>(ctx.configuration(), closesAfterFetch() ? null : rs, fields);
|
||||
R record = null;
|
||||
|
||||
ctx.result(result);
|
||||
@ -1286,7 +1287,7 @@ class CursorImpl<R extends Record> implements Cursor<R> {
|
||||
|
||||
// [#1846] Add a reference to the Cursor's ResultSet if
|
||||
// Updatable ResultSets are requested
|
||||
if (!closeAfterFetch()) {
|
||||
if (!closesAfterFetch()) {
|
||||
record.rs = rs;
|
||||
record.rsIndex = rsIndex;
|
||||
}
|
||||
@ -1317,7 +1318,7 @@ class CursorImpl<R extends Record> implements Cursor<R> {
|
||||
// the result is not eager-fetched.
|
||||
// [#1846] When fetching updatable Results, do not close the
|
||||
// Cursor's ResultSet!
|
||||
if (record == null && closeAfterFetch()) {
|
||||
if (record == null && closesAfterFetch()) {
|
||||
CursorImpl.this.close();
|
||||
}
|
||||
|
||||
|
||||
@ -754,7 +754,9 @@ final class Utils {
|
||||
return record;
|
||||
}
|
||||
finally {
|
||||
cursor.close();
|
||||
if (cursor.closesAfterFetch()) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user