diff --git a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/JdbcOutboundGateway.java b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/JdbcOutboundGateway.java
index f2e96bd484..e8fa488f83 100644
--- a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/JdbcOutboundGateway.java
+++ b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/JdbcOutboundGateway.java
@@ -31,6 +31,7 @@ import org.springframework.util.Assert;
/**
* @author Dave Syer
+ * @author Gunnar Hillert
*
* @since 2.0
*/
@@ -44,6 +45,8 @@ public class JdbcOutboundGateway extends AbstractReplyProducingMessageHandler im
private volatile boolean keysGenerated;
+ private volatile Integer maxRowsPerPoll;
+
public JdbcOutboundGateway(DataSource dataSource, String updateQuery) {
this(new JdbcTemplate(dataSource), updateQuery, null);
}
@@ -67,16 +70,34 @@ public class JdbcOutboundGateway extends AbstractReplyProducingMessageHandler im
handler = new JdbcMessageHandler(jdbcOperations, updateQuery);
}
- public void setMaxRowsPerPoll(int maxRows) {
-
- Assert.notNull(poller, "If you want to set 'maxRowsPerPoll', then you must provide a 'selectQuery'.");
- poller.setMaxRowsPerPoll(maxRows);
-
+ /**
+ * The maximum number of rows to pull out of the query results per poll (if
+ * greater than zero, otherwise all rows will be packed into the outgoing
+ * message).
+ *
+ * The value is ultimately set on the underlying {@link JdbcPollingChannelAdapter}.
+ * If not specified this value will default to zero.
+ *
+ * This parameter is only applicable if a selectQuery was provided. Null values
+ * are not permitted.
+ *
+ * @param maxRowsPerPoll Must not be null.
+ */
+ public void setMaxRowsPerPoll(Integer maxRowsPerPoll) {
+ Assert.notNull(maxRowsPerPoll, "MaxRowsPerPoll must not be null.");
+ this.maxRowsPerPoll = maxRowsPerPoll;
}
@Override
protected void onInit() {
+
+ if (this.maxRowsPerPoll != null) {
+ Assert.notNull(poller, "If you want to set 'maxRowsPerPoll', then you must provide a 'selectQuery'.");
+ poller.setMaxRowsPerPoll(this.maxRowsPerPoll);
+ }
+
handler.afterPropertiesSet();
+
}
@Override
diff --git a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/config/JdbcOutboundGatewayParser.java b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/config/JdbcOutboundGatewayParser.java
index 56dd78a1bd..b9f9a30c6e 100644
--- a/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/config/JdbcOutboundGatewayParser.java
+++ b/spring-integration-jdbc/src/main/java/org/springframework/integration/jdbc/config/JdbcOutboundGatewayParser.java
@@ -23,6 +23,8 @@ import org.w3c.dom.Element;
/**
* @author Dave Syer
+ * @author Gunnar Hillert
+ *
* @since 2.0
*
*/
diff --git a/spring-integration-jdbc/src/main/resources/org/springframework/integration/jdbc/config/spring-integration-jdbc-2.1.xsd b/spring-integration-jdbc/src/main/resources/org/springframework/integration/jdbc/config/spring-integration-jdbc-2.1.xsd
index b1ca0f222b..5f8d484cd6 100644
--- a/spring-integration-jdbc/src/main/resources/org/springframework/integration/jdbc/config/spring-integration-jdbc-2.1.xsd
+++ b/spring-integration-jdbc/src/main/resources/org/springframework/integration/jdbc/config/spring-integration-jdbc-2.1.xsd
@@ -595,14 +595,20 @@
-
-
+
+ ]]>
@@ -731,35 +735,39 @@
-
-
+
-
+
diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcOutboundGatewayTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcOutboundGatewayTests.java
index ab8815fc44..1bfe6658cf 100644
--- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcOutboundGatewayTests.java
+++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcOutboundGatewayTests.java
@@ -29,10 +29,6 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
*/
public class JdbcOutboundGatewayTests {
- /**
- * Test method for
- * {@link org.springframework.integration.jdbc.JdbcOutboundGateway#setMaxRowsPerPoll(int)}.
- */
@Test
public void testSetMaxRowsPerPollWithoutSelectQuery() {
@@ -43,6 +39,8 @@ public class JdbcOutboundGatewayTests {
try {
jdbcOutboundGateway.setMaxRowsPerPoll(10);
+ jdbcOutboundGateway.onInit();
+
} catch (IllegalArgumentException e) {
assertEquals("If you want to set 'maxRowsPerPoll', then you must provide a 'selectQuery'.", e.getMessage());
return;
@@ -52,4 +50,26 @@ public class JdbcOutboundGatewayTests {
}
+ /**
+ * Test method for
+ * {@link org.springframework.integration.jdbc.JdbcOutboundGateway#setMaxRowsPerPoll(Integer)}.
+ */
+ @Test
+ public void testSetMaxRowsPerPoll() {
+
+
+ DataSource dataSource = new EmbeddedDatabaseBuilder().build();
+
+ JdbcOutboundGateway jdbcOutboundGateway = new JdbcOutboundGateway(dataSource, "select * from DOES_NOT_EXIST");
+
+ try {
+ jdbcOutboundGateway.setMaxRowsPerPoll(null);
+ } catch (IllegalArgumentException e) {
+ assertEquals("MaxRowsPerPoll must not be null.", e.getMessage());
+ return;
+ }
+
+ fail("Expected an IllegalArgumentException to be thrown.");
+
+ }
}