org.scale7.cassandra.pelops
Class Mutator

java.lang.Object
  extended by org.scale7.cassandra.pelops.Operand
      extended by org.scale7.cassandra.pelops.Mutator

public class Mutator
extends Operand

Facilitates the mutation of data within a Cassandra keyspace: the desired mutations should first be specified by calling methods such as writeColumn(...), which should then be sent to Cassandra in a single batch by calling execute(...). After the desired batch of mutations has been executed, the Mutator object can not be re-used.

Author:
dominicwilliams

Nested Class Summary
 
Nested classes/interfaces inherited from class org.scale7.cassandra.pelops.Operand
Operand.IOperation<ReturnType>
 
Field Summary
protected  boolean deleteIfNull
           
static int NO_TTL
          Used to indicate that the ttl property on column instances should not be set.
protected  long timestamp
           
protected  int ttl
           
 
Fields inherited from class org.scale7.cassandra.pelops.Operand
thrift
 
Constructor Summary
Mutator(IThriftPool thrift)
          Create a batch mutation operation.
Mutator(IThriftPool thrift, long timestamp, boolean deleteIfNull)
          Create a batch mutation operation.
Mutator(IThriftPool thrift, long timestamp, boolean deleteIfNull, int ttl)
          Create a batch mutation operation.
 
Method Summary
 Mutator deleteColumn(String colFamily, Bytes rowKey, Bytes colName)
          Delete a column or super column.
 Mutator deleteColumn(String colFamily, String rowKey, Bytes colName)
          Delete a column or super column.
 Mutator deleteColumn(String colFamily, String rowKey, String colName)
          Delete a column or super column
 Mutator deleteColumns(String colFamily, Bytes rowKey, Bytes... colNames)
          Delete a list of columns or super columns.
 Mutator deleteColumns(String colFamily, Bytes rowKey, List<Bytes> colNames)
          Delete a list of columns or super columns.
 Mutator deleteColumns(String colFamily, String rowKey, Bytes... colNames)
          Delete a list of columns or super columns.
 Mutator deleteColumns(String colFamily, String rowKey, List<Bytes> colNames)
          Delete a list of columns or super columns.
 Mutator deleteColumns(String colFamily, String rowKey, String... colNames)
          Delete a list of columns or super columns.
 Mutator deleteSubColumn(String colFamily, Bytes rowKey, Bytes colName, Bytes subColName)
          Delete a column or super column.
 Mutator deleteSubColumn(String colFamily, String rowKey, Bytes colName, Bytes subColName)
          Delete a column or super column.
 Mutator deleteSubColumn(String colFamily, String rowKey, Bytes colName, String subColName)
          Delete a column or super column.
 Mutator deleteSubColumn(String colFamily, String rowKey, String colName, Bytes subColName)
          Delete a column or super column.
 Mutator deleteSubColumn(String colFamily, String rowKey, String colName, String subColName)
          Delete a column or super column.
 Mutator deleteSubColumns(String colFamily, Bytes rowKey, Bytes colName, List<Bytes> subColNames)
          Delete a list of sub-columns
 Mutator deleteSubColumns(String colFamily, Bytes rowKey, Bytes colName, String... subColNames)
          Delete a list of sub-columns
 Mutator deleteSubColumns(String colFamily, String rowKey, Bytes colName)
          Delete all sub-columns
 Mutator deleteSubColumns(String colFamily, String rowKey, Bytes colName, List<Bytes> subColNames)
          Delete a list of sub-columns
 Mutator deleteSubColumns(String colFamily, String rowKey, Bytes colName, String... subColNames)
          Delete a list of sub-columns
 Mutator deleteSubColumns(String colFamily, String rowKey, String colName)
          Delete all sub-columns
 Mutator deleteSubColumns(String colFamily, String rowKey, String colName, List<Bytes> subColNames)
          Delete a list of sub-columns
 Mutator deleteSubColumns(String colFamily, String rowKey, String colName, String... subColNames)
          Delete a list of sub-columns
 void execute(org.apache.cassandra.thrift.ConsistencyLevel cLevel)
          Execute the mutations that have been specified by sending them to Cassandra in a single batch.
protected  Map<Bytes,Map<String,List<org.apache.cassandra.thrift.Mutation>>> getBatch()
           
