Example #1
0
 /**
  * Query for documents stored in the document service. If a string is passed in
  * $query, the query string will be passed directly to the service.
  *
  * @param  string $collectionName Collection name
  * @param  string|\ZendCloud\DocumentService\Adapter\WindowsAzure\Query $query
  * @param  array $options
  * @return array|\ZendCloud\DocumentService\DocumentSet
  */
 public function query($collectionName, $query, $options = null)
 {
     try {
         if ($query instanceof \ZendCloud\DocumentService\Adapter\WindowsAzure\Query) {
             $entities = $this->_storageClient->retrieveEntities($query->assemble());
         } else {
             $entities = $this->_storageClient->retrieveEntities($collectionName, $query);
         }
         $documentClass = $this->getDocumentClass();
         $resultSet = array();
         foreach ($entities as $entity) {
             $resultSet[] = new $documentClass($this->_resolveAttributes($entity), array($entity->getPartitionKey(), $entity->getRowKey()));
         }
     } catch (WindowsAzureException\ExceptionInterface $e) {
         throw new Exception\RuntimeException('Error on document query: ' . $e->getMessage(), $e->getCode(), $e);
     }
     $setClass = $this->getDocumentSetClass();
     return new $setClass($resultSet);
 }