web/lib/Zend/Cloud/DocumentService/Adapter/WindowsAzure/Query.php
changeset 886 1e110b03ae96
parent 807 877f952ae2bd
child 1230 68c69c656a2c
equal deleted inserted replaced
885:2251fb41dbc7 886:1e110b03ae96
    11  * to license@zend.com so we can send you a copy immediately.
    11  * to license@zend.com so we can send you a copy immediately.
    12  *
    12  *
    13  * @category   Zend
    13  * @category   Zend
    14  * @package    Zend_Cloud
    14  * @package    Zend_Cloud
    15  * @subpackage DocumentService
    15  * @subpackage DocumentService
    16  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    16  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    17  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    17  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    18  */
    18  */
    19 
    19 
    20 /*
    20 /*
    21  * @see Zend_Cloud_DocumentService_QueryAdapter
    21  * @see Zend_Cloud_DocumentService_QueryAdapter
    22  */
    22  */
    23 require_once 'Zend/Cloud/DocumentService/QueryAdapter.php';
    23 require_once 'Zend/Cloud/DocumentService/QueryAdapter.php';
    24 
    24 
    25 /**
    25 /**
    26  * Class implementing Query adapter for working with Azure queries in a 
    26  * Class implementing Query adapter for working with Azure queries in a
    27  * structured way
    27  * structured way
    28  * 
    28  *
    29  * @todo       Look into preventing a query injection attack.
    29  * @todo       Look into preventing a query injection attack.
    30  * @category   Zend
    30  * @category   Zend
    31  * @package    Zend_Cloud
    31  * @package    Zend_Cloud
    32  * @subpackage DocumentService
    32  * @subpackage DocumentService
    33  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    33  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    34  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    34  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    35  */
    35  */
    36 class Zend_Cloud_DocumentService_Adapter_WindowsAzure_Query
    36 class Zend_Cloud_DocumentService_Adapter_WindowsAzure_Query
    37     implements Zend_Cloud_DocumentService_QueryAdapter
    37     implements Zend_Cloud_DocumentService_QueryAdapter
    38 {
    38 {
    39     /**
    39     /**
    40      * Azure concrete query
    40      * Azure concrete query
    41      * 
    41      *
    42      * @var Zend_Service_WindowsAzure_Storage_TableEntityQuery
    42      * @var Zend_Service_WindowsAzure_Storage_TableEntityQuery
    43      */
    43      */
    44     protected $_azureSelect;
    44     protected $_azureSelect;
    45     
    45 
    46     /**
    46     /**
    47      * Constructor
    47      * Constructor
    48      * 
    48      *
    49      * @param  null|Zend_Service_WindowsAzure_Storage_TableEntityQuery $select Table select object
    49      * @param  null|Zend_Service_WindowsAzure_Storage_TableEntityQuery $select Table select object
    50      * @return void
    50      * @return void
    51      */
    51      */
    52     public function __construct($select = null) 
    52     public function __construct($select = null)
    53     {
    53     {
    54         if (!$select instanceof Zend_Service_WindowsAzure_Storage_TableEntityQuery) {
    54         if (!$select instanceof Zend_Service_WindowsAzure_Storage_TableEntityQuery) {
    55             require_once 'Zend/Service/WindowsAzure/Storage/TableEntityQuery.php';
    55             require_once 'Zend/Service/WindowsAzure/Storage/TableEntityQuery.php';
    56             $select = new Zend_Service_WindowsAzure_Storage_TableEntityQuery();
    56             $select = new Zend_Service_WindowsAzure_Storage_TableEntityQuery();
    57         }
    57         }
    58         $this->_azureSelect = $select;
    58         $this->_azureSelect = $select;
    59     }
    59     }
    60 
    60 
    61     /**
    61     /**
    62      * SELECT clause (fields to be selected)
    62      * SELECT clause (fields to be selected)
    63      * 
    63      *
    64      * Does nothing for Azure.
    64      * Does nothing for Azure.
    65      * 
    65      *
    66      * @param  string $select
    66      * @param  string $select
    67      * @return Zend_Cloud_DocumentService_Adapter_WindowsAzure_Query
    67      * @return Zend_Cloud_DocumentService_Adapter_WindowsAzure_Query
    68      */
    68      */
    69     public function select($select)
    69     public function select($select)
    70     {
    70     {
    71         return $this;
    71         return $this;
    72     }
    72     }
    73     
    73 
    74     /**
    74     /**
    75      * FROM clause (table name)
    75      * FROM clause (table name)
    76      * 
    76      *
    77      * @param string $from
    77      * @param string $from
    78      * @return Zend_Cloud_DocumentService_Adapter_WindowsAzure_Query
    78      * @return Zend_Cloud_DocumentService_Adapter_WindowsAzure_Query
    79      */
    79      */
    80     public function from($from)
    80     public function from($from)
    81     {
    81     {
    82         $this->_azureSelect->from($from);
    82         $this->_azureSelect->from($from);
    83         return $this;
    83         return $this;
    84     }
    84     }
    85     
    85 
    86     /**
    86     /**
    87      * WHERE clause (conditions to be used)
    87      * WHERE clause (conditions to be used)
    88      * 
    88      *
    89      * @param string $where
    89      * @param string $where
    90      * @param mixed $value Value or array of values to be inserted instead of ?
    90      * @param mixed $value Value or array of values to be inserted instead of ?
    91      * @param string $op Operation to use to join where clauses (AND/OR)
    91      * @param string $op Operation to use to join where clauses (AND/OR)
    92      * @return Zend_Cloud_DocumentService_Adapter_WindowsAzure_Query
    92      * @return Zend_Cloud_DocumentService_Adapter_WindowsAzure_Query
    93      */
    93      */
    98             $value = array($value);
    98             $value = array($value);
    99         }
    99         }
   100         $this->_azureSelect->where($where, $value, $op);
   100         $this->_azureSelect->where($where, $value, $op);
   101         return $this;
   101         return $this;
   102     }
   102     }
   103     
   103 
   104     /**
   104     /**
   105      * WHERE clause for item ID
   105      * WHERE clause for item ID
   106      * 
   106      *
   107      * This one should be used when fetching specific rows since some adapters
   107      * This one should be used when fetching specific rows since some adapters
   108      * have special syntax for primary keys
   108      * have special syntax for primary keys
   109      * 
   109      *
   110      * @param  array $value Row ID for the document (PartitionKey, RowKey)
   110      * @param  array $value Row ID for the document (PartitionKey, RowKey)
   111      * @return Zend_Cloud_DocumentService_Adapter_WindowsAzure_Query
   111      * @return Zend_Cloud_DocumentService_Adapter_WindowsAzure_Query
   112      */
   112      */
   113     public function whereId($value)
   113     public function whereId($value)
   114     {
   114     {
   117             throw new Zend_Cloud_DocumentService_Exception('Invalid document key');
   117             throw new Zend_Cloud_DocumentService_Exception('Invalid document key');
   118         }
   118         }
   119         $this->_azureSelect->wherePartitionKey($value[0])->whereRowKey($value[1]);
   119         $this->_azureSelect->wherePartitionKey($value[0])->whereRowKey($value[1]);
   120         return $this;
   120         return $this;
   121     }
   121     }
   122     
   122 
   123     /**
   123     /**
   124      * LIMIT clause (how many rows to return)
   124      * LIMIT clause (how many rows to return)
   125      * 
   125      *
   126      * @param  int $limit
   126      * @param  int $limit
   127      * @return Zend_Cloud_DocumentService_Adapter_WindowsAzure_Query
   127      * @return Zend_Cloud_DocumentService_Adapter_WindowsAzure_Query
   128      */
   128      */
   129     public function limit($limit)
   129     public function limit($limit)
   130     {
   130     {
   132         return $this;
   132         return $this;
   133     }
   133     }
   134 
   134 
   135     /**
   135     /**
   136      * ORDER BY clause (sorting)
   136      * ORDER BY clause (sorting)
   137      * 
   137      *
   138      * @todo   Azure service doesn't seem to support this yet; emulate?
   138      * @todo   Azure service doesn't seem to support this yet; emulate?
   139      * @param  string $sort Column to sort by
   139      * @param  string $sort Column to sort by
   140      * @param  string $direction Direction - asc/desc
   140      * @param  string $direction Direction - asc/desc
   141      * @return Zend_Cloud_DocumentService_Adapter_WindowsAzure_Query
   141      * @return Zend_Cloud_DocumentService_Adapter_WindowsAzure_Query
   142      * @throws Zend_Cloud_OperationNotAvailableException
   142      * @throws Zend_Cloud_OperationNotAvailableException
   144     public function order($sort, $direction = 'asc')
   144     public function order($sort, $direction = 'asc')
   145     {
   145     {
   146         require_once 'Zend/Cloud/OperationNotAvailableException.php';
   146         require_once 'Zend/Cloud/OperationNotAvailableException.php';
   147         throw new Zend_Cloud_OperationNotAvailableException('No support for sorting for Azure yet');
   147         throw new Zend_Cloud_OperationNotAvailableException('No support for sorting for Azure yet');
   148     }
   148     }
   149     
   149 
   150     /**
   150     /**
   151      * Get Azure select query
   151      * Get Azure select query
   152      * 
   152      *
   153      * @return Zend_Service_WindowsAzure_Storage_TableEntityQuery
   153      * @return Zend_Service_WindowsAzure_Storage_TableEntityQuery
   154      */
   154      */
   155     public function getAzureSelect()
   155     public function getAzureSelect()
   156     {
   156     {
   157         return  $this->_azureSelect;
   157         return  $this->_azureSelect;
   159 
   159 
   160     /**
   160     /**
   161      * Assemble query
   161      * Assemble query
   162      *
   162      *
   163      * Simply return the WindowsAzure table entity query object
   163      * Simply return the WindowsAzure table entity query object
   164      * 
   164      *
   165      * @return Zend_Service_WindowsAzure_Storage_TableEntityQuery
   165      * @return Zend_Service_WindowsAzure_Storage_TableEntityQuery
   166      */
   166      */
   167     public function assemble()
   167     public function assemble()
   168     {
   168     {
   169         return $this->getAzureSelect();
   169         return $this->getAzureSelect();