Browse Source

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

Closes gh-31070
pull/31076/head
Sam Brannen 2 years ago
parent
commit
e0fb777325
  1. 8
      spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/DefaultJdbcClient.java
  2. 13
      spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/JdbcClient.java

8
spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/DefaultJdbcClient.java

@ -17,6 +17,7 @@ @@ -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; @@ -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 { @@ -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);

13
spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/JdbcClient.java

@ -56,6 +56,7 @@ import org.springframework.jdbc.support.rowset.SqlRowSet; @@ -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 { @@ -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.

Loading…
Cancel
Save