Esempio n. 1
0
 /**
  * Loads an entire columnfamily by keyid
  * @param string $keyID row key
  * @param bool $colAutoCreate create columns in the object instance which have not been defined
  * @param int $consistencyLevel cassandra consistency level
  * @return bool loaded OK
  */
 public function load($keyID, $colAutoCreate = NULL, $consistencyLevel = NULL)
 {
     $this->_loaded = FALSE;
     $result = PandraCore::getCFSlice($keyID, $this->getKeySpace(), $this->getName(), NULL, PandraCore::getConsistency($consistencyLevel));
     if ($result !== NULL) {
         $this->init();
         $this->_loaded = $this->populate($result, $this->getAutoCreate($colAutoCreate));
         if ($this->_loaded) {
             $this->setKeyID($keyID);
         }
     } else {
         $this->registerError(PandraCore::$lastError);
     }
     return $this->_loaded;
 }
Esempio n. 2
0
 /**
  * Loads a SuperColumn for key
  *
  * Load will generate RuntimeException if parent column family has not been set (
  *
  * @param string $keyID row key
  * @param bool $colAutoCreate create columns in the object instance which have not been defined
  * @param int $consistencyLevel cassandra consistency level
  * @return bool loaded OK
  */
 public function load($keyID, $colAutoCreate = NULL, $consistencyLevel = NULL)
 {
     if ($this->_parentCF == NULL || !$this->_parentCF instanceof PandraSuperColumnFamily) {
         throw new RuntimeException('SuperColumn Requires a ColumnFamilySuper parent');
     }
     $this->_parentCF->checkCFState();
     $this->_loaded = FALSE;
     $result = PandraCore::getCFSlice($keyID, $this->_parentCF->getKeySpace(), $this->_parentCF->getName(), $this->getName(), PandraCore::getConsistency($consistencyLevel));
     if ($result !== NULL) {
         $this->init();
         $this->_loaded = $this->populate($result, $this->getAutoCreate($colAutoCreate));
         if ($this->_loaded) {
             $this->keyID = $keyID;
         }
     } else {
         $this->registerError(PandraCore::$lastError);
     }
     return $this->_loaded;
 }
Esempio n. 3
0
 /**
  * Loads an entire columnfamily by keyid
  * @param string $keyID optional row key
  * @param bool $colAutoCreate create columns in the object instance which have not been defined
  * @param int $consistencyLevel cassandra consistency level
  * @return bool loaded OK
  */
 public function load($keyID = NULL, $consistencyLevel = NULL)
 {
     if ($keyID === NULL) {
         $keyID = $this->getKeyID();
     }
     $ok = $this->pathOK($keyID);
     $this->setLoaded(FALSE);
     if ($ok) {
         $autoCreate = $this->getAutoCreate();
         $predicate = new cassandra_SlicePredicate();
         // if autocreate is turned on, get latest limited everything
         if ($autoCreate) {
             $predicate->slice_range = new cassandra_SliceRange();
             $predicate->slice_range->start = '';
             $predicate->slice_range->finish = '';
             $predicate->slice_range->count = $this->getLimit();
             $predicate->slice_range->reversed = TRUE;
             $result = PandraCore::getCFSlice($this->getKeySpace(), $keyID, new cassandra_ColumnParent(array('column_family' => $this->getName())), $predicate, PandraCore::getConsistency($consistencyLevel));
             // otherwise by defined columns (slice query)
         } else {
             $predicate->column_names = $this->getColumnNames();
             $result = PandraCore::getCFSliceMulti($this->getKeySpace(), array($keyID), new cassandra_ColumnParent(array('column_family' => $this->getName())), $predicate, PandraCore::getConsistency($consistencyLevel));
             $result = $result[$keyID];
         }
         if ($result !== NULL) {
             // Clean slate
             $this->destroyColumns();
             $this->destroyErrors();
             $this->init();
             // Try populating
             $this->setLoaded($this->populate($result, $autoCreate));
             // If we're loaded, use a new key
             if ($this->isLoaded()) {
                 $this->setKeyID($keyID);
             }
         } else {
             $this->registerError(PandraCore::$lastError);
         }
     }
     return $ok && $this->isLoaded();
 }
