[#8646] Call Statement#setFetchSize(int) where applicable
Calling Statement#setFetchSize(int) can also make sense in other places than AbstractResultQuery. Specifically it is now also called in AbstractDMLQuery and AbstractRoutine. In each case the fetch size will be determined using Settings#getFetchSize(), except for AbstractResultQuery where the value supplied via ResultQuery#fetchSize(int) takes precedence.
This commit is contained in:
parent
dd9b3e9f3e
commit
6f13d24232
@ -699,7 +699,7 @@ abstract class AbstractDMLQuery<R extends Record> extends AbstractRowCountQuery
|
||||
case CUBRID:
|
||||
|
||||
super.prepare(ctx);
|
||||
return;
|
||||
break;
|
||||
|
||||
// Some dialects can only return AUTO_INCREMENT values
|
||||
// Other values have to be fetched in a second step
|
||||
@ -719,7 +719,7 @@ abstract class AbstractDMLQuery<R extends Record> extends AbstractRowCountQuery
|
||||
case MARIADB:
|
||||
case MYSQL:
|
||||
ctx.statement(connection.prepareStatement(ctx.sql(), Statement.RETURN_GENERATED_KEYS));
|
||||
return;
|
||||
break;
|
||||
|
||||
// The default is to return all requested fields directly
|
||||
|
||||
@ -755,10 +755,12 @@ abstract class AbstractDMLQuery<R extends Record> extends AbstractRowCountQuery
|
||||
names[i] = returningResolvedAsterisks.get(i).getName();
|
||||
|
||||
ctx.statement(connection.prepareStatement(ctx.sql(), names));
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Tools.setFetchSize(ctx, 0);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
|
||||
@ -272,15 +272,7 @@ abstract class AbstractResultQuery<R extends Record> extends AbstractQuery imple
|
||||
ctx.statement(ctx.connection().prepareStatement(ctx.sql()));
|
||||
}
|
||||
|
||||
// [#1263] [#4753] Allow for negative fetch sizes to support some non-standard
|
||||
// MySQL feature, where Integer.MIN_VALUE is used
|
||||
int f = SettingsTools.getFetchSize(fetchSize, ctx.settings());
|
||||
if (f != 0) {
|
||||
if (log.isDebugEnabled())
|
||||
log.debug("Setting fetch size", f);
|
||||
|
||||
ctx.statement().setFetchSize(f);
|
||||
}
|
||||
Tools.setFetchSize(ctx, fetchSize);
|
||||
|
||||
// [#1854] [#4753] Set the max number of rows for this result query
|
||||
int m = SettingsTools.getMaxRows(maxRows, ctx.settings());
|
||||
|
||||
@ -487,6 +487,7 @@ public abstract class AbstractRoutine<T> extends AbstractNamed implements Routin
|
||||
|
||||
listener.prepareStart(ctx);
|
||||
ctx.statement(connection.prepareCall(ctx.sql()));
|
||||
Tools.setFetchSize(ctx, 0);
|
||||
// [#1856] TODO: Add Statement flags like timeout here
|
||||
listener.prepareEnd(ctx);
|
||||
|
||||
|
||||
@ -245,6 +245,7 @@ import org.jooq.UDTRecord;
|
||||
import org.jooq.UpdatableRecord;
|
||||
import org.jooq.conf.BackslashEscaping;
|
||||
import org.jooq.conf.Settings;
|
||||
import org.jooq.conf.SettingsTools;
|
||||
import org.jooq.conf.ThrowExceptions;
|
||||
import org.jooq.exception.DataAccessException;
|
||||
import org.jooq.exception.DataTypeException;
|
||||
@ -1908,6 +1909,26 @@ final class Tools {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the statement's fetch size to the given value or
|
||||
* {@link org.jooq.conf.Settings#getFetchSize()} if {@code 0}.
|
||||
* <p>
|
||||
* This method should not be called before {@link ExecuteContext#statement(PreparedStatement)}.
|
||||
*/
|
||||
static final void setFetchSize(ExecuteContext ctx, int fetchSize) throws SQLException {
|
||||
// [#1263] [#4753] Allow for negative fetch sizes to support some non-standard
|
||||
// MySQL feature, where Integer.MIN_VALUE is used
|
||||
int f = SettingsTools.getFetchSize(fetchSize, ctx.settings());
|
||||
if (f != 0) {
|
||||
if (log.isDebugEnabled())
|
||||
log.debug("Setting fetch size", f);
|
||||
|
||||
PreparedStatement statement = ctx.statement();
|
||||
if (statement != null)
|
||||
statement.setFetchSize(f);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the only element from a list or <code>null</code>, or throw an
|
||||
* exception
|
||||
|
||||
Loading…
Reference in New Issue
Block a user