Elffuss BraidHub

kikocis/java-driver public

1663c57e5b30 · 32.5 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
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
272
273### 2.1.8
274
2752.1.8 is binary-compatible with 2.1.7 but introduces a small change in the
276driver's behavior:
277
2781. The list of contact points provided at startup is now shuffled before trying
279 to open the control connection, so that multiple clients with the same contact
280 points don't all pick the same control host. As a result, you can't assume that
281 the driver will try contact points in a deterministic order. In particular, if
282 you use the `DCAwareRoundRobinPolicy` without specifying a primary datacenter
283 name, make sure that you only provide local hosts as contact points.
284
285
286### 2.1.7
287
288This version brings a few changes in the driver's behavior; none of them break
289binary compatibility.
290
2911. The `DefaultRetryPolicy`'s behaviour has changed in the case of an Unavailable
292 exception received from a request. The new behaviour will cause the driver to
293 process a Retry on a different node at most once, otherwise an exception will
294 be thrown. This change makes sense in the case where the node tried initially
295 for the request happens to be isolated from the rest of the cluster (e.g.
296 because of a network partition) but can still answer to the client normally.
297 In this case, trying another node has a chance of success.
298 The previous behaviour was to always throw an exception.
299
3002. The following properties in `PoolingOptions` were renamed:
301 * `MaxSimultaneousRequestsPerConnectionThreshold` to `NewConnectionThreshold`
302 * `MaxSimultaneousRequestsPerHostThreshold` to `MaxRequestsPerConnection`
303
304 The old getters/setters were deprecated, but they delegate to the new
305 ones.
306
307 Also, note that the connection pool for protocol v3 can now be configured to
308 use multiple connections. See [this page](../manual/pooling) for more
309 information.
310
3113. `MappingManager(Session)` will now force the initialization of the `Session`
312 if needed. This is a change from 2.1.6, where if you gave it an uninitialized
313 session (created with `Cluster#newSession()` instead of `Cluster#connect()`),
314 it would only get initialized on the first request.
315
316 If this is a problem for you, `MappingManager(Session, ProtocolVersion)`
317 preserves the previous behavior (see the API docs for more details).
318
3194. A `BuiltStatement` is now considered non-idempotent whenever a `fcall()`
320 or `raw()` is used to build a value to be inserted in the database.
321 If you know that the CQL functions or expressions are safe, use
322 `setIdempotent(true)` on the statement.
323
324### 2.1.6
325
326See [2.0.10](#2-0-x-to-2-0-10).
327
328
329### 2.1.2
330
3312.1.2 brings important internal changes with native protocol v3 support, but
332the impact on the public API has been kept as low as possible.
333
334#### User API Changes
335
3361. The native protocol version is now modelled as an enum: `ProtocolVersion`.
337 Most public methods that take it as an argument have a backward-compatible
338 version that takes an `int` (the exception being `RegularStatement`,
339 described below). For new code, prefer the enum version.
340
341#### Internal API Changes
342
3431. `RegularStatement.getValues` now takes the protocol version as a
344 `ProtocolVersion` instead of an `int`. This is transparent for callers
345 since there is a backward-compatible alternative, but if you happened to
346 extend the class you'll need to update your implementation.
347
3482. `BatchStatement.setSerialConsistencyLevel` now returns `BatchStatement`
349 instead of `Statement`. Again, this only matters if you extended this
350 class (if so, it might be a good idea to also have a covariant return in
351 your child class).
352
3533. The constructor of `UnsupportedFeatureException` now takes a
354 `ProtocolVersion` as a parameter. This should impact few users, as there's
355 hardly any reason to build instances of that class from client code.
356
357#### New features
358
359These features are only active when the native protocol v3 is in use.
360
3611. The driver now uses a single connection per host (as opposed to a pool in
362 2.1.1). Most options in `PoolingOptions` are ignored, except for a new one
363 called `maxSimultaneousRequestsPerHostThreshold`. See the class's Javadocs
364 for detailed explanations.
365
3662. You can now provide a default timestamp with each query (but it will be
367 ignored if the CQL query string already contains a `USING TIMESTAMP`
368 clause). This can be done on a per-statement basis with
369 `Statement.setDefaultTimestamp`, or automatically with a
370 `TimestampGenerator` specified with
371 `Cluster.Builder.withTimestampGenerator` (two implementations are
372 provided: `ThreadLocalMonotonicTimestampGenerator` and
373 `AtomicMonotonicTimestampGenerator`). If you specify both, the statement's
374 timestamp takes precedence over the generator. By default, the driver has
375 the same behavior as 2.1.1 (no generator, timestamps are assigned by
376 Cassandra unless `USING TIMESTAMP` was specified).
377
3783. `BatchStatement.setSerialConsistencyLevel` no longer throws an exception,
379 it will honor the serial consistency level for the batch.
380
381
382### 2.1.1
383
384#### Internal API Changes
385
3861. The `ResultSet` interface has a new `wasApplied()` method. This will
387 only affect clients that provide their own implementation of this interface.
388
389
390### 2.1.0
391
392#### User API Changes
393
3941. The `getCaching` method of `TableMetadata#Options` now returns a
395 `Map` to account for changes to Cassandra 2.1. Also, the
396 `getIndexInterval` method now returns an `Integer` instead of an `int`
397 which will be `null` when connected to Cassandra 2.1 nodes.
398
3992. `BoundStatement` variables that have not been set explicitly will no
400 longer default to `null`. Instead, all variables must be bound explicitly,
401 otherwise the execution of the statement will fail (this also applies to
402 statements inside of a `BatchStatement`). For variables that map to a
403 primitive Java type, a new `setToNull` method has been added.
404 We made this change because the driver might soon distinguish between unset
405 and null variables, so we don't want clients relying on the "leave unset to
406 set to `null`" behavior.
407
408
409#### Internal API Changes
410
411The changes listed in this section should normally not impact end users of the
412driver, but rather third-party frameworks and tools.
413
4141. The `serialize` and `deserialize` methods in `DataType` now take an
415 additional parameter: the protocol version. As explained in the javadoc,
416 if unsure, the proper value to use for this parameter is the protocol version
417 in use by the driver, i.e. the value returned by
418 `cluster.getConfiguration().getProtocolOptions().getProtocolVersion()`.
419
4202. The `parse` method in `DataType` now returns a Java object, not a
421 `ByteBuffer`. The previous behavior can be obtained by calling the
422 `serialize` method on the returned object.
423
4243. The `getValues` method of `RegularStatement` now takes the protocol
425 version as a parameter. As above, the proper value if unsure is almost surely
426 the protocol version in use
427 (`cluster.getConfiguration().getProtocolOptions().getProtocolVersion()`).
428
429
430### 2.0.11
431
4322.0.11 preserves binary compatibility with previous versions. There are a few
433changes in the driver's behavior:
434
4351. The `DefaultRetryPolicy`'s behaviour has changed in the case of an Unavailable
436 exception received from a request. The new behaviour will cause the driver to
437 process a Retry on a different node at most once, otherwise an exception will
438 be thrown. This change makes sense in the case where the node tried initially
439 for the request happens to be isolated from the rest of the cluster (e.g.
440 because of a network partition) but can still answer to the client normally.
441 In this case, trying another node has a chance of success.
442 The previous behaviour was to always throw an exception.
443
4442. A `BuiltStatement` is now considered non-idempotent whenever a `fcall()`
445 or `raw()` is used to build a value to be inserted in the database.
446 If you know that the CQL functions or expressions are safe, use
447 `setIdempotent(true)` on the statement.
448
4493. The list of contact points provided at startup is now shuffled before trying
450 to open the control connection, so that multiple clients with the same contact
451 points don't all pick the same control host. As a result, you can't assume that
452 the driver will try contact points in a deterministic order. In particular, if
453 you use the `DCAwareRoundRobinPolicy` without specifying a primary datacenter
454 name, make sure that you only provide local hosts as contact points.
455
456
457### <a name="2-0-x-to-2-0-10"></a>2.0.x to 2.0.10
458
459We try to avoid breaking changes within a branch (2.0.x to 2.0.y), but
4602.0.10 saw a lot of new features and internal improvements. There is one
461breaking change:
462
4631. `LatencyTracker#update` now has a different signature and takes two new
464 parameters: the statement that has been executed (never null), and the exception
465 thrown while executing the query (or null, if the query executed successfully).
466 Existing implementations of this interface, once upgraded to the new method
467 signature, should continue to work as before.
468
469The following might also be of interest:
470
4712. `SocketOptions#getTcpNoDelay()` is now TRUE by default (it was previously undefined).
472 This reflects the new behavior of Netty (which was upgraded from version 3.9.0 to
473 4.0.27): `TCP_NODELAY` is now turned on by default, instead of depending on the OS
474 default like in previous versions.
475
4763. Netty is not shaded anymore in the default Maven artifact. However we publish a
477 [shaded artifact](../manual/shaded_jar/) under a different classifier.
478
4794. The internal initialization sequence of the Cluster object has been slightly changed:
480 some fields that were previously initialized in the constructor are now set when
481 the `init()` method is called. In particular, `Cluster#getMetrics()` will return
482 `null` until the cluster is initialized.
483
484### 1.0 to 2.0
485
486We used the opportunity of a major version bump to incorporate your feedback
487and improve the API, to fix a number of inconsistencies and remove cruft.
488Unfortunately this means there are some breaking changes, but the new API should
489be both simpler and more complete.
490
491The following describes the changes for 2.0 that are breaking changes of the
4921.0 API. For ease of use, we distinguish two categories of API changes: the "main"
493ones and the "other" ones.
494
495The "main" API changes are the ones that are either
496likely to affect most upgraded apps or are incompatible changes that, even if minor,
497will not be detected at compile time. Upgraders are highly encouraged to check
498this list of "main" changes while upgrading their application to 2.0 (even
499though most applications are likely to be affected by only a handful of
500changes).
501
502The "other" list is, well, other changes: those that are likely to
503affect a minor number of applications and will be detected by compile time
504errors anyway. It is ok to skip those initially and only come back to them if
505you have trouble compiling your application after an upgrade.
506
507#### Main API changes
508
5091. The `Query` class has been renamed into `Statement` (it was confusing
510 to some that the `BoundStatement` was not a `Statement`). To allow
511 this, the old `Statement` class has been renamed to `RegularStatement`.
512
5132. The `Cluster` and `Session` shutdown API has changed. There is now a
514 `closeAsync` that is asynchronous but returns a `Future` on the
515 completion of the shutdown process. There is also a `close` shortcut
516 that does the same but blocks. Also, `close` now waits for ongoing
517 queries to complete by default (but you can force the closing of all
518 connections if you want to).
519
5203. `NoHostAvailableException#getErrors` now returns the full exception objects for
521 each node instead of just a message. In other words, it returns a
522 `Map<InetAddress, Throwable>` instead of a `Map<InetAddress, String>`.
523
5244. `Statement#getConsistencyLevel` (previously `Query#getConsistencyLevel`, see
525 first point) will now return `null` by default (instead of `CL.ONE`), with the
526 meaning of "use the default consistency level".
527 The default consistency level can now be configured through the new `QueryOptions`
528 object in the cluster `Configuration`.
529
5305. The `Metrics` class now uses the Codahale metrics library version 3 (version 2 was
531 used previously). This new major version of the library has many API changes
532 compared to its version 2 (see the [release notes](https://dropwizard.github.io/metrics/3.1.0/about/release-notes/) for details),
533 which can thus impact consumers of the Metrics class.
534 Furthermore, the default `JmxReporter` now includes a name specific to the
535 cluster instance (to avoid conflicts when multiple Cluster instances are created
536 in the same JVM). As a result, tools that were polling JMX info will
537 have to be updated accordingly.
538
5396. The `QueryBuilder#in` method now has the following special case: using
540 `QueryBuilder.in(QueryBuilder.bindMarker())` will generate the string `IN ?`,
541 not `IN (?)` as was the case in 1.0. The reasoning being that the former
542 syntax, made valid by [CASSANDRA-4210](https://issues.apache.org/jira/browse/CASSANDRA-4210)
543 is a lot more useful than `IN (?)`, as the latter can more simply use an
544 equality.
545 Note that if you really want to output `IN (?)` with the query
546 builder, you can use `QueryBuilder.in(QueryBuilder.raw("?"))`.
547
5487. When binding values by name in `BoundStatement` (i.e. using the
549 `setX(String, X)` methods), if more than one variable have the same name,
550 then all values corresponding to that variable
551 name are set instead of just the first occurrence.
552
5538. The `QueryBuilder#raw` method does not automatically add quotes anymore, but
554 rather output its result without any change (as the raw name implies).
555 This means for instance that `eq("x", raw(foo))` will output `x = foo`,
556 not `x = 'foo'` (you don't need the raw method to output the latter string).
557
5589. The `QueryBuilder` will now sometimes use the new ability to send value as
559 bytes instead of serializing everything to string. In general the QueryBuilder
560 will do the right thing, but if you were calling the `getQueryString()` method
561 on a Statement created with a QueryBuilder (for other reasons than to prepare a query)
562 then the returned string may contain bind markers in place of some of the values
563 provided (and in that case, `getValues()` will contain the values corresponding
564 to those markers). If need be, it is possible to force the old behavior by
565 using the new `setForceNoValues()` method.
566
567#### Other API Changes
568
5691. Creating a Cluster instance (through `Cluster#buildFrom` or the
570 `Cluster.Builder#build` method) **does not create any connection right away
571 anymore** (and thus cannot throw a `NoHostAvailableException` or an
572 `AuthenticationException`). Instead, the initial contact points are checked
573 the first time a call to `Cluster#connect` is done. If for some reason you
574 want to emulate the previous behavior, you can use the new method
575 `Cluster#init`: `Cluster.builder().build()` in 1.0 is equivalent to
576 `Cluster.builder().build().init()` in 2.0.
577
5782. Methods from `Metadata`, `KeyspaceMetadata` and `TableMetadata` now use by default
579 case insensitive identifiers (for keyspace, table and column names in
580 parameter). You can double-quote an identifier if you want it to be a
581 case sensitive one (as you would do in CQL) and there is a `Metadata.quote`
582 helper method for that.
583
5843. The `TableMetadata#getClusteringKey` method has been renamed
585 `TableMetadata#getClusteringColumns` to match the "official" vocabulary.
586
5874. The `UnavailableException#getConsistency` method has been renamed to
588 `UnavailableException#getConsistencyLevel` for consistency with the method of
589 `QueryTimeoutException`.
590
5915. The `RegularStatement` class (ex-`Statement` class, see above) must now
592 implement two additional methods: `RegularStatement#getKeyspace` and
593 `RegularStatement#getValues`. If you had extended this class, you will have to
594 implement those new methods, but both can return null if they are not useful
595 in your case.
596
5976. The `Cluster.Initializer` interface should now implement 2 new methods:
598 `Cluster.Initializer#getInitialListeners` (which can return an empty
599 collection) and `Cluster.Initializer#getClusterName` (which can return null).
600
6017. The `Metadata#getReplicas` method now takes 2 arguments. On top of the
602 partition key, you must now provide the keyspace too. The previous behavior
603 was buggy: it's impossible to properly return the full list of replica for a
604 partition key without knowing the keyspace since replication may depend on
605 the keyspace).
606
6078. The method `LoadBalancingPolicy#newQueryPlan()` method now takes the currently
608 logged keyspace as 2nd argument. This information is necessary to do proper
609 token aware balancing (see preceding point).
610
6119. The `ResultSetFuture#set` and `ResultSetFuture#setException` methods have been
612 removed (from the public API at least). They were never meant to be exposed
613 publicly: a `resultSetFuture` is always set by the driver itself and should
614 not be set manually.
615
61610. The deprecated since 1.0.2 `Host.HealthMonitor` class has been removed. You
617 will now need to use `Host#isUp` and `Cluster#register` if you were using that
618 class.
619
620#### Features available only with Cassandra 2.0
621
622This section details the biggest additions to 2.0 API wise. It is not an
623exhaustive list of new features in 2.0.
624
6251. The new `BatchStatement` class allows to group any type of insert Statements
626 (`BoundStatement` or `RegularStatement`) for execution as a batch. For instance,
627 you can do something like:
628
629 ```java
630 List<String> values = ...;
631 PreparedStatement ps = session.prepare("INSERT INTO myTable(value) VALUES (?)");
632 BatchStatement bs = new BatchStatement();
633 for (String value : values)
634 bs.add(ps.bind(value));
635 session.execute(bs);
636 ```
637
6382. `SimpleStatement` can now take a list of values in addition to the query. This
639 allows to do the equivalent of a prepare+execute but with only one round-trip
640 to the server and without keeping the prepared statement after the
641 execution.
642
643 This is typically useful if a given query should be executed only
644 once (i.e. you don't want to prepare it) but you also don't want to
645 serialize all values into strings. Shortcut `Session#execute()` and
646 `Session#executeAsync()` methods are also provided so you that you can do:
647
648 ```java
649 String imgName = ...;
650 ByteBuffer imgBytes = ...;
651 session.execute("INSERT INTO images(name, bytes) VALUES (?, ?)", imgName, imgBytes);
652 ```
653
6543. SELECT queries are now "paged" under the hood. In other words, if a query
655 yields a very large result, only the beginning of the `ResultSet` will be fetched
656 initially, the rest being fetched "on-demand". In practice, this means that:
657
658 ```java
659 for (Row r : session.execute("SELECT * FROM mytable"))
660 ... process r ...
661 ```
662
663 should not timeout or OOM the server anymore even if "mytable" contains a lot
664 of data. In general paging should be transparent for the application (as in
665 the example above), but the implementation provides a number of knobs to
666 fine tune the behavior of that paging:
667 * the size of each "page" can be set per-query (`Statement#setFetchSize()`)
668 * the `ResultSet` object provides 2 methods to check the state of paging
669 (`ResultSet#getAvailableWithoutFetching` and `ResultSet#isFullyFetched`)
670 as well as a mean to force the pre-fetching of the next page (`ResultSet#fetchMoreResults`).