Skip to content

Commit 4eeb56f

Browse files
authored
Merge pull request #358 from jeffgbutler/final-doc-updates
Doc Updates for Release
2 parents bb0d1e4 + a06d306 commit 4eeb56f

File tree

8 files changed

+203
-79
lines changed

8 files changed

+203
-79
lines changed

CHANGELOG.md

+34-10
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This log will detail notable changes to MyBatis Dynamic SQL. Full details are available on the GitHub milestone pages.
44

5-
## Release 1.3.0 - Unreleased
5+
## Release 1.3.0 - May 6, 2021
66

77
GitHub milestone: [https://github.com/mybatis/mybatis-dynamic-sql/issues?q=milestone%3A1.3.0+](https://github.com/mybatis/mybatis-dynamic-sql/issues?q=milestone%3A1.3.0+)
88

@@ -13,13 +13,14 @@ The major themes of this release include the following:
1313
1. Add support for subqueries in select statements - both in a from clause and a join clause.
1414
1. Add support for the "exists" and "not exists" operator. This will work in "where" clauses anywhere
1515
they are supported.
16-
1. Refactor and improve the built-in conditions for consistency (see below)
17-
1. Continue to refine the Kotlin DSL. Most changes to the Kotlin DSL are internal and should be source code
16+
1. Refactor and improve the built-in conditions for consistency (see below). There is one breaking change also
17+
detailed below.
18+
1. Continue to refine the Kotlin DSL. Many changes to the Kotlin DSL are internal and should be source code
1819
compatible with existing code. There is one breaking change detailed below.
1920
1. Remove deprecated code from prior releases.
2021

21-
### Built-In Condition Refactoring
22-
All built-in conditions have been refactored. The changes should have no impact for the vast majority of users.
22+
### Built-In Condition Refactoring and Breaking Change
23+
All built-in conditions have been refactored. The changes should have little impact for the vast majority of users.
2324
However, there are some changes in behavior and one breaking change.
2425

2526
1. Internally, the conditions no longer hold value Suppliers, they now hold the values themselves. The SqlBuilder
@@ -31,13 +32,14 @@ However, there are some changes in behavior and one breaking change.
3132
for a similar purpose.
3233
1. The new "filter" method works a bit differently than the "when" method it replaces. The old "when" method could not
3334
be chained - if it was called multiple times, only the last call would take effect. The new "filter" methods works
34-
as it should and every call will take effect.
35+
as it should and every call will take effect. This allows you to construct map/filter pipelines as you would
36+
expect.
3537
1. The new "map" method will allow you to change the datatype of a condition as is normal for a "map" method. You
3638
can use this method to apply a type conversion directly within condition.
3739
1. All the "WhenPresent" conditions have been removed as separate classes. The methods that produced these conditions
3840
in the SqlBuilder remain, and they will now produce a condition with a "NotNull" filter applied. So at the API level
3941
things will function exactly as before, but the intermediate classes will be different.
40-
1. One breaking change is that the builder for List value conditions has been removed without replacement. If you
42+
1. One **breaking change** is that the builder for List value conditions has been removed without replacement. If you
4143
were using this builder to supply a "value stream transformer", then the replacement is to build a new List value
4244
condition and then call the "map" and "filter" methods as needed. For example, prior code looked like this
4345

@@ -62,9 +64,31 @@ However, there are some changes in behavior and one breaking change.
6264
```
6365
We think this is a marked improvement!
6466

65-
### Breaking Change for Kotlin
67+
### Kotlin DSL Update and Breaking Change for Kotlin
6668

67-
In this release the Kotlin support for `select` and `count` statements has been refactored. This will not impact code
69+
The Kotlin DSL continues to evolve. With this release we have fully built out the DSL, and it is no longer necessary
70+
to use any functions in `org.mybatis.dynamic.sql.SqlBuilder`. The advantages of this are many and are detailed on the
71+
Kotlin overview page in the documentation. Many functions in `SqlBuilder` have been replaced by
72+
top level functions the `org.mybatis.dynamic.sql.util.kotlin.elements` package. In most cases you can switch to the
73+
native Kotlin DSL by simply changing the import statements. For example, you can switch usage of the `isEqualTo`
74+
function by changing
75+
76+
```kotlin
77+
import org.mybatis.dynamic.sql.SqlBuilder.isEqualTo
78+
```
79+
80+
to
81+
82+
```kotlin
83+
import org.mybatis.dynamic.sql.util.kotlin.elements.isEqualTo
84+
```
85+
86+
Several functions that accepted supplier arguments are not present in the Kotlin DSL. This is to avoid difficult
87+
and confusing method overload problems for methods that did not offer any real benefit. If you were using one of these
88+
methods in the Java DSL, then in the Kotlin DSL you will have to change the function argument from a supplier to the
89+
actual value itself.
90+
91+
A **breaking change** is that Kotlin support for `select` and `count` statements has been refactored. This will not impact code
6892
created by MyBatis generator. It will have an impact on Spring/Kotlin users as well as MyBatis users that coded joins or
6993
other queries directly in Kotlin. The difference is that the `from` clause has been moved inside the lambda for select
7094
and count statements.
@@ -84,7 +108,7 @@ The new code looks like this:
84108
}
85109
```
86110

87-
This change makes the Kotlin DSL a bit more consistent and also makes it easier to implement subquery support in the
111+
This change makes the Kotlin DSL more consistent and also makes it easier to implement subquery support in the
88112
Kotlin DSL.
89113

90114
### Added

checkstyle-override.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<!--
33
4-
Copyright 2016-2020 the original author or authors.
4+
Copyright 2016-2021 the original author or authors.
55
66
Licensed under the Apache License, Version 2.0 (the "License");
77
you may not use this file except in compliance with the License.
@@ -217,7 +217,7 @@
217217
<property name="target" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/>
218218
</module>
219219
<module name="JavadocMethod">
220-
<property name="scope" value="public"/>
220+
<property name="accessModifiers" value="public"/>
221221
<property name="allowMissingParamTags" value="true"/>
222222
<property name="allowMissingReturnTag" value="true"/>
223223
<property name="allowedAnnotations" value="Override, Test"/>

pom.xml

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
<clirr.comparisonVersion>1.2.0</clirr.comparisonVersion>
4040
<module.name>org.mybatis.dynamic.sql</module.name>
4141
<kotlin.version>1.5.0</kotlin.version>
42-
<jacoco.version>0.8.7</jacoco.version>
4342
<kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget>
4443
<sonar.sources>pom.xml,src/main/java,src/main/kotlin</sonar.sources>
4544
<sonar.tests>src/test/java,src/test/kotlin</sonar.tests>
+29-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
# Complex Queries
2-
Enhancements in version 1.1.2 make it easier to code complex queries. The Select DSL is implemented as a set of related objects. As the select statement is built, intermediate objects of various types are returned from the various methods that implement the DSL. The select statement can be completed by calling the `build()` method many of the intermediate objects. Prior to version 1.1.2, it was necessary to call `build()` on the **last** intermediate object. This restriction has been removed, and it is now possible to call `build()` on **any** intermediate object. This, along with several other enhancements, has simplified the coding of complex queries.
2+
Enhancements in version 1.1.2 make it easier to code complex queries. The Select DSL is implemented as a set of related
3+
objects. As the select statement is built, intermediate objects of various types are returned from the various methods
4+
that implement the DSL. The select statement can be completed by calling the `build()` method many of the intermediate
5+
objects. Prior to version 1.1.2, it was necessary to call `build()` on the **last** intermediate object. This
6+
restriction has been removed, and it is now possible to call `build()` on **any** intermediate object. This, along with
7+
several other enhancements, has simplified the coding of complex queries.
38

4-
For example, suppose you want to code a complex search on a Person table. The search parameters are id, first name, and last name. The rules are:
9+
For example, suppose you want to code a complex search on a Person table. The search parameters are id, first name,
10+
and last name. The rules are:
511

612
1. If an id is entered, use the id and ignore the other search parameters
713
1. If an id is not entered, then do a fuzzy search based on the other parameters
@@ -19,15 +25,15 @@ public SelectStatementProvider search(Integer targetId, String fName, String lNa
1925
.and(id, isEqualTo(targetId));
2026
} else {
2127
builder
22-
.and(firstName, isLike(fName).when(Objects::nonNull).then(s -> "%" + s + "%")) // (4)
23-
.and(lastName, isLikeWhenPresent(lName).then(this::addWildcards)); // (5)
28+
.and(firstName, isLike(fName).filter(Objects::nonNull).map(s -> "%" + s + "%")) // (4) (5)
29+
.and(lastName, isLikeWhenPresent(lName).map(this::addWildcards)); // (6)
2430
}
2531

2632
builder
2733
.orderBy(lastName, firstName)
28-
.fetchFirst(50).rowsOnly(); // (6)
34+
.fetchFirst(50).rowsOnly(); // (7)
2935

30-
return builder.build().render(RenderingStrategies.MYBATIS3); // (7)
36+
return builder.build().render(RenderingStrategies.MYBATIS3); // (8)
3137
}
3238

