Hi,
This is my first post so apologies if I accidentally break any rules.
I'm wanting to implement a Batch job using a batch chunk consisting of a reader, processor and writer as follows:
Read from DB -> process -> send email and write to DB.
My understanding is that each of these are on a per item basis. So in the above scenario a single DB read would be made, but the reader presents the data from each result row in turn to the processor for processing each item, then on to the writer when the commit limit is reached, which is fine.
My issue is with the writer in that I would like to send an email for each item, but would prefer to do a single DB update for all items in one go rather than for each item.
i.e. a single "UPDATE ... WHERE id IN (1,2,3)" instead of:
"UPDATE ... WHERE id = 1;
UPDATE ... WHERE id = 2; etc."
For this I'm planning to do implement a CompositeItemWriter with something similar to the following:
Code:
public void write(java.util.List<SomeItem> item) {
int[] ids = int[item.size()];
int i = 0;
for (SomeItem o : item) {
// do single item processing i.e. send email
int[i] = item.getId();
i++;
}
// do single DB update using ID array/list
}
Just wondering if I'm on the right track, or whether there's a better recipe for this? (Or whether I'm missing something entirely
).
Thanks in advance,
G.