Beispiel #1
0
 /**
  * Test where multiple query
  */
 public function testWhereMultipleQuery()
 {
     $target = new Zend_Service_WindowsAzure_Storage_TableEntityQuery();
     $target->select()->from('MyTable')->where('Name eq ?', 'Maarten')->andWhere('Visible eq true');
     $this->assertEquals('MyTable()?$filter=Name eq \'Maarten\' and Visible eq true', $target->__toString());
 }
Beispiel #2
0
 /**
  * Retrieve entities from table
  * 
  * @param string $tableName|Zend_Service_WindowsAzure_Storage_TableEntityQuery    Table name -or- Zend_Service_WindowsAzure_Storage_TableEntityQuery instance
  * @param string $filter                                                Filter condition (not applied when $tableName is a Zend_Service_WindowsAzure_Storage_TableEntityQuery instance)
  * @param string $entityClass                                           Entity class name
  * @param string $nextPartitionKey                                      Next partition key, used for listing entities when total amount of entities is > 1000.
  * @param string $nextRowKey                                            Next row key, used for listing entities when total amount of entities is > 1000.
  * @return array Array of Zend_Service_WindowsAzure_Storage_TableEntity
  * @throws Zend_Service_WindowsAzure_Exception
  */
 public function retrieveEntities($tableName = '', $filter = '', $entityClass = 'Zend_Service_WindowsAzure_Storage_DynamicTableEntity', $nextPartitionKey = null, $nextRowKey = null)
 {
     if ($tableName === '') {
         require_once 'Zend/Service/WindowsAzure/Exception.php';
         throw new Zend_Service_WindowsAzure_Exception('Table name is not specified.');
     }
     if ($entityClass === '') {
         require_once 'Zend/Service/WindowsAzure/Exception.php';
         throw new Zend_Service_WindowsAzure_Exception('Entity class is not specified.');
     }
     // Convenience...
     if (class_exists($filter)) {
         $entityClass = $filter;
         $filter = '';
     }
     // Query string
     $queryString = '';
     // Determine query
     if (is_string($tableName)) {
         // Option 1: $tableName is a string
         // Append parentheses
         if (strpos($tableName, '()') === false) {
             $tableName .= '()';
         }
         // Build query
         $query = array();
         // Filter?
         if ($filter !== '') {
             $query[] = '$filter=' . Zend_Service_WindowsAzure_Storage_TableEntityQuery::encodeQuery($filter);
         }
         // Build queryString
         if (count($query) > 0) {
             $queryString = '?' . implode('&', $query);
         }
     } else {
         if (get_class($tableName) == 'Zend_Service_WindowsAzure_Storage_TableEntityQuery') {
             // Option 2: $tableName is a Zend_Service_WindowsAzure_Storage_TableEntityQuery instance
             // Build queryString
             $queryString = $tableName->assembleQueryString(true);
             // Change $tableName
             $tableName = $tableName->assembleFrom(true);
         } else {
             require_once 'Zend/Service/WindowsAzure/Exception.php';
             throw new Zend_Service_WindowsAzure_Exception('Invalid argument: $tableName');
         }
     }
     // Add continuation querystring parameters?
     if (!is_null($nextPartitionKey) && !is_null($nextRowKey)) {
         if ($queryString !== '') {
             $queryString .= '&';
         } else {
             $queryString .= '?';
         }
         $queryString .= 'NextPartitionKey=' . rawurlencode($nextPartitionKey) . '&NextRowKey=' . rawurlencode($nextRowKey);
     }
     // Perform request
     $response = null;
     if ($this->isInBatch() && $this->getCurrentBatch()->getOperationCount() == 0) {
         $this->getCurrentBatch()->enlistOperation($tableName, $queryString, Zend_Http_Client::GET, array(), true, null);
         $response = $this->getCurrentBatch()->commit();
         // Get inner response (multipart)
         $innerResponse = $response->getBody();
         $innerResponse = substr($innerResponse, strpos($innerResponse, 'HTTP/1.1 200 OK'));
         $innerResponse = substr($innerResponse, 0, strpos($innerResponse, '--batchresponse'));
         $response = Zend_Http_Response::fromString($innerResponse);
     } else {
         $response = $this->_performRequest($tableName, $queryString, Zend_Http_Client::GET, array(), true, null);
     }
     if ($response->isSuccessful()) {
         // Parse result
         $result = $this->_parseResponse($response);
         if (!$result) {
             return array();
         }
         $entries = null;
         if ($result->entry) {
             if (count($result->entry) > 1) {
                 $entries = $result->entry;
             } else {
                 $entries = array($result->entry);
             }
         } else {
             // This one is tricky... If we have properties defined, we have an entity.
             $properties = $result->xpath('//m:properties');
             if ($properties) {
                 $entries = array($result);
             } else {
                 return array();
             }
         }
         // Create return value
         $returnValue = array();
         foreach ($entries as $entry) {
             // Parse properties
             $properties = $entry->xpath('.//m:properties');
             $properties = $properties[0]->children('http://schemas.microsoft.com/ado/2007/08/dataservices');
             // Create entity
             $entity = new $entityClass('', '');
             $entity->setAzureValues((array) $properties, $this->_throwExceptionOnMissingData);
             // If we have a Zend_Service_WindowsAzure_Storage_DynamicTableEntity, make sure all property types are set
             if ($entity instanceof Zend_Service_WindowsAzure_Storage_DynamicTableEntity) {
                 foreach ($properties as $key => $value) {
                     $attributes = $value->attributes('http://schemas.microsoft.com/ado/2007/08/dataservices/metadata');
                     $type = (string) $attributes['type'];
                     if ($type !== '') {
                         $entity->setAzureProperty($key, (string) $value, $type);
                     }
                 }
             }
             // Update etag
             $etag = $entry->attributes('http://schemas.microsoft.com/ado/2007/08/dataservices/metadata');
             $etag = (string) $etag['etag'];
             $entity->setEtag($etag);
             // Add to result
             $returnValue[] = $entity;
         }
         // More entities?
         if (!is_null($response->getHeader('x-ms-continuation-NextPartitionKey')) && !is_null($response->getHeader('x-ms-continuation-NextRowKey'))) {
             if (strpos($queryString, '$top') === false) {
                 $returnValue = array_merge($returnValue, $this->retrieveEntities($tableName, $filter, $entityClass, $response->getHeader('x-ms-continuation-NextPartitionKey'), $response->getHeader('x-ms-continuation-NextRowKey')));
             }
         }
         // Return
         return $returnValue;
     } else {
         require_once 'Zend/Service/WindowsAzure/Exception.php';
         throw new Zend_Service_WindowsAzure_Exception($this->_getErrorMessage($response, 'Resource could not be accessed.'));
     }
 }
Beispiel #3
0
 /**
  * LIMIT clause (how many rows to return)
  * 
  * @param  int $limit
  * @return Zend_Cloud_DocumentService_Adapter_WindowsAzure_Query
  */
 public function limit($limit)
 {
     $this->_azureSelect->top($limit);
     return $this;
 }