public class

CassandraDBConnector

extends Object
java.lang.Object
   ↳ com.mulesoft.mule.cassandradb.CassandraDBConnector
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Connector allows the user to interact with any Cassandra DB. The Apache Cassandra database is the right choice when you need scalability and high availability without compromising performance. Cassandra's ColumnFamily data model offers the convenience of column indexes with the performance of log-structured updates, strong support for materialized views, and powerful built-in caching.

Summary

Fields
private Cassandra.Client client Cassandra Client
private ConsistencyLevel consistencyLevel Consistency Level.
private String host Host name or IP address
private String keyspace Cassandra keyspace
protected static final Log logger
private int port Port (default is 9160)
private TTransport tr Generic class that encapsulates the I/O layer.
Public Constructors
CassandraDBConnector()
Public Methods
void add(String rowKey, String columnParent, String counterName, int counterValue)
Increments a CounterColumn consisting of (name, value) at the given ColumnParent.
void batchMutable(Map content)
Executes the specified mutations on the keyspace.
void connect(String username, String password)
Method invoked when a connection is required
String connectionId()
Connection Identifier
String describeClusterName()
Gets the name of the cluster.
Object describeKeyspace(String keyspace)
Gets information about the specified keyspace.
List describeKeyspaces()
Gets a list of all the keyspaces configured for the cluster.
String describePartitioner()
Gets the name of the partitioner for the cluster.
List describeRing(String keyspace)
Gets the token ring; a map of ranges to host addresses.
Map describeSchemaVersions()
For each schema version present in the cluster, returns a list of nodes at that version.
String describeSnitch()
Gets the name of the snitch used for the cluster.
String describeVersion()
Gets the Thrift API version.
void disconnect()
Disconnect
Object executeCqlQuery(String query, Compression compression)
Executes a CQL (Cassandra Query Language) statement and returns a CqlResult containing the results.
Object get(String rowKey, String columnPath, List<ColumnSerializer> columnSerializers)
Get Column or SuperColumn by the path

ConsistencyLevel getConsistencyLevel()
int getCount(String rowKey, String columnParent, String start, String finish, boolean reversed, int count)
Counts the columns present in column_parent within the predicate.
String getHost()
Object getIndexedSlices(String columnParent, String start, String finish, boolean reversed, int count, int clauseCount, String clauseStartKey, List<IndexExpresion> expressionList)
Like get_range_slices, returns a list of slices, but uses IndexClause instead of KeyRange.
String getKeyspace()
int getPort()
Object getRangeSlices(String columnParent, String start, String finish, boolean reversed, int count, String startKey, String endKey, String startToken, String endToken, int keyRangeCount)
Replaces get_range_slice.
Object getRow(String rowKey, ColumnPath columnPath, List<ColumnSerializer> columnSerializers)
Get Column or SuperColumn by the path

Object getSlice(String rowKey, String columnParent, String start, String finish, boolean reversed, int count, List<ColumnSerializer> columnSerializers)
Get the group of columns contained by column_parent (either a ColumnFamily name or a ColumnFamily/SuperColumn name pair) specified by the given SlicePredicate (start, finish, reversed and count) parameters.
void insert(String rowKey, String columnParent, String columnName, String columnValue, int ttl)
Insert a Column consisting of (name, value, timestamp, ttl) at the given ColumnParent.
Map insertFromMap(Map content)
Insert object into the database

