com.mymed.model.core.wrappers.cassandra.api07
Class CassandraWrapper

java.lang.Object
  extended by com.mymed.model.core.wrappers.cassandra.api07.CassandraWrapper
All Implemented Interfaces:
ICassandraWrapper

public class CassandraWrapper
extends java.lang.Object
implements ICassandraWrapper

Wrapper for the Cassandra API v0.7.
For more info about the API, check the API web page.

Author:
Milo Casagrande

Constructor Summary
CassandraWrapper()
          Empty constructor to create a normal Cassandra client, with address the machine address, and port the default port
CassandraWrapper(java.lang.String address, int port)
          Create the Cassandra client
 
Method Summary
 void batch_mutate(java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.util.List<org.apache.cassandra.thrift.Mutation>>> mutationMap, org.apache.cassandra.thrift.ConsistencyLevel level)
          Execute the specified mutations on the keyspace
A Mutation specifies either columns to insert or columns to delete
 void batchMutate(java.util.Map<java.nio.ByteBuffer,java.util.Map<java.lang.String,java.util.List<org.apache.cassandra.thrift.Mutation>>> mutationMap, org.apache.cassandra.thrift.ConsistencyLevel level)
           
 java.lang.String describe_cluster_name()
           
 org.apache.cassandra.thrift.KsDef describe_keyspace(java.lang.String keySpace)
           
 java.util.List<org.apache.cassandra.thrift.KsDef> describe_keyspaces()
           
 java.lang.String describe_partitioner()
           
 java.util.List<org.apache.cassandra.thrift.TokenRange> describe_ring(java.lang.String keySpace)
          Get the token ring; a map of ranges to host addresses.
 java.lang.String describe_snitch()
           
 java.lang.String describe_version()
           
 int get_cf_id(java.lang.String keySpaceName, java.lang.String columnFamilyName)
          Retrieve the specified column family id in the given keyspace
 int get_count(java.lang.String key, org.apache.cassandra.thrift.ColumnParent parent, org.apache.cassandra.thrift.SlicePredicate predicate, org.apache.cassandra.thrift.ConsistencyLevel level)
          Counts the column present in the column parent within the predicate
The method is not O(1).
 java.util.List<org.apache.cassandra.thrift.KeySlice> get_indexed_slices(org.apache.cassandra.thrift.ColumnParent parent, org.apache.cassandra.thrift.IndexClause clause, org.apache.cassandra.thrift.SlicePredicate predicate, org.apache.cassandra.thrift.ConsistencyLevel level)
          Return a list of slices, but uses IndexClause instead of KeyRange.
 java.util.List<org.apache.cassandra.thrift.KeySlice> get_range_slices(org.apache.cassandra.thrift.ColumnParent parent, org.apache.cassandra.thrift.SlicePredicate predicate, org.apache.cassandra.thrift.KeyRange range, org.apache.cassandra.thrift.ConsistencyLevel level)
          Return a list of slices for the keys within the specified KeyRange
