Interface JobRepository

All Known Implementing Classes:
SimpleJobRepository

public interface JobRepository

Repository responsible for persistence of batch meta-data entities.

Author:
Lucas Ward, Dave Syer, Robert Kasanicky, David Turanski, Michael Minella, Mahmoud Ben Hassine, Parikshit Dutta
See Also:
  • Method Details

    • getJobNames

      default List<String> getJobNames()
      Retrieve the names of all job instances sorted alphabetically - i.e. jobs that have ever been executed.
      Returns:
      the names of all job instances
      Since:
      5.0
    • findJobInstancesByName

      default List<JobInstance> findJobInstancesByName(String jobName, int start, int count)
      Fetch the last job instances with the provided name, sorted backwards by primary key, using a 'like' criteria
      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.
      Since:
      5.0
    • findJobExecutions

      default List<JobExecution> findJobExecutions(JobInstance jobInstance)
      Return all JobExecutions for given JobInstance, sorted backwards by creation order (so the first element is the most recent).
      Parameters:
      jobInstance - parent JobInstance of the JobExecutions to find.
      Returns:
      List containing JobExecutions for the jobInstance.
      Since:
      5.0
    • isJobInstanceExists

      boolean isJobInstanceExists(String jobName, JobParameters jobParameters)
      Check if an instance of this job already exists with the parameters provided.
      Parameters:
      jobName - the name of the job
      jobParameters - the parameters to match
      Returns:
      true if a JobInstance already exists for this job name and job parameters
    • createJobInstance

      JobInstance createJobInstance(String jobName, JobParameters jobParameters)
      Create a new JobInstance with the name and job parameters provided.
      Parameters:
      jobName - logical name of the job
      jobParameters - parameters used to execute the job
      Returns:
      the new JobInstance
    • createJobExecution

      Create a JobExecution for a given Job and JobParameters. If matching JobInstance already exists, the job must be restartable and it's last JobExecution must *not* be completed. If matching JobInstance 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 same JobParameters and job name). The first transaction to complete in this scenario obtains a valid JobExecution, and others throw JobExecutionAlreadyRunningException (or timeout). There are no such guarantees if the JobInstanceDao and JobExecutionDao 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).

      Parameters:
      jobName - the name of the job that is to be executed
      jobParameters - the runtime parameters for the job
      Returns:
      a valid JobExecution for the arguments provided
      Throws:
      JobExecutionAlreadyRunningException - if there is a JobExecution already running for the job instance with the provided job and parameters.
      JobRestartException - if one or more existing JobInstances is found with the same parameters and Job.isRestartable() is false.
      JobInstanceAlreadyCompleteException - if a JobInstance is found and was already completed successfully.
    • update

      void update(JobExecution jobExecution)
      Update the JobExecution (but not its ExecutionContext).

      Preconditions: JobExecution must contain a valid JobInstance and be saved (have an id assigned).

      Parameters:
      jobExecution - JobExecution instance to be updated in the repo.
    • add

      void add(StepExecution stepExecution)
      Save the StepExecution and its ExecutionContext. 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 a JobRepository.

      Preconditions: StepExecution must have a valid Step.

      Parameters:
      stepExecution - StepExecution instance to be added to the repo.
    • addAll

      void addAll(Collection<StepExecution> stepExecutions)
      Save a collection of StepExecutions and each ExecutionContext. 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 by JobRepository.

      Preconditions: StepExecution must have a valid Step.

      Parameters:
      stepExecutions - collection of StepExecution instances to be added to the repo.
    • update

      void update(StepExecution stepExecution)
      Update the StepExecution (but not its ExecutionContext).

      Preconditions: StepExecution must be saved (have an id assigned).

      Parameters:
      stepExecution - StepExecution instance to be updated in the repo.
    • updateExecutionContext

      void updateExecutionContext(StepExecution stepExecution)
      Persist the updated ExecutionContexts of the given StepExecution.
      Parameters:
      stepExecution - StepExecution instance to be used to update the context.
    • updateExecutionContext

      void updateExecutionContext(JobExecution jobExecution)
      Persist the updated ExecutionContext of the given JobExecution.
      Parameters:
      jobExecution - JobExecution instance to be used to update the context.
    • getJobInstance

      @Nullable default JobInstance getJobInstance(String jobName, JobParameters jobParameters)
      Parameters:
      jobName - String name of the job.
      jobParameters - JobParameters parameters for the job instance.
      Returns:
      the JobInstance with the given name and parameters, or null.
      Since:
      5.0
    • getLastStepExecution

      @Nullable StepExecution getLastStepExecution(JobInstance jobInstance, String stepName)
      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

      long getStepExecutionCount(JobInstance jobInstance, String stepName)
      Parameters:
      jobInstance - JobInstance instance containing the step executions.
      stepName - the name of the step execution that might have run.
      Returns:
      the execution count of the step within the given job instance.
    • getLastJobExecution

      @Nullable JobExecution getLastJobExecution(String jobName, JobParameters jobParameters)
      Parameters:
      jobName - the name of the job that might have run
      jobParameters - parameters identifying the JobInstance
      Returns:
      the last execution of job if exists, null otherwise
    • deleteStepExecution

      default void deleteStepExecution(StepExecution stepExecution)
      Delete the step execution along with its execution context.
      Parameters:
      stepExecution - the step execution to delete
      Since:
      5.0
    • deleteJobExecution

      default 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)
      Parameters:
      jobExecution - the job execution to delete
      Since:
      5.0
    • deleteJobInstance

      default 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 in deleteJobExecution(JobExecution)).
      Parameters:
      jobInstance - the job instance to delete
      Since:
      5.0