cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dop Sun" <>
Subject RE: Cassandra Java Client
Date Mon, 19 Apr 2010 14:58:43 GMT
Well, there are couple of points while Jassandra is created:

1. First of all, I want to create something like that is because I come from
JDBC background, and familiar with Hibernate API. The ICriteria (which is
created for querying) is inspired by the Criteria API from hibernate.

Actually, maybe because of this background, it cost me a lot efforts try to
understand Cassandra in the beginning and Thrift API also takes time to use.

2. The Jassandra creates a layer, which removes the direct link to
underlying Thrift API (including the exceptions, ConsistencyLevel
enumeration etc)

High light this point because I believe the client of the Jassandra will
benefit for the implementation changes in future, for example, if the
Cassandra provides better Thrift API to selecting the columns for a list of
keys, SCFs, or deprecating some structures, exceptions, the client may not
be changed. Of cause, if Jassandra failed to approve itself, this is
actually not the advantage. :)

3. The Jassandra is designed to be an JDBC like API, no less, no more. It
strives to use the best API to do the quering (with token, key, SCF/ CF),
doing the CRUD, but no more than that. For example, it does not cover any
API like object mapping. But it should cover all the API functionalities
Thrift provided.

These 3 points, are different from Hector (I should be honest that I have
not tried to use it before, the feeling of difference are coming from the
sample code Hector provided).

So, the API Jassandra abstracted was something like this:

    IConnection connection = DriverManager.getConnection(
        "thrift://localhost:9160", info);
    try {
      // 2. Get a KeySpace by name
      IKeySpace keySpace = connection.getKeySpace("Keyspace1");

      // 3. Get a ColumnFamily by name
      IColumnFamily cf = keySpace.getColumnFamily("Standard2");

      // 4. Insert like this
      long now = System.currentTimeMillis();
      ByteArray nameFirst = ByteArray.ofASCII("first");
      ByteArray nameLast = ByteArray.ofASCII("last");
      ByteArray nameAge = ByteArray.ofASCII("age");
      ByteArray valueLast = ByteArray.ofUTF8("Smith");
      IColumn colFirst = new Column(nameFirst, ByteArray.ofUTF8("John"),
      cf.insert(userName, colFirst);

      IColumn colLast = new Column(nameLast, valueLast, now);
      cf.insert(userName, colLast);

      IColumn colAge = new Column(nameAge, ByteArray.ofLong(42), now);
      cf.insert(userName, colAge);

      // 5. Select like this
      ICriteria criteria = cf.createCriteria();
          .columnRange(nameAge, nameLast, 10);
      Map<String, List<IColumn>> map =;
      List<IColumn> list = map.get(userName);
      Assert.assertEquals(3, list.size());
      Assert.assertEquals(valueLast, list.get(2).getValue());

      // 6. Delete like this
      cf.delete(userName, colFirst);
      map =;
      Assert.assertEquals(2, map.get(userName).size());

      // 7. Get count like this
      criteria = cf.createCriteria();
      int count = criteria.count();
      Assert.assertEquals(2, count);
    } finally {
      // 8. Don't forget to close the connection.

-----Original Message-----
From: Jonathan Ellis [] 
Sent: Monday, April 19, 2010 10:35 PM
Subject: Re: Cassandra Java Client

How is Jassandra different from ?

On Mon, Apr 19, 2010 at 9:21 AM, Dop Sun <> wrote:
> May I take this chance to share this link here:
> It currently based with Cassandra 0.6 Thrift APIs.
> The class ThriftCriteria and ThriftColumnFamily has direct use of Thrift
> API. Also, the site itself has test code, which is actually works on
> Jassandra abstraction.
> Dop
> From: Nirmala Agadgar []
> Sent: Friday, April 16, 2010 5:56 PM
> To:
> Subject: Cassandra Java Client
> Hi,
> Can anyone tell how to implement Client that can insert data into
> in Java. Any Code or guidelines would be helpful.
> -
> Nirmala

View raw message