com.netflix.astyanax
Interface MutationBatch

Type Parameters:
K -
All Superinterfaces:
Execution<Void>
All Known Implementing Classes:
AbstractThriftMutationBatchImpl

public interface MutationBatch
extends Execution<Void>

Batch mutator which operates at the row level assuming the hierarchy: RowKey -> ColumnFamily -> Mutation. This hierarchy serves two purposes. First, it makes it possible to perform multiple operations on the same row without having to repeat specifying the row key. Second, it mirrors the underlying Thrift data structure which averts unnecessary operations to convert from one data structure to another. The mutator is not thread safe If successful, all the mutations are cleared and new mutations may be created. Any previously acquired ColumnFamilyMutations are no longer valid and should be discarded. No data is actually returned after a mutation is executed, hence the Void return value type. Example:

 ColumnFamily<String, String> cf = 
 		AFactory.makeColumnFamily(
 				"COLUMN_FAMILY_NAME", 	// Name of CF in Cassandra
 				StringSerializer.get(), // Row key serializer (implies string type)
 				StringSerializer.get(), // Column name serializer (implies string type)
 				ColumnType.STANDARD);	// This is a standard row

 	// Create a batch mutation
 	RowMutationBatch m = keyspace.prepareMutationBatch();

  // Start mutate a column family for a specific row key 
  ColumnFamilyMutation<String> cfm = m.row(cfSuper, "UserId")
	   .putColumn("Address", "976 Elm St.")
     .putColumn("Age", 50)
     .putColumn("Gender", "Male");
  
  // To delete a row
  m.row(cfSuper, "UserId").delete();
  
  // Finally, execute the query
  m.execute();
  
 
 

Author:
elandau

Method Summary
<K> void
deleteRow(Collection<ColumnFamily<K,?>> columnFamilies, K rowKey)
          Delete the row for all the specified column families
 void discardMutations()
          Discard any pending mutations.
 int getRowCount()
          Returns the number of rows being mutated
 boolean isEmpty()
          Returns true if there are no rows in the mutation.
 MutationBatch lockCurrentTimestamp()
          Force all future mutations to have the same timestamp.
 void mergeShallow(MutationBatch other)
          Perform a shallow merge of mutations from another batch.
 MutationBatch pinToHost(Host host)
          Pin this operation to a specific host
 MutationBatch setConsistencyLevel(ConsistencyLevel consistencyLevel)
          Set the consistency level for this mutation
 MutationBatch setTimeout(long timeout)
          Deprecated. 
 MutationBatch setTimestamp(long timestamp)
          Set the timestamp for all subsequent operations on this mutation
 MutationBatch withRetryPolicy(RetryPolicy retry)
          Set the retry policy to use instead of the one specified in the configuration
<K,C> ColumnListMutation<C>
withRow(ColumnFamily<K,C> columnFamily, K rowKey)
          Mutate a row.
 
Methods inherited from interface com.netflix.astyanax.Execution
execute, executeAsync
 

Method Detail

withRow

<K,C> ColumnListMutation<C> withRow(ColumnFamily<K,C> columnFamily,
                                    K rowKey)
Mutate a row. The ColumnFamilyMutation is only valid until execute() or discardMutations is called.

Parameters:
rowKey -
Returns:

deleteRow

<K> void deleteRow(Collection<ColumnFamily<K,?>> columnFamilies,
                   K rowKey)
Delete the row for all the specified column families

Parameters:
columnFamilies -

discardMutations

void discardMutations()
Discard any pending mutations. All previous references returned by row are now invalid.


mergeShallow

void mergeShallow(MutationBatch other)
Perform a shallow merge of mutations from another batch.

Throws:
UnsupportedOperationException - if the other mutation is of a different type

isEmpty

boolean isEmpty()
Returns true if there are no rows in the mutation. May return a false true if a row() was added by calling the above row() method but no mutations were created.

Returns:

getRowCount

int getRowCount()
Returns the number of rows being mutated

Returns:

pinToHost

MutationBatch pinToHost(Host host)
Pin this operation to a specific host

Parameters:
host -
Returns:

setConsistencyLevel

MutationBatch setConsistencyLevel(ConsistencyLevel consistencyLevel)
Set the consistency level for this mutation

Parameters:
consistencyLevel -

withRetryPolicy

MutationBatch withRetryPolicy(RetryPolicy retry)
Set the retry policy to use instead of the one specified in the configuration

Parameters:
retry -
Returns:

lockCurrentTimestamp

MutationBatch lockCurrentTimestamp()
Force all future mutations to have the same timestamp. Make sure to call lockTimestamp before doing any other operations otherwise previously created withRow mutations will use the previous timestamp.

Returns:

setTimeout

@Deprecated
MutationBatch setTimeout(long timeout)
Deprecated. 

This never really did anything :)

Parameters:
-

setTimestamp

MutationBatch setTimestamp(long timestamp)
Set the timestamp for all subsequent operations on this mutation

Parameters:
timestamp -
Returns:


Copyright © 2012. All Rights Reserved.