REST客户端,可以使用任何REST API运行时并持久保存数据动态创建新表

时间:2022-09-11 13:02:37

I'm looking for a solution with Spring / camel to consume multiple REST services during runtime and create tables to store the data from REST API and compare the data dynamically. I don't know the schema for JSON API in advance to generate the JAVA client classes to create JPA persistent entity classes during run time.

我正在寻找Spring / camel的解决方案,在运行时使用多个REST服务,并创建表来存储来自REST API的数据并动态地比较数据。我事先不知道JSON API的模式来生成JAVA客户端类以在运行时创建JPA持久性实体类。

1 个解决方案

#1


0  

You'll need to think through this differently. Id forget about Java class POJOs that you don't have and can't create since the class structure isn't known in advance. So anything with POJO->Entity binding would be pretty useless.

你需要以不同的方式思考。我忘记了你没有和不能创建的Java类POJO,因为事先不知道类结构。因此,任何使用POJO-> Entity绑定的东西都会毫无用处。

One solution is to simply parse the xml or json body manually with en event-based parser (like SAX for XML) and simply build an SQL create string as you go through the document. Your field and table names would correspond to the tags in the document. Without access to an XSD or other structure description, no meta data is available for field lengths or types. Make everything really long VARCHAR? Also perhaps an XML or other kind of database might suite your problem domain better. In any case, you could include such a thing right in your Camel route as a Processor that will process the body and create the necessary tables if they don't already exist. You could even alter a table for lengths in the process when you have a field value that is longer than what's currently defined.

一种解决方案是使用基于事件的解析器(如SAX for XML)手动解析xml或json主体,并在浏览文档时简单地构建SQL创建字符串。您的字段和表名称将对应于文档中的标记。如果无法访问XSD或其他结构描述,则没有可用于字段长度或类型的元数据。让一切真的很长VARCHAR?也许XML或其他类型的数据库可能更好地适应您的问题域。在任何情况下,您都可以在Camel路由中包含这样的东西作为处理器,它将处理正文并创建必要的表(如果它们尚不存在)。当字段值超过当前定义的字段值时,您甚至可以在表中更改表的长度。

#1


0  

You'll need to think through this differently. Id forget about Java class POJOs that you don't have and can't create since the class structure isn't known in advance. So anything with POJO->Entity binding would be pretty useless.

你需要以不同的方式思考。我忘记了你没有和不能创建的Java类POJO,因为事先不知道类结构。因此,任何使用POJO-> Entity绑定的东西都会毫无用处。

One solution is to simply parse the xml or json body manually with en event-based parser (like SAX for XML) and simply build an SQL create string as you go through the document. Your field and table names would correspond to the tags in the document. Without access to an XSD or other structure description, no meta data is available for field lengths or types. Make everything really long VARCHAR? Also perhaps an XML or other kind of database might suite your problem domain better. In any case, you could include such a thing right in your Camel route as a Processor that will process the body and create the necessary tables if they don't already exist. You could even alter a table for lengths in the process when you have a field value that is longer than what's currently defined.

一种解决方案是使用基于事件的解析器(如SAX for XML)手动解析xml或json主体,并在浏览文档时简单地构建SQL创建字符串。您的字段和表名称将对应于文档中的标记。如果无法访问XSD或其他结构描述,则没有可用于字段长度或类型的元数据。让一切真的很长VARCHAR?也许XML或其他类型的数据库可能更好地适应您的问题域。在任何情况下,您都可以在Camel路由中包含这样的东西作为处理器,它将处理正文并创建必要的表(如果它们尚不存在)。当字段值超过当前定义的字段值时,您甚至可以在表中更改表的长度。