Changeset 4845

Show
Ignore:
Timestamp:
08/27/08 05:44:41 (10 months ago)
Author:
guilhermeblanco
Message:

Completed Doctrine_Query_Registry support. Included named query support, backported from trunk. From now on you're able to define and run named queries from *Table classes. Documentation to be added.

Location:
branches/1.0
Files:
1 added
4 modified

Legend:

Unmodified
Added
Removed
  • branches/1.0/lib/Doctrine/Manager.php

    r4812 r4845  
    138138    { 
    139139        if ( ! isset($this->_queryRegistry)) { 
    140            $this->_queryRegistry = new Doctrine_Query_Registry; 
     140           $this->_queryRegistry = new Doctrine_Query_Registry(); 
    141141        } 
    142142        return $this->_queryRegistry; 
  • branches/1.0/lib/Doctrine/Query/Registry.php

    r3884 r4845  
    6868        return $query; 
    6969    } 
     70     
     71     
     72    public function has($key, $namespace = null) 
     73    { 
     74        return isset($namespace)  
     75            ? isset($this->_queries[$namespace][$key]) 
     76            : isset($this->_queries[$key]); 
     77    } 
    7078} 
  • branches/1.0/lib/Doctrine/Table.php

    r4829 r4845  
    12341234        public function createNamedQuery($queryKey) 
    12351235    { 
    1236         return Doctrine_Manager::getInstance()->getQueryRegistry() 
    1237                    ->get($queryKey, $this->getComponentName()); 
     1236        $queryRegistry = Doctrine_Manager::getInstance()->getQueryRegistry(); 
     1237 
     1238        if (strpos($queryKey, '/') !== false) { 
     1239            $e = explode('/', $queryKey); 
     1240             
     1241            return $queryRegistry->get($e[0], $e[1]); 
     1242        } 
     1243 
     1244        return $queryRegistry->get($queryKey, $this->getComponentName()); 
    12381245    } 
    12391246 
     
    12421249     * finds a record by its identifier 
    12431250     * 
    1244      * @param $id                       database row id 
    1245      * @param int $hydrationMode        Doctrine::HYDRATE_ARRAY or Doctrine::HYDRATE_RECORD 
    1246      * @return mixed                    Array or Doctrine_Record or false if no result 
    1247      */ 
    1248     public function find($id, $hydrationMode = null) 
    1249     { 
    1250         if (is_null($id)) { 
     1251     * @param mixed $name         Database Row ID or Query Name defined previously as a NamedQuery 
     1252     * @param mixed $params       This argument is the hydration mode (Doctrine::HYDRATE_ARRAY or  
     1253     *                            Doctrine::HYDRATE_RECORD) if first param is a Database Row ID.  
     1254     *                            Otherwise this argument expect an array of query params. 
     1255     * @param int $hydrationMode  Optional Doctrine::HYDRATE_ARRAY or Doctrine::HYDRATE_RECORD if  
     1256     *                            first argument is a NamedQuery 
     1257     * @return mixed              Doctrine_Collection, array, Doctrine_Record or false if no result 
     1258     */ 
     1259    public function find() 
     1260    { 
     1261        $num_args = func_num_args(); 
     1262 
     1263        // Named Query or IDs 
     1264        $name = func_get_arg(0); 
     1265         
     1266        if (is_null($name)) {  
    12511267            return false; 
    12521268        } 
    12531269 
    1254         $id = is_array($id) ? array_values($id) : array($id); 
    1255  
    1256         $q = $this->createQuery('dctrn_find') 
    1257             ->where( 
    1258                 'dctrn_find.' . implode( 
    1259                     ' = ? AND dctrn_find.', (array) $this->getIdentifier() 
    1260                 ) . ' = ?', $id 
    1261             ) 
    1262             ->limit(1); 
    1263         $res = $q->fetchOne(array(), $hydrationMode); 
     1270        // Define query to be used 
     1271        if ( 
     1272            ! is_array($name) && 
     1273            Doctrine_Manager::getInstance()->getQueryRegistry()->has($name, $this->getComponentName()) 
     1274        ) { 
     1275            // We're dealing with a named query 
     1276            $q = $this->createNamedQuery($name); 
     1277 
     1278            // Parameters construction 
     1279            $params = ($num_args >= 2) ? func_get_arg(1) : array(); 
     1280 
     1281            // Hydration mode 
     1282            $hydrationMode = ($num_args == 3) ? func_get_arg(2) : null; 
     1283 
     1284            // Executing query 
     1285            $res = $q->execute($params, $hydrationMode); 
     1286        } else { 
     1287            // We're passing a single ID or an array of IDs 
     1288            $q = $this->createQuery('dctrn_find') 
     1289                ->where('dctrn_find.' . implode(' = ? AND dctrn_find.', (array) $this->getIdentifier()) . ' = ?') 
     1290                ->limit(1); 
     1291                 
     1292            // Parameters construction 
     1293            $params = is_array($name) ? array_values($name) : array($name); 
     1294 
     1295            // Hydration mode 
     1296            $hydrationMode = ($num_args == 2) ? func_get_arg(1) : null; 
     1297             
     1298            // Executing query 
     1299            $res = $q->fetchOne($params, $hydrationMode); 
     1300        } 
     1301 
    12641302        $q->free(); 
    12651303         
  • branches/1.0/tests/run.php

    r4841 r4845  
    224224$core->addTestCase(new Doctrine_Table_TestCase()); 
    225225$core->addTestCase(new Doctrine_Table_RemoveColumn_TestCase()); 
     226$core->addTestCase(new Doctrine_Table_NamedQuery_TestCase()); 
    226227$core->addTestCase(new Doctrine_UnitOfWork_TestCase()); 
    227228$core->addTestCase(new Doctrine_Collection_TestCase());