kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | e6d412338c5c919521ae2827ac26e0b47e0b41d994e275455ba9cb6dbab6c4b1 |
|---|---|
| Author | Alexandre Dutra <alexandre.dutra@datastax.com> · 2015-06-19 18:33 +02:00 |
| Committer | Alexandre Dutra <alexandre.dutra@datastax.com> · 2015-06-19 18:33 +02:00 |
| Parents | da3cad0e6ca9, 81a462b8c881 |
2 files changed
modified changelog/README.md +1 −0
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | - [improvement] Unify "Target" enum for schema elements (JAVA-782) |
| 8 | 8 | - [improvement] Expose ProtocolVersion#toInt (JAVA-700) |
| 9 | 9 | - [bug] Handle void return types in accessors (JAVA-542) |
| 10 | +- [improvement] Create values() function for Insert builder using List (JAVA-225) | |
| 10 | 11 | |
| 11 | 12 | |
| 12 | 13 | ### 2.1.6 |
modified driver-core/src/main/java/com/datastax/driver/core/querybuilder/Insert.java +21 −10
| @@ -15,7 +15,6 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core.querybuilder; |
| 17 | 17 | |
| 18 | -import java.nio.ByteBuffer; | |
| 19 | 18 | import java.util.ArrayList; |
| 20 | 19 | import java.util.Arrays; |
| 21 | 20 | import java.util.List; |
| @@ -92,18 +91,30 @@ | ||
| 92 | 91 | * value in {@code values} will be inserted for the {@code i}th column |
| 93 | 92 | * in {@code names}. |
| 94 | 93 | * @return this INSERT statement. |
| 95 | - * | |
| 96 | 94 | * @throws IllegalArgumentException if {@code names.length != values.length}. |
| 97 | 95 | */ |
| 98 | 96 | 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)); | |
| 107 | 118 | } |
| 108 | 119 | return this; |
| 109 | 120 | } |