diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/explore/JobExplorer.java b/spring-batch-core/src/main/java/org/springframework/batch/core/explore/JobExplorer.java index 7e5ef85fd..fe888caf5 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/explore/JobExplorer.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/explore/JobExplorer.java @@ -21,6 +21,7 @@ import java.util.Set; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.StepExecution; +import org.springframework.batch.item.ExecutionContext; /** * Entry point for browsing executions of running or historical jobs and steps. @@ -45,7 +46,11 @@ public interface JobExplorer { List getJobInstances(String jobName, int start, int count); /** - * Retrieve a {@link JobExecution} by its id. + * Retrieve a {@link JobExecution} by its id. The complete object graph for + * this execution should be returned (unless otherwise indicated) including + * the parent {@link JobInstance} and associated {@link ExecutionContext} + * and {@link StepExecution} instances (also including their execution + * contexts). * * @param executionId the job execution id * @return the {@link JobExecution} with this id, or null if not found @@ -54,11 +59,15 @@ public interface JobExplorer { /** * Retrieve a {@link StepExecution} by its id and parent - * {@link JobExecution} id. + * {@link JobExecution} id. The execution context for the step should be + * available in the result, and the parent job execution should have its + * primitive properties, but may not contain the job instance information. * * @param jobExecutionId the parent job execution id * @param stepExecutionId the step execution id * @return the {@link StepExecution} with this id, or null if not found + * + * @see #getJobExecution(Long) */ StepExecution getStepExecution(Long jobExecutionId, Long stepExecutionId); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/SimpleJobExplorer.java b/spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/SimpleJobExplorer.java index dc92ea4bc..43cafa95f 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/SimpleJobExplorer.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/SimpleJobExplorer.java @@ -57,9 +57,8 @@ public class SimpleJobExplorer implements JobExplorer { SimpleJobExplorer() { } - public SimpleJobExplorer(JobInstanceDao jobInstanceDao, - JobExecutionDao jobExecutionDao, StepExecutionDao stepExecutionDao, - ExecutionContextDao ecDao) { + public SimpleJobExplorer(JobInstanceDao jobInstanceDao, JobExecutionDao jobExecutionDao, + StepExecutionDao stepExecutionDao, ExecutionContextDao ecDao) { super(); this.jobInstanceDao = jobInstanceDao; this.jobExecutionDao = jobExecutionDao; @@ -75,8 +74,7 @@ public class SimpleJobExplorer implements JobExplorer { * org.springframework.batch.core.JobInstance) */ public List getJobExecutions(JobInstance jobInstance) { - List executions = jobExecutionDao - .findJobExecutions(jobInstance); + List executions = jobExecutionDao.findJobExecutions(jobInstance); for (JobExecution jobExecution : executions) { getJobExecutionDependencies(jobExecution); } @@ -91,8 +89,7 @@ public class SimpleJobExplorer implements JobExplorer { * (java.lang.String) */ public Set findRunningJobExecutions(String jobName) { - Set executions = jobExecutionDao - .findRunningJobExecutions(jobName); + Set executions = jobExecutionDao.findRunningJobExecutions(jobName); for (JobExecution jobExecution : executions) { getJobExecutionDependencies(jobExecution); } @@ -110,12 +107,14 @@ public class SimpleJobExplorer implements JobExplorer { if (executionId == null) { return null; } - JobExecution jobExecution = jobExecutionDao - .getJobExecution(executionId); + JobExecution jobExecution = jobExecutionDao.getJobExecution(executionId); if (jobExecution == null) { return null; } getJobExecutionDependencies(jobExecution); + for (StepExecution stepExecution : jobExecution.getStepExecutions()) { + getStepExecutionDependencies(stepExecution); + } return jobExecution; } @@ -127,12 +126,11 @@ public class SimpleJobExplorer implements JobExplorer { * .lang.Long) */ public StepExecution getStepExecution(Long jobExecutionId, Long executionId) { - JobExecution jobExecution = getJobExecution(jobExecutionId); + JobExecution jobExecution = jobExecutionDao.getJobExecution(jobExecutionId); if (jobExecution == null) { return null; } - StepExecution stepExecution = stepExecutionDao.getStepExecution( - jobExecution, executionId); + StepExecution stepExecution = stepExecutionDao.getStepExecution(jobExecution, executionId); getStepExecutionDependencies(stepExecution); return stepExecution; } @@ -155,12 +153,13 @@ public class SimpleJobExplorer implements JobExplorer { * org.springframework.batch.core.explore.JobExplorer#getLastJobInstances * (java.lang.String, int) */ - public List getJobInstances(String jobName, int start, - int count) { + public List getJobInstances(String jobName, int start, int count) { return jobInstanceDao.getJobInstances(jobName, start, count); } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see org.springframework.batch.core.explore.JobExplorer#getJobNames() */ public List getJobNames() { @@ -176,15 +175,13 @@ public class SimpleJobExplorer implements JobExplorer { JobInstance jobInstance = jobInstanceDao.getJobInstance(jobExecution); stepExecutionDao.addStepExecutions(jobExecution); jobExecution.setJobInstance(jobInstance); - jobExecution.setExecutionContext(ecDao - .getExecutionContext(jobExecution)); + jobExecution.setExecutionContext(ecDao.getExecutionContext(jobExecution)); } private void getStepExecutionDependencies(StepExecution stepExecution) { if (stepExecution != null) { - stepExecution.setExecutionContext(ecDao - .getExecutionContext(stepExecution)); + stepExecution.setExecutionContext(ecDao.getExecutionContext(stepExecution)); } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/SimpleJobExplorerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/SimpleJobExplorerTests.java index 31be09f4f..16d122853 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/SimpleJobExplorerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/explore/support/SimpleJobExplorerTests.java @@ -59,7 +59,7 @@ public class SimpleJobExplorerTests extends TestCase { private ExecutionContextDao ecDao; - private JobExecution jobExecution = new JobExecution(jobInstance, 123L); + private JobExecution jobExecution = new JobExecution(jobInstance, 1234L); public void setUp() throws Exception { @@ -95,13 +95,11 @@ public class SimpleJobExplorerTests extends TestCase { @Test public void testGetStepExecution() throws Exception { - expect(jobExecutionDao.getJobExecution(123L)).andReturn(jobExecution); + expect(jobExecutionDao.getJobExecution(jobExecution.getId())).andReturn(jobExecution); StepExecution stepExecution = jobExecution.createStepExecution("foo"); expect(stepExecutionDao.getStepExecution(jobExecution, 123L)) .andReturn(stepExecution); - expect(ecDao.getExecutionContext(jobExecution)).andReturn(null); expect(ecDao.getExecutionContext(stepExecution)).andReturn(null); - stepExecutionDao.addStepExecutions(jobExecution); expectLastCall(); replay(jobExecutionDao, stepExecutionDao, ecDao); jobExplorer.getStepExecution(jobExecution.getId(), 123L); @@ -110,10 +108,8 @@ public class SimpleJobExplorerTests extends TestCase { @Test public void testGetStepExecutionMissing() throws Exception { - expect(jobExecutionDao.getJobExecution(123L)).andReturn(jobExecution); - stepExecutionDao.addStepExecutions(jobExecution); + expect(jobExecutionDao.getJobExecution(jobExecution.getId())).andReturn(jobExecution); expectLastCall(); - expect(ecDao.getExecutionContext(jobExecution)).andReturn(null); expect(stepExecutionDao.getStepExecution(jobExecution, 123L)) .andReturn(null); replay(jobExecutionDao, stepExecutionDao, ecDao); @@ -123,7 +119,7 @@ public class SimpleJobExplorerTests extends TestCase { @Test public void testGetStepExecutionMissingJobExecution() throws Exception { - expect(jobExecutionDao.getJobExecution(123L)).andReturn(null); + expect(jobExecutionDao.getJobExecution(jobExecution.getId())).andReturn(null); replay(jobExecutionDao, stepExecutionDao, ecDao); assertNull(jobExplorer.getStepExecution(jobExecution.getId(), 123L)); verify(jobExecutionDao, stepExecutionDao, ecDao);