Incomplete - task 84: Fix samples

Fix restart sample - StepExecutionDao was not restoring execution context
This commit is contained in:
dsyer
2008-02-26 13:19:14 +00:00
parent 5e09d034e0
commit 2b32b8d38e
5 changed files with 52 additions and 36 deletions

View File

@@ -121,8 +121,8 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement
}
/**
* Insert execution attributes. A lob creator must be used, since any
* attributes that don't match a provided type must be serialized into a
* Insert execution attributes. A {@link LobHandler} must be provided, since
* any attributes that don't match a provided type are serialized into a
* blob.
*/
public void saveExecutionContext(final StepExecution stepExecution) {
@@ -367,7 +367,7 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement
private class StepExecutionRowMapper implements RowMapper {
private final JobExecution jobExecution;
private final Step step;
public StepExecutionRowMapper(JobExecution jobExecution, Step step) {
@@ -383,10 +383,9 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement
stepExecution.setStatus(BatchStatus.getStatus(rs.getString(5)));
stepExecution.setCommitCount(rs.getInt(6));
stepExecution.setTaskCount(rs.getInt(7));
stepExecution.setExecutionContext(new ExecutionContext(PropertiesConverter.stringToProperties(rs
.getString(8))));
stepExecution
.setExitStatus(new ExitStatus("Y".equals(rs.getString(9)), rs.getString(10), rs.getString(11)));
stepExecution.setExecutionContext(findExecutionContext(stepExecution));
return stepExecution;
}

View File

@@ -101,8 +101,6 @@ public class ItemOrientedStep extends AbstractStep implements InitializingBean {
private int commitInterval = 0;
private boolean saveExecutionContext = false;
/**
* The {@link RepeatOperations} to use for the outer loop of the batch
* processing. Should be set up by the caller through a factory. Defaults to
@@ -115,11 +113,11 @@ public class ItemOrientedStep extends AbstractStep implements InitializingBean {
}
/**
* the {@link repeatoperations} to use for the inner loop of the batch
* The {@link RepeatOperations} to use for the inner loop of the batch
* processing. should be set up by the caller through a factory. defaults to
* a plain {@link repeattemplate}.
* a plain {@link RepeatTemplate}.
*
* @param chunkoperations a {@link repeatoperations} instance.
* @param chunkoperations a {@link RepeatOperations} instance.
*/
public void setChunkOperations(RepeatOperations chunkoperations) {
this.chunkOperations = chunkoperations;
@@ -256,7 +254,7 @@ public class ItemOrientedStep extends AbstractStep implements InitializingBean {
// the conversation in StepScope
stepContext.setAttribute(StepScope.ID_KEY, stepExecution.getJobExecution().getId());
if (saveExecutionContext && isRestart && lastStepExecution != null) {
if (isSaveExecutionContext() && isRestart && lastStepExecution != null) {
stepExecution.setExecutionContext(lastStepExecution.getExecutionContext());
}
else {
@@ -303,6 +301,7 @@ public class ItemOrientedStep extends AbstractStep implements InitializingBean {
}
itemReader.mark();
itemWriter.flush();
streamManager.commit(transaction);

View File

@@ -33,7 +33,6 @@ import org.springframework.batch.core.domain.StepSupport;
import org.springframework.batch.core.runtime.ExitStatusExceptionClassifier;
import org.springframework.batch.item.ExecutionContext;
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;
@@ -128,18 +127,32 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour
}
public void testSaveStepExecution() {
StepExecution execution = new StepExecution(step2, jobExecution, null);
execution.setStatus(BatchStatus.STARTED);
execution.setStartTime(new Date(System.currentTimeMillis()));
execution.setExecutionContext(new ExecutionContext(PropertiesConverter.stringToProperties("key1=0,key2=5")));
execution.setExitStatus(new ExitStatus(false, ExitStatusExceptionClassifier.FATAL_EXCEPTION,
"java.lang.Exception"));
stepExecutionDao.saveStepExecution(execution);
StepExecution retrievedExecution = stepExecutionDao.getStepExecution(jobExecution, step2);
assertNotNull(retrievedExecution);
assertEquals(execution, retrievedExecution);
assertEquals(execution.getExecutionContext().getString("key1"), retrievedExecution.getExecutionContext().getString("key1"));
assertEquals(execution.getExitStatus(), retrievedExecution.getExitStatus());
}
public void testSaveStepExecutionAndExecutionContext() {
StepExecution execution = new StepExecution(step2, jobExecution, null);
execution.setStatus(BatchStatus.STARTED);
execution.setStartTime(new Date(System.currentTimeMillis()));
execution.setExecutionContext(executionContext);
execution.setExitStatus(new ExitStatus(false, ExitStatusExceptionClassifier.FATAL_EXCEPTION,
"java.lang.Exception"));
stepExecutionDao.saveStepExecution(execution);
stepExecutionDao.saveExecutionContext(execution);
StepExecution retrievedExecution = stepExecutionDao.getStepExecution(jobExecution, step2);
assertNotNull(retrievedExecution);
assertEquals(execution, retrievedExecution);
assertEquals(execution.getExecutionContext().getString("1"), retrievedExecution.getExecutionContext().getString("1"));
assertEquals(execution.getExecutionContext().getLong("3"), retrievedExecution.getExecutionContext().getLong("3"));
assertEquals(execution.getExitStatus(), retrievedExecution.getExitStatus());
}