Elffuss BraidHub

kikocis/java-driver public

JAVA-225: Create values() function for Insert builder using List.
Changeseted244b084a4e35111689f777af82264f657e1f174f8ab4b0b09bdefa30faf471
AuthorAlexandre Dutra <alexandre.dutra@datastax.com> · 2015-06-15 09:13 +02:00
CommitterAlexandre Dutra <alexandre.dutra@datastax.com> · 2015-06-15 09:48 +02:00
Parents85d8166508e4

Browse the files at this changeset

2 files changed

modified changelog/README.md +1 −0
@@ -4,6 +4,7 @@
44
55 - [improvement] Make NativeColumnType a top-level class (JAVA-715)
66 - [improvement] Unify "Target" enum for schema elements (JAVA-782)
7+- [improvement] Create values() function for Insert builder using List (JAVA-225)
78
89
910 ### 2.1.6
modified driver-core/src/main/java/com/datastax/driver/core/querybuilder/Insert.java +21 −10
@@ -15,7 +15,6 @@
1515 */
1616 package com.datastax.driver.core.querybuilder;
1717
18-import java.nio.ByteBuffer;
1918 import java.util.ArrayList;
2019 import java.util.Arrays;
2120 import java.util.List;
@@ -92,18 +91,30 @@
9291 * value in {@code values} will be inserted for the {@code i}th column
9392 * in {@code names}.
9493 * @return this INSERT statement.
95- *
9694 * @throws IllegalArgumentException if {@code names.length != values.length}.
9795 */
9896 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]);
97+ return values(Arrays.asList(names), Arrays.asList(values));
98+ }
99+
100+ /**
101+ * Adds multiple column/value pairs to the values inserted by this INSERT statement.
102+ *
103+ * @param names a list of column names to insert/update.
104+ * @param values a list of values to insert/update. The {@code i}th
105+ * value in {@code values} will be inserted for the {@code i}th column
106+ * in {@code names}.
107+ * @return this INSERT statement.
108+ * @throws IllegalArgumentException if {@code names.size() != values.size()}.
109+ */
110+ public Insert values(List<String> names, List<Object> values) {
111+ if (names.size() != values.size())
112+ throw new IllegalArgumentException(String.format("Got %d names but %d values", names.size(), values.size()));
113+ this.names.addAll(names);
114+ this.values.addAll(values);
115+ for (int i = 0; i < names.size(); i++) {
116+ checkForBindMarkers(values.get(i));
117+ maybeAddRoutingKey(names.get(i), values.get(i));
107118 }
108119 return this;
109120 }