diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/driving/support/ColumnMapStreamContextRowMapper.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/driving/support/ColumnMapStreamContextRowMapper.java index df406f114..380bbe9a7 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/driving/support/ColumnMapStreamContextRowMapper.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/driving/support/ColumnMapStreamContextRowMapper.java @@ -23,93 +23,95 @@ import org.springframework.util.Assert; import org.springframework.util.ClassUtils; /** - *

Extension of the ColumnMapRowMapper that converts a column map to {@link StreamContext} and allows - * {@link StreamContext} to be converted back as a PreparedStatementSetter. This is useful in a restart - * scenario, as it allows for the standard functionality of the ColumnMapRowMapper to be used to - * create a map representing the columns returned by a query. It should be noted that this column ordering - * is preserved in the map using a link list version of Map. + *

+ * Extension of the ColumnMapRowMapper that converts a column map to + * {@link StreamContext} and allows {@link StreamContext} to be converted back + * as a PreparedStatementSetter. This is useful in a restart scenario, as it + * allows for the standard functionality of the {@link ColumnMapRowMapper} to be + * used to create a map representing the columns returned by a query. It should + * be noted that this column ordering is preserved in the map using a link list + * version of Map. * * * @author Lucas Ward * @author Dave Syer * @see StreamContextRowMapper */ -public class ColumnMapStreamContextRowMapper extends ColumnMapRowMapper implements StreamContextRowMapper{ - - public static final String KEY_PREFIX = ClassUtils.getQualifiedName(ColumnMapStreamContextRowMapper.class) + ".KEY."; - +public class ColumnMapStreamContextRowMapper extends ColumnMapRowMapper implements StreamContextRowMapper { + + public static final String KEY_PREFIX = ClassUtils.getQualifiedName(ColumnMapStreamContextRowMapper.class) + + ".KEY."; + public PreparedStatementSetter createSetter(StreamContext streamContext) { - + ColumnMapStreamContext columnData = new ColumnMapStreamContext(streamContext.getProperties()); - + List columns = new ArrayList(); for (Iterator iterator = columnData.keys.entrySet().iterator(); iterator.hasNext();) { - Entry entry = (Entry)iterator.next(); + Entry entry = (Entry) iterator.next(); Object column = entry.getValue(); columns.add(column); } - + return new ArgPreparedStatementSetter(columns.toArray()); } public StreamContext createStreamContext(Object key) { Assert.isInstanceOf(Map.class, key, "Input to create StreamContext must be of type Map."); - Map keys = (Map)key; + Map keys = (Map) key; return new ColumnMapStreamContext(keys); } - - + private static class ColumnMapStreamContext extends StreamContext { - + private final Map keys; public ColumnMapStreamContext(Map keys) { this.keys = keys; } - + public ColumnMapStreamContext(Properties props) { - + keys = CollectionFactory.createLinkedCaseInsensitiveMapIfPossible(props.size()); - - for(int counter = 0; counter < props.size(); counter++){ + + for (int counter = 0; counter < props.size(); counter++) { String key = KEY_PREFIX + counter; String column = props.getProperty(key); - - if(column != null){ + + if (column != null) { keys.put(key, column); } - else{ + else { break; } - + } } - + public Properties getProperties() { Properties props = new Properties(); - + int counter = 0; for (Iterator iterator = keys.entrySet().iterator(); iterator.hasNext();) { Entry entry = (Entry) iterator.next(); props.setProperty(KEY_PREFIX + counter, entry.getValue().toString()); counter++; } - + return props; } - + } - + /* * Exact duplicate of Spring class of the same name, copied because it is * package private. */ - private static class ArgPreparedStatementSetter implements PreparedStatementSetter{ + private static class ArgPreparedStatementSetter implements PreparedStatementSetter { private final Object[] args; - /** * Create a new ArgPreparedStatementSetter for the given arguments. * @param args the arguments to set @@ -118,7 +120,6 @@ public class ColumnMapStreamContextRowMapper extends ColumnMapRowMapper implemen this.args = args; } - public void setValues(PreparedStatement ps) throws SQLException { if (this.args != null) { for (int i = 0; i < this.args.length; i++) { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/driving/support/MultipleColumnJdbcKeyGenerator.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/driving/support/MultipleColumnJdbcKeyGenerator.java index fa9bcad53..ab825e55e 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/driving/support/MultipleColumnJdbcKeyGenerator.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/driving/support/MultipleColumnJdbcKeyGenerator.java @@ -138,17 +138,7 @@ public class MultipleColumnJdbcKeyGenerator implements public void setSql(String sql) { this.sql = sql; } - - /** - * Set the sql statement to be used to restore the keys list - * after a restart. - * - * @param restartSql - */ - public void setRestartSql(String restartSql) { - this.restartSql = restartSql; - } - + public void setJdbcTemplate(JdbcTemplate jdbcTemplate) { this.jdbcTemplate = jdbcTemplate; } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/driving/support/MultipleColumnJdbcKeyGeneratorIntegrationTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/driving/support/MultipleColumnJdbcKeyGeneratorIntegrationTests.java index f2ba9cf5d..79b7e35f6 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/driving/support/MultipleColumnJdbcKeyGeneratorIntegrationTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/driving/support/MultipleColumnJdbcKeyGeneratorIntegrationTests.java @@ -29,7 +29,7 @@ public class MultipleColumnJdbcKeyGeneratorIntegrationTests extends AbstractTran keyStrategy = new MultipleColumnJdbcKeyGenerator(getJdbcTemplate(), "SELECT ID, VALUE from T_FOOS order by ID"); - keyStrategy.setRestartSql("SELECT ID, VALUE from T_FOOS where ID > ? and VALUE > ? order by ID"); + keyStrategy.setRestartQuery("SELECT ID, VALUE from T_FOOS where ID > ? and VALUE > ? order by ID"); } public void testRetrieveKeys(){