Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In the convenience methods for join, make column equality optional #1692

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 45 additions & 20 deletions exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Table.kt
Original file line number Diff line number Diff line change
Expand Up @@ -137,45 +137,70 @@ abstract class ColumnSet : FieldSet {
fun select(columns: List<Expression<*>>): Query = Query(Select(this, columns), null)
}

/** Creates an inner join relation with [otherTable] using [onColumn] and [otherColumn] as the join condition. */
/**
* Creates an inner join relation with [otherTable] using [onColumn] and [otherColumn] equality
* and/or [additionalConstraint] as the join condition.
*
* @throws IllegalStateException if the join cannot be performed. See the exception message for more details.
*/
fun <C1 : ColumnSet, C2 : ColumnSet> C1.innerJoin(
otherTable: C2,
onColumn: C1.() -> Expression<*>,
otherColumn: C2.() -> Expression<*>,
onColumn: (C1.() -> Expression<*>)? = null,
otherColumn: (C2.() -> Expression<*>)? = null,
additionalConstraint: (SqlExpressionBuilder.() -> Op<Boolean>)? = null,
): Join = join(otherTable, JoinType.INNER, onColumn(this), otherColumn(otherTable), additionalConstraint)
): Join = join(otherTable, JoinType.INNER, onColumn?.invoke(this), otherColumn?.invoke(otherTable), additionalConstraint)

/** Creates a left outer join relation with [otherTable] using [onColumn] and [otherColumn] as the join condition. */
/**
* Creates a left outer join relation with [otherTable] using [onColumn] and [otherColumn] equality
* and/or [additionalConstraint] as the join condition.
*
* @throws IllegalStateException if the join cannot be performed. See the exception message for more details.
*/
fun <C1 : ColumnSet, C2 : ColumnSet> C1.leftJoin(
otherTable: C2,
onColumn: C1.() -> Expression<*>,
otherColumn: C2.() -> Expression<*>,
onColumn: (C1.() -> Expression<*>)? = null,
otherColumn: (C2.() -> Expression<*>)? = null,
additionalConstraint: (SqlExpressionBuilder.() -> Op<Boolean>)? = null,
): Join = join(otherTable, JoinType.LEFT, onColumn(), otherTable.otherColumn(), additionalConstraint)
): Join = join(otherTable, JoinType.LEFT, onColumn?.invoke(this), otherColumn?.invoke(otherTable), additionalConstraint)

/** Creates a right outer join relation with [otherTable] using [onColumn] and [otherColumn] as the join condition. */
/**
* Creates a right outer join relation with [otherTable] using [onColumn] and [otherColumn] equality
* and/or [additionalConstraint] as the join condition.
*
* @throws IllegalStateException if the join cannot be performed. See the exception message for more details.
*/
fun <C1 : ColumnSet, C2 : ColumnSet> C1.rightJoin(
otherTable: C2,
onColumn: C1.() -> Expression<*>,
otherColumn: C2.() -> Expression<*>,
onColumn: (C1.() -> Expression<*>)? = null,
otherColumn: (C2.() -> Expression<*>)? = null,
additionalConstraint: (SqlExpressionBuilder.() -> Op<Boolean>)? = null,
): Join = join(otherTable, JoinType.RIGHT, onColumn(), otherTable.otherColumn(), additionalConstraint)
): Join = join(otherTable, JoinType.RIGHT, onColumn?.invoke(this), otherColumn?.invoke(otherTable), additionalConstraint)

/** Creates a full outer join relation with [otherTable] using [onColumn] and [otherColumn] as the join condition. */
/**
* Creates a full outer join relation with [otherTable] using [onColumn] and [otherColumn] equality
* and/or [additionalConstraint] as the join condition.
*
* @throws IllegalStateException if the join cannot be performed. See the exception message for more details.
*/
fun <C1 : ColumnSet, C2 : ColumnSet> C1.fullJoin(
otherTable: C2,
onColumn: C1.() -> Expression<*>,
otherColumn: C2.() -> Expression<*>,
onColumn: (C1.() -> Expression<*>)? = null,
otherColumn: (C2.() -> Expression<*>)? = null,
additionalConstraint: (SqlExpressionBuilder.() -> Op<Boolean>)? = null,
): Join = join(otherTable, JoinType.FULL, onColumn(), otherTable.otherColumn(), additionalConstraint)
): Join = join(otherTable, JoinType.FULL, onColumn?.invoke(this), otherColumn?.invoke(otherTable), additionalConstraint)

/** Creates a cross join relation with [otherTable] using [onColumn] and [otherColumn] as the join condition. */
/**
* Creates a cross join relation with [otherTable] using [onColumn] and [otherColumn] equality
* and/or [additionalConstraint] as the join condition.
*
* @throws IllegalStateException if the join cannot be performed. See the exception message for more details.
*/
fun <C1 : ColumnSet, C2 : ColumnSet> C1.crossJoin(
otherTable: C2,
onColumn: C1.() -> Expression<*>,
otherColumn: C2.() -> Expression<*>,
onColumn: (C1.() -> Expression<*>)? = null,
otherColumn: (C2.() -> Expression<*>)? = null,
additionalConstraint: (SqlExpressionBuilder.() -> Op<Boolean>)? = null,
): Join = join(otherTable, JoinType.CROSS, onColumn(), otherTable.otherColumn(), additionalConstraint)
): Join = join(otherTable, JoinType.CROSS, onColumn?.invoke(this), otherColumn?.invoke(otherTable), additionalConstraint)

/**
* Represents a subset of [fields] from a given [source].
Expand Down
Loading