Skip to content

Commit 0853baa

Browse files
committed
Fix Javadoc in [NamedParameter]JdbcOperations.queryForObject methods
This commit fixes the Javadoc in all queryForObject(...) methods in JdbcOperations and NamedParameterJdbcOperations regarding what kinds of exceptions are thrown under which conditions. Closes gh-27559
1 parent bf461ba commit 0853baa

File tree

2 files changed

+45
-37
lines changed

2 files changed

+45
-37
lines changed

spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,22 +22,21 @@
2222
import java.util.stream.Stream;
2323

2424
import org.springframework.dao.DataAccessException;
25-
import org.springframework.dao.IncorrectResultSizeDataAccessException;
2625
import org.springframework.jdbc.support.KeyHolder;
2726
import org.springframework.jdbc.support.rowset.SqlRowSet;
2827
import org.springframework.lang.Nullable;
2928

3029
/**
3130
* Interface specifying a basic set of JDBC operations.
32-
* Implemented by {@link JdbcTemplate}. Not often used directly, but a useful
31+
*
32+
* <p>Implemented by {@link JdbcTemplate}. Not often used directly, but a useful
3333
* option to enhance testability, as it can easily be mocked or stubbed.
3434
*
3535
* <p>Alternatively, the standard JDBC infrastructure can be mocked.
3636
* However, mocking this interface constitutes significantly less work.
3737
* As an alternative to a mock objects approach to testing data access code,
38-
* consider the powerful integration testing support provided in the
39-
* {@code org.springframework.test} package, shipped in
40-
* {@code spring-test.jar}.
38+
* consider the powerful integration testing support provided via the <em>Spring
39+
* TestContext Framework</em>, in the {@code spring-test} artifact.
4140
*
4241
* @author Rod Johnson
4342
* @author Juergen Hoeller
@@ -160,8 +159,8 @@ public interface JdbcOperations {
160159
* @param rowMapper a callback that will map one object per row
161160
* @return the single mapped object (may be {@code null} if the given
162161
* {@link RowMapper} returned {@code} null)
163-
* @throws IncorrectResultSizeDataAccessException if the query does not
164-
* return exactly one row
162+
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException
163+
* if the query does not return exactly one row
165164
* @throws DataAccessException if there is any problem executing the query
166165
* @see #queryForObject(String, RowMapper, Object...)
167166
*/
@@ -180,8 +179,10 @@ public interface JdbcOperations {
180179
* @param sql the SQL query to execute
181180
* @param requiredType the type that the result object is expected to match
182181
* @return the result object of the required type, or {@code null} in case of SQL NULL
183-
* @throws IncorrectResultSizeDataAccessException if the query does not return
184-
* exactly one row, or does not return exactly one column in that row
182+
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException
183+
* if the query does not return exactly one row
184+
* @throws org.springframework.jdbc.IncorrectResultSetColumnCountException
185+
* if the query does not return a row containing a single column
185186
* @throws DataAccessException if there is any problem executing the query
186187
* @see #queryForObject(String, Class, Object...)
187188
*/
@@ -198,8 +199,8 @@ public interface JdbcOperations {
198199
* mapped to a Map (one entry for each column, using the column name as the key).
199200
* @param sql the SQL query to execute
200201
* @return the result Map (one entry per column, with column name as key)
201-
* @throws IncorrectResultSizeDataAccessException if the query does not
202-
* return exactly one row
202+
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException
203+
* if the query does not return exactly one row
203204
* @throws DataAccessException if there is any problem executing the query
204205
* @see #queryForMap(String, Object...)
205206
* @see ColumnMapRowMapper
@@ -603,8 +604,8 @@ <T> Stream<T> queryForStream(String sql, RowMapper<T> rowMapper, @Nullable Objec
603604
* @param rowMapper a callback that will map one object per row
604605
* @return the single mapped object (may be {@code null} if the given
605606
* {@link RowMapper} returned {@code} null)
606-
* @throws IncorrectResultSizeDataAccessException if the query does not
607-
* return exactly one row
607+
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException
608+
* if the query does not return exactly one row
608609
* @throws DataAccessException if the query fails
609610
*/
610611
@Nullable
@@ -623,8 +624,8 @@ <T> T queryForObject(String sql, Object[] args, int[] argTypes, RowMapper<T> row
623624
* @param rowMapper a callback that will map one object per row
624625
* @return the single mapped object (may be {@code null} if the given
625626
* {@link RowMapper} returned {@code} null)
626-
* @throws IncorrectResultSizeDataAccessException if the query does not
627-
* return exactly one row
627+
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException
628+
* if the query does not return exactly one row
628629
* @throws DataAccessException if the query fails
629630
* @deprecated as of 5.3, in favor of {@link #queryForObject(String, RowMapper, Object...)}
630631
*/
@@ -644,8 +645,8 @@ <T> T queryForObject(String sql, Object[] args, int[] argTypes, RowMapper<T> row
644645
* only the argument value but also the SQL type and optionally the scale
645646
* @return the single mapped object (may be {@code null} if the given
646647
* {@link RowMapper} returned {@code} null)
647-
* @throws IncorrectResultSizeDataAccessException if the query does not
648-
* return exactly one row
648+
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException
649+
* if the query does not return exactly one row
649650
* @throws DataAccessException if the query fails
650651
* @since 3.0.1
651652
*/
@@ -663,8 +664,10 @@ <T> T queryForObject(String sql, Object[] args, int[] argTypes, RowMapper<T> row
663664
* (constants from {@code java.sql.Types})
664665
* @param requiredType the type that the result object is expected to match
665666
* @return the result object of the required type, or {@code null} in case of SQL NULL
666-
* @throws IncorrectResultSizeDataAccessException if the query does not return
667-
* exactly one row, or does not return exactly one column in that row
667+
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException
668+
* if the query does not return exactly one row
669+
* @throws org.springframework.jdbc.IncorrectResultSetColumnCountException
670+
* if the query does not return a row containing a single column
668671
* @throws DataAccessException if the query fails
669672
* @see #queryForObject(String, Class)
670673
* @see java.sql.Types
@@ -685,8 +688,10 @@ <T> T queryForObject(String sql, Object[] args, int[] argTypes, Class<T> require
685688
* only the argument value but also the SQL type and optionally the scale
686689
* @param requiredType the type that the result object is expected to match
687690
* @return the result object of the required type, or {@code null} in case of SQL NULL
688-
* @throws IncorrectResultSizeDataAccessException if the query does not return
689-
* exactly one row, or does not return exactly one column in that row
691+
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException
692+
* if the query does not return exactly one row
693+
* @throws org.springframework.jdbc.IncorrectResultSetColumnCountException
694+
* if the query does not return a row containing a single column
690695
* @throws DataAccessException if the query fails
691696
* @see #queryForObject(String, Class)
692697
* @deprecated as of 5.3, in favor of {@link #queryForObject(String, Class, Object...)}
@@ -707,8 +712,10 @@ <T> T queryForObject(String sql, Object[] args, int[] argTypes, Class<T> require
707712
* may also contain {@link SqlParameterValue} objects which indicate not
708713
* only the argument value but also the SQL type and optionally the scale
709714
* @return the result object of the required type, or {@code null} in case of SQL NULL
710-
* @throws IncorrectResultSizeDataAccessException if the query does not return
711-
* exactly one row, or does not return exactly one column in that row
715+
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException
716+
* if the query does not return exactly one row
717+
* @throws org.springframework.jdbc.IncorrectResultSetColumnCountException
718+
* if the query does not return a row containing a single column
712719
* @throws DataAccessException if the query fails
713720
* @since 3.0.1
714721
* @see #queryForObject(String, Class)
@@ -726,8 +733,8 @@ <T> T queryForObject(String sql, Object[] args, int[] argTypes, Class<T> require
726733
* @param argTypes the SQL types of the arguments
727734
* (constants from {@code java.sql.Types})
728735
* @return the result Map (one entry per column, with column name as key)
729-
* @throws IncorrectResultSizeDataAccessException if the query does not
730-
* return exactly one row
736+
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException
737+
* if the query does not return exactly one row
731738
* @throws DataAccessException if the query fails
732739
* @see #queryForMap(String)
733740
* @see ColumnMapRowMapper
@@ -750,8 +757,8 @@ <T> T queryForObject(String sql, Object[] args, int[] argTypes, Class<T> require
750757
* only the argument value but also the SQL type and optionally the scale
751758
* @return the result Map (one entry for each column, using the
752759
* column name as the key)
753-
* @throws IncorrectResultSizeDataAccessException if the query does not
754-
* return exactly one row
760+
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException
761+
* if the query does not return exactly one row
755762
* @throws DataAccessException if the query fails
756763
* @see #queryForMap(String)
757764
* @see ColumnMapRowMapper

spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcOperations.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -268,8 +268,7 @@ <T> Stream<T> queryForStream(String sql, Map<String, ?> paramMap, RowMapper<T> r
268268
* @return the single mapped object (may be {@code null} if the given
269269
* {@link RowMapper} returned {@code} null)
270270
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException
271-
* if the query does not return exactly one row, or does not return exactly
272-
* one column in that row
271+
* if the query does not return exactly one row
273272
* @throws DataAccessException if the query fails
274273
*/
275274
@Nullable
@@ -287,8 +286,7 @@ <T> T queryForObject(String sql, SqlParameterSource paramSource, RowMapper<T> ro
287286
* @return the single mapped object (may be {@code null} if the given
288287
* {@link RowMapper} returned {@code} null)
289288
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException
290-
* if the query does not return exactly one row, or does not return exactly
291-
* one column in that row
289+
* if the query does not return exactly one row
292290
* @throws DataAccessException if the query fails
293291
*/
294292
@Nullable
@@ -305,10 +303,12 @@ <T> T queryForObject(String sql, Map<String, ?> paramMap, RowMapper<T> rowMapper
305303
* @param requiredType the type that the result object is expected to match
306304
* @return the result object of the required type, or {@code null} in case of SQL NULL
307305
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException
308-
* if the query does not return exactly one row, or does not return exactly
309-
* one column in that row
306+
* if the query does not return exactly one row
307+
* @throws org.springframework.jdbc.IncorrectResultSetColumnCountException
308+
* if the query does not return a row containing a single column
310309
* @throws DataAccessException if the query fails
311310
* @see org.springframework.jdbc.core.JdbcTemplate#queryForObject(String, Class)
311+
* @see org.springframework.jdbc.core.SingleColumnRowMapper
312312
*/
313313
@Nullable
314314
<T> T queryForObject(String sql, SqlParameterSource paramSource, Class<T> requiredType)
@@ -325,8 +325,9 @@ <T> T queryForObject(String sql, SqlParameterSource paramSource, Class<T> requir
325325
* @param requiredType the type that the result object is expected to match
326326
* @return the result object of the required type, or {@code null} in case of SQL NULL
327327
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException
328-
* if the query does not return exactly one row, or does not return exactly
329-
* one column in that row
328+
* if the query does not return exactly one row
329+
* @throws org.springframework.jdbc.IncorrectResultSetColumnCountException
330+
* if the query does not return a row containing a single column
330331
* @throws DataAccessException if the query fails
331332
* @see org.springframework.jdbc.core.JdbcTemplate#queryForObject(String, Class)
332333
*/

0 commit comments

Comments
 (0)