From 12345beaf74fc034f9d422dcf05a4ad29f21962d Mon Sep 17 00:00:00 2001 From: lucasward Date: Tue, 5 Feb 2008 02:33:21 +0000 Subject: [PATCH] BATCH-219 and BATCH-330: Created ExecutionAttributes, which are stored in the table BATCH_STEP_EXECUTION_ATTRIBUTES. --- .../io/cursor/HibernateCursorItemReader.java | 18 ++++++----- .../batch/io/cursor/JdbcCursorItemReader.java | 15 +++++---- .../io/driving/DrivingQueryItemReader.java | 12 +++---- .../batch/io/driving/KeyGenerator.java | 6 ++-- .../ColumnMapStreamContextRowMapper.java | 32 ++++++++----------- .../driving/support/IbatisKeyGenerator.java | 13 ++++---- .../MultipleColumnJdbcKeyGenerator.java | 6 ++-- .../support/SingleColumnJdbcKeyGenerator.java | 14 ++++---- .../support/StreamContextRowMapper.java | 6 ++-- .../io/file/DefaultFlatFileItemReader.java | 14 ++++---- .../batch/io/file/FlatFileItemWriter.java | 14 ++++---- .../AbstractTransactionalIoSource.java | 6 ++-- .../batch/io/xml/StaxEventItemReader.java | 14 ++++---- .../batch/io/xml/StaxEventItemWriter.java | 14 ++++---- ...mContext.java => ExecutionAttributes.java} | 23 ++++++++----- .../batch/item/ItemStream.java | 14 ++++---- .../batch/item/StreamContextProvider.java | 6 ++-- .../item/reader/DelegatingItemReader.java | 12 +++---- .../batch/item/stream/ItemStreamAdapter.java | 16 +++++----- .../item/stream/SimpleStreamManager.java | 17 +++++----- .../batch/item/stream/StreamManager.java | 10 +++--- .../item/writer/DelegatingItemWriter.java | 10 +++--- .../driving/DrivingQueryItemReaderTests.java | 17 +++++----- .../batch/io/driving/FooInputSource.java | 10 +++--- .../ColumnMapRestartDataRowMapperTests.java | 11 ++++--- ...olumnJdbcKeyGeneratorIntegrationTests.java | 12 +++---- ...olumnJdbcKeyGeneratorIntegrationTests.java | 7 ++-- .../file/DefaultFlatFileItemReaderTests.java | 6 ++-- .../io/file/FlatFileItemWriterTests.java | 8 ++--- ...bstractJdbcItemReaderIntegrationTests.java | 9 +++--- ...tDataSourceItemReaderIntegrationTests.java | 11 ++++--- .../AbstractTransactionalIoSourceTests.java | 6 ++-- .../io/xml/StaxEventItemReaderTests.java | 8 ++--- .../xml/StaxEventWriterItemWriterTests.java | 4 +-- ...sts.java => ExecutionAttributesTests.java} | 29 +++++++++++------ .../reader/DelegatingItemReaderTests.java | 14 ++++---- .../item/stream/SimpleStreamManagerTests.java | 25 ++++++++------- .../writer/ItemWriterItemProcessorTests.java | 12 +++---- 38 files changed, 254 insertions(+), 227 deletions(-) rename spring-batch-infrastructure/src/main/java/org/springframework/batch/item/{StreamContext.java => ExecutionAttributes.java} (87%) rename spring-batch-infrastructure/src/test/java/org/springframework/batch/item/{StreamContextTests.java => ExecutionAttributesTests.java} (75%) diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/cursor/HibernateCursorItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/cursor/HibernateCursorItemReader.java index 0d4a73a61..60fde6a3a 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/cursor/HibernateCursorItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/cursor/HibernateCursorItemReader.java @@ -25,8 +25,7 @@ import org.hibernate.SessionFactory; import org.hibernate.StatelessSession; import org.springframework.batch.io.Skippable; import org.springframework.batch.item.ItemReader; -import org.springframework.batch.item.ItemStream; -import org.springframework.batch.item.StreamContext; +import org.springframework.batch.item.ExecutionAttributes; import org.springframework.batch.item.reader.AbstractItemStreamItemReader; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; @@ -175,18 +174,21 @@ public class HibernateCursorItemReader extends AbstractItemStreamItemReader impl /** * @return the current row number wrapped as StreamContext */ - public StreamContext getStreamContext() { + public ExecutionAttributes getStreamContext() { Properties props = new Properties(); props.setProperty(RESTART_DATA_ROW_NUMBER_KEY, "" + currentProcessedRow); + + ExecutionAttributes executionAttributes = new ExecutionAttributes(); + executionAttributes.putString(RESTART_DATA_ROW_NUMBER_KEY, "" + currentProcessedRow); String skipped = skippedRows.toString(); - props.setProperty(SKIPPED_ROWS, skipped.substring(1, skipped.length() - 1)); - return new StreamContext(props); + executionAttributes.putString(SKIPPED_ROWS, skipped.substring(1, skipped.length() - 1)); + return executionAttributes; } /** * Sets the cursor to the received row number. */ - public void restoreFrom(StreamContext data) { + public void restoreFrom(ExecutionAttributes data) { Assert.state(!initialized, "Cannot restore when already intialized. Call close() first before restore()"); Properties props = data.getProperties(); @@ -234,7 +236,7 @@ public class HibernateCursorItemReader extends AbstractItemStreamItemReader impl * (non-Javadoc) * @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.StreamContext) */ - public void mark(StreamContext streamContext) { + public void mark(ExecutionAttributes streamContext) { lastCommitRowNumber = currentProcessedRow; if (!useStatelessSession) { statefulSession.clear(); @@ -245,7 +247,7 @@ public class HibernateCursorItemReader extends AbstractItemStreamItemReader impl * (non-Javadoc) * @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.StreamContext) */ - public void reset(StreamContext streamContext) { + public void reset(ExecutionAttributes streamContext) { currentProcessedRow = lastCommitRowNumber; if (lastCommitRowNumber == 0) { cursor.beforeFirst(); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/cursor/JdbcCursorItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/cursor/JdbcCursorItemReader.java index cc46376df..b7fe7b3dd 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/cursor/JdbcCursorItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/cursor/JdbcCursorItemReader.java @@ -32,7 +32,8 @@ import org.springframework.batch.io.Skippable; import org.springframework.batch.io.support.AbstractTransactionalIoSource; import org.springframework.batch.item.ItemStream; import org.springframework.batch.item.KeyedItemReader; -import org.springframework.batch.item.StreamContext; +import org.springframework.batch.item.ExecutionAttributes; +import org.springframework.batch.item.stream.GenericStreamContext; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.dao.DataAccessException; @@ -71,7 +72,7 @@ import org.springframework.util.StringUtils; *

* *

- * {@link StreamContext}: The current row is returned as restart data, and when + * {@link ExecutionAttributes}: The current row is returned as restart data, and when * restored from that same data, the cursor is opened and the current row set to * the value within the restart data. There are also two statistics returned by * this input source: the current line being processed and the number of lines @@ -232,7 +233,7 @@ public class JdbcCursorItemReader extends AbstractTransactionalIoSource implemen * Mark the current row. Calling reset will cause the result set to be set * to the current row when mark was called. */ - public void mark(StreamContext streamContext) { + public void mark(ExecutionAttributes streamContext) { lastCommittedRow = currentProcessedRow; skippedRows.clear(); } @@ -242,7 +243,7 @@ public class JdbcCursorItemReader extends AbstractTransactionalIoSource implemen * * @throws DataAccessException */ - public void reset(StreamContext streamContext) { + public void reset(ExecutionAttributes streamContext) { try { currentProcessedRow = lastCommittedRow; if (currentProcessedRow > 0) { @@ -390,9 +391,9 @@ public class JdbcCursorItemReader extends AbstractTransactionalIoSource implemen * * @see org.springframework.batch.restart.Restartable#getStreamContext() */ - public StreamContext getStreamContext() { + public ExecutionAttributes getStreamContext() { String skipped = skippedRows.toString(); - StreamContext context = new StreamContext(); + ExecutionAttributes context = new GenericStreamContext(); context.putString(SKIPPED_ROWS, skipped.substring(1, skipped.length() - 1)); context.putLong(CURRENT_PROCESSED_ROW, currentProcessedRow); context.putLong(SKIP_COUNT, skipCount); @@ -403,7 +404,7 @@ public class JdbcCursorItemReader extends AbstractTransactionalIoSource implemen * (non-Javadoc) * @see org.springframework.batch.item.ItemStream#restoreFrom(org.springframework.batch.item.StreamContext) */ - public void restoreFrom(StreamContext data) { + public void restoreFrom(ExecutionAttributes data) { Assert.state(!initialized); if (data == null) diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/driving/DrivingQueryItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/driving/DrivingQueryItemReader.java index 6e1d0f2ec..5d5c58f7d 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/driving/DrivingQueryItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/driving/DrivingQueryItemReader.java @@ -21,7 +21,7 @@ import java.util.List; import org.springframework.batch.io.support.AbstractTransactionalIoSource; import org.springframework.batch.item.ItemStream; import org.springframework.batch.item.KeyedItemReader; -import org.springframework.batch.item.StreamContext; +import org.springframework.batch.item.ExecutionAttributes; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.util.Assert; @@ -159,7 +159,7 @@ public class DrivingQueryItemReader extends AbstractTransactionalIoSource * been initialized before calling restore (meaning, read has been called) * then an IllegalStateException will be thrown, since all input sources * should be restored before being read from, otherwise already processed - * data could be returned. The {@link StreamContext} attempting to be restored from + * data could be returned. The {@link ExecutionAttributes} attempting to be restored from * must have been obtained from the same input source as the one * being restored from otherwise it is invalid. * @@ -168,7 +168,7 @@ public class DrivingQueryItemReader extends AbstractTransactionalIoSource * @throws IllegalStateException * if the input source has already been initialized. */ - public final void restoreFrom(StreamContext data) { + public final void restoreFrom(ExecutionAttributes data) { Assert.notNull(data, "StreamContext must not be null."); Assert.notNull(data.getProperties(), @@ -189,7 +189,7 @@ public class DrivingQueryItemReader extends AbstractTransactionalIoSource } } - public StreamContext getStreamContext() { + public ExecutionAttributes getStreamContext() { return keyGenerator.getKeyAsStreamContext(getCurrentKey()); } @@ -237,14 +237,14 @@ public class DrivingQueryItemReader extends AbstractTransactionalIoSource /* (non-Javadoc) * @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.StreamContext) */ - public void mark(StreamContext streamContext) { + public void mark(ExecutionAttributes streamContext) { lastCommitIndex = currentIndex; } /* (non-Javadoc) * @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.StreamContext) */ - public void reset(StreamContext streamContext) { + public void reset(ExecutionAttributes streamContext) { keysIterator = keys.listIterator(lastCommitIndex); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/driving/KeyGenerator.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/driving/KeyGenerator.java index 3626ba6c8..17effd4f8 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/driving/KeyGenerator.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/driving/KeyGenerator.java @@ -2,7 +2,7 @@ package org.springframework.batch.io.driving; import java.util.List; -import org.springframework.batch.item.StreamContext; +import org.springframework.batch.item.ExecutionAttributes; /** * Strategy interface used to generate keys in driving query input. @@ -24,7 +24,7 @@ public interface KeyGenerator { * @return a list of keys. * @throws IllegalArgumentException is streamContext is null. */ - List restoreKeys(StreamContext streamContext); + List restoreKeys(ExecutionAttributes streamContext); /** * Return the provided key as restart data. @@ -34,5 +34,5 @@ public interface KeyGenerator { * @throws IllegalArgumentException if key is null. * @throws IllegalArgumentException if key is an incompatible type. */ - StreamContext getKeyAsStreamContext(Object key); + ExecutionAttributes getKeyAsStreamContext(Object key); } 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 380bbe9a7..d7b2d414e 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 @@ -12,7 +12,7 @@ import java.util.Map; import java.util.Properties; import java.util.Map.Entry; -import org.springframework.batch.item.StreamContext; +import org.springframework.batch.item.ExecutionAttributes; import org.springframework.core.CollectionFactory; import org.springframework.jdbc.core.ColumnMapRowMapper; import org.springframework.jdbc.core.PreparedStatementSetter; @@ -23,27 +23,23 @@ 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 {@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. + *

Extension of the ColumnMapRowMapper that converts a column map to {@link ExecutionAttributes} and allows + * {@link ExecutionAttributes} 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. * * * @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 PreparedStatementSetter createSetter(StreamContext streamContext) { - +public class ColumnMapStreamContextRowMapper extends ColumnMapRowMapper implements StreamContextRowMapper{ + + public static final String KEY_PREFIX = ClassUtils.getQualifiedName(ColumnMapStreamContextRowMapper.class) + ".KEY."; + + public PreparedStatementSetter createSetter(ExecutionAttributes streamContext) { + ColumnMapStreamContext columnData = new ColumnMapStreamContext(streamContext.getProperties()); List columns = new ArrayList(); @@ -56,13 +52,13 @@ public class ColumnMapStreamContextRowMapper extends ColumnMapRowMapper implemen return new ArgPreparedStatementSetter(columns.toArray()); } - public StreamContext createStreamContext(Object key) { + public ExecutionAttributes createStreamContext(Object key) { Assert.isInstanceOf(Map.class, key, "Input to create StreamContext must be of type Map."); Map keys = (Map) key; return new ColumnMapStreamContext(keys); } - private static class ColumnMapStreamContext extends StreamContext { + private static class ColumnMapStreamContext extends ExecutionAttributes { private final Map keys; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/driving/support/IbatisKeyGenerator.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/driving/support/IbatisKeyGenerator.java index d27363c70..84574b2dd 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/driving/support/IbatisKeyGenerator.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/driving/support/IbatisKeyGenerator.java @@ -5,7 +5,7 @@ import java.util.Properties; import org.springframework.batch.io.driving.DrivingQueryItemReader; import org.springframework.batch.io.driving.KeyGenerator; -import org.springframework.batch.item.StreamContext; +import org.springframework.batch.item.ExecutionAttributes; import org.springframework.orm.ibatis.SqlMapClientTemplate; import org.springframework.util.Assert; @@ -43,19 +43,20 @@ public class IbatisKeyGenerator implements KeyGenerator { * * @see org.springframework.batch.restart.Restartable#getRestartData() */ - public StreamContext getKeyAsStreamContext(Object key) { + public ExecutionAttributes getKeyAsStreamContext(Object key) { Properties props = new Properties(); props.setProperty(RESTART_KEY, key.toString()); - - return new StreamContext(props); + ExecutionAttributes executionAttributes = new ExecutionAttributes(); + executionAttributes.putString(RESTART_KEY, key.toString()); + return executionAttributes; } /** * Restore the keys list given the provided restart data. * - * @see org.springframework.batch.io.driving.DrivingQueryItemReader#restoreKeys(org.springframework.batch.item.StreamContext) + * @see org.springframework.batch.io.driving.DrivingQueryItemReader#restoreKeys(org.springframework.batch.item.ExecutionAttributes) */ - public List restoreKeys(StreamContext data) { + public List restoreKeys(ExecutionAttributes data) { Properties props = data.getProperties(); Object key = props.getProperty(RESTART_KEY); 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 497dda390..5359ef8d4 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 @@ -20,7 +20,7 @@ import java.util.List; import org.springframework.batch.io.driving.DrivingQueryItemReader; import org.springframework.batch.io.driving.KeyGenerator; -import org.springframework.batch.item.StreamContext; +import org.springframework.batch.item.ExecutionAttributes; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -80,7 +80,7 @@ public class MultipleColumnJdbcKeyGenerator implements /* (non-Javadoc) * @see org.springframework.batch.io.driving.KeyGenerator#restoreKeys(org.springframework.batch.item.StreamContext) */ - public List restoreKeys(StreamContext streamContext) { + public List restoreKeys(ExecutionAttributes streamContext) { Assert.state(keyMapper != null, "KeyMapper must not be null."); Assert.state(StringUtils.hasText(restartSql), "The RestartQuery must not be null or empty" + @@ -96,7 +96,7 @@ public class MultipleColumnJdbcKeyGenerator implements /* (non-Javadoc) * @see org.springframework.batch.io.driving.KeyGenerator#getKeyAsStreamContext(java.lang.Object) */ - public StreamContext getKeyAsStreamContext(Object key) { + public ExecutionAttributes getKeyAsStreamContext(Object key) { Assert.state(keyMapper != null, "Kye mapper must not be null."); return keyMapper.createStreamContext(key); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/driving/support/SingleColumnJdbcKeyGenerator.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/driving/support/SingleColumnJdbcKeyGenerator.java index 82a087b5e..f0fdef3e4 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/driving/support/SingleColumnJdbcKeyGenerator.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/driving/support/SingleColumnJdbcKeyGenerator.java @@ -20,7 +20,7 @@ import java.util.List; import org.apache.commons.lang.ClassUtils; import org.springframework.batch.io.driving.KeyGenerator; -import org.springframework.batch.item.StreamContext; +import org.springframework.batch.item.ExecutionAttributes; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.SingleColumnRowMapper; @@ -98,27 +98,27 @@ public class SingleColumnJdbcKeyGenerator implements KeyGenerator { * @see KeyGenerator#getKeyAsStreamContext(Object) * @throws IllegalArgumentException if key is null. */ - public StreamContext getKeyAsStreamContext(Object key) { + public ExecutionAttributes getKeyAsStreamContext(Object key) { Assert.notNull(key, "The key must not be null."); - StreamContext context = new StreamContext(); + ExecutionAttributes context = new ExecutionAttributes(); context.putString(RESTART_KEY, key.toString()); return context; } /** * Return the remaining to be processed for the provided - * {@link StreamContext}. The {@link StreamContext} attempting to be + * {@link ExecutionAttributes}. The {@link ExecutionAttributes} attempting to be * restored from must have been obtained from the same * KeyGenerationStrategy as the one being restored from otherwise * it is invalid. * - * @param StreamContext obtained by calling + * @param ExecutionAttributes obtained by calling * {@link #getKeyAsStreamContext(Object)} during a previous run. * @throws IllegalStateException if restart sql statement is null. * @throws IllegalArgumentException if restart data is null. - * @see KeyGenerator#restoreKeys(org.springframework.batch.item.StreamContext) + * @see KeyGenerator#restoreKeys(org.springframework.batch.item.ExecutionAttributes) */ - public List restoreKeys(StreamContext streamContext) { + public List restoreKeys(ExecutionAttributes streamContext) { Assert.notNull(streamContext, "The restart data must not be null."); Assert.state(StringUtils.hasText(restartSql), "The RestartQuery must not be null or empty" diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/driving/support/StreamContextRowMapper.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/driving/support/StreamContextRowMapper.java index 0f162a306..6afbed491 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/driving/support/StreamContextRowMapper.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/driving/support/StreamContextRowMapper.java @@ -15,7 +15,7 @@ */ package org.springframework.batch.io.driving.support; -import org.springframework.batch.item.StreamContext; +import org.springframework.batch.item.ExecutionAttributes; import org.springframework.jdbc.core.PreparedStatementSetter; import org.springframework.jdbc.core.RowMapper; @@ -40,7 +40,7 @@ public interface StreamContextRowMapper extends RowMapper { * @return ResartData representing the composite key. * @throws IllegalArgumentException if key is null or of an unsupported type. */ - public StreamContext createStreamContext(Object key); + public ExecutionAttributes createStreamContext(Object key); /** * Given the provided restart data, return a PreparedStatementSeter that can @@ -49,5 +49,5 @@ public interface StreamContextRowMapper extends RowMapper { * @param streamContext * @return an array of objects that can be used as arguments to a JdbcTemplate. */ - public PreparedStatementSetter createSetter(StreamContext streamContext); + public PreparedStatementSetter createSetter(ExecutionAttributes streamContext); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/file/DefaultFlatFileItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/file/DefaultFlatFileItemReader.java index ad38a71fe..a6e1eb6f0 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/file/DefaultFlatFileItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/file/DefaultFlatFileItemReader.java @@ -24,7 +24,7 @@ import org.apache.commons.logging.LogFactory; import org.springframework.batch.io.Skippable; import org.springframework.batch.io.file.separator.LineReader; import org.springframework.batch.item.ItemStream; -import org.springframework.batch.item.StreamContext; +import org.springframework.batch.item.ExecutionAttributes; import org.springframework.batch.item.StreamException; /** @@ -61,9 +61,9 @@ public class DefaultFlatFileItemReader extends SimpleFlatFileItemReader implemen * file and position the buffer reader according to information provided by * the restart data * - * @param data {@link StreamContext} information + * @param data {@link ExecutionAttributes} information */ - public void restoreFrom(StreamContext data) { + public void restoreFrom(ExecutionAttributes data) { if (data == null || data.getProperties() == null || data.getProperties().getProperty(READ_STATISTICS_NAME) == null || getReader() == null) { @@ -90,11 +90,11 @@ public class DefaultFlatFileItemReader extends SimpleFlatFileItemReader implemen * current Line Count which can be used to re initialise the batch job in * case of restart. */ - public StreamContext getStreamContext() { + public ExecutionAttributes getStreamContext() { if (reader == null) { throw new StreamException("ItemStream not open or already closed."); } - StreamContext streamContext = new StreamContext(); + ExecutionAttributes streamContext = new ExecutionAttributes(); streamContext.putLong(READ_STATISTICS_NAME, reader.getCurrentLineCount()); streamContext.putLong(SKIPPED_STATISTICS_NAME, skippedLines.size()); return streamContext; @@ -116,7 +116,7 @@ public class DefaultFlatFileItemReader extends SimpleFlatFileItemReader implemen * (non-Javadoc) * @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.StreamContext) */ - public void mark(StreamContext streamContext) { + public void mark(ExecutionAttributes streamContext) { getReader().mark(); } @@ -124,7 +124,7 @@ public class DefaultFlatFileItemReader extends SimpleFlatFileItemReader implemen * (non-Javadoc) * @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.StreamContext) */ - public void reset(StreamContext streamContext) { + public void reset(ExecutionAttributes streamContext) { getReader().reset(); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/file/FlatFileItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/file/FlatFileItemWriter.java index 2ec00b8a5..d92fc2471 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/file/FlatFileItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/file/FlatFileItemWriter.java @@ -33,7 +33,7 @@ import org.springframework.batch.io.exception.BatchEnvironmentException; import org.springframework.batch.io.support.AbstractTransactionalIoSource; import org.springframework.batch.item.ItemStream; import org.springframework.batch.item.ItemWriter; -import org.springframework.batch.item.StreamContext; +import org.springframework.batch.item.ExecutionAttributes; import org.springframework.batch.item.StreamException; import org.springframework.batch.item.writer.ItemTransformer; import org.springframework.beans.factory.DisposableBean; @@ -71,7 +71,7 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements private Resource resource; - private StreamContext streamContext = new StreamContext(); + private ExecutionAttributes streamContext = new ExecutionAttributes(); private OutputState state = null; @@ -246,7 +246,7 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements /** * @see ItemStream#getStreamContext() */ - public StreamContext getStreamContext() { + public ExecutionAttributes getStreamContext() { if (state == null) { throw new StreamException("ItemStream not open or already closed."); } @@ -257,9 +257,9 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements } /** - * @see ItemStream#restoreFrom(StreamContext) + * @see ItemStream#restoreFrom(ExecutionAttributes) */ - public void restoreFrom(StreamContext data) { + public void restoreFrom(ExecutionAttributes data) { if (data == null) return; @@ -552,14 +552,14 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements /* (non-Javadoc) * @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.StreamContext) */ - public void mark(StreamContext streamContext) { + public void mark(ExecutionAttributes streamContext) { getOutputState().mark(); } /* (non-Javadoc) * @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.StreamContext) */ - public void reset(StreamContext streamContext) { + public void reset(ExecutionAttributes streamContext) { getOutputState().checkFileSize(); resetPositionForRestart(); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/support/AbstractTransactionalIoSource.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/support/AbstractTransactionalIoSource.java index 4741b7902..55d3d55e5 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/support/AbstractTransactionalIoSource.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/support/AbstractTransactionalIoSource.java @@ -17,7 +17,7 @@ package org.springframework.batch.io.support; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemWriter; -import org.springframework.batch.item.StreamContext; +import org.springframework.batch.item.ExecutionAttributes; import org.springframework.batch.item.stream.ItemStreamAdapter; /** @@ -39,14 +39,14 @@ public abstract class AbstractTransactionalIoSource extends ItemStreamAdapter { * * @see TransactionSynchronization#afterCompletion */ - public abstract void mark(StreamContext streamContext); + public abstract void mark(ExecutionAttributes streamContext); /* * Called when a transaction has been rolled back. * * @see TransactionSynchronization#afterCompletion */ - public abstract void reset(StreamContext streamContext); + public abstract void reset(ExecutionAttributes streamContext); /* (non-Javadoc) * @see org.springframework.batch.item.stream.ItemStreamAdapter#isMarkSupported() diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/xml/StaxEventItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/xml/StaxEventItemReader.java index 464cb99bb..f8055bc4b 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/xml/StaxEventItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/xml/StaxEventItemReader.java @@ -18,7 +18,7 @@ import org.springframework.batch.io.xml.stax.FragmentEventReader; import org.springframework.batch.io.xml.stax.TransactionalEventReader; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemStream; -import org.springframework.batch.item.StreamContext; +import org.springframework.batch.item.ExecutionAttributes; import org.springframework.batch.item.reader.AbstractItemReader; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; @@ -176,8 +176,8 @@ public class StaxEventItemReader extends AbstractItemReader implements ItemReade * @return wrapped count of records read so far. * @see ItemStream#getStreamContext() */ - public StreamContext getStreamContext() { - StreamContext restartData = new StreamContext(); + public ExecutionAttributes getStreamContext() { + ExecutionAttributes restartData = new ExecutionAttributes(); restartData.putLong(READ_COUNT_STATISTICS_NAME, currentRecordCount); return restartData; } @@ -186,12 +186,12 @@ public class StaxEventItemReader extends AbstractItemReader implements ItemReade * Restores the input source for the given restart data by rereading and * skipping the number of records stored in the RestartData. * - * @param StreamContext that holds the line count from the last commit. + * @param ExecutionAttributes that holds the line count from the last commit. * @throws IllegalStateException if the ItemReader has already been * initialized or if the number of records to read and skip exceeds the * available records. */ - public void restoreFrom(StreamContext data) { + public void restoreFrom(ExecutionAttributes data) { Assert.state(!initialized); if (data == null || data.getProperties() == null || !data.containsKey(READ_COUNT_STATISTICS_NAME)) { return; @@ -266,7 +266,7 @@ public class StaxEventItemReader extends AbstractItemReader implements ItemReade /* (non-Javadoc) * @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.StreamContext) */ - public void mark(StreamContext streamContext) { + public void mark(ExecutionAttributes streamContext) { lastCommitPointRecordCount = currentRecordCount; txReader.onCommit(); skipRecords = new ArrayList(); @@ -275,7 +275,7 @@ public class StaxEventItemReader extends AbstractItemReader implements ItemReade /* (non-Javadoc) * @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.StreamContext) */ - public void reset(StreamContext streamContext) { + public void reset(ExecutionAttributes streamContext) { currentRecordCount = lastCommitPointRecordCount; txReader.onRollback(); fragmentReader.reset(); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/xml/StaxEventItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/xml/StaxEventItemWriter.java index 06dd79047..3f50adb76 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/xml/StaxEventItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/io/xml/StaxEventItemWriter.java @@ -17,7 +17,7 @@ import org.springframework.batch.io.support.FileUtils; import org.springframework.batch.io.xml.stax.NoStartEndDocumentStreamWriter; import org.springframework.batch.item.ItemStream; import org.springframework.batch.item.ItemWriter; -import org.springframework.batch.item.StreamContext; +import org.springframework.batch.item.ExecutionAttributes; import org.springframework.batch.item.StreamException; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; @@ -363,11 +363,11 @@ public class StaxEventItemWriter implements ItemWriter, ItemStream, Initializing * @return the restart data * @see org.springframework.batch.item.ItemStream#getStreamContext() */ - public StreamContext getStreamContext() { + public ExecutionAttributes getStreamContext() { if (!initialized) { throw new StreamException("ItemStream is not open, or may have been closed. Cannot access context."); } - StreamContext context = new StreamContext(); + ExecutionAttributes context = new ExecutionAttributes(); context.putLong(RESTART_DATA_NAME, getPosition()); context.putLong(WRITE_STATISTICS_NAME, currentRecordCount); return context; @@ -376,9 +376,9 @@ public class StaxEventItemWriter implements ItemWriter, ItemStream, Initializing /** * Restore processing from provided restart data. * @param data the restart data - * @see org.springframework.batch.item.ItemStream#restoreFrom(org.springframework.batch.item.StreamContext) + * @see org.springframework.batch.item.ItemStream#restoreFrom(org.springframework.batch.item.ExecutionAttributes) */ - public void restoreFrom(StreamContext data) { + public void restoreFrom(ExecutionAttributes data) { long startAtPosition = 0; @@ -450,7 +450,7 @@ public class StaxEventItemWriter implements ItemWriter, ItemStream, Initializing /* (non-Javadoc) * @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.StreamContext) */ - public void mark(StreamContext streamContext) { + public void mark(ExecutionAttributes streamContext) { lastCommitPointPosition = getPosition(); lastCommitPointRecordCount = currentRecordCount; } @@ -458,7 +458,7 @@ public class StaxEventItemWriter implements ItemWriter, ItemStream, Initializing /* (non-Javadoc) * @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.StreamContext) */ - public void reset(StreamContext streamContext) { + public void reset(ExecutionAttributes streamContext) { currentRecordCount = lastCommitPointRecordCount; // close output close(); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/StreamContext.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ExecutionAttributes.java similarity index 87% rename from spring-batch-infrastructure/src/main/java/org/springframework/batch/item/StreamContext.java rename to spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ExecutionAttributes.java index 96acedd61..80be0ebc5 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/StreamContext.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ExecutionAttributes.java @@ -16,6 +16,7 @@ package org.springframework.batch.item; +import java.io.Serializable; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -31,17 +32,17 @@ import org.springframework.util.Assert; * also allows for dirty checking by setting a 'dirty' flag whenever any put is * called. */ -public class StreamContext { +public class ExecutionAttributes { private boolean dirty = false; private final Map map; - public StreamContext() { + public ExecutionAttributes() { map = new HashMap(); } - - public StreamContext(Map map) { + + public ExecutionAttributes(Map map){ this.map = map; } @@ -60,8 +61,9 @@ public class StreamContext { put(key, new Double(value)); } - - public void put(String key, Object value) { + + public void put(String key, Object value){ + Assert.isInstanceOf(Serializable.class, value, "Value: [ " + value + "must be serializable."); dirty = true; map.put(key, value); } @@ -133,17 +135,22 @@ public class StreamContext { } public boolean equals(Object obj) { - if(obj instanceof StreamContext == false){ + if(obj instanceof ExecutionAttributes == false){ return false; } if(this == obj){ return true; } - StreamContext rhs = (StreamContext)obj; + ExecutionAttributes rhs = (ExecutionAttributes)obj; return this.entrySet().equals(rhs.entrySet()); } public int hashCode() { return map.hashCode(); } + + public String toString() { + return map.toString(); + } + } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ItemStream.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ItemStream.java index f9d996079..9b9532360 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ItemStream.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ItemStream.java @@ -23,11 +23,11 @@ package org.springframework.batch.item; *

* *

- * The state that is stored is represented as {@link StreamContext} which + * The state that is stored is represented as {@link ExecutionAttributes} which * enforces a requirement that any restart data can be represented by a - * Properties object. In general, the contract is that {@link StreamContext} + * Properties object. In general, the contract is that {@link ExecutionAttributes} * that is returned via the {@link #getStreamContext()} method will be given - * back to the {@link #restoreFrom(StreamContext)} method, exactly as it was + * back to the {@link #restoreFrom(ExecutionAttributes)} method, exactly as it was * provided. *

* @@ -37,11 +37,11 @@ package org.springframework.batch.item; public interface ItemStream extends StreamContextProvider { /** - * Restart state given the provided {@link StreamContext}. + * Restart state given the provided {@link ExecutionAttributes}. * * @param context */ - void restoreFrom(StreamContext context); + void restoreFrom(ExecutionAttributes context); /** * If any resources are needed for the stream to operate they need to be @@ -75,7 +75,7 @@ public interface ItemStream extends StreamContextProvider { * * @throws UnsupportedOperationException if the operation is not supported */ - void mark(StreamContext streamContext); + void mark(ExecutionAttributes streamContext); /** * Reset the stream to the last mark. After a reset the stream state will be @@ -84,5 +84,5 @@ public interface ItemStream extends StreamContextProvider { * * @throws UnsupportedOperationException if the operation is not supported */ - void reset(StreamContext streamContext); + void reset(ExecutionAttributes streamContext); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/StreamContextProvider.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/StreamContextProvider.java index 271f830b6..ead50cf1d 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/StreamContextProvider.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/StreamContextProvider.java @@ -22,11 +22,11 @@ package org.springframework.batch.item; public interface StreamContextProvider { /** - * Get {@link StreamContext} representing this object's current state. + * Get {@link ExecutionAttributes} representing this object's current state. * Should not return null even if there is no state. * - * @return {@link StreamContext} representing current state. + * @return {@link ExecutionAttributes} representing current state. */ - StreamContext getStreamContext(); + ExecutionAttributes getStreamContext(); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/reader/DelegatingItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/reader/DelegatingItemReader.java index 1a2f55d58..33ab76604 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/reader/DelegatingItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/reader/DelegatingItemReader.java @@ -19,7 +19,7 @@ package org.springframework.batch.item.reader; import org.springframework.batch.io.Skippable; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemStream; -import org.springframework.batch.item.StreamContext; +import org.springframework.batch.item.ExecutionAttributes; import org.springframework.batch.item.StreamException; import org.springframework.beans.factory.InitializingBean; import org.springframework.util.Assert; @@ -52,18 +52,18 @@ public class DelegatingItemReader extends AbstractItemReader implements Skippabl * @throws IllegalStateException if the parent template is not itself * {@link ItemStream}. */ - public StreamContext getStreamContext() { + public ExecutionAttributes getStreamContext() { // TODO: this is not necessary... Assert.state(inputSource instanceof ItemStream, "Input source is not ItemStream"); return ((ItemStream) inputSource).getStreamContext(); } /** - * @see ItemStream#restoreFrom(StreamContext) + * @see ItemStream#restoreFrom(ExecutionAttributes) * @throws IllegalStateException if the parent template is not itself * {@link ItemStream}. */ - public void restoreFrom(StreamContext data) { + public void restoreFrom(ExecutionAttributes data) { Assert.state(inputSource instanceof ItemStream, "Input source is not ItemStream"); ((ItemStream) inputSource).restoreFrom(data); } @@ -119,7 +119,7 @@ public class DelegatingItemReader extends AbstractItemReader implements Skippabl /* (non-Javadoc) * @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.StreamContext) */ - public void mark(StreamContext streamContext) { + public void mark(ExecutionAttributes streamContext) { if (inputSource instanceof ItemStream) { ((ItemStream) inputSource).mark(streamContext); } @@ -128,7 +128,7 @@ public class DelegatingItemReader extends AbstractItemReader implements Skippabl /* (non-Javadoc) * @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.StreamContext) */ - public void reset(StreamContext streamContext) { + public void reset(ExecutionAttributes streamContext) { if (inputSource instanceof ItemStream) { ((ItemStream) inputSource).reset(streamContext); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/stream/ItemStreamAdapter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/stream/ItemStreamAdapter.java index f02b0ca98..7d4b15ea3 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/stream/ItemStreamAdapter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/stream/ItemStreamAdapter.java @@ -16,7 +16,7 @@ package org.springframework.batch.item.stream; import org.springframework.batch.item.ItemStream; -import org.springframework.batch.item.StreamContext; +import org.springframework.batch.item.ExecutionAttributes; import org.springframework.batch.item.StreamException; /** @@ -41,17 +41,17 @@ public class ItemStreamAdapter implements ItemStream { /** * No-op. - * @see org.springframework.batch.item.ItemStream#restoreFrom(org.springframework.batch.item.StreamContext) + * @see org.springframework.batch.item.ItemStream#restoreFrom(org.springframework.batch.item.ExecutionAttributes) */ - public void restoreFrom(StreamContext context) { + public void restoreFrom(ExecutionAttributes context) { } /** - * Return empty {@link StreamContext}. + * Return empty {@link ExecutionAttributes}. * @see org.springframework.batch.item.StreamContextProvider#getStreamContext() */ - public StreamContext getStreamContext() { - return new StreamContext(); + public ExecutionAttributes getStreamContext() { + return new ExecutionAttributes(); } /* (non-Javadoc) @@ -64,14 +64,14 @@ public class ItemStreamAdapter implements ItemStream { /* (non-Javadoc) * @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.StreamContext) */ - public void mark(StreamContext streamContext) { + public void mark(ExecutionAttributes streamContext) { throw new UnsupportedOperationException("Mark operation not supported."); } /* (non-Javadoc) * @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.StreamContext) */ - public void reset(StreamContext streamContext) { + public void reset(ExecutionAttributes streamContext) { throw new UnsupportedOperationException("Reset operation not supported."); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/stream/SimpleStreamManager.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/stream/SimpleStreamManager.java index 42c7e1cb7..add7b6a90 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/stream/SimpleStreamManager.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/stream/SimpleStreamManager.java @@ -24,6 +24,7 @@ import java.util.Set; import java.util.Map.Entry; import org.springframework.batch.item.ItemStream; +import org.springframework.batch.item.ExecutionAttributes; import org.springframework.batch.item.StreamContext; import org.springframework.batch.item.StreamException; import org.springframework.transaction.PlatformTransactionManager; @@ -90,11 +91,11 @@ public class SimpleStreamManager implements StreamManager { * * @see org.springframework.batch.item.stream.StreamManager#getStreamContext(java.lang.Object) */ - public StreamContext getStreamContext(Object key) { - final StreamContext result = new StreamContext(); + public ExecutionAttributes getStreamContext(Object key) { + final ExecutionAttributes result = new ExecutionAttributes(); iterate(key, new Callback() { public void execute(ItemStream stream) { - StreamContext context = stream.getStreamContext(); + ExecutionAttributes context = stream.getStreamContext(); String prefix = ClassUtils.getQualifiedName(stream.getClass()) + "."; if (!useClassNameAsPrefix) { prefix = ""; @@ -102,7 +103,7 @@ public class SimpleStreamManager implements StreamManager { for (Iterator iterator = context.entrySet().iterator(); iterator.hasNext();) { Entry entry = (Entry) iterator.next(); String contextKey = prefix + entry.getKey(); - result.put(contextKey, entry.getValue()); + result.putString(contextKey, entry.getValue().toString()); } } }); @@ -116,7 +117,7 @@ public class SimpleStreamManager implements StreamManager { * @see org.springframework.batch.item.stream.StreamManager#register(java.lang.Object, * org.springframework.batch.item.ItemStream, StreamContext) */ - public void register(Object key, ItemStream stream, StreamContext streamContext) { + public void register(Object key, ItemStream stream, ExecutionAttributes streamContext) { synchronized (registry) { Set set = (Set) registry.get(key); if (set == null) { @@ -135,8 +136,8 @@ public class SimpleStreamManager implements StreamManager { * @param streamContext * @return */ - private StreamContext extract(ItemStream stream, StreamContext context) { - StreamContext result = new StreamContext(); + private ExecutionAttributes extract(ItemStream stream, ExecutionAttributes context) { + ExecutionAttributes result = new ExecutionAttributes(); String prefix = ClassUtils.getQualifiedName(stream.getClass()) + "."; if (!useClassNameAsPrefix) { prefix = ""; @@ -145,7 +146,7 @@ public class SimpleStreamManager implements StreamManager { Entry entry = (Entry) iterator.next(); String contextKey = (String) entry.getKey(); if (contextKey.startsWith(prefix)) { - result.put(contextKey.substring(prefix.length()), entry.getValue()); + result.putString(contextKey.substring(prefix.length()), entry.getValue().toString()); } } return result; diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/stream/StreamManager.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/stream/StreamManager.java index a8ae6b836..ba8fc81de 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/stream/StreamManager.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/stream/StreamManager.java @@ -16,7 +16,7 @@ package org.springframework.batch.item.stream; import org.springframework.batch.item.ItemStream; -import org.springframework.batch.item.StreamContext; +import org.springframework.batch.item.ExecutionAttributes; import org.springframework.batch.item.StreamException; import org.springframework.transaction.TransactionStatus; @@ -39,18 +39,18 @@ public interface StreamManager { * @param stream an {@link ItemStream} * @param streamContext the context (may be null) to restore from on registration */ - void register(Object key, ItemStream stream, StreamContext streamContext); + void register(Object key, ItemStream stream, ExecutionAttributes streamContext); /** - * Extract and aggregate the {@link StreamContext} from all streams under + * Extract and aggregate the {@link ExecutionAttributes} from all streams under * this key. * * @param key the key under which {@link ItemStream} instances might have * been registered. - * @return {@link StreamContext} aggregating the contexts of all providers + * @return {@link ExecutionAttributes} aggregating the contexts of all providers * registered under this key, or empty otherwise. */ - StreamContext getStreamContext(Object key); + ExecutionAttributes getStreamContext(Object key); /** * If any resources are needed for the stream to operate they need to be diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/writer/DelegatingItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/writer/DelegatingItemWriter.java index dd628f7e6..7e2fa8a37 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/writer/DelegatingItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/writer/DelegatingItemWriter.java @@ -3,7 +3,7 @@ package org.springframework.batch.item.writer; import org.springframework.batch.io.Skippable; import org.springframework.batch.item.ItemStream; import org.springframework.batch.item.ItemWriter; -import org.springframework.batch.item.StreamContext; +import org.springframework.batch.item.ExecutionAttributes; import org.springframework.beans.factory.InitializingBean; import org.springframework.util.Assert; @@ -49,7 +49,7 @@ public class DelegatingItemWriter implements ItemWriter, Skippable, Initializing /** * @see ItemStream#getStreamContext() */ - public StreamContext getStreamContext() { + public ExecutionAttributes getStreamContext() { Assert.state(writer != null, "Source must not be null."); @@ -57,14 +57,14 @@ public class DelegatingItemWriter implements ItemWriter, Skippable, Initializing return ((ItemStream) writer).getStreamContext(); } else { - return new StreamContext(); + return new ExecutionAttributes(); } } /** - * @see ItemStream#restoreFrom(StreamContext) + * @see ItemStream#restoreFrom(ExecutionAttributes) */ - public void restoreFrom(StreamContext data) { + public void restoreFrom(ExecutionAttributes data) { Assert.state(writer != null, "Source must not be null."); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/driving/DrivingQueryItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/driving/DrivingQueryItemReaderTests.java index d9e5e502b..f5c027de6 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/driving/DrivingQueryItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/driving/DrivingQueryItemReaderTests.java @@ -9,7 +9,8 @@ import junit.framework.TestCase; import org.springframework.batch.io.sample.domain.Foo; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemStream; -import org.springframework.batch.item.StreamContext; +import org.springframework.batch.item.ExecutionAttributes; +import org.springframework.batch.item.stream.GenericStreamContext; import org.springframework.beans.factory.InitializingBean; import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.util.Assert; @@ -73,7 +74,7 @@ public class DrivingQueryItemReaderTests extends TestCase { Foo foo2 = (Foo) source.read(); assertEquals(2, foo2.getValue()); - StreamContext streamContext = getAsRestartable(source).getStreamContext(); + ExecutionAttributes streamContext = getAsRestartable(source).getStreamContext(); // create new input source source = createItemReader(); @@ -95,7 +96,7 @@ public class DrivingQueryItemReaderTests extends TestCase { Foo foo2 = (Foo) source.read(); assertEquals(2, foo2.getValue()); - StreamContext streamContext = getAsRestartable(source).getStreamContext(); + ExecutionAttributes streamContext = getAsRestartable(source).getStreamContext(); // create new input source source = createItemReader(); @@ -117,7 +118,7 @@ public class DrivingQueryItemReaderTests extends TestCase { * @throws Exception */ public void testRestoreFromEmptyData() throws Exception { - StreamContext streamContext = new StreamContext(); + ExecutionAttributes streamContext = new GenericStreamContext(new Properties()); getAsRestartable(source).restoreFrom(streamContext); @@ -164,7 +165,7 @@ public class DrivingQueryItemReaderTests extends TestCase { private static class MockKeyGenerator implements KeyGenerator{ - static StreamContext streamContext; + static ExecutionAttributes streamContext; List keys; List restartKeys; @@ -173,7 +174,7 @@ public class DrivingQueryItemReaderTests extends TestCase { //restart data properties cannot be empty. props.setProperty("", ""); - streamContext = new StreamContext(props); + streamContext = new ExecutionAttributes(props); } public MockKeyGenerator() { @@ -191,11 +192,11 @@ public class DrivingQueryItemReaderTests extends TestCase { restartKeys.add(new Foo(5, "5", 5)); } - public StreamContext getKeyAsStreamContext(Object key) { + public ExecutionAttributes getKeyAsStreamContext(Object key) { return streamContext; } - public List restoreKeys(StreamContext streamContext) { + public List restoreKeys(ExecutionAttributes streamContext) { assertEquals(MockKeyGenerator.streamContext, streamContext); return restartKeys; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/driving/FooInputSource.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/driving/FooInputSource.java index ecfe9cecc..aa6588ebf 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/driving/FooInputSource.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/driving/FooInputSource.java @@ -2,7 +2,7 @@ package org.springframework.batch.io.driving; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemStream; -import org.springframework.batch.item.StreamContext; +import org.springframework.batch.item.ExecutionAttributes; import org.springframework.batch.item.reader.AbstractItemReader; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; @@ -27,11 +27,11 @@ class FooItemReader extends AbstractItemReader implements ItemStream, ItemReader } } - public StreamContext getStreamContext() { + public ExecutionAttributes getStreamContext() { return inputSource.getStreamContext(); } - public void restoreFrom(StreamContext data) { + public void restoreFrom(ExecutionAttributes data) { inputSource.restoreFrom(data); } @@ -63,14 +63,14 @@ class FooItemReader extends AbstractItemReader implements ItemStream, ItemReader /* (non-Javadoc) * @see org.springframework.batch.item.ItemStream#mark(org.springframework.batch.item.StreamContext) */ - public void mark(StreamContext streamContext) { + public void mark(ExecutionAttributes streamContext) { inputSource.mark(streamContext); } /* (non-Javadoc) * @see org.springframework.batch.item.ItemStream#reset(org.springframework.batch.item.StreamContext) */ - public void reset(StreamContext streamContext) { + public void reset(ExecutionAttributes streamContext) { inputSource.reset(streamContext); }; } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/driving/support/ColumnMapRestartDataRowMapperTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/driving/support/ColumnMapRestartDataRowMapperTests.java index 5b1a99e47..43db8d3fc 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/driving/support/ColumnMapRestartDataRowMapperTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/driving/support/ColumnMapRestartDataRowMapperTests.java @@ -11,7 +11,8 @@ import java.util.Properties; import junit.framework.TestCase; import org.easymock.MockControl; -import org.springframework.batch.item.StreamContext; +import org.springframework.batch.item.ExecutionAttributes; +import org.springframework.batch.item.stream.GenericStreamContext; import org.springframework.core.CollectionFactory; import org.springframework.jdbc.core.PreparedStatementSetter; @@ -60,7 +61,7 @@ public class ColumnMapRestartDataRowMapperTests extends TestCase { } public void testCreateRestartData() throws Exception { - StreamContext streamContext = mapper.createStreamContext(key); + ExecutionAttributes streamContext = mapper.createStreamContext(key); Properties props = streamContext.getProperties(); assertEquals("1", props.getProperty(KEY + "0")); assertEquals("2", props.getProperty(KEY + "1")); @@ -68,7 +69,7 @@ public class ColumnMapRestartDataRowMapperTests extends TestCase { public void testCreateRestartDataFromEmptyKeys() throws Exception { - StreamContext streamContext = mapper.createStreamContext(new HashMap()); + ExecutionAttributes streamContext = mapper.createStreamContext(new HashMap()); assertEquals(0, streamContext.getProperties().size()); } @@ -77,7 +78,9 @@ public class ColumnMapRestartDataRowMapperTests extends TestCase { Properties props = new Properties(); props.setProperty(KEY + "0", "1"); props.setProperty(KEY + "1", "2"); - StreamContext streamContext = new StreamContext(props); + ExecutionAttributes streamContext = new ExecutionAttributes(); + streamContext.putString(KEY + "0", "1"); + streamContext.putString(KEY + "1", "2"); PreparedStatementSetter setter = mapper.createSetter(streamContext); ps = (PreparedStatement)psControl.getMock(); 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..aa1a66f90 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 @@ -7,7 +7,8 @@ import java.util.List; import java.util.Map; import java.util.Properties; -import org.springframework.batch.item.StreamContext; +import org.springframework.batch.item.ExecutionAttributes; +import org.springframework.batch.item.stream.GenericStreamContext; import org.springframework.core.CollectionFactory; import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests; @@ -45,10 +46,9 @@ public class MultipleColumnJdbcKeyGeneratorIntegrationTests extends AbstractTran public void testRestoreKeys(){ - Properties props = new Properties(); - props.setProperty(ColumnMapStreamContextRowMapper.KEY_PREFIX + "0", "3"); - props.setProperty(ColumnMapStreamContextRowMapper.KEY_PREFIX + "1", "3"); - StreamContext streamContext = new StreamContext(props); + ExecutionAttributes streamContext = new ExecutionAttributes(); + streamContext.putString(ColumnMapStreamContextRowMapper.KEY_PREFIX + "0", "3"); + streamContext.putString(ColumnMapStreamContextRowMapper.KEY_PREFIX + "1", "3"); List keys = keyStrategy.restoreKeys(streamContext); @@ -67,7 +67,7 @@ public class MultipleColumnJdbcKeyGeneratorIntegrationTests extends AbstractTran key.put("ID", new Long(3)); key.put("VALUE", new Integer(3)); - StreamContext streamContext = keyStrategy.getKeyAsStreamContext(key); + ExecutionAttributes streamContext = keyStrategy.getKeyAsStreamContext(key); Properties props = streamContext.getProperties(); assertEquals(2, props.size()); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/driving/support/SingleColumnJdbcKeyGeneratorIntegrationTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/driving/support/SingleColumnJdbcKeyGeneratorIntegrationTests.java index 04d5906db..1f5237cfd 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/driving/support/SingleColumnJdbcKeyGeneratorIntegrationTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/driving/support/SingleColumnJdbcKeyGeneratorIntegrationTests.java @@ -3,7 +3,8 @@ package org.springframework.batch.io.driving.support; import java.util.List; import java.util.Properties; -import org.springframework.batch.item.StreamContext; +import org.springframework.batch.item.ExecutionAttributes; +import org.springframework.batch.item.stream.GenericStreamContext; import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests; /** @@ -43,7 +44,7 @@ public class SingleColumnJdbcKeyGeneratorIntegrationTests extends AbstractTransa Properties props = new Properties(); props.setProperty(SingleColumnJdbcKeyGenerator.RESTART_KEY, "3"); - StreamContext streamContext = new StreamContext(props); + ExecutionAttributes streamContext = new GenericStreamContext(props); List keys = keyStrategy.restoreKeys(streamContext); @@ -54,7 +55,7 @@ public class SingleColumnJdbcKeyGeneratorIntegrationTests extends AbstractTransa public void testGetKeyAsStreamContext(){ - StreamContext streamContext = keyStrategy.getKeyAsStreamContext(new Long(3)); + ExecutionAttributes streamContext = keyStrategy.getKeyAsStreamContext(new Long(3)); Properties props = streamContext.getProperties(); assertEquals(1, props.size()); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/file/DefaultFlatFileItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/file/DefaultFlatFileItemReaderTests.java index 3d08f986b..57dc21645 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/file/DefaultFlatFileItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/file/DefaultFlatFileItemReaderTests.java @@ -24,7 +24,7 @@ import org.springframework.batch.io.file.mapping.DefaultFieldSet; import org.springframework.batch.io.file.mapping.FieldSet; import org.springframework.batch.io.file.mapping.FieldSetMapper; import org.springframework.batch.io.file.transform.LineTokenizer; -import org.springframework.batch.item.StreamContext; +import org.springframework.batch.item.ExecutionAttributes; import org.springframework.batch.item.StreamException; import org.springframework.core.io.ByteArrayResource; import org.springframework.core.io.Resource; @@ -179,7 +179,7 @@ public class DefaultFlatFileItemReaderTests extends TestCase { inputSource.read(); // get restart data - StreamContext streamContext = inputSource.getStreamContext(); + ExecutionAttributes streamContext = inputSource.getStreamContext(); assertEquals("4", (String) streamContext.getProperties().getProperty( DefaultFlatFileItemReader.READ_STATISTICS_NAME)); // close input @@ -195,7 +195,7 @@ public class DefaultFlatFileItemReaderTests extends TestCase { assertEquals("[testLine5]", inputSource.read().toString()); assertEquals("[testLine6]", inputSource.read().toString()); - StreamContext statistics = inputSource.getStreamContext(); + ExecutionAttributes statistics = inputSource.getStreamContext(); assertEquals(6, statistics.getLong(DefaultFlatFileItemReader.READ_STATISTICS_NAME)); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/file/FlatFileItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/file/FlatFileItemWriterTests.java index 8230cdb24..15fd2f890 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/file/FlatFileItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/file/FlatFileItemWriterTests.java @@ -25,7 +25,7 @@ import java.util.Collections; import junit.framework.TestCase; import org.springframework.batch.item.ItemStream; -import org.springframework.batch.item.StreamContext; +import org.springframework.batch.item.ExecutionAttributes; import org.springframework.batch.item.writer.ItemTransformer; import org.springframework.core.io.FileSystemResource; import org.springframework.transaction.support.TransactionSynchronizationManager; @@ -309,7 +309,7 @@ public class FlatFileItemWriterTests extends TestCase { commit(); // get restart data - StreamContext streamContext = inputSource.getStreamContext(); + ExecutionAttributes streamContext = inputSource.getStreamContext(); // close template inputSource.close(); @@ -335,7 +335,7 @@ public class FlatFileItemWriterTests extends TestCase { inputSource.write("testLine8"); // get statistics - StreamContext statistics = inputSource.getStreamContext(); + ExecutionAttributes statistics = inputSource.getStreamContext(); // close template inputSource.close(); @@ -363,7 +363,7 @@ public class FlatFileItemWriterTests extends TestCase { public void testDefaultStreamContext() throws Exception { inputSource = new FlatFileItemWriter(); inputSource.open(); - StreamContext streamContext = inputSource.getStreamContext(); + ExecutionAttributes streamContext = inputSource.getStreamContext(); assertNotNull(streamContext); assertEquals(3, streamContext.getProperties().size()); assertEquals(0, streamContext.getLong(FlatFileItemWriter.RESTART_DATA_NAME)); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/sql/AbstractJdbcItemReaderIntegrationTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/sql/AbstractJdbcItemReaderIntegrationTests.java index c563fcfd4..4794971ee 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/sql/AbstractJdbcItemReaderIntegrationTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/sql/AbstractJdbcItemReaderIntegrationTests.java @@ -3,7 +3,8 @@ package org.springframework.batch.io.sql; import org.springframework.batch.io.sample.domain.Foo; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemStream; -import org.springframework.batch.item.StreamContext; +import org.springframework.batch.item.ExecutionAttributes; +import org.springframework.batch.item.stream.GenericStreamContext; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests; @@ -76,7 +77,7 @@ public abstract class AbstractJdbcItemReaderIntegrationTests extends AbstractTra Foo foo2 = (Foo) source.read(); assertEquals(2, foo2.getValue()); - StreamContext streamContext = getAsRestartable(source).getStreamContext(); + ExecutionAttributes streamContext = getAsRestartable(source).getStreamContext(); // create new input source source = createItemReader(); @@ -98,7 +99,7 @@ public abstract class AbstractJdbcItemReaderIntegrationTests extends AbstractTra Foo foo2 = (Foo) source.read(); assertEquals(2, foo2.getValue()); - StreamContext streamContext = getAsRestartable(source).getStreamContext(); + ExecutionAttributes streamContext = getAsRestartable(source).getStreamContext(); // create new input source source = createItemReader(); @@ -120,7 +121,7 @@ public abstract class AbstractJdbcItemReaderIntegrationTests extends AbstractTra * @throws Exception */ public void testRestoreFromEmptyData() throws Exception { - StreamContext streamContext = new StreamContext(); + ExecutionAttributes streamContext = new ExecutionAttributes(); getAsRestartable(source).restoreFrom(streamContext); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/support/AbstractDataSourceItemReaderIntegrationTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/support/AbstractDataSourceItemReaderIntegrationTests.java index 9ec7855a1..8bc3d28ca 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/support/AbstractDataSourceItemReaderIntegrationTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/support/AbstractDataSourceItemReaderIntegrationTests.java @@ -4,7 +4,8 @@ import org.springframework.batch.io.Skippable; import org.springframework.batch.io.sample.domain.Foo; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemStream; -import org.springframework.batch.item.StreamContext; +import org.springframework.batch.item.ExecutionAttributes; +import org.springframework.batch.item.stream.GenericStreamContext; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests; @@ -83,7 +84,7 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends Abstr Foo foo2 = (Foo) source.read(); assertEquals(2, foo2.getValue()); - StreamContext streamContext = getAsRestartable(source).getStreamContext(); + ExecutionAttributes streamContext = getAsRestartable(source).getStreamContext(); // create new input source source = createItemReader(); @@ -105,7 +106,7 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends Abstr Foo foo2 = (Foo) source.read(); assertEquals(2, foo2.getValue()); - StreamContext streamContext = getAsRestartable(source).getStreamContext(); + ExecutionAttributes streamContext = getAsRestartable(source).getStreamContext(); // create new input source source = createItemReader(); @@ -127,7 +128,7 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends Abstr * @throws Exception */ public void testRestoreFromEmptyData() throws Exception { - StreamContext streamContext = new StreamContext(); + ExecutionAttributes streamContext = new ExecutionAttributes(); getAsRestartable(source).restoreFrom(streamContext); @@ -208,7 +209,7 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends Abstr rollback(); - StreamContext streamContext = getAsRestartable(source).getStreamContext(); + ExecutionAttributes streamContext = getAsRestartable(source).getStreamContext(); // create new input source source = createItemReader(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/support/AbstractTransactionalIoSourceTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/support/AbstractTransactionalIoSourceTests.java index 25cf00f63..5af734097 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/support/AbstractTransactionalIoSourceTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/support/AbstractTransactionalIoSourceTests.java @@ -18,7 +18,7 @@ package org.springframework.batch.io.support; import junit.framework.TestCase; -import org.springframework.batch.item.StreamContext; +import org.springframework.batch.item.ExecutionAttributes; import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.util.Assert; @@ -57,12 +57,12 @@ public class AbstractTransactionalIoSourceTests extends TestCase { private boolean commitCalled = false; private boolean rollbackCalled = false; - public void mark(StreamContext streamContext) { + public void mark(ExecutionAttributes streamContext) { Assert.isTrue(!commitCalled, "Commit aleady called"); commitCalled = true; } - public void reset(StreamContext streamContext) { + public void reset(ExecutionAttributes streamContext) { Assert.isTrue(!rollbackCalled, "Rollback aleady called"); rollbackCalled = true; } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/xml/StaxEventItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/xml/StaxEventItemReaderTests.java index 2d2a380ba..b4fd56246 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/xml/StaxEventItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/xml/StaxEventItemReaderTests.java @@ -14,7 +14,7 @@ import javax.xml.stream.events.XMLEvent; import junit.framework.TestCase; -import org.springframework.batch.item.StreamContext; +import org.springframework.batch.item.ExecutionAttributes; import org.springframework.core.io.AbstractResource; import org.springframework.core.io.ByteArrayResource; import org.springframework.core.io.Resource; @@ -112,7 +112,7 @@ public class StaxEventItemReaderTests extends TestCase { */ public void testRestart() { source.read(); - StreamContext streamContext = source.getStreamContext(); + ExecutionAttributes streamContext = source.getStreamContext(); assertEquals(1, streamContext.getLong(StaxEventItemReader.READ_COUNT_STATISTICS_NAME)); List expectedAfterRestart = (List) source.read(); @@ -127,7 +127,7 @@ public class StaxEventItemReaderTests extends TestCase { * already initialised when restoring. */ public void testInvalidRestore() { - StreamContext context = new StreamContext(); + ExecutionAttributes context = new ExecutionAttributes(); context.putLong(StaxEventItemReader.READ_COUNT_STATISTICS_NAME, 100000); try { source.restoreFrom(context); @@ -140,7 +140,7 @@ public class StaxEventItemReaderTests extends TestCase { source = createNewInputSouce(); source.open(); try { - source.restoreFrom(new StreamContext()); + source.restoreFrom(new ExecutionAttributes()); fail(); } catch (IllegalStateException e) { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/xml/StaxEventWriterItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/xml/StaxEventWriterItemWriterTests.java index feff19ab6..cfa2767cd 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/xml/StaxEventWriterItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/io/xml/StaxEventWriterItemWriterTests.java @@ -12,7 +12,7 @@ import junit.framework.TestCase; import org.apache.commons.io.FileUtils; import org.springframework.batch.io.xml.oxm.MarshallingEventWriterSerializer; -import org.springframework.batch.item.StreamContext; +import org.springframework.batch.item.ExecutionAttributes; import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.Resource; import org.springframework.oxm.Marshaller; @@ -88,7 +88,7 @@ public class StaxEventWriterItemWriterTests extends TestCase { // write records writer.write(record); writer.mark(null); - StreamContext streamContext = writer.getStreamContext(); + ExecutionAttributes streamContext = writer.getStreamContext(); // create new writer from saved restart data and continue writing writer = createItemWriter(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/StreamContextTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/ExecutionAttributesTests.java similarity index 75% rename from spring-batch-infrastructure/src/test/java/org/springframework/batch/item/StreamContextTests.java rename to spring-batch-infrastructure/src/test/java/org/springframework/batch/item/ExecutionAttributesTests.java index 49b395003..2745b683d 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/StreamContextTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/ExecutionAttributesTests.java @@ -21,14 +21,14 @@ import junit.framework.TestCase; * @author Lucas Ward * */ -public class StreamContextTests extends TestCase{ +public class ExecutionAttributesTests extends TestCase{ - StreamContext context; + ExecutionAttributes context; protected void setUp() throws Exception { super.setUp(); - context = new StreamContext(); + context = new ExecutionAttributes(); } public void testNormalUsage(){ @@ -58,30 +58,41 @@ public class StreamContextTests extends TestCase{ public void testIsEmpty(){ assertTrue(context.isEmpty()); - context.put("1", new Object()); + context.putString("1", "test"); assertFalse(context.isEmpty()); } public void testDirtyFlag(){ assertFalse(context.isDirty()); - context.put("1", new Object()); + context.putString("1", "test"); assertTrue(context.isDirty()); context.clearDirtyFlag(); assertFalse(context.isDirty()); } public void testContains(){ - context.put("1", "testString"); + context.putString("1", "testString"); assertTrue(context.containsKey("1")); assertTrue(context.containsValue("testString")); } public void testEquals(){ - context.put("1", "testString"); - StreamContext tempContext = new StreamContext(); + context.putString("1", "testString"); + ExecutionAttributes tempContext = new ExecutionAttributes(); assertFalse(tempContext.equals(context)); - tempContext.put("1", "testString"); + tempContext.putString("1", "testString"); assertTrue(tempContext.equals(context)); } + public void testSerializationCheck(){ + //adding a non serializable object should cause an error. + try{ + context.put("1", new Object()); + fail(); + } + catch(IllegalArgumentException ex){ + //expected + } + } + } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/reader/DelegatingItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/reader/DelegatingItemReaderTests.java index 2fccd80a0..0baa0d796 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/reader/DelegatingItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/reader/DelegatingItemReaderTests.java @@ -23,7 +23,7 @@ import junit.framework.TestCase; import org.springframework.batch.io.Skippable; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemStream; -import org.springframework.batch.item.StreamContext; +import org.springframework.batch.item.ExecutionAttributes; import org.springframework.batch.support.PropertiesConverter; /** @@ -82,7 +82,7 @@ public class DelegatingItemReaderTests extends TestCase { * @throws Exception */ public void testRestoreFrom() throws Exception { - itemProvider.restoreFrom(new StreamContext(PropertiesConverter.stringToProperties("value=bar"))); + itemProvider.restoreFrom(new ExecutionAttributes(PropertiesConverter.stringToProperties("value=bar"))); assertEquals("bar", itemProvider.read()); } @@ -99,11 +99,11 @@ public class DelegatingItemReaderTests extends TestCase { return PropertiesConverter.stringToProperties("a=b"); } - public StreamContext getStreamContext() { - return new StreamContext(PropertiesConverter.stringToProperties("value=foo")); + public ExecutionAttributes getStreamContext() { + return new ExecutionAttributes(PropertiesConverter.stringToProperties("value=foo")); } - public void restoreFrom(StreamContext data) { + public void restoreFrom(ExecutionAttributes data) { value = data.getProperties().getProperty("value"); } @@ -129,10 +129,10 @@ public class DelegatingItemReaderTests extends TestCase { return false; } - public void mark(StreamContext streamContext) { + public void mark(ExecutionAttributes streamContext) { } - public void reset(StreamContext streamContext) { + public void reset(ExecutionAttributes streamContext) { } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/stream/SimpleStreamManagerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/stream/SimpleStreamManagerTests.java index c7d9529d5..e5bc319a8 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/stream/SimpleStreamManagerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/stream/SimpleStreamManagerTests.java @@ -20,6 +20,7 @@ import java.util.List; import junit.framework.TestCase; +import org.springframework.batch.item.ExecutionAttributes; import org.springframework.batch.item.StreamContext; import org.springframework.batch.item.StreamException; import org.springframework.batch.support.PropertiesConverter; @@ -75,7 +76,7 @@ public class SimpleStreamManagerTests extends TestCase { * {@link org.springframework.batch.item.stream.SimpleStreamManager#getStreamContext(java.lang.Object)}. */ public void testGetStreamContextEmpty() { - StreamContext streamContext = manager.getStreamContext("foo"); + ExecutionAttributes streamContext = manager.getStreamContext("foo"); assertEquals(0, streamContext.entrySet().size()); } @@ -85,7 +86,7 @@ public class SimpleStreamManagerTests extends TestCase { */ public void testGetStreamContextNotEmpty() { manager.register("foo", stream, null); - StreamContext streamContext = manager.getStreamContext("foo"); + ExecutionAttributes streamContext = manager.getStreamContext("foo"); assertEquals(1, streamContext.entrySet().size()); assertEquals("bar", streamContext.getString(ClassUtils.getQualifiedName(stream.getClass()) + ".foo")); } @@ -96,7 +97,7 @@ public class SimpleStreamManagerTests extends TestCase { */ public void testGetStreamContextNotEmptyAndRestore() { testGetStreamContextNotEmpty(); - StreamContext context = manager.getStreamContext("foo"); + ExecutionAttributes context = manager.getStreamContext("foo"); // Register again, now with the context that was created from the same // stream... manager.register("foo", stream, context); @@ -110,7 +111,7 @@ public class SimpleStreamManagerTests extends TestCase { * {@link org.springframework.batch.item.stream.SimpleStreamManager#getStreamContext(java.lang.Object)}. */ public void testGetStreamContextNotEmptyAndRestoreWithNoPrefix() { - StreamContext context = new StreamContext(PropertiesConverter.stringToProperties("foo=bar")); + ExecutionAttributes context = new ExecutionAttributes(PropertiesConverter.stringToProperties("foo=bar")); manager.setUseClassNameAsPrefix(false); manager.register("foo", stream, context); assertEquals(1, list.size()); @@ -125,7 +126,7 @@ public class SimpleStreamManagerTests extends TestCase { public void testGetStreamContextWithNoPrefix() { manager.setUseClassNameAsPrefix(false); manager.register("foo", stream, null); - StreamContext context = manager.getStreamContext("foo"); + ExecutionAttributes context = manager.getStreamContext("foo"); assertEquals(1, context.entrySet().size()); // The list should have the foo= map value from the sub-context assertEquals("bar", context.getString("foo")); @@ -137,16 +138,16 @@ public class SimpleStreamManagerTests extends TestCase { */ public void testGetStreamContextTwoRegistrations() { manager.register("foo", new ItemStreamAdapter() { - public StreamContext getStreamContext() { - return new StreamContext(PropertiesConverter.stringToProperties("foo=bar")); + public ExecutionAttributes getStreamContext() { + return new ExecutionAttributes(PropertiesConverter.stringToProperties("foo=bar")); } }, null); manager.register("foo", new ItemStreamAdapter() { - public StreamContext getStreamContext() { - return new StreamContext(PropertiesConverter.stringToProperties("foo=spam")); + public ExecutionAttributes getStreamContext() { + return new ExecutionAttributes(PropertiesConverter.stringToProperties("foo=spam")); } }, null); - StreamContext streamContext = manager.getStreamContext("foo"); + ExecutionAttributes streamContext = manager.getStreamContext("foo"); assertEquals(2, streamContext.entrySet().size()); } @@ -234,8 +235,8 @@ public class SimpleStreamManagerTests extends TestCase { } private final class ItemStreamAdapterExtension extends ItemStreamAdapter { - public StreamContext getStreamContext() { - return new StreamContext(PropertiesConverter.stringToProperties("foo=bar")); + public ExecutionAttributes getStreamContext() { + return new ExecutionAttributes(PropertiesConverter.stringToProperties("foo=bar")); } public void restoreFrom(StreamContext context) { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/writer/ItemWriterItemProcessorTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/writer/ItemWriterItemProcessorTests.java index 109b6eb7d..de84dcc86 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/writer/ItemWriterItemProcessorTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/writer/ItemWriterItemProcessorTests.java @@ -23,7 +23,7 @@ import junit.framework.TestCase; import org.springframework.batch.io.Skippable; import org.springframework.batch.item.ItemWriter; -import org.springframework.batch.item.StreamContext; +import org.springframework.batch.item.ExecutionAttributes; import org.springframework.batch.support.PropertiesConverter; /** @@ -65,7 +65,7 @@ public class ItemWriterItemProcessorTests extends TestCase { * @throws Exception */ public void testRestoreFrom() throws Exception { - processor.restoreFrom(new StreamContext(PropertiesConverter.stringToProperties("value=bar"))); + processor.restoreFrom(new ExecutionAttributes(PropertiesConverter.stringToProperties("value=bar"))); processor.write("foo"); assertEquals("bar:foo", list.get(0)); } @@ -92,7 +92,7 @@ public class ItemWriterItemProcessorTests extends TestCase { public void testRestoreFromWithoutRestartable() throws Exception { processor.setDelegate(null); try { - processor.restoreFrom(new StreamContext(PropertiesConverter.stringToProperties("value=bar"))); + processor.restoreFrom(new ExecutionAttributes(PropertiesConverter.stringToProperties("value=bar"))); fail("Expected IllegalStateException"); } catch (IllegalStateException e) { @@ -144,11 +144,11 @@ public class ItemWriterItemProcessorTests extends TestCase { public void open() { } - public StreamContext getStreamContext() { - return new StreamContext(PropertiesConverter.stringToProperties("value=foo")); + public ExecutionAttributes getStreamContext() { + return new ExecutionAttributes(PropertiesConverter.stringToProperties("value=foo")); } - public void restoreFrom(StreamContext data) { + public void restoreFrom(ExecutionAttributes data) { value = data.getProperties().getProperty("value"); }