boolean isConnected()
Are we connected
Object multiGetCount(List<String> rowKeys, String columnParent, String start, String finish, boolean reversed, int count)
A combination of multiget_slice and get_count.
Object multiGetSlice(List<String> rowKeys, String columnParent, String start, String finish, boolean reversed, int count, List<ColumnSerializer> columnSerializers)
Retrieves slices for column_parent and predicate on each of the given keys in parallel.
void remove(String rowKey, String columnPath)
Remove data from the row specified by key at the granularity specified by column_path, and the given timestamp.
void removeCounter(String rowKey, String columnPath)
Remove a counter from the row specified by key at the granularity specified by column_path.
void setClient(Cassandra.Client client)
void setConsistencyLevel(ConsistencyLevel consistencyLevel)
void setHost(String host)
void setKeyspace(String keyspace)
void setPort(int port)
void setQueryKeyspace(String value)
Set the keyspace to use for subsequent requests.
String systemAddColumnFamilyFromObject(CfDef cfDefinition)
Adds a column family.
String systemAddColumnFamilyFromObjectWithSimpleNames(CfDef cfDefinition, List<String> columnNames)
Adds a column family.
String systemAddColumnFamilyWithParams(String columnFamilyName, String comparatorType, String keyValidationClass, String defaultValidationClass, List<ColumnDef> columnMetadata, String keyspace)
Adds a column family to the current keyspace.
String systemAddKeyspaceFromObject(KsDef keyspaceDefinition)
Creates a new keyspace and any column families defined with it.
Object systemAddKeyspaceWithParams(String keyspaceName, List<String> columnNames, ReplicationStrategy strategyClass, Map<String, String> strategyOptions)
Creates a new keyspace with the provided name with all the defaults values

String systemDropColumnFamily(String columnFamily)
Drops a column family.
Object systemDropKeyspace(String keyspace)
Drops a keyspace.
String systemUpdateColumnFamily(CfDef columnFamily)
Updates properties of a ColumnFamily.
String systemUpdateKeyspace(KsDef keyspaceDef)
Updates properties of a keyspace.
void truncate(String columnFamily)
Removes all the rows from the given column family.
[Expand]
Inherited Methods
From class java.lang.Object

Fields

private Cassandra.Client client

Cassandra Client

private ConsistencyLevel consistencyLevel

Consistency Level. Can be one of ANY, ONE (default), TWO, THREE, QUORUM, LOCAL_QUORUM, EACH_QUORUM, ALL. See http://wiki.apache.org/cassandra/API for more details.

private String host

Host name or IP address

private String keyspace

Cassandra keyspace

protected static final Log logger

private int port

Port (default is 9160)

private TTransport tr

Generic class that encapsulates the I/O layer. This is basically a thin wrapper around the combined functionality of Java input/output streams.

Public Constructors

public CassandraDBConnector ()

Public Methods

public void add (String rowKey, String columnParent, String counterName, int counterValue)

Increments a CounterColumn consisting of (name, value) at the given ColumnParent. Note that a SuperColumn cannot directly contain binary values -- it can only contain sub-Columns.

Parameters
rowKey Key of the row
columnParent Column Parent of the CounterColum
counterName Name of the column
counterValue Value of the counter
Throws
UnsupportedEncodingException Exception
InvalidRequestException Invalid request could mean keyspace or column family does not exist, required parameters are missing, or a parameter is malformed.
UnavailableException Not all the replicas required could be created and/or read.
TimedOutException Exception
TException Generic exception class for Thrift.

public void batchMutable (Map content)

Executes the specified mutations on the keyspace. content is a Map<string, Map<string, List<Mutation>>>; the outer map maps the key to the inner map, which maps the column family to the Mutation; can be read as: Map<key : string, Map<column_family : string, List<Mutation>>>. To be more specific, the outer map key is a row key, the inner map key is the column family name. A Mutation specifies either columns to insert or columns to delete. See Mutation and Deletion above for more details.

Parameters
content A Map<ByteBuffer, Map<String, List<Mutation>>>
Throws
Exception Exception

public void connect (String username, String password)

Method invoked when a connection is required

Parameters
username A username. NOTE: Please use a dummy username if you have disabled authentication
password A password. NOTE: Leave empty if not required. If specified, the connector will try to login with this credentials
Throws
ConnectionException

public String connectionId ()

Connection Identifier

public String describeClusterName ()

Gets the name of the cluster.

Returns
  • the cluster name
Throws
TException Generic exception class for Thrift.

public Object describeKeyspace (String keyspace)

Gets information about the specified keyspace.

Parameters
keyspace Name of the keyspace
Returns
  • A KsDef instance
Throws
NotFoundException Exception
InvalidRequestException Invalid request could mean keyspace or column family does not exist, required parameters are missing, or a parameter is malformed.
TException Generic exception class for Thrift.

public List describeKeyspaces ()

Gets a list of all the keyspaces configured for the cluster. (Equivalent to calling describe_keyspace(k) for k in keyspaces.)

Returns
  • A list of KsDef
