Skip to content

Commit 6ce3380

Browse files
committed
Doc updates
1 parent b71f8b8 commit 6ce3380

File tree

2 files changed

+58
-8
lines changed

2 files changed

+58
-8
lines changed

CHANGELOG.md

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,38 @@ This log will detail notable changes to MyBatis Dynamic SQL. Full details are av
66

77
GitHub milestone: [https://github.com/mybatis/mybatis-dynamic-sql/milestone/12?closed=1](https://github.com/mybatis/mybatis-dynamic-sql/milestone/12?closed=1)
88

9+
### Potentially Breaking Changes
10+
11+
This release includes a major refactoring of the "where" clause support. This is done to support common code for
12+
"having" clauses which is a new feature (see below). Most changes are source code compatible with previous
13+
releases and should be transparent with no impact. Following is a list of some more visible changes...
14+
15+
First, the "where" methods in `SqlBuilder` now return an instance of `WhereDSL.StandaloneWhereFinisher` rather than
16+
`WhereDSL`. This will only impact you if you are using the WhereDSL directly which is a rare use case.
17+
18+
Second, if you are using independent or reusable where clauses you will need to make changes. Previously you might have
19+
coded an independent where clause like this:
20+
21+
```java
22+
private WhereApplier commonWhere = d -> d.where(id, isEqualTo(1)).or(occupation, isNull());
23+
```
24+
25+
Code like this will no longer compile. There are two options for updates. The simplest change to make is to
26+
replace "where" with "and" or "or" in the above code. For example...
27+
28+
```java
29+
private WhereApplier commonWhere = d -> d.and(id, isEqualTo(1)).or(occupation, isNull());
30+
```
31+
32+
This will function as before, but you may think it looks a bit strange because the phrase starts with "and". If you
33+
want this to look more like true SQL, you can write code like this:
34+
35+
```java
36+
private final WhereApplier commonWhere = where(id, isEqualTo(1)).or(occupation, isNull()).toWhereApplier();
37+
```
38+
39+
This uses a `where` method from `SqlBuilder`.
40+
941
### "Having" Clause Support
1042

1143
This release adds support for "having" clauses in select statements. This includes a refactoring of the "where"
@@ -22,10 +54,6 @@ where (a < 2 and b > 3)
2254

2355
The renderer will now remove the open/close parentheses in a case like this.
2456

25-
The "having" support is not as full-featured as the "where" support in that we don't support independent and
26-
reusable having clauses, and we don't support composable having functions. If you have a reasonable use case
27-
for that kind of support, please let us know.
28-
2957
In the Java DSL, a "having" clause can only be coded after a "group by" clause - which is a reasonable restriction
3058
as "having" is only needed if there is a "group by".
3159

@@ -38,7 +66,29 @@ The pull request for this change is ([#550](https://github.com/mybatis/mybatis-d
3866
### Multi-Select Queries
3967

4068
A multi-select query is a special case of a union select statement. The difference is that it allows "order by" and
41-
paging clauses to be applied to the nested queries.
69+
paging clauses to be applied to the nested queries. A multi-select query looks like this:
70+
71+
```java
72+
SelectStatementProvider selectStatement = multiSelect(
73+
select(id.as("A_ID"), firstName, lastName, birthDate, employed, occupation, addressId)
74+
.from(person)
75+
.where(id, isLessThanOrEqualTo(2))
76+
.orderBy(id)
77+
.limit(1)
78+
).unionAll(
79+
select(id.as("A_ID"), firstName, lastName, birthDate, employed, occupation, addressId)
80+
.from(person)
81+
.where(id, isGreaterThanOrEqualTo(4))
82+
.orderBy(id.descending())
83+
.limit(1)
84+
).orderBy(sortColumn("A_ID"))
85+
.fetchFirst(2).rowsOnly()
86+
.build()
87+
.render(RenderingStrategies.MYBATIS3);
88+
```
89+
90+
Notice how both inner queries have `order by` and `limit` phrases, then there is an `order by` phrase
91+
for the entire query.
4292

4393
The pull request for this change is ([#591](https://github.com/mybatis/mybatis-dynamic-sql/pull/591))
4494

src/test/java/examples/simple/PersonMapperTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -953,9 +953,9 @@ void testMultiSelectPagingVariation() {
953953
.from(person)
954954
.where(id, isLessThanOrEqualTo(2))
955955
).unionAll(
956-
select(id, firstName, lastName, birthDate, employed, occupation, addressId)
957-
.from(person)
958-
.where(id, isGreaterThanOrEqualTo(4))
956+
select(id, firstName, lastName, birthDate, employed, occupation, addressId)
957+
.from(person)
958+
.where(id, isGreaterThanOrEqualTo(4))
959959
)
960960
.orderBy(id)
961961
.build()

0 commit comments

Comments
 (0)