My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Featured
Downloads
Wiki pages
Links

Jassandra is a Java Cassandra client.

2.2.0 released, with support to Cassandra 1.0.8, and passed all existing test cases. Check it out!

There are three downloads from this project:

中文(简体)

It's designed to be simple and intuitive, esp. for the developers coming from JDBC background.

Latest Updates

  • 2012.03.10: 2.2.0 released: support 1.0.8.
  • 2011.06.06: 2.1.0 released: with support for empty key range, binary keys and other bug fixes.
  • 2011.03.05: 2.0.0 released: with support for Cassandra 0.7.0, and passed all existing test cases.
  • 2011.01.28: 2.0.0 RC 1 released: with support for Cassandra 0.7.0, and passed all existing test cases.
  • 2010.08.31: 2.0.0 beta 1 released: with support for Cassandra 0.7.0 beta 1.
  • 2010.08.08: 1.3.1 released: performance improvements ( Issue 35 ) and tested against Cassandra 0.6.4.
  • 2010.07.11: 1.3.0 released: please check Migration Guide for guideline to migrate to new version.

Quick Links

Documentation

  • ConnectionUri gives how to specify the connection uri for failover and load balance.
  • Java Doc: click here

Future Plan

  1. Keep update to date with latest version of Cassandra.
  2. API improvements: make the library more simple and intuitive.
  3. Support more interface (currently, only Thrift is build-in)

Links

  1. Cassandra: this is where all start with
  2. Hector: include extensive jmx counters, failover and connection pooling.

Sample Code

Here is a quick sample:

  public void testSample() throws JassandraException {
    final String userName = "jsmith";

    // 1. Gets a connection
    Properties info = new Properties();
    info.put(DriverManager.CONSISTENCY_LEVEL,
        ConsistencyLevel.ONE.toString());

    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"),
          now);
      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();
      criteria.keyList(Lists.newArrayList(userName))
          .columnRange(nameAge, nameLast, 10);
      Map<String, List<IColumn>> map = criteria.select();
      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 = criteria.select();
      Assert.assertEquals(2, map.get(userName).size());

      // 7. Get count like this
      criteria = cf.createCriteria();
      criteria.keyList(Lists.newArrayList(userName));
      int count = criteria.count();
      Assert.assertEquals(2, count);
    } finally {
      // 8. Don't forget to close the connection.
      connection.close();
    }
  }
Powered by Google Project Hosting