|
|
|
@ -64,6 +64,7 @@ public class JdbcClientQueryTests {
@@ -64,6 +64,7 @@ public class JdbcClientQueryTests {
|
|
|
|
|
given(dataSource.getConnection()).willReturn(connection); |
|
|
|
|
given(connection.prepareStatement(anyString())).willReturn(preparedStatement); |
|
|
|
|
given(preparedStatement.executeQuery()).willReturn(resultSet); |
|
|
|
|
given(resultSet.getMetaData()).willReturn(resultSetMetaData); |
|
|
|
|
given(resultSetMetaData.getColumnCount()).willReturn(1); |
|
|
|
|
given(resultSetMetaData.getColumnLabel(1)).willReturn("age"); |
|
|
|
|
} |
|
|
|
@ -72,8 +73,7 @@ public class JdbcClientQueryTests {
@@ -72,8 +73,7 @@ public class JdbcClientQueryTests {
|
|
|
|
|
// Indexed parameters
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testQueryForListWithIndexedParam() throws Exception { |
|
|
|
|
given(resultSet.getMetaData()).willReturn(resultSetMetaData); |
|
|
|
|
public void queryForListWithIndexedParam() throws Exception { |
|
|
|
|
given(resultSet.next()).willReturn(true, true, false); |
|
|
|
|
given(resultSet.getObject(1)).willReturn(11, 12); |
|
|
|
|
|
|
|
|
@ -92,7 +92,7 @@ public class JdbcClientQueryTests {
@@ -92,7 +92,7 @@ public class JdbcClientQueryTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testQueryForListWithIndexedParamAndEmptyResult() throws Exception { |
|
|
|
|
public void queryForListWithIndexedParamAndEmptyResult() throws Exception { |
|
|
|
|
given(resultSet.next()).willReturn(false); |
|
|
|
|
|
|
|
|
|
List<Map<String, Object>> li = client.sql("SELECT AGE FROM CUSTMR WHERE ID < ?") |
|
|
|
@ -107,8 +107,7 @@ public class JdbcClientQueryTests {
@@ -107,8 +107,7 @@ public class JdbcClientQueryTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testQueryForListWithIndexedParamAndSingleRow() throws Exception { |
|
|
|
|
given(resultSet.getMetaData()).willReturn(resultSetMetaData); |
|
|
|
|
public void queryForListWithIndexedParamAndSingleRow() throws Exception { |
|
|
|
|
given(resultSet.next()).willReturn(true, false); |
|
|
|
|
given(resultSet.getObject(1)).willReturn(11); |
|
|
|
|
|
|
|
|
@ -125,12 +124,28 @@ public class JdbcClientQueryTests {
@@ -125,12 +124,28 @@ public class JdbcClientQueryTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testQueryForListWithIndexedParamAndSingleColumn() throws Exception { |
|
|
|
|
given(resultSet.getMetaData()).willReturn(resultSetMetaData); |
|
|
|
|
public void queryForMapWithIndexedParamAndSingleRow() throws Exception { |
|
|
|
|
given(resultSet.next()).willReturn(true, false); |
|
|
|
|
given(resultSet.getObject(1)).willReturn(11); |
|
|
|
|
|
|
|
|
|
List<Integer> li = client.sql("SELECT AGE FROM CUSTMR WHERE ID < ?") |
|
|
|
|
Map<String, Object> map = client.sql("SELECT AGE FROM CUSTMR WHERE ID < ?") |
|
|
|
|
.param(1, 3) |
|
|
|
|
.query().singleRow(); |
|
|
|
|
|
|
|
|
|
assertThat(map.get("age")).as("Row is Integer").isEqualTo(11); |
|
|
|
|
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID < ?"); |
|
|
|
|
verify(preparedStatement).setObject(1, 3); |
|
|
|
|
verify(resultSet).close(); |
|
|
|
|
verify(preparedStatement).close(); |
|
|
|
|
verify(connection).close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void queryForListWithIndexedParamAndSingleColumn() throws Exception { |
|
|
|
|
given(resultSet.next()).willReturn(true, false); |
|
|
|
|
given(resultSet.getObject(1)).willReturn(11); |
|
|
|
|
|
|
|
|
|
List<Object> li = client.sql("SELECT AGE FROM CUSTMR WHERE ID < ?") |
|
|
|
|
.param(1, 3) |
|
|
|
|
.query().singleColumn(); |
|
|
|
|
|
|
|
|
@ -144,17 +159,16 @@ public class JdbcClientQueryTests {
@@ -144,17 +159,16 @@ public class JdbcClientQueryTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testQueryForMapWithIndexedParamAndSingleRow() throws Exception { |
|
|
|
|
given(resultSet.getMetaData()).willReturn(resultSetMetaData); |
|
|
|
|
public void queryForIntegerWithIndexedParamAndSingleValue() throws Exception { |
|
|
|
|
given(resultSet.next()).willReturn(true, false); |
|
|
|
|
given(resultSet.getObject(1)).willReturn(11); |
|
|
|
|
given(resultSet.getObject(1)).willReturn(22); |
|
|
|
|
|
|
|
|
|
Map<String, Object> map = client.sql("SELECT AGE FROM CUSTMR WHERE ID < ?") |
|
|
|
|
Integer value = (Integer) client.sql("SELECT AGE FROM CUSTMR WHERE ID = ?") |
|
|
|
|
.param(1, 3) |
|
|
|
|
.query().singleRow(); |
|
|
|
|
.query().singleValue(); |
|
|
|
|
|
|
|
|
|
assertThat(map.get("age")).as("Row is Integer").isEqualTo(11); |
|
|
|
|
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID < ?"); |
|
|
|
|
assertThat(value).isEqualTo(22); |
|
|
|
|
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID = ?"); |
|
|
|
|
verify(preparedStatement).setObject(1, 3); |
|
|
|
|
verify(resultSet).close(); |
|
|
|
|
verify(preparedStatement).close(); |
|
|
|
@ -162,13 +176,14 @@ public class JdbcClientQueryTests {
@@ -162,13 +176,14 @@ public class JdbcClientQueryTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testQueryForIntegerWithIndexedParamAndRowMapper() throws Exception { |
|
|
|
|
public void queryForIntegerWithIndexedParamAndRowMapper() throws Exception { |
|
|
|
|
given(resultSet.next()).willReturn(true, false); |
|
|
|
|
given(resultSet.getInt(1)).willReturn(22); |
|
|
|
|
|
|
|
|
|
Integer value = client.sql("SELECT AGE FROM CUSTMR WHERE ID = ?") |
|
|
|
|
.param(1, 3) |
|
|
|
|
.query((rs, rowNum) -> rs.getInt(1)).single(); |
|
|
|
|
.query((rs, rowNum) -> rs.getInt(1)) |
|
|
|
|
.single(); |
|
|
|
|
|
|
|
|
|
assertThat(value).isEqualTo(22); |
|
|
|
|
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID = ?"); |
|
|
|
@ -179,13 +194,14 @@ public class JdbcClientQueryTests {
@@ -179,13 +194,14 @@ public class JdbcClientQueryTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testQueryForOptionalWithIndexedParamAndRowMapper() throws Exception { |
|
|
|
|
public void queryForOptionalWithIndexedParamAndRowMapper() throws Exception { |
|
|
|
|
given(resultSet.next()).willReturn(true, false); |
|
|
|
|
given(resultSet.getInt(1)).willReturn(22); |
|
|
|
|
|
|
|
|
|
Optional<Integer> value = client.sql("SELECT AGE FROM CUSTMR WHERE ID = ?") |
|
|
|
|
.param(1, 3) |
|
|
|
|
.query((rs, rowNum) -> rs.getInt(1)).optional(); |
|
|
|
|
.query((rs, rowNum) -> rs.getInt(1)) |
|
|
|
|
.optional(); |
|
|
|
|
|
|
|
|
|
assertThat(value.get()).isEqualTo(22); |
|
|
|
|
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID = ?"); |
|
|
|
@ -196,14 +212,13 @@ public class JdbcClientQueryTests {
@@ -196,14 +212,13 @@ public class JdbcClientQueryTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testQueryForIntegerWithIndexedParam() throws Exception { |
|
|
|
|
given(resultSet.getMetaData()).willReturn(resultSetMetaData); |
|
|
|
|
public void queryForIntegerWithIndexedParam() throws Exception { |
|
|
|
|
given(resultSet.next()).willReturn(true, false); |
|
|
|
|
given(resultSet.getObject(1)).willReturn(22); |
|
|
|
|
given(resultSet.getInt(1)).willReturn(22); |
|
|
|
|
|
|
|
|
|
Integer value = client.sql("SELECT AGE FROM CUSTMR WHERE ID = ?") |
|
|
|
|
.param(1, 3) |
|
|
|
|
.query().singleValue(); |
|
|
|
|
.query(Integer.class).single(); |
|
|
|
|
|
|
|
|
|
assertThat(value).isEqualTo(22); |
|
|
|
|
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID = ?"); |
|
|
|
@ -214,14 +229,13 @@ public class JdbcClientQueryTests {
@@ -214,14 +229,13 @@ public class JdbcClientQueryTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testQueryForIntWithIndexedParam() throws Exception { |
|
|
|
|
given(resultSet.getMetaData()).willReturn(resultSetMetaData); |
|
|
|
|
public void queryForIntWithIndexedParam() throws Exception { |
|
|
|
|
given(resultSet.next()).willReturn(true, false); |
|
|
|
|
given(resultSet.getObject(1)).willReturn(22); |
|
|
|
|
given(resultSet.getInt(1)).willReturn(22); |
|
|
|
|
|
|
|
|
|
int i = client.sql("SELECT AGE FROM CUSTMR WHERE ID = ?") |
|
|
|
|
.param(1, 3) |
|
|
|
|
.query().singleValue(); |
|
|
|
|
.query(Integer.class).single(); |
|
|
|
|
|
|
|
|
|
assertThat(i).as("Return of an int").isEqualTo(22); |
|
|
|
|
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID = ?"); |
|
|
|
@ -232,7 +246,7 @@ public class JdbcClientQueryTests {
@@ -232,7 +246,7 @@ public class JdbcClientQueryTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testQueryForObjectWithIndexedParamAndList() { |
|
|
|
|
public void queryForObjectWithIndexedParamAndList() { |
|
|
|
|
assertThatIllegalArgumentException().isThrownBy(() -> |
|
|
|
|
client.sql("SELECT AGE FROM CUSTMR WHERE ID IN (?)").param(Arrays.asList(3, 4)).query().singleValue()); |
|
|
|
|
} |
|
|
|
@ -241,8 +255,7 @@ public class JdbcClientQueryTests {
@@ -241,8 +255,7 @@ public class JdbcClientQueryTests {
|
|
|
|
|
// Named parameters
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testQueryForListWithNamedParam() throws Exception { |
|
|
|
|
given(resultSet.getMetaData()).willReturn(resultSetMetaData); |
|
|
|
|
public void queryForListWithNamedParam() throws Exception { |
|
|
|
|
given(resultSet.next()).willReturn(true, true, false); |
|
|
|
|
given(resultSet.getObject(1)).willReturn(11, 12); |
|
|
|
|
|
|
|
|
@ -262,7 +275,7 @@ public class JdbcClientQueryTests {
@@ -262,7 +275,7 @@ public class JdbcClientQueryTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testQueryForListWithNamedParamAndEmptyResult() throws Exception { |
|
|
|
|
public void queryForListWithNamedParamAndEmptyResult() throws Exception { |
|
|
|
|
given(resultSet.next()).willReturn(false); |
|
|
|
|
|
|
|
|
|
List<Map<String, Object>> li = client.sql("SELECT AGE FROM CUSTMR WHERE ID < :id") |
|
|
|
@ -278,8 +291,7 @@ public class JdbcClientQueryTests {
@@ -278,8 +291,7 @@ public class JdbcClientQueryTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testQueryForListWithNamedParamAndSingleRow() throws Exception { |
|
|
|
|
given(resultSet.getMetaData()).willReturn(resultSetMetaData); |
|
|
|
|
public void queryForListWithNamedParamAndSingleRow() throws Exception { |
|
|
|
|
given(resultSet.next()).willReturn(true, false); |
|
|
|
|
given(resultSet.getObject(1)).willReturn(11); |
|
|
|
|
|
|
|
|
@ -297,17 +309,15 @@ public class JdbcClientQueryTests {
@@ -297,17 +309,15 @@ public class JdbcClientQueryTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testQueryForListWithNamedParamAndSingleColumn() throws Exception { |
|
|
|
|
given(resultSet.getMetaData()).willReturn(resultSetMetaData); |
|
|
|
|
public void queryForMapWithNamedParamAndSingleRow() throws Exception { |
|
|
|
|
given(resultSet.next()).willReturn(true, false); |
|
|
|
|
given(resultSet.getObject(1)).willReturn(11); |
|
|
|
|
|
|
|
|
|
List<Integer> li = client.sql("SELECT AGE FROM CUSTMR WHERE ID < :id") |
|
|
|
|
Map<String, Object> map = client.sql("SELECT AGE FROM CUSTMR WHERE ID < :id") |
|
|
|
|
.param("id", 3) |
|
|
|
|
.query().singleColumn(); |
|
|
|
|
.query().singleRow(); |
|
|
|
|
|
|
|
|
|
assertThat(li.size()).as("All rows returned").isEqualTo(1); |
|
|
|
|
assertThat(li.get(0)).as("First row is Integer").isEqualTo(11); |
|
|
|
|
assertThat(map.get("age")).as("Row is Integer").isEqualTo(11); |
|
|
|
|
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID < ?"); |
|
|
|
|
verify(preparedStatement).setObject(1, 3); |
|
|
|
|
verify(resultSet).close(); |
|
|
|
@ -316,16 +326,16 @@ public class JdbcClientQueryTests {
@@ -316,16 +326,16 @@ public class JdbcClientQueryTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testQueryForMapWithNamedParamAndSingleRow() throws Exception { |
|
|
|
|
given(resultSet.getMetaData()).willReturn(resultSetMetaData); |
|
|
|
|
public void queryForListWithNamedParamAndSingleColumn() throws Exception { |
|
|
|
|
given(resultSet.next()).willReturn(true, false); |
|
|
|
|
given(resultSet.getObject(1)).willReturn(11); |
|
|
|
|
|
|
|
|
|
Map<String, Object> map = client.sql("SELECT AGE FROM CUSTMR WHERE ID < :id") |
|
|
|
|
List<Object> li = client.sql("SELECT AGE FROM CUSTMR WHERE ID < :id") |
|
|
|
|
.param("id", 3) |
|
|
|
|
.query().singleRow(); |
|
|
|
|
.query().singleColumn(); |
|
|
|
|
|
|
|
|
|
assertThat(map.get("age")).as("Row is Integer").isEqualTo(11); |
|
|
|
|
assertThat(li.size()).as("All rows returned").isEqualTo(1); |
|
|
|
|
assertThat(li.get(0)).as("First row is Integer").isEqualTo(11); |
|
|
|
|
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID < ?"); |
|
|
|
|
verify(preparedStatement).setObject(1, 3); |
|
|
|
|
verify(resultSet).close(); |
|
|
|
@ -334,14 +344,13 @@ public class JdbcClientQueryTests {
@@ -334,14 +344,13 @@ public class JdbcClientQueryTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testQueryForIntegerWithNamedParamAndRowMapper() throws Exception { |
|
|
|
|
public void queryForIntegerWithNamedParamAndSingleValue() throws Exception { |
|
|
|
|
given(resultSet.next()).willReturn(true, false); |
|
|
|
|
given(resultSet.getInt(1)).willReturn(22); |
|
|
|
|
given(resultSet.getObject(1)).willReturn(22); |
|
|
|
|
|
|
|
|
|
Integer value = client.sql("SELECT AGE FROM CUSTMR WHERE ID = :id") |
|
|
|
|
Integer value = (Integer) client.sql("SELECT AGE FROM CUSTMR WHERE ID = :id") |
|
|
|
|
.param("id", 3) |
|
|
|
|
.query((rs, rowNum) -> rs.getInt(1)) |
|
|
|
|
.single(); |
|
|
|
|
.query().singleValue(); |
|
|
|
|
|
|
|
|
|
assertThat(value).isEqualTo(22); |
|
|
|
|
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID = ?"); |
|
|
|
@ -352,14 +361,13 @@ public class JdbcClientQueryTests {
@@ -352,14 +361,13 @@ public class JdbcClientQueryTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testQueryForIntegerWithNamedParamAndMappedSimpleValue() throws Exception { |
|
|
|
|
given(resultSet.getMetaData()).willReturn(resultSetMetaData); |
|
|
|
|
public void queryForIntegerWithNamedParamAndRowMapper() throws Exception { |
|
|
|
|
given(resultSet.next()).willReturn(true, false); |
|
|
|
|
given(resultSet.getInt(1)).willReturn(22); |
|
|
|
|
|
|
|
|
|
Integer value = client.sql("SELECT AGE FROM CUSTMR WHERE ID = :id") |
|
|
|
|
.param("id", 3) |
|
|
|
|
.query(Integer.class) |
|
|
|
|
.query((rs, rowNum) -> rs.getInt(1)) |
|
|
|
|
.single(); |
|
|
|
|
|
|
|
|
|
assertThat(value).isEqualTo(22); |
|
|
|
@ -371,18 +379,16 @@ public class JdbcClientQueryTests {
@@ -371,18 +379,16 @@ public class JdbcClientQueryTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testQueryForMappedRecordWithNamedParam() throws Exception { |
|
|
|
|
given(resultSet.getMetaData()).willReturn(resultSetMetaData); |
|
|
|
|
given(resultSet.findColumn("age")).willReturn(1); |
|
|
|
|
public void queryForOptionalWithNamedParamAndRowMapper() throws Exception { |
|
|
|
|
given(resultSet.next()).willReturn(true, false); |
|
|
|
|
given(resultSet.getInt(1)).willReturn(22); |
|
|
|
|
|
|
|
|
|
AgeRecord value = client.sql("SELECT AGE FROM CUSTMR WHERE ID = :id") |
|
|
|
|
Optional<Integer> value = client.sql("SELECT AGE FROM CUSTMR WHERE ID = :id") |
|
|
|
|
.param("id", 3) |
|
|
|
|
.query(AgeRecord.class) |
|
|
|
|
.single(); |
|
|
|
|
.query((rs, rowNum) -> rs.getInt(1)) |
|
|
|
|
.optional(); |
|
|
|
|
|
|
|
|
|
assertThat(value.age()).isEqualTo(22); |
|
|
|
|
assertThat(value.get()).isEqualTo(22); |
|
|
|
|
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID = ?"); |
|
|
|
|
verify(preparedStatement).setObject(1, 3); |
|
|
|
|
verify(resultSet).close(); |
|
|
|
@ -391,33 +397,13 @@ public class JdbcClientQueryTests {
@@ -391,33 +397,13 @@ public class JdbcClientQueryTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testQueryForMappedFieldHolderWithNamedParam() throws Exception { |
|
|
|
|
given(resultSet.getMetaData()).willReturn(resultSetMetaData); |
|
|
|
|
public void queryForIntegerWithNamedParam() throws Exception { |
|
|
|
|
given(resultSet.next()).willReturn(true, false); |
|
|
|
|
given(resultSet.getInt(1)).willReturn(22); |
|
|
|
|
|
|
|
|
|
AgeFieldHolder value = client.sql("SELECT AGE FROM CUSTMR WHERE ID = :id") |
|
|
|
|
.param("id", 3) |
|
|
|
|
.query(AgeFieldHolder.class) |
|
|
|
|
.single(); |
|
|
|
|
|
|
|
|
|
assertThat(value.age).isEqualTo(22); |
|
|
|
|
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID = ?"); |
|
|
|
|
verify(preparedStatement).setObject(1, 3); |
|
|
|
|
verify(resultSet).close(); |
|
|
|
|
verify(preparedStatement).close(); |
|
|
|
|
verify(connection).close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testQueryForIntegerWithNamedParam() throws Exception { |
|
|
|
|
given(resultSet.getMetaData()).willReturn(resultSetMetaData); |
|
|
|
|
given(resultSet.next()).willReturn(true, false); |
|
|
|
|
given(resultSet.getObject(1)).willReturn(22); |
|
|
|
|
|
|
|
|
|
Integer value = client.sql("SELECT AGE FROM CUSTMR WHERE ID = :id") |
|
|
|
|
.param("id", 3) |
|
|
|
|
.query().singleValue(); |
|
|
|
|
.query(Integer.class).single(); |
|
|
|
|
|
|
|
|
|
assertThat(value).isEqualTo(22); |
|
|
|
|
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID = ?"); |
|
|
|
@ -428,14 +414,13 @@ public class JdbcClientQueryTests {
@@ -428,14 +414,13 @@ public class JdbcClientQueryTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testQueryForIntegerWithNamedParamAndList() throws Exception { |
|
|
|
|
given(resultSet.getMetaData()).willReturn(resultSetMetaData); |
|
|
|
|
public void queryForIntegerWithNamedParamAndList() throws Exception { |
|
|
|
|
given(resultSet.next()).willReturn(true, false); |
|
|
|
|
given(resultSet.getObject(1)).willReturn(22); |
|
|
|
|
given(resultSet.getInt(1)).willReturn(22); |
|
|
|
|
|
|
|
|
|
Integer value = client.sql("SELECT AGE FROM CUSTMR WHERE ID IN (:ids)") |
|
|
|
|
.param("ids", Arrays.asList(3, 4)) |
|
|
|
|
.query().singleValue(); |
|
|
|
|
.query(Integer.class).single(); |
|
|
|
|
|
|
|
|
|
assertThat(value).isEqualTo(22); |
|
|
|
|
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID IN (?, ?)"); |
|
|
|
@ -447,17 +432,16 @@ public class JdbcClientQueryTests {
@@ -447,17 +432,16 @@ public class JdbcClientQueryTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testQueryForIntegerWithNamedParamAndListOfExpressionLists() throws Exception { |
|
|
|
|
given(resultSet.getMetaData()).willReturn(resultSetMetaData); |
|
|
|
|
public void queryForIntegerWithNamedParamAndListOfExpressionLists() throws Exception { |
|
|
|
|
given(resultSet.next()).willReturn(true, false); |
|
|
|
|
given(resultSet.getObject(1)).willReturn(22); |
|
|
|
|
given(resultSet.getInt(1)).willReturn(22); |
|
|
|
|
|
|
|
|
|
List<Object[]> l1 = new ArrayList<>(); |
|
|
|
|
l1.add(new Object[] {3, "Rod"}); |
|
|
|
|
l1.add(new Object[] {4, "Juergen"}); |
|
|
|
|
Integer value = client.sql("SELECT AGE FROM CUSTMR WHERE (ID, NAME) IN (:multiExpressionList)") |
|
|
|
|
.param("multiExpressionList", l1) |
|
|
|
|
.query().singleValue(); |
|
|
|
|
.query(Integer.class).single(); |
|
|
|
|
|
|
|
|
|
assertThat(value).isEqualTo(22); |
|
|
|
|
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE (ID, NAME) IN ((?, ?), (?, ?))"); |
|
|
|
@ -471,14 +455,13 @@ public class JdbcClientQueryTests {
@@ -471,14 +455,13 @@ public class JdbcClientQueryTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testQueryForIntWithNamedParam() throws Exception { |
|
|
|
|
given(resultSet.getMetaData()).willReturn(resultSetMetaData); |
|
|
|
|
public void queryForIntWithNamedParam() throws Exception { |
|
|
|
|
given(resultSet.next()).willReturn(true, false); |
|
|
|
|
given(resultSet.getObject(1)).willReturn(22); |
|
|
|
|
given(resultSet.getInt(1)).willReturn(22); |
|
|
|
|
|
|
|
|
|
int i = client.sql("SELECT AGE FROM CUSTMR WHERE ID = :id") |
|
|
|
|
.param("id", 3) |
|
|
|
|
.query().singleValue(); |
|
|
|
|
.query(Integer.class).single(); |
|
|
|
|
|
|
|
|
|
assertThat(i).as("Return of an int").isEqualTo(22); |
|
|
|
|
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID = ?"); |
|
|
|
@ -489,8 +472,7 @@ public class JdbcClientQueryTests {
@@ -489,8 +472,7 @@ public class JdbcClientQueryTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testQueryForLongWithParamBean() throws Exception { |
|
|
|
|
given(resultSet.getMetaData()).willReturn(resultSetMetaData); |
|
|
|
|
public void queryForLongWithParamBean() throws Exception { |
|
|
|
|
given(resultSet.next()).willReturn(true, false); |
|
|
|
|
given(resultSet.getLong(1)).willReturn(87L); |
|
|
|
|
|
|
|
|
@ -507,8 +489,7 @@ public class JdbcClientQueryTests {
@@ -507,8 +489,7 @@ public class JdbcClientQueryTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testQueryForLongWithParamBeanWithCollection() throws Exception { |
|
|
|
|
given(resultSet.getMetaData()).willReturn(resultSetMetaData); |
|
|
|
|
public void queryForLongWithParamBeanWithCollection() throws Exception { |
|
|
|
|
given(resultSet.next()).willReturn(true, false); |
|
|
|
|
given(resultSet.getLong(1)).willReturn(87L); |
|
|
|
|
|
|
|
|
@ -526,8 +507,7 @@ public class JdbcClientQueryTests {
@@ -526,8 +507,7 @@ public class JdbcClientQueryTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testQueryForLongWithParamRecord() throws Exception { |
|
|
|
|
given(resultSet.getMetaData()).willReturn(resultSetMetaData); |
|
|
|
|
public void queryForLongWithParamRecord() throws Exception { |
|
|
|
|
given(resultSet.next()).willReturn(true, false); |
|
|
|
|
given(resultSet.getLong(1)).willReturn(87L); |
|
|
|
|
|
|
|
|
@ -544,8 +524,7 @@ public class JdbcClientQueryTests {
@@ -544,8 +524,7 @@ public class JdbcClientQueryTests {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void testQueryForLongWithParamFieldHolder() throws Exception { |
|
|
|
|
given(resultSet.getMetaData()).willReturn(resultSetMetaData); |
|
|
|
|
public void queryForLongWithParamFieldHolder() throws Exception { |
|
|
|
|
given(resultSet.next()).willReturn(true, false); |
|
|
|
|
given(resultSet.getLong(1)).willReturn(87L); |
|
|
|
|
|
|
|
|
@ -561,6 +540,41 @@ public class JdbcClientQueryTests {
@@ -561,6 +540,41 @@ public class JdbcClientQueryTests {
|
|
|
|
|
verify(connection).close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void queryForMappedRecordWithNamedParam() throws Exception { |
|
|
|
|
given(resultSet.findColumn("age")).willReturn(1); |
|
|
|
|
given(resultSet.next()).willReturn(true, false); |
|
|
|
|
given(resultSet.getInt(1)).willReturn(22); |
|
|
|
|
|
|
|
|
|
AgeRecord value = client.sql("SELECT AGE FROM CUSTMR WHERE ID = :id") |
|
|
|
|
.param("id", 3) |
|
|
|
|
.query(AgeRecord.class).single(); |
|
|
|
|
|
|
|
|
|
assertThat(value.age()).isEqualTo(22); |
|
|
|
|
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID = ?"); |
|
|
|
|
verify(preparedStatement).setObject(1, 3); |
|
|
|
|
verify(resultSet).close(); |
|
|
|
|
verify(preparedStatement).close(); |
|
|
|
|
verify(connection).close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
public void queryForMappedFieldHolderWithNamedParam() throws Exception { |
|
|
|
|
given(resultSet.next()).willReturn(true, false); |
|
|
|
|
given(resultSet.getInt(1)).willReturn(22); |
|
|
|
|
|
|
|
|
|
AgeFieldHolder value = client.sql("SELECT AGE FROM CUSTMR WHERE ID = :id") |
|
|
|
|
.param("id", 3) |
|
|
|
|
.query(AgeFieldHolder.class).single(); |
|
|
|
|
|
|
|
|
|
assertThat(value.age).isEqualTo(22); |
|
|
|
|
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID = ?"); |
|
|
|
|
verify(preparedStatement).setObject(1, 3); |
|
|
|
|
verify(resultSet).close(); |
|
|
|
|
verify(preparedStatement).close(); |
|
|
|
|
verify(connection).close(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static class ParameterBean { |
|
|
|
|
|
|
|
|
|