Elffuss BraidHub

kikocis/java-driver public

cf32ad67f65d · 29.3 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_QUORUM`.
152. [Custom codecs](../features/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 most methods that dealt with serialization and deserialization of data types have been removed:
22 * `ByteBuffer serialize(Object value, ProtocolVersion protocolVersion)`
23 * `ByteBuffer serializeValue(Object value, ProtocolVersion protocolVersion)`
24 * `Object deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion)`
25 * `Object deserialize(ByteBuffer bytes, int protocolVersion)`
26 * `Object parse(String value)`
27 * `String format(Object value)`
28 * `Class<?> asJavaClass()`
29 * `GettableByIndexData` (affects `Row`, `BoundStatement`, `TupleValue` and `UDTValue`). The following public methods were added:
30 * `<T> T get(int i, Class<T> targetClass)`
31 * `<T> T get(int i, TypeToken<T> targetType)`
32 * `<T> T get(int i, TypeCodec<T> codec)`
33 * `GettableByNameData` (affects `Row`, `BoundStatement` and `UDTValue`). The following public methods were added:
34 * `<T> T get(String name, Class<T> targetClass)`
35 * `<T> T get(String name, TypeToken<T> targetType)`
36 * `<T> T get(String name, TypeCodec<T> codec)`
37 * `SettableByIndexData` (affects `Row`, `BoundStatement`, `TupleValue` and `UDTValue`). The following public methods were added:
38 * `<V> T set(int i, V v, Class<V> targetClass)`
39 * `<V> T set(int i, V v, TypeToken<V> targetType)`
40 * `<V> T set(int i, V v, TypeCodec<V> codec)`
41 * `SettableByNameData` (affects `Row`, `BoundStatement` and `UDTValue`). The following public methods were added:
42 * `<V> T set(String name, V v, Class<V> targetClass)`
43 * `<V> T set(String name, V v, TypeToken<V> targetType)`
44 * `<V> T set(String name, V v, TypeCodec<V> codec)`
45 * `Session`. The following methods were added:
46 * `newSimpleStatement(String query)`
47 * `newSimpleStatement(String query, Object... values)`
48 * `RegularStatement`. The following public methods were modified:
49 * `getValues()`
50 * `hasValues()`
51 * `SimpleStatement`. Public constructors were removed; users are required to call either:
52 * `Session.newSimpleStatement(String query)` or
53 * `Session.newSimpleStatement(String query, Object... values)`
54 * `QueryBuilder`. This class now has a single, public constructor: `QueryBuilder(Cluster cluster)`.
55 Its fluent API has also changed; instead of e.g.: `QueryBuilder.select(...)`,
56 users should now use the following idiom: `new QueryBuilder(cluster).select(...)`
57 All methods that start a query are now instance methods instead of static ones.
58 * `PreparedStatement`. The following public method was added:
59 * `CodecRegistry getCodecRegistry()`.
60 * `TupleType`. The following public method was deleted:
61 * `TupleType of(DataType... types)`; users should now use `Metadata.newTupleType(DataType...)`.
62
63 <p>The driver runtime behavior changes in the following situations:</p>
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](../features/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](../features/query_timestamps/) is
139 now the default (provided that [native
140 protocol](../features/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](../features/custom_payloads):
150 * in `PreparedStatement`: `getIncomingPayload()`,
151 `getOutgoingPayload()` and
152 `setOutgoingPayload(Map<String,ByteBuffer>)`
153 * `AbstractSession#prepareAsync(String, Map<String,ByteBuffer>)`
154
155 Also, not that `AbstractSession#prepareAsync(Statement)` does not
156 call `AbstractSession#prepareAsync(String)` anymore, they now both
157 delegate to a private 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
205
206### 2.1.8
207
2082.1.8 is binary-compatible with 2.1.7 but introduces a small change in the
209driver's behavior:
210
2111. The list of contact points provided at startup is now shuffled before trying
212 to open the control connection, so that multiple clients with the same contact
213 points don't all pick the same control host. As a result, you can't assume that
214 the driver will try contact points in a deterministic order. In particular, if
215 you use the `DCAwareRoundRobinPolicy` without specifying a primary datacenter
216 name, make sure that you only provide local hosts as contact points.
217
218
219### 2.1.7
220
221This version brings a few changes in the driver's behavior; none of them break
222binary compatibility.
223
2241. The `DefaultRetryPolicy`'s behaviour has changed in the case of an Unavailable
225 exception received from a request. The new behaviour will cause the driver to
226 process a Retry on a different node at most once, otherwise an exception will
227 be thrown. This change makes sense in the case where the node tried initially
228 for the request happens to be isolated from the rest of the cluster (e.g.
229 because of a network partition) but can still answer to the client normally.
230 In this case, trying another node has a chance of success.
231 The previous behaviour was to always throw an exception.
232
2332. The following properties in `PoolingOptions` were renamed:
234 * `MaxSimultaneousRequestsPerConnectionThreshold` to `NewConnectionThreshold`
235 * `MaxSimultaneousRequestsPerHostThreshold` to `MaxRequestsPerConnection`
236
237 The old getters/setters were deprecated, but they delegate to the new
238 ones.
239
240 Also, note that the connection pool for protocol v3 can now be configured to
241 use multiple connections. See [this page](../features/pooling) for more
242 information.
243
2443. `MappingManager(Session)` will now force the initialization of the `Session`
245 if needed. This is a change from 2.1.6, where if you gave it an uninitialized
246 session (created with `Cluster#newSession()` instead of `Cluster#connect()`),
247 it would only get initialized on the first request.
248
249 If this is a problem for you, `MappingManager(Session, ProtocolVersion)`
250 preserves the previous behavior (see the API docs for more details).
251
2524. A `BuiltStatement` is now considered non-idempotent whenever a `fcall()`
253 or `raw()` is used to build a value to be inserted in the database.
254 If you know that the CQL functions or expressions are safe, use
255 `setIdempotent(true)` on the statement.
256
257### 2.1.6
258
259See [2.0.10](#2-0-x-to-2-0-10).
260
261
262### 2.1.2
263
2642.1.2 brings important internal changes with native protocol v3 support, but
265the impact on the public API has been kept as low as possible.
266
267#### User API Changes
268
2691. The native protocol version is now modelled as an enum: `ProtocolVersion`.
270 Most public methods that take it as an argument have a backward-compatible
271 version that takes an `int` (the exception being `RegularStatement`,
272 described below). For new code, prefer the enum version.
273
274#### Internal API Changes
275
2761. `RegularStatement.getValues` now takes the protocol version as a
277 `ProtocolVersion` instead of an `int`. This is transparent for callers
278 since there is a backward-compatible alternative, but if you happened to
279 extend the class you'll need to update your implementation.
280
2812. `BatchStatement.setSerialConsistencyLevel` now returns `BatchStatement`
282 instead of `Statement`. Again, this only matters if you extended this
283 class (if so, it might be a good idea to also have a covariant return in
284 your child class).
285
2863. The constructor of `UnsupportedFeatureException` now takes a
287 `ProtocolVersion` as a parameter. This should impact few users, as there's
288 hardly any reason to build instances of that class from client code.
289
290#### New features
291
292These features are only active when the native protocol v3 is in use.
293
2941. The driver now uses a single connection per host (as opposed to a pool in
295 2.1.1). Most options in `PoolingOptions` are ignored, except for a new one
296 called `maxSimultaneousRequestsPerHostThreshold`. See the class's Javadocs
297 for detailed explanations.
298
2992. You can now provide a default timestamp with each query (but it will be
300 ignored if the CQL query string already contains a `USING TIMESTAMP`
301 clause). This can be done on a per-statement basis with
302 `Statement.setDefaultTimestamp`, or automatically with a
303 `TimestampGenerator` specified with
304 `Cluster.Builder.withTimestampGenerator` (two implementations are
305 provided: `ThreadLocalMonotonicTimestampGenerator` and
306 `AtomicMonotonicTimestampGenerator`). If you specify both, the statement's
307 timestamp takes precedence over the generator. By default, the driver has
308 the same behavior as 2.1.1 (no generator, timestamps are assigned by
309 Cassandra unless `USING TIMESTAMP` was specified).
310
3113. `BatchStatement.setSerialConsistencyLevel` no longer throws an exception,
312 it will honor the serial consistency level for the batch.
313
314
315### 2.1.1
316
317#### Internal API Changes
318
3191. The `ResultSet` interface has a new `wasApplied()` method. This will
320 only affect clients that provide their own implementation of this interface.
321
322
323### 2.1.0
324
325#### User API Changes
326
3271. The `getCaching` method of `TableMetadata#Options` now returns a
328 `Map` to account for changes to Cassandra 2.1. Also, the
329 `getIndexInterval` method now returns an `Integer` instead of an `int`
330 which will be `null` when connected to Cassandra 2.1 nodes.
331
3322. `BoundStatement` variables that have not been set explicitly will no
333 longer default to `null`. Instead, all variables must be bound explicitly,
334 otherwise the execution of the statement will fail (this also applies to
335 statements inside of a `BatchStatement`). For variables that map to a
336 primitive Java type, a new `setToNull` method has been added.
337 We made this change because the driver might soon distinguish between unset
338 and null variables, so we don't want clients relying on the "leave unset to
339 set to `null`" behavior.
340
341
342#### Internal API Changes
343
344The changes listed in this section should normally not impact end users of the
345driver, but rather third-party frameworks and tools.
346
3471. The `serialize` and `deserialize` methods in `DataType` now take an
348 additional parameter: the protocol version. As explained in the javadoc,
349 if unsure, the proper value to use for this parameter is the protocol version
350 in use by the driver, i.e. the value returned by
351 `cluster.getConfiguration().getProtocolOptions().getProtocolVersion()`.
352
3532. The `parse` method in `DataType` now returns a Java object, not a
354 `ByteBuffer`. The previous behavior can be obtained by calling the
355 `serialize` method on the returned object.
356
3573. The `getValues` method of `RegularStatement` now takes the protocol
358 version as a parameter. As above, the proper value if unsure is almost surely
359 the protocol version in use
360 (`cluster.getConfiguration().getProtocolOptions().getProtocolVersion()`).
361
362
363### 2.0.11
364
3652.0.11 preserves binary compatibility with previous versions. There are a few
366changes in the driver's behavior:
367
3681. The `DefaultRetryPolicy`'s behaviour has changed in the case of an Unavailable
369 exception received from a request. The new behaviour will cause the driver to
370 process a Retry on a different node at most once, otherwise an exception will
371 be thrown. This change makes sense in the case where the node tried initially
372 for the request happens to be isolated from the rest of the cluster (e.g.
373 because of a network partition) but can still answer to the client normally.
374 In this case, trying another node has a chance of success.
375 The previous behaviour was to always throw an exception.
376
3772. A `BuiltStatement` is now considered non-idempotent whenever a `fcall()`
378 or `raw()` is used to build a value to be inserted in the database.
379 If you know that the CQL functions or expressions are safe, use
380 `setIdempotent(true)` on the statement.
381
3823. The list of contact points provided at startup is now shuffled before trying
383 to open the control connection, so that multiple clients with the same contact
384 points don't all pick the same control host. As a result, you can't assume that
385 the driver will try contact points in a deterministic order. In particular, if
386 you use the `DCAwareRoundRobinPolicy` without specifying a primary datacenter
387 name, make sure that you only provide local hosts as contact points.
388
389
390### <a name="2-0-x-to-2-0-10"></a>2.0.x to 2.0.10
391
392We try to avoid breaking changes within a branch (2.0.x to 2.0.y), but
3932.0.10 saw a lot of new features and internal improvements. There is one
394breaking change:
395
3961. `LatencyTracker#update` now has a different signature and takes two new
397 parameters: the statement that has been executed (never null), and the exception
398 thrown while executing the query (or null, if the query executed successfully).
399 Existing implementations of this interface, once upgraded to the new method
400 signature, should continue to work as before.
401
402The following might also be of interest:
403
4042. `SocketOptions#getTcpNoDelay()` is now TRUE by default (it was previously undefined).
405 This reflects the new behavior of Netty (which was upgraded from version 3.9.0 to
406 4.0.27): `TCP_NODELAY` is now turned on by default, instead of depending on the OS
407 default like in previous versions.
408
4093. Netty is not shaded anymore in the default Maven artifact. However we publish a
410 [shaded artifact](../features/shaded_jar/) under a different classifier.
411
4124. The internal initialization sequence of the Cluster object has been slightly changed:
413 some fields that were previously initialized in the constructor are now set when
414 the `init()` method is called. This is unlikely to affect regular driver users.
415
416### 1.0 to 2.0
417
418We used the opportunity of a major version bump to incorporate your feedback
419and improve the API, to fix a number of inconsistencies and remove cruft.
420Unfortunately this means there are some breaking changes, but the new API should
421be both simpler and more complete.
422
423The following describes the changes for 2.0 that are breaking changes of the
4241.0 API. For ease of use, we distinguish two categories of API changes: the "main"
425ones and the "other" ones.
426
427The "main" API changes are the ones that are either
428likely to affect most upgraded apps or are incompatible changes that, even if minor,
429will not be detected at compile time. Upgraders are highly encouraged to check
430this list of "main" changes while upgrading their application to 2.0 (even
431though most applications are likely to be affected by only a handful of
432changes).
433
434The "other" list is, well, other changes: those that are likely to
435affect a minor number of applications and will be detected by compile time
436errors anyway. It is ok to skip those initially and only come back to them if
437you have trouble compiling your application after an upgrade.
438
439#### Main API changes
440
4411. The `Query` class has been renamed into `Statement` (it was confusing
442 to some that the `BoundStatement` was not a `Statement`). To allow
443 this, the old `Statement` class has been renamed to `RegularStatement`.
444
4452. The `Cluster` and `Session` shutdown API has changed. There is now a
446 `closeAsync` that is asynchronous but returns a `Future` on the
447 completion of the shutdown process. There is also a `close` shortcut
448 that does the same but blocks. Also, `close` now waits for ongoing
449 queries to complete by default (but you can force the closing of all
450 connections if you want to).
451
4523. `NoHostAvailableException#getErrors` now returns the full exception objects for
453 each node instead of just a message. In other words, it returns a
454 `Map<InetAddress, Throwable>` instead of a `Map<InetAddress, String>`.
455
4564. `Statement#getConsistencyLevel` (previously `Query#getConsistencyLevel`, see
457 first point) will now return `null` by default (instead of `CL.ONE`), with the
458 meaning of "use the default consistency level".
459 The default consistency level can now be configured through the new `QueryOptions`
460 object in the cluster `Configuration`.
461
4625. The `Metrics` class now uses the Codahale metrics library version 3 (version 2 was
463 used previously). This new major version of the library has many API changes
464 compared to its version 2 (see the [release notes](https://dropwizard.github.io/metrics/3.1.0/about/release-notes/) for details),
465 which can thus impact consumers of the Metrics class.
466 Furthermore, the default `JmxReporter` now includes a name specific to the
467 cluster instance (to avoid conflicts when multiple Cluster instances are created
468 in the same JVM). As a result, tools that were polling JMX info will
469 have to be updated accordingly.
470
4716. The `QueryBuilder#in` method now has the following special case: using
472 `QueryBuilder.in(QueryBuilder.bindMarker())` will generate the string `IN ?`,
473 not `IN (?)` as was the case in 1.0. The reasoning being that the former
474 syntax, made valid by [CASSANDRA-4210](https://issues.apache.org/jira/browse/CASSANDRA-4210)
475 is a lot more useful than `IN (?)`, as the latter can more simply use an
476 equality.
477 Note that if you really want to output `IN (?)` with the query
478 builder, you can use `QueryBuilder.in(QueryBuilder.raw("?"))`.
479
4807. When binding values by name in `BoundStatement` (i.e. using the
481 `setX(String, X)` methods), if more than one variable have the same name,
482 then all values corresponding to that variable
483 name are set instead of just the first occurrence.
484
4858. The `QueryBuilder#raw` method does not automatically add quotes anymore, but
486 rather output its result without any change (as the raw name implies).
487 This means for instance that `eq("x", raw(foo))` will output `x = foo`,
488 not `x = 'foo'` (you don't need the raw method to output the latter string).
489
4909. The `QueryBuilder` will now sometimes use the new ability to send value as
491 bytes instead of serializing everything to string. In general the QueryBuilder
492 will do the right thing, but if you were calling the `getQueryString()` method
493 on a Statement created with a QueryBuilder (for other reasons than to prepare a query)
494 then the returned string may contain bind markers in place of some of the values
495 provided (and in that case, `getValues()` will contain the values corresponding
496 to those markers). If need be, it is possible to force the old behavior by
497 using the new `setForceNoValues()` method.
498
499#### Other API Changes
500
5011. Creating a Cluster instance (through `Cluster#buildFrom` or the
502 `Cluster.Builder#build` method) **does not create any connection right away
503 anymore** (and thus cannot throw a `NoHostAvailableException` or an
504 `AuthenticationException`). Instead, the initial contact points are checked
505 the first time a call to `Cluster#connect` is done. If for some reason you
506 want to emulate the previous behavior, you can use the new method
507 `Cluster#init`: `Cluster.builder().build()` in 1.0 is equivalent to
508 `Cluster.builder().build().init()` in 2.0.
509
5102. Methods from `Metadata`, `KeyspaceMetadata` and `TableMetadata` now use by default
511 case insensitive identifiers (for keyspace, table and column names in
512 parameter). You can double-quote an identifier if you want it to be a
513 case sensitive one (as you would do in CQL) and there is a `Metadata.quote`
514 helper method for that.
515
5163. The `TableMetadata#getClusteringKey` method has been renamed
517 `TableMetadata#getClusteringColumns` to match the "official" vocabulary.
518
5194. The `UnavailableException#getConsistency` method has been renamed to
520 `UnavailableException#getConsistencyLevel` for consistency with the method of
521 `QueryTimeoutException`.
522
5235. The `RegularStatement` class (ex-`Statement` class, see above) must now
524 implement two additional methods: `RegularStatement#getKeyspace` and
525 `RegularStatement#getValues`. If you had extended this class, you will have to
526 implement those new methods, but both can return null if they are not useful
527 in your case.
528
5296. The `Cluster.Initializer` interface should now implement 2 new methods:
530 `Cluster.Initializer#getInitialListeners` (which can return an empty
531 collection) and `Cluster.Initializer#getClusterName` (which can return null).
532
5337. The `Metadata#getReplicas` method now takes 2 arguments. On top of the
534 partition key, you must now provide the keyspace too. The previous behavior
535 was buggy: it's impossible to properly return the full list of replica for a
536 partition key without knowing the keyspace since replication may depend on
537 the keyspace).
538
5398. The method `LoadBalancingPolicy#newQueryPlan()` method now takes the currently
540 logged keyspace as 2nd argument. This information is necessary to do proper
541 token aware balancing (see preceding point).
542
5439. The `ResultSetFuture#set` and `ResultSetFuture#setException` methods have been
544 removed (from the public API at least). They were never meant to be exposed
545 publicly: a `resultSetFuture` is always set by the driver itself and should
546 not be set manually.
547
54810. The deprecated since 1.0.2 `Host.HealthMonitor` class has been removed. You
549 will now need to use `Host#isUp` and `Cluster#register` if you were using that
550 class.
551
552#### Features available only with Cassandra 2.0
553
554This section details the biggest additions to 2.0 API wise. It is not an
555exhaustive list of new features in 2.0.
556
5571. The new `BatchStatement` class allows to group any type of insert Statements
558 (`BoundStatement` or `RegularStatement`) for execution as a batch. For instance,
559 you can do something like:
560
561 ```java
562 List<String> values = ...;
563 PreparedStatement ps = session.prepare("INSERT INTO myTable(value) VALUES (?)");
564 BatchStatement bs = new BatchStatement();
565 for (String value : values)
566 bs.add(ps.bind(value));
567 session.execute(bs);
568 ```
569
5702. `SimpleStatement` can now take a list of values in addition to the query. This
571 allows to do the equivalent of a prepare+execute but with only one round-trip
572 to the server and without keeping the prepared statement after the
573 execution.
574
575 This is typically useful if a given query should be executed only
576 once (i.e. you don't want to prepare it) but you also don't want to
577 serialize all values into strings. Shortcut `Session#execute()` and
578 `Session#executeAsync()` methods are also provided so you that you can do:
579
580 ```java
581 String imgName = ...;
582 ByteBuffer imgBytes = ...;
583 session.execute("INSERT INTO images(name, bytes) VALUES (?, ?)", imgName, imgBytes);
584 ```
585
5863. SELECT queries are now "paged" under the hood. In other words, if a query
587 yields a very large result, only the beginning of the `ResultSet` will be fetched
588 initially, the rest being fetched "on-demand". In practice, this means that:
589
590 ```java
591 for (Row r : session.execute("SELECT * FROM mytable"))
592 ... process r ...
593 ```
594
595 should not timeout or OOM the server anymore even if "mytable" contains a lot
596 of data. In general paging should be transparent for the application (as in
597 the example above), but the implementation provides a number of knobs to
598 fine tune the behavior of that paging:
599 * the size of each "page" can be set per-query (`Statement#setFetchSize()`)
600 * the `ResultSet` object provides 2 methods to check the state of paging
601 (`ResultSet#getAvailableWithoutFetching` and `ResultSet#isFullyFetched`)
602 as well as a mean to force the pre-fetching of the next page (`ResultSet#fetchMoreResults`).