INT-2246 - Changes based on code review.
This commit is contained in:
committed by
Mark Fisher
parent
6f33252c7c
commit
462af6bea0
@@ -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 <code>zero</code>.
|
||||
*
|
||||
* 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
|
||||
|
||||
@@ -23,6 +23,8 @@ import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Gunnar Hillert
|
||||
*
|
||||
* @since 2.0
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -595,14 +595,20 @@
|
||||
<xsd:element name="sql-parameter-definition" minOccurs="0"
|
||||
maxOccurs="unbounded" type="sqlParameterDefinitionType">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
<![CDATA[
|
||||
For fully supported database these parameters
|
||||
need not be declared as for those database the
|
||||
type information can be retrieved from the
|
||||
JDBC Metadata.
|
||||
<xsd:documentation><![CDATA[
|
||||
If you are using a database that is fully supported,
|
||||
you typically don't have to specify the Stored Procedure
|
||||
parameter definitions using the 'sql-parameter-definition'
|
||||
attribute.
|
||||
|
||||
Instead, those parameters can be automatically derived
|
||||
from the JDBC Meta-data. However, if you are using
|
||||
databases that are not fully supported or if you like
|
||||
to provide customized parameter definitions, you can
|
||||
set those parameters explicitly. See also the
|
||||
'ignore-column-meta-data' attribute.
|
||||
|
||||
Fully Supported Databases (Stored Procedures):
|
||||
Fully Supported Databases (Stored Procedures):
|
||||
|
||||
* Apache Derby
|
||||
* DB2
|
||||
@@ -612,16 +618,14 @@
|
||||
* PostgreSQL
|
||||
* Sybase
|
||||
|
||||
Fully Supported Databases (Functions)
|
||||
Fully Supported Databases (Functions)
|
||||
|
||||
* MySQL
|
||||
* Microsoft SQL Server
|
||||
* Oracle
|
||||
* PostgreSQL
|
||||
|
||||
If you use a database not listed above, you
|
||||
MUST provide Sql Parameter Definitions.
|
||||
]]>
|
||||
|
||||
]]>
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:element>
|
||||
@@ -731,35 +735,39 @@
|
||||
<xsd:element name="sql-parameter-definition" minOccurs="0"
|
||||
maxOccurs="unbounded" type="sqlParameterDefinitionType">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
<![CDATA[
|
||||
For fully supported database these parameters
|
||||
generally need not be declared as for those
|
||||
databases the type information can be
|
||||
retrieved from the JDBC Metadata.
|
||||
|
||||
Fully Supported Databases (Stored Procedures):
|
||||
|
||||
* Apache Derby
|
||||
* DB2
|
||||
* MySQL
|
||||
* Microsoft SQL Server
|
||||
* Oracle
|
||||
* PostgreSQL
|
||||
* Sybase
|
||||
|
||||
Fully Supported Databases (Functions)
|
||||
|
||||
* MySQL
|
||||
* Microsoft SQL Server
|
||||
* Oracle
|
||||
* PostgreSQL
|
||||
|
||||
If you use a database not listed above, you
|
||||
MUST provide Sql Parameter Definitions.
|
||||
]]>
|
||||
<xsd:documentation><![CDATA[
|
||||
If you are using a database that is fully supported,
|
||||
you typically don't have to specify the Stored Procedure
|
||||
parameter definitions using the 'sql-parameter-definition'
|
||||
attribute.
|
||||
|
||||
Instead, those parameters can be automatically derived
|
||||
from the JDBC Meta-data. However, if you are using
|
||||
databases that are not fully supported or if you like
|
||||
to provide customized parameter definitions, you can
|
||||
set those parameters explicitly. See also the
|
||||
'ignore-column-meta-data' attribute.
|
||||
|
||||
Fully Supported Databases (Stored Procedures):
|
||||
|
||||
* Apache Derby
|
||||
* DB2
|
||||
* MySQL
|
||||
* Microsoft SQL Server
|
||||
* Oracle
|
||||
* PostgreSQL
|
||||
* Sybase
|
||||
|
||||
Fully Supported Databases (Functions)
|
||||
|
||||
* MySQL
|
||||
* Microsoft SQL Server
|
||||
* Oracle
|
||||
* PostgreSQL
|
||||
|
||||
]]>
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:annotation>
|
||||
</xsd:element>
|
||||
<xsd:element name="parameter" minOccurs="0" maxOccurs="unbounded"
|
||||
type="parameterSubElementType">
|
||||
|
||||
@@ -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.");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user