| 1 | # Datastax Java Driver for Apache Cassandra |
| 2 | |
| 3 | [](https://travis-ci.org/datastax/java-driver) |
| 4 | |
| 5 | *If you're reading this on github.com, please note that this is the readme |
| 6 | for the development version and that some features described here might |
| 7 | not yet have been released. You can find the documentation for latest |
| 8 | version through [Java driver |
| 9 | docs](http://datastax.github.io/java-driver/) or via the release tags, |
| 10 | [e.g. |
| 11 | 2.1.9](https://github.com/datastax/java-driver/tree/2.1.9).* |
| 12 | |
| 13 | A modern, [feature-rich](manual/) and highly tunable Java client |
| 14 | library for Apache Cassandra (1.2+) and DataStax Enterprise (3.1+) using |
| 15 | exclusively Cassandra's binary protocol and Cassandra Query Language v3. |
| 16 | |
| 17 | **Features:** |
| 18 | |
| 19 | * [Sync](manual/) and [Async](manual/async/) API |
| 20 | * [Simple](manual/statements/simple/), [Prepared](manual/statements/prepared/), and [Batch](manual/statements/batch/) |
| 21 | statements |
| 22 | * Asynchronous IO, parallel execution, request pipelining |
| 23 | * [Connection pooling](manual/pooling/) |
| 24 | * Auto node discovery |
| 25 | * Automatic reconnection |
| 26 | * Configurable [load balancing](manual/load_balancing/) and [retry policies](manual/retries/) |
| 27 | * Works with any cluster size |
| 28 | * [Query builder](manual/statements/built/) |
| 29 | * [Object mapper](manual/object_mapper/) |
| 30 | |
| 31 | |
| 32 | [sync]: http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/Session.html#execute-com.datastax.driver.core.Statement- |
| 33 | [async]: http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/Session.html#executeAsync-com.datastax.driver.core.Statement- |
| 34 | [simple_st]: http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/SimpleStatement.html |
| 35 | [prepared_st]: http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/Session.html#prepare-com.datastax.driver.core.RegularStatement- |
| 36 | [batch_st]: http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/BatchStatement.html |
| 37 | [pool]: manual/pooling/ |
| 38 | [lbp]: http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/policies/LoadBalancingPolicy.html |
| 39 | [retry_policy]: http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/policies/RetryPolicy.html |
| 40 | [query_builder]: http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/core/querybuilder/QueryBuilder.html |
| 41 | [mapper]: http://docs.datastax.com/en/drivers/java/2.1/com/datastax/driver/mapping/MappingManager.html |
| 42 | |
| 43 | The driver architecture is based on layers. At the bottom lies the driver core. |
| 44 | This core handles everything related to the connections to a Cassandra |
| 45 | cluster (for example, connection pool, discovering new nodes, etc.) and exposes a simple, |
| 46 | relatively low-level API on top of which higher level layers can be built. |
| 47 | |
| 48 | The driver contains the following modules: |
| 49 | |
| 50 | - driver-core: the core layer. |
| 51 | - driver-mapping: the object mapper. |
| 52 | - driver-examples: example applications using the other modules which are |
| 53 | only meant for demonstration purposes. |
| 54 | |
| 55 | **Community:** |
| 56 | |
| 57 | - JIRA: https://datastax-oss.atlassian.net/browse/JAVA |
| 58 | - MAILING LIST: https://groups.google.com/a/lists.datastax.com/forum/#!forum/java-driver-user |
| 59 | - IRC: #datastax-drivers on [irc.freenode.net](http://freenode.net) |
| 60 | - TWITTER: [@dsJavaDriver](https://twitter.com/dsJavaDriver) tweets Java |
| 61 | driver releases and important announcements (low frequency). |
| 62 | [@DataStaxEng](https://twitter.com/datastaxeng) has more news including |
| 63 | other drivers, Cassandra, and DSE. |
| 64 | - DOCS: the [user guide](http://docs.datastax.com/en/developer/java-driver/2.1/java-driver/whatsNew2.html) |
| 65 | has introductory material. We are progressively migrating the doc |
| 66 | [here](manual/) with more technical details. |
| 67 | - API: http://www.datastax.com/drivers/java/2.1 |
| 68 | |
| 69 | **Feeback requested:** help us focus our efforts, provide your input on the [Platform and Runtime Survey](http://goo.gl/forms/qwUE6qnL7U) (we kept it short). |
| 70 | |
| 71 | |
| 72 | ## Getting the driver |
| 73 | |
| 74 | The latest release of the driver is available on Maven Central. You can install |
| 75 | it in your application using the following Maven dependency: |
| 76 | |
| 77 | ```xml |
| 78 | <dependency> |
| 79 | <groupId>com.datastax.cassandra</groupId> |
| 80 | <artifactId>cassandra-driver-core</artifactId> |
| 81 | <version>2.1.9</version> |
| 82 | </dependency> |
| 83 | ``` |
| 84 | |
| 85 | Note that the object mapper is published as a separate artifact: |
| 86 | |
| 87 | ```xml |
| 88 | <dependency> |
| 89 | <groupId>com.datastax.cassandra</groupId> |
| 90 | <artifactId>cassandra-driver-mapping</artifactId> |
| 91 | <version>2.1.9</version> |
| 92 | </dependency> |
| 93 | ``` |
| 94 | |
| 95 | We also provide a [shaded JAR](manual/shaded_jar/) |
| 96 | to avoid the explicit dependency to Netty. |
| 97 | |
| 98 | If you can't use a dependency management tool, a |
| 99 | [binary tarball](http://downloads.datastax.com/java-driver/cassandra-java-driver-2.1.9.tar.gz) |
| 100 | is available for download. |
| 101 | |
| 102 | ## Compatibility |
| 103 | |
| 104 | The Java client driver 2.1 ([branch 2.1](https://github.com/datastax/java-driver/tree/2.1)) is compatible with Apache |
| 105 | Cassandra 1.2, 2.0, 2.1 and 2.2 (see [this page](http://datastax.github.io/java-driver/manual/native_protocol) for |
| 106 | the most up-to-date compatibility information). |
| 107 | |
| 108 | UDT and tuple support is available only when using Apache Cassandra 2.1 or higher (see [CQL improvements in Cassandra 2.1](http://www.datastax.com/dev/blog/cql-in-2-1)). |
| 109 | |
| 110 | Other features are available only when using Apache Cassandra 2.0 or higher (e.g. result set paging, |
| 111 | [BatchStatement](https://github.com/datastax/java-driver/blob/2.1/driver-core/src/main/java/com/datastax/driver/core/BatchStatement.java), |
| 112 | [lightweight transactions](http://www.datastax.com/documentation/cql/3.1/cql/cql_using/use_ltweight_transaction_t.html) |
| 113 | -- see [What's new in Cassandra 2.0](http://www.datastax.com/documentation/cassandra/2.0/cassandra/features/features_key_c.html)). |
| 114 | Trying to use these with a cluster running Cassandra 1.2 will result in |
| 115 | an [UnsupportedFeatureException](https://github.com/datastax/java-driver/blob/2.1/driver-core/src/main/java/com/datastax/driver/core/exceptions/UnsupportedFeatureException.java) being thrown. |
| 116 | |
| 117 | |
| 118 | ## Upgrading from previous versions |
| 119 | |
| 120 | If you are upgrading from a previous version of the driver, be sure to have a look at |
| 121 | the [upgrade guide](/upgrade_guide/). |
| 122 | |
| 123 | |
| 124 | ### Troubleshooting |
| 125 | |
| 126 | If you are having issues connecting to the cluster (seeing `NoHostAvailableConnection` exceptions) please check the |
| 127 | [connection requirements](https://github.com/datastax/java-driver/wiki/Connection-requirements). |
| 128 | |
| 129 | |
| 130 | ## License |
| 131 | Copyright 2012-2015, DataStax |
| 132 | |
| 133 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 134 | you may not use this file except in compliance with the License. |
| 135 | You may obtain a copy of the License at |
| 136 | |
| 137 | http://www.apache.org/licenses/LICENSE-2.0 |
| 138 | |
| 139 | Unless required by applicable law or agreed to in writing, software |
| 140 | distributed under the License is distributed on an "AS IS" BASIS, |
| 141 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 142 | See the License for the specific language governing permissions and |
| 143 | limitations under the License. |