@@ -26,6 +26,8 @@ import org.mybatis.dynamic.sql.where.AbstractWhereDSL
26
26
@DslMarker
27
27
annotation class MyBatisDslMarker
28
28
29
+ typealias WhereApplier = AbstractWhereDSL <* >.() -> Unit
30
+
29
31
@MyBatisDslMarker
30
32
@Suppress(" TooManyFunctions" )
31
33
abstract class KotlinBaseBuilder <W : AbstractWhereDSL <W >, B : KotlinBaseBuilder <W , B >> {
@@ -34,9 +36,9 @@ abstract class KotlinBaseBuilder<W : AbstractWhereDSL<W>, B : KotlinBaseBuilder<
34
36
getWhere().where(column, condition)
35
37
}
36
38
37
- fun <T > where (column : BindableColumn <T >, condition : VisitableCondition <T >, collect : CriteriaReceiver ): B =
39
+ fun <T > where (column : BindableColumn <T >, condition : VisitableCondition <T >, subCriteria : CriteriaReceiver ): B =
38
40
applySelf {
39
- getWhere().where(column, condition, collect )
41
+ getWhere().where(column, condition, subCriteria( CriteriaCollector ()).criteria )
40
42
}
41
43
42
44
fun applyWhere (whereApplier : WhereApplier ): B =
@@ -49,19 +51,19 @@ abstract class KotlinBaseBuilder<W : AbstractWhereDSL<W>, B : KotlinBaseBuilder<
49
51
getWhere().and (column, condition)
50
52
}
51
53
52
- fun <T > and (column : BindableColumn <T >, condition : VisitableCondition <T >, collect : CriteriaReceiver ): B =
54
+ fun <T > and (column : BindableColumn <T >, condition : VisitableCondition <T >, subCriteria : CriteriaReceiver ): B =
53
55
applySelf {
54
- getWhere().and (column, condition, collect )
56
+ getWhere().and (column, condition, subCriteria( CriteriaCollector ()).criteria )
55
57
}
56
58
57
59
fun <T > or (column : BindableColumn <T >, condition : VisitableCondition <T >): B =
58
60
applySelf {
59
61
getWhere().or (column, condition)
60
62
}
61
63
62
- fun <T > or (column : BindableColumn <T >, condition : VisitableCondition <T >, collect : CriteriaReceiver ): B =
64
+ fun <T > or (column : BindableColumn <T >, condition : VisitableCondition <T >, subCriteria : CriteriaReceiver ): B =
63
65
applySelf {
64
- getWhere().or (column, condition, collect )
66
+ getWhere().or (column, condition, subCriteria( CriteriaCollector ()).criteria )
65
67
}
66
68
67
69
fun allRows () = self()
@@ -77,44 +79,49 @@ abstract class KotlinBaseBuilder<W : AbstractWhereDSL<W>, B : KotlinBaseBuilder<
77
79
abstract class KotlinBaseJoiningBuilder <T : AbstractQueryExpressionDSL <T , SelectModel >, W : AbstractWhereDSL <W >,
78
80
B : KotlinBaseJoiningBuilder <T , W , B >> : KotlinBaseBuilder <W , B >() {
79
81
80
- fun join (table : SqlTable , receiver : JoinReceiver ): B =
81
- applySelf {
82
- getDsl().join(table, receiver )
82
+ fun join (table : SqlTable , joinCriteria : JoinReceiver ) =
83
+ applyJoin(joinCriteria) {
84
+ getDsl().join(table, it.onJoinCriterion, it.andJoinCriteria )
83
85
}
84
86
85
- fun join (table : SqlTable , alias : String , receiver : JoinReceiver ): B =
86
- applySelf {
87
- getDsl().join(table, alias, receiver )
87
+ fun join (table : SqlTable , alias : String , joinCriteria : JoinReceiver ) =
88
+ applyJoin(joinCriteria) {
89
+ getDsl().join(table, alias, it.onJoinCriterion, it.andJoinCriteria )
88
90
}
89
91
90
- fun fullJoin (table : SqlTable , receiver : JoinReceiver ): B =
91
- applySelf {
92
- getDsl().fullJoin(table, receiver )
92
+ fun fullJoin (table : SqlTable , joinCriteria : JoinReceiver ) =
93
+ applyJoin(joinCriteria) {
94
+ getDsl().fullJoin(table, it.onJoinCriterion, it.andJoinCriteria )
93
95
}
94
96
95
- fun fullJoin (table : SqlTable , alias : String , receiver : JoinReceiver ): B =
96
- applySelf {
97
- getDsl().fullJoin(table, alias, receiver )
97
+ fun fullJoin (table : SqlTable , alias : String , joinCriteria : JoinReceiver ) =
98
+ applyJoin(joinCriteria) {
99
+ getDsl().fullJoin(table, alias, it.onJoinCriterion, it.andJoinCriteria )
98
100
}
99
101
100
- fun leftJoin (table : SqlTable , receiver : JoinReceiver ): B =
101
- applySelf {
102
- getDsl().leftJoin(table, receiver )
102
+ fun leftJoin (table : SqlTable , joinCriteria : JoinReceiver ) =
103
+ applyJoin(joinCriteria) {
104
+ getDsl().leftJoin(table, it.onJoinCriterion, it.andJoinCriteria )
103
105
}
104
106
105
- fun leftJoin (table : SqlTable , alias : String , receiver : JoinReceiver ): B =
106
- applySelf {
107
- getDsl().leftJoin(table, alias, receiver )
107
+ fun leftJoin (table : SqlTable , alias : String , joinCriteria : JoinReceiver ) =
108
+ applyJoin(joinCriteria) {
109
+ getDsl().leftJoin(table, alias, it.onJoinCriterion, it.andJoinCriteria )
108
110
}
109
111
110
- fun rightJoin (table : SqlTable , receiver : JoinReceiver ): B =
111
- applySelf {
112
- getDsl().rightJoin(table, receiver)
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)
113
120
}
114
121
115
- fun rightJoin ( table : SqlTable , alias : String , receiver : JoinReceiver ): B =
122
+ private fun applyJoin ( joinCriteria : JoinReceiver , block : ( JoinCollector ) -> Unit ) =
116
123
applySelf {
117
- getDsl().rightJoin(table, alias, receiver )
124
+ joinCriteria( JoinCollector ()). also (block )
118
125
}
119
126
120
127
protected abstract fun getDsl (): AbstractQueryExpressionDSL <T , SelectModel >
0 commit comments