1

I have a requirement to split my input file which contains records of different length and type some beans. I am able to map each record to different bean using CompositeItemReader. But there is some parent-child relation exists between these records. I want to form a bean which contains child beans. Any help is appreciated.

This is my sample input file.

AB,01,05,HHGFG,05 CD,452,63,FDD,07,54,76,EQWED PT,GGG,76,YYY CD,08,06,ASW,97,55,66,BT AB,96,87,KKK,03 PT,TIPWQ,19,YEQ PT,ROPRG,39,PRVM

CD,08,06,ASW,97,55,66,BT

Here AB is considered as parent record. My segments start with AB*, CD*, PT*

Anna
  • 83
  • 2
  • 7
  • Do all the child beans/lines come directly after the parent (in the file)? For instance ParentLine1->childLine->childLine->ParentLine2->childLine->childLine – Paul Samsotha Aug 08 '14 at 08:39
  • This is my sample input file AB,01,05,HHGFG,05 CD,452,63,FDD,07,54,76,EQWED PT,GGG,76,YYY CD,08,06,ASW,97,55,66,BT AB,96,87,KKK,03 PT,TIPWQ,19,YEQ PT,ROPRG,39,PRVM CD,08,06,ASW,97,55,66,BT – Anna Aug 08 '14 at 08:40
  • AB,01,05,HHGFG,05 CD,452,63,FDD,07,54,76,EQWED PT,GGG,76,YYY CD,08,06,ASW,97,55,66,BT AB,96,87,KKK,03 PT,TIPWQ,19,YEQ PT,ROPRG,39,PRVM CD,08,06,ASW,97,55,66,BT – Anna Aug 08 '14 at 08:44
  • 1
    That doesn't really say much without explaining the relation. You should also just edit your post with new information, instead of writing it in the comments. That way you can format it with some markdown. Also please answer the question in my first comment. – Paul Samsotha Aug 08 '14 at 08:44
  • Hello, Do you have any excample for AggregateItemReader.? – Anna Aug 08 '14 at 09:48
  • `AggregateItemReader` is custom class created for that example linked by @LucaBassoRicci in his answer. Look in the src/main/resources/job of the project and look for the multilineOrder job. There's you will see a use. – Paul Samsotha Aug 08 '14 at 09:52
  • Have a look at [this post](http://stackoverflow.com/a/24246311/2587435) that uses a similar approach – Paul Samsotha Aug 08 '14 at 10:08

1 Answers1

3

Top level domain object creation is responsability of ItemReader so this type of aggregation should be done in reading phase.
In SB-sample-projects there is a multilineOrder sample where you have a skeleton about how to resolve this type of problem; of course you have to resolve "manually" parent/child relationship between objects and manage errors during read.
Another example at Spring Batch :Aggregated reader / writer Issue

Community
  • 1
  • 1
Luca Basso Ricci
  • 17,829
  • 2
  • 47
  • 69
  • Hi Luca, If possible can you provide some examples for AggregatedItemReader? I dont find any. – Anna Aug 08 '14 at 09:47
  • https://github.com/spring-projects/spring-batch/blob/master/spring-batch-samples/src/main/java/org/springframework/batch/sample/domain/multiline/AggregateItemReader.java also check linked question to my answer – Luca Basso Ricci Aug 08 '14 at 10:07