Class SimpleJobRepository
- All Implemented Interfaces:
JobRepository
Implementation of JobRepository
that stores job instances, job executions, and
step executions using the injected DAOs.
- Author:
- Lucas Ward, Dave Syer, Robert Kasanicky, David Turanski, Mahmoud Ben Hassine, Baris Cubukcuoglu, Parikshit Dutta
- See Also:
-
Constructor Summary
ConstructorDescriptionSimpleJobRepository
(JobInstanceDao jobInstanceDao, JobExecutionDao jobExecutionDao, StepExecutionDao stepExecutionDao, ExecutionContextDao ecDao) -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(StepExecution stepExecution) Save theStepExecution
and itsExecutionContext
.void
addAll
(Collection<StepExecution> stepExecutions) Save a collection ofStepExecution
s and eachExecutionContext
.createJobExecution
(String jobName, JobParameters jobParameters) createJobInstance
(String jobName, JobParameters jobParameters) Create a newJobInstance
with the name and job parameters provided.void
deleteJobExecution
(JobExecution jobExecution) Delete the job execution object graph (ie the job execution with its execution context, all related step executions and their executions contexts, as well as associated job parameters)void
deleteJobInstance
(JobInstance jobInstance) Delete the job instance object graph (ie the job instance with all associated job executions along with their respective object graphs as specified inJobRepository.deleteJobExecution(JobExecution)
).void
deleteStepExecution
(StepExecution stepExecution) Delete the step execution along with its execution context.findJobExecutions
(JobInstance jobInstance) Return allJobExecution
s for givenJobInstance
, sorted backwards by creation order (so the first element is the most recent).findJobInstancesByName
(String jobName, int start, int count) Fetch the last job instances with the provided name, sorted backwards by primary key, using a 'like' criteriagetJobInstance
(String jobName, JobParameters jobParameters) Retrieve the names of all job instances sorted alphabetically - i.e.getLastJobExecution
(String jobName, JobParameters jobParameters) getLastStepExecution
(JobInstance jobInstance, String stepName) long
getStepExecutionCount
(JobInstance jobInstance, String stepName) boolean
isJobInstanceExists
(String jobName, JobParameters jobParameters) Check if an instance of this job already exists with the parameters provided.void
update
(JobExecution jobExecution) Update theJobExecution
(but not itsExecutionContext
).void
update
(StepExecution stepExecution) Update theStepExecution
(but not itsExecutionContext
).void
updateExecutionContext
(JobExecution jobExecution) Persist the updatedExecutionContext
of the givenJobExecution
.void
updateExecutionContext
(StepExecution stepExecution) Persist the updatedExecutionContext
s of the givenStepExecution
.
-
Constructor Details
-
SimpleJobRepository
public SimpleJobRepository(JobInstanceDao jobInstanceDao, JobExecutionDao jobExecutionDao, StepExecutionDao stepExecutionDao, ExecutionContextDao ecDao)
-
-
Method Details
-
getJobNames
Description copied from interface:JobRepository
Retrieve the names of all job instances sorted alphabetically - i.e. jobs that have ever been executed.- Specified by:
getJobNames
in interfaceJobRepository
- Returns:
- the names of all job instances
-
findJobInstancesByName
Description copied from interface:JobRepository
Fetch the last job instances with the provided name, sorted backwards by primary key, using a 'like' criteria- Specified by:
findJobInstancesByName
in interfaceJobRepository
- Parameters:
jobName
-String
containing the name of the job.start
- int containing the offset of where list of job instances results should begin.count
- int containing the number of job instances to return.- Returns:
- a list of
JobInstance
for the job name requested.
-
findJobExecutions
Description copied from interface:JobRepository
Return allJobExecution
s for givenJobInstance
, sorted backwards by creation order (so the first element is the most recent).- Specified by:
findJobExecutions
in interfaceJobRepository
- Parameters:
jobInstance
- parentJobInstance
of theJobExecution
s to find.- Returns:
List
containing JobExecutions for the jobInstance.
-
isJobInstanceExists
Description copied from interface:JobRepository
Check if an instance of this job already exists with the parameters provided.- Specified by:
isJobInstanceExists
in interfaceJobRepository
- Parameters:
jobName
- the name of the jobjobParameters
- the parameters to match- Returns:
- true if a
JobInstance
already exists for this job name and job parameters
-
createJobExecution
public JobExecution createJobExecution(String jobName, JobParameters jobParameters) throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException Description copied from interface:JobRepository
Create a
JobExecution
for a givenJob
andJobParameters
. If matchingJobInstance
already exists, the job must be restartable and it's last JobExecution must *not* be completed. If matchingJobInstance
does not exist yet it will be created.If this method is run in a transaction (as it normally would be) with isolation level at
Isolation.REPEATABLE_READ
or better, then this method should block if another transaction is already executing it (for the sameJobParameters
and job name). The first transaction to complete in this scenario obtains a validJobExecution
, and others throwJobExecutionAlreadyRunningException
(or timeout). There are no such guarantees if theJobInstanceDao
andJobExecutionDao
do not respect the transaction isolation levels (e.g. if using a non-relational data-store, or if the platform does not support the higher isolation levels).- Specified by:
createJobExecution
in interfaceJobRepository
- Parameters:
jobName
- the name of the job that is to be executedjobParameters
- the runtime parameters for the job- Returns:
- a valid
JobExecution
for the arguments provided - Throws:
JobExecutionAlreadyRunningException
- if there is aJobExecution
already running for the job instance with the provided job and parameters.JobRestartException
- if one or more existingJobInstance
s is found with the same parameters andJob.isRestartable()
is false.JobInstanceAlreadyCompleteException
- if aJobInstance
is found and was already completed successfully.
-
update
Description copied from interface:JobRepository
Update theJobExecution
(but not itsExecutionContext
). Preconditions:JobExecution
must contain a validJobInstance
and be saved (have an id assigned).- Specified by:
update
in interfaceJobRepository
- Parameters:
jobExecution
-JobExecution
instance to be updated in the repo.
-
add
Description copied from interface:JobRepository
Save theStepExecution
and itsExecutionContext
. ID will be assigned - it is not permitted that an ID be assigned before calling this method. Instead, it should be left blank, to be assigned by aJobRepository
. Preconditions:StepExecution
must have a validStep
.- Specified by:
add
in interfaceJobRepository
- Parameters:
stepExecution
-StepExecution
instance to be added to the repo.
-
addAll
Description copied from interface:JobRepository
Save a collection ofStepExecution
s and eachExecutionContext
. The StepExecution ID will be assigned - it is not permitted that an ID be assigned before calling this method. Instead, it should be left blank, to be assigned byJobRepository
. Preconditions:StepExecution
must have a validStep
.- Specified by:
addAll
in interfaceJobRepository
- Parameters:
stepExecutions
- collection ofStepExecution
instances to be added to the repo.
-
update
Description copied from interface:JobRepository
Update theStepExecution
(but not itsExecutionContext
). Preconditions:StepExecution
must be saved (have an id assigned).- Specified by:
update
in interfaceJobRepository
- Parameters:
stepExecution
-StepExecution
instance to be updated in the repo.
-
updateExecutionContext
Description copied from interface:JobRepository
Persist the updatedExecutionContext
s of the givenStepExecution
.- Specified by:
updateExecutionContext
in interfaceJobRepository
- Parameters:
stepExecution
-StepExecution
instance to be used to update the context.
-
updateExecutionContext
Description copied from interface:JobRepository
Persist the updatedExecutionContext
of the givenJobExecution
.- Specified by:
updateExecutionContext
in interfaceJobRepository
- Parameters:
jobExecution
-JobExecution
instance to be used to update the context.
-
getJobInstance
- Specified by:
getJobInstance
in interfaceJobRepository
- Parameters:
jobName
-String
name of the job.jobParameters
-JobParameters
parameters for the job instance.- Returns:
- the
JobInstance
with the given name and parameters, ornull
.
-
getLastStepExecution
- Specified by:
getLastStepExecution
in interfaceJobRepository
- Parameters:
jobInstance
-JobInstance
instance containing the step executions.stepName
- the name of the step execution that might have run.- Returns:
- the last execution of step for the given job instance.
-
getStepExecutionCount
- Specified by:
getStepExecutionCount
in interfaceJobRepository
- Parameters:
jobInstance
-JobInstance
instance containing the step executions.stepName
- the name of the step execution that might have run.- Returns:
- number of executions of the step within given job instance
-
getLastJobExecution
- Specified by:
getLastJobExecution
in interfaceJobRepository
- Parameters:
jobName
- the name of the job that might have runjobParameters
- parameters identifying theJobInstance
- Returns:
- the last execution of job if exists, null otherwise
-
deleteStepExecution
Description copied from interface:JobRepository
Delete the step execution along with its execution context.- Specified by:
deleteStepExecution
in interfaceJobRepository
- Parameters:
stepExecution
- the step execution to delete
-
deleteJobExecution
Description copied from interface:JobRepository
Delete the job execution object graph (ie the job execution with its execution context, all related step executions and their executions contexts, as well as associated job parameters)- Specified by:
deleteJobExecution
in interfaceJobRepository
- Parameters:
jobExecution
- the job execution to delete
-
deleteJobInstance
Description copied from interface:JobRepository
Delete the job instance object graph (ie the job instance with all associated job executions along with their respective object graphs as specified inJobRepository.deleteJobExecution(JobExecution)
).- Specified by:
deleteJobInstance
in interfaceJobRepository
- Parameters:
jobInstance
- the job instance to delete
-
createJobInstance
Description copied from interface:JobRepository
Create a newJobInstance
with the name and job parameters provided.- Specified by:
createJobInstance
in interfaceJobRepository
- Parameters:
jobName
- logical name of the jobjobParameters
- parameters used to execute the job- Returns:
- the new
JobInstance
-