Switch to JSpecify annotations

This commit updates the whole Spring Framework codebase to use JSpecify
annotations instead of Spring null-safety annotations with JSR 305
semantics.

JSpecify provides signficant enhancements such as properly defined
specifications, a canonical dependency with no split-package issue,
better tooling, better Kotlin integration and the capability to specify
generic type, array and varargs element null-safety. Generic type
null-safety is not defined by this commit yet and will be specified
later.

A key difference is that Spring null-safety annotations, following
JSR 305 semantics, apply to fields, parameters and return values,
while JSpecify annotations apply to type usages. That's why this
commit moves nullability annotations closer to the type for fields
and return values.

See gh-28797
This commit is contained in:
Sébastien Deleuze
2024-12-03 15:22:37 +01:00
parent fcb8aed03f
commit bc5d771a06
3459 changed files with 14118 additions and 22059 deletions

View File

@@ -18,8 +18,9 @@ package org.springframework.jdbc;
import java.sql.SQLException;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.InvalidDataAccessResourceUsageException;
import org.springframework.lang.Nullable;
/**
* Exception thrown when SQL specified is invalid. Such exceptions always have
@@ -53,8 +54,7 @@ public class BadSqlGrammarException extends InvalidDataAccessResourceUsageExcept
/**
* Return the wrapped SQLException.
*/
@Nullable
public SQLException getSQLException() {
public @Nullable SQLException getSQLException() {
return (SQLException) getCause();
}

View File

@@ -18,8 +18,9 @@ package org.springframework.jdbc;
import java.sql.SQLException;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.lang.Nullable;
/**
* Fatal exception thrown when we can't connect to an RDBMS using JDBC.

View File

@@ -18,8 +18,9 @@ package org.springframework.jdbc;
import java.sql.SQLException;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.InvalidDataAccessResourceUsageException;
import org.springframework.lang.Nullable;
/**
* Exception thrown when a ResultSet has been accessed in an invalid fashion.
@@ -36,8 +37,7 @@ import org.springframework.lang.Nullable;
@SuppressWarnings("serial")
public class InvalidResultSetAccessException extends InvalidDataAccessResourceUsageException {
@Nullable
private final String sql;
private final @Nullable String sql;
/**
@@ -64,8 +64,7 @@ public class InvalidResultSetAccessException extends InvalidDataAccessResourceUs
/**
* Return the wrapped SQLException.
*/
@Nullable
public SQLException getSQLException() {
public @Nullable SQLException getSQLException() {
return (SQLException) getCause();
}
@@ -73,8 +72,7 @@ public class InvalidResultSetAccessException extends InvalidDataAccessResourceUs
* Return the SQL that caused the problem.
* @return the offending SQL, if known
*/
@Nullable
public String getSql() {
public @Nullable String getSql() {
return this.sql;
}

View File

@@ -18,8 +18,9 @@ package org.springframework.jdbc;
import java.sql.SQLWarning;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.UncategorizedDataAccessException;
import org.springframework.lang.Nullable;
/**
* Exception thrown when we're not ignoring {@link java.sql.SQLWarning SQLWarnings}.
@@ -50,8 +51,7 @@ public class SQLWarningException extends UncategorizedDataAccessException {
* Return the underlying {@link SQLWarning}.
* @since 5.3.29
*/
@Nullable
public SQLWarning getSQLWarning() {
public @Nullable SQLWarning getSQLWarning() {
return (SQLWarning) getCause();
}
@@ -60,8 +60,7 @@ public class SQLWarningException extends UncategorizedDataAccessException {
* @deprecated as of 5.3.29, in favor of {@link #getSQLWarning()}
*/
@Deprecated(since = "5.3.29")
@Nullable
public SQLWarning SQLWarning() {
public @Nullable SQLWarning SQLWarning() {
return getSQLWarning();
}

View File

@@ -18,8 +18,9 @@ package org.springframework.jdbc;
import java.sql.SQLException;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.UncategorizedDataAccessException;
import org.springframework.lang.Nullable;
/**
* Exception thrown when we can't classify an SQLException into
@@ -32,8 +33,7 @@ import org.springframework.lang.Nullable;
public class UncategorizedSQLException extends UncategorizedDataAccessException {
/** SQL that led to the problem. */
@Nullable
private final String sql;
private final @Nullable String sql;
/**
@@ -53,16 +53,14 @@ public class UncategorizedSQLException extends UncategorizedDataAccessException
/**
* Return the underlying SQLException.
*/
@Nullable
public SQLException getSQLException() {
public @Nullable SQLException getSQLException() {
return (SQLException) getCause();
}
/**
* Return the SQL that led to the problem (if known).
*/
@Nullable
public String getSql() {
public @Nullable String getSql() {
return this.sql;
}

View File

@@ -18,6 +18,7 @@ package org.springframework.jdbc.config;
import java.util.List;
import org.jspecify.annotations.Nullable;
import org.w3c.dom.Element;
import org.springframework.beans.BeanMetadataElement;
@@ -27,7 +28,6 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.ManagedList;
import org.springframework.jdbc.datasource.init.CompositeDatabasePopulator;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
@@ -48,8 +48,7 @@ abstract class DatabasePopulatorConfigUtils {
}
}
@Nullable
private static BeanDefinition createDatabasePopulator(Element element, List<Element> scripts, String execution) {
private static @Nullable BeanDefinition createDatabasePopulator(Element element, List<Element> scripts, String execution) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(CompositeDatabasePopulator.class);
boolean ignoreFailedDrops = element.getAttribute("ignore-failures").equals("DROPS");
@@ -90,8 +89,7 @@ abstract class DatabasePopulatorConfigUtils {
return builder.getBeanDefinition();
}
@Nullable
private static String getSeparator(Element element, Element scriptElement) {
private static @Nullable String getSeparator(Element element, Element scriptElement) {
String scriptSeparator = scriptElement.getAttribute("separator");
if (StringUtils.hasLength(scriptSeparator)) {
return scriptSeparator;

View File

@@ -1,9 +1,7 @@
/**
* Defines the Spring JDBC configuration namespace.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.jdbc.config;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -19,7 +19,7 @@ package org.springframework.jdbc.core;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Simple adapter for {@link PreparedStatementSetter} that applies a given array
@@ -30,15 +30,14 @@ import org.springframework.lang.Nullable;
*/
public class ArgumentPreparedStatementSetter implements PreparedStatementSetter, ParameterDisposer {
@Nullable
private final Object[] args;
private final @Nullable Object @Nullable [] args;
/**
* Create a new {@code ArgumentPreparedStatementSetter} for the given arguments.
* @param args the arguments to set
*/
public ArgumentPreparedStatementSetter(@Nullable Object[] args) {
public ArgumentPreparedStatementSetter(@Nullable Object @Nullable [] args) {
this.args = args;
}

View File

@@ -21,8 +21,9 @@ import java.sql.SQLException;
import java.sql.Types;
import java.util.Collection;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.lang.Nullable;
/**
* Simple adapter for {@link PreparedStatementSetter} that applies the given
@@ -33,11 +34,9 @@ import org.springframework.lang.Nullable;
*/
public class ArgumentTypePreparedStatementSetter implements PreparedStatementSetter, ParameterDisposer {
@Nullable
private final Object[] args;
private final @Nullable Object @Nullable [] args;
@Nullable
private final int[] argTypes;
private final int @Nullable [] argTypes;
/**
@@ -47,7 +46,7 @@ public class ArgumentTypePreparedStatementSetter implements PreparedStatementSet
* @param argTypes the corresponding SQL types of the arguments
*/
@SuppressWarnings("NullAway")
public ArgumentTypePreparedStatementSetter(@Nullable Object[] args, @Nullable int[] argTypes) {
public ArgumentTypePreparedStatementSetter(@Nullable Object @Nullable [] args, int @Nullable [] argTypes) {
if ((args != null && argTypes == null) || (args == null && argTypes != null) ||
(args != null && args.length != argTypes.length)) {
throw new InvalidDataAccessApiUsageException("args and argTypes parameters must match");

View File

@@ -28,6 +28,7 @@ import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeanWrapper;
@@ -40,7 +41,6 @@ import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
@@ -95,8 +95,7 @@ public class BeanPropertyRowMapper<T> implements RowMapper<T> {
protected final Log logger = LogFactory.getLog(getClass());
/** The class we are mapping to. */
@Nullable
private Class<T> mappedClass;
private @Nullable Class<T> mappedClass;
/** Whether we're strictly validating. */
private boolean checkFullyPopulated = false;
@@ -109,16 +108,13 @@ public class BeanPropertyRowMapper<T> implements RowMapper<T> {
private boolean primitivesDefaultedForNullValue = false;
/** ConversionService for binding JDBC values to bean properties. */
@Nullable
private ConversionService conversionService = DefaultConversionService.getSharedInstance();
private @Nullable ConversionService conversionService = DefaultConversionService.getSharedInstance();
/** Map of the properties we provide mapping for. */
@Nullable
private Map<String, PropertyDescriptor> mappedProperties;
private @Nullable Map<String, PropertyDescriptor> mappedProperties;
/** Set of bean property names we provide mapping for. */
@Nullable
private Set<String> mappedPropertyNames;
private @Nullable Set<String> mappedPropertyNames;
/**
@@ -168,8 +164,7 @@ public class BeanPropertyRowMapper<T> implements RowMapper<T> {
/**
* Get the class that we are mapping to.
*/
@Nullable
public final Class<T> getMappedClass() {
public final @Nullable Class<T> getMappedClass() {
return this.mappedClass;
}
@@ -233,8 +228,7 @@ public class BeanPropertyRowMapper<T> implements RowMapper<T> {
* or {@code null} if none.
* @since 4.3
*/
@Nullable
public ConversionService getConversionService() {
public @Nullable ConversionService getConversionService() {
return this.conversionService;
}
@@ -426,8 +420,7 @@ public class BeanPropertyRowMapper<T> implements RowMapper<T> {
* @throws SQLException in case of extraction failure
* @see #getColumnValue(ResultSet, int, Class)
*/
@Nullable
protected Object getColumnValue(ResultSet rs, int index, PropertyDescriptor pd) throws SQLException {
protected @Nullable Object getColumnValue(ResultSet rs, int index, PropertyDescriptor pd) throws SQLException {
return JdbcUtils.getResultSetValue(rs, index, pd.getPropertyType());
}
@@ -445,8 +438,7 @@ public class BeanPropertyRowMapper<T> implements RowMapper<T> {
* @since 5.3
* @see org.springframework.jdbc.support.JdbcUtils#getResultSetValue(java.sql.ResultSet, int, Class)
*/
@Nullable
protected Object getColumnValue(ResultSet rs, int index, Class<?> paramType) throws SQLException {
protected @Nullable Object getColumnValue(ResultSet rs, int index, Class<?> paramType) throws SQLException {
return JdbcUtils.getResultSetValue(rs, index, paramType);
}

View File

@@ -19,8 +19,9 @@ package org.springframework.jdbc.core;
import java.sql.CallableStatement;
import java.sql.SQLException;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.DataAccessException;
import org.springframework.lang.Nullable;
/**
* Generic callback interface for code that operates on a CallableStatement.
@@ -74,7 +75,6 @@ public interface CallableStatementCallback<T> {
* into a DataAccessException by an SQLExceptionTranslator
* @throws DataAccessException in case of custom exceptions
*/
@Nullable
T doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException;
@Nullable T doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException;
}

View File

@@ -25,8 +25,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.lang.Nullable;
/**
* Helper class that efficiently creates multiple {@link CallableStatementCreator}
@@ -130,11 +131,9 @@ public class CallableStatementCreatorFactory {
*/
private class CallableStatementCreatorImpl implements CallableStatementCreator, SqlProvider, ParameterDisposer {
@Nullable
private ParameterMapper inParameterMapper;
private @Nullable ParameterMapper inParameterMapper;
@Nullable
private Map<String, ?> inParameters;
private @Nullable Map<String, ?> inParameters;
/**
* Create a new CallableStatementCreatorImpl.

View File

@@ -21,8 +21,9 @@ import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.Map;
import org.jspecify.annotations.Nullable;
import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.LinkedCaseInsensitiveMap;
/**
@@ -90,8 +91,7 @@ public class ColumnMapRowMapper implements RowMapper<Map<String, Object>> {
* @return the Object returned
* @see org.springframework.jdbc.support.JdbcUtils#getResultSetValue
*/
@Nullable
protected Object getColumnValue(ResultSet rs, int index) throws SQLException {
protected @Nullable Object getColumnValue(ResultSet rs, int index) throws SQLException {
return JdbcUtils.getResultSetValue(rs, index);
}

View File

@@ -19,8 +19,9 @@ package org.springframework.jdbc.core;
import java.sql.Connection;
import java.sql.SQLException;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.DataAccessException;
import org.springframework.lang.Nullable;
/**
* Generic callback interface for code that operates on a JDBC Connection.
@@ -64,7 +65,6 @@ public interface ConnectionCallback<T> {
* @see JdbcTemplate#queryForObject(String, Class)
* @see JdbcTemplate#queryForRowSet(String)
*/
@Nullable
T doInConnection(Connection con) throws SQLException, DataAccessException;
@Nullable T doInConnection(Connection con) throws SQLException, DataAccessException;
}

View File

@@ -20,12 +20,13 @@ import java.lang.reflect.Constructor;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.TypeConverter;
import org.springframework.core.MethodParameter;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -61,14 +62,11 @@ import org.springframework.util.Assert;
*/
public class DataClassRowMapper<T> extends BeanPropertyRowMapper<T> {
@Nullable
private Constructor<T> mappedConstructor;
private @Nullable Constructor<T> mappedConstructor;
@Nullable
private String[] constructorParameterNames;
private String @Nullable [] constructorParameterNames;
@Nullable
private TypeDescriptor[] constructorParameterTypes;
private TypeDescriptor @Nullable [] constructorParameterTypes;
/**

View File

@@ -21,10 +21,11 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.lang.Nullable;
/**
* Interface specifying a basic set of JDBC operations.
@@ -67,8 +68,7 @@ public interface JdbcOperations {
* @return a result object returned by the action, or {@code null} if none
* @throws DataAccessException if there is any problem
*/
@Nullable
<T> T execute(ConnectionCallback<T> action) throws DataAccessException;
<T> @Nullable T execute(ConnectionCallback<T> action) throws DataAccessException;
//-------------------------------------------------------------------------
@@ -87,8 +87,7 @@ public interface JdbcOperations {
* @return a result object returned by the action, or {@code null} if none
* @throws DataAccessException if there is any problem
*/
@Nullable
<T> T execute(StatementCallback<T> action) throws DataAccessException;
<T> @Nullable T execute(StatementCallback<T> action) throws DataAccessException;
/**
* Issue a single SQL execute, typically a DDL statement.
@@ -109,8 +108,7 @@ public interface JdbcOperations {
* @throws DataAccessException if there is any problem executing the query
* @see #query(String, ResultSetExtractor, Object...)
*/
@Nullable
<T> T query(String sql, ResultSetExtractor<T> rse) throws DataAccessException;
<T> @Nullable T query(String sql, ResultSetExtractor<T> rse) throws DataAccessException;
/**
* Execute a query given static SQL, reading the ResultSet on a per-row
@@ -171,8 +169,7 @@ public interface JdbcOperations {
* @throws DataAccessException if there is any problem executing the query
* @see #queryForObject(String, RowMapper, Object...)
*/
@Nullable
<T> T queryForObject(String sql, RowMapper<T> rowMapper) throws DataAccessException;
<T> @Nullable T queryForObject(String sql, RowMapper<T> rowMapper) throws DataAccessException;
/**
* Execute a query for a result object, given static SQL.
@@ -193,8 +190,7 @@ public interface JdbcOperations {
* @throws DataAccessException if there is any problem executing the query
* @see #queryForObject(String, Class, Object...)
*/
@Nullable
<T> T queryForObject(String sql, Class<T> requiredType) throws DataAccessException;
<T> @Nullable T queryForObject(String sql, Class<T> requiredType) throws DataAccessException;
/**
* Execute a query for a result map, given static SQL.
@@ -303,8 +299,7 @@ public interface JdbcOperations {
* @return a result object returned by the action, or {@code null} if none
* @throws DataAccessException if there is any problem
*/
@Nullable
<T> T execute(PreparedStatementCreator psc, PreparedStatementCallback<T> action) throws DataAccessException;
<T> @Nullable T execute(PreparedStatementCreator psc, PreparedStatementCallback<T> action) throws DataAccessException;
/**
* Execute a JDBC data access operation, implemented as callback action
@@ -319,8 +314,7 @@ public interface JdbcOperations {
* @return a result object returned by the action, or {@code null} if none
* @throws DataAccessException if there is any problem
*/
@Nullable
<T> T execute(String sql, PreparedStatementCallback<T> action) throws DataAccessException;
<T> @Nullable T execute(String sql, PreparedStatementCallback<T> action) throws DataAccessException;
/**
* Query using a prepared statement, reading the ResultSet with a ResultSetExtractor.
@@ -332,8 +326,7 @@ public interface JdbcOperations {
* @throws DataAccessException if there is any problem
* @see PreparedStatementCreatorFactory
*/
@Nullable
<T> T query(PreparedStatementCreator psc, ResultSetExtractor<T> rse) throws DataAccessException;
<T> @Nullable T query(PreparedStatementCreator psc, ResultSetExtractor<T> rse) throws DataAccessException;
/**
* Query using a prepared statement, reading the ResultSet with a ResultSetExtractor.
@@ -346,8 +339,7 @@ public interface JdbcOperations {
* @return an arbitrary result object, as returned by the ResultSetExtractor
* @throws DataAccessException if there is any problem
*/
@Nullable
<T> T query(String sql, @Nullable PreparedStatementSetter pss, ResultSetExtractor<T> rse)
<T> @Nullable T query(String sql, @Nullable PreparedStatementSetter pss, ResultSetExtractor<T> rse)
throws DataAccessException;
/**
@@ -362,8 +354,7 @@ public interface JdbcOperations {
* @throws DataAccessException if the query fails
* @see java.sql.Types
*/
@Nullable
<T> T query(String sql, Object[] args, int[] argTypes, ResultSetExtractor<T> rse) throws DataAccessException;
<T> @Nullable T query(String sql, @Nullable Object @Nullable [] args, int[] argTypes, ResultSetExtractor<T> rse) throws DataAccessException;
/**
* Query given SQL to create a prepared statement from SQL and a list of arguments
@@ -379,8 +370,7 @@ public interface JdbcOperations {
* @deprecated as of 5.3, in favor of {@link #query(String, ResultSetExtractor, Object...)}
*/
@Deprecated
@Nullable
<T> T query(String sql, @Nullable Object[] args, ResultSetExtractor<T> rse) throws DataAccessException;
<T> @Nullable T query(String sql, @Nullable Object @Nullable [] args, ResultSetExtractor<T> rse) throws DataAccessException;
/**
* Query given SQL to create a prepared statement from SQL and a list of arguments
@@ -395,8 +385,7 @@ public interface JdbcOperations {
* @throws DataAccessException if the query fails
* @since 3.0.1
*/
@Nullable
<T> T query(String sql, ResultSetExtractor<T> rse, @Nullable Object... args) throws DataAccessException;
<T> @Nullable T query(String sql, ResultSetExtractor<T> rse, @Nullable Object @Nullable ... args) throws DataAccessException;
/**
* Query using a prepared statement, reading the ResultSet on a per-row basis
@@ -436,7 +425,7 @@ public interface JdbcOperations {
* @throws DataAccessException if the query fails
* @see java.sql.Types
*/
void query(String sql, Object[] args, int[] argTypes, RowCallbackHandler rch) throws DataAccessException;
void query(String sql, @Nullable Object @Nullable [] args, int[] argTypes, RowCallbackHandler rch) throws DataAccessException;
/**
* Query given SQL to create a prepared statement from SQL and a list of
@@ -452,7 +441,7 @@ public interface JdbcOperations {
* @deprecated as of 5.3, in favor of {@link #query(String, RowCallbackHandler, Object...)}
*/
@Deprecated
void query(String sql, @Nullable Object[] args, RowCallbackHandler rch) throws DataAccessException;
void query(String sql, @Nullable Object @Nullable [] args, RowCallbackHandler rch) throws DataAccessException;
/**
* Query given SQL to create a prepared statement from SQL and a list of
@@ -467,7 +456,7 @@ public interface JdbcOperations {
* @throws DataAccessException if the query fails
* @since 3.0.1
*/
void query(String sql, RowCallbackHandler rch, @Nullable Object... args) throws DataAccessException;
void query(String sql, RowCallbackHandler rch, @Nullable Object @Nullable ... args) throws DataAccessException;
/**
* Query using a prepared statement, mapping each row to a result object
@@ -511,7 +500,7 @@ public interface JdbcOperations {
* @throws DataAccessException if the query fails
* @see java.sql.Types
*/
<T> List<T> query(String sql, Object[] args, int[] argTypes, RowMapper<T> rowMapper) throws DataAccessException;
<T> List<T> query(String sql, @Nullable Object @Nullable [] args, int[] argTypes, RowMapper<T> rowMapper) throws DataAccessException;
/**
* Query given SQL to create a prepared statement from SQL and a list of
@@ -528,7 +517,7 @@ public interface JdbcOperations {
* @deprecated as of 5.3, in favor of {@link #query(String, RowMapper, Object...)}
*/
@Deprecated
<T> List<T> query(String sql, @Nullable Object[] args, RowMapper<T> rowMapper) throws DataAccessException;
<T> List<T> query(String sql, @Nullable Object @Nullable [] args, RowMapper<T> rowMapper) throws DataAccessException;
/**
* Query given SQL to create a prepared statement from SQL and a list of
@@ -544,7 +533,7 @@ public interface JdbcOperations {
* @throws DataAccessException if the query fails
* @since 3.0.1
*/
<T> List<T> query(String sql, RowMapper<T> rowMapper, @Nullable Object... args) throws DataAccessException;
<T> List<T> query(String sql, RowMapper<T> rowMapper, @Nullable Object @Nullable ... args) throws DataAccessException;
/**
* Query using a prepared statement, mapping each row to a result object
@@ -595,7 +584,7 @@ public interface JdbcOperations {
* @throws DataAccessException if the query fails
* @since 5.3
*/
<T> Stream<T> queryForStream(String sql, RowMapper<T> rowMapper, @Nullable Object... args)
<T> Stream<T> queryForStream(String sql, RowMapper<T> rowMapper, @Nullable Object @Nullable ... args)
throws DataAccessException;
/**
@@ -614,8 +603,7 @@ public interface JdbcOperations {
* if the query does not return exactly one row
* @throws DataAccessException if the query fails
*/
@Nullable
<T> T queryForObject(String sql, Object[] args, int[] argTypes, RowMapper<T> rowMapper)
<T> @Nullable T queryForObject(String sql, @Nullable Object @Nullable [] args, int[] argTypes, RowMapper<T> rowMapper)
throws DataAccessException;
/**
@@ -636,8 +624,7 @@ public interface JdbcOperations {
* @deprecated as of 5.3, in favor of {@link #queryForObject(String, RowMapper, Object...)}
*/
@Deprecated
@Nullable
<T> T queryForObject(String sql, @Nullable Object[] args, RowMapper<T> rowMapper) throws DataAccessException;
<T> @Nullable T queryForObject(String sql, @Nullable Object @Nullable [] args, RowMapper<T> rowMapper) throws DataAccessException;
/**
* Query given SQL to create a prepared statement from SQL and a list
@@ -656,8 +643,7 @@ public interface JdbcOperations {
* @throws DataAccessException if the query fails
* @since 3.0.1
*/
@Nullable
<T> T queryForObject(String sql, RowMapper<T> rowMapper, @Nullable Object... args) throws DataAccessException;
<T> @Nullable T queryForObject(String sql, RowMapper<T> rowMapper, @Nullable Object @Nullable ... args) throws DataAccessException;
/**
* Query given SQL to create a prepared statement from SQL and a list of
@@ -678,8 +664,7 @@ public interface JdbcOperations {
* @see #queryForObject(String, Class)
* @see java.sql.Types
*/
@Nullable
<T> T queryForObject(String sql, Object[] args, int[] argTypes, Class<T> requiredType)
<T> @Nullable T queryForObject(String sql, @Nullable Object @Nullable [] args, int[] argTypes, Class<T> requiredType)
throws DataAccessException;
/**
@@ -703,8 +688,7 @@ public interface JdbcOperations {
* @deprecated as of 5.3, in favor of {@link #queryForObject(String, Class, Object...)}
*/
@Deprecated
@Nullable
<T> T queryForObject(String sql, @Nullable Object[] args, Class<T> requiredType) throws DataAccessException;
<T> @Nullable T queryForObject(String sql, @Nullable Object @Nullable [] args, Class<T> requiredType) throws DataAccessException;
/**
* Query given SQL to create a prepared statement from SQL and a list of
@@ -726,8 +710,7 @@ public interface JdbcOperations {
* @since 3.0.1
* @see #queryForObject(String, Class)
*/
@Nullable
<T> T queryForObject(String sql, Class<T> requiredType, @Nullable Object... args) throws DataAccessException;
<T> @Nullable T queryForObject(String sql, Class<T> requiredType, @Nullable Object @Nullable ... args) throws DataAccessException;
/**
* Query given SQL to create a prepared statement from SQL and a list of
@@ -746,7 +729,7 @@ public interface JdbcOperations {
* @see ColumnMapRowMapper
* @see java.sql.Types
*/
Map<String, Object> queryForMap(String sql, Object[] args, int[] argTypes) throws DataAccessException;
Map<String, Object> queryForMap(String sql, @Nullable Object @Nullable [] args, int[] argTypes) throws DataAccessException;
/**
* Query given SQL to create a prepared statement from SQL and a list of
@@ -769,7 +752,7 @@ public interface JdbcOperations {
* @see #queryForMap(String)
* @see ColumnMapRowMapper
*/
Map<String, Object> queryForMap(String sql, @Nullable Object... args) throws DataAccessException;
Map<String, Object> queryForMap(String sql, @Nullable Object @Nullable ... args) throws DataAccessException;
/**
* Query given SQL to create a prepared statement from SQL and a list of
@@ -787,7 +770,7 @@ public interface JdbcOperations {
* @see #queryForList(String, Class)
* @see SingleColumnRowMapper
*/
<T> List<T> queryForList(String sql, Object[] args, int[] argTypes, Class<T> elementType)
<T> List<T> queryForList(String sql, @Nullable Object @Nullable [] args, int[] argTypes, Class<T> elementType)
throws DataAccessException;
/**
@@ -809,7 +792,7 @@ public interface JdbcOperations {
* @deprecated as of 5.3, in favor of {@link #queryForList(String, Class, Object...)}
*/
@Deprecated
<T> List<T> queryForList(String sql, @Nullable Object[] args, Class<T> elementType) throws DataAccessException;
<T> List<T> queryForList(String sql, @Nullable Object @Nullable [] args, Class<T> elementType) throws DataAccessException;
/**
* Query given SQL to create a prepared statement from SQL and a list of
@@ -829,7 +812,7 @@ public interface JdbcOperations {
* @see #queryForList(String, Class)
* @see SingleColumnRowMapper
*/
<T> List<T> queryForList(String sql, Class<T> elementType, @Nullable Object... args) throws DataAccessException;
<T> List<T> queryForList(String sql, Class<T> elementType, @Nullable Object @Nullable ... args) throws DataAccessException;
/**
* Query given SQL to create a prepared statement from SQL and a list of
@@ -847,7 +830,7 @@ public interface JdbcOperations {
* @see #queryForList(String)
* @see java.sql.Types
*/
List<Map<String, Object>> queryForList(String sql, Object[] args, int[] argTypes) throws DataAccessException;
List<Map<String, Object>> queryForList(String sql, @Nullable Object @Nullable [] args, int[] argTypes) throws DataAccessException;
/**
* Query given SQL to create a prepared statement from SQL and a list of
@@ -865,7 +848,7 @@ public interface JdbcOperations {
* @throws DataAccessException if the query fails
* @see #queryForList(String)
*/
List<Map<String, Object>> queryForList(String sql, @Nullable Object... args) throws DataAccessException;
List<Map<String, Object>> queryForList(String sql, @Nullable Object @Nullable ... args) throws DataAccessException;
/**
* Query given SQL to create a prepared statement from SQL and a list of
@@ -887,7 +870,7 @@ public interface JdbcOperations {
* @see javax.sql.rowset.CachedRowSet
* @see java.sql.Types
*/
SqlRowSet queryForRowSet(String sql, Object[] args, int[] argTypes) throws DataAccessException;
SqlRowSet queryForRowSet(String sql, @Nullable Object @Nullable [] args, int[] argTypes) throws DataAccessException;
/**
* Query given SQL to create a prepared statement from SQL and a list of
@@ -909,7 +892,7 @@ public interface JdbcOperations {
* @see SqlRowSetResultSetExtractor
* @see javax.sql.rowset.CachedRowSet
*/
SqlRowSet queryForRowSet(String sql, @Nullable Object... args) throws DataAccessException;
SqlRowSet queryForRowSet(String sql, @Nullable Object @Nullable ... args) throws DataAccessException;
/**
* Issue a single SQL update operation (such as an insert, update or delete
@@ -965,7 +948,7 @@ public interface JdbcOperations {
* @throws DataAccessException if there is any problem issuing the update
* @see java.sql.Types
*/
int update(String sql, Object[] args, int[] argTypes) throws DataAccessException;
int update(String sql, @Nullable Object @Nullable [] args, int[] argTypes) throws DataAccessException;
/**
* Issue a single SQL update operation (such as an insert, update or delete statement)
@@ -978,7 +961,7 @@ public interface JdbcOperations {
* @return the number of rows affected
* @throws DataAccessException if there is any problem issuing the update
*/
int update(String sql, @Nullable Object... args) throws DataAccessException;
int update(String sql, @Nullable Object @Nullable ... args) throws DataAccessException;
/**
* Issue multiple update statements on a single PreparedStatement,
@@ -1081,8 +1064,7 @@ public interface JdbcOperations {
* @return a result object returned by the action, or {@code null} if none
* @throws DataAccessException if there is any problem
*/
@Nullable
<T> T execute(CallableStatementCreator csc, CallableStatementCallback<T> action) throws DataAccessException;
<T> @Nullable T execute(CallableStatementCreator csc, CallableStatementCallback<T> action) throws DataAccessException;
/**
* Execute a JDBC data access operation, implemented as callback action
@@ -1097,8 +1079,7 @@ public interface JdbcOperations {
* @return a result object returned by the action, or {@code null} if none
* @throws DataAccessException if there is any problem
*/
@Nullable
<T> T execute(String callString, CallableStatementCallback<T> action) throws DataAccessException;
<T> @Nullable T execute(String callString, CallableStatementCallback<T> action) throws DataAccessException;
/**
* Execute an SQL call using a CallableStatementCreator to provide SQL and

View File

@@ -41,6 +41,8 @@ import java.util.stream.StreamSupport;
import javax.sql.DataSource;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.dao.support.DataAccessUtils;
@@ -53,7 +55,6 @@ import org.springframework.jdbc.support.JdbcAccessor;
import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedCaseInsensitiveMap;
@@ -335,8 +336,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
//-------------------------------------------------------------------------
@Override
@Nullable
public <T> T execute(ConnectionCallback<T> action) throws DataAccessException {
public <T> @Nullable T execute(ConnectionCallback<T> action) throws DataAccessException {
Assert.notNull(action, "Callback object must not be null");
Connection con = DataSourceUtils.getConnection(obtainDataSource());
@@ -381,8 +381,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
// Methods dealing with static SQL (java.sql.Statement)
//-------------------------------------------------------------------------
@Nullable
private <T> T execute(StatementCallback<T> action, boolean closeResources) throws DataAccessException {
private <T> @Nullable T execute(StatementCallback<T> action, boolean closeResources) throws DataAccessException {
Assert.notNull(action, "Callback object must not be null");
Connection con = DataSourceUtils.getConnection(obtainDataSource());
@@ -416,8 +415,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
}
@Override
@Nullable
public <T> T execute(StatementCallback<T> action) throws DataAccessException {
public <T> @Nullable T execute(StatementCallback<T> action) throws DataAccessException {
return execute(action, true);
}
@@ -430,8 +428,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
// Callback to execute the statement.
class ExecuteStatementCallback implements StatementCallback<Object>, SqlProvider {
@Override
@Nullable
public Object doInStatement(Statement stmt) throws SQLException {
public @Nullable Object doInStatement(Statement stmt) throws SQLException {
stmt.execute(sql);
return null;
}
@@ -445,8 +442,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
}
@Override
@Nullable
public <T> T query(final String sql, final ResultSetExtractor<T> rse) throws DataAccessException {
public <T> @Nullable T query(final String sql, final ResultSetExtractor<T> rse) throws DataAccessException {
Assert.notNull(sql, "SQL must not be null");
Assert.notNull(rse, "ResultSetExtractor must not be null");
if (logger.isDebugEnabled()) {
@@ -456,8 +452,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
// Callback to execute the query.
class QueryStatementCallback implements StatementCallback<T>, SqlProvider {
@Override
@Nullable
public T doInStatement(Statement stmt) throws SQLException {
public @Nullable T doInStatement(Statement stmt) throws SQLException {
ResultSet rs = null;
try {
rs = stmt.executeQuery(sql);
@@ -514,15 +509,13 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
}
@Override
@Nullable
public <T> T queryForObject(String sql, RowMapper<T> rowMapper) throws DataAccessException {
public <T> @Nullable T queryForObject(String sql, RowMapper<T> rowMapper) throws DataAccessException {
List<T> results = query(sql, rowMapper);
return DataAccessUtils.nullableSingleResult(results);
}
@Override
@Nullable
public <T> T queryForObject(String sql, Class<T> requiredType) throws DataAccessException {
public <T> @Nullable T queryForObject(String sql, Class<T> requiredType) throws DataAccessException {
return queryForObject(sql, getSingleColumnRowMapper(requiredType));
}
@@ -577,8 +570,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
// Callback to execute the batch update.
class BatchUpdateStatementCallback implements StatementCallback<int[]>, SqlProvider {
@Nullable
private String currSql;
private @Nullable String currSql;
@Override
public int[] doInStatement(Statement stmt) throws SQLException, DataAccessException {
@@ -623,8 +615,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
}
@Override
@Nullable
public String getSql() {
public @Nullable String getSql() {
return this.currSql;
}
}
@@ -639,8 +630,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
// Methods dealing with prepared statements
//-------------------------------------------------------------------------
@Nullable
private <T> T execute(PreparedStatementCreator psc, PreparedStatementCallback<T> action, boolean closeResources)
private <T> @Nullable T execute(PreparedStatementCreator psc, PreparedStatementCallback<T> action, boolean closeResources)
throws DataAccessException {
Assert.notNull(psc, "PreparedStatementCreator must not be null");
@@ -688,16 +678,14 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
}
@Override
@Nullable
public <T> T execute(PreparedStatementCreator psc, PreparedStatementCallback<T> action)
public <T> @Nullable T execute(PreparedStatementCreator psc, PreparedStatementCallback<T> action)
throws DataAccessException {
return execute(psc, action, true);
}
@Override
@Nullable
public <T> T execute(String sql, PreparedStatementCallback<T> action) throws DataAccessException {
public <T> @Nullable T execute(String sql, PreparedStatementCallback<T> action) throws DataAccessException {
return execute(new SimplePreparedStatementCreator(sql), action, true);
}
@@ -712,9 +700,8 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
* @return an arbitrary result object, as returned by the ResultSetExtractor
* @throws DataAccessException if there is any problem
*/
@Nullable
public <T> T query(
PreparedStatementCreator psc, @Nullable final PreparedStatementSetter pss, final ResultSetExtractor<T> rse)
public <T> @Nullable T query(
PreparedStatementCreator psc, final @Nullable PreparedStatementSetter pss, final ResultSetExtractor<T> rse)
throws DataAccessException {
Assert.notNull(rse, "ResultSetExtractor must not be null");
@@ -722,8 +709,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
return execute(psc, new PreparedStatementCallback<>() {
@Override
@Nullable
public T doInPreparedStatement(PreparedStatement ps) throws SQLException {
public @Nullable T doInPreparedStatement(PreparedStatement ps) throws SQLException {
ResultSet rs = null;
try {
if (pss != null) {
@@ -743,33 +729,28 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
}
@Override
@Nullable
public <T> T query(PreparedStatementCreator psc, ResultSetExtractor<T> rse) throws DataAccessException {
public <T> @Nullable T query(PreparedStatementCreator psc, ResultSetExtractor<T> rse) throws DataAccessException {
return query(psc, null, rse);
}
@Override
@Nullable
public <T> T query(String sql, @Nullable PreparedStatementSetter pss, ResultSetExtractor<T> rse) throws DataAccessException {
public <T> @Nullable T query(String sql, @Nullable PreparedStatementSetter pss, ResultSetExtractor<T> rse) throws DataAccessException {
return query(new SimplePreparedStatementCreator(sql), pss, rse);
}
@Override
@Nullable
public <T> T query(String sql, Object[] args, int[] argTypes, ResultSetExtractor<T> rse) throws DataAccessException {
public <T> @Nullable T query(String sql, @Nullable Object @Nullable [] args, int[] argTypes, ResultSetExtractor<T> rse) throws DataAccessException {
return query(sql, newArgTypePreparedStatementSetter(args, argTypes), rse);
}
@Deprecated
@Override
@Nullable
public <T> T query(String sql, @Nullable Object[] args, ResultSetExtractor<T> rse) throws DataAccessException {
public <T> @Nullable T query(String sql, @Nullable Object @Nullable [] args, ResultSetExtractor<T> rse) throws DataAccessException {
return query(sql, newArgPreparedStatementSetter(args), rse);
}
@Override
@Nullable
public <T> T query(String sql, ResultSetExtractor<T> rse, @Nullable Object... args) throws DataAccessException {
public <T> @Nullable T query(String sql, ResultSetExtractor<T> rse, @Nullable Object @Nullable ... args) throws DataAccessException {
return query(sql, newArgPreparedStatementSetter(args), rse);
}
@@ -784,18 +765,18 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
}
@Override
public void query(String sql, Object[] args, int[] argTypes, RowCallbackHandler rch) throws DataAccessException {
public void query(String sql, @Nullable Object @Nullable [] args, int[] argTypes, RowCallbackHandler rch) throws DataAccessException {
query(sql, newArgTypePreparedStatementSetter(args, argTypes), rch);
}
@Deprecated
@Override
public void query(String sql, @Nullable Object[] args, RowCallbackHandler rch) throws DataAccessException {
public void query(String sql, @Nullable Object @Nullable [] args, RowCallbackHandler rch) throws DataAccessException {
query(sql, newArgPreparedStatementSetter(args), rch);
}
@Override
public void query(String sql, RowCallbackHandler rch, @Nullable Object... args) throws DataAccessException {
public void query(String sql, RowCallbackHandler rch, @Nullable Object @Nullable ... args) throws DataAccessException {
query(sql, newArgPreparedStatementSetter(args), rch);
}
@@ -810,18 +791,18 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
}
@Override
public <T> List<T> query(String sql, Object[] args, int[] argTypes, RowMapper<T> rowMapper) throws DataAccessException {
public <T> List<T> query(String sql, @Nullable Object @Nullable [] args, int[] argTypes, RowMapper<T> rowMapper) throws DataAccessException {
return result(query(sql, args, argTypes, new RowMapperResultSetExtractor<>(rowMapper)));
}
@Deprecated
@Override
public <T> List<T> query(String sql, @Nullable Object[] args, RowMapper<T> rowMapper) throws DataAccessException {
public <T> List<T> query(String sql, @Nullable Object @Nullable [] args, RowMapper<T> rowMapper) throws DataAccessException {
return result(query(sql, args, new RowMapperResultSetExtractor<>(rowMapper)));
}
@Override
public <T> List<T> query(String sql, RowMapper<T> rowMapper, @Nullable Object... args) throws DataAccessException {
public <T> List<T> query(String sql, RowMapper<T> rowMapper, @Nullable Object @Nullable ... args) throws DataAccessException {
return result(query(sql, args, new RowMapperResultSetExtractor<>(rowMapper)));
}
@@ -869,13 +850,12 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
}
@Override
public <T> Stream<T> queryForStream(String sql, RowMapper<T> rowMapper, @Nullable Object... args) throws DataAccessException {
public <T> Stream<T> queryForStream(String sql, RowMapper<T> rowMapper, @Nullable Object @Nullable ... args) throws DataAccessException {
return queryForStream(new SimplePreparedStatementCreator(sql), newArgPreparedStatementSetter(args), rowMapper);
}
@Override
@Nullable
public <T> T queryForObject(String sql, Object[] args, int[] argTypes, RowMapper<T> rowMapper)
public <T> @Nullable T queryForObject(String sql, @Nullable Object @Nullable [] args, int[] argTypes, RowMapper<T> rowMapper)
throws DataAccessException {
List<T> results = query(sql, args, argTypes, new RowMapperResultSetExtractor<>(rowMapper, 1));
@@ -884,22 +864,19 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
@Deprecated
@Override
@Nullable
public <T> T queryForObject(String sql, @Nullable Object[] args, RowMapper<T> rowMapper) throws DataAccessException {
public <T> @Nullable T queryForObject(String sql,@Nullable Object @Nullable [] args, RowMapper<T> rowMapper) throws DataAccessException {
List<T> results = query(sql, args, new RowMapperResultSetExtractor<>(rowMapper, 1));
return DataAccessUtils.nullableSingleResult(results);
}
@Override
@Nullable
public <T> T queryForObject(String sql, RowMapper<T> rowMapper, @Nullable Object... args) throws DataAccessException {
public <T> @Nullable T queryForObject(String sql, RowMapper<T> rowMapper, @Nullable Object @Nullable ... args) throws DataAccessException {
List<T> results = query(sql, args, new RowMapperResultSetExtractor<>(rowMapper, 1));
return DataAccessUtils.nullableSingleResult(results);
}
@Override
@Nullable
public <T> T queryForObject(String sql, Object[] args, int[] argTypes, Class<T> requiredType)
public <T> @Nullable T queryForObject(String sql, @Nullable Object @Nullable [] args, int[] argTypes, Class<T> requiredType)
throws DataAccessException {
return queryForObject(sql, args, argTypes, getSingleColumnRowMapper(requiredType));
@@ -907,64 +884,62 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
@Deprecated
@Override
@Nullable
public <T> T queryForObject(String sql, @Nullable Object[] args, Class<T> requiredType) throws DataAccessException {
public <T> @Nullable T queryForObject(String sql, @Nullable Object @Nullable [] args, Class<T> requiredType) throws DataAccessException {
return queryForObject(sql, args, getSingleColumnRowMapper(requiredType));
}
@Override
@Nullable
public <T> T queryForObject(String sql, Class<T> requiredType, @Nullable Object... args) throws DataAccessException {
public <T> @Nullable T queryForObject(String sql, Class<T> requiredType, @Nullable Object @Nullable ... args) throws DataAccessException {
return queryForObject(sql, args, getSingleColumnRowMapper(requiredType));
}
@Override
public Map<String, Object> queryForMap(String sql, Object[] args, int[] argTypes) throws DataAccessException {
public Map<String, Object> queryForMap(String sql, @Nullable Object @Nullable [] args, int[] argTypes) throws DataAccessException {
return result(queryForObject(sql, args, argTypes, getColumnMapRowMapper()));
}
@Override
public Map<String, Object> queryForMap(String sql, @Nullable Object... args) throws DataAccessException {
public Map<String, Object> queryForMap(String sql, @Nullable Object @Nullable ... args) throws DataAccessException {
return result(queryForObject(sql, args, getColumnMapRowMapper()));
}
@Override
public <T> List<T> queryForList(String sql, Object[] args, int[] argTypes, Class<T> elementType) throws DataAccessException {
public <T> List<T> queryForList(String sql, @Nullable Object @Nullable [] args, int[] argTypes, Class<T> elementType) throws DataAccessException {
return query(sql, args, argTypes, getSingleColumnRowMapper(elementType));
}
@Deprecated
@Override
public <T> List<T> queryForList(String sql, @Nullable Object[] args, Class<T> elementType) throws DataAccessException {
public <T> List<T> queryForList(String sql, @Nullable Object @Nullable [] args, Class<T> elementType) throws DataAccessException {
return query(sql, args, getSingleColumnRowMapper(elementType));
}
@Override
public <T> List<T> queryForList(String sql, Class<T> elementType, @Nullable Object... args) throws DataAccessException {
public <T> List<T> queryForList(String sql, Class<T> elementType, @Nullable Object @Nullable ... args) throws DataAccessException {
return query(sql, args, getSingleColumnRowMapper(elementType));
}
@Override
public List<Map<String, Object>> queryForList(String sql, Object[] args, int[] argTypes) throws DataAccessException {
public List<Map<String, Object>> queryForList(String sql, @Nullable Object @Nullable [] args, int[] argTypes) throws DataAccessException {
return query(sql, args, argTypes, getColumnMapRowMapper());
}
@Override
public List<Map<String, Object>> queryForList(String sql, @Nullable Object... args) throws DataAccessException {
public List<Map<String, Object>> queryForList(String sql, @Nullable Object @Nullable ... args) throws DataAccessException {
return query(sql, args, getColumnMapRowMapper());
}
@Override
public SqlRowSet queryForRowSet(String sql, Object[] args, int[] argTypes) throws DataAccessException {
public SqlRowSet queryForRowSet(String sql, @Nullable Object @Nullable [] args, int[] argTypes) throws DataAccessException {
return result(query(sql, args, argTypes, new SqlRowSetResultSetExtractor()));
}
@Override
public SqlRowSet queryForRowSet(String sql, @Nullable Object... args) throws DataAccessException {
public SqlRowSet queryForRowSet(String sql, @Nullable Object @Nullable ... args) throws DataAccessException {
return result(query(sql, args, new SqlRowSetResultSetExtractor()));
}
protected int update(final PreparedStatementCreator psc, @Nullable final PreparedStatementSetter pss)
protected int update(final PreparedStatementCreator psc, final @Nullable PreparedStatementSetter pss)
throws DataAccessException {
logger.debug("Executing prepared SQL update");
@@ -1017,12 +992,12 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
}
@Override
public int update(String sql, Object[] args, int[] argTypes) throws DataAccessException {
public int update(String sql, @Nullable Object @Nullable [] args, int[] argTypes) throws DataAccessException {
return update(sql, newArgTypePreparedStatementSetter(args, argTypes));
}
@Override
public int update(String sql, @Nullable Object... args) throws DataAccessException {
public int update(String sql, @Nullable Object @Nullable ... args) throws DataAccessException {
return update(sql, newArgPreparedStatementSetter(args));
}
@@ -1153,8 +1128,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
//-------------------------------------------------------------------------
@Override
@Nullable
public <T> T execute(CallableStatementCreator csc, CallableStatementCallback<T> action)
public <T> @Nullable T execute(CallableStatementCreator csc, CallableStatementCallback<T> action)
throws DataAccessException {
Assert.notNull(csc, "CallableStatementCreator must not be null");
@@ -1200,8 +1174,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
}
@Override
@Nullable
public <T> T execute(String callString, CallableStatementCallback<T> action) throws DataAccessException {
public <T> @Nullable T execute(String callString, CallableStatementCallback<T> action) throws DataAccessException {
return execute(new SimpleCallableStatementCreator(callString), action);
}
@@ -1461,7 +1434,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
* @param args object array with arguments
* @return the new PreparedStatementSetter to use
*/
protected PreparedStatementSetter newArgPreparedStatementSetter(@Nullable Object[] args) {
protected PreparedStatementSetter newArgPreparedStatementSetter(@Nullable Object @Nullable [] args) {
return new ArgumentPreparedStatementSetter(args);
}
@@ -1473,7 +1446,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
* @param argTypes int array of SQLTypes for the associated arguments
* @return the new PreparedStatementSetter to use
*/
protected PreparedStatementSetter newArgTypePreparedStatementSetter(Object[] args, int[] argTypes) {
protected PreparedStatementSetter newArgTypePreparedStatementSetter(@Nullable Object @Nullable [] args, int[] argTypes) {
return new ArgumentTypePreparedStatementSetter(args, argTypes);
}
@@ -1564,8 +1537,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
* @return the SQL string, or {@code null} if not known
* @see SqlProvider
*/
@Nullable
private static String getSql(Object obj) {
private static @Nullable String getSql(Object obj) {
return (obj instanceof SqlProvider sqlProvider ? sqlProvider.getSql() : null);
}
@@ -1662,8 +1634,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
}
@Override
@Nullable
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
public @Nullable Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
// Invocation on ConnectionProxy interface coming in...
return switch (method.getName()) {
@@ -1764,8 +1735,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
}
@Override
@Nullable
public Object extractData(ResultSet rs) throws SQLException {
public @Nullable Object extractData(ResultSet rs) throws SQLException {
while (rs.next()) {
this.rch.processRow(rs);
}
@@ -1806,8 +1776,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
}
@Override
@Nullable
public Spliterator<T> trySplit() {
public @Nullable Spliterator<T> trySplit() {
return null;
}

View File

@@ -19,8 +19,9 @@ package org.springframework.jdbc.core;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.DataAccessException;
import org.springframework.lang.Nullable;
/**
* Generic callback interface for code that operates on a PreparedStatement.
@@ -74,7 +75,6 @@ public interface PreparedStatementCallback<T> {
* @see JdbcTemplate#queryForObject(String, Object[], Class)
* @see JdbcTemplate#queryForList(String, Object[])
*/
@Nullable
T doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException;
@Nullable T doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException;
}

View File

@@ -29,8 +29,9 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.lang.Nullable;
/**
* Helper class that efficiently creates multiple {@link PreparedStatementCreator}
@@ -47,8 +48,7 @@ public class PreparedStatementCreatorFactory {
private final String sql;
/** List of SqlParameter objects (may be {@code null}). */
@Nullable
private List<SqlParameter> declaredParameters;
private @Nullable List<SqlParameter> declaredParameters;
private int resultSetType = ResultSet.TYPE_FORWARD_ONLY;
@@ -56,8 +56,7 @@ public class PreparedStatementCreatorFactory {
private boolean returnGeneratedKeys = false;
@Nullable
private String[] generatedKeysColumnNames;
private String @Nullable [] generatedKeysColumnNames;
/**
@@ -155,7 +154,7 @@ public class PreparedStatementCreatorFactory {
* Return a new PreparedStatementSetter for the given parameters.
* @param params the parameter array (may be {@code null})
*/
public PreparedStatementSetter newPreparedStatementSetter(@Nullable Object[] params) {
public PreparedStatementSetter newPreparedStatementSetter(Object @Nullable [] params) {
return new PreparedStatementCreatorImpl(params != null ? Arrays.asList(params) : Collections.emptyList());
}
@@ -171,7 +170,7 @@ public class PreparedStatementCreatorFactory {
* Return a new PreparedStatementCreator for the given parameters.
* @param params the parameter array (may be {@code null})
*/
public PreparedStatementCreator newPreparedStatementCreator(@Nullable Object[] params) {
public PreparedStatementCreator newPreparedStatementCreator(Object @Nullable [] params) {
return new PreparedStatementCreatorImpl(params != null ? Arrays.asList(params) : Collections.emptyList());
}
@@ -181,7 +180,7 @@ public class PreparedStatementCreatorFactory {
* the factory's, for example because of named parameter expanding)
* @param params the parameter array (may be {@code null})
*/
public PreparedStatementCreator newPreparedStatementCreator(String sqlToUse, @Nullable Object[] params) {
public PreparedStatementCreator newPreparedStatementCreator(String sqlToUse, Object @Nullable [] params) {
return new PreparedStatementCreatorImpl(
sqlToUse, (params != null ? Arrays.asList(params) : Collections.emptyList()));
}

View File

@@ -19,8 +19,9 @@ package org.springframework.jdbc.core;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.DataAccessException;
import org.springframework.lang.Nullable;
/**
* Callback interface used by {@link JdbcTemplate}'s query methods.
@@ -61,7 +62,6 @@ public interface ResultSetExtractor<T> {
* values or navigating (that is, there's no need to catch SQLException)
* @throws DataAccessException in case of custom exceptions
*/
@Nullable
T extractData(ResultSet rs) throws SQLException, DataAccessException;
@Nullable T extractData(ResultSet rs) throws SQLException, DataAccessException;
}

View File

@@ -18,7 +18,7 @@ package org.springframework.jdbc.core;
import java.sql.ResultSet;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Common base class for ResultSet-supporting SqlParameters like
@@ -29,14 +29,11 @@ import org.springframework.lang.Nullable;
*/
public class ResultSetSupportingSqlParameter extends SqlParameter {
@Nullable
private ResultSetExtractor<?> resultSetExtractor;
private @Nullable ResultSetExtractor<?> resultSetExtractor;
@Nullable
private RowCallbackHandler rowCallbackHandler;
private @Nullable RowCallbackHandler rowCallbackHandler;
@Nullable
private RowMapper<?> rowMapper;
private @Nullable RowMapper<?> rowMapper;
/**
@@ -114,24 +111,21 @@ public class ResultSetSupportingSqlParameter extends SqlParameter {
/**
* Return the ResultSetExtractor held by this parameter, if any.
*/
@Nullable
public ResultSetExtractor<?> getResultSetExtractor() {
public @Nullable ResultSetExtractor<?> getResultSetExtractor() {
return this.resultSetExtractor;
}
/**
* Return the RowCallbackHandler held by this parameter, if any.
*/
@Nullable
public RowCallbackHandler getRowCallbackHandler() {
public @Nullable RowCallbackHandler getRowCallbackHandler() {
return this.rowCallbackHandler;
}
/**
* Return the RowMapper held by this parameter, if any.
*/
@Nullable
public RowMapper<?> getRowMapper() {
public @Nullable RowMapper<?> getRowMapper() {
return this.rowMapper;
}

View File

@@ -20,8 +20,9 @@ import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import org.jspecify.annotations.Nullable;
import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.lang.Nullable;
/**
* Implementation of RowCallbackHandler. Convenient superclass for callback handlers.
@@ -55,14 +56,12 @@ public class RowCountCallbackHandler implements RowCallbackHandler {
* Indexed from 0. Type (as in java.sql.Types) for the columns
* as returned by ResultSetMetaData object.
*/
@Nullable
private int[] columnTypes;
private int @Nullable [] columnTypes;
/**
* Indexed from 0. Column name as returned by ResultSetMetaData object.
*/
@Nullable
private String[] columnNames;
private String @Nullable [] columnNames;
/**
@@ -105,8 +104,7 @@ public class RowCountCallbackHandler implements RowCallbackHandler {
* @return the types of the columns as java.sql.Types constants.
* <b>Indexed from 0 to n-1.</b>
*/
@Nullable
public final int[] getColumnTypes() {
public final int @Nullable [] getColumnTypes() {
return this.columnTypes;
}
@@ -116,8 +114,7 @@ public class RowCountCallbackHandler implements RowCallbackHandler {
* @return the names of the columns.
* <b>Indexed from 0 to n-1.</b>
*/
@Nullable
public final String[] getColumnNames() {
public final String @Nullable [] getColumnNames() {
return this.columnNames;
}

View File

@@ -19,7 +19,7 @@ package org.springframework.jdbc.core;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* An interface used by {@link JdbcTemplate} for mapping rows of a
@@ -61,7 +61,6 @@ public interface RowMapper<T> {
* @throws SQLException if an SQLException is encountered while getting
* column values (that is, there's no need to catch SQLException)
*/
@Nullable
T mapRow(ResultSet rs, int rowNum) throws SQLException;
@Nullable T mapRow(ResultSet rs, int rowNum) throws SQLException;
}

View File

@@ -20,12 +20,13 @@ import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import org.jspecify.annotations.Nullable;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.dao.TypeMismatchDataAccessException;
import org.springframework.jdbc.IncorrectResultSetColumnCountException;
import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
import org.springframework.util.NumberUtils;
@@ -47,11 +48,9 @@ import org.springframework.util.NumberUtils;
*/
public class SingleColumnRowMapper<T> implements RowMapper<T> {
@Nullable
private Class<?> requiredType;
private @Nullable Class<?> requiredType;
@Nullable
private ConversionService conversionService = DefaultConversionService.getSharedInstance();
private @Nullable ConversionService conversionService = DefaultConversionService.getSharedInstance();
/**
@@ -102,8 +101,7 @@ public class SingleColumnRowMapper<T> implements RowMapper<T> {
*/
@Override
@SuppressWarnings("unchecked")
@Nullable
public T mapRow(ResultSet rs, int rowNum) throws SQLException {
public @Nullable T mapRow(ResultSet rs, int rowNum) throws SQLException {
// Validate column count.
ResultSetMetaData rsmd = rs.getMetaData();
int nrOfColumns = rsmd.getColumnCount();
@@ -144,8 +142,7 @@ public class SingleColumnRowMapper<T> implements RowMapper<T> {
* @see org.springframework.jdbc.support.JdbcUtils#getResultSetValue(java.sql.ResultSet, int, Class)
* @see #getColumnValue(java.sql.ResultSet, int)
*/
@Nullable
protected Object getColumnValue(ResultSet rs, int index, @Nullable Class<?> requiredType) throws SQLException {
protected @Nullable Object getColumnValue(ResultSet rs, int index, @Nullable Class<?> requiredType) throws SQLException {
if (requiredType != null) {
return JdbcUtils.getResultSetValue(rs, index, requiredType);
}
@@ -169,8 +166,7 @@ public class SingleColumnRowMapper<T> implements RowMapper<T> {
* @throws SQLException in case of extraction failure
* @see org.springframework.jdbc.support.JdbcUtils#getResultSetValue(java.sql.ResultSet, int)
*/
@Nullable
protected Object getColumnValue(ResultSet rs, int index) throws SQLException {
protected @Nullable Object getColumnValue(ResultSet rs, int index) throws SQLException {
return JdbcUtils.getResultSetValue(rs, index);
}
@@ -190,8 +186,7 @@ public class SingleColumnRowMapper<T> implements RowMapper<T> {
* @see #getColumnValue(java.sql.ResultSet, int, Class)
*/
@SuppressWarnings("unchecked")
@Nullable
protected Object convertValueToRequiredType(Object value, Class<?> requiredType) {
protected @Nullable Object convertValueToRequiredType(Object value, Class<?> requiredType) {
if (String.class == requiredType) {
return value.toString();
}

View File

@@ -18,7 +18,7 @@ package org.springframework.jdbc.core;
import java.sql.ResultSet;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Subclass of {@link SqlParameter} to represent an output parameter.
@@ -34,8 +34,7 @@ import org.springframework.lang.Nullable;
*/
public class SqlOutParameter extends ResultSetSupportingSqlParameter {
@Nullable
private SqlReturnType sqlReturnType;
private @Nullable SqlReturnType sqlReturnType;
/**
@@ -114,8 +113,7 @@ public class SqlOutParameter extends ResultSetSupportingSqlParameter {
/**
* Return the custom return type, if any.
*/
@Nullable
public SqlReturnType getSqlReturnType() {
public @Nullable SqlReturnType getSqlReturnType() {
return this.sqlReturnType;
}

View File

@@ -19,7 +19,8 @@ package org.springframework.jdbc.core;
import java.util.ArrayList;
import java.util.List;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert;
/**
@@ -36,19 +37,16 @@ import org.springframework.util.Assert;
public class SqlParameter {
// The name of the parameter, if any
@Nullable
private String name;
private @Nullable String name;
// SQL type constant from {@code java.sql.Types}
private final int sqlType;
// Used for types that are user-named like: STRUCT, DISTINCT, JAVA_OBJECT, named array types
@Nullable
private String typeName;
private @Nullable String typeName;
// The scale to apply in case of a NUMERIC or DECIMAL type, if any
@Nullable
private Integer scale;
private @Nullable Integer scale;
/**
@@ -131,8 +129,7 @@ public class SqlParameter {
/**
* Return the name of the parameter, or {@code null} if anonymous.
*/
@Nullable
public String getName() {
public @Nullable String getName() {
return this.name;
}
@@ -146,16 +143,14 @@ public class SqlParameter {
/**
* Return the type name of the parameter, if any.
*/
@Nullable
public String getTypeName() {
public @Nullable String getTypeName() {
return this.typeName;
}
/**
* Return the scale of the parameter, if any.
*/
@Nullable
public Integer getScale() {
public @Nullable Integer getScale() {
return this.scale;
}
@@ -183,7 +178,7 @@ public class SqlParameter {
* Convert a list of JDBC types, as defined in {@code java.sql.Types},
* to a List of SqlParameter objects as used in this package.
*/
public static List<SqlParameter> sqlTypesToAnonymousParameterList(@Nullable int... types) {
public static List<SqlParameter> sqlTypesToAnonymousParameterList(int @Nullable ... types) {
if (types == null) {
return new ArrayList<>();
}

View File

@@ -16,7 +16,7 @@
package org.springframework.jdbc.core;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Object to represent an SQL parameter value, including parameter meta-data
@@ -38,8 +38,7 @@ import org.springframework.lang.Nullable;
*/
public class SqlParameterValue extends SqlParameter {
@Nullable
private final Object value;
private final @Nullable Object value;
/**
@@ -89,8 +88,7 @@ public class SqlParameterValue extends SqlParameter {
/**
* Return the value object that this parameter value holds.
*/
@Nullable
public Object getValue() {
public @Nullable Object getValue() {
return this.value;
}

View File

@@ -16,7 +16,7 @@
package org.springframework.jdbc.core;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Interface to be implemented by objects that can provide SQL strings.
@@ -38,7 +38,6 @@ public interface SqlProvider {
* typically the SQL used for creating statements.
* @return the SQL string, or {@code null} if not available
*/
@Nullable
String getSql();
@Nullable String getSql();
}

View File

@@ -19,7 +19,7 @@ package org.springframework.jdbc.core;
import java.sql.CallableStatement;
import java.sql.SQLException;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Interface to be implemented for retrieving values for more complex database-specific

View File

@@ -19,8 +19,9 @@ package org.springframework.jdbc.core;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.jspecify.annotations.Nullable;
import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.lang.Nullable;
/**
* Interface to be implemented for setting values for more complex database-specific

View File

@@ -19,8 +19,9 @@ package org.springframework.jdbc.core;
import java.sql.SQLException;
import java.sql.Statement;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.DataAccessException;
import org.springframework.lang.Nullable;
/**
* Generic callback interface for code that operates on a JDBC Statement.
@@ -67,7 +68,6 @@ public interface StatementCallback<T> {
* @see JdbcTemplate#queryForObject(String, Class)
* @see JdbcTemplate#queryForRowSet(String)
*/
@Nullable
T doInStatement(Statement stmt) throws SQLException, DataAccessException;
@Nullable T doInStatement(Statement stmt) throws SQLException, DataAccessException;
}

View File

@@ -40,10 +40,10 @@ import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.core.SpringProperties;
import org.springframework.jdbc.support.SqlValue;
import org.springframework.lang.Nullable;
/**
* Utility methods for PreparedStatementSetter/Creator and CallableStatementCreator
@@ -85,8 +85,7 @@ public abstract class StatementCreatorUtils {
private static final Map<Class<?>, Integer> javaTypeToSqlTypeMap = new HashMap<>(64);
@Nullable
static Boolean shouldIgnoreGetParameterType;
static @Nullable Boolean shouldIgnoreGetParameterType;
static {
javaTypeToSqlTypeMap.put(boolean.class, Types.BOOLEAN);
@@ -494,7 +493,7 @@ public abstract class StatementCreatorUtils {
* @see DisposableSqlTypeValue#cleanup()
* @see org.springframework.jdbc.core.support.SqlLobValue#cleanup()
*/
public static void cleanupParameters(@Nullable Object... paramValues) {
public static void cleanupParameters(@Nullable Object @Nullable ... paramValues) {
if (paramValues != null) {
cleanupParameters(Arrays.asList(paramValues));
}

View File

@@ -28,6 +28,7 @@ import javax.sql.DataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.jdbc.core.RowMapper;
@@ -38,7 +39,6 @@ import org.springframework.jdbc.core.SqlReturnResultSet;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSourceUtils;
import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
@@ -58,23 +58,19 @@ public class CallMetaDataContext {
protected final Log logger = LogFactory.getLog(getClass());
// Name of procedure to call
@Nullable
private String procedureName;
private @Nullable String procedureName;
// Name of catalog for call
@Nullable
private String catalogName;
private @Nullable String catalogName;
// Name of schema for call
@Nullable
private String schemaName;
private @Nullable String schemaName;
// List of SqlParameter objects to be used in call execution
private List<SqlParameter> callParameters = new ArrayList<>();
// Actual name to use for the return value in the output map
@Nullable
private String actualFunctionReturnName;
private @Nullable String actualFunctionReturnName;
// Set of in parameter names to exclude use for any not listed
private Set<String> limitedInParameterNames = new HashSet<>();
@@ -95,8 +91,7 @@ public class CallMetaDataContext {
private boolean namedBinding;
// The provider of call meta-data
@Nullable
private CallMetaDataProvider metaDataProvider;
private @Nullable CallMetaDataProvider metaDataProvider;
/**
@@ -151,8 +146,7 @@ public class CallMetaDataContext {
/**
* Get the name of the procedure.
*/
@Nullable
public String getProcedureName() {
public @Nullable String getProcedureName() {
return this.procedureName;
}
@@ -166,8 +160,7 @@ public class CallMetaDataContext {
/**
* Get the name of the catalog.
*/
@Nullable
public String getCatalogName() {
public @Nullable String getCatalogName() {
return this.catalogName;
}
@@ -181,8 +174,7 @@ public class CallMetaDataContext {
/**
* Get the name of the schema.
*/
@Nullable
public String getSchemaName() {
public @Nullable String getSchemaName() {
return this.schemaName;
}
@@ -285,8 +277,7 @@ public class CallMetaDataContext {
* Get the name of the single out parameter for this call.
* If there are multiple parameters, the name of the first one will be returned.
*/
@Nullable
public String getScalarOutParameterName() {
public @Nullable String getScalarOutParameterName() {
if (isFunction()) {
return getFunctionReturnName();
}

View File

@@ -20,8 +20,9 @@ import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.List;
import org.jspecify.annotations.Nullable;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.lang.Nullable;
/**
* Interface specifying the API to be implemented by a class providing call meta-data.
@@ -67,46 +68,40 @@ public interface CallMetaDataProvider {
* Provide any modification of the procedure name passed in to match the meta-data currently used.
* <p>This could include altering the case.
*/
@Nullable
String procedureNameToUse(@Nullable String procedureName);
@Nullable String procedureNameToUse(@Nullable String procedureName);
/**
* Provide any modification of the catalog name passed in to match the meta-data currently used.
* <p>This could include altering the case.
*/
@Nullable
String catalogNameToUse(@Nullable String catalogName);
@Nullable String catalogNameToUse(@Nullable String catalogName);
/**
* Provide any modification of the schema name passed in to match the meta-data currently used.
* <p>This could include altering the case.
*/
@Nullable
String schemaNameToUse(@Nullable String schemaName);
@Nullable String schemaNameToUse(@Nullable String schemaName);
/**
* Provide any modification of the catalog name passed in to match the meta-data currently used.
* <p>The returned value will be used for meta-data lookups. This could include altering the case
* used or providing a base catalog if none is provided.
*/
@Nullable
String metaDataCatalogNameToUse(@Nullable String catalogName) ;
@Nullable String metaDataCatalogNameToUse(@Nullable String catalogName) ;
/**
* Provide any modification of the schema name passed in to match the meta-data currently used.
* <p>The returned value will be used for meta-data lookups. This could include altering the case
* used or providing a base schema if none is provided.
*/
@Nullable
String metaDataSchemaNameToUse(@Nullable String schemaName);
@Nullable String metaDataSchemaNameToUse(@Nullable String schemaName);
/**
* Provide any modification of the column name passed in to match the meta-data currently used.
* <p>This could include altering the case.
* @param parameterName name of the parameter of column
*/
@Nullable
String parameterNameToUse(@Nullable String parameterName);
@Nullable String parameterNameToUse(@Nullable String parameterName);
/**
* Return the name of the named parameter to use for binding the given parameter name.
@@ -147,8 +142,7 @@ public interface CallMetaDataProvider {
* Get the name of the current user. Useful for meta-data lookups etc.
* @return current user name from database connection
*/
@Nullable
String getUserName();
@Nullable String getUserName();
/**
* Are we using the meta-data for the procedure columns?

View File

@@ -18,7 +18,7 @@ package org.springframework.jdbc.core.metadata;
import java.sql.DatabaseMetaData;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Holder of meta-data for a specific parameter that is used for call processing.
@@ -32,15 +32,13 @@ public class CallParameterMetaData {
private final boolean function;
@Nullable
private final String parameterName;
private final @Nullable String parameterName;
private final int parameterType;
private final int sqlType;
@Nullable
private final String typeName;
private final @Nullable String typeName;
private final boolean nullable;
@@ -72,8 +70,7 @@ public class CallParameterMetaData {
/**
* Return the parameter name.
*/
@Nullable
public String getParameterName() {
public @Nullable String getParameterName() {
return this.parameterName;
}
@@ -129,8 +126,7 @@ public class CallParameterMetaData {
/**
* Return the parameter type name.
*/
@Nullable
public String getTypeName() {
public @Nullable String getTypeName() {
return this.typeName;
}

View File

@@ -20,7 +20,7 @@ import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.Locale;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* DB2 specific implementation for the {@link CallMetaDataProvider} interface.
@@ -66,8 +66,7 @@ public class Db2CallMetaDataProvider extends GenericCallMetaDataProvider {
}
@Override
@Nullable
public String metaDataSchemaNameToUse(@Nullable String schemaName) {
public @Nullable String metaDataSchemaNameToUse(@Nullable String schemaName) {
if (schemaName != null) {
return super.metaDataSchemaNameToUse(schemaName);
}

View File

@@ -20,7 +20,7 @@ import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.Locale;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Derby specific implementation for the {@link CallMetaDataProvider} interface.
@@ -38,8 +38,7 @@ public class DerbyCallMetaDataProvider extends GenericCallMetaDataProvider {
@Override
@Nullable
public String metaDataSchemaNameToUse(@Nullable String schemaName) {
public @Nullable String metaDataSchemaNameToUse(@Nullable String schemaName) {
if (schemaName != null) {
return super.metaDataSchemaNameToUse(schemaName);
}

View File

@@ -26,12 +26,12 @@ import java.util.Locale;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.jdbc.core.SqlInOutParameter;
import org.springframework.jdbc.core.SqlOutParameter;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
/**
@@ -125,26 +125,22 @@ public class GenericCallMetaDataProvider implements CallMetaDataProvider {
}
@Override
@Nullable
public String procedureNameToUse(@Nullable String procedureName) {
public @Nullable String procedureNameToUse(@Nullable String procedureName) {
return identifierNameToUse(procedureName);
}
@Override
@Nullable
public String catalogNameToUse(@Nullable String catalogName) {
public @Nullable String catalogNameToUse(@Nullable String catalogName) {
return identifierNameToUse(catalogName);
}
@Override
@Nullable
public String schemaNameToUse(@Nullable String schemaName) {
public @Nullable String schemaNameToUse(@Nullable String schemaName) {
return identifierNameToUse(schemaName);
}
@Override
@Nullable
public String metaDataCatalogNameToUse(@Nullable String catalogName) {
public @Nullable String metaDataCatalogNameToUse(@Nullable String catalogName) {
if (isSupportsCatalogsInProcedureCalls()) {
return catalogNameToUse(catalogName);
}
@@ -154,8 +150,7 @@ public class GenericCallMetaDataProvider implements CallMetaDataProvider {
}
@Override
@Nullable
public String metaDataSchemaNameToUse(@Nullable String schemaName) {
public @Nullable String metaDataSchemaNameToUse(@Nullable String schemaName) {
if (isSupportsSchemasInProcedureCalls()) {
return schemaNameToUse(schemaName);
}
@@ -165,8 +160,7 @@ public class GenericCallMetaDataProvider implements CallMetaDataProvider {
}
@Override
@Nullable
public String parameterNameToUse(@Nullable String parameterName) {
public @Nullable String parameterNameToUse(@Nullable String parameterName) {
return identifierNameToUse(parameterName);
}
@@ -279,8 +273,7 @@ public class GenericCallMetaDataProvider implements CallMetaDataProvider {
}
@Nullable
private String identifierNameToUse(@Nullable String identifierName) {
private @Nullable String identifierNameToUse(@Nullable String identifierName) {
if (identifierName == null) {
return null;
}
@@ -438,8 +431,7 @@ public class GenericCallMetaDataProvider implements CallMetaDataProvider {
return new ProcedureMetadata(schemaName, procedureName, matches, true);
}
@Nullable
private static String escapeNamePattern(@Nullable String name, @Nullable String escape) {
private static @Nullable String escapeNamePattern(@Nullable String name, @Nullable String escape) {
if (name == null || escape == null) {
return name;
}

View File

@@ -29,10 +29,10 @@ import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.lang.Nullable;
/**
* A generic implementation of the {@link TableMetaDataProvider} interface
@@ -54,12 +54,10 @@ public class GenericTableMetaDataProvider implements TableMetaDataProvider {
/** The name of the user currently connected. */
@Nullable
private final String userName;
private final @Nullable String userName;
/** The version of the database. */
@Nullable
private String databaseVersion;
private @Nullable String databaseVersion;
/** Indicates whether column meta-data has been used. */
private boolean tableColumnMetaDataUsed = false;
@@ -186,31 +184,26 @@ public class GenericTableMetaDataProvider implements TableMetaDataProvider {
}
@Override
@Nullable
public String tableNameToUse(@Nullable String tableName) {
public @Nullable String tableNameToUse(@Nullable String tableName) {
return identifierNameToUse(tableName);
}
@Override
@Nullable
public String columnNameToUse(@Nullable String columnName) {
public @Nullable String columnNameToUse(@Nullable String columnName) {
return identifierNameToUse(columnName);
}
@Override
@Nullable
public String catalogNameToUse(@Nullable String catalogName) {
public @Nullable String catalogNameToUse(@Nullable String catalogName) {
return identifierNameToUse(catalogName);
}
@Override
@Nullable
public String schemaNameToUse(@Nullable String schemaName) {
public @Nullable String schemaNameToUse(@Nullable String schemaName) {
return identifierNameToUse(schemaName);
}
@Nullable
private String identifierNameToUse(@Nullable String identifierName) {
private @Nullable String identifierNameToUse(@Nullable String identifierName) {
if (identifierName == null) {
return null;
}
@@ -226,14 +219,12 @@ public class GenericTableMetaDataProvider implements TableMetaDataProvider {
}
@Override
@Nullable
public String metaDataCatalogNameToUse(@Nullable String catalogName) {
public @Nullable String metaDataCatalogNameToUse(@Nullable String catalogName) {
return catalogNameToUse(catalogName);
}
@Override
@Nullable
public String metaDataSchemaNameToUse(@Nullable String schemaName) {
public @Nullable String metaDataSchemaNameToUse(@Nullable String schemaName) {
if (schemaName == null) {
return schemaNameToUse(getDefaultSchema());
}
@@ -243,16 +234,14 @@ public class GenericTableMetaDataProvider implements TableMetaDataProvider {
/**
* Provide access to the default schema for subclasses.
*/
@Nullable
protected String getDefaultSchema() {
protected @Nullable String getDefaultSchema() {
return this.userName;
}
/**
* Provide access to the version info for subclasses.
*/
@Nullable
protected String getDatabaseVersion() {
protected @Nullable String getDatabaseVersion() {
return this.databaseVersion;
}
@@ -276,8 +265,7 @@ public class GenericTableMetaDataProvider implements TableMetaDataProvider {
}
@Override
@Nullable
public String getSimpleQueryForGetGeneratedKey(String tableName, String keyColumnName) {
public @Nullable String getSimpleQueryForGetGeneratedKey(String tableName, String keyColumnName) {
return null;
}

View File

@@ -20,10 +20,11 @@ import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.sql.Types;
import org.jspecify.annotations.Nullable;
import org.springframework.jdbc.core.ColumnMapRowMapper;
import org.springframework.jdbc.core.SqlOutParameter;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.lang.Nullable;
/**
* Oracle-specific implementation for the {@link CallMetaDataProvider} interface.
@@ -58,15 +59,13 @@ public class OracleCallMetaDataProvider extends GenericCallMetaDataProvider {
}
@Override
@Nullable
public String metaDataCatalogNameToUse(@Nullable String catalogName) {
public @Nullable String metaDataCatalogNameToUse(@Nullable String catalogName) {
// Oracle uses catalog name for package name or an empty string if no package
return (catalogName == null ? "" : catalogNameToUse(catalogName));
}
@Override
@Nullable
public String metaDataSchemaNameToUse(@Nullable String schemaName) {
public @Nullable String metaDataSchemaNameToUse(@Nullable String schemaName) {
// Use current user schema if no schema specified
return (schemaName == null ? getUserName() : super.metaDataSchemaNameToUse(schemaName));
}

View File

@@ -23,8 +23,9 @@ import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.sql.Types;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.lang.Nullable;
import org.springframework.util.ReflectionUtils;
/**
@@ -43,8 +44,7 @@ public class OracleTableMetaDataProvider extends GenericTableMetaDataProvider {
private final boolean includeSynonyms;
@Nullable
private final String defaultSchema;
private final @Nullable String defaultSchema;
/**
@@ -72,8 +72,7 @@ public class OracleTableMetaDataProvider extends GenericTableMetaDataProvider {
/*
* Oracle-based implementation for detecting the current schema.
*/
@Nullable
private static String lookupDefaultSchema(DatabaseMetaData databaseMetaData) {
private static @Nullable String lookupDefaultSchema(DatabaseMetaData databaseMetaData) {
try {
CallableStatement cstmt = null;
try {
@@ -100,8 +99,7 @@ public class OracleTableMetaDataProvider extends GenericTableMetaDataProvider {
}
@Override
@Nullable
protected String getDefaultSchema() {
protected @Nullable String getDefaultSchema() {
if (this.defaultSchema != null) {
return this.defaultSchema;
}

View File

@@ -20,10 +20,11 @@ import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.sql.Types;
import org.jspecify.annotations.Nullable;
import org.springframework.jdbc.core.ColumnMapRowMapper;
import org.springframework.jdbc.core.SqlOutParameter;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.lang.Nullable;
/**
* Postgres-specific implementation for the {@link CallMetaDataProvider} interface.
@@ -65,8 +66,7 @@ public class PostgresCallMetaDataProvider extends GenericCallMetaDataProvider {
}
@Override
@Nullable
public String metaDataSchemaNameToUse(@Nullable String schemaName) {
public @Nullable String metaDataSchemaNameToUse(@Nullable String schemaName) {
return (schemaName == null ? this.schemaName : super.metaDataSchemaNameToUse(schemaName));
}

View File

@@ -19,7 +19,7 @@ package org.springframework.jdbc.core.metadata;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* SQL Server specific implementation for the {@link CallMetaDataProvider} interface.
@@ -42,8 +42,7 @@ public class SqlServerCallMetaDataProvider extends GenericCallMetaDataProvider {
@Override
@Nullable
public String parameterNameToUse(@Nullable String parameterName) {
public @Nullable String parameterNameToUse(@Nullable String parameterName) {
if (parameterName == null) {
return null;
}

View File

@@ -19,7 +19,7 @@ package org.springframework.jdbc.core.metadata;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Sybase specific implementation for the {@link CallMetaDataProvider} interface.
@@ -42,8 +42,7 @@ public class SybaseCallMetaDataProvider extends GenericCallMetaDataProvider {
@Override
@Nullable
public String parameterNameToUse(@Nullable String parameterName) {
public @Nullable String parameterNameToUse(@Nullable String parameterName) {
if (parameterName == null) {
return null;
}

View File

@@ -27,13 +27,13 @@ import javax.sql.DataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.jdbc.core.SqlTypeValue;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSourceUtils;
import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
@@ -53,16 +53,13 @@ public class TableMetaDataContext {
protected final Log logger = LogFactory.getLog(getClass());
// Name of table for this context
@Nullable
private String tableName;
private @Nullable String tableName;
// Name of catalog for this context
@Nullable
private String catalogName;
private @Nullable String catalogName;
// Name of schema for this context
@Nullable
private String schemaName;
private @Nullable String schemaName;
// Should we access insert parameter meta-data info or not
private boolean accessTableColumnMetaData = true;
@@ -74,8 +71,7 @@ public class TableMetaDataContext {
private boolean quoteIdentifiers = false;
// The provider of table meta-data
@Nullable
private TableMetaDataProvider metaDataProvider;
private @Nullable TableMetaDataProvider metaDataProvider;
// List of columns objects to be used in this context
private List<String> tableColumns = new ArrayList<>();
@@ -94,8 +90,7 @@ public class TableMetaDataContext {
/**
* Get the name of the table for this context.
*/
@Nullable
public String getTableName() {
public @Nullable String getTableName() {
return this.tableName;
}
@@ -109,8 +104,7 @@ public class TableMetaDataContext {
/**
* Get the name of the catalog for this context.
*/
@Nullable
public String getCatalogName() {
public @Nullable String getCatalogName() {
return this.catalogName;
}
@@ -124,8 +118,7 @@ public class TableMetaDataContext {
/**
* Get the name of the schema for this context.
*/
@Nullable
public String getSchemaName() {
public @Nullable String getSchemaName() {
return this.schemaName;
}
@@ -411,8 +404,7 @@ public class TableMetaDataContext {
* retrieving generated keys is not supported.
* @see #isGetGeneratedKeysSimulated()
*/
@Nullable
public String getSimpleQueryForGetGeneratedKey(String tableName, String keyColumnName) {
public @Nullable String getSimpleQueryForGetGeneratedKey(String tableName, String keyColumnName) {
return obtainMetaDataProvider().getSimpleQueryForGetGeneratedKey(tableName, keyColumnName);
}
@@ -428,8 +420,7 @@ public class TableMetaDataContext {
private static final class QuoteHandler {
@Nullable
private final String identifierQuoteString;
private final @Nullable String identifierQuoteString;
private final boolean quoting;

View File

@@ -20,7 +20,7 @@ import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.List;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Interface specifying the API to be implemented by a class providing table meta-data.
@@ -63,30 +63,26 @@ public interface TableMetaDataProvider {
* Get the table name formatted based on meta-data information.
* <p>This could include altering the case.
*/
@Nullable
String tableNameToUse(@Nullable String tableName);
@Nullable String tableNameToUse(@Nullable String tableName);
/**
* Get the column name formatted based on meta-data information.
* <p>This could include altering the case.
* @since 6.1
*/
@Nullable
String columnNameToUse(@Nullable String columnName);
@Nullable String columnNameToUse(@Nullable String columnName);
/**
* Get the catalog name formatted based on meta-data information.
* <p>This could include altering the case.
*/
@Nullable
String catalogNameToUse(@Nullable String catalogName);
@Nullable String catalogNameToUse(@Nullable String catalogName);
/**
* Get the schema name formatted based on meta-data information.
* <p>This could include altering the case.
*/
@Nullable
String schemaNameToUse(@Nullable String schemaName);
@Nullable String schemaNameToUse(@Nullable String schemaName);
/**
* Provide any modification of the catalog name passed in to match the meta-data
@@ -95,8 +91,7 @@ public interface TableMetaDataProvider {
* <p>This could include altering the case used or providing a base catalog
* if none is provided.
*/
@Nullable
String metaDataCatalogNameToUse(@Nullable String catalogName) ;
@Nullable String metaDataCatalogNameToUse(@Nullable String catalogName) ;
/**
* Provide any modification of the schema name passed in to match the meta-data
@@ -105,8 +100,7 @@ public interface TableMetaDataProvider {
* <p>This could include altering the case used or providing a base schema
* if none is provided.
*/
@Nullable
String metaDataSchemaNameToUse(@Nullable String schemaName) ;
@Nullable String metaDataSchemaNameToUse(@Nullable String schemaName) ;
/**
* Are we using the meta-data for the table columns?
@@ -132,8 +126,7 @@ public interface TableMetaDataProvider {
* retrieving generated keys is not supported.
* @see #isGetGeneratedKeysSimulated()
*/
@Nullable
String getSimpleQueryForGetGeneratedKey(String tableName, String keyColumnName);
@Nullable String getSimpleQueryForGetGeneratedKey(String tableName, String keyColumnName);
/**
* Does this database support a column name String array for retrieving generated

View File

@@ -2,9 +2,7 @@
* Context metadata abstraction for the configuration and execution
* of table inserts and stored procedure calls.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.jdbc.core.metadata;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -20,9 +20,10 @@ import java.util.HashMap;
import java.util.Map;
import java.util.StringJoiner;
import org.jspecify.annotations.Nullable;
import org.springframework.jdbc.core.SqlParameterValue;
import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -85,8 +86,7 @@ public abstract class AbstractSqlParameterSource implements SqlParameterSource {
* or {@code null} if not registered
*/
@Override
@Nullable
public String getTypeName(String paramName) {
public @Nullable String getTypeName(String paramName) {
Assert.notNull(paramName, "Parameter name must not be null");
return this.typeNames.get(paramName);
}

View File

@@ -20,13 +20,14 @@ import java.beans.PropertyDescriptor;
import java.util.ArrayList;
import java.util.List;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.NotReadablePropertyException;
import org.springframework.beans.PropertyAccessor;
import org.springframework.beans.PropertyAccessorFactory;
import org.springframework.jdbc.core.StatementCreatorUtils;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
/**
@@ -47,8 +48,7 @@ public class BeanPropertySqlParameterSource extends AbstractSqlParameterSource {
private final BeanWrapper beanWrapper;
@Nullable
private String[] propertyNames;
private String @Nullable [] propertyNames;
/**
@@ -66,8 +66,7 @@ public class BeanPropertySqlParameterSource extends AbstractSqlParameterSource {
}
@Override
@Nullable
public Object getValue(String paramName) throws IllegalArgumentException {
public @Nullable Object getValue(String paramName) throws IllegalArgumentException {
try {
return this.beanWrapper.getPropertyValue(paramName);
}
@@ -91,8 +90,7 @@ public class BeanPropertySqlParameterSource extends AbstractSqlParameterSource {
}
@Override
@NonNull
public String[] getParameterNames() {
public @NonNull String[] getParameterNames() {
return getReadablePropertyNames();
}

View File

@@ -16,7 +16,7 @@
package org.springframework.jdbc.core.namedparam;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* A simple empty implementation of the {@link SqlParameterSource} interface.
@@ -38,8 +38,7 @@ public class EmptySqlParameterSource implements SqlParameterSource {
}
@Override
@Nullable
public Object getValue(String paramName) throws IllegalArgumentException {
public @Nullable Object getValue(String paramName) throws IllegalArgumentException {
throw new IllegalArgumentException("This SqlParameterSource is empty");
}
@@ -49,14 +48,12 @@ public class EmptySqlParameterSource implements SqlParameterSource {
}
@Override
@Nullable
public String getTypeName(String paramName) {
public @Nullable String getTypeName(String paramName) {
return null;
}
@Override
@Nullable
public String[] getParameterNames() {
public String @Nullable [] getParameterNames() {
return null;
}

View File

@@ -20,9 +20,10 @@ import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import org.springframework.jdbc.core.SqlParameterValue;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -165,8 +166,7 @@ public class MapSqlParameterSource extends AbstractSqlParameterSource {
}
@Override
@Nullable
public Object getValue(String paramName) {
public @Nullable Object getValue(String paramName) {
if (!hasValue(paramName)) {
throw new IllegalArgumentException("No value registered for key '" + paramName + "'");
}
@@ -174,8 +174,7 @@ public class MapSqlParameterSource extends AbstractSqlParameterSource {
}
@Override
@NonNull
public String[] getParameterNames() {
public @NonNull String[] getParameterNames() {
return StringUtils.toStringArray(this.values.keySet());
}

View File

@@ -16,9 +16,10 @@
package org.springframework.jdbc.core.namedparam;
import org.jspecify.annotations.Nullable;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.lang.Nullable;
/**
* Extension of JdbcDaoSupport that exposes a NamedParameterJdbcTemplate as well.
@@ -30,8 +31,7 @@ import org.springframework.lang.Nullable;
*/
public class NamedParameterJdbcDaoSupport extends JdbcDaoSupport {
@Nullable
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
private @Nullable NamedParameterJdbcTemplate namedParameterJdbcTemplate;
/**
@@ -48,8 +48,7 @@ public class NamedParameterJdbcDaoSupport extends JdbcDaoSupport {
/**
* Return a NamedParameterJdbcTemplate wrapping the configured JdbcTemplate.
*/
@Nullable
public NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() {
public @Nullable NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() {
return this.namedParameterJdbcTemplate;
}

View File

@@ -20,6 +20,8 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.core.PreparedStatementCallback;
@@ -28,7 +30,6 @@ import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.lang.Nullable;
/**
* Interface specifying a basic set of JDBC operations allowing the use
@@ -75,8 +76,7 @@ public interface NamedParameterJdbcOperations {
* @return a result object returned by the action, or {@code null}
* @throws DataAccessException if there is any problem
*/
@Nullable
<T> T execute(String sql, SqlParameterSource paramSource, PreparedStatementCallback<T> action)
<T> @Nullable T execute(String sql, SqlParameterSource paramSource, PreparedStatementCallback<T> action)
throws DataAccessException;
/**
@@ -94,8 +94,7 @@ public interface NamedParameterJdbcOperations {
* @return a result object returned by the action, or {@code null}
* @throws DataAccessException if there is any problem
*/
@Nullable
<T> T execute(String sql, Map<String, ?> paramMap, PreparedStatementCallback<T> action)
<T> @Nullable T execute(String sql, Map<String, ?> paramMap, PreparedStatementCallback<T> action)
throws DataAccessException;
/**
@@ -111,8 +110,7 @@ public interface NamedParameterJdbcOperations {
* @return a result object returned by the action, or {@code null}
* @throws DataAccessException if there is any problem
*/
@Nullable
<T> T execute(String sql, PreparedStatementCallback<T> action) throws DataAccessException;
<T> @Nullable T execute(String sql, PreparedStatementCallback<T> action) throws DataAccessException;
/**
* Query given SQL to create a prepared statement from SQL and a list
@@ -124,8 +122,7 @@ public interface NamedParameterJdbcOperations {
* @return an arbitrary result object, as returned by the ResultSetExtractor
* @throws DataAccessException if the query fails
*/
@Nullable
<T> T query(String sql, SqlParameterSource paramSource, ResultSetExtractor<T> rse)
<T> @Nullable T query(String sql, SqlParameterSource paramSource, ResultSetExtractor<T> rse)
throws DataAccessException;
/**
@@ -139,8 +136,7 @@ public interface NamedParameterJdbcOperations {
* @return an arbitrary result object, as returned by the ResultSetExtractor
* @throws DataAccessException if the query fails
*/
@Nullable
<T> T query(String sql, Map<String, ?> paramMap, ResultSetExtractor<T> rse)
<T> @Nullable T query(String sql, Map<String, ?> paramMap, ResultSetExtractor<T> rse)
throws DataAccessException;
/**
@@ -154,8 +150,7 @@ public interface NamedParameterJdbcOperations {
* @return an arbitrary result object, as returned by the ResultSetExtractor
* @throws DataAccessException if the query fails
*/
@Nullable
<T> T query(String sql, ResultSetExtractor<T> rse) throws DataAccessException;
<T> @Nullable T query(String sql, ResultSetExtractor<T> rse) throws DataAccessException;
/**
* Query given SQL to create a prepared statement from SQL and a list of
@@ -277,8 +272,7 @@ public interface NamedParameterJdbcOperations {
* if the query does not return exactly one row
* @throws DataAccessException if the query fails
*/
@Nullable
<T> T queryForObject(String sql, SqlParameterSource paramSource, RowMapper<T> rowMapper)
<T> @Nullable T queryForObject(String sql, SqlParameterSource paramSource, RowMapper<T> rowMapper)
throws DataAccessException;
/**
@@ -295,8 +289,7 @@ public interface NamedParameterJdbcOperations {
* if the query does not return exactly one row
* @throws DataAccessException if the query fails
*/
@Nullable
<T> T queryForObject(String sql, Map<String, ?> paramMap, RowMapper<T> rowMapper)
<T> @Nullable T queryForObject(String sql, Map<String, ?> paramMap, RowMapper<T> rowMapper)
throws DataAccessException;
/**
@@ -316,8 +309,7 @@ public interface NamedParameterJdbcOperations {
* @see org.springframework.jdbc.core.JdbcTemplate#queryForObject(String, Class)
* @see org.springframework.jdbc.core.SingleColumnRowMapper
*/
@Nullable
<T> T queryForObject(String sql, SqlParameterSource paramSource, Class<T> requiredType)
<T> @Nullable T queryForObject(String sql, SqlParameterSource paramSource, Class<T> requiredType)
throws DataAccessException;
/**
@@ -337,8 +329,7 @@ public interface NamedParameterJdbcOperations {
* @throws DataAccessException if the query fails
* @see org.springframework.jdbc.core.JdbcTemplate#queryForObject(String, Class)
*/
@Nullable
<T> T queryForObject(String sql, Map<String, ?> paramMap, Class<T> requiredType)
<T> @Nullable T queryForObject(String sql, Map<String, ?> paramMap, Class<T> requiredType)
throws DataAccessException;
/**

View File

@@ -25,6 +25,8 @@ import java.util.stream.Stream;
import javax.sql.DataSource;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.support.DataAccessUtils;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
@@ -42,7 +44,6 @@ import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.core.SqlRowSetResultSetExtractor;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ConcurrentLruCache;
@@ -149,46 +150,40 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
@Override
@Nullable
public <T> T execute(String sql, SqlParameterSource paramSource, PreparedStatementCallback<T> action)
public <T> @Nullable T execute(String sql, SqlParameterSource paramSource, PreparedStatementCallback<T> action)
throws DataAccessException {
return getJdbcOperations().execute(getPreparedStatementCreator(sql, paramSource), action);
}
@Override
@Nullable
public <T> T execute(String sql, Map<String, ?> paramMap, PreparedStatementCallback<T> action)
public <T> @Nullable T execute(String sql, Map<String, ?> paramMap, PreparedStatementCallback<T> action)
throws DataAccessException {
return execute(sql, new MapSqlParameterSource(paramMap), action);
}
@Override
@Nullable
public <T> T execute(String sql, PreparedStatementCallback<T> action) throws DataAccessException {
public <T> @Nullable T execute(String sql, PreparedStatementCallback<T> action) throws DataAccessException {
return execute(sql, EmptySqlParameterSource.INSTANCE, action);
}
@Override
@Nullable
public <T> T query(String sql, SqlParameterSource paramSource, ResultSetExtractor<T> rse)
public <T> @Nullable T query(String sql, SqlParameterSource paramSource, ResultSetExtractor<T> rse)
throws DataAccessException {
return getJdbcOperations().query(getPreparedStatementCreator(sql, paramSource), rse);
}
@Override
@Nullable
public <T> T query(String sql, Map<String, ?> paramMap, ResultSetExtractor<T> rse)
public <T> @Nullable T query(String sql, Map<String, ?> paramMap, ResultSetExtractor<T> rse)
throws DataAccessException {
return query(sql, new MapSqlParameterSource(paramMap), rse);
}
@Override
@Nullable
public <T> T query(String sql, ResultSetExtractor<T> rse) throws DataAccessException {
public <T> @Nullable T query(String sql, ResultSetExtractor<T> rse) throws DataAccessException {
return query(sql, EmptySqlParameterSource.INSTANCE, rse);
}
@@ -245,8 +240,7 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
}
@Override
@Nullable
public <T> T queryForObject(String sql, SqlParameterSource paramSource, RowMapper<T> rowMapper)
public <T> @Nullable T queryForObject(String sql, SqlParameterSource paramSource, RowMapper<T> rowMapper)
throws DataAccessException {
List<T> results = getJdbcOperations().query(getPreparedStatementCreator(sql, paramSource), rowMapper);
@@ -254,24 +248,21 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
}
@Override
@Nullable
public <T> T queryForObject(String sql, Map<String, ?> paramMap, RowMapper<T>rowMapper)
public <T> @Nullable T queryForObject(String sql, Map<String, ?> paramMap, RowMapper<T>rowMapper)
throws DataAccessException {
return queryForObject(sql, new MapSqlParameterSource(paramMap), rowMapper);
}
@Override
@Nullable
public <T> T queryForObject(String sql, SqlParameterSource paramSource, Class<T> requiredType)
public <T> @Nullable T queryForObject(String sql, SqlParameterSource paramSource, Class<T> requiredType)
throws DataAccessException {
return queryForObject(sql, paramSource, new SingleColumnRowMapper<>(requiredType));
}
@Override
@Nullable
public <T> T queryForObject(String sql, Map<String, ?> paramMap, Class<T> requiredType)
public <T> @Nullable T queryForObject(String sql, Map<String, ?> paramMap, Class<T> requiredType)
throws DataAccessException {
return queryForObject(sql, paramMap, new SingleColumnRowMapper<>(requiredType));
@@ -351,7 +342,7 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
@Override
public int update(
String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHolder, @Nullable String[] keyColumnNames)
String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHolder, String @Nullable [] keyColumnNames)
throws DataAccessException {
PreparedStatementCreator psc = getPreparedStatementCreator(sql, paramSource, pscf -> {
@@ -401,7 +392,7 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
@Override
public int[] batchUpdate(String sql, SqlParameterSource[] batchArgs, KeyHolder generatedKeyHolder,
@Nullable String[] keyColumnNames) {
String @Nullable [] keyColumnNames) {
if (batchArgs.length == 0) {
return new int[0];

View File

@@ -22,10 +22,11 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.core.SqlParameterValue;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -387,8 +388,7 @@ public abstract class NamedParameterUtils {
* @param paramIndex the index of the desired parameter
* @return the declared SqlParameter, or {@code null} if none found
*/
@Nullable
private static SqlParameter findParameter(
private static @Nullable SqlParameter findParameter(
@Nullable List<SqlParameter> declaredParams, String paramName, int paramIndex) {
if (declaredParams != null) {

View File

@@ -21,9 +21,10 @@ import java.lang.reflect.Field;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeanUtils;
import org.springframework.jdbc.core.StatementCreatorUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
@@ -72,8 +73,7 @@ public class SimplePropertySqlParameterSource extends AbstractSqlParameterSource
}
@Override
@Nullable
public Object getValue(String paramName) throws IllegalArgumentException {
public @Nullable Object getValue(String paramName) throws IllegalArgumentException {
Object desc = getDescriptor(paramName);
if (desc instanceof PropertyDescriptor pd) {
ReflectionUtils.makeAccessible(pd.getReadMethod());

View File

@@ -16,8 +16,9 @@
package org.springframework.jdbc.core.namedparam;
import org.jspecify.annotations.Nullable;
import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.lang.Nullable;
/**
* Interface that defines common functionality for objects that can
@@ -63,8 +64,7 @@ public interface SqlParameterSource {
* @return the value of the specified parameter
* @throws IllegalArgumentException if there is no value for the requested parameter
*/
@Nullable
Object getValue(String paramName) throws IllegalArgumentException;
@Nullable Object getValue(String paramName) throws IllegalArgumentException;
/**
* Determine the SQL type for the specified named parameter.
@@ -83,8 +83,7 @@ public interface SqlParameterSource {
* @return the type name of the specified parameter,
* or {@code null} if not known
*/
@Nullable
default String getTypeName(String paramName) {
default @Nullable String getTypeName(String paramName) {
return null;
}
@@ -97,8 +96,7 @@ public interface SqlParameterSource {
* @since 5.0.3
* @see SqlParameterSourceUtils#extractCaseInsensitiveParameterNames
*/
@Nullable
default String[] getParameterNames() {
default String @Nullable [] getParameterNames() {
return null;
}

View File

@@ -22,8 +22,9 @@ import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.jspecify.annotations.Nullable;
import org.springframework.jdbc.core.SqlParameterValue;
import org.springframework.lang.Nullable;
/**
* Class that provides helper methods for the use of {@link SqlParameterSource},
@@ -95,8 +96,7 @@ public abstract class SqlParameterSourceUtils {
* @return the value object
* @see SqlParameterValue
*/
@Nullable
public static Object getTypedValue(SqlParameterSource source, String parameterName) {
public static @Nullable Object getTypedValue(SqlParameterSource source, String parameterName) {
int sqlType = source.getSqlType(parameterName);
if (sqlType != SqlParameterSource.TYPE_UNKNOWN) {
return new SqlParameterValue(sqlType, source.getTypeName(parameterName), source.getValue(parameterName));

View File

@@ -10,9 +10,7 @@
* the {@code getJdbcOperations()} method of NamedParameterJdbcTemplate and
* work with the returned classic template, or use a JdbcTemplate instance directly.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.jdbc.core.namedparam;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -2,9 +2,7 @@
* Provides the core JDBC framework, based on JdbcTemplate
* and its associated callback interfaces and helper objects.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.jdbc.core;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -26,6 +26,7 @@ import javax.sql.DataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.jdbc.core.CallableStatementCreator;
@@ -35,7 +36,6 @@ import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.core.metadata.CallMetaDataContext;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -73,15 +73,13 @@ public abstract class AbstractJdbcCall {
private volatile boolean compiled;
/** The generated string used for call statement. */
@Nullable
private String callString;
private @Nullable String callString;
/**
* A delegate enabling us to create CallableStatementCreators
* efficiently, based on this class's declared parameters.
*/
@Nullable
private CallableStatementCreatorFactory callableStatementFactory;
private @Nullable CallableStatementCreatorFactory callableStatementFactory;
/**
@@ -119,8 +117,7 @@ public abstract class AbstractJdbcCall {
/**
* Get the name of the stored procedure.
*/
@Nullable
public String getProcedureName() {
public @Nullable String getProcedureName() {
return this.callMetaDataContext.getProcedureName();
}
@@ -148,8 +145,7 @@ public abstract class AbstractJdbcCall {
/**
* Get the catalog name used.
*/
@Nullable
public String getCatalogName() {
public @Nullable String getCatalogName() {
return this.callMetaDataContext.getCatalogName();
}
@@ -163,8 +159,7 @@ public abstract class AbstractJdbcCall {
/**
* Get the schema name used.
*/
@Nullable
public String getSchemaName() {
public @Nullable String getSchemaName() {
return this.callMetaDataContext.getSchemaName();
}
@@ -226,8 +221,7 @@ public abstract class AbstractJdbcCall {
/**
* Get the call string that should be used based on parameters and meta-data.
*/
@Nullable
public String getCallString() {
public @Nullable String getCallString() {
return this.callString;
}
@@ -417,8 +411,7 @@ public abstract class AbstractJdbcCall {
* Get the name of a single out parameter or return value.
* Used for functions or procedures with one out parameter.
*/
@Nullable
protected String getScalarOutParameterName() {
protected @Nullable String getScalarOutParameterName() {
return this.callMetaDataContext.getScalarOutParameterName();
}

View File

@@ -33,6 +33,7 @@ import javax.sql.DataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
@@ -47,7 +48,6 @@ import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.JdbcUtils;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -131,8 +131,7 @@ public abstract class AbstractJdbcInsert {
/**
* Get the name of the table for this insert.
*/
@Nullable
public String getTableName() {
public @Nullable String getTableName() {
return this.tableMetaDataContext.getTableName();
}
@@ -147,8 +146,7 @@ public abstract class AbstractJdbcInsert {
/**
* Get the name of the schema for this insert.
*/
@Nullable
public String getSchemaName() {
public @Nullable String getSchemaName() {
return this.tableMetaDataContext.getSchemaName();
}
@@ -163,8 +161,7 @@ public abstract class AbstractJdbcInsert {
/**
* Get the name of the catalog for this insert.
*/
@Nullable
public String getCatalogName() {
public @Nullable String getCatalogName() {
return this.tableMetaDataContext.getCatalogName();
}
@@ -616,7 +613,7 @@ public abstract class AbstractJdbcInsert {
* @param preparedStatement the PreparedStatement
* @param values the values to be set
*/
private void setParameterValues(PreparedStatement preparedStatement, List<?> values, @Nullable int... columnTypes)
private void setParameterValues(PreparedStatement preparedStatement, List<?> values, int @Nullable ... columnTypes)
throws SQLException {
int colIndex = 0;

View File

@@ -25,6 +25,8 @@ import java.util.stream.Stream;
import javax.sql.DataSource;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeanUtils;
import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.core.JdbcTemplate;
@@ -43,7 +45,6 @@ import org.springframework.jdbc.core.namedparam.SimplePropertySqlParameterSource
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -268,7 +269,7 @@ final class DefaultJdbcClient implements JdbcClient {
return new PreparedStatementCreatorFactory(this.sql).newPreparedStatementCreator(this.indexedParams);
}
private PreparedStatementCreator statementCreatorForIndexedParamsWithKeys(@Nullable String[] keyColumnNames) {
private PreparedStatementCreator statementCreatorForIndexedParamsWithKeys(String @Nullable [] keyColumnNames) {
PreparedStatementCreatorFactory pscf = new PreparedStatementCreatorFactory(this.sql);
if (keyColumnNames != null) {
pscf.setGeneratedKeysColumnNames(keyColumnNames);

View File

@@ -26,6 +26,8 @@ import java.util.stream.Stream;
import javax.sql.DataSource;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.support.DataAccessUtils;
import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.core.ResultSetExtractor;
@@ -35,7 +37,6 @@ import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.lang.Nullable;
/**
* A fluent {@code JdbcClient} with common JDBC query and update operations,

View File

@@ -22,11 +22,12 @@ import java.util.Map;
import javax.sql.DataSource;
import org.jspecify.annotations.Nullable;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.lang.Nullable;
/**
* A SimpleJdbcCall is a multithreaded, reusable object representing a call
@@ -149,44 +150,38 @@ public class SimpleJdbcCall extends AbstractJdbcCall implements SimpleJdbcCallOp
}
@Override
@Nullable
@SuppressWarnings("unchecked")
public <T> T executeFunction(Class<T> returnType, Object... args) {
public <T> @Nullable T executeFunction(Class<T> returnType, Object... args) {
return (T) doExecute(args).get(getScalarOutParameterName());
}
@Override
@Nullable
@SuppressWarnings("unchecked")
public <T> T executeFunction(Class<T> returnType, Map<String, ?> args) {
public <T> @Nullable T executeFunction(Class<T> returnType, Map<String, ?> args) {
return (T) doExecute(args).get(getScalarOutParameterName());
}
@Override
@Nullable
@SuppressWarnings("unchecked")
public <T> T executeFunction(Class<T> returnType, SqlParameterSource args) {
public <T> @Nullable T executeFunction(Class<T> returnType, SqlParameterSource args) {
return (T) doExecute(args).get(getScalarOutParameterName());
}
@Override
@Nullable
@SuppressWarnings("unchecked")
public <T> T executeObject(Class<T> returnType, Object... args) {
public <T> @Nullable T executeObject(Class<T> returnType, Object... args) {
return (T) doExecute(args).get(getScalarOutParameterName());
}
@Override
@Nullable
@SuppressWarnings("unchecked")
public <T> T executeObject(Class<T> returnType, Map<String, ?> args) {
public <T> @Nullable T executeObject(Class<T> returnType, Map<String, ?> args) {
return (T) doExecute(args).get(getScalarOutParameterName());
}
@Override
@Nullable
@SuppressWarnings("unchecked")
public <T> T executeObject(Class<T> returnType, SqlParameterSource args) {
public <T> @Nullable T executeObject(Class<T> returnType, SqlParameterSource args) {
return (T) doExecute(args).get(getScalarOutParameterName());
}

View File

@@ -18,10 +18,11 @@ package org.springframework.jdbc.core.simple;
import java.util.Map;
import org.jspecify.annotations.Nullable;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.lang.Nullable;
/**
* Interface specifying the API for a Simple JDBC Call implemented by {@link SimpleJdbcCall}.
@@ -118,8 +119,7 @@ public interface SimpleJdbcCallOperations {
* Parameter values must be provided in the same order as the parameters are defined
* for the stored procedure.
*/
@Nullable
<T> T executeFunction(Class<T> returnType, Object... args);
<T> @Nullable T executeFunction(Class<T> returnType, Object... args);
/**
* Execute the stored function and return the results obtained as an Object of the
@@ -127,8 +127,7 @@ public interface SimpleJdbcCallOperations {
* @param returnType the type of the value to return
* @param args a Map containing the parameter values to be used in the call
*/
@Nullable
<T> T executeFunction(Class<T> returnType, Map<String, ?> args);
<T> @Nullable T executeFunction(Class<T> returnType, Map<String, ?> args);
/**
* Execute the stored function and return the results obtained as an Object of the
@@ -136,8 +135,7 @@ public interface SimpleJdbcCallOperations {
* @param returnType the type of the value to return
* @param args the MapSqlParameterSource containing the parameter values to be used in the call
*/
@Nullable
<T> T executeFunction(Class<T> returnType, SqlParameterSource args);
<T> @Nullable T executeFunction(Class<T> returnType, SqlParameterSource args);
/**
* Execute the stored procedure and return the single out parameter as an Object
@@ -148,8 +146,7 @@ public interface SimpleJdbcCallOperations {
* Parameter values must be provided in the same order as the parameters are defined for
* the stored procedure.
*/
@Nullable
<T> T executeObject(Class<T> returnType, Object... args);
<T> @Nullable T executeObject(Class<T> returnType, Object... args);
/**
* Execute the stored procedure and return the single out parameter as an Object
@@ -158,8 +155,7 @@ public interface SimpleJdbcCallOperations {
* @param returnType the type of the value to return
* @param args a Map containing the parameter values to be used in the call
*/
@Nullable
<T> T executeObject(Class<T> returnType, Map<String, ?> args);
<T> @Nullable T executeObject(Class<T> returnType, Map<String, ?> args);
/**
* Execute the stored procedure and return the single out parameter as an Object
@@ -168,8 +164,7 @@ public interface SimpleJdbcCallOperations {
* @param returnType the type of the value to return
* @param args the MapSqlParameterSource containing the parameter values to be used in the call
*/
@Nullable
<T> T executeObject(Class<T> returnType, SqlParameterSource args);
<T> @Nullable T executeObject(Class<T> returnType, SqlParameterSource args);
/**
* Execute the stored procedure and return a map of output params, keyed by name

View File

@@ -8,9 +8,7 @@
* meta-data provided by the JDBC driver to simplify the application code. Much of the
* parameter specification becomes unnecessary since it can be looked up in the meta-data.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.jdbc.core.simple;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -20,12 +20,13 @@ import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.jdbc.LobRetrievalFailureException;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.lang.Nullable;
/**
* Abstract ResultSetExtractor implementation that assumes streaming of LOB data.
@@ -70,8 +71,7 @@ public abstract class AbstractLobStreamingResultSetExtractor<T> implements Resul
* @see org.springframework.jdbc.LobRetrievalFailureException
*/
@Override
@Nullable
public final T extractData(ResultSet rs) throws SQLException, DataAccessException {
public final @Nullable T extractData(ResultSet rs) throws SQLException, DataAccessException {
if (!rs.next()) {
handleNoRowFound();
}

View File

@@ -20,8 +20,9 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.jspecify.annotations.Nullable;
import org.springframework.jdbc.core.SqlTypeValue;
import org.springframework.lang.Nullable;
/**
* Abstract implementation of the SqlTypeValue interface, for convenient

View File

@@ -20,9 +20,10 @@ import java.util.Properties;
import javax.sql.DataSource;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -49,8 +50,7 @@ public class JdbcBeanDefinitionReader {
private final org.springframework.beans.factory.support.PropertiesBeanDefinitionReader propReader;
@Nullable
private JdbcTemplate jdbcTemplate;
private @Nullable JdbcTemplate jdbcTemplate;
/**

View File

@@ -20,12 +20,13 @@ import java.sql.Connection;
import javax.sql.DataSource;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.support.DaoSupport;
import org.springframework.jdbc.CannotGetJdbcConnectionException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceUtils;
import org.springframework.jdbc.support.SQLExceptionTranslator;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -47,8 +48,7 @@ import org.springframework.util.Assert;
*/
public abstract class JdbcDaoSupport extends DaoSupport {
@Nullable
private JdbcTemplate jdbcTemplate;
private @Nullable JdbcTemplate jdbcTemplate;
/**
@@ -77,8 +77,7 @@ public abstract class JdbcDaoSupport extends DaoSupport {
/**
* Return the JDBC DataSource used by this DAO.
*/
@Nullable
public final DataSource getDataSource() {
public final @Nullable DataSource getDataSource() {
return (this.jdbcTemplate != null ? this.jdbcTemplate.getDataSource() : null);
}
@@ -95,8 +94,7 @@ public abstract class JdbcDaoSupport extends DaoSupport {
* Return the JdbcTemplate for this DAO,
* pre-initialized with the DataSource or set explicitly.
*/
@Nullable
public final JdbcTemplate getJdbcTemplate() {
public final @Nullable JdbcTemplate getJdbcTemplate() {
return this.jdbcTemplate;
}

View File

@@ -23,10 +23,11 @@ import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
import org.jspecify.annotations.Nullable;
import org.springframework.core.io.InputStreamSource;
import org.springframework.core.io.Resource;
import org.springframework.jdbc.core.SqlTypeValue;
import org.springframework.lang.Nullable;
/**
* Object to represent a binary parameter value for a SQL statement, for example,

View File

@@ -24,8 +24,9 @@ import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
import org.jspecify.annotations.Nullable;
import org.springframework.jdbc.core.SqlTypeValue;
import org.springframework.lang.Nullable;
/**
* Object to represent a character-based parameter value for a SQL statement,

View File

@@ -22,11 +22,12 @@ import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Types;
import org.jspecify.annotations.Nullable;
import org.springframework.jdbc.core.DisposableSqlTypeValue;
import org.springframework.jdbc.support.lob.DefaultLobHandler;
import org.springframework.jdbc.support.lob.LobCreator;
import org.springframework.jdbc.support.lob.LobHandler;
import org.springframework.lang.Nullable;
/**
* Object to represent an SQL BLOB/CLOB value parameter. BLOBs can either be an
@@ -73,8 +74,7 @@ import org.springframework.lang.Nullable;
@Deprecated(since = "6.2")
public class SqlLobValue implements DisposableSqlTypeValue {
@Nullable
private final Object content;
private final @Nullable Object content;
private final int length;
@@ -90,7 +90,7 @@ public class SqlLobValue implements DisposableSqlTypeValue {
* @param bytes the byte array containing the BLOB value
* @see org.springframework.jdbc.support.lob.DefaultLobHandler
*/
public SqlLobValue(@Nullable byte[] bytes) {
public SqlLobValue(byte @Nullable [] bytes) {
this(bytes, new DefaultLobHandler());
}
@@ -99,7 +99,7 @@ public class SqlLobValue implements DisposableSqlTypeValue {
* @param bytes the byte array containing the BLOB value
* @param lobHandler the LobHandler to be used
*/
public SqlLobValue(@Nullable byte[] bytes, LobHandler lobHandler) {
public SqlLobValue(byte @Nullable [] bytes, LobHandler lobHandler) {
this.content = bytes;
this.length = (bytes != null ? bytes.length : 0);
this.lobCreator = lobHandler.getLobCreator();

View File

@@ -2,9 +2,7 @@
* Classes supporting the {@code org.springframework.jdbc.core} package.
* Contains a DAO base class for JdbcTemplate usage.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.jdbc.core.support;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -20,7 +20,7 @@ import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Abstract base class for JDBC {@link javax.sql.DataSource} implementations
@@ -33,23 +33,17 @@ import org.springframework.lang.Nullable;
*/
public abstract class AbstractDriverBasedDataSource extends AbstractDataSource {
@Nullable
private String url;
private @Nullable String url;
@Nullable
private String username;
private @Nullable String username;
@Nullable
private String password;
private @Nullable String password;
@Nullable
private String catalog;
private @Nullable String catalog;
@Nullable
private String schema;
private @Nullable String schema;
@Nullable
private Properties connectionProperties;
private @Nullable Properties connectionProperties;
/**
@@ -63,8 +57,7 @@ public abstract class AbstractDriverBasedDataSource extends AbstractDataSource {
/**
* Return the JDBC URL to use for connecting through the Driver.
*/
@Nullable
public String getUrl() {
public @Nullable String getUrl() {
return this.url;
}
@@ -79,8 +72,7 @@ public abstract class AbstractDriverBasedDataSource extends AbstractDataSource {
/**
* Return the JDBC username to use for connecting through the Driver.
*/
@Nullable
public String getUsername() {
public @Nullable String getUsername() {
return this.username;
}
@@ -95,8 +87,7 @@ public abstract class AbstractDriverBasedDataSource extends AbstractDataSource {
/**
* Return the JDBC password to use for connecting through the Driver.
*/
@Nullable
public String getPassword() {
public @Nullable String getPassword() {
return this.password;
}
@@ -113,8 +104,7 @@ public abstract class AbstractDriverBasedDataSource extends AbstractDataSource {
* Return the database catalog to be applied to each Connection, if any.
* @since 4.3.2
*/
@Nullable
public String getCatalog() {
public @Nullable String getCatalog() {
return this.catalog;
}
@@ -131,8 +121,7 @@ public abstract class AbstractDriverBasedDataSource extends AbstractDataSource {
* Return the database schema to be applied to each Connection, if any.
* @since 4.3.2
*/
@Nullable
public String getSchema() {
public @Nullable String getSchema() {
return this.schema;
}
@@ -151,8 +140,7 @@ public abstract class AbstractDriverBasedDataSource extends AbstractDataSource {
/**
* Return the connection properties to be passed to the Driver, if any.
*/
@Nullable
public Properties getConnectionProperties() {
public @Nullable Properties getConnectionProperties() {
return this.connectionProperties;
}

View File

@@ -20,7 +20,8 @@ import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Savepoint;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.transaction.support.ResourceHolderSupport;
import org.springframework.util.Assert;
@@ -47,16 +48,13 @@ public class ConnectionHolder extends ResourceHolderSupport {
public static final String SAVEPOINT_NAME_PREFIX = "SAVEPOINT_";
@Nullable
private ConnectionHandle connectionHandle;
private @Nullable ConnectionHandle connectionHandle;
@Nullable
private Connection currentConnection;
private @Nullable Connection currentConnection;
private boolean transactionActive = false;
@Nullable
private Boolean savepointsSupported;
private @Nullable Boolean savepointsSupported;
private int savepointCounter = 0;
@@ -99,8 +97,7 @@ public class ConnectionHolder extends ResourceHolderSupport {
/**
* Return the ConnectionHandle held by this ConnectionHolder.
*/
@Nullable
public ConnectionHandle getConnectionHandle() {
public @Nullable ConnectionHandle getConnectionHandle() {
return this.connectionHandle;
}

View File

@@ -22,8 +22,9 @@ import java.sql.Statement;
import javax.sql.DataSource;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.lang.Nullable;
import org.springframework.transaction.CannotCreateTransactionException;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionSystemException;
@@ -121,8 +122,7 @@ import org.springframework.util.Assert;
public class DataSourceTransactionManager extends AbstractPlatformTransactionManager
implements ResourceTransactionManager, InitializingBean {
@Nullable
private DataSource dataSource;
private @Nullable DataSource dataSource;
private boolean enforceReadOnly = false;
@@ -180,8 +180,7 @@ public class DataSourceTransactionManager extends AbstractPlatformTransactionMan
/**
* Return the JDBC {@code DataSource} that this instance manages transactions for.
*/
@Nullable
public DataSource getDataSource() {
public @Nullable DataSource getDataSource() {
return this.dataSource;
}

View File

@@ -24,9 +24,9 @@ import javax.sql.DataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.jdbc.CannotGetJdbcConnectionException;
import org.springframework.lang.Nullable;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.support.TransactionSynchronization;
import org.springframework.transaction.support.TransactionSynchronizationManager;
@@ -174,8 +174,7 @@ public abstract class DataSourceUtils {
* @see Connection#setTransactionIsolation
* @see Connection#setReadOnly
*/
@Nullable
public static Integer prepareConnectionForTransaction(Connection con, @Nullable TransactionDefinition definition)
public static @Nullable Integer prepareConnectionForTransaction(Connection con, @Nullable TransactionDefinition definition)
throws SQLException {
Assert.notNull(con, "No Connection specified");

View File

@@ -25,8 +25,9 @@ import java.util.logging.Logger;
import javax.sql.DataSource;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -43,8 +44,7 @@ import org.springframework.util.Assert;
*/
public class DelegatingDataSource implements DataSource, InitializingBean {
@Nullable
private DataSource targetDataSource;
private @Nullable DataSource targetDataSource;
/**
@@ -73,8 +73,7 @@ public class DelegatingDataSource implements DataSource, InitializingBean {
/**
* Return the target DataSource that this DataSource should delegate to.
*/
@Nullable
public DataSource getTargetDataSource() {
public @Nullable DataSource getTargetDataSource() {
return this.targetDataSource;
}

View File

@@ -20,7 +20,8 @@ import java.sql.Connection;
import java.sql.SQLException;
import java.util.Map;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.util.Assert;
@@ -69,8 +70,7 @@ public class IsolationLevelDataSourceAdapter extends UserCredentialsDataSourceAd
);
@Nullable
private Integer isolationLevel;
private @Nullable Integer isolationLevel;
/**
@@ -122,8 +122,7 @@ public class IsolationLevelDataSourceAdapter extends UserCredentialsDataSourceAd
* Return the statically specified isolation level,
* or {@code null} if none.
*/
@Nullable
protected Integer getIsolationLevel() {
protected @Nullable Integer getIsolationLevel() {
return this.isolationLevel;
}
@@ -155,8 +154,7 @@ public class IsolationLevelDataSourceAdapter extends UserCredentialsDataSourceAd
* @see org.springframework.transaction.support.TransactionSynchronizationManager#getCurrentTransactionIsolationLevel()
* @see #setIsolationLevel
*/
@Nullable
protected Integer getCurrentIsolationLevel() {
protected @Nullable Integer getCurrentIsolationLevel() {
Integer isolationLevelToUse = TransactionSynchronizationManager.getCurrentTransactionIsolationLevel();
if (isolationLevelToUse == null) {
isolationLevelToUse = getIsolationLevel();
@@ -170,8 +168,7 @@ public class IsolationLevelDataSourceAdapter extends UserCredentialsDataSourceAd
* @return whether there is a read-only hint for the current scope
* @see org.springframework.transaction.support.TransactionSynchronizationManager#isCurrentTransactionReadOnly()
*/
@Nullable
protected Boolean getCurrentReadOnlyFlag() {
protected @Nullable Boolean getCurrentReadOnlyFlag() {
boolean txReadOnly = TransactionSynchronizationManager.isCurrentTransactionReadOnly();
return (txReadOnly ? Boolean.TRUE : null);
}

View File

@@ -20,7 +20,8 @@ import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.Savepoint;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.transaction.CannotCreateTransactionException;
import org.springframework.transaction.NestedTransactionNotSupportedException;
import org.springframework.transaction.SavepointManager;
@@ -46,11 +47,9 @@ import org.springframework.util.Assert;
*/
public abstract class JdbcTransactionObjectSupport implements SavepointManager, SmartTransactionObject {
@Nullable
private ConnectionHolder connectionHolder;
private @Nullable ConnectionHolder connectionHolder;
@Nullable
private Integer previousIsolationLevel;
private @Nullable Integer previousIsolationLevel;
private boolean readOnly = false;
@@ -89,8 +88,7 @@ public abstract class JdbcTransactionObjectSupport implements SavepointManager,
/**
* Return the retained previous isolation level, if any.
*/
@Nullable
public Integer getPreviousIsolationLevel() {
public @Nullable Integer getPreviousIsolationLevel() {
return this.previousIsolationLevel;
}

View File

@@ -29,8 +29,8 @@ import javax.sql.DataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -104,14 +104,11 @@ public class LazyConnectionDataSourceProxy extends DelegatingDataSource {
private static final Log logger = LogFactory.getLog(LazyConnectionDataSourceProxy.class);
@Nullable
private DataSource readOnlyDataSource;
private @Nullable DataSource readOnlyDataSource;
@Nullable
private volatile Boolean defaultAutoCommit;
private volatile @Nullable Boolean defaultAutoCommit;
@Nullable
private volatile Integer defaultTransactionIsolation;
private volatile @Nullable Integer defaultTransactionIsolation;
/**
@@ -238,16 +235,14 @@ public class LazyConnectionDataSourceProxy extends DelegatingDataSource {
/**
* Expose the default auto-commit value.
*/
@Nullable
protected Boolean defaultAutoCommit() {
protected @Nullable Boolean defaultAutoCommit() {
return this.defaultAutoCommit;
}
/**
* Expose the default transaction isolation value.
*/
@Nullable
protected Integer defaultTransactionIsolation() {
protected @Nullable Integer defaultTransactionIsolation() {
return this.defaultTransactionIsolation;
}
@@ -295,17 +290,13 @@ public class LazyConnectionDataSourceProxy extends DelegatingDataSource {
*/
private class LazyConnectionInvocationHandler implements InvocationHandler {
@Nullable
private String username;
private @Nullable String username;
@Nullable
private String password;
private @Nullable String password;
@Nullable
private Boolean autoCommit;
private @Nullable Boolean autoCommit;
@Nullable
private Integer transactionIsolation;
private @Nullable Integer transactionIsolation;
private boolean readOnly = false;
@@ -313,8 +304,7 @@ public class LazyConnectionDataSourceProxy extends DelegatingDataSource {
private boolean closed = false;
@Nullable
private Connection target;
private @Nullable Connection target;
public LazyConnectionInvocationHandler() {
this.autoCommit = defaultAutoCommit();
@@ -328,8 +318,7 @@ public class LazyConnectionDataSourceProxy extends DelegatingDataSource {
}
@Override
@Nullable
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
public @Nullable Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
// Invocation on ConnectionProxy interface coming in...
switch (method.getName()) {

View File

@@ -23,7 +23,7 @@ import java.sql.ShardingKey;
import javax.sql.DataSource;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* An adapter for a target {@link DataSource}, designed to apply sharding keys, if specified,
@@ -53,8 +53,7 @@ import org.springframework.lang.Nullable;
*/
public class ShardingKeyDataSourceAdapter extends DelegatingDataSource {
@Nullable
private ShardingKeyProvider shardingkeyProvider;
private @Nullable ShardingKeyProvider shardingkeyProvider;
/**

View File

@@ -19,7 +19,7 @@ package org.springframework.jdbc.datasource;
import java.sql.SQLException;
import java.sql.ShardingKey;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Strategy interface for determining sharding keys which are used to establish direct
@@ -43,8 +43,7 @@ public interface ShardingKeyProvider {
* @return the sharding key, or {@code null} if it is not available or cannot be determined
* @throws SQLException if an error occurs while obtaining the sharding key
*/
@Nullable
ShardingKey getShardingKey() throws SQLException;
@Nullable ShardingKey getShardingKey() throws SQLException;
/**
* Determine the super sharding key, if any. This method returns the super sharding key
@@ -53,8 +52,7 @@ public interface ShardingKeyProvider {
* determined (the default)
* @throws SQLException if an error occurs while obtaining the super sharding key
*/
@Nullable
default ShardingKey getSuperShardingKey() throws SQLException {
default @Nullable ShardingKey getSuperShardingKey() throws SQLException {
return null;
}

View File

@@ -21,8 +21,9 @@ import java.sql.Driver;
import java.sql.SQLException;
import java.util.Properties;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeanUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -54,8 +55,7 @@ import org.springframework.util.Assert;
*/
public class SimpleDriverDataSource extends AbstractDriverBasedDataSource {
@Nullable
private Driver driver;
private @Nullable Driver driver;
/**
@@ -127,8 +127,7 @@ public class SimpleDriverDataSource extends AbstractDriverBasedDataSource {
/**
* Return the JDBC Driver instance to use.
*/
@Nullable
public Driver getDriver() {
public @Nullable Driver getDriver() {
return this.driver;
}

View File

@@ -25,8 +25,9 @@ import java.sql.SQLException;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
@@ -64,16 +65,13 @@ public class SingleConnectionDataSource extends DriverManagerDataSource
private boolean rollbackBeforeClose;
/** Override auto-commit state? */
@Nullable
private Boolean autoCommit;
private @Nullable Boolean autoCommit;
/** Wrapped Connection. */
@Nullable
private Connection target;
private @Nullable Connection target;
/** Proxy Connection. */
@Nullable
private Connection connection;
private @Nullable Connection connection;
/** Lifecycle lock for the shared Connection. */
private final Lock connectionLock = new ReentrantLock();
@@ -175,8 +173,7 @@ public class SingleConnectionDataSource extends DriverManagerDataSource
* Return whether the returned Connection's "autoCommit" setting should be overridden.
* @return the "autoCommit" value, or {@code null} if none to be applied
*/
@Nullable
protected Boolean getAutoCommitValue() {
protected @Nullable Boolean getAutoCommitValue() {
return this.autoCommit;
}
@@ -368,8 +365,7 @@ public class SingleConnectionDataSource extends DriverManagerDataSource
}
@Override
@Nullable
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
public @Nullable Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
// Invocation on ConnectionProxy interface coming in...
return switch (method.getName()) {

View File

@@ -26,7 +26,8 @@ import java.sql.Statement;
import javax.sql.DataSource;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.transaction.support.TransactionSynchronizationManager;
/**
@@ -180,8 +181,7 @@ public class TransactionAwareDataSourceProxy extends DelegatingDataSource {
private final DataSource targetDataSource;
@Nullable
private Connection target;
private @Nullable Connection target;
private boolean closed = false;
@@ -190,8 +190,7 @@ public class TransactionAwareDataSourceProxy extends DelegatingDataSource {
}
@Override
@Nullable
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
public @Nullable Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
// Invocation on ConnectionProxy interface coming in...
switch (method.getName()) {

View File

@@ -19,8 +19,9 @@ package org.springframework.jdbc.datasource;
import java.sql.Connection;
import java.sql.SQLException;
import org.jspecify.annotations.Nullable;
import org.springframework.core.NamedThreadLocal;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -62,17 +63,13 @@ import org.springframework.util.StringUtils;
*/
public class UserCredentialsDataSourceAdapter extends DelegatingDataSource {
@Nullable
private String username;
private @Nullable String username;
@Nullable
private String password;
private @Nullable String password;
@Nullable
private String catalog;
private @Nullable String catalog;
@Nullable
private String schema;
private @Nullable String schema;
private final ThreadLocal<JdbcUserCredentials> threadBoundCredentials =
new NamedThreadLocal<>("Current JDBC user credentials");

View File

@@ -23,8 +23,7 @@ import javax.sql.DataSource;
import org.apache.commons.logging.LogFactory;
import org.apache.derby.jdbc.EmbeddedDriver;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* {@link EmbeddedDatabaseConfigurer} for the Apache Derby database.
@@ -39,8 +38,7 @@ final class DerbyEmbeddedDatabaseConfigurer implements EmbeddedDatabaseConfigure
private static final String URL_TEMPLATE = "jdbc:derby:memory:%s;%s";
@Nullable
private static DerbyEmbeddedDatabaseConfigurer instance;
private static @Nullable DerbyEmbeddedDatabaseConfigurer instance;
/**

View File

@@ -26,11 +26,11 @@ import javax.sql.DataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
import org.springframework.jdbc.datasource.init.DatabasePopulator;
import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -80,14 +80,11 @@ public class EmbeddedDatabaseFactory {
private DataSourceFactory dataSourceFactory = new SimpleDriverDataSourceFactory();
@Nullable
private EmbeddedDatabaseConfigurer databaseConfigurer;
private @Nullable EmbeddedDatabaseConfigurer databaseConfigurer;
@Nullable
private DatabasePopulator databasePopulator;
private @Nullable DatabasePopulator databasePopulator;
@Nullable
private DataSource dataSource;
private @Nullable DataSource dataSource;
/**
@@ -248,8 +245,7 @@ public class EmbeddedDatabaseFactory {
* or if the database has been shut down. Subclasses may call this method to
* access the {@code DataSource} instance directly.
*/
@Nullable
protected final DataSource getDataSource() {
protected final @Nullable DataSource getDataSource() {
return this.dataSource;
}

View File

@@ -18,12 +18,13 @@ package org.springframework.jdbc.datasource.embedded;
import javax.sql.DataSource;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.jdbc.datasource.init.DatabasePopulator;
import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils;
import org.springframework.lang.Nullable;
/**
* A subclass of {@link EmbeddedDatabaseFactory} that implements {@link FactoryBean}
@@ -44,8 +45,7 @@ import org.springframework.lang.Nullable;
public class EmbeddedDatabaseFactoryBean extends EmbeddedDatabaseFactory
implements FactoryBean<DataSource>, InitializingBean, DisposableBean {
@Nullable
private DatabasePopulator databaseCleaner;
private @Nullable DatabasePopulator databaseCleaner;
/**
@@ -66,8 +66,7 @@ public class EmbeddedDatabaseFactoryBean extends EmbeddedDatabaseFactory
@Override
@Nullable
public DataSource getObject() {
public @Nullable DataSource getObject() {
return getDataSource();
}

View File

@@ -18,10 +18,11 @@ package org.springframework.jdbc.datasource.embedded;
import java.util.Collections;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.hint.ExecutableMode;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.lang.Nullable;
/**
* {@link RuntimeHintsRegistrar} implementation that registers reflection hints

View File

@@ -18,7 +18,8 @@ package org.springframework.jdbc.datasource.embedded;
import java.sql.Driver;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.util.ClassUtils;
/**
@@ -33,8 +34,7 @@ import org.springframework.util.ClassUtils;
*/
final class H2EmbeddedDatabaseConfigurer extends AbstractEmbeddedDatabaseConfigurer {
@Nullable
private static H2EmbeddedDatabaseConfigurer instance;
private static @Nullable H2EmbeddedDatabaseConfigurer instance;
private final Class<? extends Driver> driverClass;

View File

@@ -18,7 +18,8 @@ package org.springframework.jdbc.datasource.embedded;
import java.sql.Driver;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.util.ClassUtils;
/**
@@ -32,8 +33,7 @@ import org.springframework.util.ClassUtils;
*/
final class HsqlEmbeddedDatabaseConfigurer extends AbstractEmbeddedDatabaseConfigurer {
@Nullable
private static HsqlEmbeddedDatabaseConfigurer instance;
private static @Nullable HsqlEmbeddedDatabaseConfigurer instance;
private final Class<? extends Driver> driverClass;

View File

@@ -1,9 +1,7 @@
/**
* Provides extensible support for creating embedded database instances.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.jdbc.datasource.embedded;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -18,9 +18,10 @@ package org.springframework.jdbc.datasource.init;
import javax.sql.DataSource;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -35,14 +36,11 @@ import org.springframework.util.Assert;
*/
public class DataSourceInitializer implements InitializingBean, DisposableBean {
@Nullable
private DataSource dataSource;
private @Nullable DataSource dataSource;
@Nullable
private DatabasePopulator databasePopulator;
private @Nullable DatabasePopulator databasePopulator;
@Nullable
private DatabasePopulator databaseCleaner;
private @Nullable DatabasePopulator databaseCleaner;
private boolean enabled = true;

View File

@@ -23,9 +23,10 @@ import java.util.List;
import javax.sql.DataSource;
import org.jspecify.annotations.Nullable;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -57,8 +58,7 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
List<Resource> scripts = new ArrayList<>();
@Nullable
private String sqlScriptEncoding;
private @Nullable String sqlScriptEncoding;
private String separator = ScriptUtils.DEFAULT_STATEMENT_SEPARATOR;

View File

@@ -16,8 +16,9 @@
package org.springframework.jdbc.datasource.init;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.DataAccessException;
import org.springframework.lang.Nullable;
/**
* Root of the hierarchy of data access exceptions that are related to processing

View File

@@ -16,8 +16,9 @@
package org.springframework.jdbc.datasource.init;
import org.jspecify.annotations.Nullable;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.lang.Nullable;
/**
* Thrown by {@link ScriptUtils} if an SQL script cannot be properly parsed.

Some files were not shown because too many files have changed in this diff Show More