IN PROGRESS - issue BATCH-340: Refactor JobRepository for greater clarity and consistency.
http://jira.springframework.org/browse/BATCH-340 Removed no-op update(StepInstance) and update(JobInstance) repository methods
This commit is contained in:
@@ -66,17 +66,6 @@ public interface JobRepository {
|
||||
public JobExecution createJobExecution(Job job, JobParameters jobParameters)
|
||||
throws JobExecutionAlreadyRunningException;
|
||||
|
||||
/**
|
||||
* Update a Job.
|
||||
*
|
||||
* Preconditions: Job must contain a valid ID. This can be ensured by first
|
||||
* obtaining a job from findOrCreateJob.
|
||||
*
|
||||
* @param job
|
||||
* @see JobInstance
|
||||
*/
|
||||
public void update(JobInstance jobInstance);
|
||||
|
||||
/**
|
||||
* Save or Update a {@link JobExecution}. If no ID is found a new instance
|
||||
* will be saved. If an ID does exist it will be updated. The ID should only
|
||||
@@ -91,18 +80,6 @@ public interface JobRepository {
|
||||
*/
|
||||
public void saveOrUpdate(JobExecution jobExecution);
|
||||
|
||||
/**
|
||||
* Update a step.
|
||||
*
|
||||
* Preconditions: {@link StepInstance} must contain a valid ID. This can be
|
||||
* ensured by first obtaining a {@link JobInstance} from findOrCreateJob,
|
||||
* and accessing it's step list.
|
||||
*
|
||||
* @param step
|
||||
* @see StepInstance
|
||||
*/
|
||||
public void update(StepInstance stepInstance);
|
||||
|
||||
/**
|
||||
* Save or Update a StepExecution. If no ID is found a new instance will be
|
||||
* created. (saved). If an ID does exist it will be updated. It is not
|
||||
|
||||
@@ -123,9 +123,7 @@ public class SimpleJob extends JobSupport {
|
||||
}
|
||||
|
||||
private void updateStatus(JobExecution jobExecution, BatchStatus status) {
|
||||
JobInstance jobIntance = jobExecution.getJobInstance();
|
||||
jobExecution.setStatus(status);
|
||||
jobRepository.update(jobIntance);
|
||||
jobRepository.saveOrUpdate(jobExecution);
|
||||
}
|
||||
|
||||
|
||||
@@ -187,7 +187,7 @@ public class SimpleJobRepository implements JobRepository {
|
||||
if (lastExecution.getStartTime().getTime() < execution.getStartTime().getTime()) {
|
||||
lastExecution = execution;
|
||||
}
|
||||
|
||||
|
||||
if (execution.isRunning()) {
|
||||
throw new JobExecutionAlreadyRunningException("A job execution for this job is already running: "
|
||||
+ jobInstance);
|
||||
@@ -243,18 +243,6 @@ public class SimpleJobRepository implements JobRepository {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing job. A job must have been obtained from the
|
||||
* findOrCreateJob method, otherwise it is likely that the id is incorrect
|
||||
* or non-existant.
|
||||
*
|
||||
* @param job to be updated.
|
||||
* @throws IllegalArgumentException if Job or it's Id is null.
|
||||
*/
|
||||
public void update(JobInstance job) {
|
||||
//TODO no-op to be removed
|
||||
}
|
||||
|
||||
/**
|
||||
* Save or Update the given StepExecution. If it's id is null, it will be
|
||||
* saved and an id will be set, otherwise it will be updated. It should be
|
||||
@@ -282,23 +270,6 @@ public class SimpleJobRepository implements JobRepository {
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the given step.
|
||||
*
|
||||
* @param StepInstance to be updated.
|
||||
* @throws IllegalArgumentException if step or it's id is null.
|
||||
*/
|
||||
public void update(StepInstance step) {
|
||||
|
||||
Assert.notNull(step, "Step cannot be null.");
|
||||
Assert.notNull(step.getId(), "Step cannot be updated if it's ID is null. It must be obtained"
|
||||
+ "from SimpleJobRepository.findOrCreateJob to be considered valid.");
|
||||
|
||||
//TODO no-op to be removed
|
||||
//stepInstanceDao.updateStepInstance(step);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Convenience method for creating a new job. A new job is created by
|
||||
* calling {@link JobDao#createJob(JobRuntimeInformation)} and then it's
|
||||
* list of StepConfigurations is passed to the createSteps method.
|
||||
@@ -311,7 +282,7 @@ public class SimpleJobRepository implements JobRepository {
|
||||
return jobInstance;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Create steps based on the given Job and list of Steps.
|
||||
*/
|
||||
private List createStepInstances(JobInstance job, List steps) {
|
||||
|
||||
@@ -430,9 +430,7 @@ public class ChunkedStep extends AbstractStep {
|
||||
* @param status the status to set
|
||||
*/
|
||||
private void updateStatus(StepExecution stepExecution, BatchStatus status) {
|
||||
StepInstance step = stepExecution.getStep();
|
||||
stepExecution.setStatus(status);
|
||||
jobRepository.update(step);
|
||||
jobRepository.saveOrUpdate(stepExecution);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -528,9 +528,7 @@ public class SimpleStepExecutor implements InitializingBean {
|
||||
* @param status the status to set
|
||||
*/
|
||||
private void updateStatus(StepExecution stepExecution, BatchStatus status) {
|
||||
StepInstance step = stepExecution.getStep();
|
||||
stepExecution.setStatus(status);
|
||||
jobRepository.update(step);
|
||||
jobRepository.saveOrUpdate(stepExecution);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -356,26 +356,6 @@ public class SimpleJobRepositoryTests extends TestCase {
|
||||
jobRepository.saveOrUpdate(jobExecution);
|
||||
}
|
||||
|
||||
public void testUpdateStep() {
|
||||
|
||||
StepInstance step = new StepInstance(null);
|
||||
|
||||
// failure scenario - id not set
|
||||
try {
|
||||
jobRepository.update(step);
|
||||
fail();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
// expected
|
||||
}
|
||||
|
||||
// successful update
|
||||
step = new StepInstance(new Long(0L));
|
||||
// stepDao.updateStepInstance(step);
|
||||
stepDaoControl.replay();
|
||||
jobRepository.update(step);
|
||||
}
|
||||
|
||||
public void testUpdateStepExecution() {
|
||||
StepExecution stepExecution = new StepExecution(new StepInstance(new Long(10L)), null, new Long(1));
|
||||
stepExecution.setId(new Long(11));
|
||||
|
||||
@@ -178,11 +178,9 @@ public class ChunkedStepTests extends TestCase {
|
||||
// JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
// StepExecution stepExecution = new StepExecution(step, jobExecutionContext);
|
||||
|
||||
repository.update(stepInstance);
|
||||
repository.saveOrUpdate(stepExecution);
|
||||
repository.saveOrUpdate(stepExecution);
|
||||
repository.saveOrUpdate(stepExecution);
|
||||
repository.update(stepInstance);
|
||||
repository.saveOrUpdate(stepExecution);
|
||||
repository.saveOrUpdate(stepExecution);
|
||||
repository.saveOrUpdate(stepExecution);
|
||||
|
||||
@@ -122,9 +122,7 @@ public class JdbcJobRepositoryTests extends AbstractTransactionalDataSourceSprin
|
||||
cacheJobIds(execution);
|
||||
execution.setEndTime(new Timestamp(System.currentTimeMillis()));
|
||||
repository.saveOrUpdate(execution);
|
||||
JobInstance job = execution.getJobInstance();
|
||||
execution.setStatus(BatchStatus.FAILED);
|
||||
repository.update(job);
|
||||
setComplete();
|
||||
endTransaction();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user