简体   繁体   English

如何在Spring Batch中的ItemWriter上提交后更新源数据的状态

[英]How to update status of source data after commit on ItemWriter in Spring Batch

I'm using ItemReader with paging to get data from the source table.我正在使用 ItemReader 和分页来从源表中获取数据。 On ItemProcessor one by one I will send a rest request to a service using the id of the item and pass their responses to the ItemWriter to store in another table.在 ItemProcessor 上,我将使用项目的 id 向服务发送一个休息请求,并将它们的响应传递给 ItemWriter 以存储在另一个表中。

At first read (page 1), each item on the chunk have a status of UNPROCESSED, then after processing and saving their responses to another table, I want to update the the status of all items in the current chunk to PROCESSED.在第一次读取(第 1 页)时,块上的每个项目的状态都为未处理,然后在处理并将其响应保存到另一个表后,我想将当前块中所有项目的状态更新为已处理。

On ItemReader I'm selecting all items that have UNPROCESSED status.在 ItemReader 上,我选择了所有具有 UNPROCESSED 状态的项目。 select * from table where status = unprocessed select * from table where status = unprocessed

My question is how can I update the status of each item in my source table that have been processed after saving the response.我的问题是如何更新保存响应后已处理的源表中每个项目的状态。 Because if I update the status, the paging is not correct anymore because of the update.因为如果我更新状态,由于更新,分页不再正确。 Page 2 will skip some items.第 2 页将跳过某些项目。

Your ItemWriter which is writing the response of your remote service can additionally write back to the source table as well.正在写入远程服务响应的 ItemWriter 也可以另外写回源表。 Thus, the item writer should do following因此,项目编写者应该执行以下操作

  1. write response of your webservice写你的网络服务的响应
  2. update the particular item id with status = processed使用状态 = 已处理更新特定项目 ID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM