arnaldop
arnaldop

Reputation: 333

How should I write a results file using Spring Batch

I have a Spring Batch import process that has the following steps:

  1. Read a file in a specific format
  2. Save data for people, attributes and appointments (each file line can mean multiple inserts to multiple tables)
  3. Write results file (primarily result of the read, but sometimes we can't process the read data into something we can coherently insert)

I currently have #1 in a set of Readers (one for each file format), and #2 and #3 in single Writer class. I feel that writing the results file should be a separate step from writing the data to the database, but I am not sure how to do this.

The options I know of are:

  1. A step listener
  2. A tasklet (?)

Are there other options and which option would be the way Spring Batch is designed for?

Upvotes: 0

Views: 1087

Answers (1)

Artefacto
Artefacto

Reputation: 97835

You can separate the current ItemWriter you have into two ItemWriters and use a CompositeItemWriter as your chunk writer. This will delegate in the order you specify to the your two writers.

Upvotes: 1

Related Questions