Hi, thanks for the reply!
I have a query returning a list of records; for each record in that list there's a subquery returning child records! The subqueries are parameterized with data returned from master record. And all this data will be in the text file.
The generated file will looks like with this:
Master Record 1
Child Record 1 from Master Record 1
Child Record 2 from Master Record 1
Child Record 3 from Master Record 1
...
Master Record 2
Child Record 1 from Master Record 2
Child Record 2 from Master Record 2
Child Record 3 from Master Record 2
Child Record 4 from Master Record 2
...
and so on...
So, I guess, no, I can't return all data in the same query because the records aren't all the same type!
By using multiple steps... one approach would be be to read all master-records in a staging table and another step to read slave-records in another staging table! But I think it doesn't solve the issue because I still need maintain two cursor's, one for the staging table and another to the subquery.
One way to do it would be to have your ItemReader query to find all of the Master records. Then you could write your ItemWriter so that for each Master that it receives, it queries for all of the Child records and then writes everything. Something like:
Alternatively, you could do the same thing in an ItemProcessor and then inject the list of Child records onto the Master.Code:public void write(List<? extends Master> items) { for(Master item : items) { List<Child> children = queryForChildren(item); //write Master and all Child records } }