My requirement is to read Foo entries from a flat file and store them in the database after processing. However, the processing step may optionally require an additional set of 'Bar' entities (for each Foo) to be written to the Bar table. Can this be achieved with CompositeItemWriter and JdbcBatchItemWriters (for Foo and Bar) without me writing a custom writer that writes Foo and its corresponding Bar[] in batch. I am processing the records in chunks and have no foreign key ID reference requirement from Bar to Foo.
I've reviewed a bunch of posts in SO related to this and want to do something like this:
// create a composite type Foo-Bar as output of processor
Foo-Bar {
Foo foo, // processed foo
List<Bar> bars // zero or more bars
}
// define step using these
ItemReader<Foo>
ItemProcessor<Foo, Foo-Bar>
ItemWriter<Foo-Bar>
but can't figure out the right approach for ItemWriter esp given each Foo item has a list of Bar items. How do you setup a JdbcBatchItemWriter to write Bar[] items for each Foo when write(List<Foo-Bar> fooBars) is called by batch framework for each chunk of fooBars.
Thank you.