org.springframework.batch.core.job

## Class SimpleStepHandler

- java.lang.Object
- - org.springframework.batch.core.job.SimpleStepHandler

- All Implemented Interfaces:
    StepHandler, org.springframework.beans.factory.InitializingBean
  Direct Known Subclasses:
    JsrStepHandler

      public class SimpleStepHandler
      extends java.lang.Object
      implements StepHandler, org.springframework.beans.factory.InitializingBean

  Implementation of `StepHandler` that manages repository and restart concerns.
  Author:
    Dave Syer

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `SimpleStepHandler()` Convenient default constructor for configuration usage.
    `SimpleStepHandler(JobRepository jobRepository)`
    `SimpleStepHandler(JobRepository jobRepository, ExecutionContext executionContext)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `afterPropertiesSet()` Check mandatory properties (jobRepository).
    `protected JobRepository` | `getJobRepository()`
    `StepExecution` | `handleStep(Step step, JobExecution execution)` Handle a step and return the execution for it.
    `void` | `setExecutionContext(ExecutionContext executionContext)` A context containing values to be added to the step execution before it is handled.
    `void` | `setJobRepository(JobRepository jobRepository)`
    `protected boolean` | `shouldStart(StepExecution lastStepExecution, JobExecution jobExecution, Step step)` Given a step and configuration, return true if the step should start, false if it should not, and throw an exception if the job should finish.

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

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

- - ### Constructor Detail

    - #### SimpleStepHandler

          public SimpleStepHandler()

      Convenient default constructor for configuration usage.

    - #### SimpleStepHandler

          public SimpleStepHandler(JobRepository jobRepository)

      Parameters:
        `jobRepository` - a `JobRepository`

    - #### SimpleStepHandler

          public SimpleStepHandler(JobRepository jobRepository,
                                   ExecutionContext executionContext)

      Parameters:
        `jobRepository` - a `JobRepository`
        `executionContext` - the `ExecutionContext` for the current Step

  - ### Method Detail

    - #### afterPropertiesSet

          public void afterPropertiesSet()
                                  throws java.lang.Exception

      Check mandatory properties (jobRepository).
      Specified by:
        `afterPropertiesSet` in interface `org.springframework.beans.factory.InitializingBean`
      Throws:
        `java.lang.Exception`
      See Also:
        `InitializingBean.afterPropertiesSet()`

    - #### getJobRepository

          protected JobRepository getJobRepository()

      Returns:
        the used jobRepository

    - #### setJobRepository

          public void setJobRepository(JobRepository jobRepository)

      Parameters:
        `jobRepository` - the jobRepository to set

    - #### setExecutionContext

          public void setExecutionContext(ExecutionContext executionContext)

      A context containing values to be added to the step execution before it is handled.
      Parameters:
        `executionContext` - the execution context to set

    - #### handleStep

          public StepExecution handleStep(Step step,
                                          JobExecution execution)
                                   throws JobInterruptedException,
                                          JobRestartException,
                                          StartLimitExceededException

      Description copied from interface: `StepHandler`
      Handle a step and return the execution for it. Does not save the `JobExecution`, but should manage the persistence of the `StepExecution` if required (e.g. at least it needs to be added to a repository before the step can be executed).
      Specified by:
        `handleStep` in interface `StepHandler`
      Parameters:
        `step` - a `Step`
        `execution` - a `JobExecution`
      Returns:
        an execution of the step
      Throws:
        `JobInterruptedException` - if there is an interruption
        `JobRestartException` - if there is a problem restarting a failed step
        `StartLimitExceededException` - if the step exceeds its start limit
      See Also:
        `Job.execute(JobExecution)`, `Step.execute(StepExecution)`

    - #### shouldStart

          protected boolean shouldStart(StepExecution lastStepExecution,
                                        JobExecution jobExecution,
                                        Step step)
                                 throws JobRestartException,
                                        StartLimitExceededException

      Given a step and configuration, return true if the step should start, false if it should not, and throw an exception if the job should finish.
      Parameters:
        `lastStepExecution` - the last step execution
        `jobExecution` -
        `step` -
      Throws:
        `StartLimitExceededException` - if the start limit has been exceeded for this step
        `JobRestartException` - if the job is in an inconsistent state from an earlier failure