Throws
InvalidRequestException Invalid request could mean keyspace or column family does not exist, required parameters are missing, or a parameter is malformed.
TException Generic exception class for Thrift.

public String describePartitioner ()

Gets the name of the partitioner for the cluster.

Returns
  • Partitioner name
Throws
TException Generic exception class for Thrift.

public List describeRing (String keyspace)

Gets 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 endpoints, because you can't use Thrift structs as map keys: https://issues.apache.org/jira/browse/THRIFT-162 for the same reason, we can't return a set here, even though order is neither important nor predictable.

Parameters
keyspace Keyspace name
Returns
  • A list of TokenRange
Throws
InvalidRequestException Invalid request could mean keyspace or column family does not exist, required parameters are missing, or a parameter is malformed.
TException Generic exception class for Thrift.

public Map describeSchemaVersions ()

For each schema version present in the cluster, returns a list of nodes at that version. Hosts that do not respond will be under the key DatabaseDescriptor.INITIAL_VERSION. The cluster is all on the same version if the size of the map is 1.

Returns
  • A map of type Map>
Throws
InvalidRequestException Invalid request could mean keyspace or column family does not exist, required parameters are missing, or a parameter is malformed.
TException Generic exception class for Thrift.

public String describeSnitch ()

Gets the name of the snitch used for the cluster.

Returns
  • String with the name of the snitch
Throws
TException Generic exception class for Thrift.

public String describeVersion ()

Gets the Thrift API version.

Returns
  • API Version string representation
Throws
TException Generic exception class for Thrift.

public void disconnect ()

Disconnect

public Object executeCqlQuery (String query, Compression compression)

Executes a CQL (Cassandra Query Language) statement and returns a CqlResult containing the results. For more information about CQL please visit: http://cassandra.apache.org/doc/cql/CQL.html

Parameters
query CQL Statement to be executed
compression Compression level, by default we use NONE
Returns
  • CqlResult containing the results of the execution
Throws
UnsupportedEncodingException Exception
InvalidRequestException Invalid request could mean keyspace or column family does not exist, required parameters are missing, or a parameter is malformed.
UnavailableException Not all the replicas required could be created and/or read.
TimedOutException Exception
SchemaDisagreementException Schemas are not in agreement across all nodes
TException Generic exception class for Thrift.

public Object get (String rowKey, String columnPath, List<ColumnSerializer> columnSerializers)

Get Column or SuperColumn by the path

Parameters
rowKey The row key
columnPath Path to the column - must be in the form of ColumnFamily:SuperColumn:Column. If you don't need a SuperColumn
columnSerializers Serializers for each column
Returns
  • the result as a JSON node
Throws
UnsupportedEncodingException Exception
InvalidRequestException Invalid request could mean keyspace or column family does not exist, required parameters are missing, or a parameter is malformed.
UnavailableException Not all the replicas required could be created and/or read.
TimedOutException Exception
TException Generic exception class for Thrift.
NotFoundException A specific column was requested that does not exist.

public ConsistencyLevel getConsistencyLevel ()

public int getCount (String rowKey, String columnParent, String start, String finish, boolean reversed, int count)

Counts the columns present in column_parent within the predicate.

Parameters
rowKey The row key
columnParent Path to the column - must be a name of the ColumnFamily or ColumnFamily:SuperColumn pair
start The column name to start the slice with. This attribute is not required, though there is no default value, and can be safely set to '', i.e., an empty byte array, to start with the first column name. Otherwise, it must a valid value under the rules of the Comparator defined for the given ColumnFamily.
finish The column name to stop the slice at. This attribute is not required, though there is no default value, and can be safely set to an empty byte array to not stop until 'count' results are seen. Otherwise, it must also be a valid value to the ColumnFamily Comparator.
reversed Whether the results should be ordered in reversed order. Similar to ORDER BY blah DESC in SQL.
count How many columns to return. Similar to LIMIT in SQL. May be arbitrarily large, but Thrift will materialize the whole result into memory before returning it to the client, so be aware that you may be better served by iterating through slices by passing the last value of one call in as the 'start' of the next instead of increasing 'count' arbitrarily large.
Returns
  • Count of register that met the conditions
