Elffuss BraidHub

kikocis/java-driver public

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