BATCH-7: Remove transaction synchronization and state management from input/output sources (formerly buffering)
http://jira.springframework.org/browse/BATCH-7 Rename Restartable to ItemStream
This commit is contained in:
@@ -19,10 +19,9 @@ import org.springframework.batch.io.exception.BatchCriticalException;
|
||||
|
||||
/**
|
||||
* Batch domain interface representing the configuration of a step. As with the
|
||||
* (@link Job), step configuration is meant to explicitly represent a the
|
||||
* configuration of a step by a developer. This allows for the separation of
|
||||
* what a developer configures from the myriad of concerns required for
|
||||
* executing a job.
|
||||
* (@link Job), a {@link Step} is meant to explicitly represent a the
|
||||
* configuration of a step by a developer, but also the ability to execute the
|
||||
* step.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
@@ -30,7 +29,7 @@ import org.springframework.batch.io.exception.BatchCriticalException;
|
||||
public interface Step {
|
||||
|
||||
/**
|
||||
* @return the name of this step configuration.
|
||||
* @return the name of this step.
|
||||
*/
|
||||
String getName();
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ package org.springframework.batch.core.domain;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -52,7 +52,7 @@ public class StepInstance extends Entity {
|
||||
|
||||
private BatchStatus status;
|
||||
|
||||
private RestartData restartData = new GenericRestartData(new Properties());
|
||||
private StreamContext streamContext = new GenericStreamContext(new Properties());
|
||||
|
||||
private int stepExecutionCount = 0;
|
||||
|
||||
@@ -87,12 +87,12 @@ public class StepInstance extends Entity {
|
||||
this.stepExecutionCount = stepExecutionCount;
|
||||
}
|
||||
|
||||
public RestartData getRestartData() {
|
||||
return restartData;
|
||||
public StreamContext getRestartData() {
|
||||
return streamContext;
|
||||
}
|
||||
|
||||
public void setRestartData(RestartData restartData) {
|
||||
this.restartData = restartData;
|
||||
public void setRestartData(StreamContext streamContext) {
|
||||
this.streamContext = streamContext;
|
||||
}
|
||||
|
||||
public BatchStatus getStatus() {
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.util.Properties;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -51,7 +51,7 @@ public class StepInstanceTests extends TestCase {
|
||||
public void testGetRestartData() {
|
||||
assertNotNull(instance.getRestartData());
|
||||
assertTrue(instance.getRestartData().getProperties().isEmpty());
|
||||
instance.setRestartData(new GenericRestartData(new Properties() {{
|
||||
instance.setRestartData(new GenericStreamContext(new Properties() {{
|
||||
setProperty("foo", "bar");
|
||||
}}));
|
||||
assertEquals("bar", instance.getRestartData().getProperties().getProperty("foo"));
|
||||
|
||||
@@ -129,9 +129,8 @@ public class SimpleJob extends JobSupport {
|
||||
private boolean shouldStart(StepInstance stepInstance, Step step) {
|
||||
|
||||
if (stepInstance.getStatus() == BatchStatus.COMPLETED && step.isAllowStartIfComplete() == false) {
|
||||
// step is complete, false should be returned, indicated that the
|
||||
// step should
|
||||
// not be started
|
||||
// step is complete, false should be returned, indicating that the
|
||||
// step should not be started
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,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.restart.GenericRestartData;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -304,7 +304,7 @@ public class SimpleJobRepository implements JobRepository {
|
||||
StepInstance stepInstance = stepDao.createStep(job, step.getName());
|
||||
// Ensure valid restart data is being returned.
|
||||
if (stepInstance.getRestartData() == null || stepInstance.getRestartData().getProperties() == null) {
|
||||
stepInstance.setRestartData(new GenericRestartData(new Properties()));
|
||||
stepInstance.setRestartData(new GenericStreamContext(new Properties()));
|
||||
}
|
||||
stepInstances.add(stepInstance);
|
||||
}
|
||||
@@ -327,7 +327,7 @@ public class SimpleJobRepository implements JobRepository {
|
||||
step.setStepExecutionCount(stepDao.getStepExecutionCount(step));
|
||||
// Ensure valid restart data is being returned.
|
||||
if (step.getRestartData() == null || step.getRestartData().getProperties() == null) {
|
||||
step.setRestartData(new GenericRestartData(new Properties()));
|
||||
step.setRestartData(new GenericStreamContext(new Properties()));
|
||||
}
|
||||
stepInstances.add(step);
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ 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.repeat.ExitStatus;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.batch.support.PropertiesConverter;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
||||
@@ -161,7 +161,7 @@ public class JdbcStepDao implements StepDao, InitializingBean {
|
||||
|
||||
StepInstance step = new StepInstance(new Long(rs.getLong(1)));
|
||||
step.setStatus(BatchStatus.getStatus(rs.getString(2)));
|
||||
step.setRestartData(new GenericRestartData(PropertiesConverter.stringToProperties(rs.getString(3))));
|
||||
step.setRestartData(new GenericStreamContext(PropertiesConverter.stringToProperties(rs.getString(3))));
|
||||
return step;
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ public class JdbcStepDao implements StepDao, InitializingBean {
|
||||
StepInstance step = new StepInstance(job, rs.getString(2), new Long(rs.getLong(1)));
|
||||
String status = rs.getString(3);
|
||||
step.setStatus(BatchStatus.getStatus(status));
|
||||
step.setRestartData(new GenericRestartData(PropertiesConverter.stringToProperties(rs.getString(3))));
|
||||
step.setRestartData(new GenericStreamContext(PropertiesConverter.stringToProperties(rs.getString(3))));
|
||||
return step;
|
||||
}
|
||||
};
|
||||
@@ -422,9 +422,9 @@ public class JdbcStepDao implements StepDao, InitializingBean {
|
||||
Assert.notNull(step.getId(), "Step Id cannot be null.");
|
||||
|
||||
Properties restartProps = null;
|
||||
RestartData restartData = step.getRestartData();
|
||||
if (restartData != null) {
|
||||
restartProps = restartData.getProperties();
|
||||
StreamContext streamContext = step.getRestartData();
|
||||
if (streamContext != null) {
|
||||
restartProps = streamContext.getProperties();
|
||||
}
|
||||
|
||||
Object[] parameters = new Object[] { step.getStatus().toString(),
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.util.Set;
|
||||
import org.springframework.batch.core.domain.JobInstance;
|
||||
import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.core.domain.StepInstance;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.batch.support.transaction.TransactionAwareProxyFactory;
|
||||
|
||||
public class MapStepDao implements StepDao {
|
||||
@@ -80,8 +80,8 @@ public class MapStepDao implements StepDao {
|
||||
return new ArrayList(steps);
|
||||
}
|
||||
|
||||
public RestartData getRestartData(Long stepId) {
|
||||
return (RestartData) restartsById.get(stepId);
|
||||
public StreamContext getRestartData(Long stepId) {
|
||||
return (StreamContext) restartsById.get(stepId);
|
||||
}
|
||||
|
||||
public int getStepExecutionCount(StepInstance stepInstance) {
|
||||
@@ -99,8 +99,8 @@ public class MapStepDao implements StepDao {
|
||||
executions.add(stepExecution);
|
||||
}
|
||||
|
||||
public void saveRestartData(Long stepId, RestartData restartData) {
|
||||
restartsById.put(stepId, restartData);
|
||||
public void saveRestartData(Long stepId, StreamContext streamContext) {
|
||||
restartsById.put(stepId, streamContext);
|
||||
}
|
||||
|
||||
public List findStepExecutions(StepInstance step) {
|
||||
|
||||
@@ -43,11 +43,11 @@ import org.springframework.batch.repeat.exception.handler.SimpleLimitExceptionHa
|
||||
import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
|
||||
import org.springframework.batch.repeat.support.RepeatTemplate;
|
||||
import org.springframework.batch.repeat.synch.BatchTransactionSynchronizationManager;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.statistics.SimpleStatisticsService;
|
||||
import org.springframework.batch.statistics.StatisticsProvider;
|
||||
import org.springframework.batch.statistics.StatisticsService;
|
||||
import org.springframework.batch.stream.ItemStream;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
@@ -391,20 +391,20 @@ public class SimpleStepExecutor {
|
||||
/**
|
||||
* @param tasklet
|
||||
* @return restart data from the {@link Tasklet} if it is
|
||||
* {@link Restartable}
|
||||
* {@link ItemStream}
|
||||
*/
|
||||
private RestartData getRestartData(Tasklet tasklet) {
|
||||
if (tasklet instanceof Restartable) {
|
||||
return ((Restartable) tasklet).getRestartData();
|
||||
private StreamContext getRestartData(Tasklet tasklet) {
|
||||
if (tasklet instanceof ItemStream) {
|
||||
return ((ItemStream) tasklet).getRestartData();
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void restoreFromRestartData(Tasklet tasklet, RestartData restartData) {
|
||||
if (tasklet instanceof Restartable && restartData != null) {
|
||||
((Restartable) tasklet).restoreFrom(restartData);
|
||||
private void restoreFromRestartData(Tasklet tasklet, StreamContext streamContext) {
|
||||
if (tasklet instanceof ItemStream && streamContext != null) {
|
||||
((ItemStream) tasklet).restoreFrom(streamContext);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,39 +20,39 @@ import java.util.Properties;
|
||||
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.ItemStream;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.batch.support.PropertiesConverter;
|
||||
|
||||
/**
|
||||
* An extension of {@link ItemOrientedTasklet} that delegates calls to
|
||||
* {@link Restartable} to the reader and writer.
|
||||
* {@link ItemStream} to the reader and writer.
|
||||
*
|
||||
* @see ItemReader
|
||||
* @see ItemWriter
|
||||
* @see Restartable
|
||||
* @see ItemStream
|
||||
*
|
||||
* @author Lucas Ward
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class RestartableItemOrientedTasklet extends ItemOrientedTasklet implements Restartable {
|
||||
public class RestartableItemOrientedTasklet extends ItemOrientedTasklet implements ItemStream {
|
||||
|
||||
/**
|
||||
* @see Restartable#getRestartData()
|
||||
* @see ItemStream#getRestartData()
|
||||
*/
|
||||
public RestartData getRestartData() {
|
||||
public StreamContext getRestartData() {
|
||||
|
||||
RestartData itemProviderRestartData = null;
|
||||
RestartData itemProcessorRestartData = null;
|
||||
StreamContext itemProviderRestartData = null;
|
||||
StreamContext itemProcessorRestartData = null;
|
||||
|
||||
if (itemProvider instanceof Restartable) {
|
||||
itemProviderRestartData = ((Restartable) itemProvider).getRestartData();
|
||||
if (itemProvider instanceof ItemStream) {
|
||||
itemProviderRestartData = ((ItemStream) itemProvider).getRestartData();
|
||||
}
|
||||
|
||||
if (itemWriter instanceof Restartable) {
|
||||
itemProcessorRestartData = ((Restartable) itemWriter).getRestartData();
|
||||
if (itemWriter instanceof ItemStream) {
|
||||
itemProcessorRestartData = ((ItemStream) itemWriter).getRestartData();
|
||||
}
|
||||
|
||||
RestartableItemOrientedTaskletRestartData restartData = new RestartableItemOrientedTaskletRestartData(itemProviderRestartData, itemProcessorRestartData);
|
||||
@@ -61,9 +61,9 @@ public class RestartableItemOrientedTasklet extends ItemOrientedTasklet implemen
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Restartable#restoreFrom(RestartData)
|
||||
* @see ItemStream#restoreFrom(StreamContext)
|
||||
*/
|
||||
public void restoreFrom(RestartData data) {
|
||||
public void restoreFrom(StreamContext data) {
|
||||
if (data == null || data.getProperties() == null)
|
||||
return;
|
||||
|
||||
@@ -76,33 +76,33 @@ public class RestartableItemOrientedTasklet extends ItemOrientedTasklet implemen
|
||||
moduleRestartData = new RestartableItemOrientedTaskletRestartData(data.getProperties());
|
||||
}
|
||||
|
||||
if (itemProvider instanceof Restartable) {
|
||||
((Restartable) itemProvider).restoreFrom(moduleRestartData.readerData);
|
||||
if (itemProvider instanceof ItemStream) {
|
||||
((ItemStream) itemProvider).restoreFrom(moduleRestartData.readerData);
|
||||
}
|
||||
if (itemWriter instanceof Restartable) {
|
||||
((Restartable) itemWriter).restoreFrom(moduleRestartData.writerData);
|
||||
if (itemWriter instanceof ItemStream) {
|
||||
((ItemStream) itemWriter).restoreFrom(moduleRestartData.writerData);
|
||||
}
|
||||
}
|
||||
|
||||
private class RestartableItemOrientedTaskletRestartData implements RestartData {
|
||||
private class RestartableItemOrientedTaskletRestartData implements StreamContext {
|
||||
|
||||
private static final String READER_KEY = "DATA_PROVIDER";
|
||||
|
||||
private static final String WRITER_KEY = "DATA_PROCESSOR";
|
||||
|
||||
private RestartData readerData;
|
||||
private StreamContext readerData;
|
||||
|
||||
private RestartData writerData;
|
||||
private StreamContext writerData;
|
||||
|
||||
public RestartableItemOrientedTaskletRestartData(RestartData providerData, RestartData writerData) {
|
||||
public RestartableItemOrientedTaskletRestartData(StreamContext providerData, StreamContext writerData) {
|
||||
this.readerData = providerData;
|
||||
this.writerData = writerData;
|
||||
}
|
||||
|
||||
public RestartableItemOrientedTaskletRestartData(Properties data) {
|
||||
readerData = new GenericRestartData(PropertiesConverter
|
||||
readerData = new GenericStreamContext(PropertiesConverter
|
||||
.stringToProperties(data.getProperty(READER_KEY)));
|
||||
writerData = new GenericRestartData(PropertiesConverter.stringToProperties(data
|
||||
writerData = new GenericStreamContext(PropertiesConverter.stringToProperties(data
|
||||
.getProperty(WRITER_KEY)));
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.springframework.batch.core.domain.JobInstance;
|
||||
import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.core.domain.StepInstance;
|
||||
import org.springframework.batch.execution.repository.dao.StepDao;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
|
||||
public class MockStepDao implements StepDao {
|
||||
|
||||
@@ -46,7 +46,7 @@ public class MockStepDao implements StepDao {
|
||||
return newSteps;
|
||||
}
|
||||
|
||||
public RestartData getRestartData(Long stepId) {
|
||||
public StreamContext getRestartData(Long stepId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class MockStepDao implements StepDao {
|
||||
public void save(StepExecution stepExecution) {
|
||||
}
|
||||
|
||||
public void saveRestartData(Long stepId, RestartData restartData) {
|
||||
public void saveRestartData(Long stepId, StreamContext streamContext) {
|
||||
}
|
||||
|
||||
public void update(StepInstance step) {
|
||||
|
||||
@@ -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.restart.GenericRestartData;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
|
||||
/*
|
||||
* Test SimpleJobRepository. The majority of test cases are tested using EasyMock,
|
||||
@@ -408,7 +408,7 @@ public class SimpleJobRepositoryTests extends TestCase {
|
||||
databaseStep1.setRestartData(null);
|
||||
stepDaoControl.setReturnValue(databaseStep1);
|
||||
stepDao.createStep(databaseJob, "TestStep2");
|
||||
databaseStep2.setRestartData(new GenericRestartData(null));
|
||||
databaseStep2.setRestartData(new GenericStreamContext(null));
|
||||
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.setRestartData(new GenericRestartData(null));
|
||||
databaseStep2.setRestartData(new GenericStreamContext(null));
|
||||
stepDaoControl.setReturnValue(databaseStep2);
|
||||
stepDao.getStepExecutionCount(databaseStep2);
|
||||
stepDaoControl.setReturnValue(1);
|
||||
|
||||
@@ -30,8 +30,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.repeat.ExitStatus;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.dao.OptimisticLockingFailureException;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
import org.springframework.util.ClassUtils;
|
||||
@@ -152,13 +152,13 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour
|
||||
step1.setStatus(BatchStatus.COMPLETED);
|
||||
Properties data = new Properties();
|
||||
data.setProperty("restart.key1", "restartData");
|
||||
RestartData restartData = new GenericRestartData(data);
|
||||
step1.setRestartData(restartData);
|
||||
StreamContext streamContext = new GenericStreamContext(data);
|
||||
step1.setRestartData(streamContext);
|
||||
stepDao.update(step1);
|
||||
StepInstance tempStep = stepDao.findStep(jobInstance, step1.getName());
|
||||
assertEquals(tempStep, step1);
|
||||
assertEquals(tempStep.getRestartData().getProperties().toString(),
|
||||
restartData.getProperties().toString());
|
||||
streamContext.getProperties().toString());
|
||||
}
|
||||
|
||||
public void testSaveStepExecution(){
|
||||
|
||||
@@ -27,8 +27,8 @@ 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.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
|
||||
public class MapStepDaoTests extends TestCase {
|
||||
|
||||
@@ -111,13 +111,13 @@ public class MapStepDaoTests extends TestCase {
|
||||
step.setStatus(BatchStatus.COMPLETED);
|
||||
Properties data = new Properties();
|
||||
data.setProperty("restart.key1", "restartData");
|
||||
RestartData restartData = new GenericRestartData(data);
|
||||
step.setRestartData(restartData);
|
||||
StreamContext streamContext = new GenericStreamContext(data);
|
||||
step.setRestartData(streamContext);
|
||||
dao.update(step);
|
||||
StepInstance tempStep = dao.findStep(job, step.getName());
|
||||
assertEquals(tempStep, step);
|
||||
assertEquals(tempStep.getRestartData().getProperties().toString(),
|
||||
restartData.getProperties().toString());
|
||||
streamContext.getProperties().toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -50,10 +50,10 @@ import org.springframework.batch.repeat.exception.handler.ExceptionHandler;
|
||||
import org.springframework.batch.repeat.interceptor.RepeatInterceptorAdapter;
|
||||
import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
|
||||
import org.springframework.batch.repeat.support.RepeatTemplate;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.statistics.StatisticsProvider;
|
||||
import org.springframework.batch.statistics.StatisticsService;
|
||||
import org.springframework.batch.stream.ItemStream;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.batch.support.PropertiesConverter;
|
||||
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
|
||||
|
||||
@@ -455,7 +455,7 @@ public class SimpleStepExecutorTests extends TestCase {
|
||||
assertEquals(0, map.size());
|
||||
}
|
||||
|
||||
private class MockRestartableTasklet implements Tasklet, Restartable {
|
||||
private class MockRestartableTasklet implements Tasklet, ItemStream {
|
||||
|
||||
private boolean getRestartDataCalled = false;
|
||||
|
||||
@@ -465,12 +465,12 @@ public class SimpleStepExecutorTests extends TestCase {
|
||||
return ExitStatus.FINISHED;
|
||||
}
|
||||
|
||||
public RestartData getRestartData() {
|
||||
public StreamContext getRestartData() {
|
||||
getRestartDataCalled = true;
|
||||
return null;
|
||||
}
|
||||
|
||||
public void restoreFrom(RestartData data) {
|
||||
public void restoreFrom(StreamContext data) {
|
||||
restoreFromCalled = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,9 +22,9 @@ import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.ItemStream;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.batch.support.PropertiesConverter;
|
||||
|
||||
/**
|
||||
@@ -32,9 +32,9 @@ import org.springframework.batch.support.PropertiesConverter;
|
||||
*/
|
||||
public class RestartableItemOrientedTaskletTests extends TestCase {
|
||||
|
||||
private static class MockProvider implements ItemReader, Restartable {
|
||||
private static class MockProvider implements ItemReader, ItemStream {
|
||||
|
||||
RestartData data = new RestartData() {
|
||||
StreamContext data = new StreamContext() {
|
||||
|
||||
public Properties getProperties() {
|
||||
return PropertiesConverter.stringToProperties("a=b");
|
||||
@@ -46,11 +46,11 @@ public class RestartableItemOrientedTaskletTests extends TestCase {
|
||||
return null;
|
||||
}
|
||||
|
||||
public RestartData getRestartData() {
|
||||
public StreamContext getRestartData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void restoreFrom(RestartData data) {
|
||||
public void restoreFrom(StreamContext data) {
|
||||
// restart data should be same as returned by getRestartData
|
||||
assertEquals(this.data.getProperties(), data.getProperties());
|
||||
}
|
||||
@@ -64,9 +64,9 @@ public class RestartableItemOrientedTaskletTests extends TestCase {
|
||||
|
||||
}
|
||||
|
||||
private static class MockWriter implements ItemWriter, Restartable {
|
||||
private static class MockWriter implements ItemWriter, ItemStream {
|
||||
|
||||
RestartData data = new RestartData() {
|
||||
StreamContext data = new StreamContext() {
|
||||
public Properties getProperties() {
|
||||
return PropertiesConverter.stringToProperties("x=y");
|
||||
}
|
||||
@@ -75,11 +75,11 @@ public class RestartableItemOrientedTaskletTests extends TestCase {
|
||||
public void write(Object data) {
|
||||
}
|
||||
|
||||
public RestartData getRestartData() {
|
||||
public StreamContext getRestartData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void restoreFrom(RestartData data) {
|
||||
public void restoreFrom(StreamContext data) {
|
||||
// restart data should be same as returned by getRestartData
|
||||
assertEquals(this.data.getProperties(), data.getProperties());
|
||||
}
|
||||
@@ -107,7 +107,7 @@ public class RestartableItemOrientedTaskletTests extends TestCase {
|
||||
module.setItemWriter(itemWriter);
|
||||
|
||||
// get restart data
|
||||
RestartData data = module.getRestartData();
|
||||
StreamContext data = module.getRestartData();
|
||||
assertNotNull(data);
|
||||
// restore from restart data (see asserts in mock classes)
|
||||
module.restoreFrom(data);
|
||||
@@ -125,9 +125,9 @@ public class RestartableItemOrientedTaskletTests extends TestCase {
|
||||
module.setItemWriter(itemWriter);
|
||||
|
||||
// get restart data
|
||||
RestartData data = module.getRestartData();
|
||||
StreamContext data = module.getRestartData();
|
||||
assertNotNull(data);
|
||||
data = new GenericRestartData(data.getProperties());
|
||||
data = new GenericStreamContext(data.getProperties());
|
||||
// restore from restart data (see asserts in mock classes)
|
||||
module.restoreFrom(data);
|
||||
}
|
||||
@@ -140,7 +140,7 @@ public class RestartableItemOrientedTaskletTests extends TestCase {
|
||||
module.setItemWriter(null);
|
||||
|
||||
// get restart data
|
||||
RestartData data = module.getRestartData();
|
||||
StreamContext data = module.getRestartData();
|
||||
assertNotNull(data);
|
||||
// restore from restart data (see asserts in mock classes)
|
||||
module.restoreFrom(data);
|
||||
|
||||
@@ -28,9 +28,9 @@ import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ResourceLifecycle;
|
||||
import org.springframework.batch.item.reader.AbstractItemReader;
|
||||
import org.springframework.batch.repeat.synch.BatchTransactionSynchronizationManager;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.ItemStream;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.transaction.support.TransactionSynchronization;
|
||||
@@ -57,7 +57,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Robert Kasanicky
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class HibernateCursorItemReader extends AbstractItemReader implements ItemReader, Restartable,
|
||||
public class HibernateCursorItemReader extends AbstractItemReader implements ItemReader, ItemStream,
|
||||
Skippable, InitializingBean, DisposableBean, ResourceLifecycle {
|
||||
|
||||
private static final String RESTART_DATA_ROW_NUMBER_KEY = ClassUtils
|
||||
@@ -187,20 +187,20 @@ public class HibernateCursorItemReader extends AbstractItemReader implements Ite
|
||||
/**
|
||||
* @return the current row number wrapped as <code>RestartData</code>
|
||||
*/
|
||||
public RestartData getRestartData() {
|
||||
public StreamContext getRestartData() {
|
||||
Properties props = new Properties();
|
||||
props.setProperty(RESTART_DATA_ROW_NUMBER_KEY, ""+currentProcessedRow);
|
||||
String skipped = skippedRows.toString();
|
||||
props.setProperty(SKIPPED_ROWS, skipped.substring(1,
|
||||
skipped.length() - 1));
|
||||
|
||||
return new GenericRestartData(props);
|
||||
return new GenericStreamContext(props);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the cursor to the received row number.
|
||||
*/
|
||||
public void restoreFrom(RestartData data) {
|
||||
public void restoreFrom(StreamContext data) {
|
||||
Assert
|
||||
.state(!initialized,
|
||||
"Cannot restore when already intialized. Call close() first before restore()");
|
||||
|
||||
@@ -33,10 +33,10 @@ import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.io.support.AbstractTransactionalIoSource;
|
||||
import org.springframework.batch.item.KeyedItemReader;
|
||||
import org.springframework.batch.item.ResourceLifecycle;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.statistics.StatisticsProvider;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.ItemStream;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
@@ -118,7 +118,7 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public class JdbcCursorItemReader extends AbstractTransactionalIoSource
|
||||
implements KeyedItemReader, ResourceLifecycle, DisposableBean,
|
||||
InitializingBean, Restartable, StatisticsProvider, Skippable {
|
||||
InitializingBean, ItemStream, StatisticsProvider, Skippable {
|
||||
|
||||
private static Log log = LogFactory.getLog(JdbcCursorItemReader.class);
|
||||
|
||||
@@ -406,11 +406,11 @@ public class JdbcCursorItemReader extends AbstractTransactionalIoSource
|
||||
*
|
||||
* @see org.springframework.batch.restart.Restartable#getRestartData()
|
||||
*/
|
||||
public RestartData getRestartData() {
|
||||
public StreamContext getRestartData() {
|
||||
String skipped = skippedRows.toString();
|
||||
Properties statistics = getStatistics();
|
||||
statistics.setProperty(SKIPPED_ROWS, skipped.substring(1,skipped.length()-1));
|
||||
return new GenericRestartData(statistics);
|
||||
return new GenericStreamContext(statistics);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -418,7 +418,7 @@ public class JdbcCursorItemReader extends AbstractTransactionalIoSource
|
||||
*
|
||||
* @see org.springframework.batch.restart.Restartable#restoreFrom(org.springframework.batch.restart.RestartData)
|
||||
*/
|
||||
public void restoreFrom(RestartData data) {
|
||||
public void restoreFrom(StreamContext data) {
|
||||
Assert.state(!initialized);
|
||||
|
||||
if (data == null)
|
||||
|
||||
@@ -22,8 +22,8 @@ import org.springframework.batch.io.support.AbstractTransactionalIoSource;
|
||||
import org.springframework.batch.item.KeyedItemReader;
|
||||
import org.springframework.batch.item.ResourceLifecycle;
|
||||
import org.springframework.batch.repeat.synch.BatchTransactionSynchronizationManager;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.stream.ItemStream;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -52,7 +52,7 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public class DrivingQueryItemReader extends AbstractTransactionalIoSource
|
||||
implements KeyedItemReader, ResourceLifecycle, InitializingBean,
|
||||
DisposableBean, Restartable {
|
||||
DisposableBean, ItemStream {
|
||||
|
||||
private boolean initialized = false;
|
||||
|
||||
@@ -171,7 +171,7 @@ public class DrivingQueryItemReader extends AbstractTransactionalIoSource
|
||||
* @throws IllegalStateException
|
||||
* if the input source has already been initialized.
|
||||
*/
|
||||
public final void restoreFrom(RestartData data) {
|
||||
public final void restoreFrom(StreamContext data) {
|
||||
|
||||
Assert.notNull(data, "RestartData must not be null.");
|
||||
Assert.notNull(data.getProperties(),
|
||||
@@ -192,7 +192,7 @@ public class DrivingQueryItemReader extends AbstractTransactionalIoSource
|
||||
}
|
||||
}
|
||||
|
||||
public RestartData getRestartData() {
|
||||
public StreamContext getRestartData() {
|
||||
return keyGenerator.getKeyAsRestartData(getCurrentKey());
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.springframework.batch.io.driving;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
|
||||
/**
|
||||
* 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 restartData is null.
|
||||
*/
|
||||
List restoreKeys(RestartData restartData);
|
||||
List restoreKeys(StreamContext 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.
|
||||
*/
|
||||
RestartData getKeyAsRestartData(Object key);
|
||||
StreamContext getKeyAsRestartData(Object key);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.core.CollectionFactory;
|
||||
import org.springframework.jdbc.core.ColumnMapRowMapper;
|
||||
import org.springframework.jdbc.core.PreparedStatementSetter;
|
||||
@@ -38,9 +38,9 @@ public class ColumnMapRestartDataRowMapper extends ColumnMapRowMapper implements
|
||||
|
||||
static final String KEY = ClassUtils.getQualifiedName(ColumnMapRestartDataRowMapper.class) + ".KEY.";
|
||||
|
||||
public PreparedStatementSetter createSetter(RestartData restartData) {
|
||||
public PreparedStatementSetter createSetter(StreamContext streamContext) {
|
||||
|
||||
ColumnMapRestartData columnData = new ColumnMapRestartData(restartData.getProperties());
|
||||
ColumnMapRestartData columnData = new ColumnMapRestartData(streamContext.getProperties());
|
||||
|
||||
List columns = new ArrayList();
|
||||
for (Iterator iterator = columnData.keys.values().iterator(); iterator.hasNext();) {
|
||||
@@ -51,7 +51,7 @@ public class ColumnMapRestartDataRowMapper extends ColumnMapRowMapper implements
|
||||
return new ArgPreparedStatementSetter(columns.toArray());
|
||||
}
|
||||
|
||||
public RestartData createRestartData(Object key) {
|
||||
public StreamContext createRestartData(Object key) {
|
||||
|
||||
Assert.isInstanceOf(Map.class, key, "Key must be of type Map.");
|
||||
Map keys = (Map)key;
|
||||
@@ -60,7 +60,7 @@ public class ColumnMapRestartDataRowMapper extends ColumnMapRowMapper implements
|
||||
}
|
||||
|
||||
|
||||
private static class ColumnMapRestartData implements RestartData{
|
||||
private static class ColumnMapRestartData implements StreamContext{
|
||||
|
||||
private final Map keys;
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ import java.util.Properties;
|
||||
|
||||
import org.springframework.batch.io.driving.DrivingQueryItemReader;
|
||||
import org.springframework.batch.io.driving.KeyGenerator;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.orm.ibatis.SqlMapClientTemplate;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -44,19 +44,19 @@ public class IbatisKeyGenerator implements KeyGenerator {
|
||||
*
|
||||
* @see org.springframework.batch.restart.Restartable#getRestartData()
|
||||
*/
|
||||
public RestartData getKeyAsRestartData(Object key) {
|
||||
public StreamContext getKeyAsRestartData(Object key) {
|
||||
Properties props = new Properties();
|
||||
props.setProperty(RESTART_KEY, key.toString());
|
||||
|
||||
return new GenericRestartData(props);
|
||||
return new GenericStreamContext(props);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore the keys list given the provided restart data.
|
||||
*
|
||||
* @see org.springframework.batch.io.driving.DrivingQueryItemReader#restoreKeys(org.springframework.batch.restart.RestartData)
|
||||
* @see org.springframework.batch.io.driving.DrivingQueryItemReader#restoreKeys(org.springframework.batch.stream.StreamContext)
|
||||
*/
|
||||
public List restoreKeys(RestartData data) {
|
||||
public List restoreKeys(StreamContext data) {
|
||||
|
||||
Properties props = data.getProperties();
|
||||
Object key = props.getProperty(RESTART_KEY);
|
||||
|
||||
@@ -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.restart.RestartData;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -80,14 +80,14 @@ public class MultipleColumnJdbcKeyGenerator implements
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.io.sql.scratch.AbstractDrivingQueryItemReader#restoreKeys(org.springframework.batch.restart.RestartData)
|
||||
*/
|
||||
public List restoreKeys(RestartData restartData) {
|
||||
public List restoreKeys(StreamContext streamContext) {
|
||||
|
||||
Assert.state(keyMapper != null, "KeyMapper must not be null.");
|
||||
Assert.state(StringUtils.hasText(restartSql), "The RestartQuery must not be null or empty" +
|
||||
" in order to restart.");
|
||||
|
||||
if (restartData.getProperties() != null) {
|
||||
return jdbcTemplate.query(restartSql, keyMapper.createSetter(restartData), keyMapper);
|
||||
if (streamContext.getProperties() != null) {
|
||||
return jdbcTemplate.query(restartSql, keyMapper.createSetter(streamContext), keyMapper);
|
||||
}
|
||||
|
||||
return new ArrayList();
|
||||
@@ -96,7 +96,7 @@ public class MultipleColumnJdbcKeyGenerator implements
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.restart.Restartable#getRestartData()
|
||||
*/
|
||||
public RestartData getKeyAsRestartData(Object key) {
|
||||
public StreamContext getKeyAsRestartData(Object key) {
|
||||
Assert.state(keyMapper != null, "RestartDataConverter must not be null.");
|
||||
return keyMapper.createRestartData(key);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.batch.io.driving.support;
|
||||
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.jdbc.core.PreparedStatementSetter;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
|
||||
@@ -40,14 +40,14 @@ public interface RestartDataRowMapper extends RowMapper {
|
||||
* @return ResartData representing the composite key.
|
||||
* @throws IllegalArgumentException if key is null or of an unsupported type.
|
||||
*/
|
||||
public RestartData createRestartData(Object key);
|
||||
public StreamContext createRestartData(Object key);
|
||||
|
||||
/**
|
||||
* Given the provided restart data, return a PreparedStatementSeter that can
|
||||
* be used as parameters to a JdbcTemplate.
|
||||
*
|
||||
* @param restartData
|
||||
* @param streamContext
|
||||
* @return an array of objects that can be used as arguments to a JdbcTemplate.
|
||||
*/
|
||||
public PreparedStatementSetter createSetter(RestartData restartData);
|
||||
public PreparedStatementSetter createSetter(StreamContext streamContext);
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ import java.util.Properties;
|
||||
|
||||
import org.apache.commons.lang.ClassUtils;
|
||||
import org.springframework.batch.io.driving.KeyGenerator;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.SingleColumnRowMapper;
|
||||
@@ -94,34 +94,34 @@ public class SingleColumnJdbcKeyGenerator implements KeyGenerator {
|
||||
* @see KeyGenerator#getKeyAsRestartData()
|
||||
* @throws IllegalArgumentException if key is null.
|
||||
*/
|
||||
public RestartData getKeyAsRestartData(Object key) {
|
||||
public StreamContext getKeyAsRestartData(Object key) {
|
||||
|
||||
Assert.notNull(key, "The key must not be null.");
|
||||
|
||||
Properties props = new Properties();
|
||||
props.setProperty(RESTART_KEY, key.toString());
|
||||
return new GenericRestartData(props);
|
||||
return new GenericStreamContext(props);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the remaining to be processed for the provided {@link RestartData}.
|
||||
* Return the remaining to be processed for the provided {@link StreamContext}.
|
||||
* The RestartData attempting to be restored from must have been obtained from the
|
||||
* <strong>same KeyGenerationStrategy as the one
|
||||
* being restored from</strong> otherwise it is invalid.
|
||||
*
|
||||
* @param RestartData obtained by calling getRestartData during a previous
|
||||
* @param StreamContext obtained by calling getRestartData 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.restart.RestartData)
|
||||
* @see KeyGenerator#restoreKeys(org.springframework.batch.stream.StreamContext)
|
||||
*/
|
||||
public List restoreKeys(RestartData restartData) {
|
||||
public List restoreKeys(StreamContext streamContext) {
|
||||
|
||||
Assert.notNull(restartData, "The restart data must not be null.");
|
||||
Assert.notNull(streamContext, "The restart data must not be null.");
|
||||
Assert.state(StringUtils.hasText(restartSql), "The RestartQuery must not be null or empty" +
|
||||
" in order to restart.");
|
||||
|
||||
String lastProcessedKey = restartData.getProperties().getProperty(RESTART_KEY);
|
||||
String lastProcessedKey = streamContext.getProperties().getProperty(RESTART_KEY);
|
||||
|
||||
if (lastProcessedKey != null) {
|
||||
return jdbcTemplate.query(restartSql, new Object[] { lastProcessedKey }, keyMapper);
|
||||
|
||||
@@ -25,10 +25,10 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.io.file.separator.LineReader;
|
||||
import org.springframework.batch.repeat.synch.BatchTransactionSynchronizationManager;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.statistics.StatisticsProvider;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.ItemStream;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.transaction.support.TransactionSynchronization;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationAdapter;
|
||||
|
||||
@@ -42,7 +42,7 @@ import org.springframework.transaction.support.TransactionSynchronizationAdapter
|
||||
* @author Tomas Slanina
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class DefaultFlatFileItemReader extends SimpleFlatFileItemReader implements Skippable, Restartable,
|
||||
public class DefaultFlatFileItemReader extends SimpleFlatFileItemReader implements Skippable, ItemStream,
|
||||
StatisticsProvider {
|
||||
|
||||
private static Log log = LogFactory.getLog(DefaultFlatFileItemReader.class);
|
||||
@@ -77,7 +77,7 @@ public class DefaultFlatFileItemReader extends SimpleFlatFileItemReader implemen
|
||||
*
|
||||
* @param restartData restartData information
|
||||
*/
|
||||
public void restoreFrom(RestartData data) {
|
||||
public void restoreFrom(StreamContext data) {
|
||||
|
||||
if (data==null ||
|
||||
data.getProperties() == null ||
|
||||
@@ -104,8 +104,8 @@ public class DefaultFlatFileItemReader extends SimpleFlatFileItemReader implemen
|
||||
* current Line Count which can be used to re initialise the batch job in
|
||||
* case of restart.
|
||||
*/
|
||||
public RestartData getRestartData() {
|
||||
return new GenericRestartData(getStatistics());
|
||||
public StreamContext getRestartData() {
|
||||
return new GenericStreamContext(getStatistics());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -34,10 +34,10 @@ import org.springframework.batch.io.support.AbstractTransactionalIoSource;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.ResourceLifecycle;
|
||||
import org.springframework.batch.item.writer.ItemTransformer;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.statistics.StatisticsProvider;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.ItemStream;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -61,7 +61,7 @@ import org.springframework.util.Assert;
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class FlatFileItemWriter extends AbstractTransactionalIoSource implements
|
||||
ItemWriter, ResourceLifecycle, Restartable, StatisticsProvider, InitializingBean,
|
||||
ItemWriter, ResourceLifecycle, ItemStream, StatisticsProvider, InitializingBean,
|
||||
DisposableBean {
|
||||
|
||||
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
|
||||
@@ -76,7 +76,7 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements
|
||||
|
||||
private Properties statistics = new Properties();
|
||||
|
||||
private RestartData restartData = new GenericRestartData(new Properties());
|
||||
private StreamContext streamContext = new GenericStreamContext(new Properties());
|
||||
|
||||
private OutputState state = new OutputState();
|
||||
|
||||
@@ -258,19 +258,19 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Restartable#getRestartData()
|
||||
* @see ItemStream#getRestartData()
|
||||
*/
|
||||
public RestartData getRestartData() {
|
||||
public StreamContext getRestartData() {
|
||||
final OutputState os = getOutputState();
|
||||
|
||||
restartData.getProperties().setProperty(RESTART_DATA_NAME, String.valueOf(os.position()));
|
||||
return restartData;
|
||||
streamContext.getProperties().setProperty(RESTART_DATA_NAME, String.valueOf(os.position()));
|
||||
return streamContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Restartable#restoreFrom(RestartData)
|
||||
* @see ItemStream#restoreFrom(StreamContext)
|
||||
*/
|
||||
public void restoreFrom(RestartData data) {
|
||||
public void restoreFrom(StreamContext data) {
|
||||
if (data == null)
|
||||
return;
|
||||
|
||||
|
||||
@@ -21,10 +21,10 @@ import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ResourceLifecycle;
|
||||
import org.springframework.batch.item.reader.AbstractItemReader;
|
||||
import org.springframework.batch.repeat.synch.BatchTransactionSynchronizationManager;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.statistics.StatisticsProvider;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.ItemStream;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -44,7 +44,7 @@ import org.springframework.util.Assert;
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class StaxEventItemReader extends AbstractItemReader implements ItemReader, ResourceLifecycle,
|
||||
Skippable, Restartable, StatisticsProvider, InitializingBean, DisposableBean {
|
||||
Skippable, ItemStream, StatisticsProvider, InitializingBean, DisposableBean {
|
||||
|
||||
public static final String READ_COUNT_STATISTICS_NAME = "StaxEventReaderItemReader.readCount";
|
||||
|
||||
@@ -192,26 +192,26 @@ public class StaxEventItemReader extends AbstractItemReader implements ItemReade
|
||||
|
||||
/**
|
||||
* @return wrapped count of records read so far.
|
||||
* @see Restartable#getRestartData()
|
||||
* @see ItemStream#getRestartData()
|
||||
*/
|
||||
public RestartData getRestartData() {
|
||||
public StreamContext getRestartData() {
|
||||
Properties restartData = new Properties();
|
||||
|
||||
restartData.setProperty(RESTART_DATA_NAME, String.valueOf(currentRecordCount));
|
||||
|
||||
return new GenericRestartData(restartData);
|
||||
return new GenericStreamContext(restartData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores the input source for the given restart data by rereading and
|
||||
* skipping the number of records stored in the RestartData.
|
||||
*
|
||||
* @param RestartData that holds the line count from the last commit.
|
||||
* @param StreamContext 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(RestartData data) {
|
||||
public void restoreFrom(StreamContext data) {
|
||||
Assert.state(!initialized);
|
||||
if (data == null || data.getProperties() == null || data.getProperties().getProperty(RESTART_DATA_NAME) == null) {
|
||||
return;
|
||||
|
||||
@@ -19,10 +19,10 @@ import org.springframework.batch.io.xml.stax.NoStartEndDocumentStreamWriter;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.ResourceLifecycle;
|
||||
import org.springframework.batch.repeat.synch.BatchTransactionSynchronizationManager;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.statistics.StatisticsProvider;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.ItemStream;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -42,7 +42,7 @@ import org.springframework.util.CollectionUtils;
|
||||
* @author Peter Zozom
|
||||
*
|
||||
*/
|
||||
public class StaxEventItemWriter implements ItemWriter, ResourceLifecycle, Restartable,
|
||||
public class StaxEventItemWriter implements ItemWriter, ResourceLifecycle, ItemStream,
|
||||
StatisticsProvider, InitializingBean, DisposableBean {
|
||||
|
||||
// default encoding
|
||||
@@ -380,23 +380,23 @@ public class StaxEventItemWriter implements ItemWriter, ResourceLifecycle, Resta
|
||||
/**
|
||||
* Get the restart data.
|
||||
* @return the restart data
|
||||
* @see org.springframework.batch.restart.Restartable#getRestartData()
|
||||
* @see org.springframework.batch.stream.ItemStream#getRestartData()
|
||||
*/
|
||||
public RestartData getRestartData() {
|
||||
public StreamContext getRestartData() {
|
||||
|
||||
Properties properties = new Properties();
|
||||
|
||||
properties.setProperty(RESTART_DATA_NAME, String.valueOf(getPosition()));
|
||||
|
||||
return new GenericRestartData(properties);
|
||||
return new GenericStreamContext(properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore processing from provided restart data.
|
||||
* @param data the restart data
|
||||
* @see org.springframework.batch.restart.Restartable#restoreFrom(org.springframework.batch.restart.RestartData)
|
||||
* @see org.springframework.batch.stream.ItemStream#restoreFrom(org.springframework.batch.stream.StreamContext)
|
||||
*/
|
||||
public void restoreFrom(RestartData data) {
|
||||
public void restoreFrom(StreamContext data) {
|
||||
|
||||
long startAtPosition = 0;
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ package org.springframework.batch.item.reader;
|
||||
|
||||
import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.stream.ItemStream;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class DelegatingItemReader extends AbstractItemReader implements Restartable, Skippable, InitializingBean{
|
||||
public class DelegatingItemReader extends AbstractItemReader implements ItemStream, Skippable, InitializingBean{
|
||||
|
||||
private ItemReader inputSource;
|
||||
|
||||
@@ -47,27 +47,27 @@ public class DelegatingItemReader extends AbstractItemReader implements Restarta
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Restartable#getRestartData()
|
||||
* @see ItemStream#getRestartData()
|
||||
* @throws IllegalStateException if the parent template is not itself
|
||||
* {@link Restartable}.
|
||||
* {@link ItemStream}.
|
||||
*/
|
||||
public RestartData getRestartData() {
|
||||
if (!(inputSource instanceof Restartable)) {
|
||||
public StreamContext getRestartData() {
|
||||
if (!(inputSource instanceof ItemStream)) {
|
||||
throw new IllegalStateException("Input Template is not Restartable");
|
||||
}
|
||||
return ((Restartable) inputSource).getRestartData();
|
||||
return ((ItemStream) inputSource).getRestartData();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Restartable#restoreFrom(RestartData)
|
||||
* @see ItemStream#restoreFrom(StreamContext)
|
||||
* @throws IllegalStateException if the parent template is not itself
|
||||
* {@link Restartable}.
|
||||
* {@link ItemStream}.
|
||||
*/
|
||||
public void restoreFrom(RestartData data) {
|
||||
if (!(inputSource instanceof Restartable)) {
|
||||
public void restoreFrom(StreamContext data) {
|
||||
if (!(inputSource instanceof ItemStream)) {
|
||||
throw new IllegalStateException("Input Template is not Restartable");
|
||||
}
|
||||
((Restartable) inputSource).restoreFrom(data);
|
||||
((ItemStream) inputSource).restoreFrom(data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,16 +8,16 @@ import java.util.Properties;
|
||||
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.ItemStream;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
|
||||
/**
|
||||
* Runs a collection of ItemProcessors in fixed-order sequence.
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class CompositeItemWriter implements ItemWriter, Restartable {
|
||||
public class CompositeItemWriter implements ItemWriter, ItemStream {
|
||||
|
||||
private static final String SEPARATOR = "#";
|
||||
|
||||
@@ -36,25 +36,25 @@ public class CompositeItemWriter implements ItemWriter, Restartable {
|
||||
* Compound restart data of all injected (Restartable) ItemProcessors,
|
||||
* property keys are prefixed with list index of the ItemProcessor.
|
||||
*/
|
||||
public RestartData getRestartData() {
|
||||
public StreamContext getRestartData() {
|
||||
Properties props = createCompoundProperties(new PropertiesExtractor() {
|
||||
public Properties extractProperties(Object o) {
|
||||
if (o instanceof Restartable) {
|
||||
return ((Restartable) o).getRestartData().getProperties();
|
||||
if (o instanceof ItemStream) {
|
||||
return ((ItemStream) o).getRestartData().getProperties();
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
});
|
||||
return new GenericRestartData(props);
|
||||
return new GenericStreamContext(props);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param data contains values of restart data, property keys are expected
|
||||
* to be prefixed with list index of the ItemProcessor.
|
||||
*/
|
||||
public void restoreFrom(RestartData data) {
|
||||
public void restoreFrom(StreamContext data) {
|
||||
if (data == null || data.getProperties() == null) {
|
||||
// do nothing
|
||||
return;
|
||||
@@ -64,8 +64,8 @@ public class CompositeItemWriter implements ItemWriter, Restartable {
|
||||
|
||||
// iterators would make the loop below less readable
|
||||
for (int i = 0; i < delegates.size(); i++) {
|
||||
if (delegates.get(i) instanceof Restartable) {
|
||||
((Restartable) delegates.get(i)).restoreFrom((RestartData) restartDataList.get(i));
|
||||
if (delegates.get(i) instanceof ItemStream) {
|
||||
((ItemStream) delegates.get(i)).restoreFrom((StreamContext) restartDataList.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public class CompositeItemWriter implements ItemWriter, Restartable {
|
||||
private List parseProperties(Properties props) {
|
||||
List restartDataList = new ArrayList(delegates.size());
|
||||
for (int i = 0; i < delegates.size(); i++) {
|
||||
restartDataList.add(new GenericRestartData(new Properties()));
|
||||
restartDataList.add(new GenericStreamContext(new Properties()));
|
||||
}
|
||||
|
||||
for (Iterator iterator = props.entrySet().iterator(); iterator.hasNext();) {
|
||||
@@ -90,7 +90,7 @@ public class CompositeItemWriter implements ItemWriter, Restartable {
|
||||
String value = (String) entry.getValue();
|
||||
int separatorIndex = key.indexOf(SEPARATOR);
|
||||
int i = Integer.valueOf(key.substring(0, separatorIndex)).intValue();
|
||||
((RestartData) restartDataList.get(i)).getProperties()
|
||||
((StreamContext) restartDataList.get(i)).getProperties()
|
||||
.setProperty(key.substring(separatorIndex + 1), value);
|
||||
}
|
||||
return restartDataList;
|
||||
|
||||
@@ -4,20 +4,20 @@ import java.util.Properties;
|
||||
|
||||
import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.ItemStream;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Simple wrapper around {@link ItemWriter} providing {@link Restartable} where
|
||||
* Simple wrapper around {@link ItemWriter} providing {@link ItemStream} where
|
||||
* the {@link ItemWriter} does. To make sure
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class DelegatingItemWriter implements ItemWriter, Restartable, Skippable, InitializingBean {
|
||||
public class DelegatingItemWriter implements ItemWriter, ItemStream, Skippable, InitializingBean {
|
||||
|
||||
private ItemWriter writer;
|
||||
|
||||
@@ -50,29 +50,29 @@ public class DelegatingItemWriter implements ItemWriter, Restartable, Skippable,
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Restartable#getRestartData()
|
||||
* @see ItemStream#getRestartData()
|
||||
*/
|
||||
public RestartData getRestartData() {
|
||||
public StreamContext getRestartData() {
|
||||
|
||||
Assert.state(writer != null, "Source must not be null.");
|
||||
|
||||
if (writer instanceof Restartable) {
|
||||
return ((Restartable) writer).getRestartData();
|
||||
if (writer instanceof ItemStream) {
|
||||
return ((ItemStream) writer).getRestartData();
|
||||
}
|
||||
else {
|
||||
return new GenericRestartData(new Properties());
|
||||
return new GenericStreamContext(new Properties());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Restartable#restoreFrom(RestartData)
|
||||
* @see ItemStream#restoreFrom(StreamContext)
|
||||
*/
|
||||
public void restoreFrom(RestartData data) {
|
||||
public void restoreFrom(StreamContext data) {
|
||||
|
||||
Assert.state(writer != null, "Source must not be null.");
|
||||
|
||||
if (writer instanceof Restartable) {
|
||||
((Restartable) writer).restoreFrom(data);
|
||||
if (writer instanceof ItemStream) {
|
||||
((ItemStream) writer).restoreFrom(data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,56 +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.restart;
|
||||
|
||||
/**
|
||||
* <p>Marker interface defining a contract for periodically storing
|
||||
* state and restoring from that state should an error occur.
|
||||
* <p>
|
||||
*
|
||||
* <p>The state that is stored is represented as {@link RestartData}
|
||||
* which enforces a requirement that any restart data can be represented
|
||||
* by a Properties object. In general, the contract is that RestartData
|
||||
* that is returned via the getRestartData method will be given back to
|
||||
* the restoreFrom method, exactly as it was provided. However, since
|
||||
* it is primarily stored in a database, there is almost no way to know
|
||||
* the whether a blank column in the database refers to null data,
|
||||
* null properties, or empty properties. Therefore, any class implementing
|
||||
* this interface should assume that no restart data is equivalent to
|
||||
* data with empty Properties.
|
||||
* </p>
|
||||
*
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public interface Restartable {
|
||||
|
||||
/**
|
||||
* Get RestartData representing this object's current state. Ideally,
|
||||
* if no state should be stored, RestartData.getProperties should return
|
||||
* an empty Properties object.
|
||||
*
|
||||
* @return RestartData representing current state.
|
||||
*/
|
||||
RestartData getRestartData();
|
||||
|
||||
/**
|
||||
* Restart state given the provided RestartData.
|
||||
*
|
||||
* @param data
|
||||
*/
|
||||
void restoreFrom(RestartData data);
|
||||
}
|
||||
@@ -14,15 +14,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.restart;
|
||||
package org.springframework.batch.stream;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
public class GenericRestartData implements RestartData {
|
||||
public class GenericStreamContext implements StreamContext {
|
||||
|
||||
private Properties data;
|
||||
|
||||
public GenericRestartData(Properties data){
|
||||
public GenericStreamContext(Properties data){
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.stream;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Marker interface defining a contract for periodically storing state and
|
||||
* restoring from that state should an error occur.
|
||||
* <p>
|
||||
*
|
||||
* <p>
|
||||
* The state that is stored is represented as {@link StreamContext} which
|
||||
* enforces a requirement that any restart data can be represented by a
|
||||
* Properties object. In general, the contract is that {@link StreamContext}
|
||||
* that is returned via the {@link #getRestartData()} method will be given back
|
||||
* to the {@link #restoreFrom(StreamContext)} method, exactly as it was
|
||||
* provided.
|
||||
* </p>
|
||||
*
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public interface ItemStream {
|
||||
|
||||
/**
|
||||
* Get {@link StreamContext} representing this object's current state.
|
||||
* Should not return null even if there is no state.
|
||||
*
|
||||
* @return {@link StreamContext} representing current state.
|
||||
*/
|
||||
StreamContext getRestartData();
|
||||
|
||||
/**
|
||||
* Restart state given the provided {@link StreamContext}.
|
||||
*
|
||||
* @param data
|
||||
*/
|
||||
void restoreFrom(StreamContext data);
|
||||
}
|
||||
@@ -14,14 +14,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.restart;
|
||||
package org.springframework.batch.stream;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Interface for representing data necessary to recover state after restart.
|
||||
*/
|
||||
public interface RestartData {
|
||||
public interface StreamContext {
|
||||
|
||||
Properties getProperties();
|
||||
}
|
||||
@@ -8,9 +8,9 @@ import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.io.sample.domain.Foo;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.ItemStream;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.transaction.support.TransactionSynchronization;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
@@ -76,12 +76,12 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
Foo foo2 = (Foo) source.read();
|
||||
assertEquals(2, foo2.getValue());
|
||||
|
||||
RestartData restartData = getAsRestartable(source).getRestartData();
|
||||
StreamContext streamContext = getAsRestartable(source).getRestartData();
|
||||
|
||||
// create new input source
|
||||
source = createItemReader();
|
||||
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
getAsRestartable(source).restoreFrom(streamContext);
|
||||
|
||||
Foo fooAfterRestart = (Foo) source.read();
|
||||
assertEquals(3, fooAfterRestart.getValue());
|
||||
@@ -98,7 +98,7 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
Foo foo2 = (Foo) source.read();
|
||||
assertEquals(2, foo2.getValue());
|
||||
|
||||
RestartData restartData = getAsRestartable(source).getRestartData();
|
||||
StreamContext streamContext = getAsRestartable(source).getRestartData();
|
||||
|
||||
// create new input source
|
||||
source = createItemReader();
|
||||
@@ -107,7 +107,7 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
assertEquals(1, foo.getValue());
|
||||
|
||||
try {
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
getAsRestartable(source).restoreFrom(streamContext);
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
@@ -120,9 +120,9 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRestoreFromEmptyData() throws Exception {
|
||||
RestartData restartData = new GenericRestartData(new Properties());
|
||||
StreamContext streamContext = new GenericStreamContext(new Properties());
|
||||
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
getAsRestartable(source).restoreFrom(streamContext);
|
||||
|
||||
Foo foo = (Foo) source.read();
|
||||
assertEquals(1, foo.getValue());
|
||||
@@ -165,13 +165,13 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
return (InitializingBean) source;
|
||||
}
|
||||
|
||||
private Restartable getAsRestartable(ItemReader source) {
|
||||
return (Restartable) source;
|
||||
private ItemStream getAsRestartable(ItemReader source) {
|
||||
return (ItemStream) source;
|
||||
}
|
||||
|
||||
private static class MockKeyGenerator implements KeyGenerator{
|
||||
|
||||
static RestartData restartData;
|
||||
static StreamContext streamContext;
|
||||
List keys;
|
||||
List restartKeys;
|
||||
|
||||
@@ -180,7 +180,7 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
//restart data properties cannot be empty.
|
||||
props.setProperty("", "");
|
||||
|
||||
restartData = new GenericRestartData(props);
|
||||
streamContext = new GenericStreamContext(props);
|
||||
}
|
||||
|
||||
public MockKeyGenerator() {
|
||||
@@ -198,13 +198,13 @@ public class DrivingQueryItemReaderTests extends TestCase {
|
||||
restartKeys.add(new Foo(5, "5", 5));
|
||||
}
|
||||
|
||||
public RestartData getKeyAsRestartData(Object key) {
|
||||
return restartData;
|
||||
public StreamContext getKeyAsRestartData(Object key) {
|
||||
return streamContext;
|
||||
}
|
||||
|
||||
public List restoreKeys(RestartData restartData) {
|
||||
public List restoreKeys(StreamContext streamContext) {
|
||||
|
||||
assertEquals(MockKeyGenerator.restartData, restartData);
|
||||
assertEquals(MockKeyGenerator.streamContext, streamContext);
|
||||
return restartKeys;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,13 +2,13 @@ package org.springframework.batch.io.driving;
|
||||
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.reader.AbstractItemReader;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.stream.ItemStream;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
class FooItemReader extends AbstractItemReader implements ItemReader, Restartable, DisposableBean, InitializingBean{
|
||||
class FooItemReader extends AbstractItemReader implements ItemReader, ItemStream, DisposableBean, InitializingBean{
|
||||
|
||||
DrivingQueryItemReader inputSource;
|
||||
FooDao fooDao = new SingleKeyFooDao();
|
||||
@@ -27,11 +27,11 @@ class FooItemReader extends AbstractItemReader implements ItemReader, Restartabl
|
||||
}
|
||||
}
|
||||
|
||||
public RestartData getRestartData() {
|
||||
public StreamContext getRestartData() {
|
||||
return inputSource.getRestartData();
|
||||
}
|
||||
|
||||
public void restoreFrom(RestartData data) {
|
||||
public void restoreFrom(StreamContext data) {
|
||||
inputSource.restoreFrom(data);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ import java.util.Properties;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.core.CollectionFactory;
|
||||
import org.springframework.jdbc.core.PreparedStatementSetter;
|
||||
import org.springframework.util.ClassUtils;
|
||||
@@ -63,16 +63,16 @@ public class ColumnMapRestartDataRowMapperTests extends TestCase {
|
||||
|
||||
public void testCreateRestartData() throws Exception {
|
||||
|
||||
RestartData restartData = mapper.createRestartData(key);
|
||||
Properties props = restartData.getProperties();
|
||||
StreamContext streamContext = mapper.createRestartData(key);
|
||||
Properties props = streamContext.getProperties();
|
||||
assertEquals("1", props.getProperty(KEY + "0"));
|
||||
assertEquals("2", props.getProperty(KEY + "1"));
|
||||
}
|
||||
|
||||
public void testCreateRestartDataFromEmptyKeys() throws Exception {
|
||||
|
||||
RestartData restartData = mapper.createRestartData(new HashMap());
|
||||
assertEquals(0, restartData.getProperties().size());
|
||||
StreamContext streamContext = mapper.createRestartData(new HashMap());
|
||||
assertEquals(0, streamContext.getProperties().size());
|
||||
}
|
||||
|
||||
public void testCreateSetter() throws Exception {
|
||||
@@ -80,8 +80,8 @@ public class ColumnMapRestartDataRowMapperTests extends TestCase {
|
||||
Properties props = new Properties();
|
||||
props.setProperty(KEY + "0", "1");
|
||||
props.setProperty(KEY + "1", "2");
|
||||
RestartData restartData = new GenericRestartData(props);
|
||||
PreparedStatementSetter setter = mapper.createSetter(restartData);
|
||||
StreamContext streamContext = new GenericStreamContext(props);
|
||||
PreparedStatementSetter setter = mapper.createSetter(streamContext);
|
||||
ps = (PreparedStatement)psControl.getMock();
|
||||
|
||||
ps.setString(1, "1");
|
||||
|
||||
@@ -7,8 +7,8 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.core.CollectionFactory;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
|
||||
@@ -49,9 +49,9 @@ public class MultipleColumnJdbcKeyGeneratorIntegrationTests extends AbstractTran
|
||||
Properties props = new Properties();
|
||||
props.setProperty(ColumnMapRestartDataRowMapper.KEY + "0", "3");
|
||||
props.setProperty(ColumnMapRestartDataRowMapper.KEY + "1", "3");
|
||||
RestartData restartData = new GenericRestartData(props);
|
||||
StreamContext streamContext = new GenericStreamContext(props);
|
||||
|
||||
List keys = keyStrategy.restoreKeys(restartData);
|
||||
List keys = keyStrategy.restoreKeys(streamContext);
|
||||
|
||||
assertEquals(2, keys.size());
|
||||
Map key = (Map)keys.get(0);
|
||||
@@ -68,8 +68,8 @@ public class MultipleColumnJdbcKeyGeneratorIntegrationTests extends AbstractTran
|
||||
key.put("ID", new Long(3));
|
||||
key.put("VALUE", new Integer(3));
|
||||
|
||||
RestartData restartData = keyStrategy.getKeyAsRestartData(key);
|
||||
Properties props = restartData.getProperties();
|
||||
StreamContext streamContext = keyStrategy.getKeyAsRestartData(key);
|
||||
Properties props = streamContext.getProperties();
|
||||
|
||||
assertEquals(2, props.size());
|
||||
assertEquals("3", props.get(ColumnMapRestartDataRowMapper.KEY + "0"));
|
||||
|
||||
@@ -3,8 +3,8 @@ package org.springframework.batch.io.driving.support;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
|
||||
/**
|
||||
@@ -44,9 +44,9 @@ public class SingleColumnJdbcKeyGeneratorIntegrationTests extends AbstractTransa
|
||||
|
||||
Properties props = new Properties();
|
||||
props.setProperty(SingleColumnJdbcKeyGenerator.RESTART_KEY, "3");
|
||||
RestartData restartData = new GenericRestartData(props);
|
||||
StreamContext streamContext = new GenericStreamContext(props);
|
||||
|
||||
List keys = keyStrategy.restoreKeys(restartData);
|
||||
List keys = keyStrategy.restoreKeys(streamContext);
|
||||
|
||||
assertEquals(2, keys.size());
|
||||
assertEquals(new Long(4), keys.get(0));
|
||||
@@ -55,8 +55,8 @@ public class SingleColumnJdbcKeyGeneratorIntegrationTests extends AbstractTransa
|
||||
|
||||
public void testGetKeyAsRestartData(){
|
||||
|
||||
RestartData restartData = keyStrategy.getKeyAsRestartData(new Long(3));
|
||||
Properties props = restartData.getProperties();
|
||||
StreamContext streamContext = keyStrategy.getKeyAsRestartData(new Long(3));
|
||||
Properties props = streamContext.getProperties();
|
||||
|
||||
assertEquals(1, props.size());
|
||||
assertEquals("3", props.get(SingleColumnJdbcKeyGenerator.RESTART_KEY));
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.batch.io.file.mapping.DefaultFieldSet;
|
||||
import org.springframework.batch.io.file.mapping.FieldSetMapper;
|
||||
import org.springframework.batch.io.file.mapping.FieldSet;
|
||||
import org.springframework.batch.io.file.transform.LineTokenizer;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.transaction.support.TransactionSynchronization;
|
||||
@@ -204,8 +204,8 @@ public class DefaultFlatFileItemReaderTests extends TestCase {
|
||||
inputSource.read();
|
||||
|
||||
// get restart data
|
||||
RestartData restartData = inputSource.getRestartData();
|
||||
assertEquals("4", (String) restartData.getProperties().getProperty(
|
||||
StreamContext streamContext = inputSource.getRestartData();
|
||||
assertEquals("4", (String) streamContext.getProperties().getProperty(
|
||||
DefaultFlatFileItemReader.READ_STATISTICS_NAME));
|
||||
// close input
|
||||
inputSource.close();
|
||||
@@ -214,7 +214,7 @@ public class DefaultFlatFileItemReaderTests extends TestCase {
|
||||
|
||||
// init for restart
|
||||
inputSource.open();
|
||||
inputSource.restoreFrom(restartData);
|
||||
inputSource.restoreFrom(streamContext);
|
||||
|
||||
// read remaining records
|
||||
assertEquals("[testLine5]", inputSource.read().toString());
|
||||
|
||||
@@ -26,7 +26,7 @@ import java.util.Properties;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.item.writer.ItemTransformer;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.transaction.support.TransactionSynchronization;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
@@ -320,7 +320,7 @@ public class FlatFileItemWriterTests extends TestCase {
|
||||
commit();
|
||||
|
||||
// get restart data
|
||||
RestartData restartData = inputSource.getRestartData();
|
||||
StreamContext restartData = inputSource.getRestartData();
|
||||
// close template
|
||||
inputSource.close();
|
||||
|
||||
@@ -373,10 +373,10 @@ public class FlatFileItemWriterTests extends TestCase {
|
||||
|
||||
public void testDefaultRestartData() throws Exception {
|
||||
inputSource = new FlatFileItemWriter();
|
||||
RestartData restartData = inputSource.getRestartData();
|
||||
assertNotNull(restartData);
|
||||
assertEquals(1, restartData.getProperties().size());
|
||||
assertEquals("0", restartData.getProperties().getProperty(FlatFileItemWriter.RESTART_DATA_NAME));
|
||||
StreamContext streamContext = inputSource.getRestartData();
|
||||
assertNotNull(streamContext);
|
||||
assertEquals(1, streamContext.getProperties().size());
|
||||
assertEquals("0", streamContext.getProperties().getProperty(FlatFileItemWriter.RESTART_DATA_NAME));
|
||||
}
|
||||
|
||||
private void commit() {
|
||||
|
||||
@@ -5,9 +5,9 @@ import java.util.Properties;
|
||||
import org.springframework.batch.io.sample.domain.Foo;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.repeat.synch.BatchTransactionSynchronizationManager;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.ItemStream;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
@@ -85,12 +85,12 @@ public abstract class AbstractJdbcItemReaderIntegrationTests extends AbstractTra
|
||||
Foo foo2 = (Foo) source.read();
|
||||
assertEquals(2, foo2.getValue());
|
||||
|
||||
RestartData restartData = getAsRestartable(source).getRestartData();
|
||||
StreamContext streamContext = getAsRestartable(source).getRestartData();
|
||||
|
||||
// create new input source
|
||||
source = createItemReader();
|
||||
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
getAsRestartable(source).restoreFrom(streamContext);
|
||||
|
||||
Foo fooAfterRestart = (Foo) source.read();
|
||||
assertEquals(3, fooAfterRestart.getValue());
|
||||
@@ -107,7 +107,7 @@ public abstract class AbstractJdbcItemReaderIntegrationTests extends AbstractTra
|
||||
Foo foo2 = (Foo) source.read();
|
||||
assertEquals(2, foo2.getValue());
|
||||
|
||||
RestartData restartData = getAsRestartable(source).getRestartData();
|
||||
StreamContext streamContext = getAsRestartable(source).getRestartData();
|
||||
|
||||
// create new input source
|
||||
source = createItemReader();
|
||||
@@ -116,7 +116,7 @@ public abstract class AbstractJdbcItemReaderIntegrationTests extends AbstractTra
|
||||
assertEquals(1, foo.getValue());
|
||||
|
||||
try {
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
getAsRestartable(source).restoreFrom(streamContext);
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
@@ -129,9 +129,9 @@ public abstract class AbstractJdbcItemReaderIntegrationTests extends AbstractTra
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRestoreFromEmptyData() throws Exception {
|
||||
RestartData restartData = new GenericRestartData(new Properties());
|
||||
StreamContext streamContext = new GenericStreamContext(new Properties());
|
||||
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
getAsRestartable(source).restoreFrom(streamContext);
|
||||
|
||||
Foo foo = (Foo) source.read();
|
||||
assertEquals(1, foo.getValue());
|
||||
@@ -170,8 +170,8 @@ public abstract class AbstractJdbcItemReaderIntegrationTests extends AbstractTra
|
||||
TransactionSynchronization.STATUS_ROLLED_BACK);
|
||||
}
|
||||
|
||||
private Restartable getAsRestartable(ItemReader source) {
|
||||
return (Restartable) source;
|
||||
private ItemStream getAsRestartable(ItemReader source) {
|
||||
return (ItemStream) source;
|
||||
}
|
||||
|
||||
private InitializingBean getAsInitializingBean(ItemReader source) {
|
||||
|
||||
@@ -6,9 +6,9 @@ import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.io.sample.domain.Foo;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.repeat.synch.BatchTransactionSynchronizationManager;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.ItemStream;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
@@ -92,12 +92,12 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends Abstr
|
||||
Foo foo2 = (Foo) source.read();
|
||||
assertEquals(2, foo2.getValue());
|
||||
|
||||
RestartData restartData = getAsRestartable(source).getRestartData();
|
||||
StreamContext streamContext = getAsRestartable(source).getRestartData();
|
||||
|
||||
// create new input source
|
||||
source = createItemReader();
|
||||
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
getAsRestartable(source).restoreFrom(streamContext);
|
||||
|
||||
Foo fooAfterRestart = (Foo) source.read();
|
||||
assertEquals(3, fooAfterRestart.getValue());
|
||||
@@ -114,7 +114,7 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends Abstr
|
||||
Foo foo2 = (Foo) source.read();
|
||||
assertEquals(2, foo2.getValue());
|
||||
|
||||
RestartData restartData = getAsRestartable(source).getRestartData();
|
||||
StreamContext streamContext = getAsRestartable(source).getRestartData();
|
||||
|
||||
// create new input source
|
||||
source = createItemReader();
|
||||
@@ -123,7 +123,7 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends Abstr
|
||||
assertEquals(1, foo.getValue());
|
||||
|
||||
try {
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
getAsRestartable(source).restoreFrom(streamContext);
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
@@ -136,9 +136,9 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends Abstr
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRestoreFromEmptyData() throws Exception {
|
||||
RestartData restartData = new GenericRestartData(new Properties());
|
||||
StreamContext streamContext = new GenericStreamContext(new Properties());
|
||||
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
getAsRestartable(source).restoreFrom(streamContext);
|
||||
|
||||
Foo foo = (Foo) source.read();
|
||||
assertEquals(1, foo.getValue());
|
||||
@@ -217,12 +217,12 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends Abstr
|
||||
|
||||
rollback();
|
||||
|
||||
RestartData restartData = getAsRestartable(source).getRestartData();
|
||||
StreamContext streamContext = getAsRestartable(source).getRestartData();
|
||||
|
||||
// create new input source
|
||||
source = createItemReader();
|
||||
|
||||
getAsRestartable(source).restoreFrom(restartData);
|
||||
getAsRestartable(source).restoreFrom(streamContext);
|
||||
|
||||
assertEquals(foo2, source.read());
|
||||
Foo foo4 = (Foo) source.read();
|
||||
@@ -245,8 +245,8 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests extends Abstr
|
||||
return (Skippable) source;
|
||||
}
|
||||
|
||||
private Restartable getAsRestartable(ItemReader source) {
|
||||
return (Restartable) source;
|
||||
private ItemStream getAsRestartable(ItemReader source) {
|
||||
return (ItemStream) source;
|
||||
}
|
||||
|
||||
private InitializingBean getAsInitializingBean(ItemReader source) {
|
||||
|
||||
@@ -16,8 +16,8 @@ import javax.xml.stream.events.XMLEvent;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.io.xml.StaxEventItemReader;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.core.io.AbstractResource;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -117,13 +117,13 @@ public class StaxEventReaderItemReaderTests extends TestCase {
|
||||
*/
|
||||
public void testRestart() {
|
||||
source.read();
|
||||
RestartData restartData = source.getRestartData();
|
||||
assertEquals("1", restartData.getProperties().
|
||||
StreamContext streamContext = source.getRestartData();
|
||||
assertEquals("1", streamContext.getProperties().
|
||||
getProperty("StaxEventReaderItemReader.recordcount"));
|
||||
List expectedAfterRestart = (List) source.read();
|
||||
|
||||
source = createNewInputSouce();
|
||||
source.restoreFrom(restartData);
|
||||
source.restoreFrom(streamContext);
|
||||
List afterRestart = (List) source.read();
|
||||
assertEquals(expectedAfterRestart.size(), afterRestart.size());
|
||||
}
|
||||
@@ -138,7 +138,7 @@ public class StaxEventReaderItemReaderTests extends TestCase {
|
||||
setProperty("StaxEventReaderItemReader.recordcount", MORE_RECORDS_THAN_INPUT_CONTAINS);
|
||||
}};
|
||||
try {
|
||||
source.restoreFrom(new GenericRestartData(props));
|
||||
source.restoreFrom(new GenericStreamContext(props));
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
@@ -148,7 +148,7 @@ public class StaxEventReaderItemReaderTests extends TestCase {
|
||||
source = createNewInputSouce();
|
||||
source.open();
|
||||
try {
|
||||
source.restoreFrom(new GenericRestartData(new Properties()));
|
||||
source.restoreFrom(new GenericStreamContext(new Properties()));
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
|
||||
@@ -13,7 +13,7 @@ import junit.framework.TestCase;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.springframework.batch.io.xml.StaxEventItemWriter;
|
||||
import org.springframework.batch.io.xml.oxm.MarshallingEventWriterSerializer;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.oxm.Marshaller;
|
||||
@@ -92,11 +92,11 @@ public class StaxEventWriterItemWriterTests extends TestCase {
|
||||
// write records
|
||||
writer.write(record);
|
||||
writer.getSynchronization().afterCompletion(TransactionSynchronization.STATUS_COMMITTED);
|
||||
RestartData restartData = writer.getRestartData();
|
||||
StreamContext streamContext = writer.getRestartData();
|
||||
|
||||
// create new writer from saved restart data and continue writing
|
||||
writer = createItemWriter();
|
||||
writer.restoreFrom(restartData);
|
||||
writer.restoreFrom(streamContext);
|
||||
writer.write(record);
|
||||
writer.destroy();
|
||||
|
||||
|
||||
@@ -24,10 +24,10 @@ import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.reader.AbstractItemReader;
|
||||
import org.springframework.batch.item.reader.DelegatingItemReader;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.statistics.StatisticsProvider;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.ItemStream;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.batch.support.PropertiesConverter;
|
||||
|
||||
/**
|
||||
@@ -85,7 +85,7 @@ public class DelegatingItemReaderTests extends TestCase {
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRestoreFrom() throws Exception {
|
||||
itemProvider.restoreFrom(new GenericRestartData(PropertiesConverter.stringToProperties("value=bar")));
|
||||
itemProvider.restoreFrom(new GenericStreamContext(PropertiesConverter.stringToProperties("value=bar")));
|
||||
assertEquals("bar", itemProvider.read());
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ public class DelegatingItemReaderTests extends TestCase {
|
||||
assertEquals("after skip", itemProvider.read());
|
||||
}
|
||||
|
||||
private static class MockItemReader extends AbstractItemReader implements ItemReader, StatisticsProvider, Restartable, Skippable {
|
||||
private static class MockItemReader extends AbstractItemReader implements ItemReader, StatisticsProvider, ItemStream, Skippable {
|
||||
|
||||
private Object value;
|
||||
|
||||
@@ -102,11 +102,11 @@ public class DelegatingItemReaderTests extends TestCase {
|
||||
return PropertiesConverter.stringToProperties("a=b");
|
||||
}
|
||||
|
||||
public RestartData getRestartData() {
|
||||
return new GenericRestartData(PropertiesConverter.stringToProperties("value=foo"));
|
||||
public StreamContext getRestartData() {
|
||||
return new GenericStreamContext(PropertiesConverter.stringToProperties("value=foo"));
|
||||
}
|
||||
|
||||
public void restoreFrom(RestartData data) {
|
||||
public void restoreFrom(StreamContext data) {
|
||||
value = data.getProperties().getProperty("value");
|
||||
}
|
||||
|
||||
|
||||
@@ -10,10 +10,10 @@ import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.writer.CompositeItemWriter;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.statistics.StatisticsProvider;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.ItemStream;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
|
||||
/**
|
||||
* Tests for {@link CompositeItemWriter}
|
||||
@@ -75,7 +75,7 @@ public class CompositeItemWriterTests extends TestCase {
|
||||
}};
|
||||
itemProcessor.setItemWriters(itemProcessors);
|
||||
|
||||
RestartData rd = itemProcessor.getRestartData();
|
||||
StreamContext rd = itemProcessor.getRestartData();
|
||||
itemProcessor.restoreFrom(rd);
|
||||
|
||||
for (Iterator iterator = itemProcessors.iterator(); iterator.hasNext();) {
|
||||
@@ -120,7 +120,7 @@ public class CompositeItemWriterTests extends TestCase {
|
||||
* Stub for testing restart. Checks the restart data received is the same that was returned by
|
||||
* <code>getRestartData()</code>
|
||||
*/
|
||||
private static class ItemWriterStub implements ItemWriter, Restartable, StatisticsProvider {
|
||||
private static class ItemWriterStub implements ItemWriter, ItemStream, StatisticsProvider {
|
||||
|
||||
private static final String RESTART_KEY = "restartData";
|
||||
private static final String STATS_KEY = "stats";
|
||||
@@ -130,14 +130,14 @@ public class CompositeItemWriterTests extends TestCase {
|
||||
private final int hashCode = this.hashCode();
|
||||
|
||||
|
||||
public RestartData getRestartData() {
|
||||
public StreamContext getRestartData() {
|
||||
Properties props = new Properties(){{
|
||||
setProperty(RESTART_KEY, String.valueOf(hashCode));
|
||||
}};
|
||||
return new GenericRestartData(props);
|
||||
return new GenericStreamContext(props);
|
||||
}
|
||||
|
||||
public void restoreFrom(RestartData data) {
|
||||
public void restoreFrom(StreamContext data) {
|
||||
if (Integer.valueOf(data.getProperties().getProperty(RESTART_KEY)).intValue() != hashCode()) {
|
||||
fail("received restart data is not the same which was saved");
|
||||
}
|
||||
|
||||
@@ -24,10 +24,10 @@ import junit.framework.TestCase;
|
||||
import org.springframework.batch.io.Skippable;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.writer.DelegatingItemWriter;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.restart.Restartable;
|
||||
import org.springframework.batch.statistics.StatisticsProvider;
|
||||
import org.springframework.batch.stream.GenericStreamContext;
|
||||
import org.springframework.batch.stream.ItemStream;
|
||||
import org.springframework.batch.stream.StreamContext;
|
||||
import org.springframework.batch.support.PropertiesConverter;
|
||||
|
||||
/**
|
||||
@@ -69,7 +69,7 @@ public class ItemWriterItemProcessorTests extends TestCase {
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testRestoreFrom() throws Exception {
|
||||
processor.restoreFrom(new GenericRestartData(PropertiesConverter.stringToProperties("value=bar")));
|
||||
processor.restoreFrom(new GenericStreamContext(PropertiesConverter.stringToProperties("value=bar")));
|
||||
processor.write("foo");
|
||||
assertEquals("bar:foo", list.get(0));
|
||||
}
|
||||
@@ -96,7 +96,7 @@ public class ItemWriterItemProcessorTests extends TestCase {
|
||||
public void testRestoreFromWithoutRestartable() throws Exception {
|
||||
processor.setDelegate(null);
|
||||
try {
|
||||
processor.restoreFrom(new GenericRestartData(PropertiesConverter.stringToProperties("value=bar")));
|
||||
processor.restoreFrom(new GenericStreamContext(PropertiesConverter.stringToProperties("value=bar")));
|
||||
fail("Expected IllegalStateException");
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
@@ -130,7 +130,7 @@ public class ItemWriterItemProcessorTests extends TestCase {
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class MockOutputSource implements ItemWriter, StatisticsProvider, Restartable, Skippable {
|
||||
public class MockOutputSource implements ItemWriter, StatisticsProvider, ItemStream, Skippable {
|
||||
|
||||
private String value;
|
||||
|
||||
@@ -152,11 +152,11 @@ public class ItemWriterItemProcessorTests extends TestCase {
|
||||
return PropertiesConverter.stringToProperties("a=b");
|
||||
}
|
||||
|
||||
public RestartData getRestartData() {
|
||||
return new GenericRestartData(PropertiesConverter.stringToProperties("value=foo"));
|
||||
public StreamContext getRestartData() {
|
||||
return new GenericStreamContext(PropertiesConverter.stringToProperties("value=foo"));
|
||||
}
|
||||
|
||||
public void restoreFrom(RestartData data) {
|
||||
public void restoreFrom(StreamContext data) {
|
||||
value = data.getProperties().getProperty("value");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user