Introduce var-args params() method in JdbcClient's StatementSpec

Closes gh-31070
This commit is contained in:
Sam Brannen 2023-08-18 11:56:28 +02:00
parent 48e94f535c
commit e0fb777325
2 changed files with 21 additions and 0 deletions

View File

@ -17,6 +17,7 @@
package org.springframework.jdbc.core.simple;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@ -47,6 +48,7 @@ import org.springframework.util.Assert;
* as created by the static factory methods.
*
* @author Juergen Hoeller
* @author Sam Brannen
* @since 6.1
* @see JdbcClient#create(DataSource)
* @see JdbcClient#create(JdbcOperations)
@ -141,6 +143,12 @@ final class DefaultJdbcClient implements JdbcClient {
return this;
}
@Override
public StatementSpec params(Object... values) {
Collections.addAll(this.indexedParams, values);
return this;
}
@Override
public StatementSpec params(List<?> values) {
this.indexedParams.addAll(values);

View File

@ -56,6 +56,7 @@ import org.springframework.jdbc.support.rowset.SqlRowSet;
* or alternatively {@link SimpleJdbcInsert} and {@link SimpleJdbcCall}.
*
* @author Juergen Hoeller
* @author Sam Brannen
* @since 6.1
* @see ResultSetExtractor
* @see RowCallbackHandler
@ -167,6 +168,18 @@ public interface JdbcClient {
*/
StatementSpec param(String name, Object value, int sqlType);
/**
* Bind a var-args list of positional parameters for "?" placeholder resolution.
* <p>The given list will be added to existing positional parameters, if any.
* Each element from the complete list will be bound as a JDBC positional
* parameter with a corresponding JDBC index (i.e. list index + 1).
* @param values the parameter values to bind
* @return this statement specification (for chaining)
* @see #param(Object)
* @see #params(List)
*/
StatementSpec params(Object... values);
/**
* Bind a list of positional parameters for "?" placeholder resolution.
* <p>The given list will be added to existing positional parameters, if any.