隐式 JOIN 路径
适用于 ✅ 开源版 ✅ 专业版 ✅ 企业版
隐式 JOIN 是 jOOQ 最强大的合成 SQL 功能之一,它完全依赖于代码生成。代码生成器生成表之间的链接,这些链接遵循
-
to-one关系(即从子表到父表) -
to-many关系(即从父表到子表) -
many-to-many关系(即从父表 1 到关系表到父表 2)
这样,就可以大大简化您的查询
// Get all books, their authors, and their respective language
create.select(
BOOK.author().FIRST_NAME,
BOOK.author().LAST_NAME,
BOOK.TITLE,
BOOK.language().CD.as("language"))
.from(BOOK)
.fetch();
该功能在代码生成器中有一些功能切换,包括
XML(独立和 Maven)
编程方式
Gradle (Kotlin)
Gradle (Groovy)
Gradle(第三方)
<configuration>
<generator>
<generate>
<!-- Allowing to turn off the feature for to-one join paths (including many-to-many).
The default is true. -->
<implicitJoinPathsToOne>true</implicitJoinPathsToOne>
<!-- Allowing to turn off the feature for to-many join paths (including many-to-many).
The default is true. -->
<implicitJoinPathsToMany>true</implicitJoinPathsToMany>
<!-- Allowing to turn off the feature for many-to-many join paths.
The default is true. -->
<implicitJoinPathsManyToMany>true</implicitJoinPathsManyToMany>
<!-- Whether implicit join path constructors should also be generated if there
isn't any outgoing or incoming foreign key relationship.
The default is false. -->
<implicitJoinPathUnusedConstructors>false</implicitJoinPathUnusedConstructors>
<!-- Influencing how the DefaultGeneratorStrategy generates identifiers.
The default is true.
When a child table has only one FK towards a parent table, then that path is "unambiguous."
In that case, the DefaultGeneratorStrategy uses the parent table name instead of the FK name. -->
<implicitJoinPathsUseTableNameForUnambiguousFKs>true</implicitJoinPathsUseTableNameForUnambiguousFKs>
<!-- Tell the KotlinGenerator to generate properties in addition to methods for these paths.
The default is true. -->
<implicitJoinPathsAsKotlinProperties>true</implicitJoinPathsAsKotlinProperties>
</generate>
</generator>
</configuration>
有关更多详细信息,请参阅配置 XSD、独立代码生成和maven 代码生成。
new org.jooq.meta.jaxb.Configuration()
.withGenerator(
new Generate()
// Allowing to turn off the feature for to-one join paths (including many-to-many).
// The default is true.
.withImplicitJoinPathsToOne(true)
// Allowing to turn off the feature for to-many join paths (including many-to-many).
// The default is true.
.withImplicitJoinPathsToMany(true)
// Allowing to turn off the feature for many-to-many join paths.
// The default is true.
.withImplicitJoinPathsManyToMany(true)
// Whether implicit join path constructors should also be generated if there
// isn't any outgoing or incoming foreign key relationship.
// The default is false.
.withImplicitJoinPathUnusedConstructors(false)
// Influencing how the DefaultGeneratorStrategy generates identifiers.
// The default is true.
//
// When a child table has only one FK towards a parent table, then that path is "unambiguous."
// In that case, the DefaultGeneratorStrategy uses the parent table name instead of the FK name.
.withImplicitJoinPathsUseTableNameForUnambiguousFKs(true)
// Tell the KotlinGenerator to generate properties in addition to methods for these paths.
// The default is true.
.withImplicitJoinPathsAsKotlinProperties(true)
)
import org.jooq.meta.jaxb.*
configuration {
generator {
generate {
// Allowing to turn off the feature for to-one join paths (including many-to-many).
// The default is true.
isImplicitJoinPathsToOne = true
// Allowing to turn off the feature for to-many join paths (including many-to-many).
// The default is true.
isImplicitJoinPathsToMany = true
// Allowing to turn off the feature for many-to-many join paths.
// The default is true.
isImplicitJoinPathsManyToMany = true
// Whether implicit join path constructors should also be generated if there
// isn't any outgoing or incoming foreign key relationship.
// The default is false.
isImplicitJoinPathUnusedConstructors = false
// Influencing how the DefaultGeneratorStrategy generates identifiers.
// The default is true.
//
// When a child table has only one FK towards a parent table, then that path is "unambiguous."
// In that case, the DefaultGeneratorStrategy uses the parent table name instead of the FK name.
isImplicitJoinPathsUseTableNameForUnambiguousFKs = true
// Tell the KotlinGenerator to generate properties in addition to methods for these paths.
// The default is true.
isImplicitJoinPathsAsKotlinProperties = true
}
}
}
有关更多详细信息,请参阅配置 XSD和gradle 代码生成。
configuration {
generator {
generate {
// Allowing to turn off the feature for to-one join paths (including many-to-many).
// The default is true.
implicitJoinPathsToOne = true
// Allowing to turn off the feature for to-many join paths (including many-to-many).
// The default is true.
implicitJoinPathsToMany = true
// Allowing to turn off the feature for many-to-many join paths.
// The default is true.
implicitJoinPathsManyToMany = true
// Whether implicit join path constructors should also be generated if there
// isn't any outgoing or incoming foreign key relationship.
// The default is false.
implicitJoinPathUnusedConstructors = false
// Influencing how the DefaultGeneratorStrategy generates identifiers.
// The default is true.
//
// When a child table has only one FK towards a parent table, then that path is "unambiguous."
// In that case, the DefaultGeneratorStrategy uses the parent table name instead of the FK name.
implicitJoinPathsUseTableNameForUnambiguousFKs = true
// Tell the KotlinGenerator to generate properties in addition to methods for these paths.
// The default is true.
implicitJoinPathsAsKotlinProperties = 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.
反馈
您对此页面有任何反馈吗?我们很乐意听到您的意见!