BATCH-295: JobLauncher now only contains one method: run(Job, JobInstanceProperties). Misc. other changes were made to facilitate.

This commit is contained in:
lucasward
2008-01-22 23:40:40 +00:00
parent 2e68e82e84
commit 4f69c324e6
9 changed files with 63 additions and 64 deletions

View File

@@ -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;
}

View File

@@ -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();
}
}
}

View File

@@ -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() {

View File

@@ -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);
}

View File

@@ -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;
/**

View File

@@ -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 {

View File

@@ -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(){

View File

@@ -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;
}
}

View File

@@ -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);