protected  org.scale7.cassandra.pelops.Mutator.MutationList getMutationList(String colFamily, Bytes key)
           
 Bytes getMutationTimestamp(boolean microsToMillis)
          Get the default time stamp used by this Mutator instance as a byte[].
 long getMutationTimestampValue()
          Get the raw time stamp value used by this Mutator instance.
 org.apache.cassandra.thrift.Column newColumn(Bytes colName, Bytes colValue)
          Create new Column object with the time stamp passed to the constructor
 org.apache.cassandra.thrift.Column newColumn(Bytes colName, Bytes colValue, int ttl)
          Create new Column object with the time stamp passed to the constructor
 org.apache.cassandra.thrift.Column newColumn(Bytes colName, String colValue)
          Create new Column object with the time stamp passed to the constructor
 org.apache.cassandra.thrift.Column newColumn(Bytes colName, String colValue, int ttl)
          Create new Column object with the time stamp passed to the constructor
 org.apache.cassandra.thrift.Column newColumn(String colName, Bytes colValue)
          Create new Column object with the time stamp passed to the constructor
 org.apache.cassandra.thrift.Column newColumn(String colName, Bytes colValue, int ttl)
          Create new Column object with the time stamp passed to the constructor
 org.apache.cassandra.thrift.Column newColumn(String colName, String colValue)
          Create new Column object with the time stamp passed to the constructor
 org.apache.cassandra.thrift.Column newColumn(String colName, String colValue, int ttl)
          Create new Column object with the time stamp passed to the constructor
 List<org.apache.cassandra.thrift.Column> newColumnList(org.apache.cassandra.thrift.Column... columns)
          Create a list of Column objects.
 Mutator writeColumn(String colFamily, Bytes rowKey, org.apache.cassandra.thrift.Column column)
          Write a column value.
 Mutator writeColumn(String colFamily, Bytes rowKey, org.apache.cassandra.thrift.Column column, boolean deleteIfNullValue)
          Write a column value.
 Mutator writeColumn(String colFamily, String rowKey, org.apache.cassandra.thrift.Column column)
          Write a column value.
 Mutator writeColumns(String colFamily, Bytes rowKey, List<org.apache.cassandra.thrift.Column> columns)
          Write a list of columns to a key
 Mutator writeColumns(String colFamily, Bytes rowKey, List<org.apache.cassandra.thrift.Column> columns, boolean deleteIfNullValue)
          Write a list of columns to a key.
 Mutator writeColumns(String colFamily, String rowKey, List<org.apache.cassandra.thrift.Column> columns)
          Write a list of columns to a key
 Mutator writeSubColumn(String colFamily, Bytes rowKey, Bytes colName, org.apache.cassandra.thrift.Column subColumn)
          Write a single sub-column value to a super column.
 Mutator writeSubColumn(String colFamily, String rowKey, Bytes colName, org.apache.cassandra.thrift.Column subColumn)
          Write a single sub-column value to a super column.
 Mutator writeSubColumn(String colFamily, String rowKey, String colName, org.apache.cassandra.thrift.Column subColumn)
          Write a single sub-column value to a super column.
 Mutator writeSubColumns(String colFamily, Bytes rowKey, Bytes colName, List<org.apache.cassandra.thrift.Column> subColumns)
          Write multiple sub-column values to a super column.
 Mutator writeSubColumns(String colFamily, Bytes rowKey, Bytes colName, List<org.apache.cassandra.thrift.Column> subColumns, boolean deleteIfNullValue)
          Write multiple sub-column values to a super column.
 Mutator writeSubColumns(String colFamily, String rowKey, Bytes colName, List<org.apache.cassandra.thrift.Column> subColumns)
          Write multiple sub-column values to a super column.
 Mutator writeSubColumns(String colFamily, String rowKey, String colName, List<org.apache.cassandra.thrift.Column> subColumns)
          Write multiple sub-column values to a super column.
 
Methods inherited from class org.scale7.cassandra.pelops.Operand
tryOperation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_TTL

public static final int NO_TTL
Used to indicate that the ttl property on column instances should not be set.

See Also:
Constant Field Values

timestamp

protected final long timestamp

deleteIfNull

protected final boolean deleteIfNull

ttl

protected final int ttl
Constructor Detail

Mutator

public Mutator(IThriftPool thrift)
Create a batch mutation operation.


Mutator

public Mutator(IThriftPool thrift,
               long timestamp,
               boolean deleteIfNull)
Create a batch mutation operation.

Parameters:
timestamp - The time stamp to use for the operation.

Mutator

