如何使用 Java 和数据库实现 XML 模式的往返

发布于 2024-10-19 10:37:04 字数 609 浏览 2 评论 0原文

实现接收 XML 文件的往返并最终使用 Java 将数据保存到数据库中的最佳方法是什么?目前我有:
1. XML 模式和XML 数据文件发送给我
- XSD 相当复杂并且属于外部方,所以我无法更改它
2.创建Java类
- JAXB 生成超过 150 个类,不幸的是架构可能会改变
- 我使用 Maven POM 来自动化该过程 3. 将 XML 数据文件解组为 Java 对象(使用 JAXB 注释)
- 数据将显示给用户进行操作
4. 将 Java 对象保存到 RDBMS (Oracle / MySQL)
- 看来JDO是最合适的解决方案
5.导出数据
- 数据可以再次导出为 XML 或 Excel(例如)

我找不到合适的方法将 JDO 元数据或注释添加到 Java 源代码(在 JAXB 过程中生成)以确保我可以保留 Java 类。我正在使用以下技术:
- Java、Maven、JAXB、JDO 和JDBC

我认为 DataNucleus 最适合,因为我可能必须经常在具有不同导出目的地的环境之间更改数据存储(RDBMS / XML / Excel)。我可能需要考虑的另外两项技术是:
- Spring 和 XDoclet

建议或教程指针将不胜感激

What is the best way of implementing a roundtrip for receiving XML files and eventually persisting the data into a database using Java. Currently I have:
1. An XML Schema & XML data files send to me
- the XSD is fairly complex and belongs to an external party, so I can not change it
2. Created the Java classes
- JAXB generates over 150 classes, unfortunately the schema can change
- I have used Maven POM to automate the process
3. Unmarshall the XML data files into Java objects (with JAXB annotation)
- the data would be displayed to the user to be manipulated
4. Persist the Java objects into a RDBMS (Oracle / MySQL)
- it seems JDO is the most suitable solution
5. Exporting the data
- The data can be exported again as XML or Excel (for example)

I can not find a suitable way to add JDO metadata or annotations to the Java source code (generated during the JAXB process) to ensure I can persist the Java classes. I am working with the following technologies:
- Java, Maven, JAXB, JDO & JDBC

I think DataNucleus would be most suited as I might have to change datastores (RDBMS / XML / Excel) often between environments with different export destinations. The only other two technologies I might need to consider is:
- Spring and XDoclet

Advice or a pointer to a tutorial would be appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜嗑 2024-10-26 10:37:04

实施的最佳方式是什么?
接收 XML 文件的往返过程和
最终将数据持久化到
使用Java的数据库。

为此,我将使用 JAXB 和 JAXB 的组合。注意:我领导 EclipseLink JAXB (MOXy)EclipseLink 还提供了一个优秀的 JPA 实现

目前我有:

1 - XML 模式和XML 数据文件发送给我

  • XSD 相当复杂并且属于外部方,所以我可以
    不改变它

选项 #1 - 从 XML 模式开始

  • 如果您想从 XML 模式开始,您可以使用 JAXB 的外部绑定文件根据需要自定义类生成,而无需修改第三方 XML 模式。

选项 #2 - 从 Java 类开始

2 - 创建 Java 类

  • JAXB 生成超过 150 个类,遗憾的是架构可能会更改
  • 我使用 Maven POM 来自动化该过程

如果 XML 模式发生更改,您始终可以重新生成模型,或者根据需要注释模型以处理对模型的修改XML 架构。

您可能会发现 HyperJAXB 项目很有用,因为我相信它将直接在 JAXB 模型上生成 JPA 注释。

3 - 解组 XML 数据
文件转换为 Java 对象(使用 JAXB
注释)

  • 数据将显示给用户进行操作

这只是正常的 JAXB 使用。有关示例,请参阅:

4 - 将 Java 对象持久化到
RDBMS(Oracle / MySQL)

  • 看来JDO是最合适的解决方案

JPA 是另一种替代方案。

5 - 导出数据

  • 数据可以再次导出为 XML 或 Excel(例如)

这也是获取 XML 输出的正常 JAXB 用法。

What is the best way of implementing a
roundtrip for receiving XML files and
eventually persisting the data into a
database using Java.

For this I would use a combination of JAXB and JAXB. Note: I lead EclipseLink JAXB (MOXy), EclipseLink also provides an excellent JPA implementation.

Currently I have:

1 - An XML Schema & XML data files send to me

  • the XSD is fairly complex and belongs to an external party, so I can
    not change it

Option #1 - Start from XML Schema

  • If you want to start from XML schema you can use JAXB's external binding file to customize the class generation as needed without modifying third party XML Schema.

Option #2 - Start from Java Classes

2 - Created the Java classes

  • JAXB generates over 150 classes, unfortunately the schema can change
  • I have used Maven POM to automate the process

If the XML schema changes you can always regenerate your model, or annotate your model as necessary to handle the modifications to the XML schema.

You may find the HyperJAXB project useful, as I believe it will generate JPA annotations right onto a JAXB model.

3 - Unmarshall the XML data
files into Java objects (with JAXB
annotation)

  • the data would be displayed to the user to be manipulated

This is just normal JAXB usage. For an example see:

4 - Persist the Java objects into a
RDBMS (Oracle / MySQL)

  • it seems JDO is the most suitable solution

JPA is another alternative.

5 - Exporting the data

  • The data can be exported again as XML or Excel (for example)

Again this is normal JAXB usage to get the XML output.

感情废物 2024-10-26 10:37:04

恕我直言,在数据库中存储由 JAXB 从不断发展的 XML 模式生成的 Java 对象实例没有多大意义。关系数据库的目标是以明确定义的关系结构存储数据,以便能够轻松查询。

如果您想要的只是能够按原样取回之前收到的 XML 文档,只需将其作为 clob 存储在某个表或文件系统中即可。

如果确实需要以结构化方式将数据存储在数据库中,那么首先设计数据库模式,然后设计映射此数据库模式所需的 JDO 类,并实现将 JAXB 对象转换为 JDO 对象所需的业务逻辑,以便将它们存储在数据库中。

但在考虑您想要使用的技术之前,我会更多地考虑您想要实现什么功能。

Storing, in database, instances of Java objects generated by JAXB from an evolving XML schema doesn't make much sense, IMHO. The goal of a relational database is to store data, in a well-defined relational structure, in order to be able to query it easily.

If all you want is to be able to get back the XML document you received some time before, as is, just store it as a clob in some table, or in the file system.

If storing the data in database in a structured way is really needed, then design your database schema first, then design the JDO classes needed to map this database schema, and implement the business logic needed to transform your JAXB objects into JDO objects in order to store them in database.

But I would think more about what functionality you want to implement before thinking about the technologies you want to use.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文