[英]How to effectively and correctly load sequential activities to Database using Spring batch?
I'm currently working on a project loading a .dat file info to database. 我目前正在一个项目中,将.dat文件信息加载到数据库中。 However, this .dat file contains not only data but also actions.
但是,此.dat文件不仅包含数据,而且还包含操作。 The first field indicates the action of the records and all else are just data.
第一个字段指示记录的操作,其他所有字段仅是数据。 Below are some examples records: A key1 key2 data1 data2 D key1 key2 data1 data2 C key1 key2 data1 data2
下面是一些示例记录:A key1 key2 data1 data2 D key1 key2 data1 data2 C key1 key2 data1 data2
let, A=add, D=delete, C=update The file size is roughly 5GB. let,A =添加,D =删除,C =更新文件大小约为5GB。 In this case, order of the records to be process does matter.
在这种情况下,要处理的记录的顺序很重要。 Is it possible to use Spring batch to batch process this?
可以使用Spring批处理对此进行批处理吗? A previous implementation done by my predecessor was to create 3 lists: addList, deleteList, updateList, and generate dml statements for them separately.
我的前任所做的以前的实现是创建3个列表:addList,deleteList,updateList,并分别为它们生成dml语句。 Although very efficient when loading, but it doesn't work because doesn't matter which order you execute these lists, it might cause data inconsistency.
尽管在加载时非常高效,但由于执行这些列表的顺序无关紧要,因此无法正常工作,但可能会导致数据不一致。 So to keep the data valid, I believe these records have to be executed in order.
因此,为了保持数据有效,我相信必须按顺序执行这些记录。
One solution I came up with is to set reader fetch-size to 1. But that seems to defeat the purpose of spring batch. 我想出的一种解决方案是将读取器的读取大小设置为1。但这似乎违反了spring batch的目的。
Are there better ways to do this? 有更好的方法可以做到这一点吗? perhaps not spring batch but something else?
也许不是春季批,而是其他?
您是否调查过PatternMatchingCompositeLineTokenizer https://docs.spring.io/spring-batch/trunk/apidocs/org/springframework/batch/item/file/mapping/PatternMatchingCompositeLineMapper.html
You should be able to achieve this (while preserving records order) using a combination of: 您应该能够(通过保留记录顺序)使用以下方式实现此目的:
PatternMatchingCompositeLineMapper
: to map items according to your patterns (A, D and C) PatternMatchingCompositeLineMapper
:根据您的模式(A,D和C)映射项目 ClassifierCompositeItemWriter
: configured with a PatternMatchingClassifier
. ClassifierCompositeItemWriter
:配置有PatternMatchingClassifier
。 This will classify items according to their type and use the corresponding writer (you should have one writer per type) to do the action.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.