Description
Expected Behavior
I'd like to have the ability to access the updateCounts
array in the JdbcBatchItemWriter<>
.
This could be easily done by extracting the "assert updates" portion of the write()
method into a protected
method.
protected void postProcess(int[] updateCounts) throws Exception {
if (assertUpdates) {
for (int i = 0; i < updateCounts.length; i++) {
int value = updateCounts[i];
if (value == 0) {
throw new EmptyResultDataAccessException("Item " + i + " of " + updateCounts.length
+ " did not update any rows: [" + items.get(i) + "]", 1);
}
}
}
}
Then, my class, using a class that tracks the facilities (my business object) that were updated and inserted could look like this.
@Override
protected void postProcess(int[] updateCounts) throws Exception {
facilityTracker.addUpdated(Arrays.stream().sum());
super.postProcess(updateCounts);
}
Current Behavior
Currently, the updateCounts
array is a local variable in the write()
method, and I'd have to totally reimplement the entire method to have access to it. Having a parallel implementation that could become out of date in subsequent releases of Spring Batch.
Context
I realize that this might be niche ask, but my batch program updates a table of "facilities" based on data received from another system. I have to keep track of how may were updated and inserted, etc., but right now I can only estimate based on the result from my ItemProcessor
. My only other option is to totally reimplement the write()
method, including the complex JDBC code.
Note
I can provide a PR soon for this if it has any chance of being committed.