包含和排除
适用于 ✅ 开源版 ✅ 专业版 ✅ 企业版
代码生成配置中最重要的元素可能是用于包含和排除内容的元素,这些内容由您的数据库元数据配置报告。
这些表达式匹配以下任何对象类型,可以是它们的完全限定名称 (catalog.schema.object_name
),也可以只是它们的名称 (object_name
)
- 数组类型
- 域
- 枚举
- 链接
- 包
- 队列
- 例程
- 序列
- 表
- UDT
排除匹配在包含之前,这意味着被排除的内容不能再次包含。 例如
<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) ... """) ) )
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) ... """ } } }
有关更多详细信息,请参见配置 XSD和gradle 代码生成。
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) ... """ } } }
有关更多详细信息,请参见配置 XSD和gradle 代码生成。
// 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
<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) ) )
import org.jooq.meta.jaxb.* configuration { generator { database { includes = ".*" excludes = "INVISIBLE_COL|INVISIBLE_ROUTINE" isIncludeExcludeColumns = true isIncludeExcludePackageRoutines = true } } }
有关更多详细信息,请参见配置 XSD和gradle 代码生成。
configuration { generator { database { includes = ".*" excludes = "INVISIBLE_COL|INVISIBLE_ROUTINE" includeExcludeColumns = true includeExcludePackageRoutines = true } } }
有关更多详细信息,请参见配置 XSD和gradle 代码生成。
// 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
,正则表达式现在将匹配表和列。 例如,然后使用这种表达式
<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) ) )
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 } } }
有关更多详细信息,请参见配置 XSD和gradle 代码生成。
configuration { generator { database { includes = """ # Table part of the expression ( TABLE1 | TABLE2 ) # Column part of the expression (optional for tables) (\..*)? """ excludes = "INVISIBLE_COL" includeExcludeColumns = true } } }
有关更多详细信息,请参见配置 XSD和gradle 代码生成。
// 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 中排除视图
<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' """) ) )
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' """ } } }
有关更多详细信息,请参见配置 XSD和gradle 代码生成。
configuration { generator { database { includes = ".*" excludes = "STATIC_OBJECTS" excludeSql = """ select table_schema || '\.' || table_name from information_schema.tables where table_type != 'VIEW' """ } } }
有关更多详细信息,请参见配置 XSD和gradle 代码生成。
// 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.
一如既往,当使用正则表达式时,它们是具有默认标志的正则表达式。
反馈
您对此页面有任何反馈吗? 我们很乐意听取您的意见!