我在maven中使用jooq codegen插件从xml架构文件生成代码。
<configuration>
<generator>
<database>
<name>org.jooq.util.xml.XMLDatabase</name>
<properties>
<!-- Use any of the SQLDialect values here -->
<property>
<key>dialect</key>
<value>MYSQL</value>
</property>
<!-- Specify the location of your database file -->
<property>
<key>xml-file</key>
<value>${project.basedir}/src/main/resources/schema.xml</value>
</property>
</properties>
</database>
<generate>
<daos>true</daos>
<pojos>true</pojos>
<records>true</records>
<relations>true</relations>
<globalObjectReferences>false</globalObjectReferences>
</generate>
<target>
<!-- The destination package of your generated classes (within the
destination directory) -->
<packageName>com.generated.classes</packageName>
<!-- The destination directory of your generated classes. Using
Maven directory layout here -->
<directory>${project.basedir}/src/generated/classes</directory>
</target>
</generator>
</configuration>
是否有从两个不同模式文件生成代码的解决方案。示例:schema-other.xml。
答案 0 :(得分:1)
XMLDatabase
元数据源尚不支持此功能。待处理的功能请求为:https://github.com/jOOQ/jOOQ/issues/6260
但是有一些解决方法:
如果两个模式/文件未链接,则可以运行两个独立的代码生成运行。如果你正在使用Maven,你可以这样做(see also this question):
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>3.9.4</version>
<executions>
<execution>
<id>first-generation</id>
<phase>generate-sources</phase>
<goals><goal>generate</goal></goals>
<configuration>
<generator>
<database>
<name>org.jooq.util.xml.XMLDatabase</name>
...
<properties>
<property>
<key>xml-file</key>
<value>file1.xml</value>
</property>
</properties>
</database>
...
<target>
<packageName>com.generated.classes.schema1</packageName>
<directory>${project.basedir}/src/generated/classes</directory>
</target>
</generator>
</configuration>
</execution>
<execution>
<id>second-generation</id>
<phase>generate-sources</phase>
<goals><goal>generate</goal></goals>
<configuration>
<!-- jOOQ configuration here -->
</configuration>
</execution>
</executions>
</plugin>
如果您使用的是独立代码生成,只需配置两个单独的代码即可。
您当然可以手动将两个XML文件合并为一个,例如通过使用XSLT进行自动合并,或手动。