Package org.springframework.batch.core

# Class JobParametersBuilder

java.lang.Object
org.springframework.batch.core.JobParametersBuilder

public class JobParametersBuilder extends Object
Helper class for creating `JobParameters`. Useful because all `JobParameter` objects are immutable, and must be instantiated separately to ensure type safety. Once created, it can be used in the same was a java.lang.StringBuilder (except, order is irrelevant), by adding various parameter types and creating a valid `JobParameters` once finished.
Using the identifying flag indicates if the parameter will be used in the identification of a JobInstance. That flag defaults to true.

Since:
  1.0
Author:
  Lucas Ward, Michael Minella, Glenn Renfro, Mahmoud Ben Hassine
See Also:
  - `JobParameters`
  - `JobParameter`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `JobParametersBuilder()`
  Default constructor.
  `JobParametersBuilder(Properties properties)`
  Constructor to add conversion capabilities to support JSR-352.
  `JobParametersBuilder(JobExplorer jobExplorer)`
  `JobParametersBuilder(JobParameters jobParameters)`
  Copy constructor.
  `JobParametersBuilder(JobParameters jobParameters, JobExplorer jobExplorer)`
  Copy constructor.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `JobParametersBuilder`
  `addDate(String key, Date parameter)`
  Add a new identifying `Date` parameter for the given key.
  `JobParametersBuilder`
  `addDate(String key, Date parameter, boolean identifying)`
  Add a new `Date` parameter for the given key.
  `JobParametersBuilder`
  `addDouble(String key, Double parameter)`
  Add a new identifying Double parameter for the given key.
  `JobParametersBuilder`
  `addDouble(String key, Double parameter, boolean identifying)`
  Add a new Double parameter for the given key.
  `JobParametersBuilder`
  `addJobParameters(JobParameters jobParameters)`
  Copy job parameters into the current state.
  `JobParametersBuilder`
  `addLong(String key, Long parameter)`
  Add a new identifying Long parameter for the given key.
  `JobParametersBuilder`
  `addLong(String key, Long parameter, boolean identifying)`
  Add a new Long parameter for the given key.
  `JobParametersBuilder`
  `addParameter(String key, JobParameter jobParameter)`
  Add a new `JobParameter` for the given key.
  `JobParametersBuilder`
  `addString(String key, String parameter)`
  Add a new identifying String parameter for the given key.
  `JobParametersBuilder`
  `addString(String key, String parameter, boolean identifying)`
  Add a new String parameter for the given key.
  `JobParametersBuilder`
  `getNextJobParameters(Job job)`
  Initializes the `JobParameters` based on the state of the `Job`.
  `JobParameters`
  `toJobParameters()`
  Conversion method that takes the current state of this builder and returns it as a JobParameters object.

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

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

- ## Constructor Details

  - ### JobParametersBuilder

    public JobParametersBuilder()
    Default constructor. Initializes the builder with empty parameters.

  - ### JobParametersBuilder

    public JobParametersBuilder(JobExplorer jobExplorer)
    Parameters:
      `jobExplorer` - `JobExplorer` used for looking up previous job parameter information

  - ### JobParametersBuilder

    public JobParametersBuilder(JobParameters jobParameters)
    Copy constructor. Initializes the builder with the supplied parameters.
    Parameters:
      `jobParameters` - `JobParameters` instance used to initialize the builder.

  - ### JobParametersBuilder

    public JobParametersBuilder(Properties properties)
    Constructor to add conversion capabilities to support JSR-352. Per the spec, it is expected that all keys and values in the provided `Properties` instance are Strings
    Parameters:
      `properties` - the job parameters to be used

  - ### JobParametersBuilder

    public JobParametersBuilder(JobParameters jobParameters, JobExplorer jobExplorer)
    Copy constructor. Initializes the builder with the supplied parameters.
    Parameters:
      `jobParameters` - `JobParameters` instance used to initialize the builder.
      `jobExplorer` - `JobExplorer` used for looking up previous job parameter information

