|
|
|
@ -51,12 +51,13 @@ import static org.mockito.Mockito.verify;
@@ -51,12 +51,13 @@ import static org.mockito.Mockito.verify;
|
|
|
|
|
*/ |
|
|
|
|
public class JdbcClientIndexedParameterTests { |
|
|
|
|
|
|
|
|
|
private static final String SELECT_NAMED_PARAMETERS = |
|
|
|
|
private static final String SELECT_INDEXED_PARAMETERS = |
|
|
|
|
"select id, forename from custmr where id = ? and country = ?"; |
|
|
|
|
|
|
|
|
|
private static final String SELECT_NO_PARAMETERS = |
|
|
|
|
"select id, forename from custmr"; |
|
|
|
|
|
|
|
|
|
private static final String UPDATE_NAMED_PARAMETERS = |
|
|
|
|
private static final String UPDATE_INDEXED_PARAMETERS = |
|
|
|
|
"update seat_status set booking_id = null where performance_id = ? and price_band_id = ?"; |
|
|
|
|
|
|
|
|
|
private static final String INSERT_GENERATE_KEYS = |
|
|
|
@ -101,7 +102,7 @@ public class JdbcClientIndexedParameterTests {
@@ -101,7 +102,7 @@ public class JdbcClientIndexedParameterTests {
|
|
|
|
|
|
|
|
|
|
params.add(new SqlParameterValue(Types.DECIMAL, 1)); |
|
|
|
|
params.add("UK"); |
|
|
|
|
Customer cust = client.sql(SELECT_NAMED_PARAMETERS).params(params).query( |
|
|
|
|
Customer cust = client.sql(SELECT_INDEXED_PARAMETERS).params(params).query( |
|
|
|
|
rs -> { |
|
|
|
|
rs.next(); |
|
|
|
|
Customer cust1 = new Customer(); |
|
|
|
@ -112,7 +113,7 @@ public class JdbcClientIndexedParameterTests {
@@ -112,7 +113,7 @@ public class JdbcClientIndexedParameterTests {
|
|
|
|
|
|
|
|
|
|
assertThat(cust.getId()).as("Customer id was assigned correctly").isEqualTo(1); |
|
|
|
|
assertThat(cust.getForename()).as("Customer forename was assigned correctly").isEqualTo("rod"); |
|
|
|
|
verify(connection).prepareStatement(SELECT_NAMED_PARAMETERS); |
|
|
|
|
verify(connection).prepareStatement(SELECT_INDEXED_PARAMETERS); |
|
|
|
|
verify(preparedStatement).setObject(1, 1, Types.DECIMAL); |
|
|
|
|
verify(preparedStatement).setString(2, "UK"); |
|
|
|
|
verify(resultSet).close(); |
|
|
|
@ -152,7 +153,7 @@ public class JdbcClientIndexedParameterTests {
@@ -152,7 +153,7 @@ public class JdbcClientIndexedParameterTests {
|
|
|
|
|
params.add(new SqlParameterValue(Types.DECIMAL, 1)); |
|
|
|
|
params.add("UK"); |
|
|
|
|
final List<Customer> customers = new ArrayList<>(); |
|
|
|
|
client.sql(SELECT_NAMED_PARAMETERS).params(params).query(rs -> { |
|
|
|
|
client.sql(SELECT_INDEXED_PARAMETERS).params(params).query(rs -> { |
|
|
|
|
Customer cust = new Customer(); |
|
|
|
|
cust.setId(rs.getInt(COLUMN_NAMES[0])); |
|
|
|
|
cust.setForename(rs.getString(COLUMN_NAMES[1])); |
|
|
|
@ -162,7 +163,7 @@ public class JdbcClientIndexedParameterTests {
@@ -162,7 +163,7 @@ public class JdbcClientIndexedParameterTests {
|
|
|
|
|
assertThat(customers).hasSize(1); |
|
|
|
|
assertThat(customers.get(0).getId()).as("Customer id was assigned correctly").isEqualTo(1); |
|
|
|
|
assertThat(customers.get(0).getForename()).as("Customer forename was assigned correctly").isEqualTo("rod"); |
|
|
|
|
verify(connection).prepareStatement(SELECT_NAMED_PARAMETERS); |
|
|
|
|
verify(connection).prepareStatement(SELECT_INDEXED_PARAMETERS); |
|
|
|
|
verify(preparedStatement).setObject(1, 1, Types.DECIMAL); |
|
|
|
|
verify(preparedStatement).setString(2, "UK"); |
|
|
|
|
verify(resultSet).close(); |
|
|
|
@ -201,7 +202,7 @@ public class JdbcClientIndexedParameterTests {
@@ -201,7 +202,7 @@ public class JdbcClientIndexedParameterTests {
|
|
|
|
|
|
|
|
|
|
params.add(new SqlParameterValue(Types.DECIMAL, 1)); |
|
|
|
|
params.add("UK"); |
|
|
|
|
List<Customer> customers = client.sql(SELECT_NAMED_PARAMETERS).params(params).query( |
|
|
|
|
List<Customer> customers = client.sql(SELECT_INDEXED_PARAMETERS).params(params).query( |
|
|
|
|
(rs, rownum) -> { |
|
|
|
|
Customer cust = new Customer(); |
|
|
|
|
cust.setId(rs.getInt(COLUMN_NAMES[0])); |
|
|
|
@ -213,7 +214,7 @@ public class JdbcClientIndexedParameterTests {
@@ -213,7 +214,7 @@ public class JdbcClientIndexedParameterTests {
|
|
|
|
|
Customer cust = customers.get(0); |
|
|
|
|
assertThat(cust.getId()).as("Customer id was assigned correctly").isEqualTo(1); |
|
|
|
|
assertThat(cust.getForename()).as("Customer forename was assigned correctly").isEqualTo("rod"); |
|
|
|
|
verify(connection).prepareStatement(SELECT_NAMED_PARAMETERS); |
|
|
|
|
verify(connection).prepareStatement(SELECT_INDEXED_PARAMETERS); |
|
|
|
|
verify(preparedStatement).setObject(1, 1, Types.DECIMAL); |
|
|
|
|
verify(preparedStatement).setString(2, "UK"); |
|
|
|
|
verify(resultSet).close(); |
|
|
|
@ -254,7 +255,7 @@ public class JdbcClientIndexedParameterTests {
@@ -254,7 +255,7 @@ public class JdbcClientIndexedParameterTests {
|
|
|
|
|
params.add(new SqlParameterValue(Types.DECIMAL, 1)); |
|
|
|
|
params.add("UK"); |
|
|
|
|
|
|
|
|
|
Customer cust = client.sql(SELECT_NAMED_PARAMETERS).params(params).query( |
|
|
|
|
Customer cust = client.sql(SELECT_INDEXED_PARAMETERS).params(params).query( |
|
|
|
|
(rs, rownum) -> { |
|
|
|
|
Customer cust1 = new Customer(); |
|
|
|
|
cust1.setId(rs.getInt(COLUMN_NAMES[0])); |
|
|
|
@ -264,7 +265,7 @@ public class JdbcClientIndexedParameterTests {
@@ -264,7 +265,7 @@ public class JdbcClientIndexedParameterTests {
|
|
|
|
|
|
|
|
|
|
assertThat(cust.getId()).as("Customer id was assigned correctly").isEqualTo(1); |
|
|
|
|
assertThat(cust.getForename()).as("Customer forename was assigned correctly").isEqualTo("rod"); |
|
|
|
|
verify(connection).prepareStatement(SELECT_NAMED_PARAMETERS); |
|
|
|
|
verify(connection).prepareStatement(SELECT_INDEXED_PARAMETERS); |
|
|
|
|
verify(preparedStatement).setObject(1, 1, Types.DECIMAL); |
|
|
|
|
verify(preparedStatement).setString(2, "UK"); |
|
|
|
|
verify(resultSet).close(); |
|
|
|
@ -282,7 +283,7 @@ public class JdbcClientIndexedParameterTests {
@@ -282,7 +283,7 @@ public class JdbcClientIndexedParameterTests {
|
|
|
|
|
params.add("UK"); |
|
|
|
|
AtomicInteger count = new AtomicInteger(); |
|
|
|
|
|
|
|
|
|
try (Stream<Customer> s = client.sql(SELECT_NAMED_PARAMETERS).params(params).query( |
|
|
|
|
try (Stream<Customer> s = client.sql(SELECT_INDEXED_PARAMETERS).params(params).query( |
|
|
|
|
(rs, rownum) -> { |
|
|
|
|
Customer cust1 = new Customer(); |
|
|
|
|
cust1.setId(rs.getInt(COLUMN_NAMES[0])); |
|
|
|
@ -297,7 +298,7 @@ public class JdbcClientIndexedParameterTests {
@@ -297,7 +298,7 @@ public class JdbcClientIndexedParameterTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
assertThat(count.get()).isEqualTo(1); |
|
|
|
|
verify(connection).prepareStatement(SELECT_NAMED_PARAMETERS); |
|
|
|
|
verify(connection).prepareStatement(SELECT_INDEXED_PARAMETERS); |
|
|
|
|
verify(preparedStatement).setObject(1, 1, Types.DECIMAL); |
|
|
|
|
verify(preparedStatement).setString(2, "UK"); |
|
|
|
|
verify(resultSet).close(); |
|
|
|
@ -311,10 +312,10 @@ public class JdbcClientIndexedParameterTests {
@@ -311,10 +312,10 @@ public class JdbcClientIndexedParameterTests {
|
|
|
|
|
|
|
|
|
|
params.add(1); |
|
|
|
|
params.add(1); |
|
|
|
|
int rowsAffected = client.sql(UPDATE_NAMED_PARAMETERS).params(params).update(); |
|
|
|
|
int rowsAffected = client.sql(UPDATE_INDEXED_PARAMETERS).params(params).update(); |
|
|
|
|
|
|
|
|
|
assertThat(rowsAffected).isEqualTo(1); |
|
|
|
|
verify(connection).prepareStatement(UPDATE_NAMED_PARAMETERS); |
|
|
|
|
verify(connection).prepareStatement(UPDATE_INDEXED_PARAMETERS); |
|
|
|
|
verify(preparedStatement).setObject(1, 1); |
|
|
|
|
verify(preparedStatement).setObject(2, 1); |
|
|
|
|
verify(preparedStatement).close(); |
|
|
|
@ -327,10 +328,10 @@ public class JdbcClientIndexedParameterTests {
@@ -327,10 +328,10 @@ public class JdbcClientIndexedParameterTests {
|
|
|
|
|
|
|
|
|
|
params.add(new SqlParameterValue(Types.DECIMAL, 1)); |
|
|
|
|
params.add(new SqlParameterValue(Types.INTEGER, 1)); |
|
|
|
|
int rowsAffected = client.sql(UPDATE_NAMED_PARAMETERS).params(params).update(); |
|
|
|
|
int rowsAffected = client.sql(UPDATE_INDEXED_PARAMETERS).params(params).update(); |
|
|
|
|
|
|
|
|
|
assertThat(rowsAffected).isEqualTo(1); |
|
|
|
|
verify(connection).prepareStatement(UPDATE_NAMED_PARAMETERS); |
|
|
|
|
verify(connection).prepareStatement(UPDATE_INDEXED_PARAMETERS); |
|
|
|
|
verify(preparedStatement).setObject(1, 1, Types.DECIMAL); |
|
|
|
|
verify(preparedStatement).setObject(2, 1, Types.INTEGER); |
|
|
|
|
verify(preparedStatement).close(); |
|
|
|
|