Throws
UnsupportedEncodingException Exception
InvalidRequestException Invalid request could mean keyspace or column family does not exist, required parameters are missing, or a parameter is malformed.
UnavailableException Not all the replicas required could be created and/or read.
TimedOutException Exception
TException Generic exception class for Thrift.

public String getHost ()

public Object getIndexedSlices (String columnParent, String start, String finish, boolean reversed, int count, int clauseCount, String clauseStartKey, List<IndexExpresion> expressionList)

Like get_range_slices, returns 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 above for the list of attributes. Note: the IndexClause must contain one IndexExpression with an EQ operator on a configured index column. Other IndexExpression structs may be added to the IndexClause for non-indexed columns to further refine the results of the EQ expression.

Parameters
columnParent Path to the column - must be a name of the ColumnFamily or ColumnFamily:SuperColumn pair
start The column name to start the slice with. This attribute is not required, though there is no default value, and can be safely set to '', i.e., an empty byte array, to start with the first column name. Otherwise, it must a valid value under the rules of the Comparator defined for the given ColumnFamily.
finish The column name to stop the slice at. This attribute is not required, though there is no default value, and can be safely set to an empty byte array to not stop until 'count' results are seen. Otherwise, it must also be a valid value to the ColumnFamily Comparator.
reversed Whether the results should be ordered in reversed order. Similar to ORDER BY blah DESC in SQL.
count How many columns to return. Similar to LIMIT in SQL. May be arbitrarily large, but Thrift will materialize the whole result into memory before returning it to the client, so be aware that you may be better served by iterating through slices by passing the last value of one call in as the 'start' of the next instead of increasing 'count' arbitrarily large.
clauseCount The number of results to which the index query will be constrained
clauseStartKey Start the index query at the specified key - can be set to '', i.e., an empty byte array, to start with the first key
expressionList The list of IndexExpression objects which must contain one EQ IndexOperator among the expressions
Returns
  • List of objects KeySlice
Throws
UnsupportedEncodingException Exception
InvalidRequestException Invalid request could mean keyspace or column family does not exist, required parameters are missing, or a parameter is malformed.
UnavailableException Not all the replicas required could be created and/or read.
TimedOutException Exception
TException Generic exception class for Thrift.

public String getKeyspace ()

public int getPort ()

public Object getRangeSlices (String columnParent, String start, String finish, boolean reversed, int count, String startKey, String endKey, String startToken, String endToken, int keyRangeCount)

Replaces get_range_slice. Returns a list of slices for the keys within the specified KeyRange. Unlike get_key_range, this applies the given predicate to all keys in the range, not just those with undeleted matching data. 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.

Parameters
columnParent Path to the column - must be a name of the ColumnFamily or ColumnFamily:SuperColumn pair
start The column name to start the slice with. This attribute is not required, though there is no default value, and can be safely set to '', i.e., an empty byte array, to start with the first column name. Otherwise, it must a valid value under the rules of the Comparator defined for the given ColumnFamily.
finish The column name to stop the slice at. This attribute is not required, though there is no default value, and can be safely set to an empty byte array to not stop until 'count' results are seen. Otherwise, it must also be a valid value to the ColumnFamily Comparator.
reversed Whether the results should be ordered in reversed order. Similar to ORDER BY blah DESC in SQL.
count How many columns to return. Similar to LIMIT in SQL. May be arbitrarily large, but Thrift will materialize the whole result into memory before returning it to the client, so be aware that you may be better served by iterating through slices by passing the last value of one call in as the 'start' of the next instead of increasing 'count' arbitrarily large.
startKey The first key in the inclusive KeyRange.
endKey The last key in the inclusive KeyRange.
startToken The first token in the exclusive KeyRange.
endToken The last token in the exclusive KeyRange.
keyRangeCount The total number of keys to permit in the KeyRange.
Returns
  • List of objects KeySlice
Throws
UnsupportedEncodingException Exception
InvalidRequestException Invalid request could mean keyspace or column family does not exist, required parameters are missing, or a parameter is malformed.
UnavailableException Not all the replicas required could be created and/or read.
TimedOutException Exception
TException Generic exception class for Thrift.

public Object getRow (String rowKey, ColumnPath columnPath, List<ColumnSerializer> columnSerializers)

