Jun 15th, 2011, 05:56 AM
Driving Query pattern and composites
Actually it is not a composite, it is a wrapper object, an account with orders.
I am a bit blank on how I would implement the driving query pattern for my case:
- I retrieve a set of domain objects with a reader (jdbc).
- Each object is passed to a processor which uses a key of the previously retrieved domain object and retrieves a set of other objects.
- I have a composite composed of the first retrieved object and the set of objects retrieved in the previous step.
- I want to write the first object and one item of the set in a file.
- Next line repeats the first object and the second item of the set.
- Continues writing the first item with the next item in the set until the set is processed.
I looked at the aggregators and thougt of overriding write in the FlatFileItemReader but since getOutputState is not accessible I did not look any further on overriding.
Extractor would not work because I am only able to pass back one line.
So the general question I think is how can I control writing of a composite?
Any ideas greatly appreciated.
Last edited by TarikS; Jun 15th, 2011 at 08:12 PM.
Jun 16th, 2011, 01:28 AM
you can try to return a list for each item in the processor and use a item writer that will receive a List<List<YourClass>>, iterate other each item and delegate to an out-of-the-box writer?
Jun 16th, 2011, 03:17 AM
Thank you Arno for your reply!
I found another way which looks like this:
- I have a reader that reads the account details (number, account holder name, etc.) from a db.
- The processor is CompositeItemProcessor:
- The first processor (aggregator) retrieves the orders of the account and stores it in holder which contains the account and the list of orders.
- The second processor (splitter) decomposes the holder and creates a lineitem object (another holder) that contains the account and one of the orders, creating a list of line items and returning the list of lineitem's.
- The writer (FlatFileItemWriter) uses a RecursiveCollectionLineAggregator which delegates to a DelimitedLineAggregator.
- The Extractor just creates the object array.
Nice framework, everything there
Jun 16th, 2011, 08:19 AM
That was what I was not sure of actually, how to implement an itemwriter without missing the functionality of the underlying database job handling ... if you'd have a pseudo example I'd be very interested.
Jun 17th, 2011, 09:45 AM
I'm afraid I don't see what you mean.
Originally Posted by TarikS