/** * 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; }
/** * Save this column family and any modified columns to Cassandra * @param cassandra_ColumnPath $columnPath * @param int $consistencyLevel Cassandra consistency level * @return bool save ok */ public function save($consistencyLevel = NULL) { $this->checkCFState(); $ok = FALSE; if ($this->getDelete()) { $columnPath = new cassandra_ColumnPath(); $columnPath->column_family = $this->getName(); $ok = PandraCore::deleteColumnPath($this->getKeySpace(), $this->keyID, $columnPath, time()); if (!$ok) { $this->registerError(PandraCore::$lastError); } } else { foreach ($this->_columns as &$cObj) { if (!$cObj->isModified()) { continue; } if (!$cObj->save($this->keyID, $this->getKeySpace(), $this->getName(), PandraCore::getConsistency($consistencyLevel))) { $this->registerError($cObj->getLastError()); return FALSE; } } $ok = TRUE; } if ($ok) { $this->reset(); } return $ok; }
public function getSetConsistency() { $newC = cassandra_ConsistencyLevel::QUORUM; PandraCore::setConsistency($newC); $this->assertTrue(PandraCore::getConsistency() == $newC); $this->assertTrue(PandraCore::getConsistency(cassandra_ConsistencyLevel::ONE) == cassandra_ConsistencyLevel::ONE); }
/** * Saves this individual column path * @param string $keyID row key * @param sring $keySpace key space * @param string $columnFamily column family name * @param int $consistencyLevel cassandra save consistency level * @return bool save ok */ public function save($keyID, $keySpace, $columnFamily, $consistencyLevel = NULL) { if (!$this->isModified()) { return TRUE; } // Build the column path for modifying this individual column $columnPath = new cassandra_ColumnPath(); $columnPath->column_family = $columnFamily; $columnPath->column = $this->name; $ok = FALSE; if ($this->_delete) { $ok = PandraCore::deleteColumnPath($keySpace, $keyID, $columnPath, $this->bindTime(), PandraCore::getConsistency($consistencyLevel)); } else { $ok = PandraCore::saveColumnPath($keySpace, $keyID, $columnPath, $this->callback === NULL ? $this->value : $this->callbackvalue(), $this->bindTime(), PandraCore::getConsistency($consistencyLevel)); } if (!$ok) { if (empty(PandraCore::$errors)) { $errorStr = 'Unkown Error'; } else { $errorStr = PandraCore::$errors; } $this->registerError($errorStr); } if ($ok) { $this->reset(); } return $ok; }
/** * Loads a SuperColumn for key * * @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->getColumnFamilyName(), 'super_column' => $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), $predicate, new cassandra_ColumnParent(array('column_family' => $this->getColumnFamilyName(), 'super_column' => $this->getName())), PandraCore::getConsistency($consistencyLevel)); $result = $result[$keyID]; } if (!empty($result)) { $this->init(); $this->setLoaded($this->populate($result, $autoCreate)); if ($this->isLoaded()) { $this->setKeyID($keyID); } } else { $this->registerError(PandraCore::$lastError); } } return $ok && $this->isLoaded(); }
/** * 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(); }
/** * Saves this individual column path, where a parent has been set (setParent()) keyid, keyspace, columnfamily or supercolumn * will be inherited for the save. * @return bool save ok */ public function save($consistencyLevel = NULL) { if (!$this->isModified()) { $this->registerError("Column " . $this->name . " is not modified"); return FALSE; } // Build the column path for modifying this individual column $columnPath = new cassandra_ColumnPath(); $columnPath->column_family = $this->getColumnFamilyName(); $columnPath->super_column = $this->getSuperColumnName(); $columnPath->column = $this->getName(); $ok = FALSE; if ($this->isDeleted()) { $ok = PandraCore::deleteColumnPath($this->getKeySpace(), $this->getKeyID(), $columnPath, $this->bindTime(), PandraCore::getConsistency($consistencyLevel)); } else { $ok = PandraCore::saveColumnPath($this->getKeySpace(), $this->getKeyID(), $columnPath, $this->callbackvalue(), $this->bindTime(), PandraCore::getConsistency($consistencyLevel)); } if (!$ok) { if (empty(PandraCore::$lastError)) { $errorStr = 'Unknown Error'; } else { $errorStr = PandraCore::$lastError; } $this->registerError($errorStr); } if ($ok) { $this->reset(); } return $ok; }
/** * Save this column family and any modified columns to Cassandra * @param cassandra_ColumnPath $columnPath * @param int $consistencyLevel Cassandra consistency level * @return bool save ok */ public function save($consistencyLevel = NULL) { $ok = $this->pathOK(); if ($ok) { if ($this->getDelete()) { $columnPath = new cassandra_ColumnPath(); $columnPath->column_family = $this->getName(); $ok = PandraCore::deleteColumnPath($this->getKeySpace(), $this->getKeyID(), $columnPath, NULL, PandraCore::getConsistency($consistencyLevel)); if (!$ok) { $this->registerError(PandraCore::$lastError); } } else { // @todo have this use thrift batch_insert method in core $modifiedColumns = $this->getModifiedColumns(); foreach ($modifiedColumns as &$cObj) { if (!$cObj->save(PandraCore::getConsistency($consistencyLevel))) { $this->registerError($cObj->getLastError()); return FALSE; } } $ok = TRUE; } if ($ok) { $this->reset(); } } return $ok; }
/** * 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; }