Permalink
Browse files

minor api fixes and doc updates

  • Loading branch information...
1 parent 8d1c2e1 commit c8005286ba42af210556ed2395d36a1c809f790f @mjpearson committed Jan 26, 2010
View
@@ -33,6 +33,9 @@
define('PANDRA_DEFAULT_CREATE_MODE', TRUE);
+define('PANDRA_DEFAULT_CONSISTENCY', cassandra_ConsistencyLevel::ONE);
+
+
function _pandraAutoLoad($className) {
if (!preg_match("/^pandra/i", $className)) return;
View
@@ -94,6 +94,10 @@ public function setValue($value, $validate = TRUE) {
return TRUE;
}
+ /**
+ * returns the callback function value for this->value
+ * @return mixed result of callback eval
+ */
public function callbackvalue() {
$value = '';
eval('$value = '.$this->callback.'("'.$this->value.'");');
@@ -113,7 +117,15 @@ static public function cast(cassandra_Column $object, $parentCF = NULL) {
return $newObj;
}
- public function save($keyID, $keySpace, $columnFamily, $consistencyLevel = 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;
@@ -125,9 +137,9 @@ public function save($keyID, $keySpace, $columnFamily, $consistencyLevel = cassa
$ok = FALSE;
if ($this->_delete) {
- $ok = Pandra::deleteColumnPath($keySpace, $keyID, $columnPath, $this->bindTime(), $consistencyLevel);
+ $ok = Pandra::deleteColumnPath($keySpace, $keyID, $columnPath, $this->bindTime(), Pandra::getConsistency($consistencyLevel));
} else {
- $ok = Pandra::saveColumnPath($keySpace, $keyID, $columnPath, ($this->callback === NULL) ? $this->value : $this->callbackvalue(), $this->bindTime(), $consistencyLevel);
+ $ok = Pandra::saveColumnPath($keySpace, $keyID, $columnPath, ($this->callback === NULL) ? $this->value : $this->callbackvalue(), $this->bindTime(), Pandra::getConsistency($consistencyLevel));
}
if (!$ok) {
@@ -144,16 +156,29 @@ public function save($keyID, $keySpace, $columnFamily, $consistencyLevel = cassa
return $ok;
}
+ /**
+ * Creates an error entry in this column and propogate to parent
+ * @param string $errorStr error string
+ */
public function registerError($errorStr) {
- if (empty($errorStr)) return;
- array_push($this->errors, $errorStr);
- if ($this->_parentCF !== NULL) $this->_parentCF->registerError($errorStr);
+ if (!empty($errorStr)) {
+ array_push($this->errors, $errorStr);
+ if ($this->_parentCF !== NULL) $this->_parentCF->registerError($errorStr);
+ }
}
+ /**
+ * Grabs all errors for the column instance
+ * @return array all errors
+ */
public function getErrors() {
return $this->errors;
}
+ /**
+ * Grabs the last logged error
+ * @return string last error message
+ */
public function getLastError() {
if (count($this->errors)) {
return $this->errors[0];
@@ -170,25 +195,31 @@ public function reset() {
}
/**
- * Marks this column for deletion
+ * mutator, marks this column for deletion and sets modified
*/
public function delete() {
$this->_delete = TRUE;
$this->setModified();
}
/**
+ * Delete accessor
* @return bool Column is marked for deletion
*/
public function isDeleted() {
return ($this->_delete && $this->_modified);
}
+ /**
+ * Modified mutator
+ * @param bool $modified column is modified
+ */
public function setModified($modified = TRUE) {
$this->_modified = $modified;
}
/**
+ * Modified accessor
* @return bool column has been modified since instance construct/load
*/
public function isModified() {
@@ -14,7 +14,7 @@
abstract class PandraColumnContainer implements ArrayAccess {
/* @var this column families name (table name) */
- protected $name = NULL;
+ protected $_name = NULL;
/* @var string magic set/get prefixes for Columns */
const _columnNamePrefix = 'column_'; // magic __get/__set column prefix in column famliy
@@ -28,48 +28,76 @@
/* @var array complete list of errors for this object instance */
public $errors = array();
- /* var bool columnfamily marked for deletion */
+ /* @var bool columnfamily marked for deletion */
protected $_delete = FALSE;
+ /* @var bool container (columns) have been modified */
protected $_modified = FALSE;
+ /* @var bool container columns have been loaded from Cassandra */
protected $_loaded = FALSE;
+ /**
+ * Constructor, calls init()
+ */
public function __construct() {
$this->init();
}
+ /**
+ * accessor, container name
+ * @return string container name
+ */
public function getName() {
- return $this->name;
+ return $this->_name;
}
+ /**
+ * mutator, container name
+ * @param string $name new name
+ */
public function setName($name) {
- $this->name = $name;
+ $this->_name = $name;
}
/**
- * constructFields builds column objects via addColumn/addSuper methods
- * when defining hard schemas. It is called automatically by the constructor.
+ * init is is always called by the constructor. Child classes can implement
+ * constructor logic, schemas, defaults validators etc. here
* @return void
*/
public function init() {
-
}
+ /**
+ * mutator, modified
+ * @param bool $modified
+ */
protected function setModified($modified = TRUE) {
$this->_modified = $modified;
}
+ /**
+ * mutator, marks this column for deletion and sets modified
+ * @param bool $delete
+ */
protected function setDelete($delete) {
$this->setModified($delete);
$this->_delete = $delete;
}
+ /**
+ * accessor, delete
+ * @return bool container is marked for deletion
+ */
public function getDelete() {
return $this->_delete;
}
+ /**
+ * Creates an error entry in this column and propogate to parent
+ * @param string $errorStr error string
+ */
public function registerError($errorStr) {
if (empty($errorStr)) return;
$this->errors[] = $errorStr;
@@ -151,7 +179,6 @@ public function getColumn($colName) {
return $this->_columns[$colName];
}
return NULL;
- //return $this->__get($colName);
}
/**
@@ -178,11 +205,6 @@ public function listColumns() {
}
/**
- *
- * @return array cassandra_Column objects
- */
-
- /**
* Resets deletion states for the column family
*/
public function reset() {
@@ -193,6 +215,10 @@ public function reset() {
}
}
+ /**
+ * removes a column from the container (does not delete from Cassandra)
+ * @param string $colName column name
+ */
public function destroyColumn($colName) {
if (array_key_exists($colName, $this->_columns)) {
unset($this->_columns[$colName]);
@@ -214,7 +240,6 @@ public function populate($data, $colAutoCreate = PANDRA_DEFAULT_CREATE_MODE) {
if ($colValue instanceof cassandra_Column) {
if ($colAutoCreate || array_key_exists($colValue->name, $this->_columns)) {
- //$this->_columns[$colValue->column->name] = PandraColumn::cast($colValue->column, $this);
$this->_columns[$colValue->name] = PandraColumn::cast($colValue, $this);
}
@@ -292,21 +317,33 @@ public function getType() {
return constant(get_class($this)."::TYPE");
}
+ /**
+ * accessor, checks if container has been explicitly modified, or it sub columns
+ * @return <type>
+ */
public function isModified() {
foreach ($this->_columns as $column) {
if ($column->isModified()) return TRUE;
}
return $this->_modified;
}
- public function bindTimeModifiedColumns() {
+ /**
+ * Binds current time to all modified columns
+ * @param int $timeOverride optional timestamp, will default to time() if NULL
+ */
+ public function bindTimeModifiedColumns($timeOverride = NULL) {
foreach ($this->_columns as &$cObj) {
if ($cObj->isModified()) {
- $cObj->bindTime();
+ $cObj->bindTime($timeOverride);
}
}
}
+ /**
+ * Returns all columns which have been modified
+ * @return array array of modified columns
+ */
public function getModifiedColumns() {
$modColumns = array();
foreach ($this->_columns as &$cObj) {
@@ -73,7 +73,7 @@ public function isDeleted() {
* @param int $consistencyLevel cassandra consistency level
* @return bool loaded OK
*/
- public function load($keyID, $colAutoCreate = PANDRA_DEFAULT_CREATE_MODE, $consistencyLevel = cassandra_ConsistencyLevel::ONE) {
+ public function load($keyID, $colAutoCreate = PANDRA_DEFAULT_CREATE_MODE, $consistencyLevel = NULL) {
$this->_loaded = FALSE;
@@ -111,7 +111,7 @@ public function checkCFState() {
* @param int $consistencyLevel Cassandra consistency level
* @return bool save ok
*/
- public function save($consistencyLevel = cassandra_ConsistencyLevel::ONE) {
+ public function save($consistencyLevel = NULL) {
$this->checkCFState();
@@ -129,7 +129,7 @@ public function save($consistencyLevel = cassandra_ConsistencyLevel::ONE) {
foreach ($this->_columns as &$cObj) {
if (!$cObj->isModified()) continue;
- if (!$cObj->save($this->keyID, $this->getKeySpace(), $this->getName(), $consistencyLevel)) {
+ if (!$cObj->save($this->keyID, $this->getKeySpace(), $this->getName(), Pandra::getConsistency($consistencyLevel))) {
$this->registerError($cObj->getLastError());
return FALSE;
}
@@ -71,7 +71,7 @@ public function getSuper($superName) {
return $this->getColumn($superName);
}
- public function save($consistencyLevel = cassandra_ConsistencyLevel::ONE) {
+ public function save($consistencyLevel = NULL) {
if (!$this->isModified()) return FALSE;
@@ -82,7 +82,7 @@ public function save($consistencyLevel = cassandra_ConsistencyLevel::ONE) {
$columnPath = new cassandra_ColumnPath();
$columnPath->column_family = $this->getName();
- $ok = Pandra::deleteColumnPath($this->getKeySpace(), $this->keyID, $columnPath, time(), $consistencyLevel);
+ $ok = Pandra::deleteColumnPath($this->getKeySpace(), $this->keyID, $columnPath, time(), Pandra::getConsistency($consistencyLevel));
if (!$ok) $this->registerError(Pandra::$lastError);
} else {
@@ -105,11 +105,11 @@ public function save($consistencyLevel = cassandra_ConsistencyLevel::ONE) {
* @param int $consistencyLevel cassandra consistency level
* @return bool loaded OK
*/
- public function load($keyID, $colAutoCreate = PANDRA_DEFAULT_CREATE_MODE, $consistencyLevel = cassandra_ConsistencyLevel::ONE) {
+ public function load($keyID, $colAutoCreate = PANDRA_DEFAULT_CREATE_MODE, $consistencyLevel = NULL) {
$this->_loaded = FALSE;
- $result = Pandra::getCFSlice($keyID, $this->getKeySpace(), $this->getName(), NULL, $consistencyLevel);
+ $result = Pandra::getCFSlice($keyID, $this->getKeySpace(), $this->getName(), NULL, Pandra::getConsistency($consistencyLevel));
if ($result !== NULL) {
$this->init();
Oops, something went wrong.

0 comments on commit c800528

Please sign in to comment.