1: <?php
2: namespace phpcassa\Batch;
3:
4: use cassandra\ConsistencyLevel;
5:
6: /**
7: * Allows you to group multiple mutations across one or more
8: * keys and column families into a single batch operation.
9: *
10: * @package phpcassa\Batch
11: */
12: class Mutator extends AbstractMutator
13: {
14: /**
15: * Intialize a mutator with a connection pool and consistency level.
16: *
17: * @param phpcassa\Connection\ConnectionPool $pool the connection pool to
18: * use for all operations
19: * @param cassandra\ConsistencyLevel $consistency_level the default consistency
20: * level this mutator will write at, with a default of
21: * ConsistencyLevel::ONE
22: */
23: public function __construct($pool,
24: $consistency_level=ConsistencyLevel::ONE) {
25: $this->pool = $pool;
26: $this->buffer = array();
27: $this->cl = $consistency_level;
28: }
29:
30: /**
31: * Add an insertion to the buffer.
32: *
33: * @param phpcassa\ColumnFamily $column_family an initialized
34: * ColumnFamily instance
35: * @param mixed $key the row key
36: * @param mixed[] $columns an array of columns to insert, whose format
37: * should match $column_family->insert_format
38: * @param int $timestamp an optional timestamp (default is "now", when
39: * this function is called, not when send() is called)
40: * @param int $ttl a TTL to apply to all columns inserted here
41: */
42: public function insert($column_family, $key, $columns, $timestamp=null, $ttl=null) {
43: return $this->insert_cf($column_family, $key, $columns, $timestamp, $ttl);
44: }
45:
46: /**
47: * Add a deletion to the buffer.
48: *
49: * @param phpcassa\ColumnFamily $column_family an initialized
50: * ColumnFamily instance
51: * @param mixed $key the row key
52: * @param mixed[] $columns a list of columns or super columns to delete
53: * @param mixed $supercolumn if you want to delete only some subcolumns from
54: * a single super column, set this to the super column name
55: * @param int $timestamp an optional timestamp (default is "now", when
56: * this function is called, not when send() is called)
57: */
58: public function remove($column_family, $key, $columns=null, $super_column=null, $timestamp=null) {
59: return $this->remove_cf($column_family, $key, $columns, $super_column, $timestamp);
60: }
61: