Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rely on exceptions, except where mdb will return a PEAR_Error

  • Loading branch information...
commit 84e55b9666877f305bc004a3d9d8fbbf5d31dec2 1 parent 484bb0a
@CloCkWeRX CloCkWeRX authored
Showing with 24 additions and 80 deletions.
  1. +19 −75 RDF/Model/Memory.php
  2. +5 −5 RDF/Store/MDB.php
View
94 RDF/Model/Memory.php
@@ -409,9 +409,6 @@ function find(RDF_Resource $subject = null, RDF_Resource $predicate = null, RDF_
$t = $this->triples[$this->index[$subject->getLabel()][$i]];
if ($this->matchStatement($t, $subject, $predicate, $object)) {
$result = $res->add($t);
- if (PEAR::isError($result)) {
- return $result;
- }
}
}
} else {
@@ -419,9 +416,6 @@ function find(RDF_Resource $subject = null, RDF_Resource $predicate = null, RDF_
foreach($this->triples as $value) {
if ($this->matchStatement($value, $subject, $predicate, $object)) {
$result = $res->add($value);
- if (PEAR::isError($result)) {
- return $result;
- }
}
}
}
@@ -459,9 +453,6 @@ function findRegex($subject_regex, $predicate_regex, $object_regex)
&& ($object_regex == null || preg_match($object_regex, $value->obj->getLabel()))
) {
$result = $res->add($value);
- if (PEAR::isError($result)) {
- return $result;
- }
}
}
@@ -492,9 +483,6 @@ function findVocabulary($vocabulary)
foreach($this->triples as $value) {
if (RDF_Util::getNamespace($value->getPredicate()) == $vocabulary) {
$result = $res->add($value);
- if (PEAR::isError($result)) {
- return $result;
- }
}
}
return $res;
@@ -516,9 +504,6 @@ function findVocabulary($vocabulary)
function findFirstMatchingStatement($subject, $predicate, $object)
{
$res = $this->find($subject, $predicate, $object);
- if (PEAR::isError($res)) {
- return $res;
- }
if ($res->size() != 0) {
return $res->triples[0];
} else {
@@ -541,9 +526,6 @@ function findFirstMatchingStatement($subject, $predicate, $object)
function findCount($subject, $predicate, $object)
{
$res = $this->find($subject, $predicate, $object);
- if (PEAR::isError($res)) {
- return $res;
- }
return $res->size();
}
@@ -569,24 +551,18 @@ function replace(RDF_Resource $subject = null, RDF_Resource $predicate = null, R
foreach($this->triples as $key => $value) {
$result = $this->triples[$key]->subj->equals($subject);
- if (PEAR::isError($result)) {
- return $result;
- }
+
if ($result) {
$this->triples[$key]->subj = $replacement;
$this->indexed = false;
}
$result = $this->triples[$key]->pred->equals($predicate);
- if (PEAR::isError($result)) {
- return $result;
- }
+
if ($result) {
$this->triples[$key]->pred = $replacement;
}
$result = $this->triples[$key]->obj->equals($object);
- if (PEAR::isError($result)) {
- return $result;
- }
+
if ($result) {
$this->triples[$key]->obj = $replacement;
}
@@ -608,9 +584,7 @@ function matchStatement($statement, $subject, $predicate, $object)
{
if ($subject) {
$result = $statement->subj->equals($subject);
- if (PEAR::isError($result)) {
- return $result;
- }
+
if (!$result) {
return false;
}
@@ -618,9 +592,7 @@ function matchStatement($statement, $subject, $predicate, $object)
if ($predicate) {
$result = $statement->pred->equals($predicate);
- if (PEAR::isError($result)) {
- return $result;
- }
+
if (!$result) {
return false;
}
@@ -628,9 +600,7 @@ function matchStatement($statement, $subject, $predicate, $object)
if ($object) {
$result = $statement->obj->equals($object);
- if (PEAR::isError($result)) {
- return $result;
- }
+
if (!$result) {
return false;
}
@@ -654,17 +624,11 @@ function getUniqueResourceURI($prefix)
while (true) {
$uri = $this->getBaseURI() . $prefix . $counter;
$tempbNode =& RDF_BlankNode::factory($uri);
- if (PEAR::isError($tempbNode)) {
- return $tempbNode;
- }
+
$res1 = $this->find($tempbNode, null, null);
- if (PEAR::isError($res1)) {
- return $res1;
- }
+
$res2 = $this->find(null, null, $tempbNode);
- if (PEAR::isError($res2)) {
- return $res2;
- }
+
if ($res1->size() == 0 && $res2->size() == 0) {
return $uri;
}
@@ -692,9 +656,7 @@ function equals(RDF_Model $that)
}
$result = $this->containsAll($that);
- if (PEAR::isError($result)) {
- return $result;
- }
+
if (!$result) {
return false;
}
@@ -735,17 +697,13 @@ function &unite(RDF_Model $model)
if (is_a($model, 'RDF_Model_Memory')) {
foreach($model->triples as $value) {
$result = $res->addWithoutDuplicates($value);
- if (PEAR::isError($result)) {
- return $result;
- }
+
}
} elseif (is_a($model, 'RDF_Model_MDB')) {
$Model_Memory =& $model->getMemModel();
foreach($Model_Memory->triples as $value) {
$result = $res->addWithoutDuplicates($value);
- if (PEAR::isError($result)) {
- return $result;
- }
+
}
}
@@ -770,17 +728,13 @@ function &subtract(RDF_Model $model)
if (is_a($model, 'RDF_Model_Memory')) {
foreach($model->triples as $value) {
$result = $res->remove($value);
- if (PEAR::isError($result)) {
- return $result;
- }
+
}
} elseif (is_a($model, 'RDF_Model_MDB')) {
$Model_Memory =& $model->getMemModel();
foreach($Model_Memory->triples as $value) {
$result = $res->remove($value);
- if (PEAR::isError($result)) {
- return $result;
- }
+
}
}
@@ -803,9 +757,7 @@ function &intersect(RDF_Model $model)
foreach($model->triples as $value) {
if ($this->contains($value)) {
$result = $res->add($value);
- if (PEAR::isError($result)) {
- return $result;
- }
+
}
}
} elseif (is_a($model, 'RDF_Model_MDB')) {
@@ -813,9 +765,7 @@ function &intersect(RDF_Model $model)
foreach($Model_Memory->triples as $value) {
if ($this->contains($value)) {
$result = $res->add($value);
- if (PEAR::isError($result)) {
- return $result;
- }
+
}
}
}
@@ -841,17 +791,13 @@ function addModel(RDF_Model $model)
if (is_a($model, 'RDF_Model_Memory')) {
foreach($model->triples as $value) {
$result = $this->_addStatementFromAnotherModel($value, $blankNodes_tmp);
- if (PEAR::isError($result)) {
- return $result;
- }
+
}
} elseif (is_a($model, 'RDF_Model_MDB')) {
$Model_Memory =& $model->getMemModel();
foreach($Model_Memory->triples as $value) {
$result = $this->_addStatementFromAnotherModel($value, $blankNodes_tmp);
- if (PEAR::isError($result)) {
- return $result;
- }
+
}
}
@@ -872,9 +818,7 @@ function &reify()
foreach($this->triples as $statement) {
$pointer =& $statement->reify($res);
$result = $res->addModel($pointer);
- if (PEAR::isError($result)) {
- return $result;
- }
+
}
return $res;
}
View
10 RDF/Store/MDB.php
@@ -50,7 +50,7 @@ function createTables($filename)
$manager =& new MDB_Manager;
$err = $manager->connect($this->dbConn);
if(PEAR::isError($err)) {
- return $err;
+ throw new RDF_Exception($err->getMessage());
}
$err = $manager->updateDatabase(
$filename,
@@ -58,7 +58,7 @@ function createTables($filename)
array('database' => $this->dbConn->database_name)
);
if(PEAR::isError($err)) {
- return $err;
+ throw new RDF_Exception($err->getMessage());
}
$dsn = $this->dbConn->getDSN();
// cant we remove this ugly hack?
@@ -100,7 +100,7 @@ function modelExists($modelURI)
$result = $this->dbConn->queryOne($sql);
if (PEAR::isError($result)) {
- return $result;
+ throw new RDF_Exception($err->getMessage());
}
return (bool)$result;
@@ -159,7 +159,7 @@ function getNewModel($modelURI, $baseURI = null)
$this->dbConn->autoCommit(true);
if (PEAR::isError($result)) {
- return $result;
+ throw new RDF_Exception($err->getMessage());
}
return new RDF_Model_MDB($this->dbConn, $modelURI, $modelID, $baseURI);
@@ -222,4 +222,4 @@ function _createUniqueModelID()
return $maxModelID;
}
} // end: Class Store_MDB
-?>
+?>
Please sign in to comment.
Something went wrong with that request. Please try again.