Get Column or SuperColumn by the path

Parameters
rowKey The row key
columnPath Path to the column
columnSerializers Serializers for each column
Returns
  • the result as a JSON node
Throws
UnsupportedEncodingException Exception
InvalidRequestException Invalid request could mean keyspace or column family does not exist, required parameters are missing, or a parameter is malformed.
UnavailableException Not all the replicas required could be created and/or read.
TimedOutException Exception
TException Generic exception class for Thrift.
NotFoundException A specific column was requested that does not exist.

public Object getSlice (String rowKey, String columnParent, String start, String finish, boolean reversed, int count, List<ColumnSerializer> columnSerializers)

Get the group of columns contained by column_parent (either a ColumnFamily name or a ColumnFamily/SuperColumn name pair) specified by the given SlicePredicate (start, finish, reversed and count) parameters.

Parameters
rowKey The row key
columnParent Path to the column - must be a name of the ColumnFamily or ColumnFamily:SuperColumn pair
start The column name to start the slice with. This attribute is not required, though there is no default value, and can be safely set to '', i.e., an empty byte array, to start with the first column name. Otherwise, it must a valid value under the rules of the Comparator defined for the given ColumnFamily.
finish The column name to stop the slice at. This attribute is not required, though there is no default value, and can be safely set to an empty byte array to not stop until 'count' results are seen. Otherwise, it must also be a valid value to the ColumnFamily Comparator.
reversed Whether the results should be ordered in reversed order. Similar to ORDER BY blah DESC in SQL.
count How many columns to return. Similar to LIMIT in SQL. May be arbitrarily large, but Thrift will materialize the whole result into memory before returning it to the client, so be aware that you may be better served by iterating through slices by passing the last value of one call in as the 'start' of the next instead of increasing 'count' arbitrarily large.
columnSerializers Serializers for each column
Returns
  • the result as a JSON node
Throws
UnsupportedEncodingException Exception
InvalidRequestException Invalid request could mean keyspace or column family does not exist, required parameters are missing, or a parameter is malformed.
UnavailableException Not all the replicas required could be created and/or read.
TimedOutException Exception
TException Generic exception class for Thrift.

public void insert (String rowKey, String columnParent, String columnName, String columnValue, int ttl)

Insert a Column consisting of (name, value, timestamp, ttl) at the given ColumnParent. 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. Any number of columns may be inserted at the same time. When inserting or updating columns in a column family, the client application specifies the row key to identify which column records to update. The row key is similar to a primary key in that it must be unique for each row within a column family. However, unlike a primary key, inserting a duplicate row key will not result in a primary key constraint violation - it will be treated as an UPSERT (update the specified columns in that row if they exist or insert them if they do not). For more details check: http://www.datastax.com/docs/0.8/dml/about_writes

Parameters
rowKey The row key
columnParent The ColumnParent
columnName The name of the column
columnValue The value of the column
ttl An optional, positive delay (in seconds) after which the Column will be automatically deleted.
Throws
UnsupportedEncodingException Exception
TException Generic exception class for Thrift.
TimedOutException Exception
UnavailableException Not all the replicas required could be created and/or read.
InvalidRequestException Invalid request could mean keyspace or column family does not exist, required parameters are missing, or a parameter is malformed.

public Map insertFromMap (Map content)

Insert object into the database

Parameters
content Content to be inserted into the database. Must be an instance of Map in the following format:

{ "ToyStores" : { - Column Family "Ohio Store" : { - RowKey "Transformer" : { - SuperColumn "Price" : "29.99", - Column "Section" : "Action Figures" } "GumDrop" : { "Price" : "0.25", "Section" : "Candy" } "MatchboxCar" : { "Price" : "1.49", "Section" : "Vehicles" } } "New York Store" : { "JawBreaker" : { "Price" : "4.25", "Section" : "Candy" } "MatchboxCar" : { "Price" : "8.79", "Section" : "Vehicles" } } } } * @param password A password

Returns
  • Same content
Throws
UnsupportedEncodingException Exception
TException Generic exception class for Thrift.
TimedOutException Time out of the request
UnavailableException Not all the replicas required could be created and/or read.
InvalidRequestException Invalid request could mean keyspace or column family does not exist, required parameters are missing, or a parameter is malformed.Why contains an associated error message.

