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 149604dd5..6862877b7 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 @@ -45,7 +45,7 @@ public class SimpleJobExplorer implements JobExplorer { private JobInstanceDao jobInstanceDao; private JobExecutionDao jobExecutionDao; - + private StepExecutionDao stepExecutionDao; private ExecutionContextDao ecDao; @@ -57,7 +57,9 @@ 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; @@ -65,78 +67,118 @@ public class SimpleJobExplorer implements JobExplorer { this.ecDao = ecDao; } - /* (non-Javadoc) - * @see org.springframework.batch.core.explore.JobExplorer#findJobExecutions(org.springframework.batch.core.JobInstance) + /* + * (non-Javadoc) + * + * @see + * org.springframework.batch.core.explore.JobExplorer#findJobExecutions( + * org.springframework.batch.core.JobInstance) */ public List getJobExecutions(JobInstance jobInstance) { - List executions = jobExecutionDao.findJobExecutions(jobInstance); - for(JobExecution jobExecution:executions){ + List executions = jobExecutionDao + .findJobExecutions(jobInstance); + for (JobExecution jobExecution : executions) { getJobExecutionDependencies(jobExecution); } return executions; } - /* (non-Javadoc) - * @see org.springframework.batch.core.explore.JobExplorer#findRunningJobExecutions(java.lang.String) + /* + * (non-Javadoc) + * + * @see + * org.springframework.batch.core.explore.JobExplorer#findRunningJobExecutions + * (java.lang.String) */ public Set findRunningJobExecutions(String jobName) { - Set executions = jobExecutionDao.findRunningJobExecutions(jobName); - for(JobExecution jobExecution:executions){ + Set executions = jobExecutionDao + .findRunningJobExecutions(jobName); + for (JobExecution jobExecution : executions) { getJobExecutionDependencies(jobExecution); } return executions; } - /* (non-Javadoc) - * @see org.springframework.batch.core.explore.JobExplorer#getJobExecution(java.lang.Long) + /* + * (non-Javadoc) + * + * @see + * org.springframework.batch.core.explore.JobExplorer#getJobExecution(java + * .lang.Long) */ public JobExecution getJobExecution(Long executionId) { - JobExecution jobExecution = jobExecutionDao.getJobExecution(executionId); - if (jobExecution==null) { + if (executionId == null) { + return null; + } + JobExecution jobExecution = jobExecutionDao + .getJobExecution(executionId); + if (jobExecution == null) { return null; } getJobExecutionDependencies(jobExecution); return jobExecution; } - - /* (non-Javadoc) - * @see org.springframework.batch.core.explore.JobExplorer#getStepExecution(java.lang.Long) + + /* + * (non-Javadoc) + * + * @see + * org.springframework.batch.core.explore.JobExplorer#getStepExecution(java + * .lang.Long) */ public StepExecution getStepExecution(Long jobExecutionId, Long executionId) { - StepExecution stepExecution = stepExecutionDao.getStepExecution(getJobExecution(jobExecutionId), executionId); + JobExecution jobExecution = getJobExecution(jobExecutionId); + if (jobExecution == null) { + return null; + } + StepExecution stepExecution = stepExecutionDao.getStepExecution( + jobExecution, executionId); getStepExecutionDependencies(stepExecution); return stepExecution; } - /* (non-Javadoc) - * @see org.springframework.batch.core.explore.JobExplorer#getJobInstance(java.lang.Long) + /* + * (non-Javadoc) + * + * @see + * org.springframework.batch.core.explore.JobExplorer#getJobInstance(java + * .lang.Long) */ public JobInstance getJobInstance(Long instanceId) { return jobInstanceDao.getJobInstance(instanceId); } - /* (non-Javadoc) - * @see org.springframework.batch.core.explore.JobExplorer#getLastJobInstances(java.lang.String, int) + /* + * (non-Javadoc) + * + * @see + * 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); } /* - * Find all dependencies for a JobExecution, including JobInstance (which requires JobParameters) - * plus StepExecutions + * Find all dependencies for a JobExecution, including JobInstance (which + * requires JobParameters) plus StepExecutions */ - private void getJobExecutionDependencies(JobExecution jobExecution){ - + private void getJobExecutionDependencies(JobExecution jobExecution) { + 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) { - stepExecution.setExecutionContext(ecDao.getExecutionContext(stepExecution)); + if (stepExecution != null) { + stepExecution.setExecutionContext(ecDao + .getExecutionContext(stepExecution)); + } } } 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 7277af07f..539408021 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 @@ -39,7 +39,7 @@ import org.springframework.batch.core.repository.dao.JobInstanceDao; import org.springframework.batch.core.repository.dao.StepExecutionDao; /** - * Test {@link SimpleJobExplorer}. + * Test {@link SimpleJobExplorer}. * * @author Dave Syer * @@ -49,13 +49,14 @@ public class SimpleJobExplorerTests extends TestCase { private SimpleJobExplorer jobExplorer; private JobExecutionDao jobExecutionDao; - + private JobInstanceDao jobInstanceDao; - + private StepExecutionDao stepExecutionDao; - private JobInstance jobInstance = new JobInstance(111L, new JobParameters(), "job"); - + private JobInstance jobInstance = new JobInstance(111L, + new JobParameters(), "job"); + private ExecutionContextDao ecDao; private JobExecution jobExecution = new JobExecution(jobInstance, 123L); @@ -67,14 +68,16 @@ public class SimpleJobExplorerTests extends TestCase { stepExecutionDao = createMock(StepExecutionDao.class); ecDao = createMock(ExecutionContextDao.class); - jobExplorer = new SimpleJobExplorer(jobInstanceDao, jobExecutionDao, stepExecutionDao, ecDao); + jobExplorer = new SimpleJobExplorer(jobInstanceDao, jobExecutionDao, + stepExecutionDao, ecDao); } @Test public void testGetJobExecution() throws Exception { expect(jobExecutionDao.getJobExecution(123L)).andReturn(jobExecution); - expect(jobInstanceDao.getJobInstance(jobExecution)).andReturn(jobInstance); + expect(jobInstanceDao.getJobInstance(jobExecution)).andReturn( + jobInstance); stepExecutionDao.addStepExecutions(jobExecution); expectLastCall(); replay(jobExecutionDao, jobInstanceDao, stepExecutionDao); @@ -94,7 +97,8 @@ public class SimpleJobExplorerTests extends TestCase { public void testGetStepExecution() throws Exception { expect(jobExecutionDao.getJobExecution(123L)).andReturn(jobExecution); StepExecution stepExecution = jobExecution.createStepExecution("foo"); - expect(stepExecutionDao.getStepExecution(jobExecution, 123L)).andReturn(stepExecution); + expect(stepExecutionDao.getStepExecution(jobExecution, 123L)) + .andReturn(stepExecution); expect(ecDao.getExecutionContext(jobExecution)).andReturn(null); expect(ecDao.getExecutionContext(stepExecution)).andReturn(null); stepExecutionDao.addStepExecutions(jobExecution); @@ -104,10 +108,33 @@ public class SimpleJobExplorerTests extends TestCase { verify(jobExecutionDao, stepExecutionDao, ecDao); } + @Test + public void testGetStepExecutionMissing() throws Exception { + expect(jobExecutionDao.getJobExecution(123L)).andReturn(jobExecution); + stepExecutionDao.addStepExecutions(jobExecution); + expectLastCall(); + expect(ecDao.getExecutionContext(jobExecution)).andReturn(null); + expect(stepExecutionDao.getStepExecution(jobExecution, 123L)) + .andReturn(null); + replay(jobExecutionDao, stepExecutionDao, ecDao); + assertNull(jobExplorer.getStepExecution(jobExecution.getId(), 123L)); + verify(jobExecutionDao, stepExecutionDao, ecDao); + } + + @Test + public void testGetStepExecutionMissingJobExecution() throws Exception { + expect(jobExecutionDao.getJobExecution(123L)).andReturn(null); + replay(jobExecutionDao, stepExecutionDao, ecDao); + assertNull(jobExplorer.getStepExecution(jobExecution.getId(), 123L)); + verify(jobExecutionDao, stepExecutionDao, ecDao); + } + @Test public void testFindRunningJobExecutions() throws Exception { - expect(jobExecutionDao.findRunningJobExecutions("job")).andReturn(Collections.singleton(jobExecution)); - expect(jobInstanceDao.getJobInstance(jobExecution)).andReturn(jobInstance); + expect(jobExecutionDao.findRunningJobExecutions("job")).andReturn( + Collections.singleton(jobExecution)); + expect(jobInstanceDao.getJobInstance(jobExecution)).andReturn( + jobInstance); stepExecutionDao.addStepExecutions(jobExecution); expectLastCall(); replay(jobExecutionDao, jobInstanceDao, stepExecutionDao); @@ -117,8 +144,10 @@ public class SimpleJobExplorerTests extends TestCase { @Test public void testFindJobExecutions() throws Exception { - expect(jobExecutionDao.findJobExecutions(jobInstance)).andReturn(Collections.singletonList(jobExecution)); - expect(jobInstanceDao.getJobInstance(jobExecution)).andReturn(jobInstance); + expect(jobExecutionDao.findJobExecutions(jobInstance)).andReturn( + Collections.singletonList(jobExecution)); + expect(jobInstanceDao.getJobInstance(jobExecution)).andReturn( + jobInstance); stepExecutionDao.addStepExecutions(jobExecution); expectLastCall(); replay(jobExecutionDao, jobInstanceDao, stepExecutionDao); @@ -138,7 +167,8 @@ public class SimpleJobExplorerTests extends TestCase { @Test public void testGetLastJobInstances() throws Exception { jobInstanceDao.getJobInstances("foo", 0, 1); - EasyMock.expectLastCall().andReturn(Collections.singletonList(jobInstance)); + EasyMock.expectLastCall().andReturn( + Collections.singletonList(jobInstance)); replay(jobExecutionDao, jobInstanceDao, stepExecutionDao); jobExplorer.getJobInstances("foo", 0, 1); verify(jobExecutionDao, jobInstanceDao, stepExecutionDao); diff --git a/spring-batch-infrastructure/.classpath b/spring-batch-infrastructure/.classpath index 6886233c2..96489ff1c 100644 --- a/spring-batch-infrastructure/.classpath +++ b/spring-batch-infrastructure/.classpath @@ -5,7 +5,6 @@ - diff --git a/spring-batch-infrastructure/.project b/spring-batch-infrastructure/.project index 769e60e21..5f34e05f7 100644 --- a/spring-batch-infrastructure/.project +++ b/spring-batch-infrastructure/.project @@ -1,37 +1,43 @@ - spring-batch-infrastructure - The Spring Batch Infrastructure is a set of low-level components, interfaces and tools for batch processing applications and optimisations. + spring-batch-infrastructure + The Spring Batch Infrastructure is a set of low-level components, interfaces and tools for batch processing applications and optimisations. - - - - org.eclipse.wst.common.project.facet.core.builder - - - - org.eclipse.jdt.core.javabuilder - - - - org.springframework.ide.eclipse.core.springbuilder - - - - org.eclipse.wst.validation.validationbuilder - - - - org.maven.ide.eclipse.maven2Builder - - - - - org.eclipse.jem.workbench.JavaEMFNature - org.eclipse.wst.common.modulecore.ModuleCoreNature - org.springframework.ide.eclipse.core.springnature - org.eclipse.jdt.core.javanature - org.eclipse.wst.common.project.facet.core.nature - org.maven.ide.eclipse.maven2Nature - - \ No newline at end of file + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.springframework.ide.eclipse.core.springbuilder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + + org.maven.ide.eclipse.maven2Nature + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.springframework.ide.eclipse.core.springnature + org.eclipse.jdt.core.javanature + org.eclipse.wst.common.project.facet.core.nature + + diff --git a/spring-batch-infrastructure/pom.xml b/spring-batch-infrastructure/pom.xml index c1a0aec46..e6e24b622 100644 --- a/spring-batch-infrastructure/pom.xml +++ b/spring-batch-infrastructure/pom.xml @@ -1,184 +1,187 @@ - - 4.0.0 - spring-batch-infrastructure - 2.0.2.CI-SNAPSHOT - jar - Infrastructure - The Spring Batch Infrastructure is a set of low-level components, interfaces and tools for batch processing applications and optimisations. + + 4.0.0 + spring-batch-infrastructure + 2.0.2.CI-SNAPSHOT + jar + Infrastructure + - - org.springframework.batch - spring-batch-parent - 2.0.2.CI-SNAPSHOT - ../spring-batch-parent - - - - tiger - - 1.5 - - - - stax - stax - - - - - - - - com.springsource.bundlor - com.springsource.bundlor.maven - - - org.apache.maven.plugins - maven-antrun-plugin - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - junit:junit - - - - - - - - junit - junit - - - org.easymock - easymock - - - org.aspectj - aspectjrt - test - - - org.aspectj - aspectjweaver - test - - - cglib - cglib-nodep - true - - - org.apache.geronimo.specs - geronimo-jms_1.1_spec - true - - - commons-logging - commons-logging - - - log4j - log4j - true - - - commons-lang - commons-lang - true - - - commons-io - commons-io - test - - - hsqldb - hsqldb - test - - - org.hibernate - hibernate - true - - - org.hibernate - hibernate-entitymanager - true - - - org.hibernate - hibernate-annotations - true - - - org.apache.geronimo.specs - geronimo-jta_1.1_spec - true - - - org.apache.ibatis - ibatis-sqlmap - true - - - javax.persistence - persistence-api - true - - - org.springframework.ws - spring-oxm - true - - - org.springframework - spring-aop - true - - - org.springframework - spring-core - - - org.springframework - spring-jdbc - true - - - org.springframework - spring-jms - true - - - org.springframework - spring-orm - true - - - org.springframework - spring-test - - - org.springframework - spring-tx - true - - - - - - org.codehaus.mojo - emma-maven-plugin - 1.0-alpha-1 - - - + + org.springframework.batch + spring-batch-parent + 2.0.2.CI-SNAPSHOT + ../spring-batch-parent + + + + tiger + + 1.5 + + + + stax + stax + + + + + + + + com.springsource.bundlor + com.springsource.bundlor.maven + + + org.apache.maven.plugins + maven-antrun-plugin + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + junit:junit + + + + + + + + junit + junit + + + org.easymock + easymock + + + org.aspectj + aspectjrt + test + + + org.aspectj + aspectjweaver + test + + + cglib + cglib-nodep + true + + + org.apache.geronimo.specs + geronimo-jms_1.1_spec + true + + + commons-logging + commons-logging + + + log4j + log4j + true + + + commons-lang + commons-lang + true + + + commons-io + commons-io + test + + + hsqldb + hsqldb + test + + + org.hibernate + hibernate + true + + + org.hibernate + hibernate-entitymanager + true + + + org.hibernate + hibernate-annotations + true + + + org.apache.geronimo.specs + geronimo-jta_1.1_spec + true + + + org.apache.ibatis + ibatis-sqlmap + true + + + javax.persistence + persistence-api + true + + + org.springframework.ws + spring-oxm + true + + + org.springframework + spring-aop + true + + + org.springframework + spring-core + + + org.springframework + spring-jdbc + true + + + org.springframework + spring-jms + true + + + org.springframework + spring-orm + true + + + org.springframework + spring-test + + + org.springframework + spring-tx + true + + + + + + org.codehaus.mojo + emma-maven-plugin + 1.0-alpha-1 + + +