RESOLVED - issue BATCH-945: Add support for step and job name in late binding
Also added some null checks in SimpleJobExplorer
This commit is contained in:
@@ -6,5 +6,6 @@
|
||||
<classpathentry excluding="**/*.java" including="**" kind="src" output="bin/test-classes" path="src/test/resources"/>
|
||||
<classpathentry kind="con" path="org.devzuz.q.maven.jdt.core.mavenClasspathContainer"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
|
||||
<classpathentry kind="output" path="bin/classes"/>
|
||||
</classpath>
|
||||
|
||||
@@ -6,6 +6,11 @@
|
||||
<project>spring-batch-infrastructure</project>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
@@ -21,10 +26,18 @@
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
|
||||
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
|
||||
<nature>org.springframework.ide.eclipse.core.springnature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.devzuz.q.maven.jdt.core.mavenNature</nature>
|
||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project-modules id="moduleCoreId" project-version="1.5.0">
|
||||
<wb-module deploy-name="spring-batch-core">
|
||||
<wb-resource deploy-path="/" source-path="/src/main/java"/>
|
||||
<wb-resource deploy-path="/" source-path="/src/test/java"/>
|
||||
<wb-resource deploy-path="/" source-path="/src/main/resources"/>
|
||||
<wb-resource deploy-path="/" source-path="/src/test/resources"/>
|
||||
</wb-module>
|
||||
</project-modules>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<faceted-project>
|
||||
<fixed facet="jst.java"/>
|
||||
<fixed facet="jst.utility"/>
|
||||
<installed facet="jst.java" version="5.0"/>
|
||||
<installed facet="jst.utility" version="1.0"/>
|
||||
</faceted-project>
|
||||
@@ -91,6 +91,9 @@ public class SimpleJobExplorer implements JobExplorer {
|
||||
*/
|
||||
public JobExecution getJobExecution(Long executionId) {
|
||||
JobExecution jobExecution = jobExecutionDao.getJobExecution(executionId);
|
||||
if (jobExecution==null) {
|
||||
return null;
|
||||
}
|
||||
getJobExecutionDependencies(jobExecution);
|
||||
return jobExecution;
|
||||
}
|
||||
@@ -100,6 +103,9 @@ public class SimpleJobExplorer implements JobExplorer {
|
||||
*/
|
||||
public StepExecution getStepExecution(Long executionId, String stepName) {
|
||||
JobExecution jobExecution = getJobExecution(executionId);
|
||||
if (jobExecution==null) {
|
||||
return null;
|
||||
}
|
||||
return stepExecutionDao.getStepExecution(jobExecution, stepName);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,9 +21,11 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.springframework.batch.core.JobInstance;
|
||||
import org.springframework.batch.core.JobParameter;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
@@ -57,6 +59,40 @@ public class StepContext extends SynchronizedAttributeAccessor {
|
||||
this.stepExecution = stepExecution;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenient accessor for current step name identifier. Usually this is the
|
||||
* same as the bean name of the step that is executing (but might not be
|
||||
* e.g. in a partition).
|
||||
*
|
||||
* @return the step name identifier of the current {@link StepExecution}
|
||||
*/
|
||||
public String getStepName() {
|
||||
return stepExecution.getStepName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenient accessor for current job name identifier.
|
||||
*
|
||||
* @return the job name identifier of the enclosing {@link JobInstance}
|
||||
* associated with the current {@link StepExecution}
|
||||
*/
|
||||
public String getJobName() {
|
||||
Assert.state(stepExecution.getJobExecution() != null, "StepExecution does not have a JobExecution");
|
||||
Assert.state(stepExecution.getJobExecution().getJobInstance() != null,
|
||||
"StepExecution does not have a JobInstance");
|
||||
return stepExecution.getJobExecution().getJobInstance().getJobName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenient accessor for System properties to make it easy to access them
|
||||
* from placeholder expressions.
|
||||
*
|
||||
* @return the current System properties
|
||||
*/
|
||||
public Properties getSystemProperties() {
|
||||
return System.getProperties();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a map containing the items from the step {@link ExecutionContext}
|
||||
*/
|
||||
@@ -136,7 +172,7 @@ public class StepContext extends SynchronizedAttributeAccessor {
|
||||
|
||||
Map<String, Set<Runnable>> copy = Collections.unmodifiableMap(callbacks);
|
||||
|
||||
for(Entry<String, Set<Runnable>> entry : copy.entrySet()) {
|
||||
for (Entry<String, Set<Runnable>> entry : copy.entrySet()) {
|
||||
Set<Runnable> set = entry.getValue();
|
||||
for (Runnable callback : set) {
|
||||
if (callback != null) {
|
||||
|
||||
@@ -72,6 +72,14 @@ public class SimpleJobExplorerTests extends TestCase {
|
||||
verify(jobExecutionDao, jobInstanceDao, stepExecutionDao);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMissingGetJobExecution() throws Exception {
|
||||
expect(jobExecutionDao.getJobExecution(123L)).andReturn(null);
|
||||
replay(jobExecutionDao);
|
||||
assertNull(jobExplorer.getJobExecution(123L));
|
||||
verify(jobExecutionDao);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStepExecution() throws Exception {
|
||||
expect(jobExecutionDao.getJobExecution(123L)).andReturn(jobExecution);
|
||||
|
||||
@@ -41,7 +41,7 @@ public class StepContextTests {
|
||||
|
||||
private List<String> list = new ArrayList<String>();
|
||||
|
||||
private StepExecution stepExecution = new StepExecution("step", new JobExecution(0L), 1L);
|
||||
private StepExecution stepExecution = new StepExecution("step", new JobExecution(new JobInstance(2L, null, "job"), 0L), 1L);
|
||||
|
||||
private StepContext context = new StepContext(stepExecution);
|
||||
|
||||
@@ -133,6 +133,16 @@ public class StepContextTests {
|
||||
assertTrue(list.contains("spam"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStepName() throws Exception {
|
||||
assertEquals("step", context.getStepName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJobName() throws Exception {
|
||||
assertEquals("job", context.getJobName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStepExecutionContext() throws Exception {
|
||||
ExecutionContext executionContext = stepExecution.getExecutionContext();
|
||||
@@ -140,6 +150,12 @@ public class StepContextTests {
|
||||
assertEquals("bar", context.getStepExecutionContext().get("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSystemProperties() throws Exception {
|
||||
System.setProperty("foo", "bar");
|
||||
assertEquals("bar", context.getSystemProperties().getProperty("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJobExecutionContext() throws Exception {
|
||||
ExecutionContext executionContext = stepExecution.getJobExecution().getExecutionContext();
|
||||
|
||||
@@ -6,5 +6,6 @@
|
||||
<classpathentry excluding="**/*.java" kind="src" path="src/main/resources"/>
|
||||
<classpathentry kind="con" path="org.devzuz.q.maven.jdt.core.mavenClasspathContainer"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
|
||||
<classpathentry kind="output" path="bin/classes"/>
|
||||
</classpath>
|
||||
|
||||
@@ -25,8 +25,15 @@
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
|
||||
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
|
||||
<nature>org.springframework.ide.eclipse.core.springnature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.devzuz.q.maven.jdt.core.mavenNature</nature>
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project-modules id="moduleCoreId" project-version="1.5.0">
|
||||
<wb-module deploy-name="spring-batch-infrastructure">
|
||||
<wb-resource deploy-path="/" source-path="/src/test/java"/>
|
||||
<wb-resource deploy-path="/" source-path="/src/test/resources"/>
|
||||
<wb-resource deploy-path="/" source-path="/src/main/java"/>
|
||||
<wb-resource deploy-path="/" source-path="/src/main/resources"/>
|
||||
</wb-module>
|
||||
</project-modules>
|
||||
@@ -1,3 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<faceted-project>
|
||||
</faceted-project>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<faceted-project>
|
||||
<fixed facet="jst.java"/>
|
||||
<fixed facet="jst.utility"/>
|
||||
<installed facet="jst.java" version="5.0"/>
|
||||
<installed facet="jst.utility" version="1.0"/>
|
||||
</faceted-project>
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
Hello
|
||||
Reference in New Issue
Block a user