Esempio n. 4
0
 public function testSaveLoadDelete()
 {
     $keyID = 'PandraColumnTest';
     $keySpace = 'Keyspace1';
     $columnFamily = 'Standard1';
     $value = 'test value';
     $this->obj->setValue($value);
     // Save by explicitly setting  keyid/keyspace/cf
     $this->obj->setKeyID($keyID);
     $this->obj->setKeyspace($keySpace);
     $this->obj->setColumnFamilyName($columnFamily);
     $this->assertTrue($this->obj->isModified());
     $this->assertTrue($this->obj->save(), $this->obj->getLastError());
     //$column = array_pop(PandraCore::getCFSlice($keySpace, $keyID, $columnFamily))->column;
     $this->assertTrue($this->obj->load());
     $column = $this->obj;
     $this->assertTrue($column->value == $value && $column->name == $this->obj->getName() && empty(PandraCore::$lastError), PandraCore::$lastError);
     $this->obj->delete();
     $this->assertTrue($this->obj->isModified() && $this->obj->isDeleted());
     $this->assertTrue($this->obj->save(), $this->obj->getLastError());
     $columnParent = new cassandra_ColumnParent(array('column_family' => $columnFamily));
     $predicate = new PandraSlicePredicate('Column', array('column' => $this->obj->getName()));
     $result = PandraCore::getCFSlice($keySpace, $keyID, $columnParent, $predicate);
     $this->assertTrue(empty($result) && empty(PandraCore::$lastError), PandraCore::$lastError);
     // save using parent
     $this->obj->setKeyID(NULL);
     $this->obj->setKeyspace(NULL);
     $this->obj->setColumnFamilyName(NULL);
     $parent = clone $this->parent;
     // Wait so we don't have a delete/insert timestamp in the same second (32 bit systems)
     if (PHP_INT_SIZE == 4) {
         sleep(1);
     }
     $parent->setKeyID($keyID);
     $parent->setKeySpace($keySpace);
     $parent->setName($columnFamily);
     $this->obj->setParent($parent);
     $value = 'new test value';
     $this->obj->setValue($value);
     $this->assertTrue($this->obj->isModified());
     $this->assertTrue($this->obj->save(), $this->obj->getLastError());
     $columnParent = new cassandra_ColumnParent(array('column_family' => $columnFamily));
     $predicate = new PandraSlicePredicate('Column', array('column' => $this->obj->getName()));
     $column = array_pop(PandraCore::getCFSlice($keySpace, $keyID, $columnParent, $predicate))->column;
     $this->assertTrue($column->value == $value && ($column->name = $this->obj->name && empty(PandraCore::$lastError)), PandraCore::$lastError);
     $this->obj->delete();
     $this->assertTrue($this->obj->isModified() && $this->obj->isDeleted());
     $this->assertTrue($this->obj->save(), $this->obj->getLastError());
 }
        // Make sure the same two characters don't appear next to each other
        if ($r != $string[$i - 1]) {
            $string .= $r;
        }
    }
    // Return the string
    return $string;
}
// generate 5 timestamped supercolumns
for ($i = 1; $i <= 5; $i++) {
    $bp = new BlogPost(UUID::v1());
    $bp->column_title = rand_str();
    $bp->column_body = rand_str();
    $scf->addSuper($bp);
}
echo 'Saving SuperColumnFamily...<br>';
print_r($scf->toJSON());
$scf->save();
// get slice of the 5 most recent entries (count = 5, reversed = true)
echo '<br><br>Loading via SuperColumnFamily container...<br>';
$scNew = new PandraSuperColumnFamily($keyID, $ks, $cfName, PandraColumnContainer::TYPE_UUID);
$scNew->limit(5)->load();
echo '<br>Loaded...<br>';
print_r($scNew->toJSON());
echo '<br><br>Loading SuperColumn Slice...<br>';
$result = PandraCore::getCFSlice($ks, $keyID, new cassandra_ColumnParent(array('column_family' => $cfName)), new PandraSlicePredicate(PandraSlicePredicate::TYPE_RANGE, array('start' => '', 'finish' => '', 'count' => 5, 'reversed' => true)));
$scNew = new PandraSuperColumnFamily($keyID, $ks, $cfName, PandraColumnContainer::TYPE_UUID);
var_dump($result);
$scNew->populate($result);
echo '<br>Imported...<br>';
print_r($scNew->toJSON());
 /**
  * Loads an entire columnfamily by keyid
  * @param string $keyID optional row key
  * @param int $consistencyLevel cassandra consistency level
  * @return bool loaded OK
  */
 public function load($keyID = NULL, $consistencyLevel = NULL)
 {
     if ($keyID === NULL) {
         $keyID = $this->getKeyID();
     }
     $ok = $this->pathOK($keyID);
     $this->setLoaded(FALSE);
     if ($ok) {
         $autoCreate = $this->getAutoCreate();
         $predicate = new cassandra_SlicePredicate();
         // if autocreate is turned on, get latest limited everything
         if ($autoCreate) {
             $predicate->slice_range = new cassandra_SliceRange();
             $predicate->slice_range->start = '';
             $predicate->slice_range->finish = '';
             $predicate->slice_range->count = $this->getLimit();
             $predicate->slice_range->reversed = TRUE;
             $result = PandraCore::getCFSlice($this->getKeySpace(), $keyID, new cassandra_ColumnParent(array('column_family' => $this->getName())), $predicate, PandraCore::getConsistency($consistencyLevel));
             // otherwise by defined columns (slice query)
         } else {
             $predicate->column_names = $this->getColumnNames();
             $result = PandraCore::getCFSliceMulti($this->getKeySpace(), array($keyID), new cassandra_ColumnParent(array('column_family' => $this->getName())), $predicate, PandraCore::getConsistency($consistencyLevel));
             $result = $result[$keyID];
         }
         if ($result !== NULL) {
             $this->init();
             foreach ($result as $superColumn) {
                 $sc = $superColumn->super_column;
                 $newSuper = new PandraSuperColumn($this->typeConvert($sc->name, UUID::UUID_FMT_STR), NULL, NULL, $this, $this->getType());
                 if ($this->addSuper($newSuper)->populate($sc->columns, $autoCreate)) {
                     $this->setLoaded(TRUE);
                 } else {
                     $this->setLoaded(FALSE);
                     break;
                 }
             }
             if ($this->isLoaded()) {
                 $this->setKeyID($keyID);
             }
         } else {
             $this->registerError(PandraCore::$lastError);
         }
     }
     return $ok && $this->isLoaded();
 }
Esempio n. 7
0
 /**
  * Loads an entire columnfamily by keyid
  * @param string $keyID row key
  * @param bool $colAutoCreate create columns in the object instance which have not been defined
  * @param int $consistencyLevel cassandra consistency level
  * @return bool loaded OK
  */
 public function load($keyID, $colAutoCreate = NULL, $consistencyLevel = NULL)
 {
     $this->_loaded = FALSE;
     $result = PandraCore::getCFSlice($keyID, $this->getKeySpace(), $this->getName(), NULL, PandraCore::getConsistency($consistencyLevel));
     if ($result !== NULL) {
         $this->init();
         foreach ($result as $superColumn) {
             $sc = $superColumn->super_column;
             // @todo Should at least 1 successful super load really indicate a successful load state?
             $this->_loaded = $this->addSuper(new PandraSuperColumn($sc->name))->populate($sc->columns, $this->getAutoCreate($colAutoCreate));
         }
         if ($this->_loaded) {
             $this->setKeyID($keyID);
         }
     } else {
         $this->registerError(PandraCore::$lastError);
     }
     return $this->_loaded;
 }