Esempio n. 1
0
 /**
  * Invalidates according graph Uri entries, the result and all triple pattern.
  *
  * @param Query $queryObject All data according to this query will be invalidated.
  */
 public function invalidateByQuery(Query $queryObject)
 {
     // log it
     $this->addToLog(array('method' => 'invalidateByQuery', 'parameter' => array('queryObject' => $queryObject)));
     $query = $queryObject->getQuery();
     // load query cache container by given query
     $queryCacheContainer = $this->cache->load($query);
     /**
      * remove according query from the query list which belongs to one of the graph URI's in the query
      * cache container.
      */
     if (true === is_array($queryCacheContainer['graph_uris'])) {
         foreach ($queryCacheContainer['graph_uris'] as $graphUri) {
             $queryList = $this->cache->load($graphUri);
             unset($queryList[$query]);
             // if graphUri entry is empty after the operation, remove it from the cache
             if (0 == count($queryList)) {
                 $this->cache->remove($graphUri);
                 // otherwise save updated entry
             } else {
                 $this->cache->save($graphUri, $queryList);
             }
         }
     }
     // check for according triple pattern
     if (true === is_array($queryCacheContainer['triple_pattern'])) {
         foreach ($queryCacheContainer['triple_pattern'] as $patternKey) {
             $queryList = $this->cache->load($patternKey);
             unset($queryList[$query]);
             // if patternKey entry is empty after the operation, remove it from the cache
             if (0 == count($queryList)) {
                 $this->cache->remove($patternKey);
                 // otherwise save updated entry
             } else {
                 $this->cache->save($patternKey, $queryList);
             }
         }
     }
     /**
      * Remove query cache container
      */
     $this->cache->remove($query);
 }
 /**
  * Create Statement instance based on a given Query instance.
  *
  * @param  Query     $queryObject Query object which represents a SPARQL query.
  * @return Statement Statement object
  * @throws \Exception             If query contains more than one triple pattern.
  * @throws \Exception             If more than one graph was found.
  */
 protected function getStatement(Query $queryObject)
 {
     $queryParts = $queryObject->getQueryParts();
     $tupleInformaton = null;
     $tupleType = null;
     /**
      * Use triple pattern
      */
     if (true === isset($queryParts['triple_pattern'])) {
         $tupleInformation = $queryParts['triple_pattern'];
         $tupleType = 'triple';
         /**
          * Use quad pattern
          */
     } elseif (true === isset($queryParts['quad_pattern'])) {
         $tupleInformation = $queryParts['quad_pattern'];
         $tupleType = 'quad';
         /**
          * Neither triple nor quad information
          */
     } else {
         throw new \Exception('Neither triple nor quad information available in given query object: ' . $queryObject->getQuery());
     }
     if (1 > count($tupleInformation)) {
         throw new \Exception('Query contains more than one triple- respectivly quad pattern.');
     }
     /**
      * Triple
      */
     if ('triple' == $tupleType) {
         $subject = $this->createNodeByValueAndType($tupleInformation[0]['s'], $tupleInformation[0]['s_type']);
         $predicate = $this->createNodeByValueAndType($tupleInformation[0]['p'], $tupleInformation[0]['p_type']);
         $object = $this->createNodeByValueAndType($tupleInformation[0]['o'], $tupleInformation[0]['o_type']);
         $graph = null;
         /**
          * Quad
          */
     } elseif ('quad' == $tupleType) {
         $subject = $this->createNodeByValueAndType($tupleInformation[0]['s'], $tupleInformation[0]['s_type']);
         $predicate = $this->createNodeByValueAndType($tupleInformation[0]['p'], $tupleInformation[0]['p_type']);
         $object = $this->createNodeByValueAndType($tupleInformation[0]['o'], $tupleInformation[0]['o_type']);
         $graph = $this->createNodeByValueAndType($tupleInformation[0]['g'], 'uri');
     }
     // no else neccessary, because otherwise the upper exception would be thrown if tupleType is neither
     // quad or triple.
     return $this->statementFactory->createStatement($subject, $predicate, $object, $graph);
 }