Package org.springframework.batch.core
Class JobParametersBuilder
java.lang.Object
org.springframework.batch.core.JobParametersBuilder
Helper class for creating
Using the
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 Summary
ConstructorsConstructorDescriptionDefault constructor.JobParametersBuilder(JobExplorer jobExplorer) JobParametersBuilder(JobParameters jobParameters) Copy constructor.JobParametersBuilder(JobParameters jobParameters, JobExplorer jobExplorer) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionAdd a new identifyingDateparameter for the given key.Add a newDateparameter for the given key.Add a new identifyingDoubleparameter for the given key.Add a newDoubleparameter for the given key.addJobParameter(String key, JobParameter<?> jobParameter) Add a newJobParameterfor the given key.addJobParameter(String name, T value, Class<T> type) Add an identifying job parameter.addJobParameter(String name, T value, Class<T> type, boolean identifying) Add a job parameter.addJobParameters(JobParameters jobParameters) Copy job parameters into the current state.addLocalDate(String key, LocalDate parameter) Add a new identifyingLocalDateparameter for the given key.addLocalDate(String key, LocalDate parameter, boolean identifying) Add a newLocalDateparameter for the given key.addLocalDateTime(String key, LocalDateTime parameter) Add a new identifyingLocalDateTimeparameter for the given key.addLocalDateTime(String key, LocalDateTime parameter, boolean identifying) Add a newLocalDateTimeparameter for the given key.addLocalTime(String key, LocalTime parameter) Add a new identifyingLocalTimeparameter for the given key.addLocalTime(String key, LocalTime parameter, boolean identifying) Add a newLocalTimeparameter for the given key.Add a new identifyingLongparameter for the given key.Add a newLongparameter for the given key.Add a new identifying String parameter for the given key.Add a new String parameter for the given key.getNextJobParameters(Job job) Initializes theJobParametersbased on the state of theJob.Conversion method that takes the current state of this builder and returns it as aJobParametersobject.
-
Constructor Details
-
JobParametersBuilder
public JobParametersBuilder()Default constructor. Initializes the builder with empty parameters. -
JobParametersBuilder
- Parameters:
jobExplorer-JobExplorerused for looking up previous job parameter information.
-
JobParametersBuilder
Copy constructor. Initializes the builder with the supplied parameters.- Parameters:
jobParameters-JobParametersinstance used to initialize the builder.
-
JobParametersBuilder
Copy constructor. Initializes the builder with the supplied parameters.- Parameters:
jobParameters-JobParametersinstance used to initialize the builder.jobExplorer-JobExplorerused for looking up previous job parameter information.
-
-
Method Details
-
addString
Add a new identifying String parameter for the given key.- Parameters:
key- The parameter accessor.parameter- The runtime parameter. Must not benull.- Returns:
- a reference to this object.
-
addString
Add a new String parameter for the given key.- Parameters:
key- The parameter accessor.parameter- The runtime parameter. Must not benull.identifying- The indicates if the parameter is used as part of identifying a job instance.- Returns:
- a reference to this object.
-
addDate
Add a new identifyingDateparameter for the given key.- Parameters:
key- The parameter accessor.parameter- The runtime parameter. Must not benull.- Returns:
- a reference to this object.
-
addDate
Add a newDateparameter for the given key.- Parameters:
key- The parameter accessor.parameter- The runtime parameter. Must not benull.identifying- Indicates if the parameter is used as part of identifying a job instance- Returns:
- a reference to this object.
-
addLocalDate
Add a new identifyingLocalDateparameter for the given key.- Parameters:
key- The parameter name.parameter- The runtime parameter. Must not benull.- Returns:
- a reference to this object.
-
addLocalDate
public JobParametersBuilder addLocalDate(String key, @NonNull LocalDate parameter, boolean identifying) Add a newLocalDateparameter for the given key.- Parameters:
key- The parameter name.parameter- The runtime parameter. Must not benull.identifying- Indicates if the parameter is used as part of identifying a job instance- Returns:
- a reference to this object.
-
addLocalTime
Add a new identifyingLocalTimeparameter for the given key.- Parameters:
key- The parameter name.parameter- The runtime parameter. Must not benull.- Returns:
- a reference to this object.
-
addLocalTime
public JobParametersBuilder addLocalTime(String key, @NonNull LocalTime parameter, boolean identifying) Add a newLocalTimeparameter for the given key.- Parameters:
key- The parameter name.parameter- The runtime parameter. Must not benull.identifying- Indicates if the parameter is used as part of identifying a job instance- Returns:
- a reference to this object.
-
addLocalDateTime
Add a new identifyingLocalDateTimeparameter for the given key.- Parameters:
key- The parameter name.parameter- The runtime parameter. Must not benull.- Returns:
- a reference to this object.
-
addLocalDateTime
public JobParametersBuilder addLocalDateTime(String key, @NonNull LocalDateTime parameter, boolean identifying) Add a newLocalDateTimeparameter for the given key.- Parameters:
key- The parameter name.parameter- The runtime parameter. Must not benull.identifying- Indicates if the parameter is used as part of identifying a job instance- Returns:
- a reference to this object.
-
addLong
Add a new identifyingLongparameter for the given key.- Parameters:
key- The parameter accessor.parameter- The runtime parameter. Must not benull.- Returns:
- a reference to this object.
-
addLong
Add a newLongparameter for the given key.- Parameters:
key- The parameter accessor.parameter- The runtime parameter. Must not benull.identifying- Indicates if the parameter is used as part of identifying a job instance.- Returns:
- a reference to this object.
-
addDouble
Add a new identifyingDoubleparameter for the given key.- Parameters:
key- The parameter accessor.parameter- The runtime parameter. Must not benull.- Returns:
- a reference to this object.
-
addDouble
Add a newDoubleparameter for the given key.- Parameters:
key- The parameter accessor.parameter- The runtime parameter. Must not benull.identifying- Indicates if the parameter is used as part of identifying a job instance.- Returns:
- a reference to this object.
-
toJobParameters
Conversion method that takes the current state of this builder and returns it as aJobParametersobject.- Returns:
- a valid
JobParametersobject.
-
addJobParameter
Add a newJobParameterfor 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 parametervalue- the value of the parameter. Must not benull.type- the type of the parameteridentifying- true if the parameter is identifying. false otherwise- Returns:
- a reference to this object.
- Since:
- 5.0
-
addJobParameter
Add an identifying job parameter.- Type Parameters:
T- the type of the parameter- Parameters:
name- the name of the parametervalue- the value of the parameter. Must not benull.type- the type of the parameter- Returns:
- a reference to this object.
- Since:
- 5.0
-
addJobParameters
Copy job parameters into the current state.- Parameters:
jobParameters- The parameters to copy in.- Returns:
- a reference to this object.
-
getNextJobParameters
Initializes theJobParametersbased on the state of theJob. 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 asCommandLineJobRunnerwith the-nextoption andJobOperator.startNextInstance(String)).- Parameters:
job- The job for which theJobParametersare being constructed.- Returns:
- a reference to this object.
- Since:
- 4.0
-