public Mutator(IThriftPool thrift,
               long timestamp,
               boolean deleteIfNull,
               int ttl)
Create a batch mutation operation.

Parameters:
thrift - the pool
timestamp - The time stamp to use for the operation.
deleteIfNull - determine if null values on columns will result in a delete
ttl - the ttl (in seconds) that columns created using the various newColumn(Bytes, Bytes) helper methods will default to (null to indicate no default)
Method Detail

execute

public void execute(org.apache.cassandra.thrift.ConsistencyLevel cLevel)
             throws PelopsException
Execute the mutations that have been specified by sending them to Cassandra in a single batch.

Parameters:
cLevel - The Cassandra consistency level to be used
Throws:
PelopsException

writeColumn

public Mutator writeColumn(String colFamily,
                           String rowKey,
                           org.apache.cassandra.thrift.Column column)
Write a column value.

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
column - The value of the column

writeColumn

public Mutator writeColumn(String colFamily,
                           Bytes rowKey,
                           org.apache.cassandra.thrift.Column column)
Write a column value.

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
column - The value of the column

writeColumn

public Mutator writeColumn(String colFamily,
                           Bytes rowKey,
                           org.apache.cassandra.thrift.Column column,
                           boolean deleteIfNullValue)
Write a column value. This method will automatically issue deletes if the deleteIfNullValue is true and the provided column does not have a value.

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
column - The value of the column
deleteIfNullValue - If true and the provided column does NOT have value (as determined by the Column.isSetValue() method) then issue a delete instead.

writeColumns

public Mutator writeColumns(String colFamily,
                            String rowKey,
                            List<org.apache.cassandra.thrift.Column> columns)
Write a list of columns to a key

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
columns - The list of columns to write

writeColumns

public Mutator writeColumns(String colFamily,
                            Bytes rowKey,
                            List<org.apache.cassandra.thrift.Column> columns)
Write a list of columns to a key

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
columns - The list of columns to write

writeColumns

public Mutator writeColumns(String colFamily,
                            Bytes rowKey,
                            List<org.apache.cassandra.thrift.Column> columns,
                            boolean deleteIfNullValue)
Write a list of columns to a key. This method will automatically issue deletes if the deleteIfNullValue is true and the provided column does not have a value.

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
columns - The list of columns to write
deleteIfNullValue - If true and if the provided columns do NOT have value (as determined by the Column.isSetValue() method) then issue a delete instead.

writeSubColumn

public Mutator writeSubColumn(String colFamily,
                              String rowKey,
                              String colName,
                              org.apache.cassandra.thrift.Column subColumn)
Write a single sub-column value to a super column. If wish to write multiple sub-columns for a super column, then it is more efficient to use writeSubColumns

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
colName - The name of the super column
subColumn - The sub-column

writeSubColumn

public Mutator writeSubColumn(String colFamily,
                              String rowKey,
                              Bytes colName,
                              org.apache.cassandra.thrift.Column subColumn)
Write a single sub-column value to a super column. If wish to write multiple sub-columns for a super column, then it is more efficient to use writeSubColumns

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
colName - The name of the super column
subColumn - The sub-column

writeSubColumn

public Mutator writeSubColumn(String colFamily,
                              Bytes rowKey,
                              Bytes colName,
                              org.apache.cassandra.thrift.Column subColumn)
Write a single sub-column value to a super column. If you wish to write multiple sub-columns for a super column, then it is more efficient to use writeSubColumns

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
colName - The name of the super column
subColumn - The sub-column

writeSubColumns

public Mutator writeSubColumns(String colFamily,
                               String rowKey,
                               String colName,
                               List<org.apache.cassandra.thrift.Column> subColumns)
Write multiple sub-column values to a super column.

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
colName - The name of the super column
subColumns - A list of the sub-columns to write

writeSubColumns

public Mutator writeSubColumns(String colFamily,
                               String rowKey,
                               Bytes colName,
                               List<org.apache.cassandra.thrift.Column> subColumns)
Write multiple sub-column values to a super column.

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
colName - The name of the super column
subColumns - A list of the sub-columns to write

writeSubColumns

public Mutator writeSubColumns(String colFamily,
                               Bytes rowKey,
                               Bytes colName,
                               List<org.apache.cassandra.thrift.Column> subColumns)
Write multiple sub-column values to a super column.

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
colName - The name of the super column
subColumns - A list of the sub-columns to write

writeSubColumns

