当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Can Spring Batch use the results of Driving Query more than once?

问题描述:

I have a batch process that I need to implement. My clients preferred batch framework is Spring Batch.

The logical process is

  1. select a load of records from a database at a known state
  2. write the records to a file
  3. update the state of the records that have been written to the file

The process is likely to touch quite a large number of records, and I'd like to keep the updating transaction as short as possible, so my intended design is to

  1. use the Driving Query Pattern to produce a list of candidate rows
  2. iterate over the results from step 1 writing them to an output file
  3. Begin transaction
  4. iterate over the results of step 1 again, updating the state of the rows in the database
  5. End Transaction

I'm intending to use an existing data access layer to do the database work, rather than using the spring JdbcCursorItemReader.

Is this something that Spring Batch can cope with readily, or do I need to think again?

Thanks in advance

Dave

网友答案:

Actually this is described in Common Batch Patterns document; you may read section 11.4 Driving Query Based ItemReaders

By using a CompositeItemWriter having a file output writer and your db update logic and a processor that takes input from your first step, you may simulate the behaviour wanted.

Hope that this helps

分享给朋友:
您可能感兴趣的文章:
随机阅读: