org.springframework.batch.core.repository.support

## Class SimpleJobRepository

- java.lang.Object
- - org.springframework.batch.core.repository.support.SimpleJobRepository

- All Implemented Interfaces:
    JobRepository

      public class SimpleJobRepository
      extends java.lang.Object
      implements JobRepository

  Implementation of `JobRepository` that stores JobInstances, JobExecutions, and StepExecutions using the injected DAOs.

  Author:
    Lucas Ward, Dave Syer, Robert Kasanicky, David Turanski, Mahmoud Ben Hassine, Baris Cubukcuoglu
  See Also:
    `JobRepository`, `JobInstanceDao`, `JobExecutionDao`, `StepExecutionDao`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `SimpleJobRepository(JobInstanceDao jobInstanceDao, JobExecutionDao jobExecutionDao, StepExecutionDao stepExecutionDao, ExecutionContextDao ecDao)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(StepExecution stepExecution)` Save the `StepExecution` and its `ExecutionContext`.
    `void` | `addAll(java.util.Collection<StepExecution> stepExecutions)` Save a collection of `StepExecution`s and each `ExecutionContext`.
    `JobExecution` | `createJobExecution(JobInstance jobInstance, JobParameters jobParameters, java.lang.String jobConfigurationLocation)` Create a new `JobExecution` based upon the `JobInstance` it's associated with, the `JobParameters` used to execute it with and the location of the configuration file that defines the job.
    `JobExecution` | `createJobExecution(java.lang.String jobName, JobParameters jobParameters)` Create a `JobExecution` for a given `Job` and `JobParameters`.
    `JobInstance` | `createJobInstance(java.lang.String jobName, JobParameters jobParameters)` Create a new `JobInstance` with the name and job parameters provided.
    `JobExecution` | `getLastJobExecution(java.lang.String jobName, JobParameters jobParameters)`
    `StepExecution` | `getLastStepExecution(JobInstance jobInstance, java.lang.String stepName)`
    `int` | `getStepExecutionCount(JobInstance jobInstance, java.lang.String stepName)`
    `boolean` | `isJobInstanceExists(java.lang.String jobName, JobParameters jobParameters)` Check if an instance of this job already exists with the parameters provided.
    `void` | `update(JobExecution jobExecution)` Update the `JobExecution` (but not its `ExecutionContext`).
    `void` | `update(StepExecution stepExecution)` Update the `StepExecution` (but not its `ExecutionContext`).
    `void` | `updateExecutionContext(JobExecution jobExecution)` Persist the updated `ExecutionContext` of the given `JobExecution`.
    `void` | `updateExecutionContext(StepExecution stepExecution)` Persist the updated `ExecutionContext`s of the given `StepExecution`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### SimpleJobRepository

          public SimpleJobRepository(JobInstanceDao jobInstanceDao,
                                     JobExecutionDao jobExecutionDao,
                                     StepExecutionDao stepExecutionDao,
                                     ExecutionContextDao ecDao)

  - ### Method Detail

    - #### isJobInstanceExists

          public boolean isJobInstanceExists(java.lang.String jobName,
                                             JobParameters jobParameters)

      Description copied from interface: `JobRepository`
      Check if an instance of this job already exists with the parameters provided.
      Specified by:
        `isJobInstanceExists` in interface `JobRepository`
      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

    - #### createJobExecution

          public JobExecution createJobExecution(java.lang.String jobName,
                                                 JobParameters jobParameters)
                                          throws JobExecutionAlreadyRunningException,
                                                 JobRestartException,
                                                 JobInstanceAlreadyCompleteException

      Description copied from interface: `JobRepository`

      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).

      Specified by:
        `createJobExecution` in interface `JobRepository`
      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 `JobInstance`s is found with the same parameters and `Job.isRestartable()` is false.
        `JobInstanceAlreadyCompleteException` - if a `JobInstance` is found and was already completed successfully.

    - #### update

          public void update(JobExecution jobExecution)

      Description copied from interface: `JobRepository`
      Update the `JobExecution` (but not its `ExecutionContext`). Preconditions: `JobExecution` must contain a valid `JobInstance` and be saved (have an id assigned).
      Specified by:
        `update` in interface `JobRepository`
      Parameters:
        `jobExecution` - `JobExecution` instance to be updated in the repo.

    - #### add

          public void add(StepExecution stepExecution)

      Description copied from interface: `JobRepository`
      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`.
      Specified by:
        `add` in interface `JobRepository`
      Parameters:
        `stepExecution` - `StepExecution` instance to be added to the repo.

    - #### addAll

          public void addAll(java.util.Collection<StepExecution> stepExecutions)

      Description copied from interface: `JobRepository`
      Save a collection of `StepExecution`s 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`.
      Specified by:
        `addAll` in interface `JobRepository`
      Parameters:
        `stepExecutions` - collection of `StepExecution` instances to be added to the repo.

    - #### update

          public void update(StepExecution stepExecution)

      Description copied from interface: `JobRepository`
      Update the `StepExecution` (but not its `ExecutionContext`). Preconditions: `StepExecution` must be saved (have an id assigned).
      Specified by:
        `update` in interface `JobRepository`
      Parameters:
        `stepExecution` - `StepExecution` instance to be updated in the repo.

    - #### updateExecutionContext

          public void updateExecutionContext(StepExecution stepExecution)

      Description copied from interface: `JobRepository`
      Persist the updated `ExecutionContext`s of the given `StepExecution`.
      Specified by:
        `updateExecutionContext` in interface `JobRepository`
      Parameters:
        `stepExecution` - `StepExecution` instance to be used to update the context.

    - #### updateExecutionContext

          public void updateExecutionContext(JobExecution jobExecution)

      Description copied from interface: `JobRepository`
      Persist the updated `ExecutionContext` of the given `JobExecution`.
      Specified by:
        `updateExecutionContext` in interface `JobRepository`
      Parameters:
        `jobExecution` - `JobExecution` instance to be used to update the context.

    - #### getLastStepExecution

          @Nullable
          public StepExecution getLastStepExecution(JobInstance jobInstance,
                                                              java.lang.String stepName)

      Specified by:
        `getLastStepExecution` in interface `JobRepository`
      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

          public int getStepExecutionCount(JobInstance jobInstance,
                                           java.lang.String stepName)

      Specified by:
        `getStepExecutionCount` in interface `JobRepository`
      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

          @Nullable
          public JobExecution getLastJobExecution(java.lang.String jobName,
                                                            JobParameters jobParameters)

      Specified by:
        `getLastJobExecution` in interface `JobRepository`
      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

    - #### createJobInstance

          public JobInstance createJobInstance(java.lang.String jobName,
                                               JobParameters jobParameters)

      Description copied from interface: `JobRepository`
      Create a new `JobInstance` with the name and job parameters provided.
      Specified by:
        `createJobInstance` in interface `JobRepository`
      Parameters:
        `jobName` - logical name of the job
        `jobParameters` - parameters used to execute the job
      Returns:
        the new `JobInstance`

    - #### createJobExecution

          public JobExecution createJobExecution(JobInstance jobInstance,
                                                 JobParameters jobParameters,
                                                 java.lang.String jobConfigurationLocation)

      Description copied from interface: `JobRepository`
      Create a new `JobExecution` based upon the `JobInstance` it's associated with, the `JobParameters` used to execute it with and the location of the configuration file that defines the job.
      Specified by:
        `createJobExecution` in interface `JobRepository`
      Parameters:
        `jobInstance` - `JobInstance` instance to initialize the new JobExecution.
        `jobParameters` - `JobParameters` instance to initialize the new JobExecution.
        `jobConfigurationLocation` - `String` instance to initialize the new JobExecution.
      Returns:
        the new `JobExecution`.