/**
  * @dataProvider errorCodeProvider
  */
 public function testGetQueryResultObjectForInstanceQuery($errorCode)
 {
     $store = $this->getMockBuilder('\\SMW\\Store')->disableOriginalConstructor()->getMockForAbstractClass();
     $expElement = $this->getMockBuilder('\\SMWExpElement')->disableOriginalConstructor()->getMockForAbstractClass();
     $iteratorMockBuilder = new IteratorMockBuilder();
     $repositoryResult = $iteratorMockBuilder->setClass('\\SMW\\SPARQLStore\\QueryEngine\\RepositoryResult')->with(array(array($expElement)))->getMockForIterator();
     $repositoryResult->expects($this->atLeastOnce())->method('getErrorCode')->will($this->returnValue($errorCode));
     $description = $this->getMockBuilder('\\SMWDescription')->disableOriginalConstructor()->getMockForAbstractClass();
     $query = new Query($description);
     $query->querymode = Query::MODE_INSTANCES;
     $instance = new QueryResultFactory($store);
     $this->assertInstanceOf('\\SMWQueryResult', $instance->newQueryResult($repositoryResult, $query));
     $this->assertQueryResultErrorCode($errorCode, $instance->newQueryResult($repositoryResult, $query));
 }
 private function getInstanceQueryResult(Query $query, Condition $compoundCondition)
 {
     if ($this->isSingletonConditionWithElementMatch($compoundCondition)) {
         $matchElement = $compoundCondition->matchElement;
         if ($compoundCondition->condition === '') {
             // all URIs exist, no querying
             $results = array(array($matchElement));
         } else {
             $condition = $this->compoundConditionBuilder->convertConditionToString($compoundCondition);
             $namespaces = $compoundCondition->namespaces;
             $askQueryResult = $this->connection->ask($condition, $namespaces);
             $results = $askQueryResult->isBooleanTrue() ? array(array($matchElement)) : array();
         }
         $repositoryResult = new RepositoryResult(array(self::RESULT_VARIABLE => 0), $results);
     } elseif ($compoundCondition instanceof FalseCondition) {
         $repositoryResult = new RepositoryResult(array(self::RESULT_VARIABLE => 0), array());
     } else {
         $condition = $this->compoundConditionBuilder->convertConditionToString($compoundCondition);
         $namespaces = $compoundCondition->namespaces;
         $options = $this->getOptions($query, $compoundCondition);
         $options['DISTINCT'] = true;
         $repositoryResult = $this->connection->select('?' . self::RESULT_VARIABLE, $condition, $options, $namespaces);
     }
     return $this->queryResultFactory->newQueryResult($repositoryResult, $query);
 }
Exemple #3
0
 /**
  * Get the results for a query in instance retrieval mode.
  *
  * @param Query $query
  *
  * @return QueryResult
  */
 public function getInstanceQueryResult(Query $query)
 {
     $this->sortkeys = $query->sortkeys;
     $this->compoundConditionBuilder->setSortKeys($this->sortkeys);
     $sparqlCondition = $this->compoundConditionBuilder->buildCondition($query->getDescription());
     $query->addErrors($this->compoundConditionBuilder->getErrors());
     if ($sparqlCondition instanceof SingletonCondition) {
         $matchElement = $sparqlCondition->matchElement;
         if ($sparqlCondition->condition === '') {
             // all URIs exist, no querying
             $results = array(array($matchElement));
         } else {
             $condition = $this->compoundConditionBuilder->convertConditionToString($sparqlCondition);
             $namespaces = $sparqlCondition->namespaces;
             $askQueryResult = $this->connection->ask($condition, $namespaces);
             $results = $askQueryResult->isBooleanTrue() ? array(array($matchElement)) : array();
         }
         $repositoryResult = new RepositoryResult(array(self::RESULT_VARIABLE => 0), $results);
     } elseif ($sparqlCondition instanceof FalseCondition) {
         $repositoryResult = new RepositoryResult(array(self::RESULT_VARIABLE => 0), array());
     } else {
         $condition = $this->compoundConditionBuilder->convertConditionToString($sparqlCondition);
         $namespaces = $sparqlCondition->namespaces;
         $options = $this->getOptions($query, $sparqlCondition);
         $options['DISTINCT'] = true;
         $repositoryResult = $this->connection->select('?' . self::RESULT_VARIABLE, $condition, $options, $namespaces);
     }
     return $this->queryResultFactory->newQueryResult($repositoryResult, $query);
 }