Database Reference
In-Depth Information
Chapter8.Clients
We're used to connecting to relational databases using drivers. For example, in Java, JDBC is
an API that abstracts the vendor implementation of the relational database to present a consist-
ent way of storing and retrieving data using Statements, PreparedStatements, ResultSets, and so
forth. To interact with the database you get a driver that works with the particular database you're
using, such as Oracle, SQL Server, or MySQL; the implementation details of this interaction are
hidden from the developer. Given the right driver, you can use a wide variety of programming
languages to connect to a wide variety of databases.
Cassandra is somewhat different in that there are no drivers for it. If you've decided to use
Python to interact with Cassandra, you don't go out and find a Cassandra driver for Python; there
is no such thing. Instead of just abstracting the database interactions from the developer's point
of view, the way JDBC does, an entirely different mechanism is used. This is a client generation
layer, provided by the Thrift API and the Avro project. But there are also high-level Cassandra
clients for Java, Scala, Ruby, C#, Python, Perl, PHP, C++, and other languages, written as con-
veniences by third-party developers.
There are benefits to these clients, in that you can easily embed them in your own applications
(which we'll see how to do) and that they frequently offer more features than the basic Thrift
interface does, including connection pooling and JMX integration and monitoring.
In the following sections, we see how Thrift and Avro work and how they're used with Cas-
sandra. Then, we move on to examine more robust client projects that independent developers
have written in various languages to offer different options for working with the database.
NOTE
If you're going to write a Cassandra application, use one of these clients instead of writing all of that
plumbing code yourself. The only difficulty is in choosing a client that will continue to stay in lockstep
with updates to Cassandra itself.
Basic Client API
In Cassandra version 0.6 and earlier, Thrift served as the foundation for the entire client API.
With version 0.7, Avro started being supported due to certain limitations of the Thrift interface
and the fact that Thrift development is no longer particularly active. For example, there are a
number of bugs in Thrift that have remained open for over a year, and the Cassandra committers
Search WWH ::




Custom Search