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
(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 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.addJobParameters
(JobParameters jobParameters) Copy job parameters into the current state.Add a new identifyingLong
parameter for the given key.Add a newLong
parameter for the given key.addParameter
(String key, JobParameter jobParameter) Add a newJobParameter
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 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
Constructor to add conversion capabilities to support JSR-352. Per the spec, it is expected that all keys and values in the providedProperties
instance areString
objects.- Parameters:
properties
- the job parameters to be used.
-
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.
-
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
Add a newJobParameter
for the given key.- Parameters:
key
- The parameter accessor.jobParameter
- The runtime parameter.- Returns:
- a reference to this object.
-
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
-