Note that when using RandomPartitioner, keys are stored in the order of their MD5 hash, making it impossible to get a meaningful range of keys between two endpoints.
 java.util.List<org.apache.cassandra.thrift.ColumnOrSuperColumn> get_slice(java.lang.String key, org.apache.cassandra.thrift.ColumnParent parent, org.apache.cassandra.thrift.SlicePredicate predicate, org.apache.cassandra.thrift.ConsistencyLevel level)
          Get the group of columns contained by the column parent specified by the given predicate
 org.apache.cassandra.thrift.ColumnOrSuperColumn get(java.lang.String key, org.apache.cassandra.thrift.ColumnPath path, org.apache.cassandra.thrift.ConsistencyLevel level)
          Get the Column or SuperColumn at the given column path
 void insert(java.lang.String key, org.apache.cassandra.thrift.ColumnParent parent, org.apache.cassandra.thrift.Column column, org.apache.cassandra.thrift.ConsistencyLevel level)
          Insert a Column consisting of (name, value, timestamp) at the given ColumnPath.column_family and optional ColumnPath.super_column.
 void login(org.apache.cassandra.thrift.AuthenticationRequest authRequest)
          Authenticates with the cluster for operations on the specified keyspace using the specified AuthenticationRequest credentials
 java.util.Map<java.nio.ByteBuffer,java.lang.Integer> multiget_count(java.util.List<java.lang.String> keys, org.apache.cassandra.thrift.ColumnParent parent, org.apache.cassandra.thrift.SlicePredicate predicate, org.apache.cassandra.thrift.ConsistencyLevel level)
          A combination of multiget_slice and get_count
 java.util.Map<java.nio.ByteBuffer,java.util.List<org.apache.cassandra.thrift.ColumnOrSuperColumn>> multiget_slice(java.util.List<java.lang.String> keys, org.apache.cassandra.thrift.ColumnParent parent, org.apache.cassandra.thrift.SlicePredicate predicate, org.apache.cassandra.thrift.ConsistencyLevel level)
          Retrieve slices for column parent and predicate on each of the given keys in parallel
 void remove(java.lang.String key, org.apache.cassandra.thrift.ColumnPath path, long timeStamp, org.apache.cassandra.thrift.ConsistencyLevel level)
          Remove data from the row specified by key at the granularity specified by the ColumnPath path, and the given timestamp.
 void set_keyspace(java.lang.String keySpace)
          Set the keyspace to work on
 java.lang.String system_add_column_family(org.apache.cassandra.thrift.CfDef cfDef)
          Adds a column family.
 java.lang.String system_add_keyspace(org.apache.cassandra.thrift.KsDef ksDef)
          Creates a new keyspace and any column families defined with it.
 java.lang.String system_drop_column_family(java.lang.String columnFamily)
          Drops a column family.
 java.lang.String system_drop_keyspace(java.lang.String keySpace)
          Drops a keyspace.
 java.lang.String system_update_column_family(org.apache.cassandra.thrift.CfDef columnFamily)
          Update the properties of a column family
 java.lang.String system_update_keyspace(org.apache.cassandra.thrift.KsDef keySpace)
          Update the properties of a keyspace
 void truncate(java.lang.String columnFamily)
          Remove all the rows from the given column family
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CassandraWrapper

public CassandraWrapper()
                 throws java.net.UnknownHostException,
                        InternalBackEndException
Empty constructor to create a normal Cassandra client, with address the machine address, and port the default port

Throws:
java.net.UnknownHostException
InternalBackEndException

CassandraWrapper

public CassandraWrapper(java.lang.String address,
                        int port)
                 throws InternalBackEndException
Create the Cassandra client

Parameters:
address - the address to use for the connection
port - the port to use for the connection
Throws:
InternalBackEndException
Method Detail

login

public void login(org.apache.cassandra.thrift.AuthenticationRequest authRequest)
           throws InternalBackEndException
Description copied from interface: ICassandraWrapper
Authenticates with the cluster for operations on the specified keyspace using the specified AuthenticationRequest credentials

Specified by:
login in interface ICassandraWrapper
Throws:
InternalBackEndException

set_keyspace

public void set_keyspace(java.lang.String keySpace)
                  throws InternalBackEndException
Description copied from interface: ICassandraWrapper
Set the keyspace to work on

Specified by:
set_keyspace in interface ICassandraWrapper
Parameters:
keySpace - the name of the keyspace
Throws:
InternalBackEndException

get

public org.apache.cassandra.thrift.ColumnOrSuperColumn get(java.lang.String key,
                                                           org.apache.cassandra.thrift.ColumnPath path,
                                                           org.apache.cassandra.thrift.ConsistencyLevel level)
                                                    throws IOBackEndException,
                                                           InternalBackEndException
Description copied from interface: ICassandraWrapper
Get the Column or SuperColumn at the given column path

Specified by:
get in interface ICassandraWrapper
level - the ConsistencyLevel to use
Returns:
the Column or SuperColumn at the given column path
Throws:
InternalBackEndException
IOBackEndException

get_slice

