From 1365b3785c95ebd3633646a7b634660485b0b077 Mon Sep 17 00:00:00 2001 From: David Syer Date: Thu, 6 May 2010 08:19:29 +0000 Subject: [PATCH] INT-1103: Added XML support for JdbcMessageStore --- .../.classpath | 20 ++-- org.springframework.integration.jdbc/pom.xml | 6 ++ .../jdbc/JdbcPollingChannelAdapter.java | 7 +- .../jdbc/config/JdbcNamespaceHandler.java | 2 + .../JdbcPollingChannelAdapterParser.java | 5 +- .../config/spring-integration-jdbc-2.0.xsd | 98 +++++++++++++++++-- .../jdbcInboundChannelAdapterCommonConfig.xml | 2 +- ...dbcInboundChannelAdapterWithUpdateTest.xml | 2 +- 8 files changed, 115 insertions(+), 27 deletions(-) diff --git a/org.springframework.integration.jdbc/.classpath b/org.springframework.integration.jdbc/.classpath index 1788a36a3e..bb4ac60998 100644 --- a/org.springframework.integration.jdbc/.classpath +++ b/org.springframework.integration.jdbc/.classpath @@ -1,10 +1,10 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/org.springframework.integration.jdbc/pom.xml b/org.springframework.integration.jdbc/pom.xml index a672d5f455..b37145ea65 100644 --- a/org.springframework.integration.jdbc/pom.xml +++ b/org.springframework.integration.jdbc/pom.xml @@ -49,6 +49,12 @@ derby 10.5.3.0_1 test + + + hsqldb + hsqldb + 1.8.0.7 + test org.springframework.integration diff --git a/org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/JdbcPollingChannelAdapter.java b/org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/JdbcPollingChannelAdapter.java index 676d68eac0..ea1b44f14e 100644 --- a/org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/JdbcPollingChannelAdapter.java +++ b/org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/JdbcPollingChannelAdapter.java @@ -23,6 +23,7 @@ import javax.sql.DataSource; import org.springframework.integration.core.Message; import org.springframework.integration.message.MessageBuilder; import org.springframework.integration.message.MessageSource; +import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.namedparam.SqlParameterSource; import org.springframework.jdbc.core.simple.SimpleJdbcOperations; @@ -66,14 +67,14 @@ public class JdbcPollingChannelAdapter implements MessageSource { } /** - * Constructor taking {@link SimpleJdbcOperations} instance to use for query + * Constructor taking {@link JdbcOperations} instance to use for query * execution and the select query to execute to retrieve new rows. * * @param jdbcOperations instance to use for query execution * @param selectQuery query to execute */ - public JdbcPollingChannelAdapter(SimpleJdbcOperations jdbcOperations, String selectQuery) { - this.jdbcOperations = jdbcOperations; + public JdbcPollingChannelAdapter(JdbcOperations jdbcOperations, String selectQuery) { + this.jdbcOperations = new SimpleJdbcTemplate(jdbcOperations); this.selectQuery = selectQuery; } diff --git a/org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/config/JdbcNamespaceHandler.java b/org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/config/JdbcNamespaceHandler.java index 9e591632b1..5980984e71 100644 --- a/org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/config/JdbcNamespaceHandler.java +++ b/org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/config/JdbcNamespaceHandler.java @@ -22,12 +22,14 @@ import org.springframework.integration.config.xml.AbstractIntegrationNamespaceHa * Namespace handler for the integration JDBC schema. * * @author Jonas Partner + * @author Dave Syer * @since 2.0 */ public class JdbcNamespaceHandler extends AbstractIntegrationNamespaceHandler { public void init() { registerBeanDefinitionParser("inbound-channel-adapter", new JdbcPollingChannelAdapterParser()); + registerBeanDefinitionParser("message-store", new JdbcMessageStoreParser()); } } diff --git a/org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/config/JdbcPollingChannelAdapterParser.java b/org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/config/JdbcPollingChannelAdapterParser.java index 53c3002aa9..a7af5a5d71 100644 --- a/org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/config/JdbcPollingChannelAdapterParser.java +++ b/org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/config/JdbcPollingChannelAdapterParser.java @@ -16,8 +16,6 @@ package org.springframework.integration.jdbc.config; -import org.w3c.dom.Element; - import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; @@ -25,6 +23,7 @@ import org.springframework.beans.factory.xml.ParserContext; import org.springframework.integration.config.xml.AbstractPollingInboundChannelAdapterParser; import org.springframework.integration.config.xml.IntegrationNamespaceUtils; import org.springframework.util.StringUtils; +import org.w3c.dom.Element; /** * Parser for {@link org.springframework.integration.jdbc.JdbcPollingChannelAdapter}. @@ -48,7 +47,7 @@ public class JdbcPollingChannelAdapterParser extends AbstractPollingInboundChann BeanDefinitionBuilder builder = BeanDefinitionBuilder .genericBeanDefinition("org.springframework.integration.jdbc.JdbcPollingChannelAdapter"); String dataSourceRef = element.getAttribute("data-source"); - String simpleJdbcOperationsRef = element.getAttribute("simple-jdbc-operations"); + String simpleJdbcOperationsRef = element.getAttribute("jdbc-operations"); boolean refToDataSourceSet = StringUtils.hasText(dataSourceRef); boolean refToSimpleJdbcOperaitonsSet = StringUtils.hasText(simpleJdbcOperationsRef); if ((refToDataSourceSet && refToSimpleJdbcOperaitonsSet) diff --git a/org.springframework.integration.jdbc/src/main/resources/org/springframework/integration/jdbc/config/spring-integration-jdbc-2.0.xsd b/org.springframework.integration.jdbc/src/main/resources/org/springframework/integration/jdbc/config/spring-integration-jdbc-2.0.xsd index 9a204a9ed2..2347807bbe 100644 --- a/org.springframework.integration.jdbc/src/main/resources/org/springframework/integration/jdbc/config/spring-integration-jdbc-2.0.xsd +++ b/org.springframework.integration.jdbc/src/main/resources/org/springframework/integration/jdbc/config/spring-integration-jdbc-2.0.xsd @@ -1,7 +1,6 @@ + + + + Defines a MessageStore (and MessageGroupStore) + backed by a database. + + + + + + + + + Reference to a data source to use to access + the database. Either this or the simple-jdbc-operations must be + specified (but not both). + + + + + + + + + + + + + Reference to a JdbcOperations. Either + this or the data-source must be + specified (but not both). + + + + + + + + + + + Unique string to use as a partition for the + data in this store, so that + multiple instances can share the same + database tables. The default + is "DEFAULT". + + + + + + + Prefix for the table names in the database + (e.g. so that a schema can be specified, or to avoid a clash + with + other tables). The default is "INT_". + + + + + + + + + + + + + + + + + + - Defines an inbound Channel Adapter for polling a database. + Defines an inbound Channel Adapter for polling a + database. - + - + @@ -52,14 +132,14 @@ - + - + diff --git a/org.springframework.integration.jdbc/src/test/resources/org/springframework/integration/jdbc/config/jdbcInboundChannelAdapterCommonConfig.xml b/org.springframework.integration.jdbc/src/test/resources/org/springframework/integration/jdbc/config/jdbcInboundChannelAdapterCommonConfig.xml index d4d0c1c033..6afe749d12 100644 --- a/org.springframework.integration.jdbc/src/test/resources/org/springframework/integration/jdbc/config/jdbcInboundChannelAdapterCommonConfig.xml +++ b/org.springframework.integration.jdbc/src/test/resources/org/springframework/integration/jdbc/config/jdbcInboundChannelAdapterCommonConfig.xml @@ -12,7 +12,7 @@ - + diff --git a/org.springframework.integration.jdbc/src/test/resources/org/springframework/integration/jdbc/config/pollingForMapJdbcInboundChannelAdapterWithUpdateTest.xml b/org.springframework.integration.jdbc/src/test/resources/org/springframework/integration/jdbc/config/pollingForMapJdbcInboundChannelAdapterWithUpdateTest.xml index 490971acca..764e696ac7 100644 --- a/org.springframework.integration.jdbc/src/test/resources/org/springframework/integration/jdbc/config/pollingForMapJdbcInboundChannelAdapterWithUpdateTest.xml +++ b/org.springframework.integration.jdbc/src/test/resources/org/springframework/integration/jdbc/config/pollingForMapJdbcInboundChannelAdapterWithUpdateTest.xml @@ -11,7 +11,7 @@ http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd"> + data-source="dataSource" update="update item set status=10 where id in (:idList)" />