1: <?php
2: namespace phpcassa\Batch;
3:
4: use phpcassa\Batch\AbstractMutator;
5:
6: /**
7: * A convenience subclass of phpcassa\Batch\Mutator for dealing
8: * with batch operations on a single column family.
9: *
10: * @package phpcassa\Batch
11: */
12: class CfMutator extends AbstractMutator {
13:
14: protected $cf;
15:
16: /**
17: * Initialize a mutator for a given column family.
18: *
19: * @param phpcassa\ColumnFamily $column_family an initialized instanced
20: * of ColumnFamily; this object's pool will be used for all
21: * operations.
22: * @param phpcassa\ConsistencyLevel $write_consistency_level the consistency
23: * level this mutator will write at; if left as NULL, this defaults to
24: * $column_family->write_consistency_level.
25: */
26: public function __construct($column_family, $write_consistency_level=null) {
27: $this->cf = $column_family;
28: $this->pool = $column_family->pool;
29: $this->buffer = array();
30: if ($write_consistency_level === null)
31: $this->cl = $column_family->write_consistency_level;
32: else
33: $this->cl = $write_consistency_level;
34: }
35:
36: /**
37: * Add an insertion to the buffer.
38: *
39: * @param mixed $key the row key
40: * @param mixed[] $columns an array of columns to insert, whose format
41: * should match $column_family->insert_format
42: * @param int $timestamp an optional timestamp (default is "now", when
43: * this function is called, not when send() is called)
44: * @param int $ttl a TTL to apply to all columns inserted here
45: */
46: public function insert($key, $columns, $timestamp=null, $ttl=null) {
47: return $this->insert_cf($this->cf, $key, $columns, $timestamp, $ttl);
48: }
49:
50: /**
51: * Add a deletion to the buffer.
52: *
53: * @param mixed $key the row key
54: * @param mixed[] $columns a list of columns or super columns to delete
55: * @param mixed $supercolumn if you want to delete only some subcolumns from
56: * a single super column, set this to the super column name
57: * @param int $timestamp an optional timestamp (default is "now", when
58: * this function is called, not when send() is called)
59: */
60: public function remove($key, $columns=null, $super_column=null, $timestamp=null) {
61: return $this->remove_cf($this->cf, $key, $columns, $super_column, $timestamp);
62: }
63: }
64: