IN PROGRESS - BATCH-505: Job-level ExecutionContext
repository now restores saved job context during JobExecution creation
This commit is contained in:
@@ -54,12 +54,13 @@ public class SimpleJob extends AbstractJob {
|
||||
|
||||
JobInstance jobInstance = execution.getJobInstance();
|
||||
|
||||
boolean isJobRestart = getJobRepository().getJobExecutionCount(jobInstance) > 0;
|
||||
if (isJobRestart) {
|
||||
execution.setExecutionContext(getJobRepository().getLastJobExecution(jobInstance).getExecutionContext());
|
||||
} else {
|
||||
execution.setExecutionContext(new ExecutionContext());
|
||||
}
|
||||
// boolean isJobRestart = getJobRepository().getJobExecutionCount(jobInstance) > 1;
|
||||
// if (isJobRestart) {
|
||||
// ExecutionContext restartContext = getJobRepository().getLastJobExecution(jobInstance).getExecutionContext();
|
||||
// execution.setExecutionContext(restartContext);
|
||||
// } else {
|
||||
// execution.setExecutionContext(new ExecutionContext());
|
||||
// }
|
||||
|
||||
StepExecution currentStepExecution = null;
|
||||
int startedCount = 0;
|
||||
|
||||
@@ -111,16 +111,5 @@ public interface JobRepository {
|
||||
* @return the execution count of the step within the given job instance.
|
||||
*/
|
||||
int getStepExecutionCount(JobInstance jobInstance, Step step);
|
||||
|
||||
/**
|
||||
* @return the execution count of the given job instance.
|
||||
*/
|
||||
int getJobExecutionCount(JobInstance jobInstance);
|
||||
|
||||
/**
|
||||
* @return the last execution of the given job instance.
|
||||
*/
|
||||
JobExecution getLastJobExecution(JobInstance jobInstance);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
private static class JobExecutionRowMapper implements RowMapper {
|
||||
private class JobExecutionRowMapper implements RowMapper {
|
||||
|
||||
private JobInstance job;
|
||||
|
||||
@@ -208,6 +208,7 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements
|
||||
jobExecution.setEndTime(rs.getTimestamp(3));
|
||||
jobExecution.setStatus(BatchStatus.getStatus(rs.getString(4)));
|
||||
jobExecution.setExitStatus(new ExitStatus("Y".equals(rs.getString(5)), rs.getString(6), rs.getString(7)));
|
||||
jobExecution.setExecutionContext(findExecutionContext(jobExecution));
|
||||
return jobExecution;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.springframework.batch.core.repository.JobRestartException;
|
||||
import org.springframework.batch.core.repository.dao.JobExecutionDao;
|
||||
import org.springframework.batch.core.repository.dao.JobInstanceDao;
|
||||
import org.springframework.batch.core.repository.dao.StepExecutionDao;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -152,6 +153,7 @@ public class SimpleJobRepository implements JobRepository {
|
||||
*/
|
||||
|
||||
JobInstance jobInstance = jobInstanceDao.getJobInstance(job, jobParameters);
|
||||
ExecutionContext executionContext;
|
||||
|
||||
// existing job instance found
|
||||
if (jobInstance != null) {
|
||||
@@ -174,13 +176,16 @@ public class SimpleJobRepository implements JobRepository {
|
||||
+ ". If you want to run this job again, change the parameters.");
|
||||
}
|
||||
}
|
||||
executionContext = jobExecutionDao.getLastJobExecution(jobInstance).getExecutionContext();
|
||||
}
|
||||
else {
|
||||
// no job found, create one
|
||||
jobInstance = jobInstanceDao.createJobInstance(job, jobParameters);
|
||||
executionContext = new ExecutionContext();
|
||||
}
|
||||
|
||||
JobExecution jobExecution = new JobExecution(jobInstance);
|
||||
jobExecution.setExecutionContext(executionContext);
|
||||
|
||||
// Save the JobExecution so that it picks up an ID (useful for clients
|
||||
// monitoring asynchronous executions):
|
||||
@@ -290,28 +295,5 @@ public class SimpleJobRepository implements JobRepository {
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return number of executions of the given job instance
|
||||
*/
|
||||
public int getJobExecutionCount(JobInstance jobInstance) {
|
||||
|
||||
return jobExecutionDao.findJobExecutions(jobInstance).size();
|
||||
}
|
||||
|
||||
public JobExecution getLastJobExecution(JobInstance jobInstance) {
|
||||
List jobExecutions = jobExecutionDao.findJobExecutions(jobInstance);
|
||||
if (jobExecutions.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
JobExecution lastExecution = (JobExecution) jobExecutions.get(0);
|
||||
for (Iterator iterator = jobExecutions.iterator(); iterator.hasNext();) {
|
||||
JobExecution exec = (JobExecution) iterator.next();
|
||||
if (lastExecution.getStartTime().getTime() < exec.getStartTime().getTime()) {
|
||||
lastExecution = exec;
|
||||
}
|
||||
}
|
||||
return lastExecution;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user