Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,14 @@ public BatchSpec entry(Consumer<BatchEntry> entryConsumer) {
return this;
}

@Override
public BatchSpec entry(@Nullable Object... values) {
DefaultBatchEntry entry = new DefaultBatchEntry();
Collections.addAll(entry.indexedParams, values);
addEntry(entry);
return this;
}

@Override
public BatchSpec entry(List<?> values) {
DefaultBatchEntry entry = new DefaultBatchEntry();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,19 @@ interface BatchSpec {
*/
BatchSpec entry(Consumer<BatchEntry> entryConsumer);

/**
* Define a batch entry with the given list of positional parameters for
* "?" placeholder resolution.
* <p>Each element of the list will be bound as a JDBC positional parameter
* with a corresponding JDBC index (i.e. list index + 1).
* <p>Note that the given list represents the parameters of a <em>single</em>
* entry; see {@link #entries(Object[])} for defining several entries at once.
* @param values the parameter values to bind
* @return this batch specification (for chaining)
* @see #entry(List)
*/
BatchSpec entry(@Nullable Object... values);

/**
* Define a batch entry with the given list of positional parameters for
* "?" placeholder resolution.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,20 @@ void updateWithGeneratedKeysAndKeyColumnNamesUsingNamedParameters() {
assertUser(expectedId, firstName, lastName);
}

@Test
void batchUpdateWithIndexedParameters() {
int[] rowsAffected = this.jdbcClient.sql(INSERT_WITH_JDBC_PARAMS)
.batch()
.entry("Jane", "Smith")
.entry("John", "Doe")
.update();

assertThat(rowsAffected).containsExactly(1, 1);
assertNumUsers(3);
assertUser(1, "Jane", "Smith");
assertUser(2, "John", "Doe");
}

@Test
void batchUpdateWithIndexedParameterList() {
int[] rowsAffected = this.jdbcClient.sql(INSERT_WITH_JDBC_PARAMS)
Expand Down
Loading