0

I was able to read from multiple tables and write them into a single xml using composite itemReader of spring batch. When I am doing this, the batch reads one row from each table at a time and writes it to xml, then proceeds to read the next row from each table.

But, my requirement is to read the entire table, write it to xml and then proceed to next table, read it completely and write to the same xml.

I have to read four tables in this manner and write all of them into a single xml.

Is there any way to do this in springbatch? Any help is appreciated.

Aacini
  • 65,180
  • 12
  • 72
  • 108
Harry
  • 1
  • 1

1 Answers1

0

You could create your own ItemReader which treats the whole table as one record. So on the first call to read() it would return a List of all rows.

You could either use the original ItemReader as a delegate or do the query yourself in your own reader.

This would change your step's datatype from T to List on Reader,Processor and Writer, so your Writer would have to be able to write a "multi-row-record".

public class DumpReader implements ItemReader<List<Row>> {
  private ItemReader<Row> delegate;  

  public List<Row> read() throws Exception {
    List<Row> data = new ArrayList<>();
    for (Row row = null; (row = this.delegate.read()) != null;) {
      data.add(row);
    }

    return data;
  }
}
dube
  • 4,898
  • 2
  • 23
  • 41