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; 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. * 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. * 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. * 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 * 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 * large result sets: Setting this higher than the default value will increase
* processing speed at the cost of memory consumption; setting this lower can * processing speed at the cost of memory consumption; setting this lower can
* avoid transferring row data that will never be read by the application. * 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 * @see java.sql.Statement#setFetchSize
*/ */
public void setFetchSize(int fetchSize) { 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 * 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, * never interested in the entire result in the first place (for example,
* when performing searches that might return a large number of matches). * 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 * @see java.sql.Statement#setMaxRows
*/ */
public void setMaxRows(int maxRows) { 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. * 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 * <p>Note: Any timeout specified here will be overridden by the remaining
* transaction timeout when executing within a transaction that has a * transaction timeout when executing within a transaction that has a
* timeout specified at the transaction level. * timeout specified at the transaction level.
@ -1386,11 +1389,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 >= 0) {
stmt.setFetchSize(fetchSize); stmt.setFetchSize(fetchSize);
} }
int maxRows = getMaxRows(); int maxRows = getMaxRows();
if (maxRows > 0) { if (maxRows >= 0) {
stmt.setMaxRows(maxRows); stmt.setMaxRows(maxRows);
} }
DataSourceUtils.applyTimeout(stmt, getDataSource(), getQueryTimeout()); 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"); * 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.
@ -254,7 +254,7 @@ public abstract class DataSourceUtils {
* @see java.sql.Statement#setQueryTimeout * @see java.sql.Statement#setQueryTimeout
*/ */
public static void applyTransactionTimeout(Statement stmt, DataSource dataSource) throws SQLException { 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. // Remaining transaction timeout overrides specified value.
stmt.setQueryTimeout(holder.getTimeToLiveInSeconds()); stmt.setQueryTimeout(holder.getTimeToLiveInSeconds());
} }
else if (timeout > 0) { else if (timeout >= 0) {
// No current transaction timeout -> apply specified value. // No current transaction timeout -> apply specified value.
stmt.setQueryTimeout(timeout); stmt.setQueryTimeout(timeout);
} }

View File

@ -121,7 +121,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations
private long receiveTimeout = RECEIVE_TIMEOUT_INDEFINITE_WAIT; private long receiveTimeout = RECEIVE_TIMEOUT_INDEFINITE_WAIT;
private long deliveryDelay = 0; private long deliveryDelay = -1;
private boolean explicitQosEnabled = false; private boolean explicitQosEnabled = false;
@ -333,7 +333,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations
/** /**
* Set the delivery delay to use for send calls (in milliseconds). * Set the delivery delay to use for send calls (in milliseconds).
* <p>The default is 0 (no delivery delay). * <p>The default is -1 (no delivery delay passed on to the broker).
* Note that this feature requires JMS 2.0. * Note that this feature requires JMS 2.0.
*/ */
public void setDeliveryDelay(long deliveryDelay) { public void setDeliveryDelay(long deliveryDelay) {
@ -622,7 +622,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations
* @throws JMSException if thrown by JMS API methods * @throws JMSException if thrown by JMS API methods
*/ */
protected void doSend(MessageProducer producer, Message message) throws JMSException { protected void doSend(MessageProducer producer, Message message) throws JMSException {
if (this.deliveryDelay > 0) { if (this.deliveryDelay >= 0) {
if (setDeliveryDelayMethod == null) { if (setDeliveryDelayMethod == null) {
throw new IllegalStateException("setDeliveryDelay requires JMS 2.0"); throw new IllegalStateException("setDeliveryDelay requires JMS 2.0");
} }