kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | ed244b084a4e35111689f777af82264f657e1f174f8ab4b0b09bdefa30faf471 |
|---|---|
| Author | Alexandre Dutra <alexandre.dutra@datastax.com> · 2015-06-15 09:13 +02:00 |
| Committer | Alexandre Dutra <alexandre.dutra@datastax.com> · 2015-06-15 09:48 +02:00 |
| Parents | 85d8166508e4 |
2 files changed
modified changelog/README.md +1 −0
| @@ -4,6 +4,7 @@ | ||
| 4 | 4 | |
| 5 | 5 | - [improvement] Make NativeColumnType a top-level class (JAVA-715) |
| 6 | 6 | - [improvement] Unify "Target" enum for schema elements (JAVA-782) |
| 7 | +- [improvement] Create values() function for Insert builder using List (JAVA-225) | |
| 7 | 8 | |
| 8 | 9 | |
| 9 | 10 | ### 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 | } |