Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting and playing with Cassandra in Java

Tags:

java

cassandra

I have read some tutorials on what Cassandra is and what it can do but my problem is how to interface with Cassandra in java? (A tutorial will be nice :-) )

If possible, can someone please show me whether I should use Thrift or Hector (which one is better and why)?

Thanks in advance.

PS Can I integrate Hibernate with Cassandra?

like image 856
Buhake Sindi Avatar asked Jul 14 '10 13:07

Buhake Sindi


People also ask

How do I connect to Cassandra with Java?

In order to connect to Cassandra from Java, we need to build a Cluster object. An address of a node needs to be provided as a contact point. If we don't provide a port number, the default port (9042) will be used. These settings allow the driver to discover the current topology of a cluster.

How do I run a query in Cassandra?

You can execute CQL queries using execute() method of Session class. Pass the query either in string format or as a Statement class object to the execute() method. Whatever you pass to this method in string format will be executed on the cqlsh.

Is Cassandra written in Java?

Cassandra is a distributed database management system which is open source with wide column store, NoSQL database to handle large amount of data across many commodity servers which provides high availability with no single point of failure. It is written in Java and developed by Apache Software Foundation.


4 Answers

Hibernate uses JDBC Drivers to connect to relational databases. Cassandra is a ColumnFamily based, which is A relational database (distributed one).

The problem is to find a proper JDBC driver for your case. Here is a project I Googled:

http://code.google.com/p/sql4d/

It's not active currently, but you got the idea of how to find the right one.

Having object-relationship mapping through Hibernate you won't have to worry about the specific dialect Cassandra use and just enjoy the ride.

Well.. that's how it sounds theoretically.

Yet another way is using Pelops library for usage of Cassandra. More info on it HERE.

Getting started with Cassandra - a rather short post on the matter.

Hope you find of your answers there!

like image 78
vlood Avatar answered Oct 23 '22 05:10

vlood


New for 0.8 is CQL (Cassandra Query Language), an SQL-alike alternative to the traditional RPC interface. Language drivers are available for:

Java (JDBC) Python (DBAPI2) Twisted

http://cassandra.apache.org/download/

http://www.datastax.com/docs/0.8/api/cql_ref

like image 22
JustusTh Avatar answered Oct 23 '22 06:10

JustusTh


Hibernate OGM looks like it might eventually be the answer.

like image 36
WizardsOfWor Avatar answered Oct 23 '22 06:10

WizardsOfWor


Some example projects using Hector: https://github.com/zznate/cassandra-tutorial https://github.com/zznate/cassandra-stress

Another example (within the actual project) but using using the CQL JDBC driver with our (shiny new) JDBC-pool: https://github.com/riptano/jdbc-conn-pool/tree/master/portfolio-example

like image 22
zznate Avatar answered Oct 23 '22 04:10

zznate