Batch Core - Maintainability
So how easy is it to maintain and extend a project which uses batch-core. Of course that mainly depends on the change. But some frameworks and libraries make it easier and some harder to integrate changes.
We take our production planning example and want to only process the data for a specific production day.
So what do we need to do:
- pass the desired production day to the program (command line parameter)
- get the passed date to the step implementation
- change the SQL to optionally use the passed date
Changes
The production day can be passed to the program in various ways as we are using MicroProfile
Config and also have our own ConfigSource for the program call parameters.
1 | java -cp production-planning.jar:libs/* rpgnextgen.batch.Main start packaging --production-day 2025-12-30 |
In the step implementation we need to add the configuration property.
1 |
|
We make this an Optional because we also want to be able to not pass a production day. And as we are using
the SmallRye implementation of MicroProfile Config we can directly use LocalDate even though the
MicroProfile Config spec doesn’t support it.
The SQL only needs a little tweaking in the WHERE clause to support optionally passing a production day.
If none is passed the parameter is expected to be null.
1 |
|
Now we can either pass the production day as a LocalDate object to the stream method or pass null.
1 | dao.stream(productionDay.orElse(null)) |
And that’s it! 🎉
Wrap up
batch-core did not stand in our way in this change but really helped us. The production day
can be easily added as a parameter to program call (but also as an environment variable as
MicroProfile Config is used). Injecting the production day to the step implementation was also
easy and the adjustment in the SQL had nothing to do with batch-core.
What we didn’t cover was parameter validation. Passing a not valid date results in an exception and abnormal termination. That may be a desired result but it depends on your environment.
So this was a really easy one 😀 .
Happy coding!
Mihael