[英]jOOQ - Does jOOQ support definition files or creation of SQL creation scripts?
In our project, concepts
are definied in a configuration file. 在我们的项目中,
concepts
在配置文件中定义。 To give an example: 举个例子:
<concepts>
<concept name="person">
<property name="age" type="integer"/>
...
</concept>
...
</concepts>
Although this has not much to do with SQL, this configuration file happens to be mappable to SQL tables, columns, ... 尽管这与SQL无关,但是此配置文件恰好可映射到SQL表,列,...。
Starting from this configuration file, I need to be able to do 2 things: 从此配置文件开始,我需要能够做两件事:
CREATE TABLE person ( ... )
). CREATE TABLE person ( ... )
)。 I would like to start using jOOQ in this project. 我想在这个项目中开始使用jOOQ。 Does jOOQ support any kind of generation (both SQL creation scripts and its POJOs, tables, ...) which does not start from an existing database?
jOOQ是否支持不从现有数据库开始的任何类型的生成(SQL创建脚本及其POJO,表等)? I looked through the documentation, but could not find much.
我浏览了文档,但是找不到很多。
If not, I am contemplating between two options: 如果没有,我正在考虑两种选择:
or 要么
Although I believe fhe first option requires more effort, it has currently my favor, since step 3 in the second option might introduce loss of information. 尽管我认为第一种选择需要付出更多的努力,但它目前对我有利,因为第二种选择中的步骤3可能会导致信息丢失。
This should obviously be solved with XSLT 显然应该使用XSLT解决
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<result>
<xsl:apply-templates select="concepts/concept"/>
</result>
</xsl:template>
<xsl:template match="concept">
<xsl:text>CREATE TABLE </xsl:text>
<xsl:value-of select="@name"/>
<xsl:text>(</xsl:text>
<xsl:apply-templates select="property"/>
<xsl:text>
);
</xsl:text>
</xsl:template>
<xsl:template match="property">
<xsl:choose>
<xsl:when test="position() > 1">
<xsl:text>
, </xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>
</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="@name"/>
<xsl:text> </xsl:text>
<xsl:value-of select="@type"/>
</xsl:template>
</xsl:stylesheet>
jOOQ-meta supports importing schema meta information from XML using the XMLDatabase
jOOQ-meta支持使用
XMLDatabase
从XML导入模式元信息
<configuration>
<generator>
<database>
<name>org.jooq.util.xml.XMLDatabase</name>
<properties>
<property>
<key>dialect</key>
<value>ORACLE</value>
</property>
<property>
<key>xml-file</key>
<value>src/main/resources/concepts-transformed.xml</value>
</property>
</properties>
Just transform your XML file into the following format: http://www.jooq.org/xsd/jooq-meta-3.5.4.xsd 只需将XML文件转换为以下格式即可: http : //www.jooq.org/xsd/jooq-meta-3.5.4.xsd
... eg using the following XSLT: ...例如,使用以下XSLT:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="schema" select="'MY_SCHEMA'"/>
<xsl:template match="/">
<information_schema xmlns="http://www.jooq.org/xsd/jooq-meta-3.5.4.xsd">
<schemata>
<schema>
<schema_name><xsl:value-of select="$schema"/></schema_name>
</schema>
</schemata>
<tables>
<xsl:apply-templates select="concepts/concept"/>
</tables>
<columns>
<xsl:apply-templates select="concepts/concept/property"/>
</columns>
</information_schema>
</xsl:template>
<xsl:template match="concept">
<table>
<schema_name><xsl:value-of select="$schema"/></schema_name>
<table_name><xsl:value-of select="@name"/></table_name>
</table>
</xsl:template>
<xsl:template match="property">
<column>
<schema_name><xsl:value-of select="$schema"/></schema_name>
<table_name><xsl:value-of select="../@name"/></table_name>
<column_name><xsl:value-of select="@name"/></column_name>
<data_type><xsl:value-of select="@type"/></data_type>
</column>
</xsl:template>
</xsl:stylesheet>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.