@@ -20,6 +20,10 @@ public class DynamicParameterList {
2020
2121 interface DynamicParameter {
2222 void setParam ( CallableStatement statement , int index ) throws SQLException ;
23+
24+ default String getSql ( String key ) {
25+ return key + " => ?" ;
26+ }
2327 }
2428
2529 private DynamicParameterList (LinkedHashMap <String , DynamicParameter > params ) {
@@ -33,8 +37,8 @@ private DynamicParameterList(LinkedHashMap<String, DynamicParameter> params) {
3337 * @return comma-separated list of parameter identifiers
3438 */
3539 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 ()) )
3842 .collect (Collectors .joining (", " ));
3943 }
4044
@@ -116,7 +120,7 @@ public DynamicParameterListBuilder addIfNotEmpty(String identifier, Object[] val
116120 }
117121
118122 public DynamicParameterListBuilder add (String identifier , Boolean value ) {
119- params .put (identifier , null );
123+ params .put (identifier , new DynamicBoolParameter ( value ) );
120124 return this ;
121125 }
122126
@@ -167,6 +171,28 @@ public void setParam(CallableStatement statement, int index) throws SQLException
167171 }
168172 }
169173
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+
170196 private static class DynamicArrayParameter implements DynamicParameter {
171197 private final Object [] value ;
172198 private final String customTypeName ;
0 commit comments