Skip to content
Browse files

0.7 fixes and namespacing

  • Loading branch information...
1 parent e9a1d35 commit fd77a0af57ec1cca4350bafd6e71ec9c47e669ab @mjpearson committed Feb 6, 2011
View
25 examples/uuid_columnfamily.class.php
@@ -5,24 +5,25 @@
* <ColumnFamily CompareWith="TimeUUIDType" Name="StandardByUUID1"/>
*
*/
-
+error_reporting(E_ALL);
+ini_set('display_errors', true);
require_once('../config.php');
-PandraCore::connect('default', 'localhost');
+Pandra\Core::connect('default', 'localhost');
// ---- TIMEUUID ColumnFamily Example
$ks = 'Keyspace1';
$cfName = 'StandardByUUID1';
$keyID = 'PandraTestUUID1';
-$cf = new PandraColumnFamily($keyID,
+$cf = new Pandra\ColumnFamily($keyID,
$ks,
$cfName,
- PandraColumnFamily::TYPE_UUID);
+ Pandra\ColumnFamily::TYPE_UUID);
// generate 5 timestamped columns
for ($i = 1; $i <= 5; $i++) {
- $cf->addColumn(UUID::v1())->setValue($i);
+ $cf->addColumn(Pandra\UUID::v1())->setValue($i);
}
echo 'Saving...<br>';
@@ -31,22 +32,22 @@
// get slice of the 5 most recent entries (count = 5, reversed = true)
echo '<br><br>Loading via CF container...<br>';
-$cfNew = new PandraColumnFamily($keyID,
+$cfNew = new Pandra\ColumnFamily($keyID,
$ks,
$cfName,
- PandraColumnFamily::TYPE_UUID);
+ Pandra\ColumnFamily::TYPE_UUID);
$cfNew->limit(5)->load();
echo '<br>Loaded...<br>';
print_r($cfNew->toJSON());
echo '<br><br>Loading Slice...<br>';
-$result = PandraCore::getCFSlice($ks,
+$result = Pandra\Core::getCFSlice($ks,
$keyID,
new cassandra_ColumnParent(array(
'column_family' => $cfName
)),
- new PandraSlicePredicate(
- PandraSlicePredicate::TYPE_RANGE,
+ new Pandra\SlicePredicate(
+ Pandra\SlicePredicate::TYPE_RANGE,
array('start' => '',
'finish' => '',
'count' => 5,
@@ -55,10 +56,10 @@
var_dump($result);
-$cfNew = new PandraColumnFamily($keyID,
+$cfNew = new Pandra\ColumnFamily($keyID,
$ks,
$cfName,
- PandraColumnFamily::TYPE_UUID);
+ Pandra\ColumnFamily::TYPE_UUID);
$cfNew->populate($result);
echo '<br>Imported...<br>';
View
3 lib/Column.class.php
@@ -600,5 +600,4 @@ public function setModified($modified = TRUE) {
public function getModified() {
return $this->_modified;
}
-}
-?>
+}
View
12 lib/ColumnContainer.class.php
@@ -171,7 +171,7 @@ public function getKeySpace() {
public function setKeyID($keyID, $validate = TRUE) {
if ($validate && !empty($this->_typeDefKey)) {
$errors = array();
- if (!PandraValidator::check($keyID, $this->getName().' KEY ('.get_class($this).')', $this->_typeDefKey, $errors)) {
+ if (!Validator::check($keyID, $this->getName().' KEY ('.get_class($this).')', $this->_typeDefKey, $errors)) {
$lastError = $errors[0];
$this->registerError($lastError);
if ($this->_parent !== NULL) {
@@ -195,15 +195,15 @@ public function getKeyID() {
/**
* Sets the validator(s) for key changes
- * @param array $typeDefs PandraValidator primitive or complex types
+ * @param array $typeDefs Validator primitive or complex types
*/
public function setKeyValidator($typeDefs) {
if (empty($typeDefs)) return;
$typeDefs = (array) $typeDefs;
foreach ($typeDefs as $typeDef) {
- if (!PandraValidator::exists($typeDef)) {
+ if (!Validator::exists($typeDef)) {
throw new RuntimeException("$typeDef is not a Validator type");
}
}
@@ -342,7 +342,7 @@ public function offsetUnset($columnName) {
* @return mixed column value
*/
public function offsetGet($columnName) {
- if ($columnName instanceof PandraClause || $columnName instanceof PandraQuery) {
+ if ($columnName instanceof Clause || $columnName instanceof PandraQuery) {
return $this->getColumn($columnName);
}
return $this->__get($columnName);
@@ -580,7 +580,7 @@ public function addColumn($columnName, $typeDef = array(), $callbackOnSave = NUL
/**
* Adds a column object to this column container, overwrites existing column (context helper)
- * @param PandraSuperColumn $columnObj
+ * @param SuperColumn $columnObj
*/
public function addColumnObj(Column $columnObj) {
if ($columnObj->getName() === NULL) throw new RuntimeException('Column has no name');
@@ -601,7 +601,7 @@ public function getColumn($columnMatch) {
return $columnMatch;
// Extract matching named columns based on clause
- } elseif ($columnMatch instanceof PandraClause) {
+ } elseif ($columnMatch instanceof Clause) {
$matches = array();
foreach ($this->_columns as $columnName => &$column) {
View
37 lib/ColumnFamily.class.php
@@ -39,21 +39,21 @@ public function load($keyID = NULL, $consistencyLevel = NULL) {
$autoCreate = $this->getAutoCreate();
- $predicate = new cassandra_SlicePredicate();
+ $predicate = new \cassandra_SlicePredicate();
// if autocreate is turned on, get latest limited everything
if ($autoCreate) {
- $predicate->slice_range = new cassandra_SliceRange();
+ $predicate->slice_range = new \cassandra_SliceRange();
$predicate->slice_range->start = $this->getStart();
$predicate->slice_range->finish = $this->getFinish();
$predicate->slice_range->count = $this->getLimit();
$predicate->slice_range->reversed = $this->getReversed();
- $result = PandraCore::getCFSlice(
+ $result = Core::getCFSlice(
$this->getKeySpace(),
$keyID,
- new cassandra_ColumnParent(
+ new \cassandra_ColumnParent(
array(
'column_family' => $this->getName())),
$predicate,
@@ -64,10 +64,10 @@ public function load($keyID = NULL, $consistencyLevel = NULL) {
$predicate->column_names = $this->getColumnNames();
- $result = PandraCore::getCFSliceMulti(
+ $result = Core::getCFSliceMulti(
$this->getKeySpace(),
array($keyID),
- new cassandra_ColumnParent(
+ new \cassandra_ColumnParent(
array(
'column_family' => $this->getName())),
$predicate,
@@ -88,7 +88,7 @@ public function load($keyID = NULL, $consistencyLevel = NULL) {
// If we're loaded, use a new key
if ($this->isLoaded()) $this->setKeyID($keyID);
} else {
- $this->registerError(PandraCore::$lastError);
+ $this->registerError(Core::$lastError);
}
}
@@ -97,7 +97,7 @@ public function load($keyID = NULL, $consistencyLevel = NULL) {
/**
* Save this column family and any modified columns to Cassandra
- * @param cassandra_ColumnPath $columnPath
+ * @param \cassandra_ColumnPath $columnPath
* @param int $consistencyLevel Cassandra consistency level
* @return bool save ok
*/
@@ -108,17 +108,17 @@ public function save($consistencyLevel = NULL) {
if ($ok) {
if ($this->getDelete()) {
- $columnPath = new cassandra_ColumnPath();
+ $columnPath = new \cassandra_ColumnPath();
$columnPath->column_family = $this->getName();
- $ok = PandraCore::deleteColumnPath(
+ $ok = Core::deleteColumnPath(
$this->getKeySpace(),
$this->getKeyID(),
$columnPath,
NULL,
$consistencyLevel);
- if (!$ok) $this->registerError(PandraCore::$lastError);
+ if (!$ok) $this->registerError(Core::$lastError);
} else {
$deletions = array();
@@ -139,22 +139,21 @@ public function save($consistencyLevel = NULL) {
if ($cObj->isDeleted()) {
$deletions[] = $cObj->getName();
} else {
- $sc = new cassandra_ColumnOrSuperColumn(array('column' => $cObj));
- $ptr[] = new cassandra_Mutation(array('column_or_supercolumn' => $sc));
+ $sc = new \cassandra_ColumnOrSuperColumn(array('column' => $cObj));
+ $ptr[] = new \cassandra_Mutation(array('column_or_supercolumn' => $sc));
}
}
if (!empty($deletions)) {
- $p = new PandraSlicePredicate(PandraSlicePredicate::TYPE_COLUMNS, $deletions);
- $sd = new cassandra_Deletion(array('timestamp' => PandraCore::getTime(), 'predicate' => $p));
- $ptr[] = new cassandra_Mutation(array('deletion' => $sd));
+ $p = new SlicePredicate(SlicePredicate::TYPE_COLUMNS, $deletions);
+ $sd = new \cassandra_Deletion(array('timestamp' => Core::getTime(), 'predicate' => $p));
+ $ptr[] = new \cassandra_Mutation(array('deletion' => $sd));
}
- $ok = PandraCore::batchMutate($this->getKeySpace(), $map, $consistencyLevel);
+ $ok = Core::batchMutate($this->getKeySpace(), $map, $consistencyLevel);
}
if ($ok) $this->reset();
}
return $ok;
}
-}
-?>
+}
View
1 lib/Core.class.php
@@ -444,6 +444,7 @@ static public function getAPCAvailable() {
* get current working node, recursive, trims disconnected clients
* @param bool $writeMode optional get the write mode client
* @param string $keySpace optional keyspace where auth has been defined
+ * @return \CassandraClient Thrift client
*/
static public function getClient($writeMode = FALSE, $keySpace = DEFAULT_POOL_NAME) {
View
12 lib/SlicePredicate.class.php
@@ -53,8 +53,8 @@ public function setSlicePredicateType($slicePredicateType) {
$this->slice_range = NULL;
} else {
$msg = 'Unsupported Predicate Type';
- PandraLog::crit($msg);
- throw new RuntimeException($msg);
+ Log::crit($msg);
+ throw new \RuntimeException($msg);
}
}
@@ -65,13 +65,13 @@ public function buildPredicateAttribute(array $predicateAttribute) {
if (empty($predicateAttribute)) {
// Warn that there's no point in building an empty predicate
- PandraLog::warning('Empty Predicate : an empty result set will be returned');
+ Log::warning('Empty Predicate : an empty result set will be returned');
}
$this->column_names = $predicateAttribute;
} elseif ($this->_slicePredicateType === self::TYPE_RANGE) {
$this->column_names = NULL;
- $this->slice_range = new cassandra_SliceRange(
+ $this->slice_range = new \cassandra_SliceRange(
array('start' => '',
'finish' => '',
'reversed' => false,
@@ -83,8 +83,8 @@ public function buildPredicateAttribute(array $predicateAttribute) {
}
} else {
$msg = 'Unsupported Predicate Type';
- PandraLog::crit($msg);
- throw new RuntimeException($msg);
+ Log::crit($msg);
+ throw new \RuntimeException($msg);
}
}
}
View
3 lib/logging/Log.class.php
@@ -176,5 +176,4 @@ static public function __callStatic($class, $args) {
self::logPriorityMessage($priority, array_pop($args));
}
}
-}
-?>
+}
View
3 lib/logging/Logger.interface.php
@@ -44,5 +44,4 @@ public function isPriorityLogger($priority);
* @param string $message Message to log
*/
public function execute($priority, $message);
-}
-?>
+}
View
5 lib/logging/LoggerSTDOUT.class.php
@@ -10,6 +10,8 @@
* @version 0.2.1
* @package pandra
*/
+namespace Pandra;
+
class LoggerSTDOUT implements Logger {
private $_isOpen = true;
@@ -48,5 +50,4 @@ public function execute($priority, $message) {
return TRUE;
}
}
-}
-?>
+}
View
5 lib/logging/LoggerSyslog.class.php
@@ -11,6 +11,8 @@
* @version 0.2.1
* @package pandra
*/
+namespace Pandra;
+
class LoggerSyslog implements Logger {
private $_isOpen = FALSE;
@@ -84,5 +86,4 @@ public function close() {
public function __destruct() {
$this->close();
}
-}
-?>
+}
View
10 lib/uuid/UUID.class.php
@@ -37,7 +37,7 @@ public static function auto() {
$tokens = explode('.', $fname);
$className = preg_replace('/^'.(self::$_pluginPfx).'/', '', $tokens[0]);
if (self::register($className)) {
- PandraLog::info('Registered UUID class '.$className);
+ Log::info('Registered UUID class '.$className);
$ok = TRUE;
break;
}
@@ -49,7 +49,7 @@ private static function bridge($function) {
if (self::$_pluginRef !== NULL) {
return call_user_func(array(self::$_pluginRef, $function));
}
- throw new RuntimeException('No UUID Plugins initialised');
+ throw new \RuntimeException('No UUID Plugins initialised');
}
public static function generate() {
@@ -69,8 +69,7 @@ public static function v5() {
}
public static function register($pluginName) {
- $className = 'Pandra'.self::$_pluginPfx.$pluginName;
-
+ $className = __NAMESPACE__.'\\'.self::$_pluginPfx.$pluginName;
if (class_exists($className) && call_user_func(array($className, 'isCapable'))) {
self::$_pluginRef = $className;
return TRUE;
@@ -105,5 +104,4 @@ public static function validUUID($uuidStr) {
public static function isBinary($uuid) {
return preg_match('/((?![\x20-\x7E]).)/', $uuid);
}
-}
-?>
+}
View
3 lib/uuid/UUIDPlugin.interface.php
@@ -43,5 +43,4 @@ public static function v4();
* @return string
*/
public static function v5();
-}
-?>
+}
View
5 lib/uuid/UUIDPluginZNative.class.php
@@ -358,7 +358,4 @@ static private function conv_string2binary($src) {
$byte = self::conv_string2byte($src);
return self::conv_byte2binary($byte);
}
-
-
-}
-?>
+}
View
33 tests/lib/PandraColumnFamilyTest.class.php → tests/lib/ColumnFamilyTest.php
@@ -1,9 +1,10 @@
<?php
+namespace Pandra;
+
require_once 'PHPUnit/Framework.php';
require_once(dirname(__FILE__).'/../../config.php');
-
-class ColumnFamilyTestObject extends PandraColumnFamily {
+class ColumnFamilyTestObject extends ColumnFamily {
public function init() {
$this->setKeySpace('Keyspace1');
@@ -15,17 +16,17 @@ public function init() {
}
/**
- * Test class for PandraColumnFamily.
+ * Test class for ColumnFamily.
* Generated by PHPUnit on 2010-01-09 at 11:52:22.
*/
-class PandraColumnFamilyTest extends PHPUnit_Framework_TestCase {
+class ColumnFamilyTest extends \PHPUnit_Framework_TestCase {
/**
- * @var PandraColumnFamily
+ * @var ColumnFamily
* @access protected
*/
protected $obj;
- private $_keyID = 'PandraCFTest';
+ private $_keyID = 'CFTest';
/**
* Sets up the fixture, for example, opens a network connection.
@@ -36,7 +37,7 @@ class PandraColumnFamilyTest extends PHPUnit_Framework_TestCase {
protected function setUp() {
$this->obj = new ColumnFamilyTestObject($this->_keyID);
//$this->obj->setKeyID($this->_keyID);
- PandraCore::connect('default', 'localhost');
+ Core::connect('default', 'localhost');
}
/**
@@ -46,7 +47,7 @@ protected function setUp() {
* @access protected
*/
protected function tearDown() {
- PandraCore::disconnectAll();
+ Core::disconnectAll();
}
public function testSaveLoadDelete() {
@@ -65,7 +66,7 @@ public function testSaveLoadDelete() {
}
public function testSaveLoadDeleteUUID() {
- $cf = new PandraColumnFamily($this->_keyID, 'Keyspace1', 'StandardByUUID1', PandraColumnContainer::TYPE_UUID);
+ $cf = new ColumnFamily($this->_keyID, 'Keyspace1', 'StandardByUUID1', ColumnContainer::TYPE_UUID);
$column = $cf->addColumn(UUID::v1());
$uuidName = UUID::toStr($column->getName());
@@ -76,13 +77,13 @@ public function testSaveLoadDeleteUUID() {
unset($cf);
- $newCF = new PandraColumnFamily($this->_keyID, 'Keyspace1', 'StandardByUUID1', PandraColumnContainer::TYPE_UUID);
+ $newCF = new ColumnFamily($this->_keyID, 'Keyspace1', 'StandardByUUID1', ColumnContainer::TYPE_UUID);
$newCF->load();
$this->assertEquals($cValue, $newCF[$uuidName]);
}
public function testSetKeyValidated() {
- $cf = new PandraColumnFamily($this->_keyID, 'Keyspace1', 'StandardByUUID1', PandraColumnContainer::TYPE_UUID);
+ $cf = new ColumnFamily($this->_keyID, 'Keyspace1', 'StandardByUUID1', ColumnContainer::TYPE_UUID);
$cf->setKeyValidator(array('uuid'));
$newKey = 'abc123';
@@ -168,7 +169,7 @@ public function testAddGetColumn() {
// CF
$column = $this->obj->addColumn($columnName);
- $this->assertTrue($column instanceof PandraColumn);
+ $this->assertTrue($column instanceof Column);
$column = $this->obj->getColumn($columnName);
$this->assertTrue($column->name == $columnName, 'Column name mismatch, expected '.$columnName.', received ',$column->name);
@@ -210,7 +211,11 @@ public function testNotations() {
// test unset
unset($this->obj['column1']);
- $this->assertFalse($this->obj->getColumn('column1') instanceof PandraColumn);
+ $this->assertFalse($this->obj->getColumn('column1') instanceof Column);
}
+
+ public function testTruncate() {
+ $this->obj->truncate();
+ }
+
}
-?>

0 comments on commit fd77a0a

Please sign in to comment.
Something went wrong with that request. Please try again.