Elffuss BraidHub

kikocis/java-driver public

7ffdb0fa8a5f · 30.9 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](../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 * `Statement`. The following public methods were modified:
46 * `getRoutingKey(ProtocolVersion, CodecRegistry)`: both parameters added.
47 * `RegularStatement`. The following public methods were modified:
48 * `getValues(ProtocolVersion, CodecRegistry)`: second parameter added.
49 * `getQueryString(CodecRegistry)` and `hasValues(CodecRegistry)`: parameter added. No-arg versions are still present
50 and use the default codec registry; refer to the Javadocs for guidance on which version to use.
51 * `PreparedStatement`. The following public method was added:
52 * `CodecRegistry getCodecRegistry()`.
53 * `TupleType`. The following public method was deleted:
54 * `TupleType of(DataType... types)`; users should now use `Metadata.newTupleType(DataType...)`.
55
56 <p>The driver runtime behavior changes in the following situations:</p>
57 * By default, the driver now returns _mutable_, _non thread-safe_ instances for CQL collection types;
58 This affects methods `getList`, `getSet`, `getMap`, `getObject` and `get` for all instances of
59 `GettableByIndexData` and `GettableByNameData` (`Row`, `BoundStatement`, `TupleValue` and `UDTValue`)
60 * `RuntimeException`s thrown during serialization or deserialization might not be
61 the same ones as before, due to the newly-introduced `CodecNotFoundException`
62 and to the dynamic nature of codec search introduced by JAVA-721.
63 * `TypeCodec.format(Object)` now returns the CQL keyword `"NULL"` instead of a `null` reference
64 for `null` inputs.
65
663. The driver now depends on Guava 16.0.1 (instead of 14.0.1).
67 This update has been mainly motivated by Guava's [Issue #1635](https://code.google.com/p/guava-libraries/issues/detail?id=1635),
68 which affects `TypeToken`, and hence all `TypeCodec` implementations handling parameterized types.
69
704. `UDTMapper` (the type previously used to convert `@UDT`-annotated
71 classes to their CQL counterpart) was removed, as well as the
72 corresponding method `MappingManager#udtMapper`.
73
74 The mapper now uses custom codecs to convert UDTs. See more
75 explanations [here](../features/object_mapper/custom_codecs/#implicit-udt-codecs).
76
775. All methods that took the protocol version as an `int` or assumed a
78 default version have been removed (they were already deprecated in
79 2.1):
80 * `AbstractGettableData(int)`
81 * `Cluster.Builder#withProtocolVersion(int)`
82 * in `ProtocolOptions`:
83 * `NEWEST_SUPPORTED_PROTOCOL_VERSION` (replaced by
84 `ProtocolVersion#NEWEST_SUPPORTED`)
85 * `int getProtocolVersion()`
86
87 There are now variants of these methods using the `ProtocolVersion`
88 enum. In addition, `ProtocolOptions#getProtocolVersionEnum` has been
89 renamed to `ProtocolOptions#getProtocolVersion`.
90
916. All methods related to the "suspected" host state have been removed
92 (they had been deprecated in 2.1.6 when the suspicion mechanism was
93 removed):
94 * `Host.StateListener#onSuspected()` (was inherited by
95 `LoadBalancingPolicy`)
96 * `Host#getInitialReconnectionAttemptFuture()`
97
987. `PoolingOptions#setMinSimultaneousRequestsPerConnectionThreshold(HostDistance,
99 int)` has been removed. The new connection pool resizing algorithm introduced by
100 [JAVA-419](https://datastax-oss.atlassian.net/browse/JAVA-419) does not need this
101 threshold anymore.
102
1038. `AddressTranslater` has been renamed to `AddressTranslator`. All
104 related methods and classes have also been renamed.
105
106 In addition, the `close()` method has been pulled up into
107 `AddressTranslator`, and `CloseableAddressTranslator` has been removed.
108 Existing third-party `AddressTranslator` implementations only need
109 to add an empty `close()` method.
110
1119. The `close()` method has been pulled up into `LoadBalancingPolicy`,
112 and `CloseableLoadBalancingPolicy` has been removed. Existing third-party
113 `LoadBalancingPolicy` implementations only need to add an empty
114 `close()` method.
115
11610. All pluggable components now have callbacks to detect when they get
117 associated with a `Cluster` instance:
118 * `ReconnectionPolicy`, `RetryPolicy`, `AddressTranslator`,
119 and `TimestampGenerator`:
120 * `init(Cluster)`
121 * `close()`
122 * `Host.StateListener` and `LatencyTracker`:
123 * `onRegister(Cluster)`
124 * `onUnregister(Cluster)`
125
126 This gives these components the opportunity to perform
127 initialization / cleanup tasks. Existing third-party implementations
128 only need to add empty methods.
129
13011. `LoadBalancingPolicy` does not extend `Host.StateListener` anymore:
131 callback methods (`onUp`, `onDown`, etc.) have been duplicated. This
132 is unlikely to affect clients.
133
13412. [Client-side timestamp generation](../features/query_timestamps/) is
135 now the default (provided that [native
136 protocol](../features/native_protocol) v3 or higher is in use). The
137 generator used is `AtomicMonotonicTimestampGenerator`.
138
13913. If a DNS name resolves to multiple A-records,
140 `Cluster.Builder#addContactPoint(String)` will now use all of these
141 addresses as contact points. This gives you the possibility of
142 maintaining contact points in DNS configuration, and having a single,
143 static contact point in your Java code.
144
14514. The following methods were added for [Custom payloads](../features/custom_payloads):
146 * in `PreparedStatement`: `getIncomingPayload()`,
147 `getOutgoingPayload()` and
148 `setOutgoingPayload(Map<String,ByteBuffer>)`
149 * `AbstractSession#prepareAsync(String, Map<String,ByteBuffer>)`
150
151 Also, not that `AbstractSession#prepareAsync(Statement)` does not
152 call `AbstractSession#prepareAsync(String)` anymore, they now both
153 delegate to a private method.
154
155 This breaks binary compatibility for these two classes; if you have
156 custom implementations, you will have to adapt them accordingly.
157
15815. Getters and setters have been added to "data-container" classes for
159 new CQL types:
160 * `getByte`/`setByte` for the `TINYINT` type
161 * `getShort`/`setShort` for the `SMALLINT` type
162 * `getTime`/`setTime` for the `TIME` type
163 * `getDate`/`setDate` for the `DATE` type
164
165 The methods for the `TIMESTAMP` CQL type have been renamed to
166 `getTimestamp` and `setTimestamp`.
167
168 This affects `Row`, `BoundStatement`, `TupleValue` and `UDTValue`.
169
17016. New exception types have been added to handle additional server-side
171 errors introduced in Cassandra 2.2:
172 * `ReadFailureException`
173 * `WriteFailureException`
174 * `FunctionExecutionException`
175
176 This is not a breaking change since all driver exceptions are
177 unchecked; but clients might decide to handle these errors in a specific
178 way.
179
180 In addition, `QueryTimeoutException` has been renamed to
181 `QueryExecutionException` (this is an intermediary class in our
182 exception hierarchy, it now has new child classes that are not
183 related to timeouts).
184
18517. `ResultSet#fetchMoreResults()` now returns a `ListenableFuture<ResultSet>`.
186 This makes the API more friendly if you chain transformations on an async
187 query to process all pages (see `AsyncResultSetTest` in the sources for an
188 example).
189
19018. `Frozen` annotations in the mapper are no longer checked at runtime (see
191 [JAVA-843](https://datastax-oss.atlassian.net/browse/JAVA-843) for more
192 explanations). So they become purely informational at this stage.
193 However it is a good idea to keep using these annotations and make sure
194 they match the schema, in anticipation for the schema generation features
195 that will be added in a future version.
196
19719. `AsyncInitSession` has been removed, `initAsync()` is now part of the
198 `Session` interface (the only purpose of the extra interface was to preserve
199 binary compatibility on the 2.1 branch).
200
20120. `TableMetadata.Options` has been made a top-level class and renamed to
202 `TableOptionsMetadata`. It is now also used by `MaterializedViewMetadata`.
203
20421. The mapper annotation `@Enumerated` has been removed, users should now
205 use the newly-introduced `driver-extras` module to get automatic
206 enum-to-CQL mappings. Two new codecs provide the same functionality:
207 `EnumOrdinalCodec` and `EnumNameCodec`:
208
209 ```java
210 enum Foo {...}
211 enum Bar {...}
212
213 // register the appropriate codecs
214 CodecRegistry.DEFAULT_INSTANCE
215 .register(new EnumOrdinalCodec<Foo>(Foo.class))
216 .register(new EnumNameCodec<Bar>(Bar.class))
217
218 // the following mappings are handled out-of-the-box
219 @Table
220 public class MyPojo {
221 private Foo foo;
222 private List<Bar> bars;
223 ...
224 }
225 ```
226
22722. The interface `IdempotenceAwarePreparedStatement` has been removed
228 and now the `PreparedStatement` interface exposes 2 new methods,
229 `setIdempotent(Boolean)` and `isIdempotent()`.
230
23123. `RetryPolicy` and `ExtendedRetryPolicy` (introduced in 2.1.10)
232 were merged together; as a consequence, `RetryPolicy` now has one
233 more method: `onRequestError`; see
234 [JAVA-819](https://datastax-oss.atlassian.net/browse/JAVA-819) for
235 more information. Furthermore, `FallthroughRetryPolicy` now returns
236 `RetryDecision.rethrow()` when `onRequestError` is called.
237
23824. `DseAuthProvider` has been deprecated and is now replaced by
239 `DseGSSAPIAuthProvider` for Kerberos authentication. `DsePlainTextAuthProvider`
240 has been introduced to handle plain text authentication with the
241 `DseAuthenticator`.
242
243
244### 2.1.8
245
2462.1.8 is binary-compatible with 2.1.7 but introduces a small change in the
247driver's behavior:
248
2491. The list of contact points provided at startup is now shuffled before trying
250 to open the control connection, so that multiple clients with the same contact
251 points don't all pick the same control host. As a result, you can't assume that
252 the driver will try contact points in a deterministic order. In particular, if
253 you use the `DCAwareRoundRobinPolicy` without specifying a primary datacenter
254 name, make sure that you only provide local hosts as contact points.
255
256
257### 2.1.7
258
259This version brings a few changes in the driver's behavior; none of them break
260binary compatibility.
261
2621. The `DefaultRetryPolicy`'s behaviour has changed in the case of an Unavailable
263 exception received from a request. The new behaviour will cause the driver to
264 process a Retry on a different node at most once, otherwise an exception will
265 be thrown. This change makes sense in the case where the node tried initially
266 for the request happens to be isolated from the rest of the cluster (e.g.
267 because of a network partition) but can still answer to the client normally.
268 In this case, trying another node has a chance of success.
269 The previous behaviour was to always throw an exception.
270
2712. The following properties in `PoolingOptions` were renamed:
272 * `MaxSimultaneousRequestsPerConnectionThreshold` to `NewConnectionThreshold`
273 * `MaxSimultaneousRequestsPerHostThreshold` to `MaxRequestsPerConnection`
274
275 The old getters/setters were deprecated, but they delegate to the new
276 ones.
277
278 Also, note that the connection pool for protocol v3 can now be configured to
279 use multiple connections. See [this page](../features/pooling) for more
280 information.
281
2823. `MappingManager(Session)` will now force the initialization of the `Session`
283 if needed. This is a change from 2.1.6, where if you gave it an uninitialized
284 session (created with `Cluster#newSession()` instead of `Cluster#connect()`),
285 it would only get initialized on the first request.
286
287 If this is a problem for you, `MappingManager(Session, ProtocolVersion)`
288 preserves the previous behavior (see the API docs for more details).
289
2904. A `BuiltStatement` is now considered non-idempotent whenever a `fcall()`
291 or `raw()` is used to build a value to be inserted in the database.
292 If you know that the CQL functions or expressions are safe, use
293 `setIdempotent(true)` on the statement.
294
295### 2.1.6
296
297See [2.0.10](#2-0-x-to-2-0-10).
298
299
300### 2.1.2
301
3022.1.2 brings important internal changes with native protocol v3 support, but
303the impact on the public API has been kept as low as possible.
304
305#### User API Changes
306
3071. The native protocol version is now modelled as an enum: `ProtocolVersion`.
308 Most public methods that take it as an argument have a backward-compatible
309 version that takes an `int` (the exception being `RegularStatement`,
310 described below). For new code, prefer the enum version.
311
312#### Internal API Changes
313
3141. `RegularStatement.getValues` now takes the protocol version as a
315 `ProtocolVersion` instead of an `int`. This is transparent for callers
316 since there is a backward-compatible alternative, but if you happened to
317 extend the class you'll need to update your implementation.
318
3192. `BatchStatement.setSerialConsistencyLevel` now returns `BatchStatement`
320 instead of `Statement`. Again, this only matters if you extended this
321 class (if so, it might be a good idea to also have a covariant return in
322 your child class).
323
3243. The constructor of `UnsupportedFeatureException` now takes a
325 `ProtocolVersion` as a parameter. This should impact few users, as there's
326 hardly any reason to build instances of that class from client code.
327
328#### New features
329
330These features are only active when the native protocol v3 is in use.
331
3321. The driver now uses a single connection per host (as opposed to a pool in
333 2.1.1). Most options in `PoolingOptions` are ignored, except for a new one
334 called `maxSimultaneousRequestsPerHostThreshold`. See the class's Javadocs
335 for detailed explanations.
336
3372. You can now provide a default timestamp with each query (but it will be
338 ignored if the CQL query string already contains a `USING TIMESTAMP`
339 clause). This can be done on a per-statement basis with
340 `Statement.setDefaultTimestamp`, or automatically with a
341 `TimestampGenerator` specified with
342 `Cluster.Builder.withTimestampGenerator` (two implementations are
343 provided: `ThreadLocalMonotonicTimestampGenerator` and
344 `AtomicMonotonicTimestampGenerator`). If you specify both, the statement's
345 timestamp takes precedence over the generator. By default, the driver has
346 the same behavior as 2.1.1 (no generator, timestamps are assigned by
347 Cassandra unless `USING TIMESTAMP` was specified).
348
3493. `BatchStatement.setSerialConsistencyLevel` no longer throws an exception,
350 it will honor the serial consistency level for the batch.
351
352
353### 2.1.1
354
355#### Internal API Changes
356
3571. The `ResultSet` interface has a new `wasApplied()` method. This will
358 only affect clients that provide their own implementation of this interface.
359
360
361### 2.1.0
362
363#### User API Changes
364
3651. The `getCaching` method of `TableMetadata#Options` now returns a
366 `Map` to account for changes to Cassandra 2.1. Also, the
367 `getIndexInterval` method now returns an `Integer` instead of an `int`
368 which will be `null` when connected to Cassandra 2.1 nodes.
369
3702. `BoundStatement` variables that have not been set explicitly will no
371 longer default to `null`. Instead, all variables must be bound explicitly,
372 otherwise the execution of the statement will fail (this also applies to
373 statements inside of a `BatchStatement`). For variables that map to a
374 primitive Java type, a new `setToNull` method has been added.
375 We made this change because the driver might soon distinguish between unset
376 and null variables, so we don't want clients relying on the "leave unset to
377 set to `null`" behavior.
378
379
380#### Internal API Changes
381
382The changes listed in this section should normally not impact end users of the
383driver, but rather third-party frameworks and tools.
384
3851. The `serialize` and `deserialize` methods in `DataType` now take an
386 additional parameter: the protocol version. As explained in the javadoc,
387 if unsure, the proper value to use for this parameter is the protocol version
388 in use by the driver, i.e. the value returned by
389 `cluster.getConfiguration().getProtocolOptions().getProtocolVersion()`.
390
3912. The `parse` method in `DataType` now returns a Java object, not a
392 `ByteBuffer`. The previous behavior can be obtained by calling the
393 `serialize` method on the returned object.
394
3953. The `getValues` method of `RegularStatement` now takes the protocol
396 version as a parameter. As above, the proper value if unsure is almost surely
397 the protocol version in use
398 (`cluster.getConfiguration().getProtocolOptions().getProtocolVersion()`).
399
400
401### 2.0.11
402
4032.0.11 preserves binary compatibility with previous versions. There are a few
404changes in the driver's behavior:
405
4061. The `DefaultRetryPolicy`'s behaviour has changed in the case of an Unavailable
407 exception received from a request. The new behaviour will cause the driver to
408 process a Retry on a different node at most once, otherwise an exception will
409 be thrown. This change makes sense in the case where the node tried initially
410 for the request happens to be isolated from the rest of the cluster (e.g.
411 because of a network partition) but can still answer to the client normally.
412 In this case, trying another node has a chance of success.
413 The previous behaviour was to always throw an exception.
414
4152. A `BuiltStatement` is now considered non-idempotent whenever a `fcall()`
416 or `raw()` is used to build a value to be inserted in the database.
417 If you know that the CQL functions or expressions are safe, use
418 `setIdempotent(true)` on the statement.
419
4203. The list of contact points provided at startup is now shuffled before trying
421 to open the control connection, so that multiple clients with the same contact
422 points don't all pick the same control host. As a result, you can't assume that
423 the driver will try contact points in a deterministic order. In particular, if
424 you use the `DCAwareRoundRobinPolicy` without specifying a primary datacenter
425 name, make sure that you only provide local hosts as contact points.
426
427
428### <a name="2-0-x-to-2-0-10"></a>2.0.x to 2.0.10
429
430We try to avoid breaking changes within a branch (2.0.x to 2.0.y), but
4312.0.10 saw a lot of new features and internal improvements. There is one
432breaking change:
433
4341. `LatencyTracker#update` now has a different signature and takes two new
435 parameters: the statement that has been executed (never null), and the exception
436 thrown while executing the query (or null, if the query executed successfully).
437 Existing implementations of this interface, once upgraded to the new method
438 signature, should continue to work as before.
439
440The following might also be of interest:
441
4422. `SocketOptions#getTcpNoDelay()` is now TRUE by default (it was previously undefined).
443 This reflects the new behavior of Netty (which was upgraded from version 3.9.0 to
444 4.0.27): `TCP_NODELAY` is now turned on by default, instead of depending on the OS
445 default like in previous versions.
446
4473. Netty is not shaded anymore in the default Maven artifact. However we publish a
448 [shaded artifact](../features/shaded_jar/) under a different classifier.
449
4504. The internal initialization sequence of the Cluster object has been slightly changed:
451 some fields that were previously initialized in the constructor are now set when
452 the `init()` method is called. In particular, `Cluster#getMetrics()` will return
453 `null` until the cluster is initialized.
454
455### 1.0 to 2.0
456
457We used the opportunity of a major version bump to incorporate your feedback
458and improve the API, to fix a number of inconsistencies and remove cruft.
459Unfortunately this means there are some breaking changes, but the new API should
460be both simpler and more complete.
461
462The following describes the changes for 2.0 that are breaking changes of the
4631.0 API. For ease of use, we distinguish two categories of API changes: the "main"
464ones and the "other" ones.
465
466The "main" API changes are the ones that are either
467likely to affect most upgraded apps or are incompatible changes that, even if minor,
468will not be detected at compile time. Upgraders are highly encouraged to check
469this list of "main" changes while upgrading their application to 2.0 (even
470though most applications are likely to be affected by only a handful of
471changes).
472
473The "other" list is, well, other changes: those that are likely to
474affect a minor number of applications and will be detected by compile time
475errors anyway. It is ok to skip those initially and only come back to them if
476you have trouble compiling your application after an upgrade.
477
478#### Main API changes
479
4801. The `Query` class has been renamed into `Statement` (it was confusing
481 to some that the `BoundStatement` was not a `Statement`). To allow
482 this, the old `Statement` class has been renamed to `RegularStatement`.
483
4842. The `Cluster` and `Session` shutdown API has changed. There is now a
485 `closeAsync` that is asynchronous but returns a `Future` on the
486 completion of the shutdown process. There is also a `close` shortcut
487 that does the same but blocks. Also, `close` now waits for ongoing
488 queries to complete by default (but you can force the closing of all
489 connections if you want to).
490
4913. `NoHostAvailableException#getErrors` now returns the full exception objects for
492 each node instead of just a message. In other words, it returns a
493 `Map<InetAddress, Throwable>` instead of a `Map<InetAddress, String>`.
494
4954. `Statement#getConsistencyLevel` (previously `Query#getConsistencyLevel`, see
496 first point) will now return `null` by default (instead of `CL.ONE`), with the
497 meaning of "use the default consistency level".
498 The default consistency level can now be configured through the new `QueryOptions`
499 object in the cluster `Configuration`.
500
5015. The `Metrics` class now uses the Codahale metrics library version 3 (version 2 was
502 used previously). This new major version of the library has many API changes
503 compared to its version 2 (see the [release notes](https://dropwizard.github.io/metrics/3.1.0/about/release-notes/) for details),
504 which can thus impact consumers of the Metrics class.
505 Furthermore, the default `JmxReporter` now includes a name specific to the
506 cluster instance (to avoid conflicts when multiple Cluster instances are created
507 in the same JVM). As a result, tools that were polling JMX info will
508 have to be updated accordingly.
509
5106. The `QueryBuilder#in` method now has the following special case: using
511 `QueryBuilder.in(QueryBuilder.bindMarker())` will generate the string `IN ?`,
512 not `IN (?)` as was the case in 1.0. The reasoning being that the former
513 syntax, made valid by [CASSANDRA-4210](https://issues.apache.org/jira/browse/CASSANDRA-4210)
514 is a lot more useful than `IN (?)`, as the latter can more simply use an
515 equality.
516 Note that if you really want to output `IN (?)` with the query
517 builder, you can use `QueryBuilder.in(QueryBuilder.raw("?"))`.
518
5197. When binding values by name in `BoundStatement` (i.e. using the
520 `setX(String, X)` methods), if more than one variable have the same name,
521 then all values corresponding to that variable
522 name are set instead of just the first occurrence.
523
5248. The `QueryBuilder#raw` method does not automatically add quotes anymore, but
525 rather output its result without any change (as the raw name implies).
526 This means for instance that `eq("x", raw(foo))` will output `x = foo`,
527 not `x = 'foo'` (you don't need the raw method to output the latter string).
528
5299. The `QueryBuilder` will now sometimes use the new ability to send value as
530 bytes instead of serializing everything to string. In general the QueryBuilder
531 will do the right thing, but if you were calling the `getQueryString()` method
532 on a Statement created with a QueryBuilder (for other reasons than to prepare a query)
533 then the returned string may contain bind markers in place of some of the values
534 provided (and in that case, `getValues()` will contain the values corresponding
535 to those markers). If need be, it is possible to force the old behavior by
536 using the new `setForceNoValues()` method.
537
538#### Other API Changes
539
5401. Creating a Cluster instance (through `Cluster#buildFrom` or the
541 `Cluster.Builder#build` method) **does not create any connection right away
542 anymore** (and thus cannot throw a `NoHostAvailableException` or an
543 `AuthenticationException`). Instead, the initial contact points are checked
544 the first time a call to `Cluster#connect` is done. If for some reason you
545 want to emulate the previous behavior, you can use the new method
546 `Cluster#init`: `Cluster.builder().build()` in 1.0 is equivalent to
547 `Cluster.builder().build().init()` in 2.0.
548
5492. Methods from `Metadata`, `KeyspaceMetadata` and `TableMetadata` now use by default
550 case insensitive identifiers (for keyspace, table and column names in
551 parameter). You can double-quote an identifier if you want it to be a
552 case sensitive one (as you would do in CQL) and there is a `Metadata.quote`
553 helper method for that.
554
5553. The `TableMetadata#getClusteringKey` method has been renamed
556 `TableMetadata#getClusteringColumns` to match the "official" vocabulary.
557
5584. The `UnavailableException#getConsistency` method has been renamed to
559 `UnavailableException#getConsistencyLevel` for consistency with the method of
560 `QueryTimeoutException`.
561
5625. The `RegularStatement` class (ex-`Statement` class, see above) must now
563 implement two additional methods: `RegularStatement#getKeyspace` and
564 `RegularStatement#getValues`. If you had extended this class, you will have to
565 implement those new methods, but both can return null if they are not useful
566 in your case.
567
5686. The `Cluster.Initializer` interface should now implement 2 new methods:
569 `Cluster.Initializer#getInitialListeners` (which can return an empty
570 collection) and `Cluster.Initializer#getClusterName` (which can return null).
571
5727. The `Metadata#getReplicas` method now takes 2 arguments. On top of the
573 partition key, you must now provide the keyspace too. The previous behavior
574 was buggy: it's impossible to properly return the full list of replica for a
575 partition key without knowing the keyspace since replication may depend on
576 the keyspace).
577
5788. The method `LoadBalancingPolicy#newQueryPlan()` method now takes the currently
579 logged keyspace as 2nd argument. This information is necessary to do proper
580 token aware balancing (see preceding point).
581
5829. The `ResultSetFuture#set` and `ResultSetFuture#setException` methods have been
583 removed (from the public API at least). They were never meant to be exposed
584 publicly: a `resultSetFuture` is always set by the driver itself and should
585 not be set manually.
586
58710. The deprecated since 1.0.2 `Host.HealthMonitor` class has been removed. You
588 will now need to use `Host#isUp` and `Cluster#register` if you were using that
589 class.
590
591#### Features available only with Cassandra 2.0
592
593This section details the biggest additions to 2.0 API wise. It is not an
594exhaustive list of new features in 2.0.
595
5961. The new `BatchStatement` class allows to group any type of insert Statements
597 (`BoundStatement` or `RegularStatement`) for execution as a batch. For instance,
598 you can do something like:
599
600 ```java
601 List<String> values = ...;
602 PreparedStatement ps = session.prepare("INSERT INTO myTable(value) VALUES (?)");
603 BatchStatement bs = new BatchStatement();
604 for (String value : values)
605 bs.add(ps.bind(value));
606 session.execute(bs);
607 ```
608
6092. `SimpleStatement` can now take a list of values in addition to the query. This
610 allows to do the equivalent of a prepare+execute but with only one round-trip
611 to the server and without keeping the prepared statement after the
612 execution.
613
614 This is typically useful if a given query should be executed only
615 once (i.e. you don't want to prepare it) but you also don't want to
616 serialize all values into strings. Shortcut `Session#execute()` and
617 `Session#executeAsync()` methods are also provided so you that you can do:
618
619 ```java
620 String imgName = ...;
621 ByteBuffer imgBytes = ...;
622 session.execute("INSERT INTO images(name, bytes) VALUES (?, ?)", imgName, imgBytes);
623 ```
624
6253. SELECT queries are now "paged" under the hood. In other words, if a query
626 yields a very large result, only the beginning of the `ResultSet` will be fetched
627 initially, the rest being fetched "on-demand". In practice, this means that:
628
629 ```java
630 for (Row r : session.execute("SELECT * FROM mytable"))
631 ... process r ...
632 ```
633
634 should not timeout or OOM the server anymore even if "mytable" contains a lot
635 of data. In general paging should be transparent for the application (as in
636 the example above), but the implementation provides a number of knobs to
637 fine tune the behavior of that paging:
638 * the size of each "page" can be set per-query (`Statement#setFetchSize()`)
639 * the `ResultSet` object provides 2 methods to check the state of paging
640 (`ResultSet#getAvailableWithoutFetching` and `ResultSet#isFullyFetched`)
641 as well as a mean to force the pre-fetching of the next page (`ResultSet#fetchMoreResults`).