Java JAXB - 编写带有重启逻辑的 XML 文件
我正在创建一个非常大的 XML 文件(700mb 以上),该文件通过批处理处理大量数据。该程序充当极大的 sybase 数据库和应用程序之间的接口。我目前将 xsd 架构绑定到类。我需要一种能够在编写 XML 时考虑重启逻辑的方法。
IE 能够知道我在哪里停止。或者换句话说,如果程序失败,我需要能够查看最后写入 XML 文件的内容,以便它可以从我上次停下的地方继续。这是一个例子。
<root>
<WorkSet>
<Work>
<Customer>
<Work>
<Customer>
<WorkSet>
<Work>
.....
<root>
假设程序在写入“工作”或“工作集”节点后失败。有没有办法从我停止处理的地方继续进行?由于 XML 文件的剪切大小(假设它完成了 500mb 的 XML 并且失败),我试图避免将 XML 文件读回内存。
感谢您的帮助。
I'm creating a very large XML file (700mb +) that process large amounts of data via batch. The program serves as an interface between a extremely large sybase database and an application. I currently have the xsd schema bound to classes. I need a way of being able to write the XML with restart logic in mind.
I.E. being able to know where I left off. Or in other words, if the program fails, I need to be able to see what the was last wrote to the XML file so it can pick up where I left off. Here's an exmaple.
<root>
<WorkSet>
<Work>
<Customer>
<Work>
<Customer>
<WorkSet>
<Work>
.....
<root>
Say the program fails after writing a write 'work' or 'workset' node. Is there a way to pick up where I left off processing? I'm trying to avoid reading the XML file back into memory due to the shear size of the XML file (Say it finishes 500mb of XML and fails).
Thanks for the help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您可以将数据拆分为独立的 WorkSet 元素,则可以使用 JAXB 的片段模式一次将它们写出一个(当 JAXB 不写入标头时)。稍后只需连接文件并添加缺少的 XML 声明、开始结束标记即可。
您可能必须为此修改生成的类。我的意思是添加
@XmlRootElement
到 WorkSet java 类。如果一个工作集对于一个步骤来说仍然很大,您也可以使用工作来执行此操作,但您必须以某种方式生成丢失的标签。If you could split your data to independent WorkSet elements you can write them out one at a time with JAXB's fragment mode (when JAXB does not write the headers). Later simply concatenate the files and add the missing XML declaration, opening end closing tags.
It's is possible that you have to modify your generated classes for this. I mean adding
@XmlRootElement
to the WorkSet java class. If one WorkSet is still big for one step you can do this with Work too, but you have to generate somehow the missing tags.我不认为 JAXB 是适合这项工作的工具,但是...
您可以编写一个自定义 Marshaller 实现来跟踪已编组的对象并使用片段模式写出各个对象。
I don't think JAXB is the appropriate tool for this job, but ...
You could write a custom Marshaller implementation that keeps track of what objects have been marshalled and use the fragment mode to write out individual objects.