From 2d1ccb0cc6cf74b2117ffd63158709c2b0fe23c3 Mon Sep 17 00:00:00 2001 From: dsyer Date: Sat, 2 Feb 2008 15:16:20 +0000 Subject: [PATCH] IN PROGRESS - issue BATCH-7: Remove transaction synchronization and state management from input/output sources (formerly buffering) http://jira.springframework.org/browse/BATCH-7 Remove GenericStreamContext --- .../batch/core/domain/StepInstance.java | 5 +-- .../core/domain/StepContributionTests.java | 6 +-- .../batch/core/domain/StepInstanceTests.java | 9 ++--- .../repository/SimpleJobRepository.java | 13 +++--- .../execution/repository/dao/JdbcStepDao.java | 11 ++--- .../repository/SimpleJobRepositoryTests.java | 8 ++-- .../repository/dao/AbstractStepDaoTests.java | 17 +++----- .../repository/dao/MapStepDaoTests.java | 8 +--- .../scope/SimpleStepContextTests.java | 3 +- .../step/simple/SimpleStepExecutorTests.java | 7 ++-- .../io/cursor/HibernateCursorItemReader.java | 4 +- .../batch/io/cursor/JdbcCursorItemReader.java | 3 +- .../ColumnMapStreamContextRowMapper.java | 3 +- .../driving/support/IbatisKeyGenerator.java | 3 +- .../support/SingleColumnJdbcKeyGenerator.java | 10 ++--- .../batch/io/file/FlatFileItemWriter.java | 3 +- .../batch/item/StreamContext.java | 4 ++ .../item/stream/GenericStreamContext.java | 40 ------------------- .../batch/item/stream/ItemStreamAdapter.java | 4 +- .../item/stream/SimpleStreamManager.java | 2 +- .../item/writer/DelegatingItemWriter.java | 5 +-- .../driving/DrivingQueryItemReaderTests.java | 5 +-- .../ColumnMapRestartDataRowMapperTests.java | 3 +- ...olumnJdbcKeyGeneratorIntegrationTests.java | 3 +- ...olumnJdbcKeyGeneratorIntegrationTests.java | 3 +- ...bstractJdbcItemReaderIntegrationTests.java | 5 +-- ...tDataSourceItemReaderIntegrationTests.java | 5 +-- .../reader/DelegatingItemReaderTests.java | 5 +-- .../writer/ItemWriterItemProcessorTests.java | 11 ++--- .../sample/tasklet/InfiniteLoopTasklet.java | 3 +- 30 files changed, 60 insertions(+), 151 deletions(-) delete mode 100644 spring-batch-infrastructure/src/main/java/org/springframework/batch/item/stream/GenericStreamContext.java diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/StepInstance.java b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/StepInstance.java index c01e09c9e..3c8989862 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/StepInstance.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/StepInstance.java @@ -16,10 +16,7 @@ package org.springframework.batch.core.domain; -import java.util.Properties; - import org.springframework.batch.item.StreamContext; -import org.springframework.batch.item.stream.GenericStreamContext; /** *

