Generate JOOQ schema from file

Can I generate Java classes using JOOQ from sql file without connecting to database? I tried to specify an inputSchema tag, but I got an exception:

WARNING: SQL exception            : Exception while executing meta query: Cannot execute query. No Connection configured

My configuration is as follows:

<configuration>
                <generator>
                    <database>
                        <name>org.jooq.util.postgres.PostgresDatabase</name>
                        <inputSchema>filesystem:src/main/resources/schema.sql</inputSchema>
                        <includes>.*</includes>
                        <outputSchemaToDefault>true</outputSchemaToDefault>
                    </database>
                    <target>
                        <packageName>pckg.some</packageName>
                        <directory>target/generated-sources/jooq</directory>
                    </target>
                </generator>
</configuration>
+4
source share
1 answer

Yes, you can do such things, although not in the way you expect. First, jOOQ does not allow you to parse SQL statements and get schema meta-information in this way. This would be difficult to implement for all currently supported DBMSs.

However, you have 2 options:

1. Run the SQL file before generating the code

SQL , , H2, .

, JPA- Java Hibernate, jOOQ: http://vladmihalcea.com/jooq-facts-from-jpa-annotations-to-jooq-table-mappings

2. XML

jOOQ XML ( -). :

<!-- This value can be used to reverse-engineer standard jOOQ-meta XML formats

         org.jooq.util.xml.XMLDatabase

     You can also provide your own org.jooq.util.Database implementation
     here, if your database is currently not supported -->
<name>org.jooq.util.oracle.OracleDatabase</name>

XSD XML , XMLDatabase, : http://www.jooq.org/xsd/jooq-meta-3.5.4.xsd

. : http://www.jooq.org/doc/latest/manual/code-generation/codegen-configuration

+3

All Articles