Specify generic type nullness in spring-jdbc

See gh-34140
This commit is contained in:
Sébastien Deleuze
2025-01-13 20:52:40 +01:00
parent 4c988146bc
commit 8299a617b9
13 changed files with 54 additions and 47 deletions

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2024 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -261,7 +261,7 @@ public class BeanPropertyRowMapper<T> implements RowMapper<T> {
* @param propertyName the property name (as used by property descriptors) * @param propertyName the property name (as used by property descriptors)
* @since 5.3.9 * @since 5.3.9
*/ */
protected void suppressProperty(String propertyName) { protected void suppressProperty(@Nullable String propertyName) {
if (this.mappedProperties != null) { if (this.mappedProperties != null) {
this.mappedProperties.remove(lowerCaseName(propertyName)); this.mappedProperties.remove(lowerCaseName(propertyName));
this.mappedProperties.remove(underscoreName(propertyName)); this.mappedProperties.remove(underscoreName(propertyName));
@@ -296,7 +296,10 @@ public class BeanPropertyRowMapper<T> implements RowMapper<T> {
* @since 4.2 * @since 4.2
* @see #underscoreName * @see #underscoreName
*/ */
protected String lowerCaseName(String name) { protected String lowerCaseName(@Nullable String name) {
if (!StringUtils.hasLength(name)) {
return "";
}
return name.toLowerCase(Locale.US); return name.toLowerCase(Locale.US);
} }
@@ -308,7 +311,7 @@ public class BeanPropertyRowMapper<T> implements RowMapper<T> {
* @since 4.2 * @since 4.2
* @see JdbcUtils#convertPropertyNameToUnderscoreName * @see JdbcUtils#convertPropertyNameToUnderscoreName
*/ */
protected String underscoreName(String name) { protected String underscoreName(@Nullable String name) {
return JdbcUtils.convertPropertyNameToUnderscoreName(name); return JdbcUtils.convertPropertyNameToUnderscoreName(name);
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -64,7 +64,7 @@ public class DataClassRowMapper<T> extends BeanPropertyRowMapper<T> {
private @Nullable Constructor<T> mappedConstructor; private @Nullable Constructor<T> mappedConstructor;
private String @Nullable [] constructorParameterNames; private @Nullable String @Nullable [] constructorParameterNames;
private TypeDescriptor @Nullable [] constructorParameterTypes; private TypeDescriptor @Nullable [] constructorParameterTypes;
@@ -108,7 +108,7 @@ public class DataClassRowMapper<T> extends BeanPropertyRowMapper<T> {
protected T constructMappedInstance(ResultSet rs, TypeConverter tc) throws SQLException { protected T constructMappedInstance(ResultSet rs, TypeConverter tc) throws SQLException {
Assert.state(this.mappedConstructor != null, "Mapped constructor was not initialized"); Assert.state(this.mappedConstructor != null, "Mapped constructor was not initialized");
Object[] args; @Nullable Object[] args;
if (this.constructorParameterNames != null && this.constructorParameterTypes != null) { if (this.constructorParameterNames != null && this.constructorParameterTypes != null) {
args = new Object[this.constructorParameterNames.length]; args = new Object[this.constructorParameterNames.length];
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -154,7 +154,7 @@ public class PreparedStatementCreatorFactory {
* Return a new PreparedStatementSetter for the given parameters. * Return a new PreparedStatementSetter for the given parameters.
* @param params the parameter array (may be {@code null}) * @param params the parameter array (may be {@code null})
*/ */
public PreparedStatementSetter newPreparedStatementSetter(Object @Nullable [] params) { public PreparedStatementSetter newPreparedStatementSetter(@Nullable Object @Nullable [] params) {
return new PreparedStatementCreatorImpl(params != null ? Arrays.asList(params) : Collections.emptyList()); return new PreparedStatementCreatorImpl(params != null ? Arrays.asList(params) : Collections.emptyList());
} }
@@ -162,7 +162,7 @@ public class PreparedStatementCreatorFactory {
* Return a new PreparedStatementCreator for the given parameters. * Return a new PreparedStatementCreator for the given parameters.
* @param params list of parameters (may be {@code null}) * @param params list of parameters (may be {@code null})
*/ */
public PreparedStatementCreator newPreparedStatementCreator(@Nullable List<?> params) { public PreparedStatementCreator newPreparedStatementCreator(@Nullable List<? extends @Nullable Object> params) {
return new PreparedStatementCreatorImpl(params != null ? params : Collections.emptyList()); return new PreparedStatementCreatorImpl(params != null ? params : Collections.emptyList());
} }
@@ -170,7 +170,7 @@ public class PreparedStatementCreatorFactory {
* Return a new PreparedStatementCreator for the given parameters. * Return a new PreparedStatementCreator for the given parameters.
* @param params the parameter array (may be {@code null}) * @param params the parameter array (may be {@code null})
*/ */
public PreparedStatementCreator newPreparedStatementCreator(Object @Nullable [] params) { public PreparedStatementCreator newPreparedStatementCreator(@Nullable Object @Nullable [] params) {
return new PreparedStatementCreatorImpl(params != null ? Arrays.asList(params) : Collections.emptyList()); return new PreparedStatementCreatorImpl(params != null ? Arrays.asList(params) : Collections.emptyList());
} }
@@ -180,7 +180,7 @@ public class PreparedStatementCreatorFactory {
* the factory's, for example because of named parameter expanding) * the factory's, for example because of named parameter expanding)
* @param params the parameter array (may be {@code null}) * @param params the parameter array (may be {@code null})
*/ */
public PreparedStatementCreator newPreparedStatementCreator(String sqlToUse, Object @Nullable [] params) { public PreparedStatementCreator newPreparedStatementCreator(String sqlToUse, @Nullable Object @Nullable [] params) {
return new PreparedStatementCreatorImpl( return new PreparedStatementCreatorImpl(
sqlToUse, (params != null ? Arrays.asList(params) : Collections.emptyList())); sqlToUse, (params != null ? Arrays.asList(params) : Collections.emptyList()));
} }
@@ -208,7 +208,7 @@ public class PreparedStatementCreatorFactory {
Set<String> names = new HashSet<>(); Set<String> names = new HashSet<>();
for (int i = 0; i < parameters.size(); i++) { for (int i = 0; i < parameters.size(); i++) {
Object param = parameters.get(i); Object param = parameters.get(i);
if (param instanceof SqlParameterValue sqlParameterValue) { if (param instanceof SqlParameterValue sqlParameterValue && sqlParameterValue.getName() != null) {
names.add(sqlParameterValue.getName()); names.add(sqlParameterValue.getName());
} }
else { else {

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -28,6 +28,8 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.core.MethodParameter; import org.springframework.core.MethodParameter;
import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.ConversionService;
@@ -82,7 +84,7 @@ public class SimplePropertyRowMapper<T> implements RowMapper<T> {
private final Constructor<T> mappedConstructor; private final Constructor<T> mappedConstructor;
private final String[] constructorParameterNames; private final @Nullable String[] constructorParameterNames;
private final TypeDescriptor[] constructorParameterTypes; private final TypeDescriptor[] constructorParameterTypes;
@@ -122,7 +124,7 @@ public class SimplePropertyRowMapper<T> implements RowMapper<T> {
@Override @Override
public T mapRow(ResultSet rs, int rowNumber) throws SQLException { public T mapRow(ResultSet rs, int rowNumber) throws SQLException {
Object[] args = new Object[this.constructorParameterNames.length]; @Nullable Object[] args = new Object[this.constructorParameterNames.length];
Set<Integer> usedIndex = new HashSet<>(); Set<Integer> usedIndex = new HashSet<>();
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
String name = this.constructorParameterNames[i]; String name = this.constructorParameterNames[i];

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2023 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -370,7 +370,7 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
new BatchPreparedStatementSetter() { new BatchPreparedStatementSetter() {
@Override @Override
public void setValues(PreparedStatement ps, int i) throws SQLException { public void setValues(PreparedStatement ps, int i) throws SQLException {
Object[] values = NamedParameterUtils.buildValueArray(parsedSql, batchArgs[i], null); @Nullable Object[] values = NamedParameterUtils.buildValueArray(parsedSql, batchArgs[i], null);
pscf.newPreparedStatementSetter(values).setValues(ps); pscf.newPreparedStatementSetter(values).setValues(ps);
} }
@Override @Override
@@ -407,12 +407,12 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
else { else {
pscf.setReturnGeneratedKeys(true); pscf.setReturnGeneratedKeys(true);
} }
Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, null); @Nullable Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, null);
PreparedStatementCreator psc = pscf.newPreparedStatementCreator(params); PreparedStatementCreator psc = pscf.newPreparedStatementCreator(params);
return getJdbcOperations().batchUpdate(psc, new BatchPreparedStatementSetter() { return getJdbcOperations().batchUpdate(psc, new BatchPreparedStatementSetter() {
@Override @Override
public void setValues(PreparedStatement ps, int i) throws SQLException { public void setValues(PreparedStatement ps, int i) throws SQLException {
Object[] values = NamedParameterUtils.buildValueArray(parsedSql, batchArgs[i], null); @Nullable Object[] values = NamedParameterUtils.buildValueArray(parsedSql, batchArgs[i], null);
pscf.newPreparedStatementSetter(values).setValues(ps); pscf.newPreparedStatementSetter(values).setValues(ps);
} }
@@ -460,7 +460,7 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations
if (customizer != null) { if (customizer != null) {
customizer.accept(pscf); customizer.accept(pscf);
} }
Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, null); @Nullable Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, null);
return pscf.newPreparedStatementCreator(params); return pscf.newPreparedStatementCreator(params);
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2024 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -348,10 +348,10 @@ public abstract class NamedParameterUtils {
* be built into the value array in the form of SqlParameterValue objects. * be built into the value array in the form of SqlParameterValue objects.
* @return the array of values * @return the array of values
*/ */
public static Object[] buildValueArray( public static @Nullable Object[] buildValueArray(
ParsedSql parsedSql, SqlParameterSource paramSource, @Nullable List<SqlParameter> declaredParams) { ParsedSql parsedSql, SqlParameterSource paramSource, @Nullable List<SqlParameter> declaredParams) {
Object[] paramArray = new Object[parsedSql.getTotalParameterCount()]; @Nullable Object[] paramArray = new Object[parsedSql.getTotalParameterCount()];
if (parsedSql.getNamedParameterCount() > 0 && parsedSql.getUnnamedParameterCount() > 0) { if (parsedSql.getNamedParameterCount() > 0 && parsedSql.getUnnamedParameterCount() > 0) {
throw new InvalidDataAccessApiUsageException( throw new InvalidDataAccessApiUsageException(
"Not allowed to mix named and traditional ? placeholders. You have " + "Not allowed to mix named and traditional ? placeholders. You have " +
@@ -497,7 +497,7 @@ public abstract class NamedParameterUtils {
* @param paramMap the Map of parameters * @param paramMap the Map of parameters
* @return the array of values * @return the array of values
*/ */
public static Object[] buildValueArray(String sql, Map<String, ?> paramMap) { public static @Nullable Object[] buildValueArray(String sql, Map<String, ?> paramMap) {
ParsedSql parsedSql = parseSqlStatement(sql); ParsedSql parsedSql = parseSqlStatement(sql);
return buildValueArray(parsedSql, new MapSqlParameterSource(paramMap), null); return buildValueArray(parsedSql, new MapSqlParameterSource(paramMap), null);
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -70,7 +70,7 @@ public class GenericSqlQuery<T> extends SqlQuery<T> {
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected RowMapper<T> newRowMapper(Object @Nullable [] parameters, @Nullable Map<?, ?> context) { protected RowMapper<T> newRowMapper(@Nullable Object @Nullable [] parameters, @Nullable Map<?, ?> context) {
if (this.rowMapper != null) { if (this.rowMapper != null) {
return this.rowMapper; return this.rowMapper;
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -63,7 +63,7 @@ public abstract class MappingSqlQuery<T> extends MappingSqlQueryWithParameters<T
* @see #mapRow(ResultSet, int) * @see #mapRow(ResultSet, int)
*/ */
@Override @Override
protected final @Nullable T mapRow(ResultSet rs, int rowNum, Object @Nullable [] parameters, @Nullable Map<?, ?> context) protected final @Nullable T mapRow(ResultSet rs, int rowNum, @Nullable Object @Nullable [] parameters, @Nullable Map<?, ?> context)
throws SQLException { throws SQLException {
return mapRow(rs, rowNum); return mapRow(rs, rowNum);

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -74,7 +74,7 @@ public abstract class MappingSqlQueryWithParameters<T> extends SqlQuery<T> {
* implementation of the mapRow() method. * implementation of the mapRow() method.
*/ */
@Override @Override
protected RowMapper<T> newRowMapper(Object @Nullable [] parameters, @Nullable Map<?, ?> context) { protected RowMapper<T> newRowMapper(@Nullable Object @Nullable [] parameters, @Nullable Map<?, ?> context) {
return new RowMapperImpl(parameters, context); return new RowMapperImpl(parameters, context);
} }
@@ -93,7 +93,7 @@ public abstract class MappingSqlQueryWithParameters<T> extends SqlQuery<T> {
* Subclasses can simply not catch SQLExceptions, relying on the * Subclasses can simply not catch SQLExceptions, relying on the
* framework to clean up. * framework to clean up.
*/ */
protected abstract @Nullable T mapRow(ResultSet rs, int rowNum, Object @Nullable [] parameters, @Nullable Map<?, ?> context) protected abstract @Nullable T mapRow(ResultSet rs, int rowNum, @Nullable Object @Nullable [] parameters, @Nullable Map<?, ?> context)
throws SQLException; throws SQLException;
@@ -103,14 +103,14 @@ public abstract class MappingSqlQueryWithParameters<T> extends SqlQuery<T> {
*/ */
protected class RowMapperImpl implements RowMapper<T> { protected class RowMapperImpl implements RowMapper<T> {
private final Object @Nullable [] params; private final @Nullable Object @Nullable [] params;
private final @Nullable Map<?, ?> context; private final @Nullable Map<?, ?> context;
/** /**
* Use an array results. More efficient if we know how many results to expect. * Use an array results. More efficient if we know how many results to expect.
*/ */
public RowMapperImpl(Object @Nullable [] parameters, @Nullable Map<?, ?> context) { public RowMapperImpl(@Nullable Object @Nullable [] parameters, @Nullable Map<?, ?> context) {
this.params = parameters; this.params = parameters;
this.context = context; this.context = context;
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -94,7 +94,7 @@ public abstract class SqlOperation extends RdbmsOperation {
* with the given parameters. * with the given parameters.
* @param params the parameter array (may be {@code null}) * @param params the parameter array (may be {@code null})
*/ */
protected final PreparedStatementSetter newPreparedStatementSetter(Object @Nullable [] params) { protected final PreparedStatementSetter newPreparedStatementSetter(@Nullable Object @Nullable [] params) {
Assert.state(this.preparedStatementFactory != null, "No PreparedStatementFactory available"); Assert.state(this.preparedStatementFactory != null, "No PreparedStatementFactory available");
return this.preparedStatementFactory.newPreparedStatementSetter(params); return this.preparedStatementFactory.newPreparedStatementSetter(params);
} }
@@ -104,7 +104,7 @@ public abstract class SqlOperation extends RdbmsOperation {
* with the given parameters. * with the given parameters.
* @param params the parameter array (may be {@code null}) * @param params the parameter array (may be {@code null})
*/ */
protected final PreparedStatementCreator newPreparedStatementCreator(Object @Nullable [] params) { protected final PreparedStatementCreator newPreparedStatementCreator(@Nullable Object @Nullable [] params) {
Assert.state(this.preparedStatementFactory != null, "No PreparedStatementFactory available"); Assert.state(this.preparedStatementFactory != null, "No PreparedStatementFactory available");
return this.preparedStatementFactory.newPreparedStatementCreator(params); return this.preparedStatementFactory.newPreparedStatementCreator(params);
} }
@@ -116,7 +116,7 @@ public abstract class SqlOperation extends RdbmsOperation {
* the factory's, for example because of named parameter expanding) * the factory's, for example because of named parameter expanding)
* @param params the parameter array (may be {@code null}) * @param params the parameter array (may be {@code null})
*/ */
protected final PreparedStatementCreator newPreparedStatementCreator(String sqlToUse, Object @Nullable [] params) { protected final PreparedStatementCreator newPreparedStatementCreator(String sqlToUse, @Nullable Object @Nullable [] params) {
Assert.state(this.preparedStatementFactory != null, "No PreparedStatementFactory available"); Assert.state(this.preparedStatementFactory != null, "No PreparedStatementFactory available");
return this.preparedStatementFactory.newPreparedStatementCreator(sqlToUse, params); return this.preparedStatementFactory.newPreparedStatementCreator(sqlToUse, params);
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -227,7 +227,7 @@ public abstract class SqlQuery<T> extends SqlOperation {
ParsedSql parsedSql = getParsedSql(); ParsedSql parsedSql = getParsedSql();
MapSqlParameterSource paramSource = new MapSqlParameterSource(paramMap); MapSqlParameterSource paramSource = new MapSqlParameterSource(paramMap);
String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource); String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource);
Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, getDeclaredParameters()); @Nullable Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, getDeclaredParameters());
RowMapper<T> rowMapper = newRowMapper(params, context); RowMapper<T> rowMapper = newRowMapper(params, context);
return getJdbcTemplate().query(newPreparedStatementCreator(sqlToUse, params), rowMapper); return getJdbcTemplate().query(newPreparedStatementCreator(sqlToUse, params), rowMapper);
} }
@@ -238,7 +238,7 @@ public abstract class SqlQuery<T> extends SqlOperation {
* the SqlParameters. Primitive parameters must be represented by their Object wrapper * the SqlParameters. Primitive parameters must be represented by their Object wrapper
* type. The ordering of parameters is not significant. * type. The ordering of parameters is not significant.
*/ */
public List<T> executeByNamedParam(Map<String, ?> paramMap) throws DataAccessException { public List<T> executeByNamedParam(Map<String, ? extends @Nullable Object> paramMap) throws DataAccessException {
return executeByNamedParam(paramMap, null); return executeByNamedParam(paramMap, null);
} }
@@ -361,6 +361,6 @@ public abstract class SqlQuery<T> extends SqlOperation {
* but it can be useful for creating the objects of the result list. * but it can be useful for creating the objects of the result list.
* @see #execute * @see #execute
*/ */
protected abstract RowMapper<T> newRowMapper(Object @Nullable [] parameters, @Nullable Map<?, ?> context); protected abstract RowMapper<T> newRowMapper(@Nullable Object @Nullable [] parameters, @Nullable Map<?, ?> context);
} }

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -20,6 +20,8 @@ import java.util.Map;
import javax.sql.DataSource; import javax.sql.DataSource;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessException;
import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException; import org.springframework.jdbc.JdbcUpdateAffectedIncorrectNumberOfRowsException;
@@ -252,7 +254,7 @@ public class SqlUpdate extends SqlOperation {
ParsedSql parsedSql = getParsedSql(); ParsedSql parsedSql = getParsedSql();
MapSqlParameterSource paramSource = new MapSqlParameterSource(paramMap); MapSqlParameterSource paramSource = new MapSqlParameterSource(paramMap);
String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource); String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource);
Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, getDeclaredParameters()); @Nullable Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, getDeclaredParameters());
int rowsAffected = getJdbcTemplate().update(newPreparedStatementCreator(sqlToUse, params)); int rowsAffected = getJdbcTemplate().update(newPreparedStatementCreator(sqlToUse, params));
checkRowsAffected(rowsAffected); checkRowsAffected(rowsAffected);
return rowsAffected; return rowsAffected;
@@ -271,7 +273,7 @@ public class SqlUpdate extends SqlOperation {
ParsedSql parsedSql = getParsedSql(); ParsedSql parsedSql = getParsedSql();
MapSqlParameterSource paramSource = new MapSqlParameterSource(paramMap); MapSqlParameterSource paramSource = new MapSqlParameterSource(paramMap);
String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource); String sqlToUse = NamedParameterUtils.substituteNamedParameters(parsedSql, paramSource);
Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, getDeclaredParameters()); @Nullable Object[] params = NamedParameterUtils.buildValueArray(parsedSql, paramSource, getDeclaredParameters());
int rowsAffected = getJdbcTemplate().update(newPreparedStatementCreator(sqlToUse, params), generatedKeyHolder); int rowsAffected = getJdbcTemplate().update(newPreparedStatementCreator(sqlToUse, params), generatedKeyHolder);
checkRowsAffected(rowsAffected); checkRowsAffected(rowsAffected);
return rowsAffected; return rowsAffected;

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2025 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -63,7 +63,7 @@ public abstract class UpdatableSqlQuery<T> extends SqlQuery<T> {
* implementation of the {@code updateRow()} method. * implementation of the {@code updateRow()} method.
*/ */
@Override @Override
protected RowMapper<T> newRowMapper(Object @Nullable [] parameters, @Nullable Map<?, ?> context) { protected RowMapper<T> newRowMapper(@Nullable Object @Nullable [] parameters, @Nullable Map<?, ?> context) {
return new RowMapperImpl(context); return new RowMapperImpl(context);
} }