Source for file DatasetDb.php
Documentation is available at DatasetDb.php
// ----------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------
* Persistent implementation of a Dataset in a database.
* A RDF dataset is a collection of named RDF graphs.
* @version $Id: fsource_dataset__datasetDatasetDb.php.html 310 2006-06-26 12:34:22Z tgauss $
* @author Daniel Westphal (http://www.d-westphal.de)
* @author Chris Bizer <chris@bizer.de>
require_once(RDFAPI_INCLUDE_DIR.
PACKAGE_DBASE);
* Reference to databse connection.
* @var resource dbConnection
* Reference to the dbStore Object.
* You can supply a Dataset name.
function DatasetDb(&$dbConnection,&$dbStore,$datasetName)
* Read all needed data into the set.
$recordSet =
& $this->dbConnection->execute("SELECT defaultModelUri
FROM datasets where datasetName='".
$this->setName.
"'");
$this->defaultGraph=
& $this->dbStore->getModel($recordSet->fields[0]);
// === Graph level methods ========================
* Sets the Dataset name. Return true on success, false otherwise.
if ($this->dbStore->datasetExists($datasetName))
$this->dbConnection->execute("UPDATE datasets SET datasetName='".
$datasetName.
"'
where datasetName='".
$this->setName.
"'");
$this->dbConnection->execute("UPDATE dataset_model SET datasetName='".
$datasetName.
"'
where datasetName='".
$this->setName.
"'");
* Returns the Datasets name.
* Adds a NamedGraph to the set.
$graphNameURI=
$graph->getGraphName();
$this->dbConnection->execute('INSERT INTO dataset_model VALUES("'.
$this->setName.
'",'.
$graph->modelID.
',"'.
$graphNameURI.
'")');
* Overwrites the existting default graph.
$this->dbConnection->execute('UPDATE datasets SET defaultModelUri ="'.
$graph->modelURI.
'" WHERE datasetName ="'.
$this->setName.
'"');
* Returns a reference to the defaultGraph.
$defaultGraphURI =
$this->dbConnection->GetOne("SELECT defaultModelUri FROM datasets WHERE datasetName ='".
$this->setName.
"'");
return ($this->dbStore->getNamedGraphDb($defaultGraphURI,'http://rdfapi-php/dataset_defaultGraph_'.
$this->setName));
* Returns true, if a defaultGraph exists. False otherwise.
* Removes a NamedGraph from the set. Nothing happens
* if no graph with that name is contained in the set.
$this->dbConnection->execute('DELETE FROM dataset_model WHERE datasetName="'.
$this->setName.
'" AND graphURI ="'.
$graphName.
'"');
* Tells wether the Dataset contains a NamedGraph.
$count=
$this->dbConnection->GetOne('SELECT count(*) FROM dataset_model WHERE datasetName="'.
$this->setName.
'" AND graphURI ="'.
$graphName.
'"');
* Returns the NamedGraph with a specific name from the Dataset.
* Changes to the graph will be reflected in the set.
* @return NamedGraphDb or null
$modelVars =
& $this->dbConnection->execute("SELECT models.modelURI, models.modelID, models.baseURI
FROM models, dataset_model
WHERE dataset_model.graphURI ='" .
$graphName .
"' AND dataset_model.modelId= models.modelID");
$modelVars->fields[1], $graphName ,$modelVars->fields[2]);
* Returns the names of the namedGraphs in this set as strings in an array.
$recordSet =
& $this->dbConnection->execute("SELECT graphURI FROM dataset_model WHERE datasetName ='".
$this->setName.
"'");
$return[] =
$recordSet->fields[0];
* Creates a new NamedGraph and adds it to the set. An existing graph with the same name will be replaced. But the old namedGraph remains in the database.
$graph =
& $this->dbStore->getNewNamedGraphDb(uniqid('http://rdfapi-php/namedGraph_'),$graphName,$baseURI);
* Deletes all NamedGraphs from the set.
$this->dbConnection->execute("DELETE FROM dataset_model WHERE datasetName ='".
$this->setName.
"'");
* Returns the number of NamedGraphs in the set. Empty graphs are counted.
return ($this->dbConnection->GetOne("SELECT count(*) FROM dataset_model WHERE datasetName ='".
$this->setName.
"'"));
* Returns an iterator over all {@link NamedGraph}s in the set.
* @return IteratorAllGraphsDb
$recordSet =
& $this->dbConnection->execute("SELECT graphURI FROM dataset_model WHERE datasetName ='".
$this->setName.
"'");
* Tells wether the set contains any NamedGraphs.
* Add all named graphs of the other dataset to this dataset.
function addAll($otherDataset)
for($iterator =
$otherDataset->listNamedGraphs(); $iterator->valid(); $iterator->next())
if ($otherDataset->hasDefaultGraph())
$this->defaultGraph =
$this->defaultGraph->unite($otherDataset->getDefaultGraph());
// === Quad level methods ========================
* Adds a quad to the Dataset. The argument must not contain any
* wildcards. If the quad is already present, nothing happens. A new
* named graph will automatically be created if necessary.
$graphName=
$quad->getGraphName();
$graphName=
$graphName->getLabel();
$statement=
$quad->getStatement();
* Tells wether the Dataset contains a quad or
* quads matching a pattern.
function containsQuad($graphName,$subject,$predicate,$object)
// static part of the sql statement
FROM statements, dataset_model
WHERE datasetName ='".
$this->setName.
"' AND statements.modelID=dataset_model.modelId ";
$sql.=
" AND graphURI ='".
$graphName->getLabel().
"'";
// dynamic part of the sql statement
* Deletes a Quad from the RDF dataset.
$graphName=
$quad->getGraphName();$graphName=
$graphName->getLabel();
$graphID =
$this->dbConnection->GetOne("SELECT modelId FROM dataset_model WHERE graphURI ='$graphName'");
// static part of the sql statement
$sql =
"DELETE FROM statements WHERE modelID = $graphID";
// dynamic part of the sql statement
* Counts the Quads in the RDF dataset. Identical Triples in
* different NamedGraphs are counted individually.
FROM statements, dataset_model
WHERE datasetName ='".
$this->setName.
"' AND statements.modelID=dataset_model.modelId ";
* Finds Statements that match a quad pattern. The argument may contain
* @param Resource or null
* @param Resource or null
* @param Resource or null
* @param Resource or null
* @return IteratorFindQuadsDb
function &findInNamedGraphs($graphName,$subject,$predicate,$object,$returnAsTriples =
false )
// static part of the sql statement
$sql =
"SELECT subject, predicate, object, l_language, l_datatype, subject_is, object_is, dataset_model.graphURI
FROM statements, dataset_model
WHERE datasetName ='".
$this->setName.
"' AND statements.modelID=dataset_model.modelId ";
$sql.=
" AND graphURI ='".
$graphName->getLabel().
"'";
// dynamic part of the sql statement
* Finds Statements that match a pattern in the default Graph. The argument may contain
* @param Resource or null
* @param Resource or null
* @param Resource or null
* @return IteratorFindQuadsDb
$defaultGraphID = (int)
$this->dbConnection->GetOne("SELECT models.modelID FROM datasets, models WHERE datasets.datasetName ='".
$this->setName.
"' AND datasets.defaultModelUri = models.modelURI");
// static part of the sql statement
$sql =
"SELECT subject, predicate, object, l_language, l_datatype, subject_is, object_is
WHERE modelID ='$defaultGraphID'";
// dynamic part of the sql statement
Documentation generated on Mon, 26 Jun 2006 14:25:20 +0200 by phpDocumentor 1.3.0RC6