public function setUp() { $this->client = new ConnectionPool(self::$KS); $this->cf_float = new ColumnFamily($this->client, 'StdFloat'); $this->cf_double = new ColumnFamily($this->client, 'StdDouble'); $this->cf_time = new ColumnFamily($this->client, 'StdTimeUUID'); $this->cf_lex = new ColumnFamily($this->client, 'StdLexicalUUID'); $this->cf_date = new ColumnFamily($this->client, 'StdDate'); $this->cf_composite = new ColumnFamily($this->client, 'StdComposite'); $this->cfs = array($this->cf_float, $this->cf_double, $this->cf_time, $this->cf_lex, $this->cf_composite); // make a millisecond precision timestamp if (PHP_INT_MAX === 2147483647) { $base_time = (double) time(); } else { // make a millisecond precision timestamp $base_time = Clock::get_time(); $base_time -= (int) $base_time % 1000; $base_time /= 1000000.0; } $this->DATE1 = $base_time + 0; $this->DATE2 = $base_time + 1; $this->DATE3 = $base_time + 2; $this->TIME1 = UUID::mint(); $this->TIME2 = UUID::mint(); $this->TIME3 = UUID::mint(); $this->LEX1 = UUID::import('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'); $this->LEX2 = UUID::import('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'); $this->LEX3 = UUID::import('cccccccccccccccccccccccccccccccc'); }
/** * Add a deletion to the buffer. * * @param phpcassa\ColumnFamily $column_family an initialized * ColumnFamily instance * @param mixed $key the row key * @param mixed[] $columns a list of columns or super columns to delete * @param mixed $supercolumn if you want to delete only some subcolumns from * a single super column, set this to the super column name * @param int $timestamp an optional timestamp (default is "now", when * this function is called, not when send() is called) */ public function remove($column_family, $key, $columns = null, $super_column = null, $timestamp = null) { if ($timestamp === null) { $timestamp = Clock::get_time(); } $deletion = new Deletion(); $deletion->timestamp = $timestamp; if ($super_column !== null) { $deletion->super_column = $column_family->pack_name($super_column, true); } if ($columns !== null) { $is_super = $column_family->is_super && $super_column === null; $packed_cols = array(); foreach ($columns as $col) { $packed_cols[] = $column_family->pack_name($col, $is_super); } $predicate = new SlicePredicate(); $predicate->column_names = $packed_cols; $deletion->predicate = $predicate; } $mutation = new Mutation(); $mutation->deletion = $deletion; $packed_key = $column_family->pack_key($key); $this->enqueue($packed_key, $column_family, array($mutation)); return $this; }
protected function pack_data($data, $timestamp = null, $ttl = null) { if ($timestamp === null) { $timestamp = Clock::get_time(); } if ($this->insert_format == self::DICTIONARY_FORMAT) { return $this->dict_to_coscs($data, $timestamp, $ttl); } else { if ($this->insert_format == self::ARRAY_FORMAT) { return $this->array_to_coscs($data, $timestamp, $ttl); } else { throw new UnexpectedValueException("Bad insert_format selected"); } } }
protected static function mintTime($node = NULL, $time_arg = NULL) { /* Generates a Version 1 UUID. These are derived from the time at which they were generated. */ // Get time since Gregorian calendar reform in 100ns intervals // This is exceedingly difficult because of PHP's (and pack()'s) // integer size limits. // Note that this will never be more accurate than to the microsecond. if ($time_arg == NULL) { $time = Clock::get_time() * 10 + self::interval; } else { $time = $time_arg * 10 + self::interval; } // Convert to a string representation $time = sprintf("%F", $time); preg_match("/^\\d+/", $time, $time); //strip decimal point // And now to a 64-bit binary representation $time = base_convert($time[0], 10, 16); $time = pack("H*", str_pad($time, 16, "0", STR_PAD_LEFT)); // Reorder bytes to their proper locations in the UUID $uuid = $time[4] . $time[5] . $time[6] . $time[7] . $time[2] . $time[3] . $time[0] . $time[1]; // Generate a random clock sequence $uuid .= self::randomBytes(2); // set variant $uuid[8] = chr(ord($uuid[8]) & self::clearVar | self::varRFC); // set version $uuid[6] = chr(ord($uuid[6]) & self::clearVer | self::version1); // Set the final 'node' parameter, a MAC address if ($node) { $node = self::makeBin($node, 6); } if (!$node) { // If no node was provided or if the node was invalid, // generate a random MAC address and set the multicast bit $node = self::randomBytes(6); $node[0] = pack("C", ord($node[0]) | 1); } $uuid .= $node; return $uuid; }