public boolean isConnected ()

Are we connected

public Object multiGetCount (List<String> rowKeys, String columnParent, String start, String finish, boolean reversed, int count)

A combination of multiget_slice and get_count.

Parameters
rowKeys A list of keys used for
columnParent Path to the column - must be a name of the ColumnFamily or ColumnFamily:SuperColumn pair
start The column name to start the slice with. This attribute is not required, though there is no default value, and can be safely set to '', i.e., an empty byte array, to start with the first column name. Otherwise, it must a valid value under the rules of the Comparator defined for the given ColumnFamily.
finish The column name to stop the slice at. This attribute is not required, though there is no default value, and can be safely set to an empty byte array to not stop until 'count' results are seen. Otherwise, it must also be a valid value to the ColumnFamily Comparator.
reversed Whether the results should be ordered in reversed order. Similar to ORDER BY blah DESC in SQL.
count How many columns to return. Similar to LIMIT in SQL. May be arbitrarily large, but Thrift will materialize the whole result into memory before returning it to the client, so be aware that you may be better served by iterating through slices by passing the last value of one call in as the 'start' of the next instead of increasing 'count' arbitrarily large.
Returns
  • A map of keys and integers
Throws
UnsupportedEncodingException Exception
InvalidRequestException Invalid request could mean keyspace or column family does not exist, required parameters are missing, or a parameter is malformed.
UnavailableException Not all the replicas required could be created and/or read.
TimedOutException Exception
TException Generic exception class for Thrift.

public Object multiGetSlice (List<String> rowKeys, String columnParent, String start, String finish, boolean reversed, int count, List<ColumnSerializer> columnSerializers)

Retrieves slices for column_parent and predicate on each of the given keys in parallel. Keys are a list of the keys to get slices for. This is similar to getRangeSlices, except it operates on a set of non-contiguous keys instead of a range of keys.

Parameters
rowKeys A list of keys used for
columnParent Path to the column - must be a name of the ColumnFamily or ColumnFamily:SuperColumn pair
start The column name to start the slice with. This attribute is not required, though there is no default value, and can be safely set to '', i.e., an empty byte array, to start with the first column name. Otherwise, it must a valid value under the rules of the Comparator defined for the given ColumnFamily.
finish The column name to stop the slice at. This attribute is not required, though there is no default value, and can be safely set to an empty byte array to not stop until 'count' results are seen. Otherwise, it must also be a valid value to the ColumnFamily Comparator.
reversed Whether the results should be ordered in reversed order. Similar to ORDER BY blah DESC in SQL.
count How many columns to return. Similar to LIMIT in SQL. May be arbitrarily large, but Thrift will materialize the whole result into memory before returning it to the client, so be aware that you may be better served by iterating through slices by passing the last value of one call in as the 'start' of the next instead of increasing 'count' arbitrarily large.
columnSerializers Serializers for each column
Returns
  • A map of keys and ColumnOrSuperColumn
Throws
UnsupportedEncodingException Exception
InvalidRequestException Invalid request could mean keyspace or column family does not exist, required parameters are missing, or a parameter is malformed.
UnavailableException Not all the replicas required could be created and/or read.
TimedOutException Exception
TException Generic exception class for Thrift.

public void remove (String rowKey, String columnPath)

Remove data from the row specified by key at the granularity specified by column_path, and the given timestamp. Note that all the values in column_path besides column_path.column_family are truly optional: you can remove the entire row by just specifying the ColumnFamily, or you can remove a SuperColumn or a single Column by specifying those levels too. Note that the timestamp is needed, so that if the commands are replayed in a different order on different nodes, the same result is produced.

Parameters
rowKey The row key
columnPath Path to the column - must be in the form of ColumnFamily:SuperColumn:Column
Throws
Exception IOException

public void removeCounter (String rowKey, String columnPath)

Remove a counter from the row specified by key at the granularity specified by column_path. Note that all the values in column_path besides column_path.column_family are truly optional: you can remove the entire row by just specifying the ColumnFamily, or you can remove a SuperColumn or a single Column by specifying those levels too. Note that counters have limited support for deletes: if you remove a counter, you must wait to issue any following update until the delete has reached all the nodes and all of them have been fully compacted.

