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
ConstructorDescriptionDefault constructor.JobParametersBuilder
(JobExplorer jobExplorer) JobParametersBuilder
(JobParameters jobParameters) Copy constructor.JobParametersBuilder
(JobParameters jobParameters, JobExplorer jobExplorer) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionAdd a new identifyingDate
parameter for the given key.Add a newDate
parameter for the given key.Add a new identifyingDouble
parameter for the given key.Add a newDouble
parameter for the given key.addJobParameter
(String key, JobParameter<?> jobParameter) Add a newJobParameter
for 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 identifyingLocalDate
parameter for the given key.addLocalDate
(String key, LocalDate parameter, boolean identifying) Add a newLocalDate
parameter for the given key.addLocalDateTime
(String key, LocalDateTime parameter) Add a new identifyingLocalDateTime
parameter for the given key.addLocalDateTime
(String key, LocalDateTime parameter, boolean identifying) Add a newLocalDateTime
parameter for the given key.addLocalTime
(String key, LocalTime parameter) Add a new identifyingLocalTime
parameter for the given key.addLocalTime
(String key, LocalTime parameter, boolean identifying) Add a newLocalTime
parameter for the given key.Add a new identifyingLong
parameter for the given key.Add a newLong
parameter for the given key.addParameter
(String key, JobParameter<?> jobParameter) Deprecated, for removal: This API element is subject to removal in a future version.since 5.0, scheduled for removal in 5.2.Add a new identifying String parameter for the given key.Add a new String parameter for the given key.getNextJobParameters
(Job job) Initializes theJobParameters
based on the state of theJob
.Conversion method that takes the current state of this builder and returns it as aJobParameters
object.
-
Constructor Details
-
JobParametersBuilder
public JobParametersBuilder()Default constructor. Initializes the builder with empty parameters. -
JobParametersBuilder
- Parameters:
jobExplorer
-JobExplorer
used for looking up previous job parameter information.
-
JobParametersBuilder
Copy constructor. Initializes the builder with the supplied parameters.- Parameters:
jobParameters
-JobParameters
instance used to initialize the builder.
-
JobParametersBuilder
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
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 identifyingDate
parameter 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 newDate
parameter 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 identifyingLocalDate
parameter 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 newLocalDate
parameter 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 identifyingLocalTime
parameter 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 newLocalTime
parameter 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 identifyingLocalDateTime
parameter 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 newLocalDateTime
parameter 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 identifyingLong
parameter 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 newLong
parameter 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 identifyingDouble
parameter 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 newDouble
parameter 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 aJobParameters
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.since 5.0, scheduled for removal in 5.2. UseaddJobParameter(java.lang.String, org.springframework.batch.core.JobParameter<?>)
.Add a newJobParameter
for the given key.- Parameters:
key
- The parameter accessor.jobParameter
- The runtime parameter.- Returns:
- a reference to this object.
-
addJobParameter
Add a newJobParameter
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 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 theJobParameters
based 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 asCommandLineJobRunner
with the-next
option andJobOperator.startNextInstance(String)
).- Parameters:
job
- The job for which theJobParameters
are being constructed.- Returns:
- a reference to this object.
- Since:
- 4.0
-