Spring batch: effectively relating header and body records -
i'm trying write proof of concept spring batch involves reading fixed-width file , inserting records database. have 0 experience fall on , finding documentation little light on want achieve.
i can read header line , body lines no problem (using fixedlengthtokenizer
, patternmatchingcompositelinemapper
). however, when comes building domain objects, need 2 things less obvious:
- the object storing header id, filename etc needs total number of records in file (not number written db - facilitate manual checks if needed)
- the object storing individual records needs reference header id of file
in other words, item-by-item reading, processing , writing isn't enough. data corresponding each row depends on other rows in file.
i'm sure there must clean spring-based approach, i'm not sure start looking.
example:
hdr 12345 row 2013-08-01 lorem ipsum row 2013-08-01 dolor sit amet
the 3 domain objects need build are:
header {id: 12345, records: 2} record {header_id: 12345, text: lorem ipsum } record {header_id: 12345, text: dolor sit amet }
in production files more complex , large - wouldn't ideal write them out in intermediate state, instance, although wonder if solution might involve processing them in 2 passes, somehow building required data way?
thanks in advance,
Comments
Post a Comment