| 1 | Driver Core |
| 2 | =========== |
| 3 | |
| 4 | This is the core module of the DataStax Java Driver for Apache Cassandra (C*), |
| 5 | which offers a simple (as in, not abstracted) but complete API to work with |
| 6 | CQL3. The main goal of the module is to handle all the functionality related |
| 7 | to managing connections to a Cassandra cluster (but leaving higher level |
| 8 | abstraction like object mapping to separate modules). |
| 9 | |
| 10 | |
| 11 | Features |
| 12 | -------- |
| 13 | |
| 14 | The features provided by the core module includes: |
| 15 | - Asynchronous: the driver uses the new CQL binary protocol asynchronous |
| 16 | capabilities. Only a relatively low number of connections per nodes needs to |
| 17 | be maintained open to achieve good performance. |
| 18 | - Nodes discovery: the driver automatically discovers and uses all nodes of the |
| 19 | C* cluster, including newly bootstrapped ones. |
| 20 | - Configurable load balancing: the driver allows for custom routing and load |
| 21 | balancing of queries to C* nodes. Out of the box, round robin is provided |
| 22 | with optional data-center awareness (only nodes from the local data-center |
| 23 | are queried (and have connections maintained to)) and optional token |
| 24 | awareness (that is, the ability to prefer a replica for the query as coordinator). |
| 25 | - Transparent fail-over: if C* nodes fail or become unreachable, the driver |
| 26 | automatically and transparently tries other nodes and schedules |
| 27 | reconnection to the dead nodes in the background. |
| 28 | - C* trace handling: tracing can be set on a per-query basis and the driver |
| 29 | provides a convenient API to retrieve the trace. |
| 30 | - Convenient schema access: the driver exposes a C* schema in a usable way. |
| 31 | - Configurable retry policy: a retry policy can be set to define a precise |
| 32 | behavior to adopt on query execution exceptions (for example, timeouts, |
| 33 | unavailability). This avoids polluting client code with retry-related code. |
| 34 | |
| 35 | |
| 36 | Prerequisite |
| 37 | ------------ |
| 38 | |
| 39 | The driver uses Casandra's native protocol which is available starting from |
| 40 | Cassandra 1.2. Some of the features (result set paging, BatchStatement, ...) of |
| 41 | this version 2.0 of the driver require Cassandra 2.0 however and will throw |
| 42 | 'unsupported feature' exceptions if used against a Cassandra 1.2 cluster. |
| 43 | |
| 44 | If you are having issues connecting to the cluster (seeing ``NoHostAvailableConnection`` |
| 45 | exceptions) please check the `connection requirements <https://github.com/datastax/java-driver/wiki/Connection-requirements>`_. |
| 46 | |
| 47 | If you want to run the unit tests provided with this driver, you will also need |
| 48 | to have ccm installed (http://github.com/pcmanus/ccm) as the tests use it. Also |
| 49 | note that the first time you run the tests, ccm will download/compile the |
| 50 | source of C* under the hood, which may require some time (that depends on your |
| 51 | Internet connection or machine). |
| 52 | |
| 53 | |
| 54 | Installing |
| 55 | ---------- |
| 56 | |
| 57 | The last release of the driver is available on Maven Central. You can install |
| 58 | it in your application using the following Maven dependency:: |
| 59 | |
| 60 | <dependency> |
| 61 | <groupId>com.datastax.cassandra</groupId> |
| 62 | <artifactId>cassandra-driver-core</artifactId> |
| 63 | <version>2.0.9.2</version> |
| 64 | </dependency> |
| 65 | |
| 66 | |
| 67 | Upgrading from 1.x branch |
| 68 | ------------------------- |
| 69 | |
| 70 | If you are upgrading from the 1.x branch of the driver, be sure to have a look at |
| 71 | the `upgrade guide <https://github.com/datastax/java-driver/blob/2.0/driver-core/Upgrade_guide_to_2.0.rst>`_. |
| 72 | |
| 73 | We used the opportunity of a major version bump to incorporate your feedback and improve the API, |
| 74 | to fix a number of inconsistencies and remove cruft. |
| 75 | Unfortunately this means there are some breaking changes, but the new API should be both simpler and more complete. |
| 76 | |
| 77 | |
| 78 | Getting Started |
| 79 | --------------- |
| 80 | |
| 81 | Suppose you have a Cassandra cluster running on 3 nodes whose hostnames are: |
| 82 | cass1, cass2 and cass3. A simple example using this core driver could be:: |
| 83 | |
| 84 | Cluster cluster = Cluster.builder() |
| 85 | .addContactPoints("cass1", "cass2") |
| 86 | .build(); |
| 87 | Session session = cluster.connect("db1"); |
| 88 | |
| 89 | for (Row row : session.execute("SELECT * FROM table1")) |
| 90 | // do something ... |
| 91 | |
| 92 | Please note that when we build the Cluster object, we only provide the address |
| 93 | to 2 Cassandra hosts. We could have provided only one host or the 3 of them, |
| 94 | this doesn't matter as long as the driver is able to contact one of the host |
| 95 | provided as "contact points". Even if only one host was provided, the driver |
| 96 | would use this host to discover the other ones and use the whole cluster |
| 97 | automatically. This is also true for new nodes joining the cluster. |
| 98 | |
| 99 | For now, please refer to the API reference (http://www.datastax.com/drivers/java/apidocs/). |
| 100 | More informations and documentation will come later. |