Skip to content

Commit e8aeab3

Browse files
committed
Documentation
1 parent efd0de8 commit e8aeab3

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ In the next major release of the library, all deprecated code will be removed.
2424
- Added the `applyOperator` function to make it easy to use non-standard database operators in expressions ([#220](https://github.com/mybatis/mybatis-dynamic-sql/issues/220))
2525
- Added convenience methods for count(column) and count(distinct column) ([#221](https://github.com/mybatis/mybatis-dynamic-sql/issues/221))
2626
- Added support for union queries in Kotlin ([#187](https://github.com/mybatis/mybatis-dynamic-sql/issues/187))
27+
- Added the ability to write "in" conditions that will render even if empty ([#228](https://github.com/mybatis/mybatis-dynamic-sql/issues/228))
2728
- Many enhancements for Spring including:
2829
- Fixed a bug where multi-row insert statements did not render properly for Spring ([#224](https://github.com/mybatis/mybatis-dynamic-sql/issues/224))
2930
- Added support for a parameter type converter for use cases where the Java type of a column does not match the database column type ([#131](https://github.com/mybatis/mybatis-dynamic-sql/issues/131))

src/site/markdown/docs/conditions.md

+17
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,23 @@ The library supplies several specializations of optional conditions to be used i
124124
### Optionality with the "In" Conditions
125125
Optionality with the "in" and "not in" conditions is a bit more complex than the other types of conditions. The first thing to know is that no "in" or "not in" condition will render if the list of values is empty. For example, there will never be rendered SQL like `where name in ()`. So optionality of the "in" conditions is more about optionality of the *values* of the condition. The library comes with functions that will filter out null values, and will upper case String values to enable case insensitive queries. There are extension points to add additional filtering and mapping if you so desire.
126126

127+
We think it is a good thing that the library will not render invalid SQL. Normally an "in" condition will be dropped from rendering if the list of values is empty - either through filtering or from the creation of the list. But there is some danger with this stance. Because the condition could be dropped from the rendered SQL, more rows could be impacted than expected if the list ends up empty for whatever reason. Our recommended solution is to make sure that you validate list values - especially if they are coming from direct user input. Another option is to force the conditions to render even if they are empty - which will cause a database error in most cases. If you want to force "in" conditions to render even if they are empty, you will need to create your own condition and configure it to render when empty. This is easily done by subclassing one of the existing conditions. For example:
128+
129+
```java
130+
public class IsInRequired<T> extends IsIn<T> {
131+
protected IsInRequired(Collection<T> values) {
132+
super(values);
133+
forceRenderingWhenEmpty(); // calling this method will force the condition to render even if the values list is empty
134+
}
135+
136+
public static <T> IsInRequired<T> isIn(Collection<T> values) {
137+
return new IsInRequired<>(values);
138+
}
139+
}
140+
```
141+
142+
Note that we do not supply conditions like this as a part of the standard library because we believe that forcing the library to render invalid SQL is an extreme measure and should be undertaken with care.
143+
127144
The following table shows the different supplied In conditions and how they will render for different sets of inputs. The table assumes the following types of input:
128145

129146
- Example 1 assumes an input list of ("foo", null, "bar") - like `where(name, isIn("foo", null, "bar"))`

0 commit comments

Comments
 (0)