Riyaz
Riyaz

Reputation: 676

Passing an Object from LineCallbackHandler to ItemWriter

I am writing a batch application which reads line-by-line from a file, process the content and write to database. Am using FlatFileItemReader for reading from file.

The first line in the file is special (header) which is skipped using linesToSkip and processed using a LineCallbackHandler (HeaderHandler). The HeaderHandler builds a cache using the header information.

Now I want to make use of this cache within my ItemWriter. Am not sure how to pass the cache object I build within HeaderHandler to my ItemWriter. Is there a clean way of doing this?

Upvotes: 2

Views: 2630

Answers (1)

Michael Pralow
Michael Pralow

Reputation: 6630

you have at least 2 possibilities:

  1. use the StepExecutionContext as temporary memory for your data, take a look at the spring batch doc: passing data to future steps (just ignore the promotionListener part) your headerHandler writes the cache into the context and the writer pulls the cache from the context
  2. use a spring bean with either a custom DataObjectClass or String, Map, etc. which will be injected in the headerHandler and the (custom)itemWriter both use it accordingly

Upvotes: 2

Related Questions