Skip to content

Commit 899a9cd

Browse files
committed
Join builder polishing
1 parent 66731ee commit 899a9cd

File tree

1 file changed

+28
-39
lines changed

1 file changed

+28
-39
lines changed

src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/KotlinBaseBuilders.kt

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -79,60 +79,49 @@ abstract class KotlinBaseBuilder<W : AbstractWhereDSL<W>, B : KotlinBaseBuilder<
7979
abstract class KotlinBaseJoiningBuilder<T : AbstractQueryExpressionDSL<T, SelectModel>, W : AbstractWhereDSL<W>,
8080
B : KotlinBaseJoiningBuilder<T, W, B>> : KotlinBaseBuilder<W, B>() {
8181

82-
fun join(table: SqlTable, joinCriteria: JoinReceiver): B =
83-
applySelf {
84-
with(joinCriteria(JoinCollector())) {
85-
this@KotlinBaseJoiningBuilder.getDsl().join(table, onJoinCriterion, andJoinCriteria)
86-
}
82+
fun join(table: SqlTable, joinCriteria: JoinReceiver) =
83+
applyJoin(joinCriteria) {
84+
getDsl().join(table, it.onJoinCriterion, it.andJoinCriteria)
8785
}
8886

89-
fun join(table: SqlTable, alias: String, joinCriteria: JoinReceiver): B =
90-
applySelf {
91-
with(joinCriteria(JoinCollector())) {
92-
this@KotlinBaseJoiningBuilder.getDsl().join(table, alias, onJoinCriterion, andJoinCriteria)
93-
}
87+
fun join(table: SqlTable, alias: String, joinCriteria: JoinReceiver) =
88+
applyJoin(joinCriteria) {
89+
getDsl().join(table, alias, it.onJoinCriterion, it.andJoinCriteria)
9490
}
9591

96-
fun fullJoin(table: SqlTable, joinCriteria: JoinReceiver): B =
97-
applySelf {
98-
with(joinCriteria(JoinCollector())) {
99-
this@KotlinBaseJoiningBuilder.getDsl().fullJoin(table, onJoinCriterion, andJoinCriteria)
100-
}
92+
fun fullJoin(table: SqlTable, joinCriteria: JoinReceiver) =
93+
applyJoin(joinCriteria) {
94+
getDsl().fullJoin(table, it.onJoinCriterion, it.andJoinCriteria)
10195
}
10296

103-
fun fullJoin(table: SqlTable, alias: String, joinCriteria: JoinReceiver): B =
104-
applySelf {
105-
with(joinCriteria(JoinCollector())) {
106-
this@KotlinBaseJoiningBuilder.getDsl().fullJoin(table, alias, onJoinCriterion, andJoinCriteria)
107-
}
97+
fun fullJoin(table: SqlTable, alias: String, joinCriteria: JoinReceiver) =
98+
applyJoin(joinCriteria) {
99+
getDsl().fullJoin(table, alias, it.onJoinCriterion, it.andJoinCriteria)
108100
}
109101

110-
fun leftJoin(table: SqlTable, joinCriteria: JoinReceiver): B =
111-
applySelf {
112-
with(joinCriteria(JoinCollector())) {
113-
this@KotlinBaseJoiningBuilder.getDsl().leftJoin(table, onJoinCriterion, andJoinCriteria)
114-
}
102+
fun leftJoin(table: SqlTable, joinCriteria: JoinReceiver) =
103+
applyJoin(joinCriteria) {
104+
getDsl().leftJoin(table, it.onJoinCriterion, it.andJoinCriteria)
115105
}
116106

117-
fun leftJoin(table: SqlTable, alias: String, joinCriteria: JoinReceiver): B =
118-
applySelf {
119-
with(joinCriteria(JoinCollector())) {
120-
this@KotlinBaseJoiningBuilder.getDsl().leftJoin(table, alias, onJoinCriterion, andJoinCriteria)
121-
}
107+
fun leftJoin(table: SqlTable, alias: String, joinCriteria: JoinReceiver) =
108+
applyJoin(joinCriteria) {
109+
getDsl().leftJoin(table, alias, it.onJoinCriterion, it.andJoinCriteria)
122110
}
123111

124-
fun rightJoin(table: SqlTable, joinCriteria: JoinReceiver): B =
125-
applySelf {
126-
with(joinCriteria(JoinCollector())) {
127-
this@KotlinBaseJoiningBuilder.getDsl().rightJoin(table, onJoinCriterion, andJoinCriteria)
128-
}
112+
fun rightJoin(table: SqlTable, joinCriteria: JoinReceiver) =
113+
applyJoin(joinCriteria) {
114+
getDsl().rightJoin(table, it.onJoinCriterion, it.andJoinCriteria)
115+
}
116+
117+
fun rightJoin(table: SqlTable, alias: String, joinCriteria: JoinReceiver) =
118+
applyJoin(joinCriteria) {
119+
getDsl().rightJoin(table, alias, it.onJoinCriterion, it.andJoinCriteria)
129120
}
130121

131-
fun rightJoin(table: SqlTable, alias: String, joinCriteria: JoinReceiver): B =
122+
private fun applyJoin(joinCriteria: JoinReceiver, block: (JoinCollector) -> Unit) =
132123
applySelf {
133-
with(joinCriteria(JoinCollector())) {
134-
this@KotlinBaseJoiningBuilder.getDsl().rightJoin(table, alias, onJoinCriterion, andJoinCriteria)
135-
}
124+
joinCriteria(JoinCollector()).also(block)
136125
}
137126

138127
protected abstract fun getDsl(): AbstractQueryExpressionDSL<T, SelectModel>

0 commit comments

Comments
 (0)