Parameters
rowKey Key of the row
columnPath Column that will be affected by the remove counter
Throws
UnsupportedEncodingException Exception
InvalidRequestException Invalid request could mean keyspace or column family does not exist, required parameters are missing, or a parameter is malformed.
UnavailableException Not all the replicas required could be created and/or read.
TimedOutException Exception
TException Generic exception class for Thrift.

public void setClient (Cassandra.Client client)

Parameters
client

public void setConsistencyLevel (ConsistencyLevel consistencyLevel)

Parameters
consistencyLevel

public void setHost (String host)

Parameters
host

public void setKeyspace (String keyspace)

Parameters
keyspace

public void setPort (int port)

Parameters
port

public void setQueryKeyspace (String value)

Set the keyspace to use for subsequent requests.

Parameters
value New value that will be used to all following requests
Throws
InvalidRequestException Invalid request could mean keyspace or column family does not exist, required parameters are missing, or a parameter is malformed.
TException Generic exception class for Thrift.

public String systemAddColumnFamilyFromObject (CfDef cfDefinition)

Adds a column family. This method will throw an exception if a column family with the same name is already associated with the keyspace. Column names in metadata need to be ByteBuffer. You can achieve this by usin the CassandraDBUtils like in the next example

Parameters
cfDefinition An instance of CfDef
Returns
  • The new Schema version ID.
Throws
InvalidRequestException Invalid request could mean keyspace or column family does not exist, required parameters are missing, or a parameter is malformed.
SchemaDisagreementException Schemas are not in agreement across all nodes
TException Generic exception class for Thrift.

public String systemAddColumnFamilyFromObjectWithSimpleNames (CfDef cfDefinition, List<String> columnNames)

Adds a column family. This method will throw an exception if a column family with the same name is already associated with the keyspace. This method also recieves a list of string to be used as column names

Parameters
cfDefinition An instance of CfDef
columnNames A list that contains the columns names for columns defined in column_metadata
Returns
  • The new Schema version ID.
Throws
InvalidRequestException Invalid request could mean keyspace or column family does not exist, required parameters are missing, or a parameter is malformed.
SchemaDisagreementException Schemas are not in agreement across all nodes
TException Generic exception class for Thrift.
UnsupportedEncodingException Exception

public String systemAddColumnFamilyWithParams (String columnFamilyName, String comparatorType, String keyValidationClass, String defaultValidationClass, List<ColumnDef> columnMetadata, String keyspace)

Adds a column family to the current keyspace. This method will throw an exception if a column family with the same name is already associated with the keyspace.

Parameters
columnFamilyName The name of the column to be added
comparatorType Validator to use to validate and compare column names in this column family. For Standard column families it applies to columns, for Super column families applied to super columns.Default is BytesType, which is a straight forward lexical comparison of the bytes in each column.

Supported values are:

  • AsciiType
  • BooleanType
  • BytesType
  • CounterColumnType (distributed counter column)
  • DateType
  • DoubleType
  • FloatType
  • Int32Type
  • IntegerType (a generic variable-length integer type)
  • LexicalUUIDType
  • LongType
  • UTF8Type
  • CompositeType (should be used with sub-types specified e.g. 'CompositeType(UTF8Type, Int32Type)' quotes are important (!) in this case)
It is also valid to specify the fully-qualified class name to a class that extends org.apache.cassandra.db.marshal.AbstractType.
keyValidationClass Validator to use for keys. Default is BytesType which applies no validation.

Supported values are:

  • AsciiType
  • BooleanType
  • BytesType
  • DateType
  • DoubleType
  • FloatType
  • Int32Type
  • IntegerType (a generic variable-length integer type)
  • LexicalUUIDType
  • LongType
  • UTF8Type
It is also valid to specify the fully-qualified class name to a class that extends org.apache.cassandra.db.marshal.AbstractType.
defaultValidationClass Validator to use for values in columns which are not listed in the column_metadata. Default is BytesType which applies no validation.

