合成列
适用于 ❌ 开源版 ✅ Express 版 ✅ 专业版 ✅ 企业版
在某些用例中,您可能希望 jOOQ 的代码生成器生成比您的元数据源指示的更多的列(每个表)。例如:
- 您的代码生成用户无权访问某些列,但您的运行时用户将有权访问。
- 您的代码生成数据库尚未/不再拥有这些列,但您的生产系统拥有。
- 您正在生成客户端计算列,并且您希望它们具有
VIRTUAL
语义(读取时计算),因此这些列实际上并不存在于模式中。
在这些情况下,您可以像这样将合成列添加到您的模式中:
XML(独立和 Maven)
编程方式
Gradle (Kotlin)
Gradle (Groovy)
Gradle(第三方)
<configuration> <generator> <database> <syntheticObjects> <columns> <column> <!-- Optional regular expression matching all tables that have this identity. --> <tables>SCHEMA\.TABLE</tables> <!-- The name of the column --> <name>COLUMN</name> <!-- The type of the column --> <type>INTEGER</type> </column> </columns> </syntheticObjects> </database> </generator> </configuration>
有关更多详细信息,请参见配置 XSD,独立代码生成和Maven 代码生成。
new org.jooq.meta.jaxb.Configuration() .withGenerator(new Generator() .withDatabase(new Database() .withSyntheticObjects(new SyntheticObjectsType() .withColumns( new SyntheticColumnType() // Optional regular expression matching all tables that have this identity. .withTables("SCHEMA\\.TABLE") // The name of the column .withName("COLUMN") // The type of the column .withType("INTEGER") ) ) ) )
有关更多详细信息,请参见配置 XSD和以编程方式进行代码生成。
import org.jooq.meta.jaxb.* configuration { generator { database { syntheticObjects { columns { column { // Optional regular expression matching all tables that have this identity. tables = "SCHEMA\\.TABLE" // The name of the column name = "COLUMN" // The type of the column type = "INTEGER" } } } } } }
有关更多详细信息,请参见配置 XSD和gradle 代码生成。
configuration { generator { database { syntheticObjects { columns { column { // Optional regular expression matching all tables that have this identity. tables = "SCHEMA\\.TABLE" // The name of the column name = "COLUMN" // The type of the column type = "INTEGER" } } } } } }
有关更多详细信息,请参见配置 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.
一如既往,当使用正则表达式时,它们是具有默认标志的正则表达式。
反馈
您对此页面有任何反馈吗? 我们很乐意听取您的意见!