- ## Method Details

  - ### addString

    public JobParametersBuilder addString(String key, @NonNull String parameter)
    Add a new identifying String parameter for the given key.
    Parameters:
      `key` - - parameter accessor.
      `parameter` - - runtime parameter. Must not be `null`.
    Returns:
      a reference to this object.

  - ### addString

    public JobParametersBuilder addString(String key, @NonNull String parameter, boolean identifying)
    Add a new String parameter for the given key.
    Parameters:
      `key` - - parameter accessor.
      `parameter` - - runtime parameter. Must not be `null`.
      `identifying` - - indicates if the parameter is used as part of identifying a job instance
    Returns:
      a reference to this object.

  - ### addDate

    public JobParametersBuilder addDate(String key, @NonNull Date parameter)
    Add a new identifying `Date` parameter for the given key.
    Parameters:
      `key` - - parameter accessor.
      `parameter` - - runtime parameter. Must not be `null`.
    Returns:
      a reference to this object.

  - ### addDate

    public JobParametersBuilder addDate(String key, @NonNull Date parameter, boolean identifying)
    Add a new `Date` parameter for the given key.
    Parameters:
      `key` - - parameter accessor.
      `parameter` - - runtime parameter. Must not be `null`.
      `identifying` - - indicates if the parameter is used as part of identifying a job instance
    Returns:
      a reference to this object.

  - ### addLong

    public JobParametersBuilder addLong(String key, @NonNull Long parameter)
    Add a new identifying Long parameter for the given key.
    Parameters:
      `key` - - parameter accessor.
      `parameter` - - runtime parameter. Must not be `null`.
    Returns:
      a reference to this object.

  - ### addLong

    public JobParametersBuilder addLong(String key, @NonNull Long parameter, boolean identifying)
    Add a new Long parameter for the given key.
    Parameters:
      `key` - - parameter accessor.
      `parameter` - - runtime parameter. Must not be `null`.
      `identifying` - - indicates if the parameter is used as part of identifying a job instance
    Returns:
      a reference to this object.

  - ### addDouble

    public JobParametersBuilder addDouble(String key, @NonNull Double parameter)
    Add a new identifying Double parameter for the given key.
    Parameters:
      `key` - - parameter accessor.
      `parameter` - - runtime parameter. Must not be `null`.
    Returns:
      a reference to this object.

  - ### addDouble

    public JobParametersBuilder addDouble(String key, @NonNull Double parameter, boolean identifying)
    Add a new Double parameter for the given key.
    Parameters:
      `key` - - parameter accessor.
      `parameter` - - runtime parameter. Must not be `null`.
      `identifying` - - indicates if the parameter is used as part of identifying a job instance
    Returns:
      a reference to this object.

  - ### toJobParameters

    public JobParameters toJobParameters()
    Conversion method that takes the current state of this builder and returns it as a JobParameters object.
    Returns:
      a valid `JobParameters` object.

  - ### addParameter

    public JobParametersBuilder addParameter(String key, JobParameter jobParameter)
    Add a new `JobParameter` for the given key.
    Parameters:
      `key` - - parameter accessor
      `jobParameter` - - runtime parameter
    Returns:
      a reference to this object.

  - ### addJobParameters

    public JobParametersBuilder addJobParameters(JobParameters jobParameters)
    Copy job parameters into the current state.
    Parameters:
      `jobParameters` - parameters to copy in
    Returns:
      a reference to this object.

  - ### getNextJobParameters

    public JobParametersBuilder getNextJobParameters(Job job)
    Initializes the `JobParameters` based on the state of the `Job`. This should be called after all parameters have been entered into the builder. All parameters already set on this builder instance will be appended to those retrieved from the job incrementer, overriding any with the same key (Same behaviour as `CommandLineJobRunner` with "-next" option and `JobOperator.startNextInstance(String)`)
    Parameters:
      `job` - the job for which the `JobParameters` are being constructed.
    Returns:
      a reference to this object.
    Since:
      4.0