| 1 | Upgrade Guide to 2.1 |
| 2 | ==================== |
| 3 | |
| 4 | The purpose of this guide is to detail the changes made by version 2.1 of |
| 5 | the Java Driver. |
| 6 | |
| 7 | 2.1.0 |
| 8 | ----- |
| 9 | |
| 10 | User API Changes |
| 11 | ~~~~~~~~~~~~~~~~ |
| 12 | |
| 13 | 1. The ``getCaching`` method of ``TableMetadata#Options`` now returns a |
| 14 | ``Map`` to account for changes to Cassandra 2.1. Also, the |
| 15 | ``getIndexInterval`` method now returns an ``Integer`` instead of an ``int`` |
| 16 | which will be ``null`` when connected to Cassandra 2.1 nodes. |
| 17 | |
| 18 | 2. ``BoundStatement`` variables that have not been set explicitly will no |
| 19 | longer default to ``null``. Instead, all variables must be bound explicitly, |
| 20 | otherwise the execution of the statement will fail (this also applies to |
| 21 | statements inside of a ``BatchStatement``). For variables that map to a |
| 22 | primitive Java type, a new ``setToNull`` method has been added. |
| 23 | We made this change because the driver might soon distinguish between unset |
| 24 | and null variables, so we don't want clients relying on the "leave unset to |
| 25 | set to ``null``" behavior. |
| 26 | |
| 27 | |
| 28 | Internal API Changes |
| 29 | ~~~~~~~~~~~~~~~~~~~~ |
| 30 | |
| 31 | The changes listed in this section should normally not impact end users of the |
| 32 | driver, but rather third-party frameworks and tools. |
| 33 | |
| 34 | 1. The ``serialize`` and ``deserialize`` methods in ``DataType`` now take an |
| 35 | additional parameter: the protocol version. As explained in the javadoc, |
| 36 | if unsure, the proper value to use for this parameter is the protocol version |
| 37 | in use by the driver, i.e. the value returned by |
| 38 | ``cluster.getConfiguration().getProtocolOptions().getProtocolVersion()``. |
| 39 | |
| 40 | 2. The ``parse`` method in ``DataType`` now returns a Java object, not a |
| 41 | ``ByteBuffer``. The previous behavior can be obtained by calling the |
| 42 | ``serialize`` method on the returned object. |
| 43 | |
| 44 | 3. The ``getValues`` method of ``RegularStatement`` now takes the protocol |
| 45 | version as a parameter. As above, the proper value if unsure is almost surely |
| 46 | the protocol version in use |
| 47 | (``cluster.getConfiguration().getProtocolOptions().getProtocolVersion()``). |
| 48 | |
| 49 | |
| 50 | 2.1.1 |
| 51 | ----- |
| 52 | |
| 53 | Internal API Changes |
| 54 | ~~~~~~~~~~~~~~~~~~~~ |
| 55 | |
| 56 | 1. The ``ResultSet`` interface has a new ``wasApplied()`` method. This will |
| 57 | only affect clients that provide their own implementation of this interface. |
| 58 | |
| 59 | |
| 60 | 2.1.2 |
| 61 | ----- |
| 62 | |
| 63 | 2.1.2 brings important internal changes with native protocol v3 support, but |
| 64 | the impact on the public API has been kept as low as possible. |
| 65 | |
| 66 | User API Changes |
| 67 | ~~~~~~~~~~~~~~~~ |
| 68 | |
| 69 | 1. The native protocol version is now modelled as an enum: ``ProtocolVersion``. |
| 70 | Most public methods that take it as an argument have a backward-compatible |
| 71 | version that takes an ``int`` (the exception being ``RegularStatement``, |
| 72 | described below). For new code, prefer the enum version. |
| 73 | |
| 74 | Internal API Changes |
| 75 | ~~~~~~~~~~~~~~~~~~~~ |
| 76 | |
| 77 | 1. ``RegularStatement.getValues`` now takes the protocol version as a |
| 78 | ``ProtocolVersion`` instead of an ``int``. This is transparent for callers |
| 79 | since there is a backward-compatible alternative, but if you happened to |
| 80 | extend the class you'll need to update your implementation. |
| 81 | |
| 82 | 2. ``BatchStatement.setSerialConsistencyLevel`` now returns ``BatchStatement`` |
| 83 | instead of ``Statement``. Again, this only matters if you extended this |
| 84 | class (if so, it might be a good idea to also have a covariant return in |
| 85 | your child class). |
| 86 | |
| 87 | 3. The constructor of ``UnsupportedFeatureException`` now takes a |
| 88 | ``ProtocolVersion`` as a parameter. This should impact few users, as there's |
| 89 | hardly any reason to build instances of that class from client code. |
| 90 | |
| 91 | New features |
| 92 | ~~~~~~~~~~~~ |
| 93 | |
| 94 | These features are only active when the native protocol v3 is in use. |
| 95 | |
| 96 | 1. The driver now uses a single connection per host (as opposed to a pool in |
| 97 | 2.1.1). Most options in ``PoolingOptions`` are ignored, except for a new one |
| 98 | called ``maxSimultaneousRequestsPerHostThreshold``. See the class's Javadocs |
| 99 | for detailed explanations. |
| 100 | |
| 101 | 2. You can now provide a default timestamp with each query (but it will be |
| 102 | ignored if the CQL query string already contains a ``USING TIMESTAMP`` |
| 103 | clause). This can be done on a per-statement basis with |
| 104 | ``Statement.setDefaultTimestamp``, or automatically with a |
| 105 | ``TimestampGenerator`` specified with |
| 106 | ``Cluster.Builder.withTimestampGenerator`` (two implementations are |
| 107 | provided: ``ThreadLocalMonotonicTimestampGenerator`` and |
| 108 | ``AtomicMonotonicTimestampGenerator``). If you specify both, the statement's |
| 109 | timestamp takes precedence over the generator. By default, the driver has |
| 110 | the same behavior as 2.1.1 (no generator, timestamps are assigned by |
| 111 | Cassandra unless ``USING TIMESTAMP`` was specified). |
| 112 | |
| 113 | 3. ``BatchStatement.setSerialConsistencyLevel`` no longer throws an exception, |
| 114 | it will honor the serial consistency level for the batch. |