Skip to content

Commit 57d63a1

Browse files
jhoellerunknown
authored andcommitted
JdbcTemplate and JmsTemplate pass settings with 0 values on to the driver
Issue: SPR-12338
1 parent aae221c commit 57d63a1

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,22 +111,22 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
111111
private boolean ignoreWarnings = true;
112112

113113
/**
114-
* If this variable is set to a non-zero value, it will be used for setting the
114+
* If this variable is set to a non-negative value, it will be used for setting the
115115
* fetchSize property on statements used for query processing.
116116
*/
117-
private int fetchSize = 0;
117+
private int fetchSize = -1;
118118

119119
/**
120-
* If this variable is set to a non-zero value, it will be used for setting the
120+
* If this variable is set to a non-negative value, it will be used for setting the
121121
* maxRows property on statements used for query processing.
122122
*/
123-
private int maxRows = 0;
123+
private int maxRows = -1;
124124

125125
/**
126-
* If this variable is set to a non-zero value, it will be used for setting the
126+
* If this variable is set to a non-negative value, it will be used for setting the
127127
* queryTimeout property on statements used for query processing.
128128
*/
129-
private int queryTimeout = 0;
129+
private int queryTimeout = -1;
130130

131131
/**
132132
* If this variable is set to true then all results checking will be bypassed for any
@@ -224,7 +224,8 @@ public boolean isIgnoreWarnings() {
224224
* large result sets: Setting this higher than the default value will increase
225225
* processing speed at the cost of memory consumption; setting this lower can
226226
* avoid transferring row data that will never be read by the application.
227-
* <p>Default is 0, indicating to use the JDBC driver's default.
227+
* <p>Default is -1, indicating to use the JDBC driver's default
228+
* (i.e. to not pass a specific fetch size setting on the driver).
228229
* @see java.sql.Statement#setFetchSize
229230
*/
230231
public void setFetchSize(int fetchSize) {
@@ -244,7 +245,8 @@ public int getFetchSize() {
244245
* the entire result set in the database or in the JDBC driver if we're
245246
* never interested in the entire result in the first place (for example,
246247
* when performing searches that might return a large number of matches).
247-
* <p>Default is 0, indicating to use the JDBC driver's default.
248+
* <p>Default is -1, indicating to use the JDBC driver's default
249+
* (i.e. to not pass a specific max rows setting on the driver).
248250
* @see java.sql.Statement#setMaxRows
249251
*/
250252
public void setMaxRows(int maxRows) {
@@ -260,7 +262,8 @@ public int getMaxRows() {
260262

261263
/**
262264
* Set the query timeout for statements that this JdbcTemplate executes.
263-
* <p>Default is 0, indicating to use the JDBC driver's default.
265+
* <p>Default is -1, indicating to use the JDBC driver's default
266+
* (i.e. to not pass a specific query timeout setting on the driver).
264267
* <p>Note: Any timeout specified here will be overridden by the remaining
265268
* transaction timeout when executing within a transaction that has a
266269
* timeout specified at the transaction level.
@@ -1386,11 +1389,11 @@ protected Map<String, Object> createResultsMap() {
13861389
*/
13871390
protected void applyStatementSettings(Statement stmt) throws SQLException {
13881391
int fetchSize = getFetchSize();
1389-
if (fetchSize > 0) {
1392+
if (fetchSize >= 0) {
13901393
stmt.setFetchSize(fetchSize);
13911394
}
13921395
int maxRows = getMaxRows();
1393-
if (maxRows > 0) {
1396+
if (maxRows >= 0) {
13941397
stmt.setMaxRows(maxRows);
13951398
}
13961399
DataSourceUtils.applyTimeout(stmt, getDataSource(), getQueryTimeout());

spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -254,7 +254,7 @@ public static boolean isConnectionTransactional(Connection con, DataSource dataS
254254
* @see java.sql.Statement#setQueryTimeout
255255
*/
256256
public static void applyTransactionTimeout(Statement stmt, DataSource dataSource) throws SQLException {
257-
applyTimeout(stmt, dataSource, 0);
257+
applyTimeout(stmt, dataSource, -1);
258258
}
259259

260260
/**
@@ -274,7 +274,7 @@ public static void applyTimeout(Statement stmt, DataSource dataSource, int timeo
274274
// Remaining transaction timeout overrides specified value.
275275
stmt.setQueryTimeout(holder.getTimeToLiveInSeconds());
276276
}
277-
else if (timeout > 0) {
277+
else if (timeout >= 0) {
278278
// No current transaction timeout -> apply specified value.
279279
stmt.setQueryTimeout(timeout);
280280
}

spring-jms/src/main/java/org/springframework/jms/core/JmsTemplate.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations
121121

122122
private long receiveTimeout = RECEIVE_TIMEOUT_INDEFINITE_WAIT;
123123

124-
private long deliveryDelay = 0;
124+
private long deliveryDelay = -1;
125125

126126

127127
private boolean explicitQosEnabled = false;
@@ -333,7 +333,7 @@ public long getReceiveTimeout() {
333333

334334
/**
335335
* Set the delivery delay to use for send calls (in milliseconds).
336-
* <p>The default is 0 (no delivery delay).
336+
* <p>The default is -1 (no delivery delay passed on to the broker).
337337
* Note that this feature requires JMS 2.0.
338338
*/
339339
public void setDeliveryDelay(long deliveryDelay) {
@@ -622,7 +622,7 @@ protected void doSend(Session session, Destination destination, MessageCreator m
622622
* @throws JMSException if thrown by JMS API methods
623623
*/
624624
protected void doSend(MessageProducer producer, Message message) throws JMSException {
625-
if (this.deliveryDelay > 0) {
625+
if (this.deliveryDelay >= 0) {
626626
if (setDeliveryDelayMethod == null) {
627627
throw new IllegalStateException("setDeliveryDelay requires JMS 2.0");
628628
}

0 commit comments

Comments
 (0)