Changeset 4524 for trunk/lib/Doctrine

Show
Ignore:
Timestamp:
06/16/08 19:31:21 (7 months ago)
Author:
romanb
Message:

Removed static EntityManager? lookup from productions. Entity refactorings.

Location:
trunk/lib/Doctrine
Files:
10 modified

Legend:

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

    r4523 r4524  
    6767     * An Entity is in proxy state when its properties are not fully loaded. 
    6868     */ 
    69     const STATE_PROXY = 4; 
     69    //const STATE_PROXY = 4; 
    7070 
    7171    /** 
     
    964964        } 
    965965         
    966         $class = $this->_class; 
    967         if ($class->hasField($fieldName)) { 
    968             if ($value instanceof Doctrine_Entity) { 
     966        if ($this->_class->hasField($fieldName)) { 
     967            /*if ($value instanceof Doctrine_Entity) { 
    969968                $type = $class->getTypeOf($fieldName); 
    970969                // FIXME: composite key support 
     
    974973                    $value = $id; 
    975974                } 
    976             } 
     975            }*/ 
    977976 
    978977            $old = isset($this->_data[$fieldName]) ? $this->_data[$fieldName] : null; 
    979978 
    980             if ($old !== $value) { 
     979            if ($old != $value) { 
    981980                $this->_data[$fieldName] = $value; 
    982981                $this->_modified[] = $fieldName; 
    983982                 
    984                 /* We can't do this currently because there are tests that change 
    985                  * the primary key of already persisted entities (ugh). */ 
    986                 if ($this->isTransient() && $class->isIdentifier($fieldName)) { 
     983                if ($this->isTransient() && $this->_class->isIdentifier($fieldName)) { 
    987984                    $this->_id[$fieldName] = $value; 
    988985                } 
     
    997994                } 
    998995            } 
    999         } else if ($class->hasRelation($fieldName)) { 
     996        } else if ($this->_class->hasRelation($fieldName)) { 
    1000997            $this->_rawSetReference($fieldName, $value); 
    1001998        } else { 
     
    11421139                    break; 
    11431140                default: 
    1144                     if ($this->_data[$field] instanceof Doctrine_Entity) { 
     1141                    /*if ($this->_data[$field] instanceof Doctrine_Entity) { 
    11451142                        // FIXME: composite key support 
    11461143                        $ids = $this->_data[$field]->identifier(); 
    11471144                        $id = count($ids) > 0 ? array_pop($ids) : null; 
    11481145                        $this->_data[$field] = $id; 
    1149                     } 
     1146                    }*/ 
    11501147                    /** TODO: 
    11511148                    if ($this->_data[$v] === null) { 
     
    11601157        // @todo cleanup 
    11611158        // populates the discriminator field in Single & Class Table Inheritance 
    1162         $class = $this->_class; 
    1163         if ($class->getInheritanceType() == Doctrine::INHERITANCE_TYPE_JOINED || 
    1164                 $class->getInheritanceType() == Doctrine::INHERITANCE_TYPE_SINGLE_TABLE) { 
    1165             $discCol = $class->getInheritanceOption('discriminatorColumn'); 
    1166             $discMap = $class->getInheritanceOption('discriminatorMap'); 
     1159        if ($this->_class->getInheritanceType() == Doctrine::INHERITANCE_TYPE_JOINED || 
     1160                $this->_class->getInheritanceType() == Doctrine::INHERITANCE_TYPE_SINGLE_TABLE) { 
     1161            $discCol = $this->_class->getInheritanceOption('discriminatorColumn'); 
     1162            $discMap = $this->_class->getInheritanceOption('discriminatorMap'); 
    11671163            $old = $this->get($discCol, false); 
    11681164            $discValue = array_search($this->_entityName, $discMap); 
  • trunk/lib/Doctrine/EntityManager.php

    r4523 r4524  
    6060    private $_config; 
    6161     
    62      
    6362    /** 
    6463     * The database connection used by the EntityManager. 
     
    410409    public function save(Doctrine_Entity $entity) 
    411410    { 
     411        $state = $entity->_state(); 
     412        if ($state == Doctrine_Entity::STATE_CLEAN || $state == Doctrine_Entity::STATE_LOCKED) { 
     413            return; 
     414        } 
     415         
    412416        //... 
     417        //$this->_unitOfWork-> 
     418        switch ($entity->_state()) { 
     419            case Doctrine_Entity::STATE_CLEAN: 
     420                //nothing to do 
     421                break; 
     422            case Doctrine_Entity::STATE_DIRTY: 
     423                $this->_unitOfWork->registerDirty($entity); 
     424                break; 
     425            case Doctrine_Entity::STATE_TCLEAN: 
     426            case Doctrine_Entity::STATE_TDIRTY: 
     427                //... 
     428        } 
    413429    } 
    414430     
  • trunk/lib/Doctrine/EntityPersister/Abstract.php

    r4523 r4524  
    249249     
    250250    /** 
    251      * Saves an entity and all it's related entities. 
     251     * Saves an entity. 
    252252     * 
    253253     * @param Doctrine_Entity $record    The entity to save. 
    254254     * @param Doctrine_Connection $conn  The connection to use. Will default to the mapper's 
    255255     *                                   connection. 
    256      * @throws Doctrine_Mapper_Exception If the mapper is unable to save the given entity. 
    257      */ 
    258     public function save(Doctrine_Entity $record, Doctrine_Connection $conn = null) 
     256     */ 
     257    public function save(Doctrine_Entity $record) 
    259258    { 
    260259        if ( ! ($record instanceof $this->_domainClassName)) { 
     
    283282                $this->_insertOrUpdate($record); 
    284283            } else { 
    285                 $conn->transaction->addInvalid($record); 
     284                $conn->getTransaction()->addInvalid($record); 
    286285            } 
    287286 
     
    376375                // Protection against infinite function recursion before attempting to save 
    377376                if ($obj instanceof Doctrine_Entity && $obj->isModified()) { 
    378                     $obj->save($this->_conn); 
     377                    $obj->save(); 
    379378                     
    380379                    /** Can this be removed? 
  • trunk/lib/Doctrine/Query/Parser.php

    r4523 r4524  
    102102     */ 
    103103    protected $_errorDistance; 
     104     
     105    /** 
     106     * The EntityManager. 
     107     * 
     108     * @var EnityManager 
     109     */ 
     110    protected $_em; 
    104111 
    105112    // End of Error management stuff 
     
    114121    public function __construct(Doctrine_Query $query) 
    115122    { 
     123        $this->_em = $query->getEntityManager(); 
    116124        $this->_scanner = new Doctrine_Query_Scanner($query->getDql()); 
    117         $this->_sqlBuilder = Doctrine_Query_SqlBuilder::fromConnection($query->getEntityManager()); 
     125        $this->_sqlBuilder = Doctrine_Query_SqlBuilder::fromConnection($this->_em); 
    118126        $this->_keywordTable = new Doctrine_Query_Token(); 
    119127 
     
    334342        $this->_errorDistance = 0; 
    335343    } 
    336  
     344     
     345    /** 
     346     * Gets the EntityManager used by the parser. 
     347     * 
     348     * @return EntityManager 
     349     */ 
     350    public function getEntityManager() 
     351    { 
     352        return $this->_em; 
     353    } 
    337354} 
  • trunk/lib/Doctrine/Query/Production.php

    r4523 r4524  
    11<?php 
    2  
    32/* 
    43 *  $Id$ 
     
    5453     */ 
    5554    protected $_parser; 
     55     
     56    /** 
     57     * The EntityManager. 
     58     * 
     59     * @var EntityManager 
     60     */ 
     61    protected $_em; 
    5662 
    5763 
     
    6470    { 
    6571        $this->_parser = $parser; 
     72        $this->_em = $this->_parser->getEntityManager(); 
    6673    } 
    6774 
  • trunk/lib/Doctrine/Query/Production/PathExpression.php

    r4523 r4524  
    131131 
    132132        // Retrieving connection 
    133         $manager = Doctrine_EntityManagerFactory::getManager();  
    134         $conn = $manager->getConnection(); 
     133        $conn = $this->_em->getConnection(); 
    135134 
    136135        // Looking for queryComponent to fetch 
  • trunk/lib/Doctrine/Query/Production/PathExpressionEndingWithAsterisk.php

    r4523 r4524  
    120120 
    121121        // Retrieving connection 
    122         $manager = Doctrine_EntityManagerFactory::getManager();  
    123         $conn = $manager->getConnection(); 
     122        $conn = $this->_em->getConnection(); 
    124123 
    125124        // Looking for componentAlias to fetch 
  • trunk/lib/Doctrine/Query/Production/RangeVariableDeclaration.php

    r4523 r4524  
    116116 
    117117        // Get the connection for the component 
    118         $conn = $this->_parser->getSqlBuilder()->getConnection(); 
    119         $manager = Doctrine_EntityManagerFactory::getManager(); 
     118        $conn = $this->_em->getConnection(); 
    120119        $componentName = $this->_identifiers[0]; 
    121120 
    122121        // Retrieving ClassMetadata and Mapper 
    123122        try { 
    124             $classMetadata = $manager->getClassMetadata($componentName); 
     123            $classMetadata = $this->_em->getClassMetadata($componentName); 
    125124 
    126125            // Building queryComponent 
     
    156155 
    157156        // Get the connection for the component 
    158         $conn = $this->_parser->getSqlBuilder()->getConnection(); 
    159         $manager = Doctrine_EntityManagerFactory::getManager(); 
     157        $conn = $this->_em->getConnection(); 
    160158 
    161159        // Retrieve the base component 
  • trunk/lib/Doctrine/Query/Production/SelectExpression.php

    r4523 r4524  
    137137 
    138138        // Retrieving connection 
    139         $manager = Doctrine_EntityManagerFactory::getManager();  
    140         $conn = $manager->getConnection(); 
     139        $conn = $this->_em->getConnection(); 
    141140 
    142141        switch (get_class($this->_leftExpression)) { 
  • trunk/lib/Doctrine/Query/Production/VariableDeclaration.php

    r4523 r4524  
    8484 
    8585            // Get the connection for the component 
    86             $conn = $this->_parser->getSqlBuilder()->getConnection(); 
    87             $manager = Doctrine_EntityManagerFactory::getManager(); 
     86            $conn = $this->_em->getConnection(); 
    8887 
    8988            // Retrieving ClassMetadata and Mapper 
    9089            try { 
    91                 $classMetadata = $manager->getMetadata($this->_componentName); 
     90                $classMetadata = $this->_em->getMetadata($this->_componentName); 
    9291 
    9392                // Building queryComponent 
     
    125124 
    126125        // Retrieving connection 
    127         $manager = Doctrine_EntityManagerFactory::getManager(); 
    128         $conn = $manager->getConnection(); 
     126        $conn = $this->_em->getConnection(); 
    129127 
    130128        return $conn->quoteIdentifier($queryComponent['metadata']->getTableName()) . ' '