Elffuss BraidHub

kikocis/java-driver public

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