Skip to content

Commit 3a354f9

Browse files
authored
Merge pull request #595 from jeffgbutler/deprecationsv2
[Kotlin] Deprecate the general and/or methods
2 parents 696136c + ca494a2 commit 3a354f9

File tree

9 files changed

+382
-260
lines changed

9 files changed

+382
-260
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ want this to look more like true SQL, you can write code like this:
3636
private final WhereApplier commonWhere = where(id, isEqualTo(1)).or(occupation, isNull()).toWhereApplier();
3737
```
3838

39-
This uses a `where` method from `SqlBuilder`.
39+
This uses a `where` method from the `SqlBuilder` class.
4040

4141
### "Having" Clause Support
4242

@@ -59,7 +59,8 @@ as "having" is only needed if there is a "group by".
5959

6060
In the Kotlin DSL, the "group by" restriction is not present because of the free form nature of that DSL - but you
6161
should probably only use "having" if there is a "group by". Also note that the freestanding "and" and "or"
62-
functions in the Kotlin DSL still only apply to the where clause.
62+
functions in the Kotlin DSL still only apply to the where clause. For this reason, the freestanding "and" and "or"
63+
methods are deprecated. Please only use the "and" and "or" methods inside a "where" or "having" lambda.
6364

6465
The pull request for this change is ([#550](https://github.com/mybatis/mybatis-dynamic-sql/pull/550))
6566

@@ -110,6 +111,7 @@ The pull request for this change is ([#591](https://github.com/mybatis/mybatis-d
110111
([#572](https://github.com/mybatis/mybatis-dynamic-sql/pull/572))
111112
5. Add `SqlBuilder.concat` and the equivalent in Kotlin. This is a concatenate function that works on more databases.
112113
([#573](https://github.com/mybatis/mybatis-dynamic-sql/pull/573))
114+
6. Several classes and methods in the Kotlin DSL are deprecated in response to the new "having" support
113115

114116
## Release 1.4.1 - October 7, 2022
115117

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,24 @@ abstract class KotlinBaseBuilder<D : AbstractWhereStarter<*,*>> {
5151
getDsl().where(criteria)
5252
}
5353

54+
@Deprecated("Please move the \"and\" function into the where lambda. If the where lambda has more than one condition, you may need to surround the existing conditions with \"group\" first.")
5455
fun and(criteria: GroupingCriteriaReceiver): Unit =
5556
GroupingCriteriaCollector().apply(criteria).let {
5657
getDsl().where().and(it.initialCriterion, it.subCriteria)
5758
}
5859

60+
@Deprecated("Please move the \"and\" function into the where lambda. If the where lambda has more than one condition, you may need to surround the existing conditions with \"group\" first.")
5961
fun and(criteria: List<AndOrCriteriaGroup>) {
6062
getDsl().where().and(criteria)
6163
}
6264

65+
@Deprecated("Please move the \"or\" function into the where lambda. If the where lambda has more than one condition, you may need to surround the existing conditions with \"group\" first.")
6366
fun or(criteria: GroupingCriteriaReceiver): Unit =
6467
GroupingCriteriaCollector().apply(criteria).let {
6568
getDsl().where().or(it.initialCriterion, it.subCriteria)
6669
}
6770

71+
@Deprecated("Please move the \"or\" function into the where lambda. If the where lambda has more than one condition, you may need to surround the existing conditions with \"group\" first.")
6872
fun or(criteria: List<AndOrCriteriaGroup>) {
6973
getDsl().where().or(criteria)
7074
}

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

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ class PersonMapperTest {
6363
val mapper = session.getMapper(PersonMapper::class.java)
6464

6565
val rows = mapper.select {
66-
where { id isEqualTo 1 }
67-
or { occupation.isNull() }
66+
where {
67+
id isEqualTo 1
68+
or { occupation.isNull() }
69+
}
6870
}
6971

7072
assertThat(rows).hasSize(3)
@@ -106,8 +108,10 @@ class PersonMapperTest {
106108
val mapper = session.getMapper(PersonMapper::class.java)
107109

108110
val rows = mapper.selectDistinct {
109-
where { id isGreaterThan 1 }
110-
or { occupation.isNull() }
111+
where {
112+
id isGreaterThan 1
113+
or { occupation.isNull() }
114+
}
111115
}
112116

113117
assertThat(rows).hasSize(5)
@@ -375,8 +379,10 @@ class PersonMapperTest {
375379

376380
rows = mapper.update {
377381
set(occupation) equalTo "Programmer"
378-
where { id isEqualTo 100 }
379-
and { firstName isEqualTo "Joe" }
382+
where {
383+
id isEqualTo 100
384+
and { firstName isEqualTo "Joe" }
385+
}
380386
}
381387

382388
assertThat(rows).isEqualTo(1)
@@ -494,8 +500,10 @@ class PersonMapperTest {
494500
val mapper = session.getMapper(PersonMapper::class.java)
495501

496502
val rows = mapper.count {
497-
where { employed.isTrue() }
498-
and { occupation isEqualTo "Brontosaurus Operator" }
503+
where {
504+
employed.isTrue()
505+
and { occupation isEqualTo "Brontosaurus Operator" }
506+
}
499507
}
500508

501509
assertThat(rows).isEqualTo(2L)
@@ -524,10 +532,12 @@ class PersonMapperTest {
524532
val mapper = session.getMapper(PersonMapper::class.java)
525533

526534
val rows = mapper.count {
527-
where { id isEqualTo 1 }
528-
or {
529-
id isEqualTo 2
530-
or { id isEqualTo 3 }
535+
where {
536+
id isEqualTo 1
537+
or {
538+
id isEqualTo 2
539+
or { id isEqualTo 3 }
540+
}
531541
}
532542
}
533543

@@ -541,10 +551,12 @@ class PersonMapperTest {
541551
val mapper = session.getMapper(PersonMapper::class.java)
542552

543553
val rows = mapper.count {
544-
where { id isLessThan 5 }
545-
and {
546-
id isLessThan 3
547-
and { id isEqualTo 1 }
554+
where {
555+
id isLessThan 5
556+
and {
557+
id isLessThan 3
558+
and { id isEqualTo 1 }
559+
}
548560
}
549561
}
550562

0 commit comments

Comments
 (0)