JdbcTemplate passes negative values other than -1 on to the driver (for MySQL's special values)
Issue: SPR-14028
This commit is contained in:
parent
100f3c5eeb
commit
0b1639d963
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2016 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -219,12 +219,14 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the fetch size for this JdbcTemplate. This is important for processing
|
* Set the fetch size for this JdbcTemplate. This is important for processing large
|
||||||
* large result sets: Setting this higher than the default value will increase
|
* result sets: Setting this higher than the default value will increase processing
|
||||||
* processing speed at the cost of memory consumption; setting this lower can
|
* speed at the cost of memory consumption; setting this lower can avoid transferring
|
||||||
* avoid transferring row data that will never be read by the application.
|
* row data that will never be read by the application.
|
||||||
* <p>Default is -1, indicating to use the JDBC driver's default
|
* <p>Default is -1, indicating to use the JDBC driver's default configuration
|
||||||
* (i.e. to not pass a specific fetch size setting on the driver).
|
* (i.e. to not pass a specific fetch size setting on to the driver).
|
||||||
|
* <p>Note: As of 4.3, negative values other than -1 will get passed on to the
|
||||||
|
* driver, since e.g. MySQL supports special behavior for {@code Integer.MIN_VALUE}.
|
||||||
* @see java.sql.Statement#setFetchSize
|
* @see java.sql.Statement#setFetchSize
|
||||||
*/
|
*/
|
||||||
public void setFetchSize(int fetchSize) {
|
public void setFetchSize(int fetchSize) {
|
||||||
|
@ -239,13 +241,15 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the maximum number of rows for this JdbcTemplate. This is important
|
* Set the maximum number of rows for this JdbcTemplate. This is important for
|
||||||
* for processing subsets of large result sets, avoiding to read and hold
|
* processing subsets of large result sets, avoiding to read and hold the entire
|
||||||
* the entire result set in the database or in the JDBC driver if we're
|
* result set in the database or in the JDBC driver if we're never interested in
|
||||||
* never interested in the entire result in the first place (for example,
|
* the entire result in the first place (for example, when performing searches
|
||||||
* when performing searches that might return a large number of matches).
|
* that might return a large number of matches).
|
||||||
* <p>Default is -1, indicating to use the JDBC driver's default
|
* <p>Default is -1, indicating to use the JDBC driver's default configuration
|
||||||
* (i.e. to not pass a specific max rows setting on the driver).
|
* (i.e. to not pass a specific max rows setting on to the driver).
|
||||||
|
* <p>Note: As of 4.3, negative values other than -1 will get passed on to the
|
||||||
|
* driver, in sync with {@link #setFetchSize}'s support for special MySQL values.
|
||||||
* @see java.sql.Statement#setMaxRows
|
* @see java.sql.Statement#setMaxRows
|
||||||
*/
|
*/
|
||||||
public void setMaxRows(int maxRows) {
|
public void setMaxRows(int maxRows) {
|
||||||
|
@ -1348,11 +1352,11 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
|
||||||
*/
|
*/
|
||||||
protected void applyStatementSettings(Statement stmt) throws SQLException {
|
protected void applyStatementSettings(Statement stmt) throws SQLException {
|
||||||
int fetchSize = getFetchSize();
|
int fetchSize = getFetchSize();
|
||||||
if (fetchSize >= 0) {
|
if (fetchSize != -1) {
|
||||||
stmt.setFetchSize(fetchSize);
|
stmt.setFetchSize(fetchSize);
|
||||||
}
|
}
|
||||||
int maxRows = getMaxRows();
|
int maxRows = getMaxRows();
|
||||||
if (maxRows >= 0) {
|
if (maxRows != -1) {
|
||||||
stmt.setMaxRows(maxRows);
|
stmt.setMaxRows(maxRows);
|
||||||
}
|
}
|
||||||
DataSourceUtils.applyTimeout(stmt, getDataSource(), getQueryTimeout());
|
DataSourceUtils.applyTimeout(stmt, getDataSource(), getQueryTimeout());
|
||||||
|
|
Loading…
Reference in New Issue