Skip to content

Commit

Permalink
add getModelOrCreate method. Fixing #15
Browse files Browse the repository at this point in the history
and move getQueryCount method down
  • Loading branch information
white-gecko committed Oct 4, 2012
1 parent 4158443 commit ff9a86f
Showing 1 changed file with 36 additions and 11 deletions.
47 changes: 36 additions & 11 deletions library/Erfurt/Store.php
Expand Up @@ -862,19 +862,9 @@ public function getModel($modelIri, $useAc = true)
return $modelInstance;
}

/**
* Returns the number fo queries committed.
*
* @return int
*/
public function getQueryCount()
{
return self::$_queryCount;
}

/**
* Creates a new empty model instance with IRI $modelIri.
*
*
* @param string $modelIri
* @param string $baseIri
* @param string $type
Expand Down Expand Up @@ -916,6 +906,41 @@ public function getNewModel($modelIri, $baseIri = '', $type = Erfurt_Store::MODE
return $this->getModel($modelIri, $useAc);
}

/**
* Returns a model if it exists and else creates it
*
* @param string $modelIri
* @param string $baseIri
* @param string $type
* @param boolean $useAc
*
* @throws Erfurt_Store_Exception
*
* @return Erfurt_Rdf_Model
*/
public function getModelOrCreate ($modelIri, $baseIri = '', $type = Erfurt_Store::MODEL_TYPE_OWL, $useAc = true)
{
try {
// Create it if it doesn't exist
$model = $store->getNewModel($modelIri, $useAc);
} catch (Erfurt_Store_Exception $e) {
// Get it if it already exists
$model = $store->getModel($modelIri, $baseIri, $type, $useAc);
}

return $model;
}

/**
* Returns the number fo queries committed.
*
* @return int
*/
public function getQueryCount()
{
return self::$_queryCount;
}

/**
* Returns inferred objects in realation to a certain set of resources.
*
Expand Down

0 comments on commit ff9a86f

Please sign in to comment.