3339
public String addWildcards(String s) {
@@ -37,11 +43,21 @@ public String addWildcards(String s) {
3743

3844
Notes:
3945

40-
1. Note the use of the `var` keyword here. If you are using an older version of Java, the actual type is `QueryExpressionDSL<SelectModel>.QueryExpressionWhereBuilder`
41-
1. Here we are calling `where()` with no parameters. This sets up the builder to accept conditions further along in the code. If no conditions are added, then the where clause will not be rendered
42-
1. This `if` statement implements the rules of the search. If an ID is entered , use it. Otherwise, do a fuzzy search based on first name and last name.
43-
1. The `then` statement on this line allows you to change the parameter value before it is placed in the parameter Map. In this case we are adding SQL wildcards to the start and end of the search String - but only if the search String is not null. If the search String is null, the lambda will not be called and the condition will not render
44-
1. This shows using a method reference instead of a lambda on the `then`. Method references allow you to more clearly express intent. Note also the use of the `isLikeWhenPresent` condition which is a built in condition that checks for nulls
45-
1. It is a good idea to limit the number of rows returned from a search. The library now supports `fetch first` syntax for limiting rows
46-
1. Note that we are calling the `build` method from the intermediate object retrieved in step 1. It is no longer necessary to call `build` on the last object returned from a select builder
46+
1. Note the use of the `var` keyword here. If you are using an older version of Java, the actual type is
47+
`QueryExpressionDSL<SelectModel>.QueryExpressionWhereBuilder`
48+
1. Here we are calling `where()` with no parameters. This sets up the builder to accept conditions further along in the
49+
code. If no conditions are added, then the where clause will not be rendered
50+
1. This `if` statement implements the rules of the search. If an ID is entered , use it. Otherwise, do a fuzzy search
51+
based on first name and last name.
52+
1. The `filter` method on this line will mark the condition as unrenderable if the filter is not satisfied.
53+
1. The `map` statement on this line allows you to change the parameter value before it is placed in the parameter Map.
54+
In this case we are adding SQL wildcards to the start and end of the search String - but only if the search String
55+
is not null. If the search String is null, the lambda will not be called and the condition will not render
56+
1. This line shows the use of a method reference instead of a lambda on the `map`. Method references allow you to more
57+
clearly express intent. Note also the use of the `isLikeWhenPresent` function which is a built-in function that
58+
applies a non-null filter
59+
1. It is a good idea to limit the number of rows returned from a search. The library now supports `fetch first` syntax
60+
for limiting rows
61+
1. Note that we are calling the `build` method from the intermediate object retrieved in step 1. It is no longer
62+
necessary to call `build` on the last object returned from a select builder
4763

0 commit comments

Comments
 (0)