Permalink
Browse files

Refactored 'pandra' class to 'pandracore', system will become namespa…

…ced after debian/ubuntu 5.3 stable release.
  • Loading branch information...
1 parent 5f1d7c8 commit f33479ce222694e5cb37b7950d80edb5a75d071e @mjpearson committed Feb 6, 2010
View
@@ -22,7 +22,7 @@ function _pandraAutoLoad($className) {
if (!preg_match("/^pandra/i", $className)) return;
- if ($className != 'Pandra') $className = preg_replace('/^pandra/i', '', $className);
+ $className = preg_replace('/^pandra/i', '', $className);
// class path relative to config
$classPath = dirname(__FILE__)."/lib/";
@@ -14,8 +14,8 @@
error_reporting(E_ALL);
require_once(dirname(__FILE__).'/../config.php');
-if (!Pandra::connect('default', 'localhost')) {
- die(Pandra::$lastError);
+if (!PandraCore::connect('default', 'localhost')) {
+ die(PandraCore::$lastError);
}
// hard code the row key for this example
View
@@ -142,16 +142,16 @@ public function save($keyID, $keySpace, $columnFamily, $consistencyLevel = NULL)
$ok = FALSE;
if ($this->_delete) {
- $ok = Pandra::deleteColumnPath($keySpace, $keyID, $columnPath, $this->bindTime(), Pandra::getConsistency($consistencyLevel));
+ $ok = PandraCore::deleteColumnPath($keySpace, $keyID, $columnPath, $this->bindTime(), PandraCore::getConsistency($consistencyLevel));
} else {
- $ok = Pandra::saveColumnPath($keySpace, $keyID, $columnPath, ($this->callback === NULL) ? $this->value : $this->callbackvalue(), $this->bindTime(), Pandra::getConsistency($consistencyLevel));
+ $ok = PandraCore::saveColumnPath($keySpace, $keyID, $columnPath, ($this->callback === NULL) ? $this->value : $this->callbackvalue(), $this->bindTime(), PandraCore::getConsistency($consistencyLevel));
}
if (!$ok) {
- if (empty(Pandra::$errors)) {
+ if (empty(PandraCore::$errors)) {
$errorStr = 'Unkown Error';
} else {
- $errorStr = Pandra::$errors;
+ $errorStr = PandraCore::$errors;
}
$this->registerError($errorStr);
View
@@ -77,14 +77,14 @@ public function load($keyID, $colAutoCreate = NULL, $consistencyLevel = NULL) {
$this->_loaded = FALSE;
- $result = Pandra::getCFSlice($keyID, $this->getKeySpace(), $this->getName(), NULL, Pandra::getConsistency($consistencyLevel));
+ $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(Pandra::$lastError);
+ $this->registerError(PandraCore::$lastError);
}
return $this->_loaded;
@@ -122,14 +122,14 @@ public function save($consistencyLevel = NULL) {
$columnPath = new cassandra_ColumnPath();
$columnPath->column_family = $this->getName();
- $ok = Pandra::deleteColumnPath($this->getKeySpace(), $this->keyID, $columnPath, time());
- if (!$ok) $this->registerError(Pandra::$lastError);
+ $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(), Pandra::getConsistency($consistencyLevel))) {
+ if (!$cObj->save($this->keyID, $this->getKeySpace(), $this->getName(), PandraCore::getConsistency($consistencyLevel))) {
$this->registerError($cObj->getLastError());
return FALSE;
}
@@ -8,7 +8,7 @@
* @package Pandra
* @author Michael Pearson <pandra-support@phpgrease.net>
*/
-class Pandra {
+class PandraCore {
static public $lastError = '';
@@ -185,7 +185,7 @@ static public function loadConfigXML() {
public function deleteColumnPath($keySpace, $keyID, cassandra_ColumnPath $columnPath, $time, $consistencyLevel = NULL) {
try {
- $client = Pandra::getClient(TRUE);
+ $client = self::getClient(TRUE);
$client->remove($keySpace, $keyID, $columnPath, $time, self::getConsistency($consistencyLevel));
} catch (TException $te) {
self::$lastError = 'TException: '.$te->getMessage() . "\n";
@@ -196,7 +196,7 @@ public function deleteColumnPath($keySpace, $keyID, cassandra_ColumnPath $column
public function saveColumnPath($keySpace, $keyID, cassandra_ColumnPath $columnPath, $value, $time, $consistencyLevel = NULL) {
try {
- $client = Pandra::getClient(TRUE);
+ $client = self::getClient(TRUE);
$client->insert($keySpace, $keyID, $columnPath, $value, $time, self::getConsistency($consistencyLevel));
} catch (TException $te) {
self::$lastError = 'TException: '.$te->getMessage() . "\n";
@@ -207,7 +207,7 @@ public function saveColumnPath($keySpace, $keyID, cassandra_ColumnPath $columnPa
public function saveSuperColumn($keySpace, $keyID, $superCFName, $superName, array $columns, $consistencyLevel = NULL) {
try {
- $client = Pandra::getClient(TRUE);
+ $client = self::getClient(TRUE);
$scContainer = new cassandra_ColumnOrSuperColumn();
$scContainer->super_column = new cassandra_SuperColumn();
@@ -233,7 +233,7 @@ public function saveSuperColumn($keySpace, $keyID, $superCFName, $superName, arr
*/
public function getCFSlice($keyID, $keySpace, $cfName, $superName = NULL, $consistencyLevel = NULL) {
- $client = Pandra::getClient();
+ $client = self::getClient();
// build the column path
$columnParent = new cassandra_ColumnParent();
View
@@ -47,23 +47,23 @@ public function save($consistencyLevel = NULL) {
$columnPath->column_family = $this->_parentCF->getName();
$columnPath->super_column = $this->getName();
- $ok = Pandra::delete($this->keySpace, $this->keyID, $columnPath, time(), Pandra::getConsistency($consistencyLevel));
- if (!$ok) $this->registerError(Pandra::$lastError);
+ $ok = PandraCore::delete($this->keySpace, $this->keyID, $columnPath, time(), PandraCore::getConsistency($consistencyLevel));
+ if (!$ok) $this->registerError(PandraCore::$lastError);
return $ok;
}
} else {
$this->bindTimeModifiedColumns();
- $ok = Pandra::saveSuperColumn( $this->_parentCF->getKeySpace(),
+ $ok = PandraCore::saveSuperColumn( $this->_parentCF->getKeySpace(),
$this->_parentCF->keyID,
$this->_parentCF->getName(),
$this->getName(),
$this->getModifiedColumns(),
- Pandra::getConsistency($consistencyLevel));
+ PandraCore::getConsistency($consistencyLevel));
- if (!$ok) $this->registerError(Pandra::$lastError);
+ if (!$ok) $this->registerError(PandraCore::$lastError);
if ($ok) $this->reset();
return $ok;
@@ -89,14 +89,14 @@ public function load($keyID, $colAutoCreate = NULL, $consistencyLevel = NULL) {
$this->_loaded = FALSE;
- $result = Pandra::getCFSlice($keyID, $this->_parentCF->getKeySpace(), $this->_parentCF->getName(), $this->getName(), Pandra::getConsistency($consistencyLevel));
+ $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(Pandra::$lastError);
+ $this->registerError(PandraCore::$lastError);
}
return $this->_loaded;
@@ -79,14 +79,14 @@ public function save($consistencyLevel = NULL) {
$columnPath = new cassandra_ColumnPath();
$columnPath->column_family = $this->getName();
- $ok = Pandra::deleteColumnPath($this->getKeySpace(), $this->keyID, $columnPath, time(), Pandra::getConsistency($consistencyLevel));
- if (!$ok) $this->registerError(Pandra::$lastError);
+ $ok = PandraCore::deleteColumnPath($this->getKeySpace(), $this->keyID, $columnPath, time(), PandraCore::getConsistency($consistencyLevel));
+ if (!$ok) $this->registerError(PandraCore::$lastError);
} else {
foreach ($this->_columns as $colName => $superColumn) {
$ok = $superColumn->save();
if (!$ok) {
- $this->registerError(Pandra::$lastError);
+ $this->registerError(PandraCore::$lastError);
break;
}
}
@@ -106,7 +106,7 @@ public function load($keyID, $colAutoCreate = NULL, $consistencyLevel = NULL) {
$this->_loaded = FALSE;
- $result = Pandra::getCFSlice($keyID, $this->getKeySpace(), $this->getName(), NULL, Pandra::getConsistency($consistencyLevel));
+ $result = PandraCore::getCFSlice($keyID, $this->getKeySpace(), $this->getName(), NULL, PandraCore::getConsistency($consistencyLevel));
if ($result !== NULL) {
$this->init();
@@ -119,7 +119,7 @@ public function load($keyID, $colAutoCreate = NULL, $consistencyLevel = NULL) {
if ($this->_loaded) $this->setKeyID($keyID);
} else {
- $this->registerError(Pandra::$lastError);
+ $this->registerError(PandraCore::$lastError);
}
return $this->_loaded;
@@ -37,7 +37,7 @@ class PandraColumnFamilyTest extends PHPUnit_Framework_TestCase {
protected function setUp() {
$this->obj = new ColumnFamilyTestObject();
$this->obj->keyID = $this->_keyID;
- Pandra::connect('default', 'localhost');
+ PandraCore::connect('default', 'localhost');
}
/**
@@ -48,7 +48,7 @@ protected function setUp() {
*/
protected function tearDown() {
- Pandra::disconnectAll();
+ PandraCore::disconnectAll();
}
/**
@@ -1,13 +1,13 @@
<?php
require_once 'PHPUnit/Framework.php';
require_once(dirname(__FILE__).'/../../config.php');
-require_once dirname(__FILE__).'/../../lib/Pandra.class.php';
+require_once dirname(__FILE__).'/../../lib/Core.class.php';
/**
* Test class for Pandra.
* Generated by PHPUnit on 2010-01-09 at 11:52:23.
*/
-class PandraTest extends PHPUnit_Framework_TestCase {
+class PandraCoreTest extends PHPUnit_Framework_TestCase {
/**
* Sets up the fixture, for example, opens a network connection.
@@ -18,7 +18,7 @@ class PandraTest extends PHPUnit_Framework_TestCase {
* @access protected
*/
protected function setUp() {
- Pandra::connect('default', 'localhost');
+ PandraCore::connect('default', 'localhost');
}
/**
@@ -28,77 +28,77 @@ protected function setUp() {
* @access protected
*/
protected function tearDown() {
- Pandra::disconnect('default');
+ PandraCore::disconnect('default');
}
/**
* Get a modes list
*/
public function testSupportedModes() {
- $modes = Pandra::getSupportedModes();
+ $modes = PandraCore::getSupportedModes();
$this->assertTrue(is_array($modes) && !empty($modes));
}
/**
* Set Read Mode
*/
public function testSetReadMode() {
- $supportedModes = Pandra::getSupportedModes();
+ $supportedModes = PandraCore::getSupportedModes();
foreach ($supportedModes as $mode) {
- Pandra::setReadMode($mode);
- $this->assertEquals(Pandra::getReadMode(), $mode);
+ PandraCore::setReadMode($mode);
+ $this->assertEquals(PandraCore::getReadMode(), $mode);
}
}
/**
* Set Write Mode
*/
public function testSetWriteMode() {
- $supportedModes = Pandra::getSupportedModes();
+ $supportedModes = PandraCore::getSupportedModes();
foreach ($supportedModes as $mode) {
- Pandra::setWriteMode($mode);
- $this->assertEquals(Pandra::getWriteMode(), $mode);
+ PandraCore::setWriteMode($mode);
+ $this->assertEquals(PandraCore::getWriteMode(), $mode);
}
}
/**
* Set active node to named 'default', as well as unknown 'NOP'
*/
public function testSetActiveNode() {
- $this->assertTrue(Pandra::setActiveNode('default'));
- $this->assertFalse(Pandra::setActiveNode('NOP'));
+ $this->assertTrue(PandraCore::setActiveNode('default'));
+ $this->assertFalse(PandraCore::setActiveNode('NOP'));
}
/**
* @todo Implement testDisconnect().
*/
public function testDisconnect() {
- $this->assertTrue(Pandra::disconnect('default'));
+ $this->assertTrue(PandraCore::disconnect('default'));
}
/**
* Disconnect all nodes
*/
public function testDisconnectAll() {
- $this->assertTrue(Pandra::disconnectAll());
+ $this->assertTrue(PandraCore::disconnectAll());
}
/**
* Connect to a good and bad host
*/
public function testConnect() {
- $this->assertTrue(Pandra::connect('default', 'localhost'));
- $this->assertFalse(Pandra::connect('default_BAD', 'ih-opethishostdoesntexist'));
+ $this->assertTrue(PandraCore::connect('default', 'localhost'));
+ $this->assertFalse(PandraCore::connect('default_BAD', 'ih-opethishostdoesntexist'));
}
/**
* Get client for all supported modes
*/
public function testGetClient() {
- $supportedModes = Pandra::getSupportedModes();
+ $supportedModes = PandraCore::getSupportedModes();
foreach ($supportedModes as $mode) {
- Pandra::setReadMode($mode);
- $client = Pandra::getClient();
+ PandraCore::setReadMode($mode);
+ $client = PandraCore::getClient();
$this->assertEquals(get_class($client), 'CassandraClient', "Bad Client (mode $mode)");
}
}
@@ -107,7 +107,7 @@ public function testGetClient() {
* Describe a named keyspace
*/
public function testGetKeyspace() {
- $ks = Pandra::getKeyspace('Keyspace1');
+ $ks = PandraCore::getKeyspace('Keyspace1');
$this->assertTrue(is_array($ks) && !empty($ks));
@@ -123,7 +123,7 @@ public function testGetKeyspace() {
* @todo Implement testLoadConfigXML().
*/
public function testLoadConfigXML() {
- $config = Pandra::loadConfigXML();
+ $config = PandraCore::loadConfigXML();
$this->assertTrue(get_class($config) == 'SimpleXMLElement');
}
@@ -155,9 +155,9 @@ public function getSetConsistency() {
$newC = cassandra_ConsistencyLevel::QUORUM;
- Pandra::setConsistency($newC);
- $this->assertTrue(Pandra::getConsistency() == $newC);
- $this->assertTrue(Pandra::getConsistency(cassandra_ConsistencyLevel::ONE) == cassandra_ConsistencyLevel::ONE);
+ PandraCore::setConsistency($newC);
+ $this->assertTrue(PandraCore::getConsistency() == $newC);
+ $this->assertTrue(PandraCore::getConsistency(cassandra_ConsistencyLevel::ONE) == cassandra_ConsistencyLevel::ONE);
}
}
?>
@@ -46,7 +46,7 @@ class PandraSuperColumnFamilyTest extends PHPUnit_Framework_TestCase {
protected function setUp() {
$this->obj = new TestCFSuper();
$this->obj->keyID = $this->_keyID;
- Pandra::connect('default', 'localhost');
+ PandraCore::connect('default', 'localhost');
}
/**
@@ -56,7 +56,7 @@ protected function setUp() {
* @access protected
*/
protected function tearDown() {
- Pandra::disconnectAll();
+ PandraCore::disconnectAll();
}
public function testAddGetColumn() {
Oops, something went wrong.

0 comments on commit f33479c

Please sign in to comment.