Elffuss BraidHub

kikocis/java-driver public

0960065b032a · 32.7 KiBRenderedRawPermalink
1## Upgrade guide
2
3The purpose of this guide is to detail changes made by successive
4versions of the Java driver.
5
6### 3.0.0
7
8This version brings parity with Cassandra 2.2 and 3.0.
9
10It is **not binary compatible** with the driver's 2.1 branch.
11The main changes were introduced by the custom codecs feature (see below).
12We've also seized the opportunity to remove code that was deprecated in 2.1.
13
141. The default consistency level in `QueryOptions` is now `LOCAL_ONE`.
152. [Custom codecs](../manual/custom_codecs/)
16 ([JAVA-721](https://datastax-oss.atlassian.net/browse/JAVA-721))
17 introduce several breaking changes and also modify a few runtime behaviors.
18
19 Here is a detailed list of breaking API changes:
20 * `TypeCodec` was package-private before and is now public.
21 * `DataType` has no more references to `TypeCodec`, so methods that dealt with serialization and deserialization of
22 data types have been removed:
23 * `ByteBuffer serialize(Object value, ProtocolVersion protocolVersion)`
24 * `ByteBuffer serializeValue(Object value, ProtocolVersion protocolVersion)`
25 * `Object deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion)`
26 * `Object deserialize(ByteBuffer bytes, int protocolVersion)`
27 * `Object parse(String value)`
28 * `String format(Object value)`
29 * `Class<?> asJavaClass()`
30
31 These methods must now be invoked on `TypeCodec` directly. To resolve the `TypeCodec` instance for a particular
32 data type, use `CodecRegistry#codecFor`.
33 * `GettableByIndexData` (affects `Row`, `BoundStatement`, `TupleValue` and `UDTValue`). The following public methods were added:
34 * `<T> T get(int i, Class<T> targetClass)`
35 * `<T> T get(int i, TypeToken<T> targetType)`
36 * `<T> T get(int i, TypeCodec<T> codec)`
37 * `GettableByNameData` (affects `Row`, `BoundStatement` and `UDTValue`). The following public methods were added:
38 * `<T> T get(String name, Class<T> targetClass)`
39 * `<T> T get(String name, TypeToken<T> targetType)`
40 * `<T> T get(String name, TypeCodec<T> codec)`
41 * `SettableByIndexData` (affects `Row`, `BoundStatement`, `TupleValue` and `UDTValue`). The following public methods were added:
42 * `<V> T set(int i, V v, Class<V> targetClass)`
43 * `<V> T set(int i, V v, TypeToken<V> targetType)`
44 * `<V> T set(int i, V v, TypeCodec<V> codec)`
45 * `SettableByNameData` (affects `Row`, `BoundStatement` and `UDTValue`). The following public methods were added:
46 * `<V> T set(String name, V v, Class<V> targetClass)`
47 * `<V> T set(String name, V v, TypeToken<V> targetType)`
48 * `<V> T set(String name, V v, TypeCodec<V> codec)`
49 * `Statement`. The following public methods were modified:
50 * `getRoutingKey(ProtocolVersion, CodecRegistry)`: both parameters added.
51 * `RegularStatement`. The following public methods were modified:
52 * `getValues(ProtocolVersion, CodecRegistry)`: second parameter added.
53 * `getQueryString(CodecRegistry)` and `hasValues(CodecRegistry)`: parameter added. No-arg versions are still present
54 and use the default codec registry; refer to the Javadocs for guidance on which version to use.
55 * `PreparedStatement`. The following public method was added:
56 * `CodecRegistry getCodecRegistry()`.
57 * `TupleType`. The following public method was deleted:
58 * `TupleType of(DataType... types)`; users should now use `Metadata.newTupleType(DataType...)`.
59
60 <p>The driver runtime behavior changes in the following situations:</p>
61 * By default, the driver now returns _mutable_, _non thread-safe_ instances for CQL collection types;
62 This affects methods `getList`, `getSet`, `getMap`, `getObject` and `get` for all instances of
63 `GettableByIndexData` and `GettableByNameData` (`Row`, `BoundStatement`, `TupleValue` and `UDTValue`)
64 * `RuntimeException`s thrown during serialization or deserialization might not be
65 the same ones as before, due to the newly-introduced `CodecNotFoundException`
66 and to the dynamic nature of codec search introduced by JAVA-721.
67 * `TypeCodec.format(Object)` now returns the CQL keyword `"NULL"` instead of a `null` reference
68 for `null` inputs.
69
703. The driver now depends on Guava 16.0.1 (instead of 14.0.1).
71 This update has been mainly motivated by Guava's [Issue #1635](https://code.google.com/p/guava-libraries/issues/detail?id=1635),
72 which affects `TypeToken`, and hence all `TypeCodec` implementations handling parameterized types.
73
744. `UDTMapper` (the type previously used to convert `@UDT`-annotated
75 classes to their CQL counterpart) was removed, as well as the
76 corresponding method `MappingManager#udtMapper`.
77
78 The mapper now uses custom codecs to convert UDTs. See more
79 explanations [here](../manual/object_mapper/custom_codecs/#implicit-udt-codecs).
80
815. All methods that took the protocol version as an `int` or assumed a
82 default version have been removed (they were already deprecated in
83 2.1):
84 * `AbstractGettableData(int)`
85 * `Cluster.Builder#withProtocolVersion(int)`
86 * in `ProtocolOptions`:
87 * `NEWEST_SUPPORTED_PROTOCOL_VERSION` (replaced by
88 `ProtocolVersion#NEWEST_SUPPORTED`)
89 * `int getProtocolVersion()`
90
91 There are now variants of these methods using the `ProtocolVersion`
92 enum. In addition, `ProtocolOptions#getProtocolVersionEnum` has been
93 renamed to `ProtocolOptions#getProtocolVersion`.
94
956. All methods related to the "suspected" host state have been removed
96 (they had been deprecated in 2.1.6 when the suspicion mechanism was
97 removed):
98 * `Host.StateListener#onSuspected()` (was inherited by
99 `LoadBalancingPolicy`)
100 * `Host#getInitialReconnectionAttemptFuture()`
101
1027. `PoolingOptions#setMinSimultaneousRequestsPerConnectionThreshold(HostDistance,
103 int)` has been removed. The new connection pool resizing algorithm introduced by
104 [JAVA-419](https://datastax-oss.atlassian.net/browse/JAVA-419) does not need this
105 threshold anymore.
106
1078. `AddressTranslater` has been renamed to `AddressTranslator`. All
108 related methods and classes have also been renamed.
109
110 In addition, the `close()` method has been pulled up into
111 `AddressTranslator`, and `CloseableAddressTranslator` has been removed.
112 Existing third-party `AddressTranslator` implementations only need
113 to add an empty `close()` method.
114
1159. The `close()` method has been pulled up into `LoadBalancingPolicy`,
116 and `CloseableLoadBalancingPolicy` has been removed. Existing third-party
117 `LoadBalancingPolicy` implementations only need to add an empty
118 `close()` method.
119
12010. All pluggable components now have callbacks to detect when they get
121 associated with a `Cluster` instance:
122 * `ReconnectionPolicy`, `RetryPolicy`, `AddressTranslator`,
123 and `TimestampGenerator`:
124 * `init(Cluster)`
125 * `close()`
126 * `Host.StateListener` and `LatencyTracker`:
127 * `onRegister(Cluster)`
128 * `onUnregister(Cluster)`
129
130 This gives these components the opportunity to perform
131 initialization / cleanup tasks. Existing third-party implementations
132 only need to add empty methods.
133
13411. `LoadBalancingPolicy` does not extend `Host.StateListener` anymore:
135 callback methods (`onUp`, `onDown`, etc.) have been duplicated. This
136 is unlikely to affect clients.
137
13812. [Client-side timestamp generation](../manual/query_timestamps/) is
139 now the default (provided that [native
140 protocol](../manual/native_protocol) v3 or higher is in use). The
141 generator used is `AtomicMonotonicTimestampGenerator`.
142
14313. If a DNS name resolves to multiple A-records,
144 `Cluster.Builder#addContactPoint(String)` will now use all of these
145 addresses as contact points. This gives you the possibility of
146 maintaining contact points in DNS configuration, and having a single,
147 static contact point in your Java code.
148
14914. The following methods were added for [Custom payloads](../manual/custom_payloads):
150 * in `PreparedStatement`: `getIncomingPayload()`,
151 `getOutgoingPayload()` and
152 `setOutgoingPayload(Map<String,ByteBuffer>)`
153 * `AbstractSession#prepareAsync(String, Map<String,ByteBuffer>)`
154
155 Also, note that `AbstractSession#prepareAsync(Statement)` does not
156 call `AbstractSession#prepareAsync(String)` anymore, they now both
157 delegate to a protected method.
158
159 This breaks binary compatibility for these two classes; if you have
160 custom implementations, you will have to adapt them accordingly.
161
16215. Getters and setters have been added to "data-container" classes for
163 new CQL types:
164 * `getByte`/`setByte` for the `TINYINT` type
165 * `getShort`/`setShort` for the `SMALLINT` type
166 * `getTime`/`setTime` for the `TIME` type
167 * `getDate`/`setDate` for the `DATE` type
168
169 The methods for the `TIMESTAMP` CQL type have been renamed to
170 `getTimestamp` and `setTimestamp`.
171
172 This affects `Row`, `BoundStatement`, `TupleValue` and `UDTValue`.
173
17416. New exception types have been added to handle additional server-side
175 errors introduced in Cassandra 2.2:
176 * `ReadFailureException`
177 * `WriteFailureException`
178 * `FunctionExecutionException`
179
180 This is not a breaking change since all driver exceptions are
181 unchecked; but clients might decide to handle these errors in a specific
182 way.
183
184 In addition, `QueryTimeoutException` has been renamed to
185 `QueryExecutionException` (this is an intermediary class in our
186 exception hierarchy, it now has new child classes that are not
187 related to timeouts).
188
18917. `ResultSet#fetchMoreResults()` now returns a `ListenableFuture<ResultSet>`.
190 This makes the API more friendly if you chain transformations on an async
191 query to process all pages (see `AsyncResultSetTest` in the sources for an
192 example).
193
19418. `Frozen` annotations in the mapper are no longer checked at runtime (see
195 [JAVA-843](https://datastax-oss.atlassian.net/browse/JAVA-843) for more
196 explanations). So they become purely informational at this stage.
197 However it is a good idea to keep using these annotations and make sure
198 they match the schema, in anticipation for the schema generation features
199 that will be added in a future version.
200
20119. `AsyncInitSession` has been removed, `initAsync()` is now part of the
202 `Session` interface (the only purpose of the extra interface was to preserve
203 binary compatibility on the 2.1 branch).
204
20520. `TableMetadata.Options` has been made a top-level class and renamed to
206 `TableOptionsMetadata`. It is now also used by `MaterializedViewMetadata`.
207
20821. The mapper annotation `@Enumerated` has been removed, users should now
209 use the newly-introduced `driver-extras` module to get automatic
210 enum-to-CQL mappings. Two new codecs provide the same functionality:
211 `EnumOrdinalCodec` and `EnumNameCodec`:
212
213 ```java
214 enum Foo {...}
215 enum Bar {...}
216
217 // register the appropriate codecs
218 CodecRegistry.DEFAULT_INSTANCE
219 .register(new EnumOrdinalCodec<Foo>(Foo.class))
220 .register(new EnumNameCodec<Bar>(Bar.class))
221
222 // the following mappings are handled out-of-the-box
223 @Table
224 public class MyPojo {
225 private Foo foo;
226 private List<Bar> bars;
227 ...
228 }
229 ```
230
23122. The interface `IdempotenceAwarePreparedStatement` has been removed
232 and now the `PreparedStatement` interface exposes 2 new methods,
233 `setIdempotent(Boolean)` and `isIdempotent()`.
234
23523. `RetryPolicy` and `ExtendedRetryPolicy` (introduced in 2.1.10)
236 were merged together; as a consequence, `RetryPolicy` now has one
237 more method: `onRequestError`; see
238 [JAVA-819](https://datastax-oss.atlassian.net/browse/JAVA-819) for
239 more information. Furthermore, `FallthroughRetryPolicy` now returns
240 `RetryDecision.rethrow()` when `onRequestError` is called.
241
24224. `DseAuthProvider` has been deprecated and is now replaced by
243 `DseGSSAPIAuthProvider` for Kerberos authentication. `DsePlainTextAuthProvider`
244 has been introduced to handle plain text authentication with the
245 `DseAuthenticator`.
246
24725. The constructor of `DCAwareRoundRobinPolicy` is not accessible anymore. You
248 should use `DCAwareRoundRobinPolicy#builder()` to create new instances.
249
25026. `ColumnMetadata.getTable()` has been renamed to `ColumnMetadata.getParent()`.
251 Also, its return type is now `AbstractTableMetadata` which can be either
252 a `TableMetadata` object or a `MaterializedViewMetadata` object.
253 This change is motivated by the fact that a column can now belong to a
254 table or a materialized view.
255
25627. `ColumnMetadata.getIndex()` has been removed.
257 This is due to the fact that secondary indexes have been completely redesigned
258 in Cassandra 3.0, and the former one-to-one relationship between a column and its index
259 has been replaced with a one-to-many relationship between a table and its indexes.
260 This is reflected in the driver's API by the new methods
261 `TableMetadata.getIndexes()` and `TableMetadata.getIndex(String name)`.
262 See [CASSANDRA-9459](https://issues.apache.org/jira/browse/CASSANDRA-9459) and
263 and [JAVA-1008](https://datastax-oss.atlassian.net/browse/JAVA-1008) for
264 more details.
265 Unfortunately, there is no easy way to recover the functionality provided
266 by the deleted method, _even for Cassandra versions <= 3.0_.
267
26828. `IndexMetadata` is now a top-level class and its structure has been deeply modified.
269 Again, this is due to the fact that secondary indexes have been completely redesigned
270 in Cassandra 3.0.
271
27229. `SSLOptions` has been refactored to allow the option to choose between JDK and Netty-based
273 SSL implementations. See [JAVA-841](https://datastax-oss.atlassian.net/browse/JAVA-841) and
274 the [SSL documentation](../manual/ssl) for more details.
275
276
277### 2.1.8
278
2792.1.8 is binary-compatible with 2.1.7 but introduces a small change in the
280driver's behavior:
281
2821. The list of contact points provided at startup is now shuffled before trying
283 to open the control connection, so that multiple clients with the same contact
284 points don't all pick the same control host. As a result, you can't assume that
285 the driver will try contact points in a deterministic order. In particular, if
286 you use the `DCAwareRoundRobinPolicy` without specifying a primary datacenter
287 name, make sure that you only provide local hosts as contact points.
288
289
290### 2.1.7
291
292This version brings a few changes in the driver's behavior; none of them break
293binary compatibility.
294
2951. The `DefaultRetryPolicy`'s behaviour has changed in the case of an Unavailable
296 exception received from a request. The new behaviour will cause the driver to
297 process a Retry on a different node at most once, otherwise an exception will
298 be thrown. This change makes sense in the case where the node tried initially
299 for the request happens to be isolated from the rest of the cluster (e.g.
300 because of a network partition) but can still answer to the client normally.
301 In this case, trying another node has a chance of success.
302 The previous behaviour was to always throw an exception.
303
3042. The following properties in `PoolingOptions` were renamed:
305 * `MaxSimultaneousRequestsPerConnectionThreshold` to `NewConnectionThreshold`
306 * `MaxSimultaneousRequestsPerHostThreshold` to `MaxRequestsPerConnection`
307
308 The old getters/setters were deprecated, but they delegate to the new
309 ones.
310
311 Also, note that the connection pool for protocol v3 can now be configured to
312 use multiple connections. See [this page](../manual/pooling) for more
313 information.
314
3153. `MappingManager(Session)` will now force the initialization of the `Session`
316 if needed. This is a change from 2.1.6, where if you gave it an uninitialized
317 session (created with `Cluster#newSession()` instead of `Cluster#connect()`),
318 it would only get initialized on the first request.
319
320 If this is a problem for you, `MappingManager(Session, ProtocolVersion)`
321 preserves the previous behavior (see the API docs for more details).
322
3234. A `BuiltStatement` is now considered non-idempotent whenever a `fcall()`
324 or `raw()` is used to build a value to be inserted in the database.
325 If you know that the CQL functions or expressions are safe, use
326 `setIdempotent(true)` on the statement.
327
328### 2.1.6
329
330See [2.0.10](#2-0-x-to-2-0-10).
331
332
333### 2.1.2
334
3352.1.2 brings important internal changes with native protocol v3 support, but
336the impact on the public API has been kept as low as possible.
337
338#### User API Changes
339
3401. The native protocol version is now modelled as an enum: `ProtocolVersion`.
341 Most public methods that take it as an argument have a backward-compatible
342 version that takes an `int` (the exception being `RegularStatement`,
343 described below). For new code, prefer the enum version.
344
345#### Internal API Changes
346
3471. `RegularStatement.getValues` now takes the protocol version as a
348 `ProtocolVersion` instead of an `int`. This is transparent for callers
349 since there is a backward-compatible alternative, but if you happened to
350 extend the class you'll need to update your implementation.
351
3522. `BatchStatement.setSerialConsistencyLevel` now returns `BatchStatement`
353 instead of `Statement`. Again, this only matters if you extended this
354 class (if so, it might be a good idea to also have a covariant return in
355 your child class).
356
3573. The constructor of `UnsupportedFeatureException` now takes a
358 `ProtocolVersion` as a parameter. This should impact few users, as there's
359 hardly any reason to build instances of that class from client code.
360
361#### New features
362
363These features are only active when the native protocol v3 is in use.
364
3651. The driver now uses a single connection per host (as opposed to a pool in
366 2.1.1). Most options in `PoolingOptions` are ignored, except for a new one
367 called `maxSimultaneousRequestsPerHostThreshold`. See the class's Javadocs
368 for detailed explanations.
369
3702. You can now provide a default timestamp with each query (but it will be
371 ignored if the CQL query string already contains a `USING TIMESTAMP`
372 clause). This can be done on a per-statement basis with
373 `Statement.setDefaultTimestamp`, or automatically with a
374 `TimestampGenerator` specified with
375 `Cluster.Builder.withTimestampGenerator` (two implementations are
376 provided: `ThreadLocalMonotonicTimestampGenerator` and
377 `AtomicMonotonicTimestampGenerator`). If you specify both, the statement's
378 timestamp takes precedence over the generator. By default, the driver has
379 the same behavior as 2.1.1 (no generator, timestamps are assigned by
380 Cassandra unless `USING TIMESTAMP` was specified).
381
3823. `BatchStatement.setSerialConsistencyLevel` no longer throws an exception,
383 it will honor the serial consistency level for the batch.
384
385
386### 2.1.1
387
388#### Internal API Changes
389
3901. The `ResultSet` interface has a new `wasApplied()` method. This will
391 only affect clients that provide their own implementation of this interface.
392
393
394### 2.1.0
395
396#### User API Changes
397
3981. The `getCaching` method of `TableMetadata#Options` now returns a
399 `Map` to account for changes to Cassandra 2.1. Also, the
400 `getIndexInterval` method now returns an `Integer` instead of an `int`
401 which will be `null` when connected to Cassandra 2.1 nodes.
402
4032. `BoundStatement` variables that have not been set explicitly will no
404 longer default to `null`. Instead, all variables must be bound explicitly,
405 otherwise the execution of the statement will fail (this also applies to
406 statements inside of a `BatchStatement`). For variables that map to a
407 primitive Java type, a new `setToNull` method has been added.
408 We made this change because the driver might soon distinguish between unset
409 and null variables, so we don't want clients relying on the "leave unset to
410 set to `null`" behavior.
411
412
413#### Internal API Changes
414
415The changes listed in this section should normally not impact end users of the
416driver, but rather third-party frameworks and tools.
417
4181. The `serialize` and `deserialize` methods in `DataType` now take an
419 additional parameter: the protocol version. As explained in the javadoc,
420 if unsure, the proper value to use for this parameter is the protocol version
421 in use by the driver, i.e. the value returned by
422 `cluster.getConfiguration().getProtocolOptions().getProtocolVersion()`.
423
4242. The `parse` method in `DataType` now returns a Java object, not a
425 `ByteBuffer`. The previous behavior can be obtained by calling the
426 `serialize` method on the returned object.
427
4283. The `getValues` method of `RegularStatement` now takes the protocol
429 version as a parameter. As above, the proper value if unsure is almost surely
430 the protocol version in use
431 (`cluster.getConfiguration().getProtocolOptions().getProtocolVersion()`).
432
433
434### 2.0.11
435
4362.0.11 preserves binary compatibility with previous versions. There are a few
437changes in the driver's behavior:
438
4391. The `DefaultRetryPolicy`'s behaviour has changed in the case of an Unavailable
440 exception received from a request. The new behaviour will cause the driver to
441 process a Retry on a different node at most once, otherwise an exception will
442 be thrown. This change makes sense in the case where the node tried initially
443 for the request happens to be isolated from the rest of the cluster (e.g.
444 because of a network partition) but can still answer to the client normally.
445 In this case, trying another node has a chance of success.
446 The previous behaviour was to always throw an exception.
447
4482. A `BuiltStatement` is now considered non-idempotent whenever a `fcall()`
449 or `raw()` is used to build a value to be inserted in the database.
450 If you know that the CQL functions or expressions are safe, use
451 `setIdempotent(true)` on the statement.
452
4533. The list of contact points provided at startup is now shuffled before trying
454 to open the control connection, so that multiple clients with the same contact
455 points don't all pick the same control host. As a result, you can't assume that
456 the driver will try contact points in a deterministic order. In particular, if
457 you use the `DCAwareRoundRobinPolicy` without specifying a primary datacenter
458 name, make sure that you only provide local hosts as contact points.
459
460
461### <a name="2-0-x-to-2-0-10"></a>2.0.x to 2.0.10
462
463We try to avoid breaking changes within a branch (2.0.x to 2.0.y), but
4642.0.10 saw a lot of new features and internal improvements. There is one
465breaking change:
466
4671. `LatencyTracker#update` now has a different signature and takes two new
468 parameters: the statement that has been executed (never null), and the exception
469 thrown while executing the query (or null, if the query executed successfully).
470 Existing implementations of this interface, once upgraded to the new method
471 signature, should continue to work as before.
472
473The following might also be of interest:
474
4752. `SocketOptions#getTcpNoDelay()` is now TRUE by default (it was previously undefined).
476 This reflects the new behavior of Netty (which was upgraded from version 3.9.0 to
477 4.0.27): `TCP_NODELAY` is now turned on by default, instead of depending on the OS
478 default like in previous versions.
479
4803. Netty is not shaded anymore in the default Maven artifact. However we publish a
481 [shaded artifact](../manual/shaded_jar/) under a different classifier.
482
4834. The internal initialization sequence of the Cluster object has been slightly changed:
484 some fields that were previously initialized in the constructor are now set when
485 the `init()` method is called. In particular, `Cluster#getMetrics()` will return
486 `null` until the cluster is initialized.
487
488### 1.0 to 2.0
489
490We used the opportunity of a major version bump to incorporate your feedback
491and improve the API, to fix a number of inconsistencies and remove cruft.
492Unfortunately this means there are some breaking changes, but the new API should
493be both simpler and more complete.
494
495The following describes the changes for 2.0 that are breaking changes of the
4961.0 API. For ease of use, we distinguish two categories of API changes: the "main"
497ones and the "other" ones.
498
499The "main" API changes are the ones that are either
500likely to affect most upgraded apps or are incompatible changes that, even if minor,
501will not be detected at compile time. Upgraders are highly encouraged to check
502this list of "main" changes while upgrading their application to 2.0 (even
503though most applications are likely to be affected by only a handful of
504changes).
505
506The "other" list is, well, other changes: those that are likely to
507affect a minor number of applications and will be detected by compile time
508errors anyway. It is ok to skip those initially and only come back to them if
509you have trouble compiling your application after an upgrade.
510
511#### Main API changes
512
5131. The `Query` class has been renamed into `Statement` (it was confusing
514 to some that the `BoundStatement` was not a `Statement`). To allow
515 this, the old `Statement` class has been renamed to `RegularStatement`.
516
5172. The `Cluster` and `Session` shutdown API has changed. There is now a
518 `closeAsync` that is asynchronous but returns a `Future` on the
519 completion of the shutdown process. There is also a `close` shortcut
520 that does the same but blocks. Also, `close` now waits for ongoing
521 queries to complete by default (but you can force the closing of all
522 connections if you want to).
523
5243. `NoHostAvailableException#getErrors` now returns the full exception objects for
525 each node instead of just a message. In other words, it returns a
526 `Map<InetAddress, Throwable>` instead of a `Map<InetAddress, String>`.
527
5284. `Statement#getConsistencyLevel` (previously `Query#getConsistencyLevel`, see
529 first point) will now return `null` by default (instead of `CL.ONE`), with the
530 meaning of "use the default consistency level".
531 The default consistency level can now be configured through the new `QueryOptions`
532 object in the cluster `Configuration`.
533
5345. The `Metrics` class now uses the Codahale metrics library version 3 (version 2 was
535 used previously). This new major version of the library has many API changes
536 compared to its version 2 (see the [release notes](https://dropwizard.github.io/metrics/3.1.0/about/release-notes/) for details),
537 which can thus impact consumers of the Metrics class.
538 Furthermore, the default `JmxReporter` now includes a name specific to the
539 cluster instance (to avoid conflicts when multiple Cluster instances are created
540 in the same JVM). As a result, tools that were polling JMX info will
541 have to be updated accordingly.
542
5436. The `QueryBuilder#in` method now has the following special case: using
544 `QueryBuilder.in(QueryBuilder.bindMarker())` will generate the string `IN ?`,
545 not `IN (?)` as was the case in 1.0. The reasoning being that the former
546 syntax, made valid by [CASSANDRA-4210](https://issues.apache.org/jira/browse/CASSANDRA-4210)
547 is a lot more useful than `IN (?)`, as the latter can more simply use an
548 equality.
549 Note that if you really want to output `IN (?)` with the query
550 builder, you can use `QueryBuilder.in(QueryBuilder.raw("?"))`.
551
5527. When binding values by name in `BoundStatement` (i.e. using the
553 `setX(String, X)` methods), if more than one variable have the same name,
554 then all values corresponding to that variable
555 name are set instead of just the first occurrence.
556
5578. The `QueryBuilder#raw` method does not automatically add quotes anymore, but
558 rather output its result without any change (as the raw name implies).
559 This means for instance that `eq("x", raw(foo))` will output `x = foo`,
560 not `x = 'foo'` (you don't need the raw method to output the latter string).
561
5629. The `QueryBuilder` will now sometimes use the new ability to send value as
563 bytes instead of serializing everything to string. In general the QueryBuilder
564 will do the right thing, but if you were calling the `getQueryString()` method
565 on a Statement created with a QueryBuilder (for other reasons than to prepare a query)
566 then the returned string may contain bind markers in place of some of the values
567 provided (and in that case, `getValues()` will contain the values corresponding
568 to those markers). If need be, it is possible to force the old behavior by
569 using the new `setForceNoValues()` method.
570
571#### Other API Changes
572
5731. Creating a Cluster instance (through `Cluster#buildFrom` or the
574 `Cluster.Builder#build` method) **does not create any connection right away
575 anymore** (and thus cannot throw a `NoHostAvailableException` or an
576 `AuthenticationException`). Instead, the initial contact points are checked
577 the first time a call to `Cluster#connect` is done. If for some reason you
578 want to emulate the previous behavior, you can use the new method
579 `Cluster#init`: `Cluster.builder().build()` in 1.0 is equivalent to
580 `Cluster.builder().build().init()` in 2.0.
581
5822. Methods from `Metadata`, `KeyspaceMetadata` and `TableMetadata` now use by default
583 case insensitive identifiers (for keyspace, table and column names in
584 parameter). You can double-quote an identifier if you want it to be a
585 case sensitive one (as you would do in CQL) and there is a `Metadata.quote`
586 helper method for that.
587
5883. The `TableMetadata#getClusteringKey` method has been renamed
589 `TableMetadata#getClusteringColumns` to match the "official" vocabulary.
590
5914. The `UnavailableException#getConsistency` method has been renamed to
592 `UnavailableException#getConsistencyLevel` for consistency with the method of
593 `QueryTimeoutException`.
594
5955. The `RegularStatement` class (ex-`Statement` class, see above) must now
596 implement two additional methods: `RegularStatement#getKeyspace` and
597 `RegularStatement#getValues`. If you had extended this class, you will have to
598 implement those new methods, but both can return null if they are not useful
599 in your case.
600
6016. The `Cluster.Initializer` interface should now implement 2 new methods:
602 `Cluster.Initializer#getInitialListeners` (which can return an empty
603 collection) and `Cluster.Initializer#getClusterName` (which can return null).
604
6057. The `Metadata#getReplicas` method now takes 2 arguments. On top of the
606 partition key, you must now provide the keyspace too. The previous behavior
607 was buggy: it's impossible to properly return the full list of replica for a
608 partition key without knowing the keyspace since replication may depend on
609 the keyspace).
610
6118. The method `LoadBalancingPolicy#newQueryPlan()` method now takes the currently
612 logged keyspace as 2nd argument. This information is necessary to do proper
613 token aware balancing (see preceding point).
614
6159. The `ResultSetFuture#set` and `ResultSetFuture#setException` methods have been
616 removed (from the public API at least). They were never meant to be exposed
617 publicly: a `resultSetFuture` is always set by the driver itself and should
618 not be set manually.
619
62010. The deprecated since 1.0.2 `Host.HealthMonitor` class has been removed. You
621 will now need to use `Host#isUp` and `Cluster#register` if you were using that
622 class.
623
624#### Features available only with Cassandra 2.0
625
626This section details the biggest additions to 2.0 API wise. It is not an
627exhaustive list of new features in 2.0.
628
6291. The new `BatchStatement` class allows to group any type of insert Statements
630 (`BoundStatement` or `RegularStatement`) for execution as a batch. For instance,
631 you can do something like:
632
633 ```java
634 List<String> values = ...;
635 PreparedStatement ps = session.prepare("INSERT INTO myTable(value) VALUES (?)");
636 BatchStatement bs = new BatchStatement();
637 for (String value : values)
638 bs.add(ps.bind(value));
639 session.execute(bs);
640 ```
641
6422. `SimpleStatement` can now take a list of values in addition to the query. This
643 allows to do the equivalent of a prepare+execute but with only one round-trip
644 to the server and without keeping the prepared statement after the
645 execution.
646
647 This is typically useful if a given query should be executed only
648 once (i.e. you don't want to prepare it) but you also don't want to
649 serialize all values into strings. Shortcut `Session#execute()` and
650 `Session#executeAsync()` methods are also provided so you that you can do:
651
652 ```java
653 String imgName = ...;
654 ByteBuffer imgBytes = ...;
655 session.execute("INSERT INTO images(name, bytes) VALUES (?, ?)", imgName, imgBytes);
656 ```
657
6583. SELECT queries are now "paged" under the hood. In other words, if a query
659 yields a very large result, only the beginning of the `ResultSet` will be fetched
660 initially, the rest being fetched "on-demand". In practice, this means that:
661
662 ```java
663 for (Row r : session.execute("SELECT * FROM mytable"))
664 ... process r ...
665 ```
666
667 should not timeout or OOM the server anymore even if "mytable" contains a lot
668 of data. In general paging should be transparent for the application (as in
669 the example above), but the implementation provides a number of knobs to
670 fine tune the behavior of that paging:
671 * the size of each "page" can be set per-query (`Statement#setFetchSize()`)
672 * the `ResultSet` object provides 2 methods to check the state of paging
673 (`ResultSet#getAvailableWithoutFetching` and `ResultSet#isFullyFetched`)
674 as well as a mean to force the pre-fetching of the next page (`ResultSet#fetchMoreResults`).