diff --git a/core/src/main/java/org/springframework/batch/core/domain/JobInstance.java b/core/src/main/java/org/springframework/batch/core/domain/JobInstance.java index 1db6d1680..d8d804433 100644 --- a/core/src/main/java/org/springframework/batch/core/domain/JobInstance.java +++ b/core/src/main/java/org/springframework/batch/core/domain/JobInstance.java @@ -41,13 +41,21 @@ public class JobInstance extends Entity { private int jobExecutionCount; + /** + * @deprecated should only be used by Hibernate + */ public JobInstance() { this(null); } - public JobInstance(Long id) { + public JobInstance(JobIdentifier identifier, Long id) { super(); setId(id); + this.identifier = identifier; + } + + public JobInstance(JobIdentifier identifier) { + this(identifier, null); } public BatchStatus getStatus() { @@ -87,15 +95,6 @@ public class JobInstance extends Entity { return identifier; } - /** - * Public setter for the identifier. - * - * @param identifier the identifier to set - */ - public void setIdentifier(JobIdentifier identifier) { - this.identifier = identifier; - } - /** * @return the identifier name if there is one */ diff --git a/core/src/main/java/org/springframework/batch/core/runtime/JobExecutionRegistry.java b/core/src/main/java/org/springframework/batch/core/runtime/JobExecutionRegistry.java index 38e8229dd..4aef274fc 100644 --- a/core/src/main/java/org/springframework/batch/core/runtime/JobExecutionRegistry.java +++ b/core/src/main/java/org/springframework/batch/core/runtime/JobExecutionRegistry.java @@ -33,16 +33,14 @@ public interface JobExecutionRegistry { /** * Register a job instance and obtain the runtime context of the * execution. - * - * @param runtimeInformation the {@link JobRuntimeInformation} that can be + * @param job containing the {@link JobRuntimeInformation} that can be * used to identify this execution in subsequent calls to the registry. Must * not be null. - * @param job * @param the {@link JobInstance} instance to register. * * @throws NullPointerException if the first parameter is null. */ - JobExecutionContext register(JobIdentifier jobIdentifier, JobInstance job); + JobExecutionContext register(JobInstance job); /** * Check if a given {@link JobExecution}, or one with the same id property, diff --git a/core/src/test/java/org/springframework/batch/core/domain/JobInstanceTests.java b/core/src/test/java/org/springframework/batch/core/domain/JobInstanceTests.java index fc4c68070..ae43e847b 100644 --- a/core/src/test/java/org/springframework/batch/core/domain/JobInstanceTests.java +++ b/core/src/test/java/org/springframework/batch/core/domain/JobInstanceTests.java @@ -27,13 +27,13 @@ import junit.framework.TestCase; */ public class JobInstanceTests extends TestCase { - private JobInstance instance = new JobInstance(new Long(11)); + private JobInstance instance = new JobInstance(null, new Long(11)); /** * Test method for {@link org.springframework.batch.core.domain.JobInstance#JobInstance()}. */ public void testJobInstance() { - assertNull(new JobInstance().getId()); + assertNull(new JobInstance(null).getId()); } /** @@ -76,7 +76,7 @@ public class JobInstanceTests extends TestCase { */ public void testGetIdentifier() { assertEquals(null, instance.getIdentifier()); - instance.setIdentifier(new JobIdentifier() { + instance = new JobInstance(new JobIdentifier() { public String getName() { return "foo"; } @@ -89,7 +89,7 @@ public class JobInstanceTests extends TestCase { */ public void testGetName() { assertEquals(null, instance.getName()); - instance.setIdentifier(new JobIdentifier() { + instance = new JobInstance(new JobIdentifier() { public String getName() { return "foo"; } diff --git a/core/src/test/java/org/springframework/batch/core/domain/StepInstanceTests.java b/core/src/test/java/org/springframework/batch/core/domain/StepInstanceTests.java index 60260a40f..e87c4d9d2 100644 --- a/core/src/test/java/org/springframework/batch/core/domain/StepInstanceTests.java +++ b/core/src/test/java/org/springframework/batch/core/domain/StepInstanceTests.java @@ -71,7 +71,7 @@ public class StepInstanceTests extends TestCase { */ public void testGetJob() { assertEquals(null, instance.getJob()); - JobInstance job = new JobInstance(); + JobInstance job = new JobInstance(null); instance.setJob(job); assertEquals(job, instance.getJob()); } @@ -101,12 +101,12 @@ public class StepInstanceTests extends TestCase { */ public void testGetJobId() { assertEquals(null, instance.getJobId()); - instance.setJob(new JobInstance(new Long(23))); + instance.setJob(new JobInstance(null, new Long(23))); assertEquals(23, instance.getJobId().longValue()); } public void testEqualsWithSameIdentifier() throws Exception { - JobInstance job = new JobInstance(new Long(100)); + JobInstance job = new JobInstance(null, new Long(100)); StepInstance step1 = new StepInstance(new Long(0)); StepInstance step2 = new StepInstance(new Long(0)); step1.setJob(job); diff --git a/core/src/test/java/org/springframework/batch/core/runtime/JobExecutionContextTests.java b/core/src/test/java/org/springframework/batch/core/runtime/JobExecutionContextTests.java index abade62f6..0d594b2bf 100644 --- a/core/src/test/java/org/springframework/batch/core/runtime/JobExecutionContextTests.java +++ b/core/src/test/java/org/springframework/batch/core/runtime/JobExecutionContextTests.java @@ -113,6 +113,7 @@ public class JobExecutionContextTests extends TestCase { } private JobExecutionContext createContext(String name, int jobId) { - return new JobExecutionContext(new SimpleJobIdentifier(name), new JobInstance(new Long(jobId))); + JobIdentifier jobIdentifier = new SimpleJobIdentifier(name); + return new JobExecutionContext(jobIdentifier, new JobInstance(jobIdentifier, new Long(jobId))); } } diff --git a/core/src/test/java/org/springframework/batch/core/runtime/StepExecutionContextTests.java b/core/src/test/java/org/springframework/batch/core/runtime/StepExecutionContextTests.java index 86d9c96fe..4332e27fe 100644 --- a/core/src/test/java/org/springframework/batch/core/runtime/StepExecutionContextTests.java +++ b/core/src/test/java/org/springframework/batch/core/runtime/StepExecutionContextTests.java @@ -106,8 +106,9 @@ public class StepExecutionContextTests extends TestCase { * @return */ private StepExecutionContext createContext(String name, int jobId, int stepId) { - JobInstance job = new JobInstance(new Long(jobId)); - return new StepExecutionContext(new JobExecutionContext(new SimpleJobIdentifier(name), job), new StepInstance( + JobIdentifier jobIdentifier = new SimpleJobIdentifier(name); + JobInstance job = new JobInstance(jobIdentifier, new Long(jobId)); + return new StepExecutionContext(new JobExecutionContext(jobIdentifier, job), new StepInstance( new Long(stepId))); } }