Supported values are:

  • AsciiType
  • BooleanType
  • BytesType
  • CounterColumnType (distributed counter column)
  • DateType
  • DoubleType
  • FloatType
  • Int32Type
  • IntegerType (a generic variable-length integer type)
  • LexicalUUIDType
  • LongType
  • UTF8Type
  • CompositeType (should be used with sub-types specified e.g. 'CompositeType(UTF8Type, Int32Type)' quotes are important (!) in this case)
It is also valid to specify the fully-qualified class name to a class that extends org.apache.cassandra.db.marshal.AbstractType.
columnMetadata A list with the column definitions. If null, a dynamic column family will be created. For more details check http://www.datastax.com/docs/1.0/ddl/column_family
keyspace The name of the keyspace. If null, current keyspace will be used
Returns
  • The new Schema version ID.
Throws
InvalidRequestException Invalid request could mean keyspace or column family does not exist, required parameters are missing, or a parameter is malformed.
SchemaDisagreementException Schemas are not in agreement across all nodes
TException Generic exception class for Thrift.

public String systemAddKeyspaceFromObject (KsDef keyspaceDefinition)

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.

This will create a keyspace named MyKeyspace with no column families

Parameters
keyspaceDefinition The keyspace definition that will be added
Returns
  • The new schema version ID.
Throws
InvalidRequestException Invalid request could mean keyspace or column family does not exist, required parameters are missing, or a parameter is malformed.
SchemaDisagreementException Schemas are not in agreement across all nodes
TException Generic exception class for Thrift.

public Object systemAddKeyspaceWithParams (String keyspaceName, List<String> columnNames, ReplicationStrategy strategyClass, Map<String, String> strategyOptions)

Creates a new keyspace with the provided name with all the defaults values

Parameters
keyspaceName The keyspace name
columnNames List of the column names the keyspace will have
strategyClass The name of the class that handles the Replication Strategy.
strategyOptions Map containing the configuration for the strategy class selected.
Returns
  • The new schema version ID.
Throws
InvalidRequestException Invalid request could mean keyspace or column family does not exist, required parameters are missing, or a parameter is malformed.
SchemaDisagreementException Schemas are not in agreement across all nodes
TException Generic exception class for Thrift.

public String systemDropColumnFamily (String columnFamily)

Drops a column family. Creates a snapshot and then submits a 'graveyard' compaction during which the abandoned files will be deleted.

Parameters
columnFamily The name of the column family to be drop
Returns
  • The new schema version ID.
Throws
InvalidRequestException Invalid request could mean keyspace or column family does not exist, required parameters are missing, or a parameter is malformed.
SchemaDisagreementException Schemas are not in agreement across all nodes
TException Generic exception class for Thrift.

public Object systemDropKeyspace (String keyspace)

Drops a keyspace. Creates a snapshot and then submits a 'graveyard' compaction during which the abandoned files will be deleted.

Parameters
keyspace Name of the keyspace to be dropped
Returns
  • The new schema version ID.
Throws
InvalidRequestException Invalid request could mean keyspace or column family does not exist, required parameters are missing, or a parameter is malformed.
SchemaDisagreementException Schemas are not in agreement across all nodes
TException Generic exception class for Thrift.

public String systemUpdateColumnFamily (CfDef columnFamily)

Updates properties of a ColumnFamily.

Parameters
columnFamily CfDef with new settings
Returns
  • The new schema version ID.
Throws
InvalidRequestException Invalid request could mean keyspace or column family does not exist, required parameters are missing, or a parameter is malformed.
SchemaDisagreementException Schemas are not in agreement across all nodes
TException Generic exception class for Thrift.

public String systemUpdateKeyspace (KsDef keyspaceDef)

Updates properties of a keyspace.

Parameters
keyspaceDef New keyspace to be applied for update
Returns
  • The new schema version ID.
Throws
InvalidRequestException Invalid request could mean keyspace or column family does not exist, required parameters are missing, or a parameter is malformed.
SchemaDisagreementException Schemas are not in agreement across all nodes
TException Generic exception class for Thrift.

public void truncate (String columnFamily)

Removes all the rows from the given column family.

Parameters
columnFamily Column Family
Throws
InvalidRequestException Invalid request could mean keyspace or column family does not exist, required parameters are missing, or a parameter is malformed.
UnavailableException Not all the replicas required could be created and/or read.
TException Generic exception class for Thrift.