Elffuss BraidHub

kikocis/java-driver public

Merge branch 'cvent-2.0' into 2.0
Changeset3915fb25e480db24cef7801c93eab5396942ce7931bbb7b9aec6c38e5b11d4ce
Authorolim7t <omichallat+github@gmail.com> · 2014-09-23 17:08 +02:00
Committerolim7t <omichallat+github@gmail.com> · 2014-09-23 17:08 +02:00
Parents597fa42e6e24, 2379dc95161f

Browse the files at this changeset

2 files changed

modified driver-core/src/main/java/com/datastax/driver/core/BoundStatement.java +39 −10
@@ -42,7 +42,8 @@
4242
4343 final PreparedStatement statement;
4444 final ByteBuffer[] values;
45-
45+ private ByteBuffer routingKey;
46+
4647 /**
4748 * Creates a new {@code BoundStatement} from the provided prepared
4849 * statement.
@@ -51,7 +52,7 @@
5152 public BoundStatement(PreparedStatement statement) {
5253 this.statement = statement;
5354 this.values = new ByteBuffer[statement.getVariables().size()];
54-
55+
5556 if (statement.getConsistencyLevel() != null)
5657 this.setConsistencyLevel(statement.getConsistencyLevel());
5758 if (statement.getSerialConsistencyLevel() != null)
@@ -195,28 +196,56 @@
195196 return this;
196197 }
197198
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+
198219 /**
199220 * The routing key for this bound query.
200221 * <p>
201222 * This method will return a non-{@code null} value if either of the following occur:
202223 * <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>
208230 * </ul>
209231 * Otherwise, {@code null} is returned.
210232 * <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.
213237 *
214238 * @return the routing key for this statement or {@code null}.
215239 */
216240 @Override
217241 public ByteBuffer getRoutingKey() {
218- if (statement.getRoutingKey() != null)
242+ if (this.routingKey != null) {
243+ return this.routingKey;
244+ }
245+
246+ if (statement.getRoutingKey() != null) {
219247 return statement.getRoutingKey();
248+ }
220249
221250 int[] rkIndexes = statement.getPreparedId().routingKeyIndexes;
222251 if (rkIndexes != null) {
modified pom.xml +1 −0
@@ -17,6 +17,7 @@
1717 <groupId>org.sonatype.oss</groupId>
1818 <artifactId>oss-parent</artifactId>
1919 <version>7</version>
20+ <relativePath></relativePath>
2021 </parent>
2122
2223 <groupId>com.datastax.cassandra</groupId>