简体   繁体   English

Java JAXB-使用重新启动逻辑编写XML文件

[英]Java JAXB - Writing XML files with restart logic

I'm creating a very large XML file (700mb +) that process large amounts of data via batch. 我正在创建一个非常大的XML文件(700mb +),该文件通过批处理处理大量数据。 The program serves as an interface between a extremely large sybase database and an application. 该程序可充当超大型sybase数据库和应用程序之间的接口。 I currently have the xsd schema bound to classes. 我目前有绑定到类的xsd模式。 I need a way of being able to write the XML with restart logic in mind. 我需要一种能够在考虑重新启动逻辑的情况下编写XML的方法。

IE being able to know where I left off. IE能够知道我离开的地方。 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. 换句话说,如果程序失败,我需要能够看到上次写入XML文件的内容,以便可以从我上次中断的地方继续。 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. 假设在写入“ work”或“ workset”节点后程序失败。 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). 由于XML文件的剪切大小,我试图避免将XML文件读回内存(例如,它完成了500mb的XML并失败了)。

Thanks for the help. 谢谢您的帮助。

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). 如果可以将数据拆分为独立的WorkSet元素,则可以使用JAXB的片段模式一次将它们写出一个(当JAXB不写标头时)。 Later simply concatenate the files and add the missing XML declaration, opening end closing tags. 稍后,只需将文件连接起来,然后添加缺少的XML声明,即可打开结束符。

It's is possible that you have to modify your generated classes for this. 您可能必须为此修改生成的类。 I mean adding @XmlRootElement to the WorkSet java class. 我的意思是将@XmlRootElement添加到WorkSet java类。 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. 如果一个WorkSet仍然很大,您也可以使用Work来执行此操作,但是您必须以某种方式生成丢失的标签。

I don't think JAXB is the appropriate tool for this job, but ... 我认为JAXB不是适合此工作的工具,但是...

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. 您可以编写一个自定义的Marshaller实现,以跟踪已编组了哪些对象,并使用片段模式写出单个对象。

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

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