Skip to content

Commit

Permalink
Consistent Object result declarations for ResultQuerySpec
Browse files Browse the repository at this point in the history
Closes gh-31403
  • Loading branch information
jhoeller committed Oct 10, 2023
1 parent de6692e commit c0d98fc
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,9 @@ public Map<String, Object> singleRow() {
return classicOps.queryForMap(sql, indexedParams.toArray());
}

@SuppressWarnings("unchecked")
@Override
public <T> List<T> singleColumn() {
return (List<T>) classicOps.queryForList(sql, Object.class, indexedParams.toArray());
public List<Object> singleColumn() {
return classicOps.queryForList(sql, Object.class, indexedParams.toArray());
}
}

Expand All @@ -310,10 +309,9 @@ public Map<String, Object> singleRow() {
return namedParamOps.queryForMap(sql, namedParamSource);
}

@SuppressWarnings("unchecked")
@Override
public <T> List<T> singleColumn() {
return (List<T>) namedParamOps.queryForList(sql, namedParamSource, Object.class);
public List<Object> singleColumn() {
return namedParamOps.queryForList(sql, namedParamSource, Object.class);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,17 +323,16 @@ interface ResultQuerySpec {
* Retrieve a single column result,
* retaining the order from the original database result.
* @return a (potentially empty) list of rows, with each
* row represented as a column value of the given type
* row represented as its single column value
*/
<T> List<T> singleColumn();
List<Object> singleColumn();

/**
* Retrieve a single value result.
* @return the single row represented as its single
* column value of the given type
* @return the single row represented as its single column value
* @see DataAccessUtils#requiredSingleResult(Collection)
*/
default <T> T singleValue() {
default Object singleValue() {
return DataAccessUtils.requiredSingleResult(singleColumn());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void setup() throws Exception {


@Test
public void testQueryWithResultSetExtractor() throws SQLException {
public void queryWithResultSetExtractor() throws SQLException {
given(resultSet.next()).willReturn(true);
given(resultSet.getInt("id")).willReturn(1);
given(resultSet.getString("forename")).willReturn("rod");
Expand All @@ -122,7 +122,7 @@ public void testQueryWithResultSetExtractor() throws SQLException {
}

@Test
public void testQueryWithResultSetExtractorNoParameters() throws SQLException {
public void queryWithResultSetExtractorNoParameters() throws SQLException {
given(resultSet.next()).willReturn(true);
given(resultSet.getInt("id")).willReturn(1);
given(resultSet.getString("forename")).willReturn("rod");
Expand All @@ -145,7 +145,7 @@ public void testQueryWithResultSetExtractorNoParameters() throws SQLException {
}

@Test
public void testQueryWithRowCallbackHandler() throws SQLException {
public void queryWithRowCallbackHandler() throws SQLException {
given(resultSet.next()).willReturn(true, false);
given(resultSet.getInt("id")).willReturn(1);
given(resultSet.getString("forename")).willReturn("rod");
Expand All @@ -172,7 +172,7 @@ public void testQueryWithRowCallbackHandler() throws SQLException {
}

@Test
public void testQueryWithRowCallbackHandlerNoParameters() throws SQLException {
public void queryWithRowCallbackHandlerNoParameters() throws SQLException {
given(resultSet.next()).willReturn(true, false);
given(resultSet.getInt("id")).willReturn(1);
given(resultSet.getString("forename")).willReturn("rod");
Expand All @@ -195,7 +195,7 @@ public void testQueryWithRowCallbackHandlerNoParameters() throws SQLException {
}

@Test
public void testQueryWithRowMapper() throws SQLException {
public void queryWithRowMapper() throws SQLException {
given(resultSet.next()).willReturn(true, false);
given(resultSet.getInt("id")).willReturn(1);
given(resultSet.getString("forename")).willReturn("rod");
Expand Down Expand Up @@ -223,7 +223,7 @@ public void testQueryWithRowMapper() throws SQLException {
}

@Test
public void testQueryWithRowMapperNoParameters() throws SQLException {
public void queryWithRowMapperNoParameters() throws SQLException {
given(resultSet.next()).willReturn(true, false);
given(resultSet.getInt("id")).willReturn(1);
given(resultSet.getString("forename")).willReturn("rod");
Expand All @@ -247,7 +247,7 @@ public void testQueryWithRowMapperNoParameters() throws SQLException {
}

@Test
public void testQueryForObjectWithRowMapper() throws SQLException {
public void queryForObjectWithRowMapper() throws SQLException {
given(resultSet.next()).willReturn(true, false);
given(resultSet.getInt("id")).willReturn(1);
given(resultSet.getString("forename")).willReturn("rod");
Expand All @@ -274,7 +274,7 @@ public void testQueryForObjectWithRowMapper() throws SQLException {
}

@Test
public void testQueryForStreamWithRowMapper() throws SQLException {
public void queryForStreamWithRowMapper() throws SQLException {
given(resultSet.next()).willReturn(true, false);
given(resultSet.getInt("id")).willReturn(1);
given(resultSet.getString("forename")).willReturn("rod");
Expand Down Expand Up @@ -307,7 +307,7 @@ public void testQueryForStreamWithRowMapper() throws SQLException {
}

@Test
public void testUpdate() throws SQLException {
public void update() throws SQLException {
given(preparedStatement.executeUpdate()).willReturn(1);

params.add(1);
Expand All @@ -323,7 +323,7 @@ public void testUpdate() throws SQLException {
}

@Test
public void testUpdateWithTypedParameters() throws SQLException {
public void updateWithTypedParameters() throws SQLException {
given(preparedStatement.executeUpdate()).willReturn(1);

params.add(new SqlParameterValue(Types.DECIMAL, 1));
Expand All @@ -339,7 +339,7 @@ public void testUpdateWithTypedParameters() throws SQLException {
}

@Test
public void testUpdateAndGeneratedKeys() throws SQLException {
public void updateAndGeneratedKeys() throws SQLException {
given(resultSetMetaData.getColumnCount()).willReturn(1);
given(resultSetMetaData.getColumnLabel(1)).willReturn("1");
given(resultSet.getMetaData()).willReturn(resultSetMetaData);
Expand Down
Loading

0 comments on commit c0d98fc

Please sign in to comment.