KJoinDefinition
Definition
A KJoinDefinition
object contain all necessary information to join two tables in a query.
This object can only be built through the on
method available on KTable
objects and KCommonTableExpressionFilled
objects:
Available on
methods
1. on(
KCondition
kCondition)
This method allows the KTable
or the CTE to be added to a JOIN
clause.
- kCondition: which contains all the information about the condition that will be supplied to the
JOIN
clause.
2. on(
KRaw
kRaw)
This method allows the KTable
or the CTE to be added to JOIN
clause.
- kRaw: is a raw content which will be supplied in the
JOIN
clause.
Those KTable
that are automatically generated bring with them additional predefined methods that return a KJoinDefinition
according to the relationships between tables that are detected in the database diagram.
The syntax of these additional methods is:
join + TableNameUpperCamelCase
The KTable
that calls the on
method will be the one that will be introduced in the join.
Example: KCondition
Java code:
k
.select(
APP_USER.FIRST_NAME,
ROLE.TENANT_ID
)
.from(APP_USER)
.innerJoin(ROLE.on(APP_USER.ROLE_ID.eq(ROLE.ID)))
.multiple();
SQL generated:
SELECT au.first_name, ro.tenant_id
FROM app_user au
INNER JOIN role ro ON (au.role_id = ro.id)
Parameters:
- None
Example: KRaw
Java code:
k
.select(
APP_USER.FIRST_NAME,
ROLE.TENANT_ID
)
.from(APP_USER)
.innerJoin(ROLE.on(raw("au.role_id = ro.id")))
.multiple();
SQL generated:
SELECT au.first_name, ro.tenant_id
FROM app_user au
INNER JOIN role ro ON (au.role_id = ro.id)
Parameters:
- None
Example: Predefined method
Java code:
k
.select(
APP_USER.FIRST_NAME,
ROLE.TENANT_ID
)
.from(APP_USER)
.innerJoin(APP_USER.joinRole())
.multiple();
SQL generated:
SELECT au.first_name, ro.tenant_id
FROM app_user au
INNER JOIN role ro ON (au.role_id = ro.id)
Parameters:
- None