public java.util.List<org.apache.cassandra.thrift.ColumnOrSuperColumn> get_slice(java.lang.String key,
                                                                                 org.apache.cassandra.thrift.ColumnParent parent,
                                                                                 org.apache.cassandra.thrift.SlicePredicate predicate,
                                                                                 org.apache.cassandra.thrift.ConsistencyLevel level)
                                                                          throws InternalBackEndException
Description copied from interface: ICassandraWrapper
Get the group of columns contained by the column parent specified by the given predicate

Specified by:
get_slice in interface ICassandraWrapper
parent - either a ColumnFamily or a ColumnFamily/ SuperColum pair
predicate - the SlicePredicate
level - the ConsistencyLevel to use
Returns:
the group of columns contained by the column parent
Throws:
InternalBackEndException

multiget_slice

public java.util.Map<java.nio.ByteBuffer,java.util.List<org.apache.cassandra.thrift.ColumnOrSuperColumn>> multiget_slice(java.util.List<java.lang.String> keys,
                                                                                                                         org.apache.cassandra.thrift.ColumnParent parent,
                                                                                                                         org.apache.cassandra.thrift.SlicePredicate predicate,
                                                                                                                         org.apache.cassandra.thrift.ConsistencyLevel level)
                                                                                                                  throws InternalBackEndException
Description copied from interface: ICassandraWrapper
Retrieve slices for column parent and predicate on each of the given keys in parallel

Specified by:
multiget_slice in interface ICassandraWrapper
Parameters:
keys - the list of keys
predicate - the SlicePredicate
level - the ConsistencyLevel to use
Returns:
the slices for the given keys
Throws:
InternalBackEndException

get_count

public int get_count(java.lang.String key,
                     org.apache.cassandra.thrift.ColumnParent parent,
                     org.apache.cassandra.thrift.SlicePredicate predicate,
                     org.apache.cassandra.thrift.ConsistencyLevel level)
              throws InternalBackEndException
Description copied from interface: ICassandraWrapper
Counts the column present in the column parent within the predicate
The method is not O(1). It takes all the columns from disk to calculate the answer. The only benefit of the method is that you do not need to pull all the columns over Thrift interface to count them.

Specified by:
get_count in interface ICassandraWrapper
predicate - the SlicePredicate
level - the ConsistencyLevel to use
Returns:
the number of columns
Throws:
InternalBackEndException

multiget_count

public java.util.Map<java.nio.ByteBuffer,java.lang.Integer> multiget_count(java.util.List<java.lang.String> keys,
                                                                           org.apache.cassandra.thrift.ColumnParent parent,
                                                                           org.apache.cassandra.thrift.SlicePredicate predicate,
                                                                           org.apache.cassandra.thrift.ConsistencyLevel level)
                                                                    throws InternalBackEndException
Description copied from interface: ICassandraWrapper
A combination of multiget_slice and get_count

Specified by:
multiget_count in interface ICassandraWrapper
predicate - the SlicePredicate
level - the ConsistencyLevel to use
Returns:
Throws:
InternalBackEndException

get_range_slices

public java.util.List<org.apache.cassandra.thrift.KeySlice> get_range_slices(org.apache.cassandra.thrift.ColumnParent parent,
                                                                             org.apache.cassandra.thrift.SlicePredicate predicate,
                                                                             org.apache.cassandra.thrift.KeyRange range,
                                                                             org.apache.cassandra.thrift.ConsistencyLevel level)
                                                                      throws InternalBackEndException
Description copied from interface: ICassandraWrapper
Return a list of slices for the keys within the specified KeyRange
Note that when using RandomPartitioner, keys are stored in the order of their MD5 hash, making it impossible to get a meaningful range of keys between two endpoints.

Specified by:
get_range_slices in interface ICassandraWrapper
predicate - the SlicePredicate
range - the KeyRange
level - the ConsistencyLevel to use
Returns:
a list of slices
Throws:
InternalBackEndException

get_indexed_slices

