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