Package 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`

public class SimpleStepHandler extends Object implements StepHandler, org.springframework.beans.factory.InitializingBean
Implementation of `StepHandler` that manages repository and restart concerns.

Author:
  Dave Syer

- ## Constructor Summary

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

- ## Method Summary

  Modifier and Type
  Method
  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 Details

  - ### 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 Details

  - ### afterPropertiesSet

    public void afterPropertiesSet() throws Exception
    Check mandatory properties (jobRepository).
    Specified by:
      `afterPropertiesSet` in interface `org.springframework.beans.factory.InitializingBean`
    Throws:
      `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` - the `JobExecution` instance to be evaluated.
      `step` - the `Step` instance to be evaluated.
    Returns:
      true if step should start, false if it should not.
    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