diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java index 73783db820..6190090e4b 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java @@ -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. - *

Default is 0, indicating to use the JDBC driver's default. + *

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). - *

Default is 0, indicating to use the JDBC driver's default. + *

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. - *

Default is 0, indicating to use the JDBC driver's default. + *

Default is -1, indicating to use the JDBC driver's default + * (i.e. to not pass a specific query timeout setting on the driver). *

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()); diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceUtils.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceUtils.java index 7c58f69d61..5cad3aa6f0 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceUtils.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceUtils.java @@ -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); } diff --git a/spring-jms/src/main/java/org/springframework/jms/core/JmsTemplate.java b/spring-jms/src/main/java/org/springframework/jms/core/JmsTemplate.java index d1d9caecee..8ae419c502 100644 --- a/spring-jms/src/main/java/org/springframework/jms/core/JmsTemplate.java +++ b/spring-jms/src/main/java/org/springframework/jms/core/JmsTemplate.java @@ -121,7 +121,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations private long receiveTimeout = RECEIVE_TIMEOUT_INDEFINITE_WAIT; - private long deliveryDelay = 0; + private long deliveryDelay = -1; 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). - *

The default is 0 (no delivery delay). + *

The default is -1 (no delivery delay passed on to the broker). * Note that this feature requires JMS 2.0. */ public void setDeliveryDelay(long deliveryDelay) { @@ -622,7 +622,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations * @throws JMSException if thrown by JMS API methods */ protected void doSend(MessageProducer producer, Message message) throws JMSException { - if (this.deliveryDelay > 0) { + if (this.deliveryDelay >= 0) { if (setDeliveryDelayMethod == null) { throw new IllegalStateException("setDeliveryDelay requires JMS 2.0"); }