From 9da682fc01a47f838dec46d68162f5960e2bd726 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Thu, 29 Apr 2010 18:18:48 +0000 Subject: [PATCH] polishing --- ... => DefaultSqlParameterSourceFactory.java} | 71 +++++++------- .../integration/jdbc/JdbcMessageStore.java | 83 +++++++++-------- .../jdbc/JdbcPollingChannelAdapter.java | 92 +++++++++---------- ...ry.java => SqlParameterSourceFactory.java} | 15 ++- .../jdbc/config/JdbcNamespaceHandler.java | 6 +- .../JdbcPollingChannelAdapterParser.java | 44 ++++----- .../jdbc/util/SerializationUtils.java | 19 ++-- .../config/spring-integration-jdbc-2.0.xsd | 19 ++-- .../jdbc/JdbcMessageStoreTests-context.xml | 16 ++-- .../jdbcInboundChannelAdapterCommonConfig.xml | 17 ++-- ...ingForMapJdbcInboundChannelAdapterTest.xml | 2 +- ...dbcInboundChannelAdapterWithUpdateTest.xml | 10 +- 12 files changed, 188 insertions(+), 206 deletions(-) rename org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/{DefaultSqlParamterSourceFactory.java => DefaultSqlParameterSourceFactory.java} (59%) rename org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/{SqlParamterSourceFactory.java => SqlParameterSourceFactory.java} (72%) diff --git a/org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/DefaultSqlParamterSourceFactory.java b/org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/DefaultSqlParameterSourceFactory.java similarity index 59% rename from org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/DefaultSqlParamterSourceFactory.java rename to org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/DefaultSqlParameterSourceFactory.java index 1604b561c5..16a6bbe39a 100644 --- a/org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/DefaultSqlParamterSourceFactory.java +++ b/org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/DefaultSqlParameterSourceFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2010 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. @@ -24,65 +24,64 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.beans.DirectFieldAccessor; import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.jdbc.core.namedparam.SqlParameterSource; /** - * A default implementation of {@link SqlParamterSourceFactory} which creates an - * {@link SqlParameterSource} according to the result of the polled data passed - * in + * A default implementation of {@link SqlParameterSourceFactory} which creates an + * {@link SqlParameterSource} according to the result of the polled data passed in. * - * Where the result of the poll is a List a list of ids generated by looking for - * a map entry or bean property named by default 'id'. The resulting {@link SqlParameterSource} - * contains this list under a default key of 'idList'. + * Where the result of the poll is a List, a list of ids is generated by looking for + * a map entry or bean property named by default 'id'. The resulting + * {@link SqlParameterSource} contains this list under a default key of 'idList'. * - * Where the result of the poll is a {@link Map} this is wrapped in an instance of {@link MapSqlParameterSource} - * Otherwise the result is wrapped in an instance of {@link BeanPropertySqlParameterSource} + * Where the result of the poll is a {@link Map}, this is wrapped in an instance of + * {@link MapSqlParameterSource}. Otherwise the result is wrapped in an instance of + * {@link BeanPropertySqlParameterSource}. * * @author Jonas Partner - * + * @since 2.0 */ -public class DefaultSqlParamterSourceFactory implements - SqlParamterSourceFactory { +public class DefaultSqlParameterSourceFactory implements SqlParameterSourceFactory { private final Log logger = LogFactory.getLog(getClass()); private final Map staticParameters; - private volatile String polledRowIdName = "id"; + private final String polledRowIdName = "id"; - private volatile String updateIdsParamName = "idList"; + private final String updateIdsParamName = "idList"; - public DefaultSqlParamterSourceFactory() { - this.staticParameters = Collections - .unmodifiableMap(new HashMap()); + + public DefaultSqlParameterSourceFactory() { + this.staticParameters = Collections.unmodifiableMap(new HashMap()); } - public DefaultSqlParamterSourceFactory(Map staticParameters) { + public DefaultSqlParameterSourceFactory(Map staticParameters) { this.staticParameters = Collections.unmodifiableMap(staticParameters); } - public SqlParameterSource createParamterSource(Object resultOfSelect) { + + @SuppressWarnings("unchecked") + public SqlParameterSource createParameterSource(Object resultOfSelect) { SqlParameterSource toReturn; if (resultOfSelect instanceof List) { List ids = new ArrayList(); for (Object rowObj : (List) resultOfSelect) { if (rowObj instanceof Map) { ids.add(((Map) rowObj).get(this.polledRowIdName)); - } else { - DirectFieldAccessor accessor = new DirectFieldAccessor( - rowObj); + } + else { + DirectFieldAccessor accessor = new DirectFieldAccessor(rowObj); if (accessor.isReadableProperty(this.polledRowIdName)) { - ids - .add(accessor - .getPropertyValue(this.polledRowIdName)); - } else { - logger - .warn("No id field named " - + this.polledRowIdName - + " found for result of polled row. Update may not include all rows"); + ids.add(accessor.getPropertyValue(this.polledRowIdName)); + } + else { + logger.warn("No id field named '" + this.polledRowIdName + + "' found for result of polled row. Update may not include all rows."); } } } @@ -93,14 +92,14 @@ public class DefaultSqlParamterSourceFactory implements thisParamSource.addValue(this.updateIdsParamName, ids); thisParamSource.getValue("idList"); toReturn = thisParamSource; - } else if (resultOfSelect instanceof Map) { - MapSqlParameterSource mapParameterSource = new MapSqlParameterSource( - (Map) resultOfSelect); + } + else if (resultOfSelect instanceof Map) { + MapSqlParameterSource mapParameterSource = new MapSqlParameterSource((Map) resultOfSelect); mapParameterSource.addValues(this.staticParameters); toReturn = mapParameterSource; - } else { - BeanPropertySqlParameterSource beanParameterSource = new BeanPropertySqlParameterSource( - resultOfSelect); + } + else { + BeanPropertySqlParameterSource beanParameterSource = new BeanPropertySqlParameterSource(resultOfSelect); toReturn = beanParameterSource; } return toReturn; diff --git a/org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/JdbcMessageStore.java b/org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/JdbcMessageStore.java index e84d51081a..2f1e618b9c 100644 --- a/org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/JdbcMessageStore.java +++ b/org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/JdbcMessageStore.java @@ -1,3 +1,19 @@ +/* + * Copyright 2002-2010 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.springframework.integration.jdbc; import java.sql.PreparedStatement; @@ -13,6 +29,7 @@ import javax.sql.DataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.integration.core.Message; import org.springframework.integration.jdbc.util.SerializationUtils; import org.springframework.integration.message.MessageBuilder; @@ -34,7 +51,7 @@ import org.springframework.util.StringUtils; * * is the target database type. * * @author Dave Syer - * + * @since 2.0 */ public class JdbcMessageStore implements MessageStore { @@ -76,6 +93,7 @@ public class JdbcMessageStore implements MessageStore { private MessageMapper mapper = new MessageMapper(); + /** * Convenient constructor for configuration use. */ @@ -91,6 +109,7 @@ public class JdbcMessageStore implements MessageStore { jdbcTemplate = new JdbcTemplate(dataSource); } + /** * Replace patterns in the input to produce a valid SQL query. This * implementation replaces the table prefix. @@ -126,8 +145,8 @@ public class JdbcMessageStore implements MessageStore { /** * The {@link JdbcOperations} to use when interacting with the database. - * Either this property can be set or the {@link #setDataSource(DataSource) - * dataSource}. + * Either this property can be set or the + * {@link #setDataSource(DataSource) dataSource}. * * @param dataSource a {@link DataSource} */ @@ -156,21 +175,16 @@ public class JdbcMessageStore implements MessageStore { } public Message delete(UUID id) { - Message message = get(id); if (message == null) { return null; } - int updated = jdbcTemplate.update(getQuery(DELETE_MESSAGE), new Object[] { getKey(id) }, new int[] { Types.VARCHAR }); - if (updated != 0) { return message; } - return null; - } public Message get(UUID id) { @@ -182,12 +196,11 @@ public class JdbcMessageStore implements MessageStore { } public List> list(Object correlationId) { - return jdbcTemplate.query(getQuery(LIST_MESSAGES_BY_CORRELATION_KEY), new Object[] { getKey(correlationId) }, - mapper); + return jdbcTemplate.query(getQuery(LIST_MESSAGES_BY_CORRELATION_KEY), + new Object[] { getKey(correlationId) }, mapper); } public Message put(final Message message) { - if (message.getHeaders().containsKey(SAVED_KEY)) { @SuppressWarnings("unchecked") Message saved = (Message) get(message.getHeaders().getId()); @@ -214,41 +227,15 @@ public class JdbcMessageStore implements MessageStore { lobHandler.getLobCreator().setBlobAsBytes(ps, 4, messageBytes); } }); - return result; - - } - - private String getKey(Object input) { - return input==null ? null : UUIDConverter.getUUID(input).toString(); - } - - /** - * Convenience class to be used to unpack a message from a result set row. - * Uses column named in the result set to extract the required data, so that - * select clause ordering is unimportant. - * - * @author Dave Syer - * - */ - private class MessageMapper implements RowMapper> { - - public Message mapRow(ResultSet rs, int rowNum) throws SQLException { - Message message = (Message) SerializationUtils.deserialize(lobHandler.getBlobAsBytes(rs, - "MESSAGE_BYTES")); - return message; - } - } public void put(Object correlationId, Message message) { // TODO Auto-generated method stub - } public void put(Object correlationId, Collection> messages) { // TODO Auto-generated method stub - } public Message delete(Object correlationId, UUID messageId) { @@ -258,7 +245,27 @@ public class JdbcMessageStore implements MessageStore { public void deleteAll(Object correlationId) { // TODO Auto-generated method stub - + } + + private String getKey(Object input) { + return input == null ? null : UUIDConverter.getUUID(input).toString(); + } + + + /** + * Convenience class to be used to unpack a message from a result set row. + * Uses column named in the result set to extract the required data, so that + * select clause ordering is unimportant. + * + * @author Dave Syer + */ + private class MessageMapper implements RowMapper> { + + public Message mapRow(ResultSet rs, int rowNum) throws SQLException { + Message message = (Message) SerializationUtils.deserialize( + lobHandler.getBlobAsBytes(rs, "MESSAGE_BYTES")); + return message; + } } } 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 60b28e86b7..676d68eac0 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2010 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. @@ -30,10 +30,11 @@ import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; /** * A polling channel adapter that creates messages from the payload returned by - * executing a select query Optionally an update can be executed after the - * select in order to update processed rows + * executing a select query. Optionally an update can be executed after the + * select in order to update processed rows. * * @author Jonas Partner + * @since 2.0 */ public class JdbcPollingChannelAdapter implements MessageSource { @@ -49,16 +50,15 @@ public class JdbcPollingChannelAdapter implements MessageSource { private volatile String updateSql; - private volatile SqlParamterSourceFactory sqlParameterSourceFactoryForUpdate = new DefaultSqlParamterSourceFactory(); + private volatile SqlParameterSourceFactory sqlParameterSourceFactoryForUpdate = new DefaultSqlParameterSourceFactory(); + /** - * Constructor taking query to execute to retreive new rows and - * {@link DataSource} from which the DB Connection can be obtained + * Constructor taking {@link DataSource} from which the DB Connection can + * be obtained and the select query to execute to retrieve new rows. * - * @param dataSource - * used to create a {@link SimpleJdbcTemplate} - * @param selectQuery - * query to execute + * @param dataSource used to create a {@link SimpleJdbcTemplate} + * @param selectQuery query to execute */ public JdbcPollingChannelAdapter(DataSource dataSource, String selectQuery) { this.jdbcOperations = new SimpleJdbcTemplate(dataSource); @@ -66,19 +66,18 @@ public class JdbcPollingChannelAdapter implements MessageSource { } /** - * Constructor taking query to execute on a poll and - * {@link SimpleJdbcOperations} instance to use for query execution + * Constructor taking {@link SimpleJdbcOperations} instance to use for query + * execution and the select query to execute to retrieve new rows. * - * @param jdbcOperations - * @param selectQuery - * query to execute + * @param jdbcOperations instance to use for query execution + * @param selectQuery query to execute */ - public JdbcPollingChannelAdapter(SimpleJdbcOperations jdbcOperations, - String selectQuery) { + public JdbcPollingChannelAdapter(SimpleJdbcOperations jdbcOperations, String selectQuery) { this.jdbcOperations = jdbcOperations; this.selectQuery = selectQuery; } + public void setRowMapper(RowMapper rowMapper) { this.rowMapper = rowMapper; } @@ -91,18 +90,18 @@ public class JdbcPollingChannelAdapter implements MessageSource { this.updatePerRow = updatePerRow; } - public void setSqlParameterSourceFactoryForUpdate( - SqlParamterSourceFactory sqlParameterSourceFactoryForUpdate) { + public void setSqlParameterSourceFactoryForUpdate(SqlParameterSourceFactory sqlParameterSourceFactoryForUpdate) { this.sqlParameterSourceFactoryForUpdate = sqlParameterSourceFactoryForUpdate; } /** - * Polls for new rows returning a message containing one or more rows where - * rows are found and null where no rows are returned by the select query + * Executes the query. If a query result set contains one or more rows, the Message + * payload will contain either a List of Maps for each row or, if a RowMapper has + * been provided, the values mapped from those rows. If the query returns no rows, + * this method will return null. */ public Message receive() { - Object payload = null; - payload = pollAndUpdate(); + Object payload = pollAndUpdate(); if (payload == null) { return null; } @@ -110,59 +109,54 @@ public class JdbcPollingChannelAdapter implements MessageSource { } /** - * Execute the select query and the update query if provided and rows are - * returned by the select query - * - * @return + * Execute the select query and the update query if provided. + * Returns the rows returned by the select query. If a RowMapper + * has been provided, the mapped results are returned. */ - protected Object pollAndUpdate() { - List payload; + private Object pollAndUpdate() { + List payload; if (this.rowMapper != null) { payload = pollWithRowMapper(); - } else { - payload = this.jdbcOperations.queryForList(this.selectQuery, - this.sqlQueryParameterSource); } - + else { + payload = this.jdbcOperations.queryForList(this.selectQuery, this.sqlQueryParameterSource); + } if (payload.size() < 1) { payload = null; } - if (payload != null && updateSql != null) { if (this.updatePerRow) { for (Object row : payload) { executeUpdateQuery(row); } - } else { + } + else { executeUpdateQuery(payload); } } return payload; - } - protected void executeUpdateQuery(Object obj) { + private void executeUpdateQuery(Object obj) { SqlParameterSource updateParamaterSource = null; if (this.sqlParameterSourceFactoryForUpdate != null) { - - updateParamaterSource = this.sqlParameterSourceFactoryForUpdate - .createParamterSource(obj); + updateParamaterSource = this.sqlParameterSourceFactoryForUpdate.createParameterSource(obj); this.jdbcOperations.update(this.updateSql, updateParamaterSource); - } else { + } + else { this.jdbcOperations.update(this.updateSql); } } - protected List pollWithRowMapper() { - List payload = null; + private List pollWithRowMapper() { + List payload = null; if (this.sqlQueryParameterSource != null) { - payload = this.jdbcOperations.query(this.selectQuery, - this.rowMapper, this.sqlQueryParameterSource); - } else { - payload = this.jdbcOperations.query(this.selectQuery, - this.rowMapper); + payload = this.jdbcOperations.query(this.selectQuery, this.rowMapper, this.sqlQueryParameterSource); + } + else { + payload = this.jdbcOperations.query(this.selectQuery, this.rowMapper); } return payload; } -} \ No newline at end of file +} diff --git a/org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/SqlParamterSourceFactory.java b/org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/SqlParameterSourceFactory.java similarity index 72% rename from org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/SqlParamterSourceFactory.java rename to org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/SqlParameterSourceFactory.java index 09f5096bfd..f2b57fa0b9 100644 --- a/org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/SqlParamterSourceFactory.java +++ b/org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/SqlParameterSourceFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2010 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. @@ -21,18 +21,17 @@ import org.springframework.jdbc.core.namedparam.SqlParameterSource; /** * Collaborator for {@link JdbcPollingChannelAdapter} which allows creation of * instances of {@link SqlParameterSource} for use in updates to be created - * according to the result of the poll + * according to the result of the poll. * * @author Jonas Partner - * + * @since 2.0 */ -public interface SqlParamterSourceFactory { +public interface SqlParameterSourceFactory { /** - * Return a new {@link SqlParameterSource} - * @param obj the result of the preceeding poll operation - * @return + * Return a new {@link SqlParameterSource}. + * @param pollResult the result of the preceding poll operation */ - public SqlParameterSource createParamterSource(Object obj); + public SqlParameterSource createParameterSource(Object resultOfSelect); } 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 d8a296be2b..9e591632b1 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 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. @@ -13,14 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.jdbc.config; import org.springframework.integration.config.xml.AbstractIntegrationNamespaceHandler; /** + * Namespace handler for the integration JDBC schema. * * @author Jonas Partner - * + * @since 2.0 */ public class JdbcNamespaceHandler extends AbstractIntegrationNamespaceHandler { 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 f58b0fe56c..53c3002aa9 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2010 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. @@ -16,6 +16,8 @@ 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; @@ -23,15 +25,14 @@ 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 JdbcPollingChannelAdapterParser} + * Parser for {@link org.springframework.integration.jdbc.JdbcPollingChannelAdapter}. + * * @author Jonas Partner - * + * @since 2.0 */ -public class JdbcPollingChannelAdapterParser extends - AbstractPollingInboundChannelAdapterParser { +public class JdbcPollingChannelAdapterParser extends AbstractPollingInboundChannelAdapterParser { protected boolean shouldGenerateId() { return false; @@ -40,44 +41,37 @@ public class JdbcPollingChannelAdapterParser extends protected boolean shouldGenerateIdAsFallback() { return true; } - - + @Override protected String parseSource(Element element, ParserContext parserContext) { + Object source = parserContext.extractSource(element); 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("simple-jdbc-operations"); boolean refToDataSourceSet = StringUtils.hasText(dataSourceRef); - boolean refToSimpleJdbcOperaitonsSet = StringUtils - .hasText(simpleJdbcOperationsRef); - + boolean refToSimpleJdbcOperaitonsSet = StringUtils.hasText(simpleJdbcOperationsRef); if ((refToDataSourceSet && refToSimpleJdbcOperaitonsSet) || (!refToDataSourceSet && !refToSimpleJdbcOperaitonsSet)) { - throw new BeanCreationException( - "Exactly one of the attributes data-source or simple-jdbc-operations should be set for the JDBC inbound-channel-adapter"); + parserContext.getReaderContext().error("Exactly one of the attributes data-source or " + + "simple-jdbc-operations should be set for the JDBC inbound-channel-adapter", source); } - String query = element.getAttribute("query"); - if(!StringUtils.hasText(query)){ + if (!StringUtils.hasText(query)) { throw new BeanCreationException("The query attrbitue is required"); } - if(refToDataSourceSet){ + if (refToDataSourceSet) { builder.addConstructorArgReference(dataSourceRef); - } else { + } + else { builder.addConstructorArgReference(simpleJdbcOperationsRef); } builder.addConstructorArgValue(query); - IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "row-mapper"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "update", "updateSql"); IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "update-per-row"); - - - - return BeanDefinitionReaderUtils.registerWithGeneratedName(builder - .getBeanDefinition(), parserContext.getRegistry()); + return BeanDefinitionReaderUtils.registerWithGeneratedName( + builder.getBeanDefinition(), parserContext.getRegistry()); } } diff --git a/org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/util/SerializationUtils.java b/org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/util/SerializationUtils.java index 400597e7d7..c7c1b66bed 100644 --- a/org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/util/SerializationUtils.java +++ b/org.springframework.integration.jdbc/src/main/java/org/springframework/integration/jdbc/util/SerializationUtils.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.jdbc.util; import java.io.ByteArrayInputStream; @@ -21,12 +22,10 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; - /** * Static utility to help with serialization. * * @author Dave Syer - * */ public class SerializationUtils { @@ -37,20 +36,17 @@ public class SerializationUtils { * @return an array of bytes representing the object in a portable fashion */ public static byte[] serialize(Object object) { - - if (object==null) { + if (object == null) { return null; } - ByteArrayOutputStream stream = new ByteArrayOutputStream(); try { new ObjectOutputStream(stream).writeObject(object); - } catch (IOException e) { - throw new IllegalArgumentException("Could not serialize object of type: "+object.getClass(), e); } - + catch (IOException e) { + throw new IllegalArgumentException("Could not serialize object of type: " + object.getClass(), e); + } return stream.toByteArray(); - } /** @@ -58,11 +54,9 @@ public class SerializationUtils { * @return the result of deserializing the bytes */ public static Object deserialize(byte[] bytes) { - - if (bytes==null) { + if (bytes == null) { return null; } - try { return new ObjectInputStream(new ByteArrayInputStream(bytes)).readObject(); } @@ -72,7 +66,6 @@ public class SerializationUtils { catch (ClassNotFoundException e) { throw new IllegalStateException("Could not deserialize object type", e); } - } } 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 dde6b88e8d..9a204a9ed2 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,6 +1,7 @@ - - Defines an inbound Channel Adapter for polling a database. + Defines an inbound Channel Adapter for polling a database. - + + type="org.springframework.jdbc.core.simple.SimpleJdbcOperations" /> @@ -43,7 +42,7 @@ - + @@ -54,14 +53,13 @@ + type="org.springframework.jdbc.core.RowMapper" /> - + @@ -74,4 +72,5 @@ + \ No newline at end of file diff --git a/org.springframework.integration.jdbc/src/test/resources/org/springframework/integration/jdbc/JdbcMessageStoreTests-context.xml b/org.springframework.integration.jdbc/src/test/resources/org/springframework/integration/jdbc/JdbcMessageStoreTests-context.xml index 103b5a264d..5adbde114a 100644 --- a/org.springframework.integration.jdbc/src/test/resources/org/springframework/integration/jdbc/JdbcMessageStoreTests-context.xml +++ b/org.springframework.integration.jdbc/src/test/resources/org/springframework/integration/jdbc/JdbcMessageStoreTests-context.xml @@ -1,24 +1,22 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:jdbc="http://www.springframework.org/schema/jdbc" + xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> - - + + - + 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 e6f2b0b922..d4d0c1c033 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 @@ -1,10 +1,12 @@ + xmlns:beans="http://www.springframework.org/schema/beans" + xmlns:si="http://www.springframework.org/schema/integration" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:jdbc="http://www.springframework.org/schema/jdbc" + xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd + http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> @@ -14,13 +16,12 @@ - + - + - \ No newline at end of file diff --git a/org.springframework.integration.jdbc/src/test/resources/org/springframework/integration/jdbc/config/pollingForMapJdbcInboundChannelAdapterTest.xml b/org.springframework.integration.jdbc/src/test/resources/org/springframework/integration/jdbc/config/pollingForMapJdbcInboundChannelAdapterTest.xml index 5178a8df57..eda3d79d7e 100644 --- a/org.springframework.integration.jdbc/src/test/resources/org/springframework/integration/jdbc/config/pollingForMapJdbcInboundChannelAdapterTest.xml +++ b/org.springframework.integration.jdbc/src/test/resources/org/springframework/integration/jdbc/config/pollingForMapJdbcInboundChannelAdapterTest.xml @@ -11,7 +11,7 @@ http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd"> + data-source="dataSource" /> 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 eb02a672fe..490971acca 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 @@ -3,20 +3,16 @@ xmlns:beans="http://www.springframework.org/schema/beans" xmlns:si="http://www.springframework.org/schema/integration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://www.springframework.org/schema/beans + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd http://www.springframework.org/schema/integration/jdbc http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd"> - - - - + data-source="dataSource" update="update item set status =10 where id in (:idList)" /> + -