Changeset 4452 for trunk/lib/Doctrine

Show
Ignore:
Timestamp:
05/27/08 05:52:50 (8 months ago)
Author:
guilhermeblanco
Message:

Changed Doctrine_Query to accept a Doctrine_EntityManager instead of a Doctrine_Connection. Updated Doctrine_EntityManager. Updated test cases and included one new passing test case for SELECT generation. Fixed whitespace bug in DELETE and UPDATE statements.

Location:
trunk/lib/Doctrine
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/Doctrine/EntityManager.php

    r4436 r4452  
    247247        $query = new Doctrine_Query($this); 
    248248        if ( ! empty($dql)) { 
    249             $query->parseQuery($dql); 
     249            $query->setDql($dql); 
    250250        } 
    251251         
  • trunk/lib/Doctrine/Query.php

    r4422 r4452  
    3838{ 
    3939    /** 
    40      * @var Doctrine_Connection The connection used by this query object. 
    41      */ 
    42     protected $_connection; 
     40     * @var Doctrine_EntityManager The entity manager used by this query object. 
     41     */ 
     42    protected $_entityManager; 
    4343 
    4444    /** 
     
    9494 
    9595 
    96     public function __construct(Doctrine_Connection $conn = null, Doctrine_Hydrator_Abstract $hydrator = null) 
    97     { 
    98         $this->setConnection($conn); 
    99  
    100         if ($hydrator === null) { 
    101             $hydrator = new Doctrine_Hydrator(Doctrine_EntityManager::getManager()); 
    102         } 
    103  
    104         $this->_hydrator = $hydrator; 
     96    public function __construct(Doctrine_EntityManager $entityManager) 
     97    { 
     98        $this->_entityManager = $entityManager; 
     99        $this->_hydrator = new Doctrine_Hydrator($entityManager); 
    105100 
    106101        $this->free(); 
     
    121116 
    122117    /** 
    123      * Retrieves the assocated Doctrine_Connection to this Doctrine_Query 
    124      * 
    125      * @return Doctrine_Connection 
    126      */ 
    127     public function getConnection() 
    128     { 
    129         return $this->_connection; 
    130     } 
    131  
    132  
    133     /** 
    134      * Defines an assocated Doctrine_Connection to this Doctrine_Query 
    135      * 
    136      * @param Doctrine_Connection $conn A valid Doctrine_Connection 
    137      * @return void 
    138      */ 
    139     public function setConnection(Doctrine_Connection $conn = null) 
    140     { 
    141         if ($conn === null) { 
    142             $conn = Doctrine_EntityManager::getManager()->getConnection(); 
    143         } 
    144  
    145         $this->_connection = $conn; 
     118     * Retrieves the assocated Doctrine_EntityManager to this Doctrine_Query 
     119     * 
     120     * @return Doctrine_EntityManager 
     121     */ 
     122    public function getEntityManager() 
     123    { 
     124        return $this->_entityManager; 
    146125    } 
    147126 
     
    231210    { 
    232211        if ($this->_state === self::STATE_DIRTY) { 
    233             $parser = new Doctrine_Query_Parser($this->getDql()); 
     212            $parser = new Doctrine_Query_Parser($this); 
    234213            $this->_parserResult = $parser->parse(); 
    235214            $this->_state = self::STATE_CLEAN; 
     
    314293    { 
    315294        // If there is a CacheDriver associated to cache queries... 
    316         if ($this->_queryCache || $this->_connection->getAttribute(Doctrine::ATTR_QUERY_CACHE)) { 
     295        if ($this->_queryCache || $this->_entityManager->getConnection()->getAttribute(Doctrine::ATTR_QUERY_CACHE)) { 
    317296            $queryCacheDriver = $this->getQueryCacheDriver(); 
    318297 
     
    348327        // We always have an instance of Doctrine_Query_ParserResult on hands... 
    349328        if ($this->_parserResult->isLimitSubqueryUsed() && 
    350             $this->_connection->getAttribute(Doctrine::ATTR_DRIVER_NAME) !== 'mysql') { 
     329            $this->_entityManager->getConnection()->getAttribute(Doctrine::ATTR_DRIVER_NAME) !== 'mysql') { 
    351330            $params = array_merge($params, $params); 
    352331        } 
     
    363342    { 
    364343        // Convert boolean params 
    365         $params = $this->_connection->convertBooleans($params); 
     344        $params = $this->_entityManager->getConnection()->convertBooleans($params); 
    366345 
    367346        // Convert enum params 
     
    400379            return $this->_resultCache; 
    401380        } else { 
    402             return $this->_connection->getResultCacheDriver(); 
     381            return $this->_entityManager->getConnection()->getResultCacheDriver(); 
    403382        } 
    404383    } 
     
    489468            return $this->_queryCache; 
    490469        } else { 
    491             return $this->_connection->getQueryCacheDriver(); 
     470            return $this->_entityManager->getConnection()->getQueryCacheDriver(); 
    492471        } 
    493472    } 
  • trunk/lib/Doctrine/Query/Parser.php

    r4451 r4452  
    112112     * @param Doctrine_Connection $connection The connection to use 
    113113     */ 
    114     public function __construct($dql, Doctrine_Connection $connection = null) 
    115     { 
    116         $this->_scanner = new Doctrine_Query_Scanner($dql); 
    117         $this->_sqlBuilder = Doctrine_Query_SqlBuilder::fromConnection($connection); 
     114    public function __construct(Doctrine_Query $query) 
     115    { 
     116        $this->_scanner = new Doctrine_Query_Scanner($query->getDql()); 
     117        $this->_sqlBuilder = Doctrine_Query_SqlBuilder::fromConnection($query->getEntityManager()); 
    118118        $this->_keywordTable = new Doctrine_Query_Token(); 
    119119 
  • trunk/lib/Doctrine/Query/ParserResult.php

    r4451 r4452  
    7575     * @param array $queryFields Query fields. 
    7676     */ 
    77     public function setQueryComponents(array $queryFields) 
     77    public function setQueryFields(array $queryFields) 
    7878    { 
    7979        $this->_queryFields = $queryFields; 
  • trunk/lib/Doctrine/Query/Production/DeleteStatement.php

    r4422 r4452  
    5555        // Simple "DELETE FROM table_name" gives 0 affected rows. 
    5656        return $this->_deleteClause->buildSql() . (($this->_whereClause !== null) 
    57              ? $this->_whereClause->buildSql() : ' WHERE 1 = 1'); 
     57             ? ' ' . $this->_whereClause->buildSql() : ' WHERE 1 = 1'); 
    5858    } 
    5959} 
  • trunk/lib/Doctrine/Query/Production/UpdateStatement.php

    r4422 r4452  
    5555        // Simple "UPDATE table_name SET column_name = value" gives 0 affected rows. 
    5656        return $this->_updateClause->buildSql() . (($this->_whereClause !== null) 
    57              ? $this->_whereClause->buildSql() : ' WHERE 1 = 1'); 
     57             ? ' ' . $this->_whereClause->buildSql() : ' WHERE 1 = 1'); 
    5858    } 
    5959} 
  • trunk/lib/Doctrine/Query/Production/WhereClause.php

    r4422 r4452  
    4848    public function buildSql() 
    4949    { 
    50         return ' WHERE ' . $this->_conditionalExpression->buildSql(); 
     50        return 'WHERE ' . $this->_conditionalExpression->buildSql(); 
    5151    } 
    5252} 
  • trunk/lib/Doctrine/Query/SqlBuilder.php

    r4422 r4452  
    4343 
    4444 
    45     public static function fromConnection(Doctrine_Connection $connection = null) 
     45    public static function fromConnection(Doctrine_EntityManager $entityManager) 
    4646    { 
    47         if ($connection === null) { 
    48             $connection = Doctrine_EntityManager::getManager()->getConnection(); 
    49         } 
     47        $connection = $entityManager->getConnection(); 
    5048 
    5149        $className = "Doctrine_Query_SqlBuilder_" . $connection->getDriverName();