Skip to content

Commit fda6dd6

Browse files
committed
Update docs
1 parent e8876ad commit fda6dd6

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

src/site/markdown/docs/conditions.md

+18-23
Original file line numberDiff line numberDiff line change
@@ -200,29 +200,6 @@ of the *values* of the condition. The library comes with functions that will fil
200200
case String values to enable case insensitive queries. There are extension points to add additional filtering and
201201
mapping if you so desire.
202202

203-
We think it is a good thing that the library will not render invalid SQL. An "in" condition will always be dropped from
204-
rendering if the list of values is empty. But there is some danger with this stance. Because the condition could be
205-
dropped from the rendered SQL, more rows could be impacted than expected if the list ends up empty for whatever reason.
206-
Our recommended solution is to make sure that you validate list values - especially if they are coming from direct user
207-
input. Another option is to take some action when the list is empty. This can be especially helpful when you are
208-
applying filters to the value list or using one of the built-in "when present" conditions. In that case, it is
209-
possible that the list of values could end up empty after a validation check.
210-
211-
The "In" conditions support a callback that will be invoked when the value list is empty and just before the statement
212-
is rendered. You could use the callback to create a condition that will throw an exception when the list is empty.
213-
For example:
214-
215-
```java
216-
private static <T> IsIn<T> isInRequired(Collection<T> values) {
217-
return IsIn.of(values).withListEmptyCallback(() -> { throw new RuntimeException("In values cannot be empty"); } );
218-
}
219-
220-
// Alternatively, there is a convenience method in the Callback interface
221-
private static <T> IsIn<T> isInRequired(Collection<T> values) {
222-
return IsIn.of(values).withListEmptyCallback(Callback.exceptionThrowingCallback("In values cannot be empty"));
223-
}
224-
```
225-
226203
The following table shows the different supplied In conditions and how they will render for different sets of inputs.
227204
The table assumes the following types of input:
228205

@@ -286,3 +263,21 @@ Then the condition could be used in a query as follows:
286263
.build()
287264
.render(RenderingStrategies.MYBATIS3);
288265
```
266+
267+
## Potential for Non Rendering Where Clauses
268+
269+
An "in" condition will always be dropped from rendering if the list of values is empty. Other conditions could be
270+
dropped from a where clause due to filtering. If all conditions fail to render, then the entire where clause will be
271+
dropped from the rendered SQL. In general, we think it is a good thing that the library will not render invalid SQL.
272+
But this stance does present a danger - if a where clause is dropped from the rendered SQL, then the statement could
273+
end up impacting all rows in a table. For example, a delete statement could inadvertently delete all rows in a table.
274+
275+
By default, and out of an abundance of caution, the library will not allow a statement to render if the entire where
276+
clause will be dropped. If a where clause is coded, but fails to render, then the library will throw a
277+
`NonRenderingWhereClauseException` by default.
278+
279+
If no where clause is coded in a statement, then we assume the statement is intended to affect all rows in a table.
280+
In that case no exception will be thrown.
281+
282+
This behavior can be modified through configuration - either globally for the entire library, or for each statement
283+
individually. See the "Configuration of the Library" page for details on configuration options.

0 commit comments

Comments
 (0)