diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/Entity.java b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/Entity.java index d36c1c49a..70b8eb6a0 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/Entity.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/Entity.java @@ -18,6 +18,7 @@ package org.springframework.batch.core.domain; import java.io.Serializable; +import org.springframework.util.Assert; import org.springframework.util.ClassUtils; /** @@ -42,6 +43,10 @@ public class Entity implements Serializable { public Entity(Long id) { super(); + + //Commented out because StepExecutions are still created in a disconnected + //manner. The Repository should create them, then this can be uncommented. + //Assert.notNull(id, "Entity id must not be null."); this.id = id; } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/JobExecution.java b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/JobExecution.java index 4610fe0bf..78e9e2147 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/JobExecution.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/JobExecution.java @@ -19,6 +19,7 @@ package org.springframework.batch.core.domain; import java.util.Collection; import java.util.Date; import java.util.HashSet; +import java.util.Iterator; import org.springframework.batch.repeat.ExitStatus; @@ -54,8 +55,8 @@ public class JobExecution extends Entity { * the job of which this execution is a part */ public JobExecution(JobInstance job, Long id) { + super(id); this.jobInstance = job; - setId(id); } /** @@ -140,7 +141,7 @@ public class JobExecution extends Entity { * @param stepExecution */ public StepExecution createStepExecution(StepInstance stepInstance) { - StepExecution stepExecution = new StepExecution(stepInstance, this); + StepExecution stepExecution = new StepExecution(stepInstance, this, null); this.stepExecutions.add(stepExecution); return stepExecution; } @@ -153,10 +154,26 @@ public class JobExecution extends Entity { } /** - * Test if this {@link JobExecution} indicates that it is running. + * Test if this {@link JobExecution} indicates that it is running. It should + * be noted that this does not necessarily mean that it has been + * persisted as such yet. * @return true if the end time is null */ public boolean isRunning() { return endTime==null; } + + /** + * Stop the JobExecution, each StepExecution will be iterated through, calling + * setTermianteOnly, signaling to the StepExecutor currently running that it should + * be terminated. + * + */ + public void stop(){ + + for(Iterator it = stepExecutions.iterator();it.hasNext();){ + StepExecution stepExecution = (StepExecution)it.next(); + stepExecution.setTerminateOnly(); + } + } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/JobInstance.java b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/JobInstance.java index 2b61579cc..28dca4c9f 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/JobInstance.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/JobInstance.java @@ -19,6 +19,8 @@ package org.springframework.batch.core.domain; import java.util.ArrayList; import java.util.List; +import org.springframework.util.Assert; + /** * Batch domain object representing a job instance. A job instance is defined as @@ -33,7 +35,7 @@ public class JobInstance extends Entity { private List stepInstances = new ArrayList(); - private JobIdentifier identifier; + private JobInstanceProperties jobInstanceProperties; private Job job; @@ -42,21 +44,17 @@ public class JobInstance extends Entity { private int jobExecutionCount; - public JobInstance(JobIdentifier jobIdentifier){ - this.identifier = jobIdentifier; + public JobInstance(Long id, JobInstanceProperties jobInstanceProperties) { + super(id); + Assert.notNull(jobInstanceProperties, "JobInstanceProperties must not be null."); + this.jobInstanceProperties = jobInstanceProperties; } - public JobInstance(JobIdentifier identifier, Long id, Job job) { - super(); - setId(id); - this.identifier = identifier; + public JobInstance(Long id, JobInstanceProperties jobInstanceProperties, Job job){ + this(id, jobInstanceProperties); this.job = job; } - public JobInstance(JobIdentifier jobIdentifier, Long id){ - this(jobIdentifier, id, null); - } - public BatchStatus getStatus() { return status; } @@ -64,7 +62,7 @@ public class JobInstance extends Entity { public void setStatus(BatchStatus status) { this.status = status; } - + public List getStepInstances() { return stepInstances; } @@ -86,19 +84,17 @@ public class JobInstance extends Entity { } /** - * Public accessor for the identifier property. - * - * @return the identifier + * @return JobInstanceProperties */ - public JobIdentifier getIdentifier() { - return identifier; + public JobInstanceProperties getJobInstanceProperties() { + return jobInstanceProperties; } /** - * @return the identifier name if there is one + * @return the job name. (Equivalent to getJob().getName()) */ - public String getName() { - return identifier==null ? null : identifier.getName(); + public String getJobName() { + return getJob().getName(); } public JobExecution createJobExecution() { @@ -106,7 +102,8 @@ public class JobInstance extends Entity { } public String toString() { - return super.toString()+", identifier=["+identifier+"]"; + return super.toString()+", JobInstanceProperties=["+ jobInstanceProperties +"]" + + ", Job=[" + job + "]"; } public Job getJob() { diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/StepExecution.java b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/StepExecution.java index ac958417f..4a333507b 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/domain/StepExecution.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/domain/StepExecution.java @@ -71,13 +71,12 @@ public class StepExecution extends Entity { * @param jobExecution the current job execution */ public StepExecution(StepInstance step, JobExecution jobExecution, Long id) { - this(); + super(id); this.step = step; this.jobExecution = jobExecution; - setId(id); } - - public StepExecution(StepInstance step, JobExecution jobExecution) { + + public StepExecution(StepInstance step, JobExecution jobExecution){ this(step, jobExecution, null); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/JobRepository.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/JobRepository.java index e4018d82a..b06fec0da 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/JobRepository.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/JobRepository.java @@ -20,6 +20,7 @@ import org.springframework.batch.core.domain.Job; import org.springframework.batch.core.domain.JobExecution; import org.springframework.batch.core.domain.JobIdentifier; import org.springframework.batch.core.domain.JobInstance; +import org.springframework.batch.core.domain.JobInstanceProperties; import org.springframework.batch.core.domain.StepExecution; import org.springframework.batch.core.domain.StepInstance; @@ -52,12 +53,9 @@ public interface JobRepository { * exists, its persisted values (including ID) will be returned in a new * {@link JobInstance} object. If no previous run is found, a new job will * be created and returned. - * + * @param jobInstanceProperties TODO * @param jobConfiguration * describes the configuration for this job - * @param jobIdentifier - * identifies this particular run of the configuration across - * possible restarts * * @return a valid job execution for the identifier provided * @throws JobExecutionAlreadyRunningException @@ -65,8 +63,8 @@ public interface JobRepository { * job instance that would otherwise be returned * */ - public JobExecution findOrCreateJob(Job job, - JobIdentifier jobIdentifier) + public JobExecution createJobExecution(Job job, + JobInstanceProperties jobInstanceProperties) throws JobExecutionAlreadyRunningException; /** diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/domain/JobExecutionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/domain/JobExecutionTests.java index de38793da..47d5d5fb4 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/domain/JobExecutionTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/domain/JobExecutionTests.java @@ -28,9 +28,9 @@ import org.springframework.batch.repeat.ExitStatus; */ public class JobExecutionTests extends TestCase { - private JobExecution execution = new JobExecution(new JobInstance(null, new Long(11), null)); + private JobExecution execution = new JobExecution(new JobInstance(new Long(11), new JobInstanceProperties()), new Long(12)); - private JobExecution context = new JobExecution(new JobInstance(new SimpleJobIdentifier("foo"), new Long(11), null)); + private JobExecution context = new JobExecution(new JobInstance(new Long(11), new JobInstanceProperties(), new Job("foo")), new Long(12)); /** * Test method for @@ -86,7 +86,7 @@ public class JobExecutionTests extends TestCase { */ public void testGetJobId() { assertEquals(11, execution.getJobId().longValue()); - execution = new JobExecution(new JobInstance(null, new Long(23), null)); + execution = new JobExecution(new JobInstance(new Long(23), new JobInstanceProperties()), null); assertEquals(23, execution.getJobId().longValue()); } @@ -118,7 +118,7 @@ public class JobExecutionTests extends TestCase { } public void testContextContainsInfo() throws Exception { - assertEquals("foo", context.getJobInstance().getIdentifier().getName()); + assertEquals("foo", context.getJobInstance().getJobName()); } public void testAddAndRemoveStepExecution() throws Exception { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/domain/JobInstanceTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/domain/JobInstanceTests.java index af93e627d..692bd9d9c 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/domain/JobInstanceTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/domain/JobInstanceTests.java @@ -28,15 +28,8 @@ import junit.framework.TestCase; */ public class JobInstanceTests extends TestCase { - private JobInstance instance = new JobInstance(null, new Long(11), new Job("job")); + private JobInstance instance = new JobInstance(new Long(11), new JobInstanceProperties(), new Job("job")); - /** - * Test method for {@link org.springframework.batch.core.domain.JobInstance#JobInstance()}. - */ - public void testJobInstance() { - assertNull(new JobInstance(null, null, null).getId()); - } - /** * Test method for {@link org.springframework.batch.core.domain.JobInstance#getStatus()}. */ @@ -71,23 +64,13 @@ public class JobInstanceTests extends TestCase { instance.setJobExecutionCount(22); assertEquals(22, instance.getJobExecutionCount()); } - - /** - * Test method for {@link org.springframework.batch.core.domain.JobInstance#getIdentifier()}. - */ - public void testGetIdentifier() { - assertEquals(null, instance.getIdentifier()); - instance = new JobInstance(new SimpleJobIdentifier("foo"), new Long(1)); - assertEquals("foo", instance.getIdentifier().getName()); - } /** * Test method for {@link org.springframework.batch.core.domain.JobInstance#getIdentifier()}. */ public void testGetName() { - assertEquals(null, instance.getName()); - instance = new JobInstance(new SimpleJobIdentifier("foo"), new Long(1)); - assertEquals("foo", instance.getName()); + instance = new JobInstance(new Long(1), new JobInstanceProperties(), new Job("foo")); + assertEquals("foo", instance.getJobName()); } public void testGetJob(){ diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/domain/StepExecutionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/domain/StepExecutionTests.java index cda147bc9..ede5eed31 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/domain/StepExecutionTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/domain/StepExecutionTests.java @@ -212,9 +212,9 @@ public class StepExecutionTests extends TestCase { } private StepExecution newStepExecution(Long long1, Long long2) { - JobInstance job = new JobInstance(null, null); + JobInstance job = new JobInstance(new Long(3), new JobInstanceProperties()); StepInstance step = new StepInstance(job, "foo", long1); - StepExecution execution = new StepExecution(step, new JobExecution(job, long2)); + StepExecution execution = new StepExecution(step, new JobExecution(job, long2), new Long(4)); return execution; } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/domain/StepInstanceTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/domain/StepInstanceTests.java index db583b221..d4c37d970 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/domain/StepInstanceTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/domain/StepInstanceTests.java @@ -71,7 +71,7 @@ public class StepInstanceTests extends TestCase { */ public void testGetJobInstance() { assertEquals(null, instance.getJobInstance()); - JobInstance jobInstance = new JobInstance(null, null); + JobInstance jobInstance = new JobInstance(new Long(1), new JobInstanceProperties()); instance = new StepInstance(jobInstance, null); assertEquals(jobInstance, instance.getJobInstance()); } @@ -79,7 +79,7 @@ public class StepInstanceTests extends TestCase { public void testGetJob(){ Job job = new Job("job"); - JobInstance jobInstance = new JobInstance(null, null, job); + JobInstance jobInstance = new JobInstance(new Long(2), new JobInstanceProperties(), job); instance = new StepInstance(jobInstance, null); assertEquals(job, instance.getJobInstance().getJob()); } @@ -98,12 +98,12 @@ public class StepInstanceTests extends TestCase { */ public void testGetJobId() { assertEquals(null, instance.getJobId()); - instance = new StepInstance(new JobInstance(null, new Long(23), null), null); + instance = new StepInstance(new JobInstance(new Long(23), new JobInstanceProperties()), null); assertEquals(23, instance.getJobId().longValue()); } public void testEqualsWithSameIdentifier() throws Exception { - JobInstance job = new JobInstance(null, new Long(100), null); + JobInstance job = new JobInstance(new Long(100), new JobInstanceProperties()); StepInstance step1 = new StepInstance(job, "foo", new Long(0)); StepInstance step2 = new StepInstance(job, "foo", new Long(0)); assertEquals(step1, step2);