public java.util.List<org.apache.cassandra.thrift.KeySlice> get_indexed_slices(org.apache.cassandra.thrift.ColumnParent parent,
                                                                               org.apache.cassandra.thrift.IndexClause clause,
                                                                               org.apache.cassandra.thrift.SlicePredicate predicate,
                                                                               org.apache.cassandra.thrift.ConsistencyLevel level)
                                                                        throws InternalBackEndException
Description copied from interface: ICassandraWrapper
Return a list of slices, but uses IndexClause instead of KeyRange. To use this method, the underlying ColumnFamily of the ColumnParent must have been configured with a column_metadata attribute, specifying at least the name and index_type attributes. See CfDef and ColumnDef for the list of attributes.

Specified by:
get_indexed_slices in interface ICassandraWrapper
clause - the IndexClause to use
predicate - the SlicePredicate
level - the ConsistencyLevel to use
Returns:
a list of slices
Throws:
InternalBackEndException

insert

public void insert(java.lang.String key,
                   org.apache.cassandra.thrift.ColumnParent parent,
                   org.apache.cassandra.thrift.Column column,
                   org.apache.cassandra.thrift.ConsistencyLevel level)
            throws InternalBackEndException
Description copied from interface: ICassandraWrapper
Insert a Column consisting of (name, value, timestamp) at the given ColumnPath.column_family and optional ColumnPath.super_column. Note that a SuperColumn cannot directly contain binary values, it can only contain sub-Columns. Only one sub-Column may be inserted at a time, as well.

Specified by:
insert in interface ICassandraWrapper
Throws:
InternalBackEndException

batch_mutate

public void batch_mutate(java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.util.List<org.apache.cassandra.thrift.Mutation>>> mutationMap,
                         org.apache.cassandra.thrift.ConsistencyLevel level)
                  throws InternalBackEndException
Description copied from interface: ICassandraWrapper
Execute the specified mutations on the keyspace
A Mutation specifies either columns to insert or columns to delete

Specified by:
batch_mutate in interface ICassandraWrapper
Throws:
InternalBackEndException

batchMutate

public void batchMutate(java.util.Map<java.nio.ByteBuffer,java.util.Map<java.lang.String,java.util.List<org.apache.cassandra.thrift.Mutation>>> mutationMap,
                        org.apache.cassandra.thrift.ConsistencyLevel level)
                 throws InternalBackEndException
Throws:
InternalBackEndException

remove

public void remove(java.lang.String key,
                   org.apache.cassandra.thrift.ColumnPath path,
                   long timeStamp,
                   org.apache.cassandra.thrift.ConsistencyLevel level)
            throws InternalBackEndException
Description copied from interface: ICassandraWrapper
Remove data from the row specified by key at the granularity specified by the ColumnPath path, and the given timestamp.

Specified by:
remove in interface ICassandraWrapper
level - the ConsistencyLevel to use
Throws:
InternalBackEndException

truncate

public void truncate(java.lang.String columnFamily)
              throws InternalBackEndException
Description copied from interface: ICassandraWrapper
Remove all the rows from the given column family

Specified by:
truncate in interface ICassandraWrapper
Throws:
InternalBackEndException

describe_cluster_name

public java.lang.String describe_cluster_name()
                                       throws InternalBackEndException
Specified by:
describe_cluster_name in interface ICassandraWrapper
Returns:
the name of the cluster
Throws:
InternalBackEndException

describe_keyspace

public org.apache.cassandra.thrift.KsDef describe_keyspace(java.lang.String keySpace)
                                                    throws InternalBackEndException,
                                                           IOBackEndException
Specified by:
describe_keyspace in interface ICassandraWrapper
Returns:
the information about the specified keyspace
Throws:
InternalBackEndException
IOBackEndException

describe_keyspaces

public java.util.List<org.apache.cassandra.thrift.KsDef> describe_keyspaces()
                                                                     throws InternalBackEndException
Specified by:
describe_keyspaces in interface ICassandraWrapper
Returns:
a list of all the keyspaces configured for the cluster
Throws:
InternalBackEndException

describe_partitioner

