Add support to use any type as a job parameter

This commit also changes the way job parameters
are parsed and persisted.

NB: This commit should ideally have been split
into two change sets. But the changes are tightly
related that is was not possible to separate them.

Related to:

* https://github.com/spring-projects/spring-batch/issues/3960
* https://github.com/spring-projects/spring-batch/issues/2122
* https://github.com/spring-projects/spring-batch/issues/1035
* https://github.com/spring-projects/spring-batch/issues/1983
This commit is contained in:
Mahmoud Ben Hassine
2022-09-30 10:31:22 +02:00
parent 027302469a
commit 2660f2bb27
72 changed files with 2508 additions and 927 deletions

View File

@@ -958,7 +958,7 @@ The following example shows a date passed as a job parameter to a job defined in
====
[source, role="xmlContent"]
----
<bash$ java CommandLineJobRunner endOfDayJob.xml endOfDay schedule.date(date)=2007/05/05
<bash$ java CommandLineJobRunner endOfDayJob.xml endOfDay schedule.date=2007-05-05,java.time.LocalDate
----
====
@@ -968,7 +968,7 @@ The following example shows a date passed as a job parameter to a job defined in
====
[source, role="javaContent"]
----
<bash$ java CommandLineJobRunner io.spring.EndOfDayJobConfiguration endOfDay schedule.date(date)=2007/05/05
<bash$ java CommandLineJobRunner io.spring.EndOfDayJobConfiguration endOfDay schedule.date=2007-05-05,java.time.LocalDate
----
====
@@ -976,7 +976,7 @@ The following example shows a date passed as a job parameter to a job defined in
====
By default, the `CommandLineJobRunner` uses a `DefaultJobParametersConverter` that implicitly converts
key/value pairs to identifying job parameters. However, you can explicitly specify
which job parameters are identifying and which are not by prefixing them with `+` or `-`, respectively.
which job parameters are identifying and which are not by suffixing them with `true` or `false`, respectively.
In the following example, `schedule.date` is an identifying job parameter, while `vendor.id` is not:
@@ -984,7 +984,8 @@ In the following example, `schedule.date` is an identifying job parameter, while
[source, role="xmlContent"]
----
<bash$ java CommandLineJobRunner endOfDayJob.xml endOfDay \
+schedule.date(date)=2007/05/05 -vendor.id=123
schedule.date=2007-05-05,java.time.LocalDate,true \
vendor.id=123,java.lang.Long,false
----
====
@@ -992,7 +993,8 @@ In the following example, `schedule.date` is an identifying job parameter, while
[source, role="javaContent"]
----
<bash$ java CommandLineJobRunner io.spring.EndOfDayJobConfiguration endOfDay \
+schedule.date(date)=2007/05/05 -vendor.id=123
schedule.date=2007-05-05,java.time.LocalDate,true \
vendor.id=123,java.lang.Long,false
----
====
@@ -1006,7 +1008,8 @@ for simplicity, the class was used directly. This example uses the `EndOfDay`
example from the <<domain.adoc#domainLanguageOfBatch,The Domain Language of Batch>>. The first
argument is `endOfDayJob.xml`, which is the Spring ApplicationContext that contains the
`Job`. The second argument, `endOfDay,` represents the job name. The final argument,
`schedule.date(date)=2007/05/05`, is converted into a `JobParameters` object.
`schedule.date=2007-05-05,java.time.LocalDate`, is converted into a `JobParameter` object of type
`java.time.LocalDate`.
[role="xmlContent"]
The following example shows a sample configuration for `endOfDay` in XML:
@@ -1030,8 +1033,8 @@ for simplicity, the class was used directly. This example uses the `EndOfDay`
example from the <<domain.adoc#domainLanguageOfBatch,The Domain Language of Batch>>. The first
argument is `io.spring.EndOfDayJobConfiguration`, which is the fully qualified class name
to the configuration class that contains the Job. The second argument, `endOfDay`, represents
the job name. The final argument, `schedule.date(date)=2007/05/05`, is converted into a
`JobParameters` object.
the job name. The final argument, `schedule.date=2007-05-05,java.time.LocalDate`, is converted
into a `JobParameter` object of type `java.time.LocalDate`.
[role="javaContent"]
The following example shows a sample configuration for `endOfDay` in Java:
@@ -1067,7 +1070,8 @@ for simplicity, the class was used directly. This example uses the `EndOfDay`
example from the <<domain.adoc#domainLanguageOfBatch,The Domain Language of Batch>>. The first
argument is where your job is configured (either an XML file or a fully qualified class
name). The second argument, `endOfDay`, represents the job name. The final argument,
`schedule.date(date)=2007/05/05`, is converted into a `JobParameters` object.
schedule.date=2007-05-05,java.time.LocalDate`, is converted into a `JobParameter` object of type
`java.time.LocalDate`.
// TODO Given that this block is for PDF output, should it have the xmlContent and
// javaContent markers?

View File

@@ -138,12 +138,9 @@ listing shows:
----
CREATE TABLE BATCH_JOB_EXECUTION_PARAMS (
JOB_EXECUTION_ID BIGINT NOT NULL ,
TYPE_CD VARCHAR(6) NOT NULL ,
KEY_NAME VARCHAR(100) NOT NULL ,
STRING_VAL VARCHAR(250) ,
DATE_VAL DATETIME DEFAULT NULL ,
LONG_VAL BIGINT ,
DOUBLE_VAL DOUBLE PRECISION ,
NAME VARCHAR(100) NOT NULL ,
TYPE VARCHAR(100) NOT NULL ,
VALUE VARCHAR(2500) ,
IDENTIFYING CHAR(1) NOT NULL ,
constraint JOB_EXEC_PARAMS_FK foreign key (JOB_EXECUTION_ID)
references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID)
@@ -157,11 +154,9 @@ job execution to which the parameter entry belongs. Note that multiple rows (tha
key/value pairs) may exist for each execution.
* TYPE_CD: String representation of the type of value stored, which can be a string, a
date, a long, or a double. Because the type must be known, it cannot be null.
* KEY_NAME: The parameter key.
* STRING_VAL: Parameter value if the type is string.
* DATE_VAL: Parameter value if the type is date.
* LONG_VAL: Parameter value if the type is long.
* DOUBLE_VAL: Parameter value if the type is double.
* NAME: The parameter name.
* TYPE: The fully qualified name of the type of the parameter.
* VALUE: Parameter value
* IDENTIFYING: Flag indicating whether the parameter contributed to the identity of the
related `JobInstance`.