|
|
|
|
@@ -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 {
|
|
|
|
|
// 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 {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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 {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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,27 +124,7 @@ public class JdbcClientQueryTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testQueryForListWithIndexedParamAndSingleColumn() throws Exception {
|
|
|
|
|
given(resultSet.getMetaData()).willReturn(resultSetMetaData);
|
|
|
|
|
given(resultSet.next()).willReturn(true, false);
|
|
|
|
|
given(resultSet.getObject(1)).willReturn(11);
|
|
|
|
|
|
|
|
|
|
List<Integer> li = client.sql("SELECT AGE FROM CUSTMR WHERE ID < ?")
|
|
|
|
|
.param(1, 3)
|
|
|
|
|
.query().singleColumn();
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
verify(preparedStatement).close();
|
|
|
|
|
verify(connection).close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testQueryForMapWithIndexedParamAndSingleRow() throws Exception {
|
|
|
|
|
given(resultSet.getMetaData()).willReturn(resultSetMetaData);
|
|
|
|
|
public void queryForMapWithIndexedParamAndSingleRow() throws Exception {
|
|
|
|
|
given(resultSet.next()).willReturn(true, false);
|
|
|
|
|
given(resultSet.getObject(1)).willReturn(11);
|
|
|
|
|
|
|
|
|
|
@@ -162,13 +141,31 @@ public class JdbcClientQueryTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testQueryForIntegerWithIndexedParamAndRowMapper() throws Exception {
|
|
|
|
|
public void queryForListWithIndexedParamAndSingleColumn() throws Exception {
|
|
|
|
|
given(resultSet.next()).willReturn(true, false);
|
|
|
|
|
given(resultSet.getInt(1)).willReturn(22);
|
|
|
|
|
given(resultSet.getObject(1)).willReturn(11);
|
|
|
|
|
|
|
|
|
|
Integer value = client.sql("SELECT AGE FROM CUSTMR WHERE ID = ?")
|
|
|
|
|
List<Object> li = client.sql("SELECT AGE FROM CUSTMR WHERE ID < ?")
|
|
|
|
|
.param(1, 3)
|
|
|
|
|
.query((rs, rowNum) -> rs.getInt(1)).single();
|
|
|
|
|
.query().singleColumn();
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
verify(preparedStatement).close();
|
|
|
|
|
verify(connection).close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void queryForIntegerWithIndexedParamAndSingleValue() throws Exception {
|
|
|
|
|
given(resultSet.next()).willReturn(true, false);
|
|
|
|
|
given(resultSet.getObject(1)).willReturn(22);
|
|
|
|
|
|
|
|
|
|
Integer value = (Integer) client.sql("SELECT AGE FROM CUSTMR WHERE ID = ?")
|
|
|
|
|
.param(1, 3)
|
|
|
|
|
.query().singleValue();
|
|
|
|
|
|
|
|
|
|
assertThat(value).isEqualTo(22);
|
|
|
|
|
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID = ?");
|
|
|
|
|
@@ -179,13 +176,32 @@ public class JdbcClientQueryTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testQueryForOptionalWithIndexedParamAndRowMapper() 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();
|
|
|
|
|
|
|
|
|
|
assertThat(value).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 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 {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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 {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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 {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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 {
|
|
|
|
|
// 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 {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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 {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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,27 +309,7 @@ public class JdbcClientQueryTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testQueryForListWithNamedParamAndSingleColumn() throws Exception {
|
|
|
|
|
given(resultSet.getMetaData()).willReturn(resultSetMetaData);
|
|
|
|
|
given(resultSet.next()).willReturn(true, false);
|
|
|
|
|
given(resultSet.getObject(1)).willReturn(11);
|
|
|
|
|
|
|
|
|
|
List<Integer> li = client.sql("SELECT AGE FROM CUSTMR WHERE ID < :id")
|
|
|
|
|
.param("id", 3)
|
|
|
|
|
.query().singleColumn();
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
verify(preparedStatement).close();
|
|
|
|
|
verify(connection).close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testQueryForMapWithNamedParamAndSingleRow() throws Exception {
|
|
|
|
|
given(resultSet.getMetaData()).willReturn(resultSetMetaData);
|
|
|
|
|
public void queryForMapWithNamedParamAndSingleRow() throws Exception {
|
|
|
|
|
given(resultSet.next()).willReturn(true, false);
|
|
|
|
|
given(resultSet.getObject(1)).willReturn(11);
|
|
|
|
|
|
|
|
|
|
@@ -334,7 +326,42 @@ public class JdbcClientQueryTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testQueryForIntegerWithNamedParamAndRowMapper() throws Exception {
|
|
|
|
|
public void queryForListWithNamedParamAndSingleColumn() 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 < :id")
|
|
|
|
|
.param("id", 3)
|
|
|
|
|
.query().singleColumn();
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
verify(preparedStatement).close();
|
|
|
|
|
verify(connection).close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void queryForIntegerWithNamedParamAndSingleValue() throws Exception {
|
|
|
|
|
given(resultSet.next()).willReturn(true, false);
|
|
|
|
|
given(resultSet.getObject(1)).willReturn(22);
|
|
|
|
|
|
|
|
|
|
Integer value = (Integer) client.sql("SELECT AGE FROM CUSTMR WHERE ID = :id")
|
|
|
|
|
.param("id", 3)
|
|
|
|
|
.query().singleValue();
|
|
|
|
|
|
|
|
|
|
assertThat(value).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 queryForIntegerWithNamedParamAndRowMapper() throws Exception {
|
|
|
|
|
given(resultSet.next()).willReturn(true, false);
|
|
|
|
|
given(resultSet.getInt(1)).willReturn(22);
|
|
|
|
|
|
|
|
|
|
@@ -352,15 +379,31 @@ public class JdbcClientQueryTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testQueryForIntegerWithNamedParamAndMappedSimpleValue() throws Exception {
|
|
|
|
|
given(resultSet.getMetaData()).willReturn(resultSetMetaData);
|
|
|
|
|
public void queryForOptionalWithNamedParamAndRowMapper() 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 = :id")
|
|
|
|
|
.param("id", 3)
|
|
|
|
|
.query((rs, rowNum) -> rs.getInt(1))
|
|
|
|
|
.optional();
|
|
|
|
|
|
|
|
|
|
assertThat(value.get()).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 queryForIntegerWithNamedParam() 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)
|
|
|
|
|
.single();
|
|
|
|
|
.query(Integer.class).single();
|
|
|
|
|
|
|
|
|
|
assertThat(value).isEqualTo(22);
|
|
|
|
|
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID = ?");
|
|
|
|
|
@@ -371,71 +414,13 @@ public class JdbcClientQueryTests {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testQueryForMappedRecordWithNamedParam() throws Exception {
|
|
|
|
|
given(resultSet.getMetaData()).willReturn(resultSetMetaData);
|
|
|
|
|
given(resultSet.findColumn("age")).willReturn(1);
|
|
|
|
|
public void queryForIntegerWithNamedParamAndList() 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")
|
|
|
|
|
.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 testQueryForMappedFieldHolderWithNamedParam() throws Exception {
|
|
|
|
|
given(resultSet.getMetaData()).willReturn(resultSetMetaData);
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
assertThat(value).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 testQueryForIntegerWithNamedParamAndList() 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 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 {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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 {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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 {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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 {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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 {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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 {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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 {
|
|
|
|
|
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 {
|
|
|
|
|
|
|
|
|
|
|