kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 4a4ffe7ce8ed6523ed65b8ec8157344631174447c0db834e5e380b2e02df364a |
|---|---|
| Author | Olivier Michallat <olim7t@users.noreply.github.com> · 2015-10-30 16:35 +01:00 |
| Committer | Olivier Michallat <olim7t@users.noreply.github.com> · 2015-10-30 16:35 +01:00 |
| Parents | 93c7dfb4d9c2, b4617e6d2b80 |
3 files changed
modified changelog/README.md +1 −0
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | - [improvement] JAVA-920: Downgrade "error creating pool" message to WARN. |
| 7 | 7 | - [bug] JAVA-954: Don't trigger reconnection before initialization complete. |
| 8 | 8 | - [improvement] JAVA-914: Avoid rejected tasks at shutdown. |
| 9 | +- [improvement] JAVA-921: Add SimpleStatement.getValuesCount(). | |
| 9 | 10 | |
| 10 | 11 | |
| 11 | 12 | ### 2.0.11 |
modified driver-core/src/main/java/com/datastax/driver/core/SimpleStatement.java +12 −0
| @@ -117,6 +117,18 @@ | ||
| 117 | 117 | return values == null ? null : convert(values); |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | + /** | |
| 121 | + * Returns the number of values provided for this statement. | |
| 122 | + * <p> | |
| 123 | + * This is more efficient than calling {@link #getValues()} and getting the length | |
| 124 | + * of the returned array, because {@code getValues()} does some internal conversions. | |
| 125 | + * | |
| 126 | + * @return the number of values. | |
| 127 | + */ | |
| 128 | + public int getValuesCount() { | |
| 129 | + return values == null ? 0 : values.length; | |
| 130 | + } | |
| 131 | + | |
| 120 | 132 | /** |
| 121 | 133 | * Returns the {@code i}th value as the Java type matching its CQL type. |
| 122 | 134 | * |
modified driver-core/src/test/java/com/datastax/driver/core/SimpleStatementTest.java +10 −0
| @@ -48,4 +48,14 @@ | ||
| 48 | 48 | assertThat(actual).isSameAs(expected); |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | + @Test(groups = "unit") | |
| 52 | + public void should_return_number_of_values() { | |
| 53 | + assertThat( | |
| 54 | + new SimpleStatement("doesn't matter").getValuesCount() | |
| 55 | + ).isEqualTo(0); | |
| 56 | + assertThat( | |
| 57 | + new SimpleStatement("doesn't matter", 1, 2).getValuesCount() | |
| 58 | + ).isEqualTo(2); | |
| 59 | + } | |
| 60 | + | |
| 51 | 61 | } |