简体   繁体   English

Jooq XML 数据库生成

[英]Jooq XML Database generation

I am manually defining a Database XML schema to use the Jooq capabilities to generate the corresponding code from the definition.我手动定义了一个数据库 XML 模式,以使用 Jooq 功能从定义中生成相应的代码。 I am using Gradle to generate the code with Jooq:我正在使用 Gradle 和 Jooq 生成代码:

jooq {
    version = '3.13.5'
    edition = nu.studer.gradle.jooq.JooqEdition.OSS
    configurations {
        crate {  
            generationTool {
                logging = org.jooq.meta.jaxb.Logging.INFO
                generator {
                    database {
                        name = 'org.jooq.meta.xml.XMLDatabase'
                        properties {
                            property {
                                key = 'dialect'
                                value = 'POSTGRES'
                            }
                            property {
                                key = 'xmlFile'
                                value = 'src/main/resources/crate_information_schema.xml'
                            }
                        }
                    }
                    target {
                        packageName = 'it.fox.crate'
                        directory = 'src/generated/crate'
                    }
                    strategy.name = "it.fox.generator.CrateGenerationStrategy"
                }
            }
        }
    }
}

and this is the XML file crate_information_schema.xml I am referencing:这是我引用的 XML 文件crate_information_schema.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<information_schema xmlns="http://www.jooq.org/xsd/jooq-meta-3.14.0.xsd">
    <schemata>
        <schema>
            <catalog_name></catalog_name>
            <schema_name>doc</schema_name>
            <comment></comment>
        </schema>
    </schemata>
    <tables>
        <table>
            <table_catalog></table_catalog>
            <table_schema>doc</table_schema>
            <table_name>events</table_name>
            <table_type>BASE TABLE</table_type>
            <comment></comment>
        </table>
    </tables>
    <columns>
        <column>
            <table_catalog></table_catalog>
            <table_schema>doc</table_schema>
            <table_name>events</table_name>
            <column_name>data_block['angularPositionArray']</column_name>
            <data_type>real_array</data_type>
            <character_maximum_length>0</character_maximum_length>
            <numeric_precision>19</numeric_precision>
            <numeric_scale>0</numeric_scale>
            <ordinal_position>1</ordinal_position>
            <is_nullable>false</is_nullable>
            <comment>angularPositionArray</comment>
        </column>
        <column>
            <table_catalog></table_catalog>
            <table_schema>doc</table_schema>
            <table_name>events</table_name>
            <column_name>data_block['eventId']</column_name>
            <data_type>bigint(20)</data_type>
            <character_maximum_length>0</character_maximum_length>
            <numeric_precision>19</numeric_precision>
            <numeric_scale>0</numeric_scale>
            <ordinal_position>1</ordinal_position>
            <is_nullable>false</is_nullable>
            <comment>eventId</comment>
        </column>
    </columns>
</information_schema>

The code generated is not good, because it indicate the Data Type used is unknown:生成的代码不好,因为它表明使用的数据类型未知:

 /**
     * @deprecated Unknown data type. Please define an explicit {@link org.jooq.Binding} to specify how this type should be handled. Deprecation can be turned off using {@literal <deprecationOnUnknownTypes/>} in your code generator configuration.
     */
    @java.lang.Deprecated
    public final TableField<EventsRecord, Object> angularPositionArray = createField(DSL.name("data_block['angularPositionArray']"), org.jooq.impl.DefaultDataType.getDefaultDataType("\"real_array\"").nullable(false), this, "angularPositionArray");

I have a couple of questions:我有一些问题:

  • which is the correct data type for Real Array?哪个是 Real Array 的正确数据类型?
  • where is the list of supported data type with the keys to use in the XML?支持的数据类型列表以及要在 XML 中使用的键在哪里?

NB CrateDB is an unsupported DataBase but Jooq could talk to the DB using the Postgres driver, the only problem is to create manually the schema. NB CrateDB 是不受支持的数据库,但 Jooq 可以使用 Postgres 驱动程序与数据库对话,唯一的问题是手动创建模式。

which is the correct data type for Real Array?哪个是 Real Array 的正确数据类型?

Use <data_type>real array</data_type> (with a whitespace)使用<data_type>real array</data_type> (带空格)

where is the list of supported data type with the keys to use in the XML?支持的数据类型列表以及要在 XML 中使用的键在哪里?

It's the same as for any other code generation data source: All the types in SQLDataType are supported.它与任何其他代码生成数据源相同:支持SQLDataType中的所有类型。 The convention around array types is currently undocumented, but any of HSQLDB's or PostgreSQL's notations should work.围绕数组类型的约定目前没有记录,但任何 HSQLDB 或 PostgreSQL 的符号都应该工作。 The feature request to formally support array types as user defined types via standard SQL INFORMATION_SCHEMA.ELEMENT_TYPES is here: https://github.com/jOOQ/jOOQ/issues/8090通过标准 SQL INFORMATION_SCHEMA.ELEMENT_TYPES正式支持数组类型作为用户定义类型的功能请求在这里: https : //github.com/jOOQ/jOOQ/issues/8090

NB CrateDB is an unsupported DataBase but Jooq could talk to the DB using the Postgres driver, the only problem is to create manually the schema. NB CrateDB 是不受支持的数据库,但 Jooq 可以使用 Postgres 驱动程序与数据库对话,唯一的问题是手动创建模式。

You can obviously use the XMLDatabase for this.您显然可以为此使用XMLDatabase I'm guessing you cannot use the JDBCDatabase , because the INFORMATION_SCHEMA is too different, and the PG_CATALOG schema doesn't exist?我猜你不能使用JDBCDatabase ,因为INFORMATION_SCHEMA太不同了, PG_CATALOG模式不存在? However, you could easily implement your own org.jooq.meta.Database , too, if that makes more sense.但是,如果更有意义,您也可以轻松实现自己的org.jooq.meta.Database

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM