@@ -6,6 +6,38 @@ This log will detail notable changes to MyBatis Dynamic SQL. Full details are av
66
77GitHub 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
1143This 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
2355The 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-
2957In the Java DSL, a "having" clause can only be coded after a "group by" clause - which is a reasonable restriction
3058as "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
4068A 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
4393The pull request for this change is ([ #591 ] ( https://github.com/mybatis/mybatis-dynamic-sql/pull/591 ) )
4494
0 commit comments