RESOLVED - issue BATCH-406: jobInstance properties lastExecution and executionCount are useless
http://jira.springframework.org/browse/BATCH-406 removed lastExecution property and createExecution method
This commit is contained in:
@@ -26,8 +26,8 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* Trying to execute an existing JobIntance that has already completed
|
||||
* successfully will result in error. Error will be raised also for an attempt
|
||||
* to restart a failed JobInstance if the Job ({@link JobInstance#getJob()}) is not
|
||||
* restartable.
|
||||
* to restart a failed JobInstance if the Job ({@link JobInstance#getJob()})
|
||||
* is not restartable.
|
||||
*
|
||||
* @see Job
|
||||
* @see JobParameters
|
||||
@@ -44,24 +44,13 @@ public class JobInstance extends Entity {
|
||||
|
||||
private Job job;
|
||||
|
||||
private JobExecution lastExecution;
|
||||
|
||||
public JobInstance(Long id, JobParameters jobParameters, Job job) {
|
||||
super(id);
|
||||
Assert.notNull(job);
|
||||
this.jobParameters = jobParameters == null ? new JobParameters()
|
||||
: jobParameters;
|
||||
this.jobParameters = jobParameters == null ? new JobParameters() : jobParameters;
|
||||
this.job = job;
|
||||
}
|
||||
|
||||
public void setLastExecution(JobExecution lastExecution) {
|
||||
this.lastExecution = lastExecution;
|
||||
}
|
||||
|
||||
public JobExecution getLastExecution() {
|
||||
return lastExecution;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@link JobParameters}
|
||||
*/
|
||||
@@ -76,15 +65,8 @@ public class JobInstance extends Entity {
|
||||
return job == null ? null : job.getName();
|
||||
}
|
||||
|
||||
public JobExecution createJobExecution() {
|
||||
JobExecution newExecution = new JobExecution(this);
|
||||
this.setLastExecution(newExecution);
|
||||
return newExecution;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + ", JobParameters=[" + jobParameters + "]"
|
||||
+ ", Job=[" + job + "]";
|
||||
return super.toString() + ", JobParameters=[" + jobParameters + "]" + ", Job=[" + job + "]";
|
||||
}
|
||||
|
||||
public Job getJob() {
|
||||
|
||||
@@ -24,13 +24,6 @@ import junit.framework.TestCase;
|
||||
public class JobInstanceTests extends TestCase {
|
||||
|
||||
private JobInstance instance = new JobInstance(new Long(11), new JobParameters(), new JobSupport("job"));
|
||||
|
||||
public void testLastExecution(){
|
||||
JobExecution lastExecution = new JobExecution();
|
||||
assertNull(instance.getLastExecution());
|
||||
instance.setLastExecution(lastExecution);
|
||||
assertEquals(lastExecution, instance.getLastExecution());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link org.springframework.batch.core.domain.JobInstance#getIdentifier()}.
|
||||
@@ -44,12 +37,6 @@ public class JobInstanceTests extends TestCase {
|
||||
assertEquals("job", instance.getJob().getName());
|
||||
}
|
||||
|
||||
public void testCreateJobExecution(){
|
||||
JobExecution execution = instance.createJobExecution();
|
||||
assertNotNull(execution);
|
||||
assertEquals(execution, instance.getLastExecution());
|
||||
}
|
||||
|
||||
public void testCreateWithNulls(){
|
||||
try {
|
||||
new JobInstance(null, null, null);
|
||||
|
||||
@@ -61,7 +61,6 @@ public class SimpleJob extends AbstractJob {
|
||||
public void execute(JobExecution execution) throws InfrastructureException {
|
||||
|
||||
JobInstance jobInstance = execution.getJobInstance();
|
||||
jobInstance.setLastExecution(execution);
|
||||
|
||||
StepExecution currentStepExecution = null;
|
||||
int startedCount = 0;
|
||||
|
||||
@@ -139,8 +139,6 @@ public class SimpleJobRepository implements JobRepository {
|
||||
Assert.notNull(job, "Job must not be null.");
|
||||
Assert.notNull(jobParameters, "JobParameters must not be null.");
|
||||
|
||||
JobInstance jobInstance;
|
||||
|
||||
/*
|
||||
* Find all jobs matching the runtime information.
|
||||
*
|
||||
@@ -150,7 +148,7 @@ public class SimpleJobRepository implements JobRepository {
|
||||
* has finished.
|
||||
*/
|
||||
|
||||
jobInstance = jobInstanceDao.getJobInstance(job, jobParameters);
|
||||
JobInstance jobInstance = jobInstanceDao.getJobInstance(job, jobParameters);
|
||||
|
||||
// existing job instance found
|
||||
if (jobInstance != null) {
|
||||
@@ -159,40 +157,29 @@ public class SimpleJobRepository implements JobRepository {
|
||||
}
|
||||
|
||||
List executions = jobExecutionDao.findJobExecutions(jobInstance);
|
||||
JobExecution lastExecution = null;
|
||||
|
||||
// check for running executions and find the last started
|
||||
for (Iterator iterator = executions.iterator(); iterator.hasNext();) {
|
||||
JobExecution execution = (JobExecution) iterator.next();
|
||||
if (lastExecution == null) {
|
||||
lastExecution = execution;
|
||||
}
|
||||
if (execution.getStartTime() != null && lastExecution.getStartTime() != null
|
||||
&& lastExecution.getStartTime().getTime() < execution.getStartTime().getTime()) {
|
||||
lastExecution = execution;
|
||||
}
|
||||
|
||||
if (execution.isRunning()) {
|
||||
throw new JobExecutionAlreadyRunningException("A job execution for this job is already running: "
|
||||
+ jobInstance);
|
||||
}
|
||||
}
|
||||
jobInstance.setLastExecution(lastExecution);
|
||||
}
|
||||
else {
|
||||
// no job found, create one
|
||||
jobInstance = jobInstanceDao.createJobInstance(job, jobParameters);
|
||||
}
|
||||
|
||||
return generateJobExecution(jobInstance);
|
||||
|
||||
}
|
||||
|
||||
private JobExecution generateJobExecution(JobInstance jobInstance) {
|
||||
JobExecution execution = jobInstance.createJobExecution();
|
||||
|
||||
JobExecution jobExecution = new JobExecution(jobInstance);
|
||||
|
||||
// Save the JobExecution so that it picks up an ID (useful for clients
|
||||
// monitoring asynchronous executions):
|
||||
saveOrUpdate(execution);
|
||||
return execution;
|
||||
saveOrUpdate(jobExecution);
|
||||
|
||||
return jobExecution;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -105,12 +105,7 @@ public class SimpleJobRepositoryTests extends TestCase {
|
||||
|
||||
jobConfiguration.setSteps(stepConfigurations);
|
||||
|
||||
databaseJob = new JobInstance(new Long(1), jobParameters, jobConfiguration) {
|
||||
public JobExecution createJobExecution() {
|
||||
jobExecution = super.createJobExecution();
|
||||
return jobExecution;
|
||||
}
|
||||
};
|
||||
databaseJob = new JobInstance(new Long(1), jobParameters, jobConfiguration);
|
||||
|
||||
databaseStep1 = "dbStep1";
|
||||
databaseStep2 = "dbStep2";
|
||||
|
||||
@@ -81,7 +81,6 @@ public abstract class AbstractJobDaoTests extends AbstractTransactionalDataSourc
|
||||
jobExecution.setStartTime(jobExecutionStartTime);
|
||||
jobExecution.setStatus(BatchStatus.STARTED);
|
||||
jobExecutionDao.saveJobExecution(jobExecution);
|
||||
jobInstance.setLastExecution(jobExecution);
|
||||
}
|
||||
|
||||
public void testVersionIsNotNullForJob() throws Exception {
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.core.domain.JobExecution;
|
||||
import org.springframework.batch.core.domain.JobInstance;
|
||||
import org.springframework.batch.core.domain.JobParameters;
|
||||
import org.springframework.batch.execution.job.JobSupport;
|
||||
@@ -32,7 +33,7 @@ import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer
|
||||
*
|
||||
*/
|
||||
public class JdbcJobDaoQueryTests extends TestCase {
|
||||
|
||||
|
||||
JdbcJobExecutionDao jobExecutionDao;
|
||||
|
||||
List list = new ArrayList();
|
||||
@@ -42,7 +43,7 @@ public class JdbcJobDaoQueryTests extends TestCase {
|
||||
* @see junit.framework.TestCase#setUp()
|
||||
*/
|
||||
protected void setUp() throws Exception {
|
||||
|
||||
|
||||
jobExecutionDao = new JdbcJobExecutionDao();
|
||||
jobExecutionDao.setJobExecutionIncrementer(new DataFieldMaxValueIncrementer() {
|
||||
|
||||
@@ -69,7 +70,10 @@ public class JdbcJobDaoQueryTests extends TestCase {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
jobExecutionDao.saveJobExecution(new JobInstance(new Long(11), new JobParameters(), new JobSupport("testJob")).createJobExecution());
|
||||
JobExecution jobExecution = new JobExecution(new JobInstance(new Long(11), new JobParameters(), new JobSupport(
|
||||
"testJob")));
|
||||
|
||||
jobExecutionDao.saveJobExecution(jobExecution);
|
||||
assertEquals(1, list.size());
|
||||
String query = (String) list.get(0);
|
||||
assertTrue("Query did not contain FOO_:" + query, query.indexOf("FOO_") >= 0);
|
||||
|
||||
@@ -62,7 +62,7 @@ public class StepExecutionProxyResourceTests extends TestCase {
|
||||
protected void setUp() throws Exception {
|
||||
|
||||
jobInstance = new JobInstance(new Long(0), new JobParameters(), new JobSupport("testJob"));
|
||||
JobExecution jobExecution = jobInstance.createJobExecution();
|
||||
JobExecution jobExecution = new JobExecution(jobInstance);
|
||||
Step step = new StepSupport("bar");
|
||||
stepExecution = jobExecution.createStepExecution(step);
|
||||
resource.beforeStep(stepExecution);
|
||||
@@ -97,7 +97,7 @@ public class StepExecutionProxyResourceTests extends TestCase {
|
||||
resource.setFilePattern("foo/data/%JOB_NAME%/%job.key%-foo");
|
||||
jobInstance = new JobInstance(new Long(0), new JobParametersBuilder().addString("job.key", "spam")
|
||||
.toJobParameters(), new JobSupport("testJob"));
|
||||
JobExecution jobExecution = jobInstance.createJobExecution();
|
||||
JobExecution jobExecution = new JobExecution(jobInstance);
|
||||
Step step = new StepSupport("bar");
|
||||
resource.beforeStep(jobExecution.createStepExecution(step));
|
||||
doTestPathName("spam-foo", "foo" + pathsep + "data" + pathsep);
|
||||
|
||||
@@ -518,7 +518,7 @@ public class ItemOrientedStepTests extends TestCase {
|
||||
};
|
||||
itemOrientedStep.setItemProcessor(new SimpleItemHandler(itemReader, itemWriter));
|
||||
|
||||
JobExecution jobExecutionContext = jobInstance.createJobExecution();
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
StepExecution stepExecution = new StepExecution(itemOrientedStep, jobExecutionContext);
|
||||
|
||||
stepExecution.setExecutionContext(new ExecutionContext(PropertiesConverter.stringToProperties("foo=bar")));
|
||||
@@ -551,7 +551,7 @@ public class ItemOrientedStepTests extends TestCase {
|
||||
}
|
||||
});
|
||||
|
||||
JobExecution jobExecutionContext = jobInstance.createJobExecution();
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
StepExecution stepExecution = new StepExecution(itemOrientedStep, jobExecutionContext);
|
||||
|
||||
stepExecution.setExecutionContext(new ExecutionContext(PropertiesConverter.stringToProperties("foo=bar")));
|
||||
@@ -579,7 +579,7 @@ public class ItemOrientedStepTests extends TestCase {
|
||||
}
|
||||
});
|
||||
|
||||
JobExecution jobExecutionContext = jobInstance.createJobExecution();
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
StepExecution stepExecution = new StepExecution(itemOrientedStep, jobExecutionContext);
|
||||
|
||||
stepExecution.setExecutionContext(new ExecutionContext(PropertiesConverter.stringToProperties("foo=bar")));
|
||||
@@ -611,7 +611,7 @@ public class ItemOrientedStepTests extends TestCase {
|
||||
}
|
||||
});
|
||||
|
||||
JobExecution jobExecutionContext = jobInstance.createJobExecution();
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
StepExecution stepExecution = new StepExecution(itemOrientedStep, jobExecutionContext);
|
||||
|
||||
try {
|
||||
@@ -642,7 +642,7 @@ public class ItemOrientedStepTests extends TestCase {
|
||||
itemOrientedStep.setItemProcessor(new SimpleItemHandler(itemReader, itemWriter));
|
||||
itemOrientedStep.registerStream(itemReader);
|
||||
|
||||
JobExecution jobExecutionContext = jobInstance.createJobExecution();
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
StepExecution stepExecution = new StepExecution(itemOrientedStep, jobExecutionContext);
|
||||
|
||||
stepExecution.setExecutionContext(new ExecutionContext(PropertiesConverter.stringToProperties("foo=bar")));
|
||||
|
||||
Reference in New Issue
Block a user