@@ -20,6 +20,10 @@ public class DynamicParameterList {
20
20
21
21
interface DynamicParameter {
22
22
void setParam ( CallableStatement statement , int index ) throws SQLException ;
23
+
24
+ default String getSql ( String key ) {
25
+ return key + " => ?" ;
26
+ }
23
27
}
24
28
25
29
private DynamicParameterList (LinkedHashMap <String , DynamicParameter > params ) {
@@ -33,8 +37,8 @@ private DynamicParameterList(LinkedHashMap<String, DynamicParameter> params) {
33
37
* @return comma-separated list of parameter identifiers
34
38
*/
35
39
public String getSql () {
36
- return params .keySet ().stream ()
37
- .map (e -> e + " => ?" )
40
+ return params .entrySet ().stream ()
41
+ .map (e -> e . getValue (). getSql ( e . getKey ()) )
38
42
.collect (Collectors .joining (", " ));
39
43
}
40
44
@@ -116,7 +120,7 @@ public DynamicParameterListBuilder addIfNotEmpty(String identifier, Object[] val
116
120
}
117
121
118
122
public DynamicParameterListBuilder add (String identifier , Boolean value ) {
119
- params .put (identifier , null );
123
+ params .put (identifier , new DynamicBoolParameter ( value ) );
120
124
return this ;
121
125
}
122
126
@@ -167,6 +171,28 @@ public void setParam(CallableStatement statement, int index) throws SQLException
167
171
}
168
172
}
169
173
174
+ private static class DynamicBoolParameter implements DynamicParameter {
175
+ private final Boolean value ;
176
+
177
+ DynamicBoolParameter ( Boolean value ) {
178
+ this .value = value ;
179
+ }
180
+
181
+ @ Override
182
+ public void setParam (CallableStatement statement , int index ) throws SQLException {
183
+ if ( value == null ) {
184
+ statement .setNull (index , Types .BOOLEAN );
185
+ } else {
186
+ statement .setInt (index , (value )?1 :0 );
187
+ }
188
+ }
189
+
190
+ @ Override
191
+ public String getSql (String key ) {
192
+ return key + " => (case ? when 1 then true else false)" ;
193
+ }
194
+ }
195
+
170
196
private static class DynamicArrayParameter implements DynamicParameter {
171
197
private final Object [] value ;
172
198
private final String customTypeName ;
0 commit comments