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 4c059e060..269224f02 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 @@ -126,7 +126,7 @@ public class SimpleJobExplorer implements JobExplorer { private void getJobExecutionDependencies(JobExecution jobExecution){ JobInstance jobInstance = jobInstanceDao.getJobInstance(jobExecution); - stepExecutionDao.getStepExecutions(jobExecution); + stepExecutionDao.addStepExecutions(jobExecution); jobExecution.setJobInstance(jobInstance); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java index f4d12fd73..a4c4526af 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java @@ -220,10 +220,9 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement } } - public List getStepExecutions(JobExecution jobExecution) { - List executions = getJdbcTemplate().query(getQuery(GET_STEP_EXECUTIONS), - new StepExecutionRowMapper(jobExecution), jobExecution.getId()); - return executions; + public void addStepExecutions(JobExecution jobExecution) { + getJdbcTemplate().query(getQuery(GET_STEP_EXECUTIONS), new StepExecutionRowMapper(jobExecution), + jobExecution.getId()); } private static class StepExecutionRowMapper implements ParameterizedRowMapper { diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapStepExecutionDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapStepExecutionDao.java index 354bf096c..0ef3d61b7 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapStepExecutionDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapStepExecutionDao.java @@ -99,10 +99,10 @@ public class MapStepExecutionDao implements StepExecutionDao { return executionsByStepExecutionId.get(stepExecutionId); } - public List getStepExecutions(JobExecution jobExecution) { + public void addStepExecutions(JobExecution jobExecution) { Map executions = executionsByJobExecutionId.get(jobExecution.getId()); if (executions == null || executions.isEmpty()) { - return Collections.emptyList(); + return; } List result = new ArrayList(executions.values()); Collections.sort(result, new Comparator() { @@ -117,6 +117,5 @@ public class MapStepExecutionDao implements StepExecutionDao { copy.add(copy(exec)); } jobExecution.addStepExecutions(copy); - return copy; } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/StepExecutionDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/StepExecutionDao.java index c3b74852d..8a9ee047b 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/StepExecutionDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/StepExecutionDao.java @@ -16,7 +16,6 @@ package org.springframework.batch.core.repository.dao; -import java.util.List; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.StepExecution; @@ -56,8 +55,7 @@ public interface StepExecutionDao { * Retrieve all the {@link StepExecution} for the parent {@link JobExecution}. * * @param jobExecution the parent job execution - * @return a list of {@link StepExecution} */ - List getStepExecutions(JobExecution jobExecution); + void addStepExecutions(JobExecution jobExecution); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java index b4677fc62..c0a157e4d 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java @@ -186,8 +186,8 @@ public class SimpleJobRepository implements JobRepository { List jobExecutions = jobExecutionDao.findJobExecutions(jobInstance); List stepExecutions = new ArrayList(jobExecutions.size()); for (JobExecution jobExecution : jobExecutions) { - List allStepExecutions = stepExecutionDao.getStepExecutions(jobExecution); - for (StepExecution stepExecution : allStepExecutions) { + stepExecutionDao.addStepExecutions(jobExecution); + for (StepExecution stepExecution : jobExecution.getStepExecutions()) { if (stepName.equals(stepExecution.getStepName())) { stepExecutions.add(stepExecution); } @@ -216,8 +216,8 @@ public class SimpleJobRepository implements JobRepository { int count = 0; List jobExecutions = jobExecutionDao.findJobExecutions(jobInstance); for (JobExecution jobExecution : jobExecutions) { - List allStepExecutions = stepExecutionDao.getStepExecutions(jobExecution); - for (StepExecution stepExecution : allStepExecutions) { + stepExecutionDao.addStepExecutions(jobExecution); + for (StepExecution stepExecution : jobExecution.getStepExecutions()) { if (stepName.equals(stepExecution.getStepName())) { count++; } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/exlore/support/MapJobExplorerIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/exlore/support/MapJobExplorerIntegrationTests.java index 0c0c4dd85..c38022115 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/exlore/support/MapJobExplorerIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/exlore/support/MapJobExplorerIntegrationTests.java @@ -46,6 +46,9 @@ public class MapJobExplorerIntegrationTests { @Test public void testRunningJobExecution() throws Exception { + + MapJobRepositoryFactoryBean.clear(); + SimpleJobLauncher jobLauncher = new SimpleJobLauncher(); MapJobRepositoryFactoryBean repositoryFactory = new MapJobRepositoryFactoryBean(); ResourcelessTransactionManager transactionManager = new ResourcelessTransactionManager(); @@ -55,6 +58,7 @@ public class MapJobExplorerIntegrationTests { jobLauncher.setJobRepository(jobRepository); jobLauncher.setTaskExecutor(new SimpleAsyncTaskExecutor()); jobLauncher.afterPropertiesSet(); + SimpleJob job = new SimpleJob("job"); TaskletStep step = new TaskletStep("step"); step.setTasklet(new Tasklet() { @@ -71,12 +75,16 @@ public class MapJobExplorerIntegrationTests { job.addStep(step); job.setJobRepository(jobRepository); job.afterPropertiesSet(); + jobLauncher.run(job, new JobParametersBuilder().addString("test", getClass().getName()).toJobParameters()); + Thread.sleep(500L); JobExplorer explorer = (JobExplorer) new MapJobExplorerFactoryBean().getObject(); Set executions = explorer.findRunningJobExecutions("job"); assertEquals(1, executions.size()); assertEquals(1, executions.iterator().next().getStepExecutions().size()); + block = false; + } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/exlore/support/SimpleJobExplorerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/exlore/support/SimpleJobExplorerTests.java index a35747510..9441c9e13 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/exlore/support/SimpleJobExplorerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/exlore/support/SimpleJobExplorerTests.java @@ -18,6 +18,7 @@ package org.springframework.batch.core.exlore.support; import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.expectLastCall; import static org.easymock.EasyMock.replay; import static org.easymock.EasyMock.verify; @@ -69,7 +70,8 @@ public class SimpleJobExplorerTests extends TestCase { public void testGetJobExecution() throws Exception { expect(jobExecutionDao.getJobExecution(123L)).andReturn(jobExecution); expect(jobInstanceDao.getJobInstance(jobExecution)).andReturn(jobInstance); - expect(stepExecutionDao.getStepExecutions(jobExecution)).andReturn(null); + stepExecutionDao.addStepExecutions(jobExecution); + expectLastCall(); replay(jobExecutionDao, jobInstanceDao, stepExecutionDao); jobExplorer.getJobExecution(123L); verify(jobExecutionDao, jobInstanceDao, stepExecutionDao); @@ -87,7 +89,8 @@ public class SimpleJobExplorerTests extends TestCase { public void testGetStepExecution() throws Exception { expect(jobExecutionDao.getJobExecution(123L)).andReturn(jobExecution); expect(stepExecutionDao.getStepExecution(jobExecution, 123L)).andReturn(null); - expect(stepExecutionDao.getStepExecutions(jobExecution)).andReturn(null); + stepExecutionDao.addStepExecutions(jobExecution); + expectLastCall(); replay(jobExecutionDao, stepExecutionDao); jobExplorer.getStepExecution(jobExecution.getId(), 123L); verify(jobExecutionDao, stepExecutionDao); @@ -97,7 +100,8 @@ public class SimpleJobExplorerTests extends TestCase { public void testFindRunningJobExecutions() throws Exception { expect(jobExecutionDao.findRunningJobExecutions("job")).andReturn(Collections.singleton(jobExecution)); expect(jobInstanceDao.getJobInstance(jobExecution)).andReturn(jobInstance); - expect(stepExecutionDao.getStepExecutions(jobExecution)).andReturn(null); + stepExecutionDao.addStepExecutions(jobExecution); + expectLastCall(); replay(jobExecutionDao, jobInstanceDao, stepExecutionDao); jobExplorer.findRunningJobExecutions("job"); verify(jobExecutionDao, jobInstanceDao, stepExecutionDao); @@ -107,7 +111,8 @@ public class SimpleJobExplorerTests extends TestCase { public void testFindJobExecutions() throws Exception { expect(jobExecutionDao.findJobExecutions(jobInstance)).andReturn(Collections.singletonList(jobExecution)); expect(jobInstanceDao.getJobInstance(jobExecution)).andReturn(jobInstance); - expect(stepExecutionDao.getStepExecutions(jobExecution)).andReturn(null); + stepExecutionDao.addStepExecutions(jobExecution); + expectLastCall(); replay(jobExecutionDao, jobInstanceDao, stepExecutionDao); jobExplorer.getJobExecutions(jobInstance); verify(jobExecutionDao, jobInstanceDao, stepExecutionDao); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractStepExecutionDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractStepExecutionDaoTests.java index adbf9d258..aa14fce7b 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractStepExecutionDaoTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractStepExecutionDaoTests.java @@ -21,9 +21,9 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; +import java.util.Collection; import java.util.Collections; import java.util.Date; -import java.util.List; import org.junit.Before; import org.junit.Test; @@ -131,8 +131,9 @@ public abstract class AbstractStepExecutionDaoTests extends AbstractTransactiona stepExecution.setRollbackCount(3); dao.saveStepExecution(stepExecution); - List retrieved = dao.getStepExecutions(jobExecution); - assertStepExecutionsAreEqual(stepExecution, retrieved.get(0)); + dao.addStepExecutions(jobExecution); + Collection retrieved = jobExecution.getStepExecutions(); + assertStepExecutionsAreEqual(stepExecution, retrieved.iterator().next()); } @Transactional @@ -229,8 +230,9 @@ public abstract class AbstractStepExecutionDaoTests extends AbstractTransactiona @Test public void testGetStepExecutionsWhenNoneExist() throws Exception { - assertEquals("empty list is returned if no stepExecutions exist for given jobExecution", Collections - .emptyList(), dao.getStepExecutions(jobExecution)); + int count = jobExecution.getStepExecutions().size(); + dao.addStepExecutions(jobExecution); + assertEquals("Incorrect size of collection", count, jobExecution.getStepExecutions().size()); } private void assertStepExecutionsAreEqual(StepExecution expected, StepExecution actual) { diff --git a/spring-batch-samples/src/main/resources/jobs/iosample/jdbcCursor.xml b/spring-batch-samples/src/main/resources/jobs/iosample/jdbcCursor.xml index 207fa4f91..630113c89 100644 --- a/spring-batch-samples/src/main/resources/jobs/iosample/jdbcCursor.xml +++ b/spring-batch-samples/src/main/resources/jobs/iosample/jdbcCursor.xml @@ -1,31 +1,31 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + diff --git a/spring-batch-samples/src/main/resources/jobs/skipSampleJob.xml b/spring-batch-samples/src/main/resources/jobs/skipSampleJob.xml index f211eba31..8f8ace253 100644 --- a/spring-batch-samples/src/main/resources/jobs/skipSampleJob.xml +++ b/spring-batch-samples/src/main/resources/jobs/skipSampleJob.xml @@ -1,36 +1,36 @@ - - - - - + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + @@ -41,7 +41,7 @@ - + @@ -56,72 +56,72 @@ - - - - - - - - - - - stepName - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + stepName + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spring-batch-samples/src/main/resources/jobs/tradeJob.xml b/spring-batch-samples/src/main/resources/jobs/tradeJob.xml index 073043698..d4855f52d 100644 --- a/spring-batch-samples/src/main/resources/jobs/tradeJob.xml +++ b/spring-batch-samples/src/main/resources/jobs/tradeJob.xml @@ -1,118 +1,118 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file