JdbcTemplate and JmsTemplate pass settings with 0 values on to the driver

Issue: SPR-12338
This commit is contained in:
Juergen Hoeller
2014-10-16 17:54:04 +02:00
committed by unknown
parent aae221cb15
commit 57d63a1903
3 changed files with 20 additions and 17 deletions

View File

@@ -111,22 +111,22 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
private boolean ignoreWarnings = true;
/**
* If this variable is set to a non-zero value, it will be used for setting the
* If this variable is set to a non-negative value, it will be used for setting the
* fetchSize property on statements used for query processing.
*/
private int fetchSize = 0;
private int fetchSize = -1;
/**
* If this variable is set to a non-zero value, it will be used for setting the
* If this variable is set to a non-negative value, it will be used for setting the
* maxRows property on statements used for query processing.
*/
private int maxRows = 0;
private int maxRows = -1;
/**
* If this variable is set to a non-zero value, it will be used for setting the
* If this variable is set to a non-negative value, it will be used for setting the
* queryTimeout property on statements used for query processing.
*/
private int queryTimeout = 0;
private int queryTimeout = -1;
/**
* If this variable is set to true then all results checking will be bypassed for any
@@ -224,7 +224,8 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
* large result sets: Setting this higher than the default value will increase
* processing speed at the cost of memory consumption; setting this lower can
* avoid transferring row data that will never be read by the application.
* <p>Default is 0, indicating to use the JDBC driver's default.
* <p>Default is -1, indicating to use the JDBC driver's default
* (i.e. to not pass a specific fetch size setting on the driver).
* @see java.sql.Statement#setFetchSize
*/
public void setFetchSize(int fetchSize) {
@@ -244,7 +245,8 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
* the entire result set in the database or in the JDBC driver if we're
* never interested in the entire result in the first place (for example,
* when performing searches that might return a large number of matches).
* <p>Default is 0, indicating to use the JDBC driver's default.
* <p>Default is -1, indicating to use the JDBC driver's default
* (i.e. to not pass a specific max rows setting on the driver).
* @see java.sql.Statement#setMaxRows
*/
public void setMaxRows(int maxRows) {
@@ -260,7 +262,8 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
/**
* Set the query timeout for statements that this JdbcTemplate executes.
* <p>Default is 0, indicating to use the JDBC driver's default.
* <p>Default is -1, indicating to use the JDBC driver's default
* (i.e. to not pass a specific query timeout setting on the driver).
* <p>Note: Any timeout specified here will be overridden by the remaining
* transaction timeout when executing within a transaction that has a
* timeout specified at the transaction level.
@@ -1386,11 +1389,11 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
*/
protected void applyStatementSettings(Statement stmt) throws SQLException {
int fetchSize = getFetchSize();
if (fetchSize > 0) {
if (fetchSize >= 0) {
stmt.setFetchSize(fetchSize);
}
int maxRows = getMaxRows();
if (maxRows > 0) {
if (maxRows >= 0) {
stmt.setMaxRows(maxRows);
}
DataSourceUtils.applyTimeout(stmt, getDataSource(), getQueryTimeout());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -254,7 +254,7 @@ public abstract class DataSourceUtils {
* @see java.sql.Statement#setQueryTimeout
*/
public static void applyTransactionTimeout(Statement stmt, DataSource dataSource) throws SQLException {
applyTimeout(stmt, dataSource, 0);
applyTimeout(stmt, dataSource, -1);
}
/**
@@ -274,7 +274,7 @@ public abstract class DataSourceUtils {
// Remaining transaction timeout overrides specified value.
stmt.setQueryTimeout(holder.getTimeToLiveInSeconds());
}
else if (timeout > 0) {
else if (timeout >= 0) {
// No current transaction timeout -> apply specified value.
stmt.setQueryTimeout(timeout);
}