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

匹配器策略

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

使用自定义匹配器策略

上一节中,我们已经了解了如何以编程方式覆盖生成器策略。在本章中,我们将了解如何在 XML 或 Maven 代码生成器配置中配置此类策略。 除了指定策略名称之外,您还可以指定一个 <matchers/> 元素,如下面的小节所述。

此类匹配器的一般结构如下

XML(独立和 Maven)
编程方式
Gradle (Kotlin)
Gradle (Groovy)
Gradle(第三方)
<configuration>
  <!-- These properties can be added directly to the generator element: -->
  <generator>
    <strategy>
      <matchers>

        <tables>
          <table>

            <!-- Match unqualified or qualified table names. If left empty, this matcher applies to all tables. -->
            <expression>MY_TABLE</expression>

            <!-- These elements influence the naming of a generated org.jooq.Table object. -->
            <tableClass> a MatcherRule specification </tableClass>
            <tableIdentifier> a MatcherRule specification </tableIdentifier>
            <tableExtends>com.example.MyOptionalTableBaseType</tableExtends>
            <tableImplements>com.example.MyOptionalCustomInterface</tableImplements>
          </table>
        </tables>
      </matchers>
    </strategy>
  </generator>
</configuration>

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

new org.jooq.meta.jaxb.Configuration()

  // These properties can be added directly to the generator element:
  .withGenerator(new Generator()
    .withStrategy(new Strategy()
      .withMatchers(new Matchers()
        .withTables(
          new MatchersTableType()

            // Match unqualified or qualified table names. If left empty, this matcher applies to all tables.
            .withExpression("MY_TABLE")

            // These elements influence the naming of a generated org.jooq.Table object.
            .withTableClass(MatcherRule. a MatcherRule specification )
            .withTableIdentifier(MatcherRule. a MatcherRule specification )
            .withTableExtends("com.example.MyOptionalTableBaseType")
            .withTableImplements("com.example.MyOptionalCustomInterface")
        )
      )
    )
  )

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

import org.jooq.meta.jaxb.*


configuration {

  // These properties can be added directly to the generator element:
  generator {
    strategy {
      matchers {
        tables {
          table {

            // Match unqualified or qualified table names. If left empty, this matcher applies to all tables.
            expression = "MY_TABLE"

            // These elements influence the naming of a generated org.jooq.Table object.
            tableClass = MatcherRule. a MatcherRule specification 
            tableIdentifier = MatcherRule. a MatcherRule specification 
            tableExtends = "com.example.MyOptionalTableBaseType"
            tableImplements = "com.example.MyOptionalCustomInterface"
          }
        }
      }
    }
  }
}

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

configuration {

  // These properties can be added directly to the generator element:
  generator {
    strategy {
      matchers {
        tables {
          table {

            // Match unqualified or qualified table names. If left empty, this matcher applies to all tables.
            expression = "MY_TABLE"

            // These elements influence the naming of a generated org.jooq.Table object.
            tableClass = " a MatcherRule specification "
            tableIdentifier = " a MatcherRule specification "
            tableExtends = "com.example.MyOptionalTableBaseType"
            tableImplements = "com.example.MyOptionalCustomInterface"
          }
        }
      }
    }
  }
}

有关更多详细信息,请参阅配置 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.

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

匹配器配置元素可以是以下任何一种

  • 匹配标识符的正则表达式
  • org.jooq.meta.jaxb.MatcherRule 规范(请参阅MatcherRule
  • 常量值
所有匹配对象标识符的正则表达式都尝试首先通过非限定名称 (org.jooq.meta.Definition.getName()) 匹配标识符,然后通过限定名称 (org.jooq.meta.Definition.getQualifiedName()) 匹配。
当使用任何 recordExtendstableExtends 等设置时,您必须确保正确实现内部 jOOQ API,由于这些 API 是内部 API,因此此处未对其进行记录。 特别是,如果您要扩展 org.jooq.impl.TableImpl,例如,您的自定义基类可能会在 jOOQ 的小版本之间中断,因为会添加新的构造函数。

以下部分更详细地解释了以上内容

反馈

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

The jOOQ Logo