previousStatus == BatchStatus.STARTING ||
previousStatus == BatchStatus.STOPPING) {
throw MESSAGES.jobRestartException(executionId, previousStatus);
}
if (previousStatus == BatchStatus.FAILED || previousStatus == BatchStatus.STOPPED) {
final JobInstanceImpl jobInstance = (JobInstanceImpl) getJobInstance(executionId);
final List<JobExecution> executions = getJobExecutions(jobInstance);
final JobExecution mostRecentExecution = executions.get(executions.size() - 1);
if (executionId != mostRecentExecution.getExecutionId()) {
throw MESSAGES.jobExecutionNotMostRecentException(executionId, jobInstance.getInstanceId());
}
// the job may not have been loaded, e.g., when the restart is performed in a new JVM
final String jobName = originalToRestart.getJobName();
if (repository.getJob(jobName) == null) {
final Job jobDefined = ArchiveXmlLoader.loadJobXml(jobName, batchEnvironment.getClassLoader(), new ArrayList<Job>());
repository.addJob(jobDefined);
}
if (jobInstance.getUnsubstitutedJob() == null) {
jobInstance.setUnsubstitutedJob(repository.getJob(jobName));
}
try {
newExecutionId = invokeTransaction(new TransactionInvocation<Long>() {
@Override
public Long invoke() throws JobStartException, JobSecurityException {