[#2806] Add ResultQuery.fetchSize() to influence the JDBC Statement's fetch size
This commit is contained in:
parent
0deb4f6f92
commit
759cab3fc4
@ -1018,6 +1018,17 @@ public interface ResultQuery<R extends Record> extends Query {
|
||||
*/
|
||||
ResultQuery<R> maxRows(int rows);
|
||||
|
||||
/**
|
||||
* Specify the fetch size of the underlying {@link Statement}.
|
||||
* <p>
|
||||
* Regardless of this setting, {@link #fetchLazy()} is the only way in jOOQ
|
||||
* not to fetch all data in memory. However, you may influence how your JDBC
|
||||
* driver interacts with your database through specifying a fetch size.
|
||||
*
|
||||
* @see Statement#setFetchSize(int)
|
||||
*/
|
||||
ResultQuery<R> fetchSize(int rows);
|
||||
|
||||
/**
|
||||
* Specify the <code>ResultSet</code> concurrency of <code>ResultSet</code>
|
||||
* objects created by jOOQ.
|
||||
|
||||
@ -90,11 +90,11 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
|
||||
private static final JooqLogger log = JooqLogger.getLogger(AbstractResultQuery.class);
|
||||
|
||||
private int maxRows;
|
||||
private int fetchSize;
|
||||
private int resultSetConcurrency;
|
||||
private int resultSetType;
|
||||
private int resultSetHoldability;
|
||||
private transient boolean lazy;
|
||||
private transient int size;
|
||||
private transient boolean many;
|
||||
private transient Cursor<R> cursor;
|
||||
private Result<R> result;
|
||||
@ -144,6 +144,12 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final ResultQuery<R> fetchSize(int rows) {
|
||||
this.fetchSize = rows;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final ResultQuery<R> resultSetConcurrency(int concurrency) {
|
||||
this.resultSetConcurrency = concurrency;
|
||||
@ -226,11 +232,11 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
|
||||
|
||||
// [#1263] Allow for negative fetch sizes to support some non-standard
|
||||
// MySQL feature, where Integer.MIN_VALUE is used
|
||||
if (size != 0) {
|
||||
if (fetchSize != 0) {
|
||||
if (log.isDebugEnabled())
|
||||
log.debug("Setting fetch size", size);
|
||||
log.debug("Setting fetch size", fetchSize);
|
||||
|
||||
ctx.statement().setFetchSize(size);
|
||||
ctx.statement().setFetchSize(fetchSize);
|
||||
}
|
||||
|
||||
// [#1854] Set the max number of rows for this result query
|
||||
@ -336,16 +342,16 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Cursor<R> fetchLazy(int fetchSize) {
|
||||
public final Cursor<R> fetchLazy(int size) {
|
||||
lazy = true;
|
||||
size = fetchSize;
|
||||
fetchSize = size;
|
||||
|
||||
try {
|
||||
execute();
|
||||
}
|
||||
finally {
|
||||
lazy = false;
|
||||
size = 0;
|
||||
fetchSize = 0;
|
||||
}
|
||||
|
||||
return cursor;
|
||||
|
||||
@ -1623,6 +1623,11 @@ class SelectImpl<R extends Record, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,
|
||||
return getDelegate().maxRows(rows);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final ResultQuery<R> fetchSize(int rows) {
|
||||
return getDelegate().fetchSize(rows);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final ResultQuery<R> resultSetConcurrency(int resultSetConcurrency) {
|
||||
return getDelegate().resultSetConcurrency(resultSetConcurrency);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user