【问题标题】:How to use JOOQ Java Generator includes and excludes如何使用 JOOQ Java Generator 包含和排除
【发布时间】:2020-04-30 14:28:40
【问题描述】:

JOOQ Java 代码生成工具使用包含和排除元素中定义的正则表达式来控制生成的内容。我找不到关于运行这些表达式的架构结构的解释。

我希望能够排除服务器中的特定数据库以及按前缀或具体的表。

简单例子:

  • 给定一个带有两个数据库“A”和“B”的 SQL 服务器,我如何指示 JOOQ 只为数据库“A”中的表生成?

  • 如何指示 JOOQ 只为以前缀“qtbl”开头的表生成?

如果有可用的示例用例展示一些简单的常见配置,那就太好了。

【问题讨论】:

    标签: jooq


    【解决方案1】:

    jOOQ manual section about includes and excludes 以及其他一些解释代码生成器使用正则表达式匹配标识符的部分确定代码生成器将始终尝试:

    • 匹配完全限定标识符
    • 匹配不合格的标识符

    或者,如果您使用的是 jOOQ 3.12+ 并且没有关闭 <regexMatchesPartialQualification/>

    • 匹配部分限定标识符(请参阅#7947

    例如:

    <excludes>
      (?i:                      # Using case insensitive regex for the example
           database_prefix.*?\. # Match a catalog prefix prior to the qualifying "."
           .*?\.                # You don't seem to care about schema names, so match them all
           table_prefix.*?      # Match a table prefix at the end of the identifier
      )
    </excludes>
    

    除上述之外,如果您想在没有模式匹配的情况下排除特定数据库(“目录”)的生成,如果您指定 &lt;inputCatalog&gt;A&lt;/inputCatalog&gt;,您将获得更好的结果。另请参阅manual's section about schema mapping

    好处包括更快的代码生成,因为在使用正则表达式再次排除它们之前,只会在该目录中搜索要生成的对象。所以,你的配置可能是这样的:

    <!-- Include only database A -->
    <inputCatalog>A</inputCatalog>
    
    <!-- Include only tables with this (unqualified) prefix -->
    <includes>qtbl.*</includes>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-25
      • 2018-07-16
      • 2018-07-09
      • 2012-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多