IN PROGRESS - issue BATCH-366: Do we still need StepInstance?

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

Killed StepInstance - test coverage temporarily low due to commenting obsolete tests (but sample jobs work fine).
This commit is contained in:
robokaso
2008-02-19 15:41:26 +00:00
parent d7b9cf9d92
commit 96c48bcbc5
54 changed files with 665 additions and 1321 deletions

View File

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

View File

@@ -31,7 +31,7 @@ import java.util.List;
*/
public class JobInstance extends Entity {
private List stepInstances = new ArrayList();
private List stepNames = new ArrayList();
private JobParameters jobParameters;
@@ -59,16 +59,16 @@ public class JobInstance extends Entity {
return lastExecution;
}
public List getStepInstances() {
return stepInstances;
public List getStepNames() {
return stepNames;
}
public void setStepInstances(List stepInstances) {
this.stepInstances = stepInstances;
public void setStepNames(List stepInstances) {
this.stepNames = stepInstances;
}
public void addStepInstance(StepInstance stepInstance) {
this.stepInstances.add(stepInstance);
public void addStepName(String stepName) {
this.stepNames.add(stepName);
}
public int getJobExecutionCount() {

View File

@@ -36,8 +36,8 @@ import org.springframework.batch.repeat.ExitStatus;
public class StepExecution extends Entity {
private JobExecution jobExecution;
private StepInstance step;
private String stepName;
private BatchStatus status = BatchStatus.STARTING;
@@ -75,9 +75,9 @@ public class StepExecution extends Entity {
* @param jobExecution the current job execution
* @param id the id of this execution
*/
public StepExecution(StepInstance step, JobExecution jobExecution, Long id) {
public StepExecution(String stepName, JobExecution jobExecution, Long id) {
super(id);
this.step = step;
this.stepName = stepName;
this.jobExecution = jobExecution;
}
@@ -87,8 +87,8 @@ public class StepExecution extends Entity {
* @param step the step to which this execution belongs
* @param jobExecution the current job execution
*/
public StepExecution(StepInstance step, JobExecution jobExecution) {
this(step, jobExecution, null);
public StepExecution(String stepName, JobExecution jobExecution) {
this(stepName, jobExecution, null);
}
/**
@@ -232,15 +232,10 @@ public class StepExecution extends Entity {
}
/**
* Returns the id for this step
*
* @return the id for this step
* @return the name of the step
*/
public Long getStepId() {
if (step != null) {
return step.getId();
}
return null;
public String getStepName() {
return stepName;
}
/**
@@ -261,16 +256,16 @@ public class StepExecution extends Entity {
* @see org.springframework.batch.container.common.domain.Entity#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
Object stepId = getStepId();
//TODO make sure the equality makes sense
Object jobExecutionId = getJobExecutionId();
if (stepId == null && jobExecutionId == null || !(obj instanceof StepExecution) || getId() == null) {
if (stepName == null && jobExecutionId == null || !(obj instanceof StepExecution) || getId() == null) {
return super.equals(obj);
}
StepExecution other = (StepExecution) obj;
if (stepId == null) {
if (stepName == null) {
return jobExecutionId.equals(other.getJobExecutionId());
}
return stepId.equals(other.getStepId())
return stepName.equals(other.getStepName())
&& (jobExecutionId == null || jobExecutionId.equals(other.getJobExecutionId()));
}
@@ -280,21 +275,16 @@ public class StepExecution extends Entity {
* @see org.springframework.batch.container.common.domain.Entity#hashCode()
*/
public int hashCode() {
Object stepId = getStepId();
Object jobExecutionId = getJobExecutionId();
return super.hashCode() + 31 * (stepId != null ? stepId.hashCode() : 0) + 91
return super.hashCode() + 31 * (stepName != null ? stepName.hashCode() : 0) + 91
* (jobExecutionId != null ? jobExecutionId.hashCode() : 0);
}
public String toString() {
return super.toString() + ", name=" + getName() + ", taskCount=" + taskCount + ", commitCount=" + commitCount
return super.toString() + ", name=" + stepName + ", taskCount=" + taskCount + ", commitCount=" + commitCount
+ ", rollbackCount=" + rollbackCount;
}
private String getName() {
return step == null ? null : step.getName();
}
/**
* @param exitStatus
*/
@@ -309,15 +299,6 @@ public class StepExecution extends Entity {
return exitStatus;
}
/**
* Accessor for the step governing this execution.
*
* @return the step
*/
public StepInstance getStep() {
return step;
}
/**
* Accessor for the execution context information of the enclosing job.
*

View File

@@ -1,108 +0,0 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.core.domain;
/**
* <p>
* Batch domain entity representing a step which is sequentially executed by a
* job. Logically, steps are identified as a function of a job plus each step's
* name. For example, job 'TestJob' which has 2 steps: "TestStep1" and
* "TestStep2". The first step can be thought of as identified by
* "TestJob.TestStep1". In relational terms this may be represented by a foreign
* key on the Job's ID. Therefore, Each step instance is uniquely identified by
* it's ID, which is obtained from a JobRepository. Two steps with the same name
* and same job can be considered the same step.
* </p>
*
* <p>
* Because each step represents a runnable batch artifact with it's own
* lifecycle, each step contains status and an execution count. Status
* represents the status of each step's last execution (such as started,
* completed, failed, etc) and execution count is the count of executions for
* this individual step. It should be noted that a restartable job will create a
* new step instance (the same logical step, with a different ID) for every run.
* </p>
*
* @author Lucas Ward
* @author Dave Syer
*
*/
public class StepInstance extends Entity {
private JobInstance jobInstance;
private StepExecution lastExecution;
private int stepExecutionCount = 0;
private String name;
/**
* Package private constructor for Hibernate only
*/
StepInstance() {
this(null);
}
public StepInstance(Long stepId) {
this(null, null, stepId);
}
public StepInstance(JobInstance job, String name) {
this(job, name, null);
}
public StepInstance(JobInstance job, String name, Long stepId) {
setId(stepId);
this.jobInstance = job;
this.name = name;
}
public int getStepExecutionCount() {
return stepExecutionCount;
}
public void setStepExecutionCount(int stepExecutionCount) {
this.stepExecutionCount = stepExecutionCount;
}
public JobInstance getJobInstance() {
return jobInstance;
}
public String getName() {
return name;
}
public Long getJobId() {
return jobInstance==null ? null : jobInstance.getId();
}
public void setLastExecution(StepExecution lastExecution) {
this.lastExecution = lastExecution;
}
public StepExecution getLastExecution() {
return lastExecution;
}
// @Override
public String toString() {
return super.toString() + ", name=" + name + " in " + jobInstance;
}
}

View File

@@ -92,4 +92,15 @@ public interface JobRepository {
*/
public void saveOrUpdate(StepExecution stepExecution);
/**
* @return the last execution of step for the given job instance.
*/
public StepExecution getLastStepExecution(JobInstance jobInstance, String stepName);
/**
* @return the execution count of the step within the given job instance.
*/
public int getStepExecutionCount(JobInstance jobInstance, String stepName);
}