You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
3
8
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:
5
11
6
12
1. If an id is entered, use the id and ignore the other search parameters
7
13
1. If an id is not entered, then do a fuzzy search based on the other parameters
@@ -37,11 +43,21 @@ public String addWildcards(String s) {
37
43
38
44
Notes:
39
45
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
@@ -96,20 +148,22 @@ table lists the optional conditions and shows how to use them:
96
148
97
149
| Condition | Example | Rendering Rules |
98
150
|-----------|---------|-----------------|
99
-
| Between| where(foo, isBetween(x).and(y).when(BiPredicate)) | The library will pass x and y to the BiPredicate's test method. The condition will render if BiPredicate.test(x, y) returns true |
100
-
| Equals | where(foo, isEqualTo(x).when(Predicate)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true |
101
-
| Greater Than | where(id, isGreaterThan(x).when(Predicate)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true |
102
-
| Greater Than or Equals | where(id, isGreaterThanOrEqualTo(x).when(Predicate)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true |
103
-
| Less Than | where(id, isLessThan(x).when(Predicate)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true |
104
-
| Less Than or Equals | where(id, isLessThanOrEqualTo(x).when(Predicate)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true |
105
-
| Like | where(id, isLike(x).when(Predicate)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true |
106
-
| Like Case Insensitive | where(id, isLikeCaseInsensitive(x).when(Predicate<String>)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true |
107
-
| Not Between | where(id, isNotBetween(x).and(y).when(BiPredicate)) | The library will pass x and y to the BiPredicate's test method. The condition will render if BiPredicate.test(x, y) returns true |
108
-
| Not Equals | where(id, isNotEqualTo(x).when(Predicate)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true |
109
-
| Not Like | where(id, isNotLike(x).when(Predicate)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true |
110
-
| Not Like Case Insensitive | where(id, isNotLikeCaseInsensitive(x).when(Predicate<String>)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true |
111
-
| Not Null | where(id, isNotNull().when(BooleanSupplier) | The condition will render if BooleanSupplier.getAsBoolean() returns true |
112
-
| Null | where(id, isNull().when(BooleanSupplier) | The condition will render if BooleanSupplier.getAsBoolean() returns true |
151
+
| Between| where(foo, isBetween(x).and(y).filter(BiPredicate)) | The library will pass x and y to the BiPredicate's test method. The condition will render if BiPredicate.test(x, y) returns true |
152
+
| Between| where(foo, isBetween(x).and(y).filter(Predicate)) | The library will invoke the Predicate's test method twice - once with x, once with y. The condition will render if both function calls return true |
153
+
| Equals | where(foo, isEqualTo(x).filter(Predicate)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true |
154
+
| Greater Than | where(id, isGreaterThan(x).filter(Predicate)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true |
155
+
| Greater Than or Equals | where(id, isGreaterThanOrEqualTo(x).filter(Predicate)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true |
156
+
| Less Than | where(id, isLessThan(x).filter(Predicate)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true |
157
+
| Less Than or Equals | where(id, isLessThanOrEqualTo(x).filter(Predicate)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true |
158
+
| Like | where(id, isLike(x).filter(Predicate)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true |
159
+
| Like Case Insensitive | where(id, isLikeCaseInsensitive(x).filter(Predicate<String>)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true |
160
+
| Not Between | where(id, isNotBetween(x).and(y).filter(BiPredicate)) | The library will pass x and y to the BiPredicate's test method. The condition will render if BiPredicate.test(x, y) returns true |
161
+
| Not Between| where(foo, isNotBetween(x).and(y).filter(Predicate)) | The library will invoke the Predicate's test method twice - once with x, once with y. The condition will render if both function calls return true |
162
+
| Not Equals | where(id, isNotEqualTo(x).filter(Predicate)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true |
163
+
| Not Like | where(id, isNotLike(x).filter(Predicate)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true |
164
+
| Not Like Case Insensitive | where(id, isNotLikeCaseInsensitive(x).filter(Predicate<String>)) | The library will pass x to the Predicate's test method. The condition will render if Predicate.test(x) returns true |
165
+
| Not Null | where(id, isNotNull().filter(BooleanSupplier) | The condition will render if BooleanSupplier.getAsBoolean() returns true |
166
+
| Null | where(id, isNull().filter(BooleanSupplier) | The condition will render if BooleanSupplier.getAsBoolean() returns true |
113
167
114
168
### "When Present" Condition Builders
115
169
The library supplies several methods that supply conditions to be used in the common case of checking for null
0 commit comments