Jul 15th, 2010, 11:54 AM
Single DB call using DAO that returns a list of items to supply to/as the ItemReader?
This question probably doesn't sit with Batch as well as it should because it doesn't represent a job that has a lot of items to process, but...
My understanding is that the ItemReader supplies a single item that you want to process within the job (as the name suggests). You can then optionally process it and then pass that item on the the ItemWriter for final processing (for lack of a better term).
A database is just one example of a possible source/destination for the reader and writers.
The problem I'm having, or more likely the gaping hole in my understanding, is that the DB query I'd like to use as the "input" for the job, the Reader, returns a list of result items, rather than a single item from a single row. I'd prefer to keep the query this way, since limiting or returning only the first row from the same or a similar query each time doesn't sound as nice or efficient.
I know I could do this by providing the query string to a JDBC ItemReader bean or similar, but I'd like to do it using a DAO method call, since this makes it easily test-able in isolation and re-useable.
At the moment I'm having to use a 'ItemReaderAdapter' so I can target the DAO method, but treating the LIST of results returned from the DAO as a single item for processing and being supplied to the ItemWriter.
I don't think this sounds like an unusual scenario, so I'm sure there must be a better more elegant solution. Can anyone point me in the right direction?
Thanks in advance,
Last edited by gph; Jul 16th, 2010 at 06:00 AM.
Jul 18th, 2010, 11:10 PM
There is http://static.springsource.org/sprin...temReader.html and also one based on a List. Is that what you need?
Jul 19th, 2010, 05:46 AM
Excellent - thanks Dave. This looks like exactly what I'm after.
... and armed with your nod towards the ListItemReader, I also found this post which gives a nice example of a possible implementation:
So thanks Spring Forum