public Mutator writeSubColumns(String colFamily,
                               Bytes rowKey,
                               Bytes colName,
                               List<org.apache.cassandra.thrift.Column> subColumns,
                               boolean deleteIfNullValue)
Write multiple sub-column values to a super column. This method will automatically delete sub columns if the deleteIfNullValue is true and any of the sub columns do not have a value.

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
colName - The name of the super column
subColumns - A list of the sub-columns to write
deleteIfNullValue - If true and if the provided columns do NOT have values (as determined by the Column.isSetValue() method) then issue a call to deleteSubColumns(String, String, Bytes) with the columns that have no values.

deleteColumn

public Mutator deleteColumn(String colFamily,
                            String rowKey,
                            String colName)
Delete a column or super column

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
colName - The name of the column or super column to delete.

deleteColumn

public Mutator deleteColumn(String colFamily,
                            String rowKey,
                            Bytes colName)
Delete a column or super column.

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
colName - The name of the column or super column to delete.

deleteColumn

public Mutator deleteColumn(String colFamily,
                            Bytes rowKey,
                            Bytes colName)
Delete a column or super column.

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
colName - The name of the column or super column to delete.

deleteColumns

public Mutator deleteColumns(String colFamily,
                             String rowKey,
                             Bytes... colNames)
Delete a list of columns or super columns.

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
colNames - The column and/or super column names to delete

deleteColumns

public Mutator deleteColumns(String colFamily,
                             Bytes rowKey,
                             Bytes... colNames)
Delete a list of columns or super columns.

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
colNames - The column and/or super column names to delete

deleteColumns

public Mutator deleteColumns(String colFamily,
                             String rowKey,
                             String... colNames)
Delete a list of columns or super columns.

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
colNames - The column and/or super column names to delete

deleteColumns

public Mutator deleteColumns(String colFamily,
                             String rowKey,
                             List<Bytes> colNames)
Delete a list of columns or super columns.

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
colNames - The column and/or super column names to delete

deleteColumns

public Mutator deleteColumns(String colFamily,
                             Bytes rowKey,
                             List<Bytes> colNames)
Delete a list of columns or super columns.

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
colNames - The column and/or super column names to delete

deleteSubColumn

public Mutator deleteSubColumn(String colFamily,
                               String rowKey,
                               String colName,
                               String subColName)
Delete a column or super column.

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
colName - The name of the super column to modify.
subColName - The name of the sub-column to delete.

deleteSubColumn

public Mutator deleteSubColumn(String colFamily,
                               String rowKey,
                               Bytes colName,
                               String subColName)
Delete a column or super column.

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
colName - The name of the super column to modify.
subColName - The name of the sub-column to delete.

deleteSubColumn

public Mutator deleteSubColumn(String colFamily,
                               String rowKey,
                               String colName,
                               Bytes subColName)
Delete a column or super column.

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
colName - The name of the super column to modify.
subColName - The name of the sub-column to delete.

deleteSubColumn

public Mutator deleteSubColumn(String colFamily,
                               String rowKey,
                               Bytes colName,
                               Bytes subColName)
Delete a column or super column.

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
colName - The name of the super column to modify.
subColName - The name of the sub-column to delete.

deleteSubColumn

public Mutator deleteSubColumn(String colFamily,
                               Bytes rowKey,
                               Bytes colName,
                               Bytes subColName)
Delete a column or super column.

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
colName - The name of the super column to modify.
subColName - The name of the sub-column to delete.

deleteSubColumns

public Mutator deleteSubColumns(String colFamily,
                                String rowKey,
                                String colName,
                                String... subColNames)
Delete a list of sub-columns

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
colName - The name of the super column to modify
subColNames - The sub-column names to delete (empty value will result in all columns being removed)

deleteSubColumns

public Mutator deleteSubColumns(String colFamily,
                                String rowKey,
                                Bytes colName,
                                String... subColNames)
Delete a list of sub-columns

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
colName - The name of the super column to modify
subColNames - The sub-column names to delete (empty value will result in all columns being removed)

deleteSubColumns

public Mutator deleteSubColumns(String colFamily,
                                Bytes rowKey,
                                Bytes colName,
                                String... subColNames)
Delete a list of sub-columns

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
colName - The name of the super column to modify
subColNames - The sub-column names to delete (empty value will result in all columns being removed)

deleteSubColumns

public Mutator deleteSubColumns(String colFamily,
                                String rowKey,
                                String colName)
Delete all sub-columns

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
colName - The name of the super column to modify

