Browse Source

Merge branch '5.3.x'

pull/27560/head
Sam Brannen 5 years ago
parent
commit
4fc359f75e
  1. 63
      spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java
  2. 19
      spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcOperations.java

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -22,22 +22,21 @@ import java.util.Map;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessException;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.jdbc.support.KeyHolder; import org.springframework.jdbc.support.KeyHolder;
import org.springframework.jdbc.support.rowset.SqlRowSet; import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
/** /**
* Interface specifying a basic set of JDBC operations. * Interface specifying a basic set of JDBC operations.
* Implemented by {@link JdbcTemplate}. Not often used directly, but a useful *
* <p>Implemented by {@link JdbcTemplate}. Not often used directly, but a useful
* option to enhance testability, as it can easily be mocked or stubbed. * option to enhance testability, as it can easily be mocked or stubbed.
* *
* <p>Alternatively, the standard JDBC infrastructure can be mocked. * <p>Alternatively, the standard JDBC infrastructure can be mocked.
* However, mocking this interface constitutes significantly less work. * However, mocking this interface constitutes significantly less work.
* As an alternative to a mock objects approach to testing data access code, * As an alternative to a mock objects approach to testing data access code,
* consider the powerful integration testing support provided in the * consider the powerful integration testing support provided via the <em>Spring
* {@code org.springframework.test} package, shipped in * TestContext Framework</em>, in the {@code spring-test} artifact.
* {@code spring-test.jar}.
* *
* @author Rod Johnson * @author Rod Johnson
* @author Juergen Hoeller * @author Juergen Hoeller
@ -160,8 +159,8 @@ public interface JdbcOperations {
* @param rowMapper a callback that will map one object per row * @param rowMapper a callback that will map one object per row
* @return the single mapped object (may be {@code null} if the given * @return the single mapped object (may be {@code null} if the given
* {@link RowMapper} returned {@code} null) * {@link RowMapper} returned {@code} null)
* @throws IncorrectResultSizeDataAccessException if the query does not * @throws org.springframework.dao.IncorrectResultSizeDataAccessException
* return exactly one row * if the query does not return exactly one row
* @throws DataAccessException if there is any problem executing the query * @throws DataAccessException if there is any problem executing the query
* @see #queryForObject(String, RowMapper, Object...) * @see #queryForObject(String, RowMapper, Object...)
*/ */
@ -180,8 +179,10 @@ public interface JdbcOperations {
* @param sql the SQL query to execute * @param sql the SQL query to execute
* @param requiredType the type that the result object is expected to match * @param requiredType the type that the result object is expected to match
* @return the result object of the required type, or {@code null} in case of SQL NULL * @return the result object of the required type, or {@code null} in case of SQL NULL
* @throws IncorrectResultSizeDataAccessException if the query does not return * @throws org.springframework.dao.IncorrectResultSizeDataAccessException
* exactly one row, or does not return exactly one column in that row * if the query does not return exactly one row
* @throws org.springframework.jdbc.IncorrectResultSetColumnCountException
* if the query does not return a row containing a single column
* @throws DataAccessException if there is any problem executing the query * @throws DataAccessException if there is any problem executing the query
* @see #queryForObject(String, Class, Object...) * @see #queryForObject(String, Class, Object...)
*/ */
@ -198,8 +199,8 @@ public interface JdbcOperations {
* mapped to a Map (one entry for each column, using the column name as the key). * mapped to a Map (one entry for each column, using the column name as the key).
* @param sql the SQL query to execute * @param sql the SQL query to execute
* @return the result Map (one entry per column, with column name as key) * @return the result Map (one entry per column, with column name as key)
* @throws IncorrectResultSizeDataAccessException if the query does not * @throws org.springframework.dao.IncorrectResultSizeDataAccessException
* return exactly one row * if the query does not return exactly one row
* @throws DataAccessException if there is any problem executing the query * @throws DataAccessException if there is any problem executing the query
* @see #queryForMap(String, Object...) * @see #queryForMap(String, Object...)
* @see ColumnMapRowMapper * @see ColumnMapRowMapper
@ -603,8 +604,8 @@ public interface JdbcOperations {
* @param rowMapper a callback that will map one object per row * @param rowMapper a callback that will map one object per row
* @return the single mapped object (may be {@code null} if the given * @return the single mapped object (may be {@code null} if the given
* {@link RowMapper} returned {@code} null) * {@link RowMapper} returned {@code} null)
* @throws IncorrectResultSizeDataAccessException if the query does not * @throws org.springframework.dao.IncorrectResultSizeDataAccessException
* return exactly one row * if the query does not return exactly one row
* @throws DataAccessException if the query fails * @throws DataAccessException if the query fails
*/ */
@Nullable @Nullable
@ -623,8 +624,8 @@ public interface JdbcOperations {
* @param rowMapper a callback that will map one object per row * @param rowMapper a callback that will map one object per row
* @return the single mapped object (may be {@code null} if the given * @return the single mapped object (may be {@code null} if the given
* {@link RowMapper} returned {@code} null) * {@link RowMapper} returned {@code} null)
* @throws IncorrectResultSizeDataAccessException if the query does not * @throws org.springframework.dao.IncorrectResultSizeDataAccessException
* return exactly one row * if the query does not return exactly one row
* @throws DataAccessException if the query fails * @throws DataAccessException if the query fails
* @deprecated as of 5.3, in favor of {@link #queryForObject(String, RowMapper, Object...)} * @deprecated as of 5.3, in favor of {@link #queryForObject(String, RowMapper, Object...)}
*/ */
@ -644,8 +645,8 @@ public interface JdbcOperations {
* only the argument value but also the SQL type and optionally the scale * only the argument value but also the SQL type and optionally the scale
* @return the single mapped object (may be {@code null} if the given * @return the single mapped object (may be {@code null} if the given
* {@link RowMapper} returned {@code} null) * {@link RowMapper} returned {@code} null)
* @throws IncorrectResultSizeDataAccessException if the query does not * @throws org.springframework.dao.IncorrectResultSizeDataAccessException
* return exactly one row * if the query does not return exactly one row
* @throws DataAccessException if the query fails * @throws DataAccessException if the query fails
* @since 3.0.1 * @since 3.0.1
*/ */
@ -663,8 +664,10 @@ public interface JdbcOperations {
* (constants from {@code java.sql.Types}) * (constants from {@code java.sql.Types})
* @param requiredType the type that the result object is expected to match * @param requiredType the type that the result object is expected to match
* @return the result object of the required type, or {@code null} in case of SQL NULL * @return the result object of the required type, or {@code null} in case of SQL NULL
* @throws IncorrectResultSizeDataAccessException if the query does not return * @throws org.springframework.dao.IncorrectResultSizeDataAccessException
* exactly one row, or does not return exactly one column in that row * if the query does not return exactly one row
* @throws org.springframework.jdbc.IncorrectResultSetColumnCountException
* if the query does not return a row containing a single column
* @throws DataAccessException if the query fails * @throws DataAccessException if the query fails
* @see #queryForObject(String, Class) * @see #queryForObject(String, Class)
* @see java.sql.Types * @see java.sql.Types
@ -685,8 +688,10 @@ public interface JdbcOperations {
* only the argument value but also the SQL type and optionally the scale * only the argument value but also the SQL type and optionally the scale
* @param requiredType the type that the result object is expected to match * @param requiredType the type that the result object is expected to match
* @return the result object of the required type, or {@code null} in case of SQL NULL * @return the result object of the required type, or {@code null} in case of SQL NULL
* @throws IncorrectResultSizeDataAccessException if the query does not return * @throws org.springframework.dao.IncorrectResultSizeDataAccessException
* exactly one row, or does not return exactly one column in that row * if the query does not return exactly one row
* @throws org.springframework.jdbc.IncorrectResultSetColumnCountException
* if the query does not return a row containing a single column
* @throws DataAccessException if the query fails * @throws DataAccessException if the query fails
* @see #queryForObject(String, Class) * @see #queryForObject(String, Class)
* @deprecated as of 5.3, in favor of {@link #queryForObject(String, Class, Object...)} * @deprecated as of 5.3, in favor of {@link #queryForObject(String, Class, Object...)}
@ -707,8 +712,10 @@ public interface JdbcOperations {
* may also contain {@link SqlParameterValue} objects which indicate not * may also contain {@link SqlParameterValue} objects which indicate not
* only the argument value but also the SQL type and optionally the scale * only the argument value but also the SQL type and optionally the scale
* @return the result object of the required type, or {@code null} in case of SQL NULL * @return the result object of the required type, or {@code null} in case of SQL NULL
* @throws IncorrectResultSizeDataAccessException if the query does not return * @throws org.springframework.dao.IncorrectResultSizeDataAccessException
* exactly one row, or does not return exactly one column in that row * if the query does not return exactly one row
* @throws org.springframework.jdbc.IncorrectResultSetColumnCountException
* if the query does not return a row containing a single column
* @throws DataAccessException if the query fails * @throws DataAccessException if the query fails
* @since 3.0.1 * @since 3.0.1
* @see #queryForObject(String, Class) * @see #queryForObject(String, Class)
@ -726,8 +733,8 @@ public interface JdbcOperations {
* @param argTypes the SQL types of the arguments * @param argTypes the SQL types of the arguments
* (constants from {@code java.sql.Types}) * (constants from {@code java.sql.Types})
* @return the result Map (one entry per column, with column name as key) * @return the result Map (one entry per column, with column name as key)
* @throws IncorrectResultSizeDataAccessException if the query does not * @throws org.springframework.dao.IncorrectResultSizeDataAccessException
* return exactly one row * if the query does not return exactly one row
* @throws DataAccessException if the query fails * @throws DataAccessException if the query fails
* @see #queryForMap(String) * @see #queryForMap(String)
* @see ColumnMapRowMapper * @see ColumnMapRowMapper
@ -750,8 +757,8 @@ public interface JdbcOperations {
* only the argument value but also the SQL type and optionally the scale * only the argument value but also the SQL type and optionally the scale
* @return the result Map (one entry for each column, using the * @return the result Map (one entry for each column, using the
* column name as the key) * column name as the key)
* @throws IncorrectResultSizeDataAccessException if the query does not * @throws org.springframework.dao.IncorrectResultSizeDataAccessException
* return exactly one row * if the query does not return exactly one row
* @throws DataAccessException if the query fails * @throws DataAccessException if the query fails
* @see #queryForMap(String) * @see #queryForMap(String)
* @see ColumnMapRowMapper * @see ColumnMapRowMapper

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

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2020 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -268,8 +268,7 @@ public interface NamedParameterJdbcOperations {
* @return the single mapped object (may be {@code null} if the given * @return the single mapped object (may be {@code null} if the given
* {@link RowMapper} returned {@code} null) * {@link RowMapper} returned {@code} null)
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException * @throws org.springframework.dao.IncorrectResultSizeDataAccessException
* if the query does not return exactly one row, or does not return exactly * if the query does not return exactly one row
* one column in that row
* @throws DataAccessException if the query fails * @throws DataAccessException if the query fails
*/ */
@Nullable @Nullable
@ -287,8 +286,7 @@ public interface NamedParameterJdbcOperations {
* @return the single mapped object (may be {@code null} if the given * @return the single mapped object (may be {@code null} if the given
* {@link RowMapper} returned {@code} null) * {@link RowMapper} returned {@code} null)
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException * @throws org.springframework.dao.IncorrectResultSizeDataAccessException
* if the query does not return exactly one row, or does not return exactly * if the query does not return exactly one row
* one column in that row
* @throws DataAccessException if the query fails * @throws DataAccessException if the query fails
*/ */
@Nullable @Nullable
@ -305,10 +303,12 @@ public interface NamedParameterJdbcOperations {
* @param requiredType the type that the result object is expected to match * @param requiredType the type that the result object is expected to match
* @return the result object of the required type, or {@code null} in case of SQL NULL * @return the result object of the required type, or {@code null} in case of SQL NULL
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException * @throws org.springframework.dao.IncorrectResultSizeDataAccessException
* if the query does not return exactly one row, or does not return exactly * if the query does not return exactly one row
* one column in that row * @throws org.springframework.jdbc.IncorrectResultSetColumnCountException
* if the query does not return a row containing a single column
* @throws DataAccessException if the query fails * @throws DataAccessException if the query fails
* @see org.springframework.jdbc.core.JdbcTemplate#queryForObject(String, Class) * @see org.springframework.jdbc.core.JdbcTemplate#queryForObject(String, Class)
* @see org.springframework.jdbc.core.SingleColumnRowMapper
*/ */
@Nullable @Nullable
<T> T queryForObject(String sql, SqlParameterSource paramSource, Class<T> requiredType) <T> T queryForObject(String sql, SqlParameterSource paramSource, Class<T> requiredType)
@ -325,8 +325,9 @@ public interface NamedParameterJdbcOperations {
* @param requiredType the type that the result object is expected to match * @param requiredType the type that the result object is expected to match
* @return the result object of the required type, or {@code null} in case of SQL NULL * @return the result object of the required type, or {@code null} in case of SQL NULL
* @throws org.springframework.dao.IncorrectResultSizeDataAccessException * @throws org.springframework.dao.IncorrectResultSizeDataAccessException
* if the query does not return exactly one row, or does not return exactly * if the query does not return exactly one row
* one column in that row * @throws org.springframework.jdbc.IncorrectResultSetColumnCountException
* if the query does not return a row containing a single column
* @throws DataAccessException if the query fails * @throws DataAccessException if the query fails
* @see org.springframework.jdbc.core.JdbcTemplate#queryForObject(String, Class) * @see org.springframework.jdbc.core.JdbcTemplate#queryForObject(String, Class)
*/ */

Loading…
Cancel
Save