简体   繁体   English

如何使用Spring批处理有效且正确地将顺序活动加载到数据库?

[英]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? 也许不是春季批,而是其他?

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.

相关问题 在使用多个标签的情况下,如何使用Spring Batch有效地解析XML - How to parse XML effectively using spring batch in case of mutiple tags 如何使用web.xml和Tomcat在Spring中正确加载上下文 - How to correctly load context in Spring using web.xml and Tomcat 如何使用 spring 批处理将数据库结果集转换为 xml 文件 - How to convert database result sets into xml file using spring batch 如何使用Spring Boot Batch Job更新数据库中的大数据 - How to update huge data in database using Spring Boot Batch Job 如何在Hibernate中有效地加载记录 - How to load records effectively in Hibernate 如何有效地实现数据库功能? - How to implement database functionality effectively? Spring 批处理:使用自定义批处理大小将列表写入数据库表 - Spring Batch : Write a List to a database table using a custom batch size 如何有效地在休眠中进行批量更新 - How to DO Batch Update in Hibernate Effectively 如何有效地使用网格或盒子布局? (正确吗?) - How to use grid or box layouts effectively? (Correctly?) 使用 Spring Boot 和 Spring Batch 读取 .csv 文件并将其存储在数据库中 - Reading .csv file and storing it in a database using Spring Boot and Spring Batch
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM