kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 3915fb25e480db24cef7801c93eab5396942ce7931bbb7b9aec6c38e5b11d4ce |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2014-09-23 17:08 +02:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2014-09-23 17:08 +02:00 |
| Parents | 597fa42e6e24, 2379dc95161f |
2 files changed
modified driver-core/src/main/java/com/datastax/driver/core/BoundStatement.java +39 −10
| @@ -42,7 +42,8 @@ | ||
| 42 | 42 | |
| 43 | 43 | final PreparedStatement statement; |
| 44 | 44 | final ByteBuffer[] values; |
| 45 | - | |
| 45 | + private ByteBuffer routingKey; | |
| 46 | + | |
| 46 | 47 | /** |
| 47 | 48 | * Creates a new {@code BoundStatement} from the provided prepared |
| 48 | 49 | * statement. |
| @@ -51,7 +52,7 @@ | ||
| 51 | 52 | public BoundStatement(PreparedStatement statement) { |
| 52 | 53 | this.statement = statement; |
| 53 | 54 | this.values = new ByteBuffer[statement.getVariables().size()]; |
| 54 | - | |
| 55 | + | |
| 55 | 56 | if (statement.getConsistencyLevel() != null) |
| 56 | 57 | this.setConsistencyLevel(statement.getConsistencyLevel()); |
| 57 | 58 | if (statement.getSerialConsistencyLevel() != null) |
| @@ -195,28 +196,56 @@ | ||
| 195 | 196 | return this; |
| 196 | 197 | } |
| 197 | 198 | |
| 199 | + /** | |
| 200 | + * Sets the routing key for this bound statement. | |
| 201 | + * <p> | |
| 202 | + * While you can provide a fixed routing key for all executions of this bound statement with this method, it is | |
| 203 | + * not mandatory to provide one through this method. This method should only be used if the partition key of the | |
| 204 | + * prepared query is not part of the prepared variables (that is if the partition key is fixed). | |
| 205 | + * <p> | |
| 206 | + * Note that if the partition key is part of the prepared variables, the routing key will be automatically computed | |
| 207 | + * once those variables are bound. | |
| 208 | + * | |
| 209 | + * @param routingKey the raw (binary) value to use as routing key. | |
| 210 | + * @return this {@code BoundStatement} object. | |
| 211 | + * | |
| 212 | + * @see Statement#getRoutingKey | |
| 213 | + */ | |
| 214 | + public BoundStatement setRoutingKey(ByteBuffer routingKey) { | |
| 215 | + this.routingKey = routingKey; | |
| 216 | + return this; | |
| 217 | + } | |
| 218 | + | |
| 198 | 219 | /** |
| 199 | 220 | * The routing key for this bound query. |
| 200 | 221 | * <p> |
| 201 | 222 | * This method will return a non-{@code null} value if either of the following occur: |
| 202 | 223 | * <ul> |
| 203 | - * <li>All the columns composing the partition key are bound | |
| 204 | - * variables of this {@code BoundStatement}. The routing key will then be | |
| 205 | - * built using the values provided for these partition key columns.</li> | |
| 206 | - * <li>The routing key has been set through {@link PreparedStatement#setRoutingKey} | |
| 207 | - * for the {@code PreparedStatement} this statement has been built from.</li> | |
| 224 | + * <li>All the columns composing the partition key are bound variables of this {@code BoundStatement}. The routing | |
| 225 | + * key will then be built using the values provided for these partition key columns.</li> | |
| 226 | + * <li>The routing key has been set through {@link BoundStatement#setRoutingKey} for the {@code BoundStatement} this | |
| 227 | + * statement has been built from.</li> | |
| 228 | + * <li>The routing key has been set through {@link PreparedStatement#setRoutingKey} for the | |
| 229 | + * {@code PreparedStatement} this statement has been built from.</li> | |
| 208 | 230 | * </ul> |
| 209 | 231 | * Otherwise, {@code null} is returned. |
| 210 | 232 | * <p> |
| 211 | - * Note that if the routing key has been set through {@link PreparedStatement#setRoutingKey}, | |
| 212 | - * that latter value takes precedence even if the partition key is part of the bound variables. | |
| 233 | + * | |
| 234 | + * Note that if the routing key has been set through {@link BoundStatement#setRoutingKey}, then that takes | |
| 235 | + * precedence. If the routing key has been set through {@link PreparedStatement#setRoutingKey} then that is used | |
| 236 | + * next. If neither of those are set then it is computed. | |
| 213 | 237 | * |
| 214 | 238 | * @return the routing key for this statement or {@code null}. |
| 215 | 239 | */ |
| 216 | 240 | @Override |
| 217 | 241 | public ByteBuffer getRoutingKey() { |
| 218 | - if (statement.getRoutingKey() != null) | |
| 242 | + if (this.routingKey != null) { | |
| 243 | + return this.routingKey; | |
| 244 | + } | |
| 245 | + | |
| 246 | + if (statement.getRoutingKey() != null) { | |
| 219 | 247 | return statement.getRoutingKey(); |
| 248 | + } | |
| 220 | 249 | |
| 221 | 250 | int[] rkIndexes = statement.getPreparedId().routingKeyIndexes; |
| 222 | 251 | if (rkIndexes != null) { |
modified pom.xml +1 −0
| @@ -17,6 +17,7 @@ | ||
| 17 | 17 | <groupId>org.sonatype.oss</groupId> |
| 18 | 18 | <artifactId>oss-parent</artifactId> |
| 19 | 19 | <version>7</version> |
| 20 | + <relativePath></relativePath> | |
| 20 | 21 | </parent> |
| 21 | 22 | |
| 22 | 23 | <groupId>com.datastax.cassandra</groupId> |