kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 20cf9ec03bbfc03fe2abacceed368e1a4e096f94035b420924c20db8e5fa9f2c |
|---|---|
| Author | Alexandre Dutra <alexandre.dutra@datastax.com> · 2015-06-15 09:13 +02:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-06-22 16:03 +02:00 |
| Parents | b721e157091b |
2 files changed
modified changelog/README.md +1 −0
| @@ -12,6 +12,7 @@ | ||
| 12 | 12 | - [bug] Prevent QueryBuilder from trying to serialize raw string (JAVA-688) |
| 13 | 13 | - [bug] Support bind marker in QueryBuilder DELETE's list index (JAVA-679) |
| 14 | 14 | - [improvement] Improve QueryBuilder API for SELECT DISTINCT (JAVA-475) |
| 15 | +- [improvement] Create values() function for Insert builder using List (JAVA-225) | |
| 15 | 16 | |
| 16 | 17 | Merged from 2.0.10_fixes branch: |
| 17 | 18 |
modified driver-core/src/main/java/com/datastax/driver/core/querybuilder/Insert.java +20 −8
| @@ -92,18 +92,30 @@ | ||
| 92 | 92 | * value in {@code values} will be inserted for the {@code i}th column |
| 93 | 93 | * in {@code names}. |
| 94 | 94 | * @return this INSERT statement. |
| 95 | - * | |
| 96 | 95 | * @throws IllegalArgumentException if {@code names.length != values.length}. |
| 97 | 96 | */ |
| 98 | 97 | 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 | + } | |
| 103 | 100 | |
| 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)); | |
| 107 | 119 | } |
| 108 | 120 | return this; |
| 109 | 121 | } |