可用版本: Dev (3.21) | 最新 (3.20) | 3.19 | 3.18 | 3.17 | 3.16 | 3.15 | 3.14

合成唯一键

适用于 ❌ 开源版   ✅ Express 版   ✅ 专业版   ✅ 企业版

jOOQ 的代码生成器可以识别数据库声明并报告的唯一键。但是一些数据库不会报告所有的键,或者一些表没有启用它们,或者有时候,视图是底层表的 1:1 表示,但它不会公开键信息。在这种情况下,此正则表达式可以匹配用户希望“假装”是此类唯一键的一部分的所有列。如果需要复合合成唯一键,则正则表达式应匹配该表中作为唯一键一部分的所有列。例如,复合合成唯一键由 SCHEMA.TABLE 表中的 (COLUMN1, COLUMN2) 组成

XML(独立和 Maven)
编程方式
Gradle (Kotlin)
Gradle (Groovy)
Gradle(第三方)
<configuration>
  <generator>
    <database>
      <syntheticObjects>
        <uniqueKeys>
          <uniqueKey>

            <!-- Optional name of the unique key, if tables matches only a single table. -->
            <name>UK_TABLE</name>

            <!-- Optional regular expression matching all tables that have this unique key. -->
            <tables>SCHEMA\.TABLE</tables>

            <!-- List multiple fields in the key order -->
            <fields>
              <field>COLUMN1</field>
              <field>COLUMN2</field>
            </fields>
          </uniqueKey>
        </uniqueKeys>
      </syntheticObjects>
    </database>
  </generator>
</configuration>

有关更多详细信息,请参阅配置 XSD独立代码生成maven 代码生成

new org.jooq.meta.jaxb.Configuration()
  .withGenerator(new Generator()
    .withDatabase(new Database()
      .withSyntheticObjects(new SyntheticObjectsType()
        .withUniqueKeys(
          new SyntheticUniqueKeyType()

            // Optional name of the unique key, if tables matches only a single table.
            .withName("UK_TABLE")

            // Optional regular expression matching all tables that have this unique key.
            .withTables("SCHEMA\\.TABLE")

            // List multiple fields in the key order
            .withFields(
              "COLUMN1",
              "COLUMN2"
            )
        )
      )
    )
  )

有关更多详细信息,请参阅配置 XSD编程式代码生成

import org.jooq.meta.jaxb.*


configuration {
  generator {
    database {
      syntheticObjects {
        uniqueKeys {
          uniqueKey {

            // Optional name of the unique key, if tables matches only a single table.
            name = "UK_TABLE"

            // Optional regular expression matching all tables that have this unique key.
            tables = "SCHEMA\\.TABLE"

            // List multiple fields in the key order
            fields {
              field = "COLUMN1"
              field = "COLUMN2"
            }
          }
        }
      }
    }
  }
}

有关更多详细信息,请参阅配置 XSDgradle 代码生成

configuration {
  generator {
    database {
      syntheticObjects {
        uniqueKeys {
          uniqueKey {

            // Optional name of the unique key, if tables matches only a single table.
            name = "UK_TABLE"

            // Optional regular expression matching all tables that have this unique key.
            tables = "SCHEMA\\.TABLE"

            // List multiple fields in the key order
            fields {
              field = "COLUMN1"
              field = "COLUMN2"
            }
          }
        }
      }
    }
  }
}

有关更多详细信息,请参阅配置 XSDgradle 代码生成

// The jOOQ-codegen-gradle plugin has been introduced in version 3.19.
// Please use the official plugin instead of the third party plugin that was recommended before.

一如既往,当使用正则表达式时,它们是具有默认标志的正则表达式

引用此页

反馈

您对此页面有任何反馈吗? 我们很乐意听取您的意见!

The jOOQ Logo