英文:
How to update status of source data after commit on ItemWriter in Spring Batch
问题
我正在使用带分页的ItemReader从源表中获取数据。在ItemProcessor中,我将逐一使用项目的ID向服务发送rest请求,并将它们的响应传递给ItemWriter,以存储在另一个表中。
在第一次读取(第1页)时,每个块上的项目都具有UNPROCESSED状态,然后在处理并将其响应保存到另一个表后,我希望将当前块中所有项目的状态更新为PROCESSED。
在ItemReader中,我正在选择所有具有UNPROCESSED状态的项目。
select * from table where status = unprocessed
我的问题是,在保存响应后如何更新源表中已处理的每个项目的状态。因为如果我更新状态,分页将不再正确,会因为更新而导致第2页跳过一些项目。
英文:
I'm using ItemReader with paging to get data from the source table. 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.
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.
On ItemReader I'm selecting all items that have UNPROCESSED status.
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.
答案1
得分: 0
你的ItemWriter负责写入远程服务的响应,还可以写回源表。因此,item writer 应执行以下操作:
- 写入 Web 服务的响应。
- 使用状态 = 已处理更新特定的项目 ID。
英文:
Your ItemWriter which is writing the response of your remote service can additionally write back to the source table as well. Thus, the item writer should do following
- write response of your webservice
- update the particular item id with status = processed
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论