Elffuss BraidHub

kikocis/java-driver public

JAVA-225: Create values() function for Insert builder using List.
Changeset20cf9ec03bbfc03fe2abacceed368e1a4e096f94035b420924c20db8e5fa9f2c
AuthorAlexandre Dutra <alexandre.dutra@datastax.com> · 2015-06-15 09:13 +02:00
Committerolim7t <omichallat+github@gmail.com> · 2015-06-22 16:03 +02:00
Parentsb721e157091b

Browse the files at this changeset

2 files changed

modified changelog/README.md +1 −0
@@ -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
modified driver-core/src/main/java/com/datastax/driver/core/querybuilder/Insert.java +20 −8
@@ -92,18 +92,30 @@
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));
98+ return values(Arrays.asList(names), Arrays.asList(values));
99+ }
103100
104- for (int i = 0; i < names.length; i++) {
105- checkForBindMarkers(values[i]);
106- maybeAddRoutingKey(names[i], values[i]);
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 }