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

包含和排除

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

代码生成配置中最重要的元素可能是用于包含和排除内容的元素,这些内容由您的数据库元数据配置报告。

这些表达式匹配以下任何对象类型,可以是它们的完全限定名称 (catalog.schema.object_name),也可以只是它们的名称 (object_name)

  • 数组类型
  • 枚举
  • 链接
  • 队列
  • 例程
  • 序列
  • UDT

排除匹配在包含之前,这意味着被排除的内容不能再次包含。 例如

XML(独立和 Maven)
编程方式
Gradle (Kotlin)
Gradle (Groovy)
Gradle(第三方)
<configuration>
  <generator>
    <database>
      <includes>.*</includes>
      <excludes>
           UNUSED_TABLE                # This table (unqualified name) should not be generated
         | PREFIX_.*                   # Objects with a given prefix should not be generated
         | SECRET_SCHEMA\.SECRET_TABLE # This table (qualified name) should not be generated
         | SECRET_ROUTINE              # This routine (unqualified name) ...
      </excludes>
    </database>
  </generator>
</configuration>

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

new org.jooq.meta.jaxb.Configuration()
  .withGenerator(new Generator()
    .withDatabase(new Database()
      .withIncludes(".*")
      .withExcludes("""
           UNUSED_TABLE                # This table (unqualified name) should not be generated
         | PREFIX_.*                   # Objects with a given prefix should not be generated
         | SECRET_SCHEMA\.SECRET_TABLE # This table (qualified name) should not be generated
         | SECRET_ROUTINE              # This routine (unqualified name) ...
      """)
    )
  )

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

import org.jooq.meta.jaxb.*


configuration {
  generator {
    database {
      includes = ".*"
      excludes = """
           UNUSED_TABLE                # This table (unqualified name) should not be generated
         | PREFIX_.*                   # Objects with a given prefix should not be generated
         | SECRET_SCHEMA\.SECRET_TABLE # This table (qualified name) should not be generated
         | SECRET_ROUTINE              # This routine (unqualified name) ...
      """
    }
  }
}

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

configuration {
  generator {
    database {
      includes = ".*"
      excludes = """
           UNUSED_TABLE                # This table (unqualified name) should not be generated
         | PREFIX_.*                   # Objects with a given prefix should not be generated
         | SECRET_SCHEMA\.SECRET_TABLE # This table (qualified name) should not be generated
         | SECRET_ROUTINE              # This routine (unqualified name) ...
      """
    }
  }
}

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

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

标识符范围

一组特殊的附加选项允许指定上述两个正则表达式是否也应匹配嵌套对象,例如表列或包例程。 以下示例将隐藏任何表中的INVISIBLE_COL(以及以这种方式调用的表和其他对象),以及INVISIBLE_ROUTINE

XML(独立和 Maven)
编程方式
Gradle (Kotlin)
Gradle (Groovy)
Gradle(第三方)
<configuration>
  <generator>
    <database>
      <includes>.*</includes>
      <excludes>INVISIBLE_COL|INVISIBLE_ROUTINE</excludes>
      <includeExcludeColumns>true</includeExcludeColumns>
      <includeExcludePackageRoutines>true</includeExcludePackageRoutines>
    </database>
  </generator>
</configuration>

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

new org.jooq.meta.jaxb.Configuration()
  .withGenerator(new Generator()
    .withDatabase(new Database()
      .withIncludes(".*")
      .withExcludes("INVISIBLE_COL|INVISIBLE_ROUTINE")
      .withIncludeExcludeColumns(true)
      .withIncludeExcludePackageRoutines(true)
    )
  )

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

import org.jooq.meta.jaxb.*


configuration {
  generator {
    database {
      includes = ".*"
      excludes = "INVISIBLE_COL|INVISIBLE_ROUTINE"
      isIncludeExcludeColumns = true
      isIncludeExcludePackageRoutines = true
    }
  }
}

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

configuration {
  generator {
    database {
      includes = ".*"
      excludes = "INVISIBLE_COL|INVISIBLE_ROUTINE"
      includeExcludeColumns = true
      includeExcludePackageRoutines = true
    }
  }
}

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

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

如果启用了这些标志,请确保理解它们将在标识符层次结构的所有相关级别上匹配。 例如,对于includeExcludeColumns,正则表达式现在将匹配表列。 例如,然后使用这种表达式

XML(独立和 Maven)
编程方式
Gradle (Kotlin)
Gradle (Groovy)
Gradle(第三方)
<configuration>
  <generator>
    <database>
      <includes>
      # Table part of the expression
      (
        TABLE1
      | TABLE2
      )

      # Column part of the expression (optional for tables)
      (\..*)?
      </includes>
      <excludes>INVISIBLE_COL</excludes>
      <includeExcludeColumns>true</includeExcludeColumns>
    </database>
  </generator>
</configuration>

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

new org.jooq.meta.jaxb.Configuration()
  .withGenerator(new Generator()
    .withDatabase(new Database()
      .withIncludes("""
      # Table part of the expression
      (
        TABLE1
      | TABLE2
      )

      # Column part of the expression (optional for tables)
      (\..*)?
      """)
      .withExcludes("INVISIBLE_COL")
      .withIncludeExcludeColumns(true)
    )
  )

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

import org.jooq.meta.jaxb.*


configuration {
  generator {
    database {
      includes = """
      # Table part of the expression
      (
        TABLE1
      | TABLE2
      )

      # Column part of the expression (optional for tables)
      (\..*)?
      """
      excludes = "INVISIBLE_COL"
      isIncludeExcludeColumns = true
    }
  }
}

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

configuration {
  generator {
    database {
      includes = """
      # Table part of the expression
      (
        TABLE1
      | TABLE2
      )

      # Column part of the expression (optional for tables)
      (\..*)?
      """
      excludes = "INVISIBLE_COL"
      includeExcludeColumns = true
    }
  }
}

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

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

动态正则表达式

有时,您希望基于比对象的标识符更复杂的元数据动态生成正则表达式。 例如,您可能希望排除生成所有视图。 这可以通过附加<includeSql/<<excludeSql/<元素来完成,这些元素生成的表达式与<includes/<<excludes/<组合在一起。 例如,如果您在 PostgreSQL 中排除视图

XML(独立和 Maven)
编程方式
Gradle (Kotlin)
Gradle (Groovy)
Gradle(第三方)
<configuration>
  <generator>
    <database>
      <includes>.*</includes>
      <excludes>STATIC_OBJECTS</excludes>
      <excludeSql>
        select table_schema || '\.' || table_name
        from information_schema.tables
        where table_type != 'VIEW'
      </excludeSql>
    </database>
  </generator>
</configuration>

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

new org.jooq.meta.jaxb.Configuration()
  .withGenerator(new Generator()
    .withDatabase(new Database()
      .withIncludes(".*")
      .withExcludes("STATIC_OBJECTS")
      .withExcludeSql("""
        select table_schema || '\.' || table_name
        from information_schema.tables
        where table_type != 'VIEW'
      """)
    )
  )

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

import org.jooq.meta.jaxb.*


configuration {
  generator {
    database {
      includes = ".*"
      excludes = "STATIC_OBJECTS"
      excludeSql = """
        select table_schema || '\.' || table_name
        from information_schema.tables
        where table_type != 'VIEW'
      """
    }
  }
}

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

configuration {
  generator {
    database {
      includes = ".*"
      excludes = "STATIC_OBJECTS"
      excludeSql = """
        select table_schema || '\.' || table_name
        from information_schema.tables
        where table_type != 'VIEW'
      """
    }
  }
}

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