public java.lang.String describe_partitioner()
                                      throws InternalBackEndException
Specified by:
describe_partitioner in interface ICassandraWrapper
Returns:
the name of the partitioner for the cluster
Throws:
InternalBackEndException

describe_ring

public java.util.List<org.apache.cassandra.thrift.TokenRange> describe_ring(java.lang.String keySpace)
                                                                     throws InternalBackEndException
Description copied from interface: ICassandraWrapper
Get the token ring; a map of ranges to host addresses. Represented as a set of TokenRange instead of a map from range to list of end points

Specified by:
describe_ring in interface ICassandraWrapper
Returns:
Throws:
InternalBackEndException

describe_snitch

public java.lang.String describe_snitch()
                                 throws InternalBackEndException
Specified by:
describe_snitch in interface ICassandraWrapper
Returns:
the name of the snitch used for the cluster
Throws:
InternalBackEndException

describe_version

public java.lang.String describe_version()
                                  throws InternalBackEndException
Specified by:
describe_version in interface ICassandraWrapper
Returns:
the Thrift API version
Throws:
InternalBackEndException

system_add_column_family

public java.lang.String system_add_column_family(org.apache.cassandra.thrift.CfDef cfDef)
                                          throws InternalBackEndException
Description copied from interface: ICassandraWrapper
Adds a column family. This method will throw an exception if a column family with the same name is already associated with the keyspace

Specified by:
system_add_column_family in interface ICassandraWrapper
Returns:
the new schema version ID
Throws:
InternalBackEndException

system_drop_column_family

public java.lang.String system_drop_column_family(java.lang.String columnFamily)
                                           throws InternalBackEndException
Description copied from interface: ICassandraWrapper
Drops a column family. Creates a snapshot and then submits a 'graveyard' compaction during which the abandoned files will be deleted

Specified by:
system_drop_column_family in interface ICassandraWrapper
Returns:
the new schema version ID
Throws:
InternalBackEndException

system_add_keyspace

public java.lang.String system_add_keyspace(org.apache.cassandra.thrift.KsDef ksDef)
                                     throws InternalBackEndException
Description copied from interface: ICassandraWrapper
Creates a new keyspace and any column families defined with it. Callers are not required to first create an empty keyspace and then create column families for it.

Specified by:
system_add_keyspace in interface ICassandraWrapper
Parameters:
ksDef - the keyspace definition
Returns:
the new schema version ID
Throws:
InternalBackEndException

system_drop_keyspace

public java.lang.String system_drop_keyspace(java.lang.String keySpace)
                                      throws InternalBackEndException
Description copied from interface: ICassandraWrapper
Drops a keyspace. Creates a snapshot and then submits a 'graveyard' compaction during which the abandoned files will be deleted

Specified by:
system_drop_keyspace in interface ICassandraWrapper
Returns:
the new schema version ID
Throws:
InternalBackEndException

system_update_column_family

public java.lang.String system_update_column_family(org.apache.cassandra.thrift.CfDef columnFamily)
                                             throws InternalBackEndException
Description copied from interface: ICassandraWrapper
Update the properties of a column family

Specified by:
system_update_column_family in interface ICassandraWrapper
Returns:
the new schema version ID
Throws:
InternalBackEndException

system_update_keyspace

public java.lang.String system_update_keyspace(org.apache.cassandra.thrift.KsDef keySpace)
                                        throws InternalBackEndException
Description copied from interface: ICassandraWrapper
Update the properties of a keyspace

Specified by:
system_update_keyspace in interface ICassandraWrapper
Returns:
the new schema version ID
Throws:
InternalBackEndException

get_cf_id

public int get_cf_id(java.lang.String keySpaceName,
                     java.lang.String columnFamilyName)
              throws InternalBackEndException,
                     IOBackEndException
Retrieve the specified column family id in the given keyspace

Parameters:
keySpaceName - the keyspace where the column family is located
columnFamilyName - the column family to search
Returns:
the id of the column family
Throws:
InternalBackEndException
IOBackEndException