Skip to content

Commit 294868c

Browse files
Alexandre Dutraolim7t
authored andcommitted
JAVA-225: Create values() function for Insert builder using List.
1 parent 805b1f0 commit 294868c

2 files changed

Lines changed: 22 additions & 9 deletions

File tree

changelog/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- [bug] Prevent QueryBuilder from trying to serialize raw string (JAVA-688)
1313
- [bug] Support bind marker in QueryBuilder DELETE's list index (JAVA-679)
1414
- [improvement] Improve QueryBuilder API for SELECT DISTINCT (JAVA-475)
15+
- [improvement] Create values() function for Insert builder using List (JAVA-225)
1516

1617
Merged from 2.0.10_fixes branch:
1718

driver-core/src/main/java/com/datastax/driver/core/querybuilder/Insert.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,30 @@ public Insert value(String name, Object value) {
9292
* value in {@code values} will be inserted for the {@code i}th column
9393
* in {@code names}.
9494
* @return this INSERT statement.
95-
*
9695
* @throws IllegalArgumentException if {@code names.length != values.length}.
9796
*/
9897
public Insert values(String[] names, Object[] values) {
99-
if (names.length != values.length)
100-
throw new IllegalArgumentException(String.format("Got %d names but %d values", names.length, values.length));
101-
this.names.addAll(Arrays.asList(names));
102-
this.values.addAll(Arrays.asList(values));
103-
104-
for (int i = 0; i < names.length; i++) {
105-
checkForBindMarkers(values[i]);
106-
maybeAddRoutingKey(names[i], values[i]);
98+
return values(Arrays.asList(names), Arrays.asList(values));
99+
}
100+
101+
/**
102+
* Adds multiple column/value pairs to the values inserted by this INSERT statement.
103+
*
104+
* @param names a list of column names to insert/update.
105+
* @param values a list of values to insert/update. The {@code i}th
106+
* value in {@code values} will be inserted for the {@code i}th column
107+
* in {@code names}.
108+
* @return this INSERT statement.
109+
* @throws IllegalArgumentException if {@code names.size() != values.size()}.
110+
*/
111+
public Insert values(List<String> names, List<Object> values) {
112+
if (names.size() != values.size())
113+
throw new IllegalArgumentException(String.format("Got %d names but %d values", names.size(), values.size()));
114+
this.names.addAll(names);
115+
this.values.addAll(values);
116+
for (int i = 0; i < names.size(); i++) {
117+
checkForBindMarkers(values.get(i));
118+
maybeAddRoutingKey(names.get(i), values.get(i));
107119
}
108120
return this;
109121
}

0 commit comments

Comments
 (0)