Skip to content

Commit 31f5dbe

Browse files
committed
Better function name
1 parent 7836e10 commit 31f5dbe

File tree

4 files changed

+14
-32
lines changed

4 files changed

+14
-32
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ import org.mybatis.dynamic.sql.where.AbstractWhereSupport
2525
@DslMarker
2626
annotation class MyBatisDslMarker
2727

28-
@Deprecated("Please use independentWhere")
28+
@Deprecated("Please use booleanExpression")
2929
typealias WhereApplier = KotlinBaseBuilder<*>.() -> Unit
3030

31-
@Deprecated("Please use independentWhere")
31+
@Deprecated("Please use booleanExpression")
3232
fun WhereApplier.andThen(after: WhereApplier): WhereApplier = {
3333
invoke(this)
3434
after(this)
@@ -69,7 +69,7 @@ abstract class KotlinBaseBuilder<D : AbstractWhereSupport<*,*>> {
6969
getDsl().where().or(criteria)
7070
}
7171

72-
@Deprecated("Please create an independent where clause, then pass it to the \"where\" method")
72+
@Deprecated("Please create a booleanExpression, then pass it to the \"where\" method")
7373
fun applyWhere(whereApplier: WhereApplier) = whereApplier.invoke(this)
7474

7575
/**

src/main/kotlin/org/mybatis/dynamic/sql/util/kotlin/elements/SqlElements.kt

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ import org.mybatis.dynamic.sql.where.condition.IsNotNull
7878
import org.mybatis.dynamic.sql.where.condition.IsNull
7979

8080
/**
81-
* Simple function for code beautification. This allows creation of an independent where clause
81+
* Function for code simplification. This allows creation of an independent where or having clause
8282
* that can be reused in different statements. For example:
8383
*
84-
* val whereClause = where { id isEqualTo 3 }
84+
* val whereClause = booleanExpression { id isEqualTo 3 }
8585
*
8686
* val rows = countFrom(foo) {
8787
* where(whereClause)
@@ -92,25 +92,7 @@ import org.mybatis.dynamic.sql.where.condition.IsNull
9292
* val whereClause: GroupingCriteriaReceiver = { id isEqualTo 3 }
9393
*
9494
*/
95-
fun where(receiver: GroupingCriteriaReceiver): GroupingCriteriaReceiver = receiver
96-
97-
/**
98-
* Simple function for code beautification. This allows creation of an independent having clause
99-
* that can be reused in different statements. For example:
100-
*
101-
* val havingClause = where { count() isGreaterThanTo 1 }
102-
*
103-
* val rows = select(id, count()) {
104-
* from(foo)
105-
* groupBy(id)
106-
* having(havingClause)
107-
* }
108-
*
109-
* Use of this function is optional. You can also write code like this:
110-
*
111-
* val havingClause: GroupingCriteriaReceiver = { count() isGreaterThanTo 1 }
112-
*/
113-
fun having(receiver: GroupingCriteriaReceiver): GroupingCriteriaReceiver = receiver
95+
fun booleanExpression(receiver: GroupingCriteriaReceiver): GroupingCriteriaReceiver = receiver
11496

11597
// support for criteria without initial conditions
11698
fun and(receiver: GroupingCriteriaReceiver): AndOrCriteriaGroup =

src/test/kotlin/examples/kotlin/mybatis3/canonical/ReusableWhereTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import org.junit.jupiter.api.Test
2828
import org.junit.jupiter.api.TestInstance
2929
import org.mybatis.dynamic.sql.util.kotlin.WhereApplier
3030
import org.mybatis.dynamic.sql.util.kotlin.andThen
31-
import org.mybatis.dynamic.sql.util.kotlin.elements.where
31+
import org.mybatis.dynamic.sql.util.kotlin.elements.booleanExpression
3232
import org.mybatis.dynamic.sql.util.kotlin.mybatis3.select
3333

3434
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@@ -45,7 +45,7 @@ class ReusableWhereTest {
4545
}
4646

4747
@Test
48-
fun testCount() {
48+
fun testCountWithDeprecatedClause() {
4949
sqlSessionFactory.openSession().use { session ->
5050
val mapper = session.getMapper(PersonMapper::class.java)
5151

@@ -63,7 +63,7 @@ class ReusableWhereTest {
6363
val mapper = session.getMapper(PersonMapper::class.java)
6464

6565
val rows = mapper.delete {
66-
applyWhere(commonWhere)
66+
where(commonWhereClause)
6767
}
6868

6969
assertThat(rows).isEqualTo(3)
@@ -76,7 +76,7 @@ class ReusableWhereTest {
7676
val mapper = session.getMapper(PersonMapper::class.java)
7777

7878
val rows = mapper.select {
79-
applyWhere(commonWhere)
79+
where(commonWhereClause)
8080
orderBy(id)
8181
}
8282

@@ -91,7 +91,7 @@ class ReusableWhereTest {
9191

9292
val rows = mapper.update {
9393
set(occupation) equalToStringConstant "worker"
94-
applyWhere(commonWhere)
94+
where(commonWhereClause)
9595
}
9696

9797
assertThat(rows).isEqualTo(3)
@@ -145,7 +145,7 @@ class ReusableWhereTest {
145145
or { occupation.isNull() }
146146
}
147147

148-
private val commonWhereClause = where {
148+
private val commonWhereClause = booleanExpression {
149149
id isEqualTo 1
150150
or { occupation.isNull() }
151151
}

src/test/kotlin/examples/kotlin/mybatis3/general/KGroupingTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import org.junit.jupiter.api.Test
2525
import org.mybatis.dynamic.sql.SqlTable
2626
import org.mybatis.dynamic.sql.exception.InvalidSqlException
2727
import org.mybatis.dynamic.sql.util.kotlin.elements.add
28+
import org.mybatis.dynamic.sql.util.kotlin.elements.booleanExpression
2829
import org.mybatis.dynamic.sql.util.kotlin.elements.column
2930
import org.mybatis.dynamic.sql.util.kotlin.elements.count
30-
import org.mybatis.dynamic.sql.util.kotlin.elements.having
3131
import org.mybatis.dynamic.sql.util.kotlin.elements.isBetween
3232
import org.mybatis.dynamic.sql.util.kotlin.elements.isLessThanOrEqualTo
3333
import org.mybatis.dynamic.sql.util.kotlin.mybatis3.select
@@ -363,7 +363,7 @@ class KGroupingTest {
363363

364364
@Test
365365
fun testIndependentHaving() {
366-
val havingClause = having { count() isGreaterThan 6 }
366+
val havingClause = booleanExpression { count() isGreaterThan 6 }
367367

368368
val selectStatement = select(A, count()) {
369369
from(foo)

0 commit comments

Comments
 (0)