@@ -52,7 +49,7 @@ public class StepInstance extends Entity { private BatchStatus status; - private StreamContext streamContext = new GenericStreamContext(new Properties()); + private StreamContext streamContext = new StreamContext(); private int stepExecutionCount = 0; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/domain/StepContributionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/domain/StepContributionTests.java index 4cb7cdbe8..154a345b5 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/domain/StepContributionTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/domain/StepContributionTests.java @@ -18,8 +18,6 @@ package org.springframework.batch.core.domain; import junit.framework.TestCase; import org.springframework.batch.item.StreamContext; -import org.springframework.batch.item.stream.GenericStreamContext; -import org.springframework.batch.support.PropertiesConverter; /** * @author Dave Syer @@ -47,7 +45,9 @@ public class StepContributionTests extends TestCase { */ public void testSetStreamContext() { assertEquals(null, contribution.getStreamContext()); - contribution.setStreamContext(new GenericStreamContext(PropertiesConverter.stringToProperties("foo=bar"))); + StreamContext context = new StreamContext(); + context.putString("foo", "bar"); + contribution.setStreamContext(context); assertEquals(1, contribution.getStreamContext().getProperties().size()); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/domain/StepInstanceTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/domain/StepInstanceTests.java index 58dbdf8ee..6c7ac44ab 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/domain/StepInstanceTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/domain/StepInstanceTests.java @@ -15,11 +15,10 @@ */ package org.springframework.batch.core.domain; -import java.util.Properties; - import junit.framework.TestCase; -import org.springframework.batch.item.stream.GenericStreamContext; +import org.springframework.batch.item.StreamContext; +import org.springframework.batch.support.PropertiesConverter; /** * @author Dave Syer @@ -51,9 +50,7 @@ public class StepInstanceTests extends TestCase { public void testGetStreamContext() { assertNotNull(instance.getStreamContext()); assertTrue(instance.getStreamContext().getProperties().isEmpty()); - instance.setStreamContext(new GenericStreamContext(new Properties() {{ - setProperty("foo", "bar"); - }})); + instance.setStreamContext(new StreamContext(PropertiesConverter.stringToProperties("foo=bar"))); assertEquals("bar", instance.getStreamContext().getProperties().getProperty("foo")); } diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/SimpleJobRepository.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/SimpleJobRepository.java index b0ed04ad0..b2368786a 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/SimpleJobRepository.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/SimpleJobRepository.java @@ -19,13 +19,12 @@ package org.springframework.batch.execution.repository; import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.Properties; import org.springframework.batch.core.domain.Job; -import org.springframework.batch.core.domain.JobSupport; import org.springframework.batch.core.domain.JobExecution; import org.springframework.batch.core.domain.JobInstance; import org.springframework.batch.core.domain.JobParameters; +import org.springframework.batch.core.domain.JobSupport; import org.springframework.batch.core.domain.Step; import org.springframework.batch.core.domain.StepExecution; import org.springframework.batch.core.domain.StepInstance; @@ -34,7 +33,7 @@ import org.springframework.batch.core.repository.JobExecutionAlreadyRunningExcep import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.execution.repository.dao.JobDao; import org.springframework.batch.execution.repository.dao.StepDao; -import org.springframework.batch.item.stream.GenericStreamContext; +import org.springframework.batch.item.StreamContext; import org.springframework.transaction.annotation.Isolation; import org.springframework.util.Assert; @@ -303,8 +302,8 @@ public class SimpleJobRepository implements JobRepository { Step step = (Step) i.next(); StepInstance stepInstance = stepDao.createStep(job, step.getName()); // Ensure valid restart data is being returned. - if (stepInstance.getStreamContext() == null || stepInstance.getStreamContext().getProperties() == null) { - stepInstance.setStreamContext(new GenericStreamContext(new Properties())); + if (stepInstance.getStreamContext() == null || stepInstance.getStreamContext() == null) { + stepInstance.setStreamContext(new StreamContext()); } stepInstances.add(stepInstance); } @@ -326,8 +325,8 @@ public class SimpleJobRepository implements JobRepository { step.setStepExecutionCount(stepDao.getStepExecutionCount(step)); // Ensure valid restart data is being returned. - if (step.getStreamContext() == null || step.getStreamContext().getProperties() == null) { - step.setStreamContext(new GenericStreamContext(new Properties())); + if (step.getStreamContext() == null || step.getStreamContext() == null) { + step.setStreamContext(new StreamContext()); } stepInstances.add(step); } diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcStepDao.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcStepDao.java index 630d345f2..1df32e386 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcStepDao.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcStepDao.java @@ -31,7 +31,6 @@ import org.springframework.batch.core.domain.StepExecution; import org.springframework.batch.core.domain.StepInstance; import org.springframework.batch.execution.repository.dao.JdbcJobDao.JobExecutionRowMapper; import org.springframework.batch.item.StreamContext; -import org.springframework.batch.item.stream.GenericStreamContext; import org.springframework.batch.repeat.ExitStatus; import org.springframework.batch.support.PropertiesConverter; import org.springframework.beans.factory.InitializingBean; @@ -161,9 +160,7 @@ public class JdbcStepDao implements StepDao, InitializingBean { StepInstance step = new StepInstance(new Long(rs.getLong(1))); step.setStatus(BatchStatus.getStatus(rs.getString(2))); - step - .setStreamContext(new GenericStreamContext(PropertiesConverter.stringToProperties(rs - .getString(3)))); + step.setStreamContext(new StreamContext(PropertiesConverter.stringToProperties(rs.getString(3)))); return step; } @@ -213,8 +210,8 @@ public class JdbcStepDao implements StepDao, InitializingBean { stepExecution.setStatus(BatchStatus.getStatus(rs.getString(5))); stepExecution.setCommitCount(rs.getInt(6)); stepExecution.setTaskCount(rs.getInt(7)); - stepExecution.setStreamContext(new GenericStreamContext(PropertiesConverter.stringToProperties(rs - .getString(8)))); + stepExecution.setStreamContext(new StreamContext(PropertiesConverter + .stringToProperties(rs.getString(8)))); stepExecution.setExitStatus(new ExitStatus("Y".equals(rs.getString(9)), rs.getString(10), rs .getString(11))); return stepExecution; @@ -247,7 +244,7 @@ public class JdbcStepDao implements StepDao, InitializingBean { String status = rs.getString(3); step.setStatus(BatchStatus.getStatus(status)); step - .setStreamContext(new GenericStreamContext(PropertiesConverter.stringToProperties(rs + .setStreamContext(new StreamContext(PropertiesConverter.stringToProperties(rs .getString(3)))); return step; } diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryTests.java index 555542822..0186d6dbb 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryTests.java @@ -25,11 +25,11 @@ import junit.framework.TestCase; import org.easymock.ArgumentsMatcher; import org.easymock.MockControl; -import org.springframework.batch.core.domain.JobSupport; import org.springframework.batch.core.domain.JobExecution; import org.springframework.batch.core.domain.JobInstance; import org.springframework.batch.core.domain.JobParameters; import org.springframework.batch.core.domain.JobParametersBuilder; +import org.springframework.batch.core.domain.JobSupport; import org.springframework.batch.core.domain.Step; import org.springframework.batch.core.domain.StepExecution; import org.springframework.batch.core.domain.StepInstance; @@ -37,7 +37,7 @@ import org.springframework.batch.core.domain.StepSupport; import org.springframework.batch.core.repository.BatchRestartException; import org.springframework.batch.execution.repository.dao.JobDao; import org.springframework.batch.execution.repository.dao.StepDao; -import org.springframework.batch.item.stream.GenericStreamContext; +import org.springframework.batch.item.StreamContext; /* * Test SimpleJobRepository. The majority of test cases are tested using EasyMock, @@ -408,7 +408,7 @@ public class SimpleJobRepositoryTests extends TestCase { databaseStep1.setStreamContext(null); stepDaoControl.setReturnValue(databaseStep1); stepDao.createStep(databaseJob, "TestStep2"); - databaseStep2.setStreamContext(new GenericStreamContext(null)); + databaseStep2.setStreamContext(new StreamContext()); stepDaoControl.setReturnValue(databaseStep2); jobDao.save(new JobExecution(databaseJob)); jobDaoControl.setMatcher(new ArgumentsMatcher(){ @@ -443,7 +443,7 @@ public class SimpleJobRepositoryTests extends TestCase { stepDao.getStepExecutionCount(databaseStep1); stepDaoControl.setReturnValue(1); stepDao.findStep(databaseJob, "TestStep2"); - databaseStep2.setStreamContext(new GenericStreamContext(null)); + databaseStep2.setStreamContext(new StreamContext()); stepDaoControl.setReturnValue(databaseStep2); stepDao.getStepExecutionCount(databaseStep2); stepDaoControl.setReturnValue(1); diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractStepDaoTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractStepDaoTests.java index 601c9c5fe..3ff8fdabc 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractStepDaoTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractStepDaoTests.java @@ -18,7 +18,6 @@ package org.springframework.batch.execution.repository.dao; import java.util.Date; import java.util.List; -import java.util.Properties; import org.springframework.batch.core.domain.BatchStatus; import org.springframework.batch.core.domain.Job; @@ -30,8 +29,8 @@ import org.springframework.batch.core.domain.StepExecution; import org.springframework.batch.core.domain.StepInstance; import org.springframework.batch.core.runtime.ExitCodeExceptionClassifier; import org.springframework.batch.item.StreamContext; -import org.springframework.batch.item.stream.GenericStreamContext; import org.springframework.batch.repeat.ExitStatus; +import org.springframework.batch.support.PropertiesConverter; import org.springframework.dao.OptimisticLockingFailureException; import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests; import org.springframework.util.ClassUtils; @@ -151,9 +150,7 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour public void testUpdateStepWithStreamContext() { step1.setStatus(BatchStatus.COMPLETED); - Properties data = new Properties(); - data.setProperty("restart.key1", "restartData"); - StreamContext streamContext = new GenericStreamContext(data); + StreamContext streamContext = new StreamContext(PropertiesConverter.stringToProperties("key1=restartData")); step1.setStreamContext(streamContext); stepDao.update(step1); StepInstance tempStep = stepDao.findStep(jobInstance, step1.getName()); @@ -166,10 +163,7 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour StepExecution execution = new StepExecution(step2, jobExecution, null); execution.setStatus(BatchStatus.STARTED); execution.setStartTime(new Date(System.currentTimeMillis())); - Properties statistics = new Properties(); - statistics.setProperty("statistic.key1", "0"); - statistics.setProperty("statistic.key2", "5"); - execution.setStreamContext(new GenericStreamContext(statistics)); + execution.setStreamContext(new StreamContext(PropertiesConverter.stringToProperties("key1=0,key2=5"))); execution.setExitStatus(new ExitStatus(false, ExitCodeExceptionClassifier.FATAL_EXCEPTION, "java.lang.Exception")); stepDao.save(execution); @@ -177,8 +171,7 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour assertEquals(1, executions.size()); StepExecution tempExecution = (StepExecution) executions.get(0); assertEquals(execution, tempExecution); - assertEquals(execution.getStreamContext().getString("statistic.key1"), tempExecution.getStreamContext() - .getString("statistic.key1")); + assertEquals(execution.getStreamContext().getString("key1"), tempExecution.getStreamContext().getString("key1")); assertEquals(execution.getExitStatus(), tempExecution.getExitStatus()); } @@ -234,7 +227,7 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour public void testUpdateStepExecutionOptimisticLocking() throws Exception { stepExecution.incrementVersion(); // not really allowed outside dao - // code + // code try { stepDao.update(stepExecution); fail("Expected OptimisticLockingFailureException"); diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/MapStepDaoTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/MapStepDaoTests.java index 369e8b17e..113d6e2c4 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/MapStepDaoTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/MapStepDaoTests.java @@ -17,7 +17,6 @@ package org.springframework.batch.execution.repository.dao; import java.util.List; -import java.util.Properties; import junit.framework.TestCase; @@ -26,9 +25,8 @@ import org.springframework.batch.core.domain.JobInstance; import org.springframework.batch.core.domain.JobParameters; import org.springframework.batch.core.domain.StepExecution; import org.springframework.batch.core.domain.StepInstance; -import org.springframework.batch.execution.repository.dao.MapStepDao; import org.springframework.batch.item.StreamContext; -import org.springframework.batch.item.stream.GenericStreamContext; +import org.springframework.batch.support.PropertiesConverter; public class MapStepDaoTests extends TestCase { @@ -109,9 +107,7 @@ public class MapStepDaoTests extends TestCase { public void testSaveStreamContext() throws Exception { assertEquals(null, dao.getStreamContext(step.getId())); step.setStatus(BatchStatus.COMPLETED); - Properties data = new Properties(); - data.setProperty("restart.key1", "restartData"); - StreamContext streamContext = new GenericStreamContext(data); + StreamContext streamContext = new StreamContext(PropertiesConverter.stringToProperties("key1=restartData")); step.setStreamContext(streamContext); dao.update(step); StepInstance tempStep = dao.findStep(job, step.getName()); diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/scope/SimpleStepContextTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/scope/SimpleStepContextTests.java index 7c10d5884..4d69b7827 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/scope/SimpleStepContextTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/scope/SimpleStepContextTests.java @@ -25,7 +25,6 @@ import junit.framework.TestCase; import org.springframework.batch.core.domain.StepExecution; import org.springframework.batch.item.ItemStream; import org.springframework.batch.item.StreamContext; -import org.springframework.batch.item.stream.GenericStreamContext; import org.springframework.batch.item.stream.ItemStreamAdapter; import org.springframework.batch.item.stream.SimpleStreamManager; import org.springframework.batch.support.PropertiesConverter; @@ -166,7 +165,7 @@ public class SimpleStepContextTests extends TestCase { } public StreamContext getStreamContext(Object key) { - return new GenericStreamContext(PropertiesConverter.stringToProperties("foo=bar")); + return new StreamContext(PropertiesConverter.stringToProperties("foo=bar")); } public void open(Object key) { diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/simple/SimpleStepExecutorTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/simple/SimpleStepExecutorTests.java index 9c78bef85..b1b27b4f9 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/simple/SimpleStepExecutorTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/step/simple/SimpleStepExecutorTests.java @@ -43,7 +43,6 @@ import org.springframework.batch.item.ItemWriter; import org.springframework.batch.item.StreamContext; import org.springframework.batch.item.StreamException; import org.springframework.batch.item.reader.ListItemReader; -import org.springframework.batch.item.stream.GenericStreamContext; import org.springframework.batch.item.stream.ItemStreamAdapter; import org.springframework.batch.item.stream.SimpleStreamManager; import org.springframework.batch.item.writer.AbstractItemWriter; @@ -306,7 +305,7 @@ public class SimpleStepExecutorTests extends TestCase { JobExecution jobExecutionContext = new JobExecution(jobInstance); StepExecution stepExecution = new StepExecution(step, jobExecutionContext); stepExecution.getStep().setStreamContext( - new GenericStreamContext(PropertiesConverter.stringToProperties("foo=bar"))); + new StreamContext(PropertiesConverter.stringToProperties("foo=bar"))); stepExecutor.execute(stepExecution); @@ -415,7 +414,7 @@ public class SimpleStepExecutorTests extends TestCase { stepExecutor.setStreamManager(new SimpleStreamManager(new ResourcelessTransactionManager()) { public StreamContext getStreamContext(Object key) { // TODO Auto-generated method stub - return new GenericStreamContext(PropertiesConverter.stringToProperties("foo=bar")); + return new StreamContext(PropertiesConverter.stringToProperties("foo=bar")); } }); @@ -447,7 +446,7 @@ public class SimpleStepExecutorTests extends TestCase { public StreamContext getStreamContext() { getStreamContextCalled = true; - return new GenericStreamContext(PropertiesConverter.stringToProperties("spam=bucket")); + return new StreamContext(PropertiesConverter.stringToProperties("spam=bucket")); } public void restoreFrom(StreamContext data) { 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 9ee02fa3f..fabab92a5 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 @@ -27,7 +27,6 @@ import org.springframework.batch.io.Skippable; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.StreamContext; import org.springframework.batch.item.reader.AbstractItemStreamItemReader; -import org.springframework.batch.item.stream.GenericStreamContext; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.util.Assert; @@ -180,8 +179,7 @@ public class HibernateCursorItemReader extends AbstractItemStreamItemReader impl props.setProperty(RESTART_DATA_ROW_NUMBER_KEY, "" + currentProcessedRow); String skipped = skippedRows.toString(); props.setProperty(SKIPPED_ROWS, skipped.substring(1, skipped.length() - 1)); - - return new GenericStreamContext(props); + return new StreamContext(props); } /** 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 ebd0d8a1a..cc46376df 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 @@ -33,7 +33,6 @@ 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.stream.GenericStreamContext; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.dao.DataAccessException; @@ -393,7 +392,7 @@ public class JdbcCursorItemReader extends AbstractTransactionalIoSource implemen */ public StreamContext getStreamContext() { String skipped = skippedRows.toString(); - StreamContext context = new GenericStreamContext(); + StreamContext context = new StreamContext(); context.putString(SKIPPED_ROWS, skipped.substring(1, skipped.length() - 1)); context.putLong(CURRENT_PROCESSED_ROW, currentProcessedRow); context.putLong(SKIP_COUNT, skipCount); 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 c899bb911..df406f114 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 @@ -13,7 +13,6 @@ import java.util.Properties; import java.util.Map.Entry; import org.springframework.batch.item.StreamContext; -import org.springframework.batch.item.stream.GenericStreamContext; import org.springframework.core.CollectionFactory; import org.springframework.jdbc.core.ColumnMapRowMapper; import org.springframework.jdbc.core.PreparedStatementSetter; @@ -60,7 +59,7 @@ public class ColumnMapStreamContextRowMapper extends ColumnMapRowMapper implemen } - private static class ColumnMapStreamContext extends GenericStreamContext { + private static class ColumnMapStreamContext extends StreamContext { 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 48cbcaffd..d27363c70 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 @@ -6,7 +6,6 @@ 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.stream.GenericStreamContext; import org.springframework.orm.ibatis.SqlMapClientTemplate; import org.springframework.util.Assert; @@ -48,7 +47,7 @@ public class IbatisKeyGenerator implements KeyGenerator { Properties props = new Properties(); props.setProperty(RESTART_KEY, key.toString()); - return new GenericStreamContext(props); + return new StreamContext(props); } /** 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 a21acf19b..82a087b5e 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 @@ -17,12 +17,10 @@ package org.springframework.batch.io.driving.support; import java.util.ArrayList; import java.util.List; -import java.util.Properties; import org.apache.commons.lang.ClassUtils; import org.springframework.batch.io.driving.KeyGenerator; import org.springframework.batch.item.StreamContext; -import org.springframework.batch.item.stream.GenericStreamContext; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.SingleColumnRowMapper; @@ -101,12 +99,10 @@ public class SingleColumnJdbcKeyGenerator implements KeyGenerator { * @throws IllegalArgumentException if key is null. */ public StreamContext getKeyAsStreamContext(Object key) { - Assert.notNull(key, "The key must not be null."); - - Properties props = new Properties(); - props.setProperty(RESTART_KEY, key.toString()); - return new GenericStreamContext(props); + StreamContext context = new StreamContext(); + context.putString(RESTART_KEY, key.toString()); + return context; } /** 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 9782621ed..9abfedb02 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 @@ -35,7 +35,6 @@ import org.springframework.batch.item.ItemStream; import org.springframework.batch.item.ItemWriter; import org.springframework.batch.item.StreamContext; import org.springframework.batch.item.StreamException; -import org.springframework.batch.item.stream.GenericStreamContext; import org.springframework.batch.item.writer.ItemTransformer; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; @@ -72,7 +71,7 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements private Resource resource; - private StreamContext streamContext = new GenericStreamContext(new Properties()); + private StreamContext streamContext = new StreamContext(); private OutputState state = null; 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/StreamContext.java index fde18cac8..96acedd61 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/StreamContext.java @@ -41,6 +41,10 @@ public class StreamContext { map = new HashMap(); } + public StreamContext(Map map) { + this.map = map; + } + public void putString(String key, String value) { Assert.notNull(value); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/stream/GenericStreamContext.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/stream/GenericStreamContext.java deleted file mode 100644 index cd221e5eb..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/stream/GenericStreamContext.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2006-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.batch.item.stream; - -import java.util.Iterator; -import java.util.Properties; -import java.util.Map.Entry; - -import org.springframework.batch.item.StreamContext; - -public class GenericStreamContext extends StreamContext { - - public GenericStreamContext() { - super(); - } - - public GenericStreamContext(Properties data) { - super(); - if (data != null) { - for (Iterator it = data.entrySet().iterator(); it.hasNext();) { - Entry entry = (Entry) it.next(); - putString(entry.getKey().toString(), entry.getValue().toString()); - } - } - } -} 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 c57867479..f02b0ca98 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 @@ -15,8 +15,6 @@ */ package org.springframework.batch.item.stream; -import java.util.Properties; - import org.springframework.batch.item.ItemStream; import org.springframework.batch.item.StreamContext; import org.springframework.batch.item.StreamException; @@ -53,7 +51,7 @@ public class ItemStreamAdapter implements ItemStream { * @see org.springframework.batch.item.StreamContextProvider#getStreamContext() */ public StreamContext getStreamContext() { - return new GenericStreamContext(new Properties()); + return new StreamContext(); } /* (non-Javadoc) 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 12ebadd82..eccb00c69 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 @@ -107,7 +107,7 @@ public class SimpleStreamManager implements StreamManager { } } } - return new GenericStreamContext(result); + return new StreamContext(result); } /** 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 2a128f70d..dd628f7e6 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 @@ -1,12 +1,9 @@ package org.springframework.batch.item.writer; -import java.util.Properties; - 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.stream.GenericStreamContext; import org.springframework.beans.factory.InitializingBean; import org.springframework.util.Assert; @@ -60,7 +57,7 @@ public class DelegatingItemWriter implements ItemWriter, Skippable, Initializing return ((ItemStream) writer).getStreamContext(); } else { - return new GenericStreamContext(new Properties()); + return new StreamContext(); } } 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 4cd7e78cf..d9e5e502b 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 @@ -10,7 +10,6 @@ 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.stream.GenericStreamContext; import org.springframework.beans.factory.InitializingBean; import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.util.Assert; @@ -118,7 +117,7 @@ public class DrivingQueryItemReaderTests extends TestCase { * @throws Exception */ public void testRestoreFromEmptyData() throws Exception { - StreamContext streamContext = new GenericStreamContext(new Properties()); + StreamContext streamContext = new StreamContext(); getAsRestartable(source).restoreFrom(streamContext); @@ -174,7 +173,7 @@ public class DrivingQueryItemReaderTests extends TestCase { //restart data properties cannot be empty. props.setProperty("", ""); - streamContext = new GenericStreamContext(props); + streamContext = new StreamContext(props); } public MockKeyGenerator() { 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 996fadb95..5b1a99e47 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 @@ -12,7 +12,6 @@ import junit.framework.TestCase; import org.easymock.MockControl; import org.springframework.batch.item.StreamContext; -import org.springframework.batch.item.stream.GenericStreamContext; import org.springframework.core.CollectionFactory; import org.springframework.jdbc.core.PreparedStatementSetter; @@ -78,7 +77,7 @@ public class ColumnMapRestartDataRowMapperTests extends TestCase { Properties props = new Properties(); props.setProperty(KEY + "0", "1"); props.setProperty(KEY + "1", "2"); - StreamContext streamContext = new GenericStreamContext(props); + StreamContext streamContext = new StreamContext(props); 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 f2bb312a2..f2ba9cf5d 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 @@ -8,7 +8,6 @@ import java.util.Map; import java.util.Properties; import org.springframework.batch.item.StreamContext; -import org.springframework.batch.item.stream.GenericStreamContext; import org.springframework.core.CollectionFactory; import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests; @@ -49,7 +48,7 @@ public class MultipleColumnJdbcKeyGeneratorIntegrationTests extends AbstractTran Properties props = new Properties(); props.setProperty(ColumnMapStreamContextRowMapper.KEY_PREFIX + "0", "3"); props.setProperty(ColumnMapStreamContextRowMapper.KEY_PREFIX + "1", "3"); - StreamContext streamContext = new GenericStreamContext(props); + StreamContext streamContext = new StreamContext(props); List keys = keyStrategy.restoreKeys(streamContext); 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 f54493d80..04d5906db 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 @@ -4,7 +4,6 @@ import java.util.List; import java.util.Properties; import org.springframework.batch.item.StreamContext; -import org.springframework.batch.item.stream.GenericStreamContext; import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests; /** @@ -44,7 +43,7 @@ public class SingleColumnJdbcKeyGeneratorIntegrationTests extends AbstractTransa Properties props = new Properties(); props.setProperty(SingleColumnJdbcKeyGenerator.RESTART_KEY, "3"); - StreamContext streamContext = new GenericStreamContext(props); + StreamContext streamContext = new StreamContext(props); List keys = keyStrategy.restoreKeys(streamContext); 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 8089e48db..c563fcfd4 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 @@ -1,12 +1,9 @@ package org.springframework.batch.io.sql; -import java.util.Properties; - 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.stream.GenericStreamContext; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests; @@ -123,7 +120,7 @@ public abstract class AbstractJdbcItemReaderIntegrationTests extends AbstractTra * @throws Exception */ public void testRestoreFromEmptyData() throws Exception { - StreamContext streamContext = new GenericStreamContext(new Properties()); + StreamContext streamContext = new StreamContext(); 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 59f08ece9..9ec7855a1 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 @@ -1,13 +1,10 @@ package org.springframework.batch.io.support; -import java.util.Properties; - 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.stream.GenericStreamContext; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests; @@ -130,7 +127,7 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends Abstr * @throws Exception */ public void testRestoreFromEmptyData() throws Exception { - StreamContext streamContext = new GenericStreamContext(new Properties()); + StreamContext streamContext = new StreamContext(); getAsRestartable(source).restoreFrom(streamContext); 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 452c0a6c1..2fccd80a0 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 @@ -24,7 +24,6 @@ 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.stream.GenericStreamContext; import org.springframework.batch.support.PropertiesConverter; /** @@ -83,7 +82,7 @@ public class DelegatingItemReaderTests extends TestCase { * @throws Exception */ public void testRestoreFrom() throws Exception { - itemProvider.restoreFrom(new GenericStreamContext(PropertiesConverter.stringToProperties("value=bar"))); + itemProvider.restoreFrom(new StreamContext(PropertiesConverter.stringToProperties("value=bar"))); assertEquals("bar", itemProvider.read()); } @@ -101,7 +100,7 @@ public class DelegatingItemReaderTests extends TestCase { } public StreamContext getStreamContext() { - return new GenericStreamContext(PropertiesConverter.stringToProperties("value=foo")); + return new StreamContext(PropertiesConverter.stringToProperties("value=foo")); } public void restoreFrom(StreamContext data) { 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 1dfa6b7ca..109b6eb7d 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 @@ -24,7 +24,6 @@ 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.stream.GenericStreamContext; import org.springframework.batch.support.PropertiesConverter; /** @@ -66,7 +65,7 @@ public class ItemWriterItemProcessorTests extends TestCase { * @throws Exception */ public void testRestoreFrom() throws Exception { - processor.restoreFrom(new GenericStreamContext(PropertiesConverter.stringToProperties("value=bar"))); + processor.restoreFrom(new StreamContext(PropertiesConverter.stringToProperties("value=bar"))); processor.write("foo"); assertEquals("bar:foo", list.get(0)); } @@ -93,7 +92,7 @@ public class ItemWriterItemProcessorTests extends TestCase { public void testRestoreFromWithoutRestartable() throws Exception { processor.setDelegate(null); try { - processor.restoreFrom(new GenericStreamContext(PropertiesConverter.stringToProperties("value=bar"))); + processor.restoreFrom(new StreamContext(PropertiesConverter.stringToProperties("value=bar"))); fail("Expected IllegalStateException"); } catch (IllegalStateException e) { @@ -145,12 +144,8 @@ public class ItemWriterItemProcessorTests extends TestCase { public void open() { } - public Properties getStatistics() { - return PropertiesConverter.stringToProperties("a=b"); - } - public StreamContext getStreamContext() { - return new GenericStreamContext(PropertiesConverter.stringToProperties("value=foo")); + return new StreamContext(PropertiesConverter.stringToProperties("value=foo")); } public void restoreFrom(StreamContext data) { diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/tasklet/InfiniteLoopTasklet.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/tasklet/InfiniteLoopTasklet.java index 6b1fc71b2..d8ef7c6ef 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/tasklet/InfiniteLoopTasklet.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/tasklet/InfiniteLoopTasklet.java @@ -19,7 +19,6 @@ package org.springframework.batch.sample.tasklet; import org.springframework.batch.core.tasklet.Tasklet; import org.springframework.batch.item.StreamContext; import org.springframework.batch.item.StreamContextProvider; -import org.springframework.batch.item.stream.GenericStreamContext; import org.springframework.batch.repeat.ExitStatus; import org.springframework.batch.support.PropertiesConverter; @@ -53,7 +52,7 @@ public class InfiniteLoopTasklet implements Tasklet, StreamContextProvider { * @see org.springframework.batch.item.stream.ItemStreamAdapter#getStreamContext() */ public StreamContext getStreamContext() { - return new GenericStreamContext(PropertiesConverter.stringToProperties("count=" + count)); + return new StreamContext(PropertiesConverter.stringToProperties("count=" + count)); } }