Skip to content

Commit 797f5db

Browse files
committed
StatementCreatorUtils handles Types.BOOLEAN through PreparedStatement.setBoolean
Issue: SPR-14116
1 parent 7c450fa commit 797f5db

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

spring-jdbc/src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -364,6 +364,14 @@ else if (scale != null) {
364364
ps.setObject(paramIndex, inValue, sqlType);
365365
}
366366
}
367+
else if (sqlType == Types.BOOLEAN) {
368+
if (inValue instanceof Boolean) {
369+
ps.setBoolean(paramIndex, (Boolean) inValue);
370+
}
371+
else {
372+
ps.setObject(paramIndex, inValue, Types.BOOLEAN);
373+
}
374+
}
367375
else if (sqlType == Types.DATE) {
368376
if (inValue instanceof java.util.Date) {
369377
if (inValue instanceof java.sql.Date) {

spring-jdbc/src/test/java/org/springframework/jdbc/object/SqlUpdateTests.java

+18-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -49,28 +49,39 @@ public class SqlUpdateTests {
4949

5050
private static final String UPDATE =
5151
"update seat_status set booking_id = null";
52+
5253
private static final String UPDATE_INT =
5354
"update seat_status set booking_id = null where performance_id = ?";
55+
5456
private static final String UPDATE_INT_INT =
5557
"update seat_status set booking_id = null where performance_id = ? and price_band_id = ?";
58+
5659
private static final String UPDATE_NAMED_PARAMETERS =
5760
"update seat_status set booking_id = null where performance_id = :perfId and price_band_id = :priceId";
61+
5862
private static final String UPDATE_STRING =
5963
"update seat_status set booking_id = null where name = ?";
64+
6065
private static final String UPDATE_OBJECTS =
6166
"update seat_status set booking_id = null where performance_id = ? and price_band_id = ? and name = ? and confirmed = ?";
67+
6268
private static final String INSERT_GENERATE_KEYS =
6369
"insert into show (name) values(?)";
6470

6571
@Rule
6672
public ExpectedException thrown = ExpectedException.none();
6773

6874
private DataSource dataSource;
75+
6976
private Connection connection;
77+
7078
private PreparedStatement preparedStatement;
79+
7180
private ResultSet resultSet;
81+
7282
private ResultSetMetaData resultSetMetaData;
7383

84+
7485
@Before
7586
public void setUp() throws Exception {
7687
dataSource = mock(DataSource.class);
@@ -87,6 +98,7 @@ public void verifyClosed() throws Exception {
8798
verify(connection).close();
8899
}
89100

101+
90102
@Test
91103
public void testUpdate() throws SQLException {
92104
given(preparedStatement.executeUpdate()).willReturn(1);
@@ -192,7 +204,7 @@ public void testUpdateMixed() throws SQLException {
192204
verify(preparedStatement).setObject(1, 1, Types.NUMERIC);
193205
verify(preparedStatement).setObject(2, 1, Types.NUMERIC, 2);
194206
verify(preparedStatement).setString(3, "rod");
195-
verify(preparedStatement).setObject(4, Boolean.TRUE, Types.BOOLEAN);
207+
verify(preparedStatement).setBoolean(4, Boolean.TRUE);
196208
}
197209

198210
@Test
@@ -231,7 +243,7 @@ public void testUpdateConstructor() throws SQLException {
231243
verify(preparedStatement).setObject(1, 1, Types.NUMERIC);
232244
verify(preparedStatement).setObject(2, 1, Types.NUMERIC);
233245
verify(preparedStatement).setString(3, "rod");
234-
verify(preparedStatement).setObject(4, Boolean.TRUE, Types.BOOLEAN);
246+
verify(preparedStatement).setBoolean(4, Boolean.TRUE);
235247
}
236248

237249
@Test
@@ -360,10 +372,7 @@ public MixedUpdater() {
360372
}
361373

362374
public int run(int performanceId, int type, String name, boolean confirmed) {
363-
Object[] params =
364-
new Object[] {performanceId, type, name,
365-
new Boolean(confirmed)};
366-
return update(params);
375+
return update(performanceId, type, name, confirmed);
367376
}
368377
}
369378

@@ -379,8 +388,7 @@ public GeneratedKeysUpdater() {
379388
}
380389

381390
public int run(String name, KeyHolder generatedKeyHolder) {
382-
Object[] params = new Object[] {name};
383-
return update(params, generatedKeyHolder);
391+
return update(new Object[] {name}, generatedKeyHolder);
384392
}
385393
}
386394

@@ -394,10 +402,7 @@ public ConstructorUpdater() {
394402
}
395403

396404
public int run(int performanceId, int type, String name, boolean confirmed) {
397-
Object[] params =
398-
new Object[] {
399-
performanceId, type, name, new Boolean(confirmed)};
400-
return update(params);
405+
return update(performanceId, type, name, confirmed);
401406
}
402407
}
403408

0 commit comments

Comments
 (0)