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

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -