StatementCreatorUtils handles Types.BOOLEAN through PreparedStatement.setBoolean
Issue: SPR-14116
(cherry picked from commit 797f5db
)
This commit is contained in:
parent
2166f2060f
commit
6b0f26c335
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -364,6 +364,14 @@ public abstract class StatementCreatorUtils {
|
|||
ps.setObject(paramIndex, inValue, sqlType);
|
||||
}
|
||||
}
|
||||
else if (sqlType == Types.BOOLEAN) {
|
||||
if (inValue instanceof Boolean) {
|
||||
ps.setBoolean(paramIndex, (Boolean) inValue);
|
||||
}
|
||||
else {
|
||||
ps.setObject(paramIndex, inValue, Types.BOOLEAN);
|
||||
}
|
||||
}
|
||||
else if (sqlType == Types.DATE) {
|
||||
if (inValue instanceof java.util.Date) {
|
||||
if (inValue instanceof java.sql.Date) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -49,16 +49,22 @@ public class SqlUpdateTests {
|
|||
|
||||
private static final String UPDATE =
|
||||
"update seat_status set booking_id = null";
|
||||
|
||||
private static final String UPDATE_INT =
|
||||
"update seat_status set booking_id = null where performance_id = ?";
|
||||
|
||||
private static final String UPDATE_INT_INT =
|
||||
"update seat_status set booking_id = null where performance_id = ? and price_band_id = ?";
|
||||
|
||||
private static final String UPDATE_NAMED_PARAMETERS =
|
||||
"update seat_status set booking_id = null where performance_id = :perfId and price_band_id = :priceId";
|
||||
|
||||
private static final String UPDATE_STRING =
|
||||
"update seat_status set booking_id = null where name = ?";
|
||||
|
||||
private static final String UPDATE_OBJECTS =
|
||||
"update seat_status set booking_id = null where performance_id = ? and price_band_id = ? and name = ? and confirmed = ?";
|
||||
|
||||
private static final String INSERT_GENERATE_KEYS =
|
||||
"insert into show (name) values(?)";
|
||||
|
||||
|
@ -66,11 +72,16 @@ public class SqlUpdateTests {
|
|||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private DataSource dataSource;
|
||||
|
||||
private Connection connection;
|
||||
|
||||
private PreparedStatement preparedStatement;
|
||||
|
||||
private ResultSet resultSet;
|
||||
|
||||
private ResultSetMetaData resultSetMetaData;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
dataSource = mock(DataSource.class);
|
||||
|
@ -87,6 +98,7 @@ public class SqlUpdateTests {
|
|||
verify(connection).close();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testUpdate() throws SQLException {
|
||||
given(preparedStatement.executeUpdate()).willReturn(1);
|
||||
|
@ -192,7 +204,7 @@ public class SqlUpdateTests {
|
|||
verify(preparedStatement).setObject(1, 1, Types.NUMERIC);
|
||||
verify(preparedStatement).setObject(2, 1, Types.NUMERIC, 2);
|
||||
verify(preparedStatement).setString(3, "rod");
|
||||
verify(preparedStatement).setObject(4, Boolean.TRUE, Types.BOOLEAN);
|
||||
verify(preparedStatement).setBoolean(4, Boolean.TRUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -231,7 +243,7 @@ public class SqlUpdateTests {
|
|||
verify(preparedStatement).setObject(1, 1, Types.NUMERIC);
|
||||
verify(preparedStatement).setObject(2, 1, Types.NUMERIC);
|
||||
verify(preparedStatement).setString(3, "rod");
|
||||
verify(preparedStatement).setObject(4, Boolean.TRUE, Types.BOOLEAN);
|
||||
verify(preparedStatement).setBoolean(4, Boolean.TRUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -360,10 +372,7 @@ public class SqlUpdateTests {
|
|||
}
|
||||
|
||||
public int run(int performanceId, int type, String name, boolean confirmed) {
|
||||
Object[] params =
|
||||
new Object[] {performanceId, type, name,
|
||||
new Boolean(confirmed)};
|
||||
return update(params);
|
||||
return update(performanceId, type, name, confirmed);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -379,8 +388,7 @@ public class SqlUpdateTests {
|
|||
}
|
||||
|
||||
public int run(String name, KeyHolder generatedKeyHolder) {
|
||||
Object[] params = new Object[] {name};
|
||||
return update(params, generatedKeyHolder);
|
||||
return update(new Object[] {name}, generatedKeyHolder);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -394,10 +402,7 @@ public class SqlUpdateTests {
|
|||
}
|
||||
|
||||
public int run(int performanceId, int type, String name, boolean confirmed) {
|
||||
Object[] params =
|
||||
new Object[] {
|
||||
performanceId, type, name, new Boolean(confirmed)};
|
||||
return update(params);
|
||||
return update(performanceId, type, name, confirmed);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue