Skip to content

Commit cd009d6

Browse files
committed
Documentation
1 parent 93af255 commit cd009d6

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

CHANGELOG.md

+19
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@ This log will detail notable changes to MyBatis Dynamic SQL. Full details are av
66

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

9+
### Potentially Breaking Change
10+
11+
In this release we have changed the default behavior of the library in one key area. If a where clause is coded,
12+
but fails to render because all the optional conditionals drop out of the where clause, then the library will now
13+
throw a `NonRenderingWhereClauseException`. We have made this change out of an abundance of caution. The prior
14+
behavior would allow generation of statements that inadvertently affected all rows in a table.
15+
16+
Because of this change, we have also deprecated the "empty callback" functions in the "in" conditions.
17+
18+
If you desire the prior behavior where non rendering where clauses are allowed, you can change the global configuration
19+
of the library or - even better - change the configuration of individual statements where this behavior should be allowed.
20+
21+
For examples of global and statement configuration, see the "Configuration of the Library" page.
22+
23+
### Other Changes
24+
925
1. Added support for criteria groups without an initial criteria. This makes it possible to create an independent list
1026
of pre-created criteria and then add the list to a where clause. See the tests in the related pull request for
1127
usage examples. ([#462](https://github.com/mybatis/mybatis-dynamic-sql/pull/462))
@@ -15,6 +31,9 @@ GitHub milestone: [https://github.com/mybatis/mybatis-dynamic-sql/issues?q=miles
1531
3. Updated the Kotlin DSL to use Kotlin 1.7's new "definitely non-null" types where appropriate. This helps us to more
1632
accurately represent the nullable/non-nullable expectations for API method calls.
1733
([#496](https://github.com/mybatis/mybatis-dynamic-sql/pull/496))
34+
4. Added the ability to configure the library and change some default behaviors. Currently, this is limited to changing
35+
the behavior of the library in regard to where clauses that will not render. See the new configuration page for
36+
details.
1837

1938
## Release 1.4.0 - March 3, 2022
2039

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Configuration of the Library
2+
3+
Most behaviors of MyBatis Dynamic SQL are not configurable - the library does what it does.
4+
This page will detail the behaviors that can be modified. Configuration is available with version 1.4.1 and later
5+
of the library.
6+
7+
The library can be configured globally - which will change the behavior for all statements - or each individual statement
8+
can be configured. There are sensible defaults for all configuration values, so configuration is not strictly necessary.
9+
If you want to change any of the default behaviors of the library, then the information on this page will help.
10+
11+
Prior to version 1.4.1 of the library, there was no configurable behavior in the library. In version 1.4.1 we changed
12+
the default behavior of the library to throw an exception if a where clause fails to render. We did this out of an
13+
abundance of caution because the optional conditions in a where clause could lead to a statement that affected all
14+
rows in a table (for example, a delete statement could inadvertently delete all rows in a table). If you want the library
15+
to function as it did before version 1.4.1 where it was acceptable to have a where clause that didn't render, then you
16+
can change the global configuration as shown below.
17+
18+
## Global Configuration
19+
20+
On first use the library will initialize the global configuration. The global configuration can be changed via a property
21+
file named `mybatis-dynamic-sql.properties` in the root of the classpath. If you wish to use a different file name,
22+
you can specify the file name as a JVM property named `mybatis-dynamic-sql.configurationFile`. Note that the global
23+
configuration is created one time and shared for every statement in the same JVM.
24+
25+
The configuration file is a standard Java properties file. The possible values are detailed in the next section.
26+
27+
## Global Configuration Properties
28+
29+
| Property | Default | Meaning |
30+
|--------------------------------|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
31+
| nonRenderingWhereClauseAllowed | false | If a where clause is specified, but fails to render, then the library will throw a `NonRenderingWhereClauseException` by default. If you set this value to true, then no exception will be thrown. This could cause statements to be rendered without where clauses that affect all rows in a table. |
32+
33+
## Statement Configuration
34+
35+
If the global configuration is not acceptable for any individual statement, you can also configure the statement in the
36+
DSL. Consider the following statement:
37+
38+
```java
39+
DeleteStatementProvider deleteStatement = deleteFrom(animalData)
40+
.where(id, isNotIn(null, 22, null).filter(Objects::nonNull).filter(i -> i != 22))
41+
.configureStatement(c -> c.setNonRenderingWhereClauseAllowed(true))
42+
.build()
43+
.render(RenderingStrategies.MYBATIS3);
44+
```
45+
46+
In this case, the `isNotIn` condition has filters that will remove all values from the condition. In that case, the
47+
condition will not render and, subsequently, the where clause will not render. This means that the generated delete
48+
statement would delete all rows in the table. By default, the global configuration will block this statement from
49+
rendering and throw a `NonRenderingWhereClauseException`. If for some reason you would like to allow a statement
50+
like this to be rendered, then you can allow it as shown above with the `configureStatement` method.
51+
52+
The Kotlin DSL contains the same function:
53+
54+
```kotlin
55+
val deleteStatement = deleteFrom(person) {
56+
where { id isNotEqualToWhenPresent null }
57+
configureStatement { isNonRenderingWhereClauseAllowed = true }
58+
}
59+
```
60+

src/site/site.xml

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<item href="docs/introduction.html" name="Introduction" />
3838
<item href="docs/CHANGELOG.html" name="Change Log" />
3939
<item href="docs/quickStart.html" name="Quick Start" />
40+
<item href="docs/configuration.html" name="Configuration of the Library" />
4041
<item href="docs/databaseObjects.html" name="Modeling Database Objects" />
4142
<item href="docs/whereClauses.html" name="WHERE Clause Support" >
4243
<item href="docs/conditions.html" name="WHERE Conditions"/>

0 commit comments

Comments
 (0)