OPEN - issue BATCH-90: StepExecution and StepExecutionContext are parallel domains, and StepExecution is by comparison anaemic

http://opensource.atlassian.com/projects/spring/browse/BATCH-90

Tidy the JobInstance up a bit (no need for setter of identifier)
This commit is contained in:
dsyer
2007-09-30 11:48:07 +00:00
parent 21a4ea540e
commit a2c03d271a
6 changed files with 23 additions and 24 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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