Skip to content
Browse files

Rely on exceptions, except where mdb will return a PEAR_Error

  • Loading branch information...
1 parent 9ea6a15 commit 484bb0a2f9362313e8064125b3ac9eea85b651b6 @CloCkWeRX CloCkWeRX committed Mar 25, 2012
Showing with 19 additions and 47 deletions.
  1. +19 −47 RDF/Model/MDB.php
View
66 RDF/Model/MDB.php
@@ -138,7 +138,7 @@ function add(RDF_Statement $statement)
$result = $this->dbConn->query($sql);
if (PEAR::isError($result)) {
- return $result;
+ throw new RDF_Exception($result->getMessage());
}
}
}
@@ -265,7 +265,7 @@ function contains(&$statement)
$result = $this->dbConn->queryOne($sql);
if (PEAR::isError($result)) {
- return $result;
+ throw new RDF_Exception($result->getMessage());
}
return (bool)$result;
@@ -359,7 +359,7 @@ function find(RDF_Resource $subject = null, RDF_Resource $predicate = null, RDF_
$result = $this->dbConn->query($sql);
if (PEAR::isError($result)) {
- return $result;
+ throw new RDF_Exception($result->getMessage());
// write the recordSet into memory Model
}
return $this->_convertRecordSetToMemModel($result);
@@ -414,7 +414,7 @@ function findVocabulary($vocabulary)
$result = $this->dbConn->query($sql);
if (PEAR::isError($result)) {
- return $result;
+ throw new RDF_Exception($result->getMessage());
// write the recordSet into memory Model
}
return $this->_convertRecordSetToMemModel($result);
@@ -446,7 +446,7 @@ function findFirstMatchingStatement(RDF_Resource $subject = null, RDF_Resource $
$result = $this->dbConn->query($sql);
if (PEAR::isError($result)) {
- return $result;
+ throw new RDF_Exception($result->getMessage());
}
if (!$this->dbConn->numRows($result)) {
return null;
@@ -559,9 +559,7 @@ function equals(RDF_Model $that)
}
$result = $this->containsAll($that);
- if (PEAR::isError($result)) {
- return $result;
- }
+
if (!$result) {
return false;
}
@@ -673,20 +671,16 @@ function addModel(RDF_Model $model)
$this->dbConn->autoCommit(false);
foreach ($model->triples as $statement) {
$result = $this->_addStatementFromAnotherModel($statement, $blankNodes_tmp);
- if (PEAR::isError($result)) {
- return $result;
- }
- }
+
+ }
$this->dbConn->commit();
$this->dbConn->autoCommit(true);
} elseif (is_a($model, 'RDF_Model_MDB')) {
$this->dbConn->autoCommit(false);
$Model_Memory =& $model->getMemModel();
foreach($Model_Memory->triples as $statement) {
$result = $this->_addStatementFromAnotherModel($statement, $blankNodes_tmp);
- if (PEAR::isError($result)) {
- return $result;
- }
+
}
$this->dbConn->commit();
$this->dbConn->autoCommit(true);
@@ -729,7 +723,7 @@ function delete()
$result = $this->dbConn->commit();
$this->dbConn->autoCommit(true);
if (PEAR::isError($result)) {
- return $result;
+ throw new RDF_Exception($result->getMessage());
}
return $this->close();
}
@@ -760,17 +754,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;
}
@@ -839,42 +827,26 @@ function _convertRecordSetToMemModel($result)
} else {
$sub =& RDF_BlankNode::factory($row[0]);
}
- if (PEAR::isError($sub)) {
- return $sub;
- }
+
// predicate
$pred =& RDF_Resource::factory($row[1]);
- if (PEAR::isError($pred)) {
- return $pred;
- }
+
// object
if ($row[6] == 'r') {
$obj =& RDF_Resource::factory($row[2]);
- if (PEAR::isError($obj)) {
- return $obj;
- }
+
} elseif ($row[6] == 'b') {
$obj =& RDF_BlankNode::factory($row[2]);
- if (PEAR::isError($obj)) {
- return $obj;
- }
} else {
$obj =& RDF_Literal::factory($row[2], $row[3]);
- if (PEAR::isError($obj)) {
- return $obj;
- }
+
if ($row[4]) {
$obj->setDatatype($row[4]);
}
}
$statement =& RDF_Statement::factory($sub, $pred, $obj);
- if (PEAR::isError($statement)) {
- return $statement;
- }
+
$result = $res->add($statement);
- if (PEAR::isError($result)) {
- return $result;
- }
}
$this->dbConn->freeResult($result);
return $res;
@@ -963,7 +935,7 @@ function _containsRow($row)
$result =& $this->dbConn->queryOne($sql);
if (PEAR::isError($result)) {
- return $result;
+ throw new RDF_Exception($result->getMessage());
}
return (bool)$result;
}

0 comments on commit 484bb0a

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