Elffuss BraidHub

kikocis/java-driver public

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