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 StringBuilder (except that order is irrelevant), by adding various parameter types and creating a valid JobParameters object once finished.

Using the identifying flag indicates if the parameter should be used in the identification of a JobInstance object. That flag defaults to true.
Since:
1.0
Author:
Lucas Ward, Michael Minella, Glenn Renfro, Mahmoud Ben Hassine
See Also:
  • 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(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 - The parameter accessor.
      parameter - The 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 - The parameter accessor.
      parameter - The runtime parameter. Must not be null.
      identifying - The 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 - The parameter accessor.
      parameter - The 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 - The parameter accessor.
      parameter - The 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.
    • addLocalDate

      public JobParametersBuilder addLocalDate(String key, @NonNull LocalDate parameter)
      Add a new identifying LocalDate parameter for the given key.
      Parameters:
      key - The parameter name.
      parameter - The runtime parameter. Must not be null.
      Returns:
      a reference to this object.
    • addLocalDate

      public JobParametersBuilder addLocalDate(String key, @NonNull LocalDate parameter, boolean identifying)
      Add a new LocalDate parameter for the given key.
      Parameters:
      key - The parameter name.
      parameter - The 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.
    • addLocalTime

      public JobParametersBuilder addLocalTime(String key, @NonNull LocalTime parameter)
      Add a new identifying LocalTime parameter for the given key.
      Parameters:
      key - The parameter name.
      parameter - The runtime parameter. Must not be null.
      Returns:
      a reference to this object.
    • addLocalTime

      public JobParametersBuilder addLocalTime(String key, @NonNull LocalTime parameter, boolean identifying)
      Add a new LocalTime parameter for the given key.
      Parameters:
      key - The parameter name.
      parameter - The 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.
    • addLocalDateTime

      public JobParametersBuilder addLocalDateTime(String key, @NonNull LocalDateTime parameter)
      Add a new identifying LocalDateTime parameter for the given key.
      Parameters:
      key - The parameter name.
      parameter - The runtime parameter. Must not be null.
      Returns:
      a reference to this object.
    • addLocalDateTime

      public JobParametersBuilder addLocalDateTime(String key, @NonNull LocalDateTime parameter, boolean identifying)
      Add a new LocalDateTime parameter for the given key.
      Parameters:
      key - The parameter name.
      parameter - The 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 - The parameter accessor.
      parameter - The 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 - The parameter accessor.
      parameter - The 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 - The parameter accessor.
      parameter - The 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 - The parameter accessor.
      parameter - The 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

      @Deprecated(since="5.0", forRemoval=true) public JobParametersBuilder addParameter(String key, JobParameter<?> jobParameter)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Add a new JobParameter for the given key.
      Parameters:
      key - The parameter accessor.
      jobParameter - The runtime parameter.
      Returns:
      a reference to this object.
    • addJobParameter

      public JobParametersBuilder addJobParameter(String key, JobParameter<?> jobParameter)
      Add a new JobParameter for the given key.
      Parameters:
      key - The parameter accessor.
      jobParameter - The runtime parameter.
      Returns:
      a reference to this object.
    • addJobParameter

      public <T> JobParametersBuilder addJobParameter(String name, @NonNull T value, Class<T> type, boolean identifying)
      Add a job parameter.
      Type Parameters:
      T - the type of the parameter
      Parameters:
      name - the name of the parameter
      value - the value of the parameter. Must not be null.
      type - the type of the parameter
      identifying - true if the parameter is identifying. false otherwise
      Returns:
      a reference to this object.
      Since:
      5.0
    • addJobParameter

      public <T> JobParametersBuilder addJobParameter(String name, @NonNull T value, Class<T> type)
      Add an identifying job parameter.
      Type Parameters:
      T - the type of the parameter
      Parameters:
      name - the name of the parameter
      value - the value of the parameter. Must not be null.
      type - the type of the parameter
      Returns:
      a reference to this object.
      Since:
      5.0
    • addJobParameters

      public JobParametersBuilder addJobParameters(JobParameters jobParameters)
      Copy job parameters into the current state.
      Parameters:
      jobParameters - The 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 are appended to those retrieved from the job incrementer, overriding any with the same key (this is the same behavior as CommandLineJobRunner with the -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