pranab / agiato

A simple no frill Cassandra java API

Home Page:http://pkghosh.wordpress.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Agiato is a simple no frill Cassandra NOSQL database API. My goal has been to make sure that
it does not take someone more than hour to learn the API and start using it.


It DOES the following
---------------------
- Supports Cassandra version .7x
- Simple wrapper around thrift API
- API does not support different data types. Basically deals with ByteBuffer
- An Util class is provided for conversion between ByteBuffer and basic data types, which the client app may use
- API only understands ByteBuffer
- The whole API is defined in one class
- There is database connection pooling using appache commons pool library
- There is a simple round robin load balancer, out of the box.
- User defined load balancer can be plugged in
- There is JSON file that defines cluster, connection configuration, key space definitions, indexes and named queries
- The API loads the JSON on start up and creates the key space and column families if necessary
- The client app needs to make sure cassandra.json file is placed in the class path


The API DOES NO DO the following
--------------------------------
- Object mapping
- Data type support


It WILL DO the following in future
----------------------------------
- Support named query and index defined in JSON 

Setup
-----
Here is a sample cassandra.json file. You should change the content to meet your need. Agiato expects this file in the class
path.

{
    "cluster" :
	{
		"hosts" :
		[
			{
				"name" : "localhost",
				"port" : 9160
			}
		],
		"loadBalancerClass" : "agiato.cassandra.connect.RoundRobinLoadBalancer",
		"poolConfig" : 
		{
			"maxActive" : 8,
			"maxIdle" : 8
		}
	},
	"keySpace" :
	{
		"name" : "PatientMonitor",
		"replicaPlacementStrategy" : "org.apache.cassandra.locator.SimpleStrategy",
		"replicationFactor" : 1,
		"endPointSnitch" : "org.apache.cassandra.locator.EndPointSnitch",
		"columnFamilies" : 
		[
			{
				"name" : "MonitorData",
				"columnType" : "Standard",
				"compareWith" : "UTF8Type",
				"keysCached" : 1000,
				"rowsCached" : 10
			},
			{
				"name" : "Patient",
				"columnType" : "Standard",
				"compareWith" : "UTF8Type",
				"keysCached" : 100,
				"rowsCached" : 10
			}

		],
		"indexes" :
	 	[
			{
				"name" : "monitorDataByPatientID",
				"colFamily" : "MonitorData",
				"type" : "1.1.1.2",
				"indexedColumnName" : "patientID",
				"indexedDataType" : 1,
				"storedDataType" : 2,
				"indexKeysCached" : 10,
				"indexRowsCached" : 5
			}
		]

	}
}


Example client code
-------------------
//when your app starts
DataManager.initialize(false);

//insert a super column into MonitorData column family
DataAccess dataAccess = new DataAccess();
List<SuperColumnValue> superColValues = new ArrayList<SuperColumnValue>();

long rowKey = ...
long superColName = ...
List<ColumnValue> colValues = new ArrayList<ColumnValue>();
ColumnValue colVal = new ColumnValue();
colVal.write("ecg", getEcg());
colValues.add(colVal);

colVal = new ColumnValue();
colVal.write("diaBp", getDiaBp());
colValues.add(colVal);

colVal = new ColumnValue();
colVal.write("sysBp", getSysBp());
colValues.add(colVal);

colVal = new ColumnValue();
colVal.write("temp", getTemp());
colValues.add(colVal);

colVal = new ColumnValue();
colVal.write("pulse", getPulse());
colValues.add(colVal);

SuperColumnValue superColVal = new SuperColumnValue();
superColVal.setNameFromLong(superColName);
superColVal.setValues(colValues);
superColValues.add(superColVal);

dataAccess.insertSuperColumns("MonitorData", rowKey, superColValues, ConsistencyLevel.ALL);

Note
----
Index and named query is not fully tested. It's work in progress. I will provide an update when
it's functional

Reference
---------
For background material on this please visit my following blogs  
http://pkghosh.wordpress.com/2011/03/02/cassandra-secondary-index-patterns/
http://pkghosh.wordpress.com/2010/12/11/easy-cassandra-data-access/






About

A simple no frill Cassandra java API

http://pkghosh.wordpress.com/


Languages

Language:Java 100.0%