RESOLVED - BATCH-751: ensure StepExecution is saved before trying to save ExecutionContext

EC is now saved immediately after AbstractStep updates the status to 'STARTED'
This commit is contained in:
robokaso
2008-07-30 08:05:43 +00:00
parent 32f5a8800f
commit 6de6b622dc
3 changed files with 15 additions and 1 deletions

View File

@@ -155,6 +155,8 @@ public abstract class AbstractStep implements Step, InitializingBean, BeanNameAw
UnexpectedJobExecutionException {
stepExecution.setStartTime(new Date());
stepExecution.setStatus(BatchStatus.STARTED);
getJobRepository().saveOrUpdate(stepExecution);
ExitStatus exitStatus = ExitStatus.FAILED;
Exception commitException = null;

View File

@@ -222,7 +222,6 @@ public class ItemOrientedStep extends AbstractStep {
*/
protected ExitStatus doExecute(final StepExecution stepExecution) throws Exception {
stream.update(stepExecution.getExecutionContext());
getJobRepository().saveOrUpdate(stepExecution);
getJobRepository().saveOrUpdateExecutionContext(stepExecution);
itemHandler.mark();

View File

@@ -13,6 +13,7 @@ import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.StepExecutionListener;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.util.Assert;
/**
* Tests for {@link AbstractStep}.
@@ -101,13 +102,25 @@ public class AbstractStepTests extends TestCase {
* Remembers the last saved values of execution context.
*/
private static class JobRepositoryStub extends JobRepositorySupport {
static long counter = 0;
ExecutionContext saved = new ExecutionContext();
public void saveOrUpdateExecutionContext(StepExecution stepExecution) {
Assert.state(stepExecution.getId() != null, "StepExecution must be already saved");
saved = stepExecution.getExecutionContext();
}
public void saveOrUpdate(StepExecution stepExecution) {
if (stepExecution.getId() == null) {
stepExecution.setId(new Long(counter));
counter++;
}
}
}
protected void setUp() throws Exception {