简体   繁体   English

Spring Batch:读取数据库并写入多记录平面文件

[英]Spring Batch: Reading database and writing into multi record Flat files

Hi I am doing POC/base for design on reading database and writing into flat files. 嗨,我正在做POC /基础设计,用于读取数据库和写入平面文件。 I am struggling on couple of issues here but first I will tell you the output format of flat file 我在这里要解决几个问题,但首先我将告诉您平面文件的输出格式 在此处输入图片说明

Please let me know how do design the input writer where I need to read the transactions from different tables, process records , figure out the summary fields and then how should I design the Item Writer which has such a complex design. 请让我知道如何设计输入编写器,在这里我需要从不同的表中读取事务,处理记录,找出摘要字段,然后如何设计具有如此复杂设计的项目编写器。 Please advice. 请指教。 I am successfully able to read from single table and write to file but the above task looks complex. 我可以成功地从单个表读取并写入文件,但是上述任务看起来很复杂。

Extend the FlatFileItemWriter to only open a file once and append to it instead of overwriting it. 扩展FlatFileItemWriter仅打开一个文件并将其追加到文件,而不是覆盖它。 Then pass that same filewriter into multiple readers in the order you would like them to appear. 然后按照您希望它们出现的顺序将同一个文件编写器传递给多个阅读器。 (Make sure that each object read by the readers are extensible by something that the writer understands! Maybe interface BatchWriteable would be a good name.) (确保读者能够读取的每个对象都可以被作者理解的东西扩展!也许interface BatchWriteable是一个好名字。)

Some back-of-the-envelope pseudocode: 一些信封后面的伪代码:

Before everything starts: 在一切开始之前:

  • Open file. 打开文件。
  • Write file headers. 编写文件头。
  • Start Batch step 开始批处理步骤

implement as many times as necessary 实施多次

  • Read Batch section 阅读批次部分
  • Process Batch section 处理批次部分
  • A Write Batch section 写批处理部分

when done: 完成后:

  • Write file footer 写入文件页脚
  • Close file 关闭档案

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

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