IN PROGRESS - issue BATCH-7: Remove transaction synchronization and state management from input/output sources (formerly buffering)
http://jira.springframework.org/browse/BATCH-7 Remove GenericStreamContext
This commit is contained in:
@@ -19,13 +19,12 @@ package org.springframework.batch.execution.repository;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.batch.core.domain.Job;
|
||||
import org.springframework.batch.core.domain.JobSupport;
|
||||
import org.springframework.batch.core.domain.JobExecution;
|
||||
import org.springframework.batch.core.domain.JobInstance;
|
||||
import org.springframework.batch.core.domain.JobParameters;
|
||||
import org.springframework.batch.core.domain.JobSupport;
|
||||
import org.springframework.batch.core.domain.Step;
|
||||
import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.core.domain.StepInstance;
|
||||
@@ -34,7 +33,7 @@ import org.springframework.batch.core.repository.JobExecutionAlreadyRunningExcep
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.execution.repository.dao.JobDao;
|
||||
import org.springframework.batch.execution.repository.dao.StepDao;
|
||||
import org.springframework.batch.item.stream.GenericStreamContext;
|
||||
import org.springframework.batch.item.StreamContext;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -303,8 +302,8 @@ public class SimpleJobRepository implements JobRepository {
|
||||
Step step = (Step) i.next();
|
||||
StepInstance stepInstance = stepDao.createStep(job, step.getName());
|
||||
// Ensure valid restart data is being returned.
|
||||
if (stepInstance.getStreamContext() == null || stepInstance.getStreamContext().getProperties() == null) {
|
||||
stepInstance.setStreamContext(new GenericStreamContext(new Properties()));
|
||||
if (stepInstance.getStreamContext() == null || stepInstance.getStreamContext() == null) {
|
||||
stepInstance.setStreamContext(new StreamContext());
|
||||
}
|
||||
stepInstances.add(stepInstance);
|
||||
}
|
||||
@@ -326,8 +325,8 @@ public class SimpleJobRepository implements JobRepository {
|
||||
|
||||
step.setStepExecutionCount(stepDao.getStepExecutionCount(step));
|
||||
// Ensure valid restart data is being returned.
|
||||
if (step.getStreamContext() == null || step.getStreamContext().getProperties() == null) {
|
||||
step.setStreamContext(new GenericStreamContext(new Properties()));
|
||||
if (step.getStreamContext() == null || step.getStreamContext() == null) {
|
||||
step.setStreamContext(new StreamContext());
|
||||
}
|
||||
stepInstances.add(step);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.core.domain.StepInstance;
|
||||
import org.springframework.batch.execution.repository.dao.JdbcJobDao.JobExecutionRowMapper;
|
||||
import org.springframework.batch.item.StreamContext;
|
||||
import org.springframework.batch.item.stream.GenericStreamContext;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.support.PropertiesConverter;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
@@ -161,9 +160,7 @@ public class JdbcStepDao implements StepDao, InitializingBean {
|
||||
|
||||
StepInstance step = new StepInstance(new Long(rs.getLong(1)));
|
||||
step.setStatus(BatchStatus.getStatus(rs.getString(2)));
|
||||
step
|
||||
.setStreamContext(new GenericStreamContext(PropertiesConverter.stringToProperties(rs
|
||||
.getString(3))));
|
||||
step.setStreamContext(new StreamContext(PropertiesConverter.stringToProperties(rs.getString(3))));
|
||||
return step;
|
||||
}
|
||||
|
||||
@@ -213,8 +210,8 @@ public class JdbcStepDao implements StepDao, InitializingBean {
|
||||
stepExecution.setStatus(BatchStatus.getStatus(rs.getString(5)));
|
||||
stepExecution.setCommitCount(rs.getInt(6));
|
||||
stepExecution.setTaskCount(rs.getInt(7));
|
||||
stepExecution.setStreamContext(new GenericStreamContext(PropertiesConverter.stringToProperties(rs
|
||||
.getString(8))));
|
||||
stepExecution.setStreamContext(new StreamContext(PropertiesConverter
|
||||
.stringToProperties(rs.getString(8))));
|
||||
stepExecution.setExitStatus(new ExitStatus("Y".equals(rs.getString(9)), rs.getString(10), rs
|
||||
.getString(11)));
|
||||
return stepExecution;
|
||||
@@ -247,7 +244,7 @@ public class JdbcStepDao implements StepDao, InitializingBean {
|
||||
String status = rs.getString(3);
|
||||
step.setStatus(BatchStatus.getStatus(status));
|
||||
step
|
||||
.setStreamContext(new GenericStreamContext(PropertiesConverter.stringToProperties(rs
|
||||
.setStreamContext(new StreamContext(PropertiesConverter.stringToProperties(rs
|
||||
.getString(3))));
|
||||
return step;
|
||||
}
|
||||
|
||||
@@ -25,11 +25,11 @@ import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.ArgumentsMatcher;
|
||||
import org.easymock.MockControl;
|
||||
import org.springframework.batch.core.domain.JobSupport;
|
||||
import org.springframework.batch.core.domain.JobExecution;
|
||||
import org.springframework.batch.core.domain.JobInstance;
|
||||
import org.springframework.batch.core.domain.JobParameters;
|
||||
import org.springframework.batch.core.domain.JobParametersBuilder;
|
||||
import org.springframework.batch.core.domain.JobSupport;
|
||||
import org.springframework.batch.core.domain.Step;
|
||||
import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.core.domain.StepInstance;
|
||||
@@ -37,7 +37,7 @@ import org.springframework.batch.core.domain.StepSupport;
|
||||
import org.springframework.batch.core.repository.BatchRestartException;
|
||||
import org.springframework.batch.execution.repository.dao.JobDao;
|
||||
import org.springframework.batch.execution.repository.dao.StepDao;
|
||||
import org.springframework.batch.item.stream.GenericStreamContext;
|
||||
import org.springframework.batch.item.StreamContext;
|
||||
|
||||
/*
|
||||
* Test SimpleJobRepository. The majority of test cases are tested using EasyMock,
|
||||
@@ -408,7 +408,7 @@ public class SimpleJobRepositoryTests extends TestCase {
|
||||
databaseStep1.setStreamContext(null);
|
||||
stepDaoControl.setReturnValue(databaseStep1);
|
||||
stepDao.createStep(databaseJob, "TestStep2");
|
||||
databaseStep2.setStreamContext(new GenericStreamContext(null));
|
||||
databaseStep2.setStreamContext(new StreamContext());
|
||||
stepDaoControl.setReturnValue(databaseStep2);
|
||||
jobDao.save(new JobExecution(databaseJob));
|
||||
jobDaoControl.setMatcher(new ArgumentsMatcher(){
|
||||
@@ -443,7 +443,7 @@ public class SimpleJobRepositoryTests extends TestCase {
|
||||
stepDao.getStepExecutionCount(databaseStep1);
|
||||
stepDaoControl.setReturnValue(1);
|
||||
stepDao.findStep(databaseJob, "TestStep2");
|
||||
databaseStep2.setStreamContext(new GenericStreamContext(null));
|
||||
databaseStep2.setStreamContext(new StreamContext());
|
||||
stepDaoControl.setReturnValue(databaseStep2);
|
||||
stepDao.getStepExecutionCount(databaseStep2);
|
||||
stepDaoControl.setReturnValue(1);
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.batch.execution.repository.dao;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.batch.core.domain.BatchStatus;
|
||||
import org.springframework.batch.core.domain.Job;
|
||||
@@ -30,8 +29,8 @@ import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.core.domain.StepInstance;
|
||||
import org.springframework.batch.core.runtime.ExitCodeExceptionClassifier;
|
||||
import org.springframework.batch.item.StreamContext;
|
||||
import org.springframework.batch.item.stream.GenericStreamContext;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
import org.springframework.batch.support.PropertiesConverter;
|
||||
import org.springframework.dao.OptimisticLockingFailureException;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
import org.springframework.util.ClassUtils;
|
||||
@@ -151,9 +150,7 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour
|
||||
public void testUpdateStepWithStreamContext() {
|
||||
|
||||
step1.setStatus(BatchStatus.COMPLETED);
|
||||
Properties data = new Properties();
|
||||
data.setProperty("restart.key1", "restartData");
|
||||
StreamContext streamContext = new GenericStreamContext(data);
|
||||
StreamContext streamContext = new StreamContext(PropertiesConverter.stringToProperties("key1=restartData"));
|
||||
step1.setStreamContext(streamContext);
|
||||
stepDao.update(step1);
|
||||
StepInstance tempStep = stepDao.findStep(jobInstance, step1.getName());
|
||||
@@ -166,10 +163,7 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour
|
||||
StepExecution execution = new StepExecution(step2, jobExecution, null);
|
||||
execution.setStatus(BatchStatus.STARTED);
|
||||
execution.setStartTime(new Date(System.currentTimeMillis()));
|
||||
Properties statistics = new Properties();
|
||||
statistics.setProperty("statistic.key1", "0");
|
||||
statistics.setProperty("statistic.key2", "5");
|
||||
execution.setStreamContext(new GenericStreamContext(statistics));
|
||||
execution.setStreamContext(new StreamContext(PropertiesConverter.stringToProperties("key1=0,key2=5")));
|
||||
execution.setExitStatus(new ExitStatus(false, ExitCodeExceptionClassifier.FATAL_EXCEPTION,
|
||||
"java.lang.Exception"));
|
||||
stepDao.save(execution);
|
||||
@@ -177,8 +171,7 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour
|
||||
assertEquals(1, executions.size());
|
||||
StepExecution tempExecution = (StepExecution) executions.get(0);
|
||||
assertEquals(execution, tempExecution);
|
||||
assertEquals(execution.getStreamContext().getString("statistic.key1"), tempExecution.getStreamContext()
|
||||
.getString("statistic.key1"));
|
||||
assertEquals(execution.getStreamContext().getString("key1"), tempExecution.getStreamContext().getString("key1"));
|
||||
assertEquals(execution.getExitStatus(), tempExecution.getExitStatus());
|
||||
}
|
||||
|
||||
@@ -234,7 +227,7 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour
|
||||
|
||||
public void testUpdateStepExecutionOptimisticLocking() throws Exception {
|
||||
stepExecution.incrementVersion(); // not really allowed outside dao
|
||||
// code
|
||||
// code
|
||||
try {
|
||||
stepDao.update(stepExecution);
|
||||
fail("Expected OptimisticLockingFailureException");
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.batch.execution.repository.dao;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
@@ -26,9 +25,8 @@ import org.springframework.batch.core.domain.JobInstance;
|
||||
import org.springframework.batch.core.domain.JobParameters;
|
||||
import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.core.domain.StepInstance;
|
||||
import org.springframework.batch.execution.repository.dao.MapStepDao;
|
||||
import org.springframework.batch.item.StreamContext;
|
||||
import org.springframework.batch.item.stream.GenericStreamContext;
|
||||
import org.springframework.batch.support.PropertiesConverter;
|
||||
|
||||
public class MapStepDaoTests extends TestCase {
|
||||
|
||||
@@ -109,9 +107,7 @@ public class MapStepDaoTests extends TestCase {
|
||||
public void testSaveStreamContext() throws Exception {
|
||||
assertEquals(null, dao.getStreamContext(step.getId()));
|
||||
step.setStatus(BatchStatus.COMPLETED);
|
||||
Properties data = new Properties();
|
||||
data.setProperty("restart.key1", "restartData");
|
||||
StreamContext streamContext = new GenericStreamContext(data);
|
||||
StreamContext streamContext = new StreamContext(PropertiesConverter.stringToProperties("key1=restartData"));
|
||||
step.setStreamContext(streamContext);
|
||||
dao.update(step);
|
||||
StepInstance tempStep = dao.findStep(job, step.getName());
|
||||
|
||||
@@ -25,7 +25,6 @@ import junit.framework.TestCase;
|
||||
import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.StreamContext;
|
||||
import org.springframework.batch.item.stream.GenericStreamContext;
|
||||
import org.springframework.batch.item.stream.ItemStreamAdapter;
|
||||
import org.springframework.batch.item.stream.SimpleStreamManager;
|
||||
import org.springframework.batch.support.PropertiesConverter;
|
||||
@@ -166,7 +165,7 @@ public class SimpleStepContextTests extends TestCase {
|
||||
}
|
||||
|
||||
public StreamContext getStreamContext(Object key) {
|
||||
return new GenericStreamContext(PropertiesConverter.stringToProperties("foo=bar"));
|
||||
return new StreamContext(PropertiesConverter.stringToProperties("foo=bar"));
|
||||
}
|
||||
|
||||
public void open(Object key) {
|
||||
|
||||
@@ -43,7 +43,6 @@ import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.StreamContext;
|
||||
import org.springframework.batch.item.StreamException;
|
||||
import org.springframework.batch.item.reader.ListItemReader;
|
||||
import org.springframework.batch.item.stream.GenericStreamContext;
|
||||
import org.springframework.batch.item.stream.ItemStreamAdapter;
|
||||
import org.springframework.batch.item.stream.SimpleStreamManager;
|
||||
import org.springframework.batch.item.writer.AbstractItemWriter;
|
||||
@@ -306,7 +305,7 @@ public class SimpleStepExecutorTests extends TestCase {
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
StepExecution stepExecution = new StepExecution(step, jobExecutionContext);
|
||||
stepExecution.getStep().setStreamContext(
|
||||
new GenericStreamContext(PropertiesConverter.stringToProperties("foo=bar")));
|
||||
new StreamContext(PropertiesConverter.stringToProperties("foo=bar")));
|
||||
|
||||
stepExecutor.execute(stepExecution);
|
||||
|
||||
@@ -415,7 +414,7 @@ public class SimpleStepExecutorTests extends TestCase {
|
||||
stepExecutor.setStreamManager(new SimpleStreamManager(new ResourcelessTransactionManager()) {
|
||||
public StreamContext getStreamContext(Object key) {
|
||||
// TODO Auto-generated method stub
|
||||
return new GenericStreamContext(PropertiesConverter.stringToProperties("foo=bar"));
|
||||
return new StreamContext(PropertiesConverter.stringToProperties("foo=bar"));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -447,7 +446,7 @@ public class SimpleStepExecutorTests extends TestCase {
|
||||
|
||||
public StreamContext getStreamContext() {
|
||||
getStreamContextCalled = true;
|
||||
return new GenericStreamContext(PropertiesConverter.stringToProperties("spam=bucket"));
|
||||
return new StreamContext(PropertiesConverter.stringToProperties("spam=bucket"));
|
||||
}
|
||||
|
||||
public void restoreFrom(StreamContext data) {
|
||||
|
||||
Reference in New Issue
Block a user