IN PROGRESS - issue BATCH-340: Refactor JobRepository for greater clarity and consistency.

http://jira.springframework.org/browse/BATCH-340

more StepInstance heritage cleaned up - StepExecution refers to Step rather than stepName string
This commit is contained in:
robokaso
2008-02-25 17:21:46 +00:00
parent 59f884b832
commit 7368aa3541
25 changed files with 162 additions and 139 deletions

View File

@@ -143,8 +143,8 @@ public class JobExecution extends Entity {
*
* @param stepExecution
*/
public StepExecution createStepExecution(String stepName) {
StepExecution stepExecution = new StepExecution(stepName, this, null);
public StepExecution createStepExecution(Step step) {
StepExecution stepExecution = new StepExecution(step, this, null);
this.stepExecutions.add(stepExecution);
return stepExecution;
}

View File

@@ -20,6 +20,7 @@ import java.util.Date;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.util.Assert;
/**
* Batch domain object representation the execution of a step. Unlike
@@ -37,7 +38,7 @@ public class StepExecution extends Entity {
private JobExecution jobExecution;
private String stepName;
private Step step;
private BatchStatus status = BatchStatus.STARTING;
@@ -75,9 +76,10 @@ public class StepExecution extends Entity {
* @param jobExecution the current job execution
* @param id the id of this execution
*/
public StepExecution(String stepName, JobExecution jobExecution, Long id) {
public StepExecution(Step step, JobExecution jobExecution, Long id) {
super(id);
this.stepName = stepName;
Assert.notNull(step);
this.step = step;
this.jobExecution = jobExecution;
}
@@ -87,8 +89,8 @@ public class StepExecution extends Entity {
* @param step the step to which this execution belongs
* @param jobExecution the current job execution
*/
public StepExecution(String stepName, JobExecution jobExecution) {
this(stepName, jobExecution, null);
public StepExecution(Step step, JobExecution jobExecution) {
this(step, jobExecution, null);
}
/**
@@ -235,7 +237,7 @@ public class StepExecution extends Entity {
* @return the name of the step
*/
public String getStepName() {
return stepName;
return step.getName();
}
/**
@@ -258,14 +260,14 @@ public class StepExecution extends Entity {
public boolean equals(Object obj) {
//TODO make sure the equality makes sense
Object jobExecutionId = getJobExecutionId();
if (stepName == null && jobExecutionId == null || !(obj instanceof StepExecution) || getId() == null) {
if (step == null && jobExecutionId == null || !(obj instanceof StepExecution) || getId() == null) {
return super.equals(obj);
}
StepExecution other = (StepExecution) obj;
if (stepName == null) {
if (step == null) {
return jobExecutionId.equals(other.getJobExecutionId());
}
return stepName.equals(other.getStepName())
return step.getName().equals(other.getStepName())
&& (jobExecutionId == null || jobExecutionId.equals(other.getJobExecutionId()));
}
@@ -276,12 +278,12 @@ public class StepExecution extends Entity {
*/
public int hashCode() {
Object jobExecutionId = getJobExecutionId();
return super.hashCode() + 31 * (stepName != null ? stepName.hashCode() : 0) + 91
return super.hashCode() + 31 * (step.getName() != null ? step.getName().hashCode() : 0) + 91
* (jobExecutionId != null ? jobExecutionId.hashCode() : 0);
}
public String toString() {
return super.toString() + ", name=" + stepName + ", taskCount=" + taskCount + ", commitCount=" + commitCount
return super.toString() + ", name=" + step.getName() + ", taskCount=" + taskCount + ", commitCount=" + commitCount
+ ", rollbackCount=" + rollbackCount;
}

View File

@@ -130,12 +130,12 @@ public class JobExecutionTests extends TestCase {
public void testAddAndRemoveStepExecution() throws Exception {
assertEquals(0, execution.getStepExecutions().size());
execution.createStepExecution(null);
execution.createStepExecution(new StepSupport("stepName"));
assertEquals(1, execution.getStepExecutions().size());
}
public void testStop() throws Exception {
StepExecution stepExecution = execution.createStepExecution(null);
StepExecution stepExecution = execution.createStepExecution(new StepSupport("stepName"));
assertFalse(stepExecution.isTerminateOnly());
execution.stop();
assertTrue(stepExecution.isTerminateOnly());

View File

@@ -31,9 +31,10 @@ import org.springframework.batch.support.PropertiesConverter;
*/
public class StepExecutionTests extends TestCase {
private StepExecution execution = newStepExecution("stepName",
private StepExecution execution = newStepExecution(new StepSupport("stepName"),
new Long(23));
private StepExecution blankExecution = new StepExecution(new StepSupport("blank"), new JobExecution());
/**
* Test method for
* {@link org.springframework.batch.core.domain.JobExecution#JobExecution()}.
@@ -47,7 +48,7 @@ public class StepExecutionTests extends TestCase {
* {@link org.springframework.batch.core.domain.JobExecution#JobExecution()}.
*/
public void testStepExecutionWithNullId() {
assertNull(new StepExecution(null, null).getId());
assertNull(new StepExecution(new StepSupport("stepName"), new JobExecution()).getId());
}
/**
@@ -176,7 +177,7 @@ public class StepExecutionTests extends TestCase {
}
public void testToStringWithNullName() throws Exception {
String value = new StepExecution().toString();
String value = new StepExecution(new StepSupport(null), new JobExecution()).toString();
assertTrue("Should contain name=null: "+value, value.indexOf("name=null")>=0);
}
@@ -198,29 +199,30 @@ public class StepExecutionTests extends TestCase {
}
public void testEqualsWithSameIdentifier() throws Exception {
Entity step1 = newStepExecution("stepName", new Long(11));
Entity step2 = newStepExecution("stepName", new Long(11));
assertEquals(step1, step2);
Step step = new StepSupport("stepName");
Entity stepExecution1 = newStepExecution(step, new Long(11));
Entity stepExecution2 = newStepExecution(step, new Long(11));
assertEquals(stepExecution1, stepExecution2);
}
public void testEqualsWithNull() throws Exception {
Entity step = newStepExecution("stepName", new Long(11));
assertFalse(step.equals(null));
Entity stepExecution = newStepExecution(new StepSupport("stepName"), new Long(11));
assertFalse(stepExecution.equals(null));
}
public void testEqualsWithNullIdentifiers() throws Exception {
Entity step = newStepExecution("stepName", new Long(11));
assertFalse(step.equals(new StepExecution()));
Entity stepExecution = newStepExecution(new StepSupport("stepName"), new Long(11));
assertFalse(stepExecution.equals(blankExecution));
}
public void testEqualsWithNullJob() throws Exception {
Entity step = newStepExecution(null, new Long(11));
assertFalse(step.equals(new StepExecution()));
Entity stepExecution = newStepExecution(new StepSupport("stepName"), new Long(11));
assertFalse(stepExecution.equals(blankExecution));
}
public void testEqualsWithNullStep() throws Exception {
Entity step = newStepExecution("stepName", null);
assertFalse(step.equals(new StepExecution()));
Entity stepExecution = newStepExecution(new StepSupport("stepName"), null);
assertFalse(stepExecution.equals(blankExecution));
}
public void testEqualsWithSelf() throws Exception {
@@ -228,16 +230,17 @@ public class StepExecutionTests extends TestCase {
}
public void testEqualsWithDifferent() throws Exception {
Entity step = newStepExecution("foo", new Long(13));
assertFalse(execution.equals(step));
Entity stepExecution = newStepExecution(new StepSupport("foo"), new Long(13));
assertFalse(execution.equals(stepExecution));
}
public void testEqualsWithNullStepId() throws Exception {
execution = newStepExecution(null, new Long(31));
assertEquals(null, execution.getStepName());
StepExecution step = newStepExecution(null, new Long(31));
assertEquals(step.getJobExecutionId(), execution.getJobExecutionId());
assertTrue(execution.equals(step));
Step step = new StepSupport("name");
execution = newStepExecution(step, new Long(31));
assertEquals("name", execution.getStepName());
StepExecution stepExecution = newStepExecution(step, new Long(31));
assertEquals(stepExecution.getJobExecutionId(), execution.getJobExecutionId());
assertTrue(execution.equals(stepExecution));
}
public void testHashCode() throws Exception {
@@ -247,7 +250,7 @@ public class StepExecutionTests extends TestCase {
public void testHashCodeWithNullIds() throws Exception {
assertTrue("Hash code not same as parent",
new Entity(execution.getId()).hashCode() != new StepExecution()
new Entity(execution.getId()).hashCode() != blankExecution
.hashCode());
}
@@ -259,9 +262,9 @@ public class StepExecutionTests extends TestCase {
assertTrue(set.contains(execution));
}
private StepExecution newStepExecution(String stepName, Long long2) {
private StepExecution newStepExecution(Step step, Long long2) {
JobInstance job = new JobInstance(new Long(3), new JobParameters(), new JobSupport("testJob"));
StepExecution execution = new StepExecution(stepName, new JobExecution(job, long2), new Long(4));
StepExecution execution = new StepExecution(step, new JobExecution(job, long2), new Long(4));
return execution;
}