deleteSubColumns

public Mutator deleteSubColumns(String colFamily,
                                String rowKey,
                                String colName,
                                List<Bytes> subColNames)
Delete a list of sub-columns

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
colName - The name of the super column to modify
subColNames - The sub-column names to delete

deleteSubColumns

public Mutator deleteSubColumns(String colFamily,
                                String rowKey,
                                Bytes colName)
Delete all sub-columns

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
colName - The name of the super column to modify

deleteSubColumns

public Mutator deleteSubColumns(String colFamily,
                                String rowKey,
                                Bytes colName,
                                List<Bytes> subColNames)
Delete a list of sub-columns

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
colName - The name of the super column to modify
subColNames - The sub-column names to delete

deleteSubColumns

public Mutator deleteSubColumns(String colFamily,
                                Bytes rowKey,
                                Bytes colName,
                                List<Bytes> subColNames)
Delete a list of sub-columns

Parameters:
colFamily - The column family
rowKey - The key of the row to modify
colName - The name of the super column to modify
subColNames - The sub-column names to delete

newColumn

public org.apache.cassandra.thrift.Column newColumn(String colName,
                                                    String colValue)
Create new Column object with the time stamp passed to the constructor

Parameters:
colName - The column name
colValue - The column value
Returns:
An appropriate Column object

newColumn

public org.apache.cassandra.thrift.Column newColumn(String colName,
                                                    String colValue,
                                                    int ttl)
Create new Column object with the time stamp passed to the constructor

Parameters:
colName - The column name
colValue - The column value
ttl - The time to live (in seconds) for the column
Returns:
An appropriate Column object

newColumn

public org.apache.cassandra.thrift.Column newColumn(Bytes colName,
                                                    String colValue)
Create new Column object with the time stamp passed to the constructor

Parameters:
colName - The column name
colValue - The column value
Returns:
An appropriate Column object

newColumn

public org.apache.cassandra.thrift.Column newColumn(Bytes colName,
                                                    String colValue,
                                                    int ttl)
Create new Column object with the time stamp passed to the constructor

Parameters:
colName - The column name
colValue - The column value
ttl - The time to live (in seconds) for the column
Returns:
An appropriate Column object

newColumn

public org.apache.cassandra.thrift.Column newColumn(String colName,
                                                    Bytes colValue)
Create new Column object with the time stamp passed to the constructor

Parameters:
colName - The column name
colValue - The column value
Returns:
An appropriate Column object

newColumn

public org.apache.cassandra.thrift.Column newColumn(String colName,
                                                    Bytes colValue,
                                                    int ttl)
Create new Column object with the time stamp passed to the constructor

Parameters:
colName - The column name
colValue - The column value
ttl - The time to live (in seconds) for the column
Returns:
An appropriate Column object

newColumn

public org.apache.cassandra.thrift.Column newColumn(Bytes colName,
                                                    Bytes colValue)
Create new Column object with the time stamp passed to the constructor

Parameters:
colName - The column name
colValue - The column value
Returns:
An appropriate Column object

newColumn

public org.apache.cassandra.thrift.Column newColumn(Bytes colName,
                                                    Bytes colValue,
                                                    int ttl)
Create new Column object with the time stamp passed to the constructor

Parameters:
colName - The column name
colValue - The column value
ttl - The time to live (in seconds) for the column (-1 for default)
Returns:
An appropriate Column object

newColumnList

public List<org.apache.cassandra.thrift.Column> newColumnList(org.apache.cassandra.thrift.Column... columns)
Create a list of Column objects.

Parameters:
columns - The columns from which to compose the list
Returns:
A list of Column objects

getMutationTimestamp

public Bytes getMutationTimestamp(boolean microsToMillis)
Get the default time stamp used by this Mutator instance as a byte[].

Parameters:
microsToMillis - If the time stamp is UTC microseconds (as is a self-constructed time stamp), whether to convert this into a standard milliseconds value
Returns:
A byte array containing the time stamp long value

getMutationTimestampValue

public long getMutationTimestampValue()
Get the raw time stamp value used by this Mutator instance.

Returns:
The raw time stamp value being used

getBatch

protected Map<Bytes,Map<String,List<org.apache.cassandra.thrift.Mutation>>> getBatch()

getMutationList

protected org.scale7.cassandra.pelops.Mutator.MutationList getMutationList(String colFamily,
                                                                           Bytes key)


Copyright © 2011. All Rights Reserved.