Trac

Changeset 4628 for trunk

Show
Ignore:
Timestamp:
07/04/08 17:32:19 (2 months ago)
Author:
romanb
Message:

The usual 2.0 refactoring/implementation commit.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/Doctrine/ClassMetadata.php

    r4523 r4628  
    142142 
    143143    /** 
     144     * Enter description here... 
     145     * 
     146     * @var array 
     147     */ 
     148    protected $_attributes = array('loadReferences' => true); 
     149     
     150    /** 
    144151     * An array of field names. used to look up field names from column names. 
    145152     * Keys are column names and values are field names. 
     
    149156     */ 
    150157    protected $_fieldNames = array(); 
    151      
    152     /** 
    153      * Enter description here... 
    154      * 
    155      * @var unknown_type 
    156      */ 
    157     protected $_attributes = array('loadReferences' => true); 
    158158 
    159159    /** 
     
    167167     
    168168    /** 
     169     * Map that maps lowercased column names to field names. 
     170     * Mainly used during hydration because Doctrine enforces PDO_CASE_LOWER 
     171     * for portability. 
     172     * 
     173     * @var array 
     174     */ 
     175    protected $_lcColumnToFieldNames = array(); 
     176     
     177    /** 
    169178     * Enter description here... 
    170179     * 
    171180     * @var unknown_type 
    172181     */ 
    173     protected $_subclassFieldNames = array(); 
     182    //protected $_subclassFieldNames = array(); 
    174183 
    175184    /** 
     
    193202     * @var integer 
    194203     */ 
    195     protected $_columnCount; 
     204    //protected $_columnCount; 
    196205 
    197206    /** 
     
    541550 
    542551    /** 
    543      * getFieldName 
    544      * 
    545      * returns the field name for a column name 
    546      * if no field name can be found the column name is returned. 
     552     * Gets the field name for a column name. 
     553     * If no field name can be found the column name is returned. 
    547554     * 
    548555     * @param string $columnName    column name 
     
    556563     
    557564    /** 
     565     * Gets the field name for a completely lowercased column name. 
     566     * Mainly used during hydration. 
     567     * 
     568     * @param string $lcColumnName 
     569     * @return string 
     570     */ 
     571    public function getFieldNameForLowerColumnName($lcColumnName) 
     572    { 
     573        return isset($this->_lcColumnToFieldNames[$lcColumnName]) ? 
     574                $this->_lcColumnToFieldNames[$lcColumnName] : $lcColumnName; 
     575    } 
     576     
     577    public function hasLowerColumn($lcColumnName) 
     578    { 
     579        return isset($this->_lcColumnToFieldNames[$lcColumnName]); 
     580    } 
     581     
     582    /** 
     583     * Looks up the field name for a (lowercased) column name. 
    558584     *  
    559      */ 
    560     public function lookupFieldName($columnName) 
    561     { 
    562         if (isset($this->_fieldNames[$columnName])) { 
    563             return $this->_fieldNames[$columnName]; 
    564         } else if (isset($this->_subclassFieldNames[$columnName])) { 
    565             return $this->_subclassFieldNames[$columnName]; 
    566         } 
     585     * This is mostly used during hydration, because we want to make the 
     586     * conversion to field names while iterating over the result set for best 
     587     * performance. By doing this at that point, we can avoid re-iterating over 
     588     * the data just to convert the column names to field names. 
     589     *  
     590     * However, when this is happening, we don't know the real 
     591     * class name to instantiate yet (the row data may target a sub-type), hence 
     592     * this method looks up the field name in the subclass mappings if it's not 
     593     * found on this class mapping. 
     594     * This lookup on subclasses is costly but happens only *once* for a column 
     595     * during hydration because the hydrator caches effectively. 
     596     */ 
     597    public function lookupFieldName($lcColumnName) 
     598    { 
     599        if (isset($this->_lcColumnToFieldNames[$lcColumnName])) { 
     600            return $this->_lcColumnToFieldNames[$lcColumnName]; 
     601        }/* else if (isset($this->_subclassFieldNames[$lcColumnName])) { 
     602            return $this->_subclassFieldNames[$lcColumnName]; 
     603        }*/ 
    567604         
    568         $classMetadata = $this; 
    569         $conn = $this->_em; 
    570          
    571         foreach ($classMetadata->getSubclasses() as $subClass) { 
    572             $subClassMetadata = $conn->getClassMetadata($subClass); 
    573             if ($subClassMetadata->hasColumn($columnName)) { 
    574                 $this->_subclassFieldNames[$columnName] = $subClassMetadata->getFieldName($columnName); 
    575                 return $this->_subclassFieldNames[$columnName]; 
     605        foreach ($this->getSubclasses() as $subClass) { 
     606            $subClassMetadata = $this->_em->getClassMetadata($subClass); 
     607            if ($subClassMetadata->hasLowerColumn($lcColumnName)) { 
     608                /*$this->_subclassFieldNames[$lcColumnName] = $subClassMetadata-> 
     609                        getFieldNameForLowerColumnName($lcColumnName); 
     610                return $this->_subclassFieldNames[$lcColumnName];*/ 
     611                return $subClassMetadata->getFieldNameForLowerColumnName($lcColumnName); 
    576612            } 
    577613        } 
    578614 
    579         throw new Doctrine_ClassMetadata_Exception("No field name found for column name '$columnName' during lookup."); 
     615        throw new Doctrine_ClassMetadata_Exception("No field name found for column name '$lcColumnName' during lookup."); 
    580616    } 
    581617 
     
    616652        } 
    617653 
    618         // extract column name & field name 
     654        // extract column name & field name & lowercased column name 
    619655        $parts = explode(' as ', $name); 
    620656        if (count($parts) > 1) { 
     
    623659            $fieldName = $parts[0]; 
    624660        } 
    625         $name = strtolower($parts[0]); 
    626  
    627         if (isset($this->_columnNames[$fieldName])) { 
     661        $columnName = $parts[0]; 
     662        $lcColumnName = strtolower($parts[0]); 
     663 
     664        if (isset($this->_mappedColumns[$columnName])) { 
    628665            return; 
    629666        } 
    630667 
     668        // Fill column name <-> field name lookup maps 
    631669        if ($prepend) { 
    632             $this->_columnNames = array_merge(array($fieldName => $name), $this->_columnNames); 
    633             $this->_fieldNames = array_merge(array($name => $fieldName), $this->_fieldNames); 
     670            $this->_columnNames = array_merge(array($fieldName => $columnName), $this->_columnNames); 
     671            $this->_fieldNames = array_merge(array($columnName => $fieldName), $this->_fieldNames); 
    634672        } else { 
    635             $this->_columnNames[$fieldName] = $name; 
    636             $this->_fieldNames[$name] = $fieldName; 
    637         } 
     673            $this->_columnNames[$fieldName] = $columnName; 
     674            $this->_fieldNames[$columnName] = $fieldName; 
     675        } 
     676        $this->_lcColumnToFieldNames[$lcColumnName] = $fieldName; 
     677         
    638678         
    639679        // Inspect & fill $options 
     
    663703 
    664704        if ($prepend) { 
    665             $this->_mappedColumns = array_merge(array($name => $options), $this->_mappedColumns); 
     705            $this->_mappedColumns = array_merge(array($columnName => $options), $this->_mappedColumns); 
    666706        } else { 
    667             $this->_mappedColumns[$name] = $options; 
     707            $this->_mappedColumns[$columnName] = $options; 
    668708        } 
    669709 
  • trunk/lib/Doctrine/Collection.php

    r4523 r4628  
    6666     * @var Doctrine_Entity 
    6767     */ 
    68     protected $reference
     68    protected $_owner
    6969 
    7070    /** 
     
    9494     * @var Doctrine_Null 
    9595     */ 
    96     protected static $null; 
     96    //protected static $null; 
     97     
     98    /** 
     99     * The EntityManager. 
     100     * 
     101     * @var EntityManager 
     102     */ 
     103    protected $_em; 
    97104 
    98105    /** 
     
    105112    public function __construct($entityBaseType, $keyField = null) 
    106113    { 
    107         if (is_string($entityBaseType)) { 
    108             $this->_entityBaseType = $entityBaseType; 
    109             $mapper = Doctrine_EntityManagerFactory::getManager($entityBaseType) 
    110                     ->getEntityPersister($entityBaseType); 
    111         } 
    112         $this->_mapper = $mapper; 
     114        $this->_entityBaseType = $entityBaseType; 
     115        $this->_em = Doctrine_EntityManagerFactory::getManager($entityBaseType); 
     116        $this->_mapper = $this->_em->getEntityPersister($entityBaseType); 
    113117 
    114118        if ($keyField === null) { 
    115             $keyField = $mapper->getClassMetadata()->getBoundQueryPart('indexBy'); 
     119            $keyField = $this->_mapper->getClassMetadata()->getBoundQueryPart('indexBy'); 
    116120        } 
    117121 
     
    126130            $this->_keyField = $keyField; 
    127131        } 
    128     } 
    129  
    130     /** 
    131      * initNullObject 
    132      * Initializes the null object for this collection. 
    133      * 
    134      * @return void 
    135      */ 
    136     public static function initNullObject(Doctrine_Null $null) 
    137     { 
    138         self::$null = $null; 
    139     } 
    140  
    141     /** 
    142      * getTable 
    143      * Returns the table of the mapper of the collection. 
    144      * 
    145      * @return Doctrine_Table 
    146      */ 
    147     public function getTable() 
    148     { 
    149         return $this->_mapper->getTable(); 
    150     } 
    151      
    152     /** 
    153      * getMapper 
    154      * Returns the mapper of this collection. 
    155      * 
    156      * @return Doctrine_Mapper 
    157      */ 
    158     public function getMapper() 
    159     { 
    160         return $this->_mapper; 
    161132    } 
    162133 
     
    307278     
    308279    /** 
    309      * setReference 
     280     * INTERNAL: 
    310281     * sets a reference pointer 
    311282     * 
    312283     * @return void 
    313284     */ 
    314     public function setReference(Doctrine_Entity $record, Doctrine_Relation $relation) 
    315     { 
    316         $this->reference = $record
     285    public function setReference(Doctrine_Entity $entity, Doctrine_Relation $relation) 
     286    { 
     287        $this->_owner = $entity
    317288        $this->relation  = $relation; 
    318289 
     
    320291                $relation instanceof Doctrine_Relation_LocalKey) { 
    321292            $this->referenceField = $relation->getForeignFieldName(); 
    322             $value = $record->get($relation->getLocalFieldName()); 
    323             foreach ($this->data as $record) { 
     293            $value = $entity->get($relation->getLocalFieldName()); 
     294            foreach ($this->data as $entity) { 
    324295                if ($value !== null) { 
    325                     $record->set($this->referenceField, $value, false); 
     296                    $entity->set($this->referenceField, $value, false); 
    326297                } else { 
    327                     $record->set($this->referenceField, $this->reference, false); 
     298                    $entity->set($this->referenceField, $this->_owner, false); 
    328299                } 
    329300            } 
     
    334305 
    335306    /** 
     307     * INTERNAL: 
    336308     * getReference 
    337309     * 
     
    340312    public function getReference() 
    341313    { 
    342         return $this->reference; 
    343     } 
    344  
    345     /** 
    346      * remove 
    347      * removes a specified collection element 
     314        return $this->_owner; 
     315    } 
     316 
     317    /** 
     318     * Removes an entity from the collection. 
    348319     * 
    349320     * @param mixed $key 
     
    358329 
    359330    /** 
    360      * contains 
    361      * whether or not this collection contains a specified element 
     331     * Checks whether the collection contains an entity. 
    362332     * 
    363333     * @param mixed $key                    the key of the element 
     
    379349 
    380350    /** 
    381      * get 
    382351     * returns a record for given key 
    383      * 
    384      * There are two special cases: 
    385      * 
    386      * 1. if null is given as a key a new record is created and attached 
    387      * at the end of the collection 
    388      * 
    389      * 2. if given key does not exist, then a new record is create and attached 
    390      * to the given key 
    391352     * 
    392353     * Collection also maps referential information to newly created records 
     
    397358    public function get($key) 
    398359    { 
    399         if ( ! isset($this->data[$key])) { 
    400             $record = $this->_mapper->create(); 
    401  
    402             if (isset($this->referenceField)) { 
    403                 $value = $this->reference->get($this->relation->getLocalFieldName()); 
    404  
    405                 if ($value !== null) { 
    406                     $record->set($this->referenceField, $value, false); 
    407                 } else { 
    408                     $record->set($this->referenceField, $this->reference, false); 
    409                 } 
    410             } 
    411              
    412             if ($key === null) { 
    413                 $this->data[] = $record; 
    414             } else { 
    415                 $this->data[$key] = $record;             
    416             } 
    417  
    418             if (isset($this->_keyField)) { 
    419                 $record->set($this->_keyField, $key); 
    420             } 
    421  
    422             return $record; 
    423         } 
    424  
    425         return $this->data[$key]; 
     360        if (isset($this->data[$key])) { 
     361            return $this->data[$key]; 
     362        } 
     363        return null; 
    426364    } 
    427365 
     
    492430     *           to adhere to the Doctrine_Access::set() signature. 
    493431     */ 
    494     public function set($key, $record
    495     { 
    496         if ( ! $record instanceOf Doctrine_Entity) { 
     432    public function set($key, $entity
     433    { 
     434        if ( ! $entity instanceof Doctrine_Entity) { 
    497435            throw new Doctrine_Collection_Exception('Value variable in set is not an instance of Doctrine_Entity'); 
    498436        } 
    499437 
    500438        if (isset($this->referenceField)) { 
    501             $record->set($this->referenceField, $this->reference, false); 
    502         } 
    503         $this->data[$key] = $record
     439            $entity->set($this->referenceField, $this->_owner, false); 
     440        } 
     441        $this->data[$key] = $entity
    504442    } 
    505443 
     
    518456 
    519457        if (isset($this->referenceField)) { 
    520             $value = $this->reference->get($this->relation->getLocalFieldName()); 
     458            $value = $this->_owner->get($this->relation->getLocalFieldName()); 
    521459 
    522460            if ($value !== null) { 
    523461                $record->set($this->referenceField, $value, false); 
    524462            } else { 
    525                 $record->set($this->referenceField, $this->reference, false); 
     463                $record->set($this->referenceField, $this->_owner, false); 
    526464            } 
    527465        } 
     
    560498 
    561499    /** 
     500     * INTERNAL: 
    562501     * loadRelated 
    563502     * 
     
    579518                } 
    580519            } 
    581             $query->from($this->_mapper->getComponentName() . '(' . implode(", ",$this->_mapper->getTable()->getPrimaryKeys()) . ')'); 
    582             $query->where($this->_mapper->getComponentName() . '.id IN (' . substr(str_repeat("?, ", count($list)),0,-2) . ')'); 
     520            $query->from($this->_mapper->getComponentName() 
     521                    . '(' . implode(", ",$this->_mapper->getTable()->getPrimaryKeys()) . ')'); 
     522            $query->where($this->_mapper->getComponentName() 
     523                    . '.id IN (' . substr(str_repeat("?, ", count($list)),0,-2) . ')'); 
    583524 
    584525            return $query; 
     
    608549 
    609550    /** 
     551     * INTERNAL: 
    610552     * populateRelated 
    611553     * 
     
    930872        $this->data = array(); 
    931873 
    932         if ($this->reference) { 
    933             $this->reference->free($deep); 
    934             $this->reference = null; 
     874        if ($this->_owner) { 
     875            $this->_owner->free($deep); 
     876            $this->_owner = null; 
    935877        } 
    936878    } 
  • trunk/lib/Doctrine/Configuration.php

    r4523 r4628  
    2828 * It combines all configuration options from DBAL & ORM. 
    2929 * 
     30 * @author Roman Borschel <roman@code-factory.org> 
    3031 * @since 2.0 
    3132 */ 
  • trunk/lib/Doctrine/Connection.php

    r4523 r4628  
    7979     * The PDO database handle.  
    8080     * 
    81      * @var PDO 
    82      * @todo Rename to $pdo.               
    83      */ 
    84     protected $dbh; 
     81     * @var PDO            
     82     */ 
     83    protected $_pdo; 
    8584     
    8685    /** 
     
    117116     * @var string $driverName                   
    118117     */ 
    119     protected $driverName; 
     118    protected $_driverName; 
    120119     
    121120    /** 
     
    124123     * @var boolean $isConnected                 
    125124     */ 
    126     protected $isConnected = false; 
     125    protected $_isConnected = false; 
    127126     
    128127    /** 
     
    164163     * @var array $availableDrivers          
    165164     */ 
    166     private static $availableDrivers = array( 
     165    private static $_availableDrivers = array( 
    167166            'Mysql', 'Pgsql', 'Oracle', 'Informix', 'Mssql', 'Sqlite', 'Firebird' 
    168167            ); 
     
    173172     * @var integer 
    174173     */ 
    175     protected $_count = 0; 
     174    protected $_queryCount = 0; 
    176175 
    177176     
     
    221220     * Constructor. 
    222221     * 
    223      * @param Doctrine_Manager $manager                 the manager object 
    224      * @param PDO|Doctrine_Adapter_Interface $adapter   database driver 
     222     * @param array $params  The connection parameters. 
    225223     */ 
    226224    public function __construct(array $params) 
    227225    { 
    228226        if (isset($params['pdo'])) { 
    229             $this->dbh = $params['pdo']; 
    230             $this->isConnected = true; 
     227            $this->_pdo = $params['pdo']; 
     228            $this->_isConnected = true; 
    231229        } 
    232230        $this->_params = $params; 
     
    320318 
    321319    /** 
    322      * getDriverName 
    323      * 
    324320     * Gets the name of the instance driver 
    325321     * 
     
    328324    public function getDriverName() 
    329325    { 
    330         return $this->driverName; 
     326        return $this->_driverName; 
    331327    } 
    332328     
     
    335331     * 
    336332     * @return PDO              the database handler 
     333     * @deprecated 
    337334     */ 
    338335    public function getDbh() 
    339336    { 
    340         //$this->connect(); 
    341          
    342         return $this->dbh; 
     337        $this->connect(); 
     338        return $this->_pdo; 
     339    } 
     340     
     341    /** 
     342     * Gets the PDO handle used by the connection. 
     343     * 
     344     * @return PDO 
     345     */ 
     346    public function getPdo() 
     347    { 
     348        $this->connect(); 
     349        return $this->_pdo; 
    343350    } 
    344351     
     
    350357    public function connect() 
    351358    { 
    352         if ($this->isConnected) { 
     359        if ($this->_isConnected) { 
    353360            return false; 
    354361        } 
     
    357364        //$this->getListener()->preConnect($event); 
    358365 
    359         $e = explode(':', $this->options['dsn']); 
     366        // TODO: the extension_loaded check can happen earlier, maybe in the factory 
    360367        if (extension_loaded('pdo')) { 
    361             if (in_array($e[0], PDO::getAvailableDrivers())) { 
    362                 $this->dbh = new PDO( 
    363                         $this->options['dsn'], $this->options['username'], 
    364                         $this->options['password'], $this->options['other']); 
    365                 $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
    366                 $this->dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); 
    367             } 
     368            $driverOptions = isset($this->_params['driverOptions']) ? 
     369                    $this->_params['driverOptions'] : array(); 
     370            $user = isset($this->_params['user']) ? 
     371                    $this->_params['user'] : null; 
     372            $password = isset($this->_params['password']) ? 
     373                    $this->_params['password'] : null; 
     374            $this->_pdo = new PDO( 
     375                    $this->_constructPdoDsn(), 
     376                    $user, 
     377                    $password, 
     378                    $driverOptions 
     379                    ); 
     380            $this->_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
     381            $this->_pdo->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER); 
    368382        } else { 
    369383            throw new Doctrine_Connection_Exception("Couldn't locate driver named " . $e[0]); 
     
    371385 
    372386        // attach the pending attributes to adapter 
    373         foreach($this->pendingAttributes as $attr => $value) { 
     387        /*foreach($this->pendingAttributes as $attr => $value) { 
    374388            // some drivers don't support setting this so we just skip it 
    375389            if ($attr == Doctrine::ATTR_DRIVER_NAME) { 
    376390                continue; 
    377391            } 
    378             $this->dbh->setAttribute($attr, $value); 
    379         } 
    380  
    381         $this->isConnected = true; 
     392            $this->_pdo->setAttribute($attr, $value); 
     393        }*/ 
     394 
     395        $this->_isConnected = true; 
    382396 
    383397        //$this->getListener()->postConnect($event); 
     
    395409    protected function _constructPdoDsn() 
    396410    { 
    397          
     411        throw Doctrine_Exception::notImplemented('_constructPdoDsn', get_class($this)); 
    398412    } 
    399413     
     
    403417    public function incrementQueryCount()  
    404418    { 
    405         $this->_count++; 
    406     } 
    407  
    408     /** 
    409      * converts given driver name 
    410      * 
    411      * @param 
    412      */ 
    413     public function driverName($name) 
    414     {} 
    415  
    416     /** 
    417      * supports 
     419        $this->_queryCount++; 
     420    } 
     421 
     422    /** 
     423     * Checks whether a certain feature is supported. 
    418424     * 
    419425     * @param string $feature   the name of the feature 
     
    666672    public function quote($input, $type = null) 
    667673    { 
    668         return $this->dbh->quote($input, $type); 
     674        return $this->_pdo->quote($input, $type); 
    669675    } 
    670676 
     
    783789     
    784790            if ( ! $event->skipOperation) { 
    785                 $stmt = $this->dbh->prepare($statement); 
     791                $stmt = $this->_pdo->prepare($statement); 
    786792            } 
    787793     
     
    847853 
    848854                if ( ! $event->skipOperation) { 
    849                     $stmt = $this->dbh->query($query); 
    850                     $this->_count++; 
     855                    $stmt = $this->_pdo->query($query); 
     856                    $this->_queryCount++; 
    851857                } 
    852858                $this->getAttribute(Doctrine::ATTR_LISTENER)->postQuery($event); 
     
    882888 
    883889                if ( ! $event->skipOperation) { 
    884                     $count = $this->dbh->exec($query); 
    885                     $this->_count++; 
     890                    $count = $this->_pdo->exec($query); 
     891                    $this->_queryCount++; 
    886892                } 
    887893                $this->getAttribute(Doctrine::ATTR_LISTENER)->postExec($event); 
     
    927933        //$this->getListener()->preError($event); 
    928934         
    929         $name = 'Doctrine_Connection_' . $this->driverName . '_Exception'; 
     935        $name = 'Doctrine_Connection_' . $this->_driverName . '_Exception'; 
    930936         
    931937        $exc = new $name($e->getMessage(), (int) $e->getCode()); 
     
    950956    public function count() 
    951957    { 
    952         return $this->_count; 
     958        return $this->_queryCount; 
    953959    } 
    954960     
     
    965971        $this->clear(); 
    966972 
    967         unset($this->dbh); 
    968         $this->isConnected = false; 
     973        unset($this->_pdo); 
     974        $this->_isConnected = false; 
    969975 
    970976        //$this->getAttribute(Doctrine::ATTR_LISTENER)->postClose($event); 
     
    991997        $this->connect(); 
    992998         
    993         return $this->dbh->errorCode(); 
     999        return $this->_pdo->errorCode(); 
    9941000    } 
    9951001 
     
    10041010        $this->connect(); 
    10051011         
    1006         return $this->dbh->errorInfo(); 
     1012        return $this->_pdo->errorInfo(); 
    10071013    } 
    10081014     
  • trunk/lib/Doctrine/Connection/Mock.php

    r4470 r4628  
    3939     * @var string $driverName                  the name of this connection driver 
    4040     */ 
    41     protected $driverName = 'MySql'; 
     41    protected $_driverName = 'Mysql'; 
    4242 
    4343    /** 
  • trunk/lib/Doctrine/Connection/Mysql.php

    r4523 r4628  
    4141     * @var string                 
    4242     */ 
    43     protected $driverName = 'Mysql'; 
     43    protected $_driverName = 'Mysql'; 
    4444 
    4545    /** 
     
    208208        return $this->exec($query); 
    209209    } 
     210     
     211    /** 
     212     * Constructs the MySql PDO DSN. 
     213     *  
     214     * Overrides Connection#_constructPdoDsn(). 
     215     * 
     216     * @return string  The DSN. 
     217     */ 
     218    protected function _constructPdoDsn() 
     219    { 
     220        $dsn = 'mysql:'; 
     221        if (isset($this->_params['host'])) { 
     222            $dsn .= 'host=' . $this->_params['host'] . ';'; 
     223        } 
     224        if (isset($this->_params['port'])) { 
     225            $dsn .= 'port=' . $this->_params['port'] . ';'; 
     226        } 
     227        if (isset($this->_params['dbname'])) { 
     228            $dsn .= 'dbname=' . $this->_params['dbname'] . ';'; 
     229        } 
     230        if (isset($this->_params['unix_socket'])) { 
     231            $dsn .= 'unix_socket=' . $this->_params['unix_socket'] . ';'; 
     232        } 
     233         
     234        return $dsn; 
     235    } 
    210236} 
  • trunk/lib/Doctrine/Connection/Sqlite.php

    r4523 r4628  
    3939     * @var string $driverName                  the name of this connection driver 
    4040     */ 
    41     protected $driverName = 'Sqlite'; 
     41    protected $_driverName = 'Sqlite'; 
    4242 
    4343    /** 
     
    6969                          'pattern_escaping'     => false, 
    7070                          ); 
     71                           
    7172        parent::__construct($params); 
    7273 
    73         if ($this->isConnected) { 
    74             $this->dbh->sqliteCreateFunction('mod', array('Doctrine_Expression_Sqlite', 'modImpl'), 2); 
    75             $this->dbh->sqliteCreateFunction('md5', 'md5', 1); 
    76             $this->dbh->sqliteCreateFunction('now', 'time', 0); 
     74        if ($this->_isConnected) { 
     75            $this->_pdo->sqliteCreateFunction('mod', array('Doctrine_Expression_Sqlite', 'modImpl'), 2); 
     76            $this->_pdo->sqliteCreateFunction('md5', 'md5', 1); 
     77            $this->_pdo->sqliteCreateFunction('now', 'time', 0); 
    7778        } 
    7879    } 
     
    8687    public function connect()  
    8788    { 
    88         if ($this->isConnected) { 
     89        if ($this->_isConnected) { 
    8990            return false; 
    9091        } 
     
    9293        parent::connect(); 
    9394 
    94         $this->dbh->sqliteCreateFunction('mod',    array('Doctrine_Expression_Sqlite', 'modImpl'), 2); 
    95         $this->dbh->sqliteCreateFunction('md5', 'md5', 1); 
    96         $this->dbh->sqliteCreateFunction('now', 'time', 0); 
     95        $this->_pdo->sqliteCreateFunction('mod', array('Doctrine_Expression_Sqlite', 'modImpl'), 2); 
     96        $this->_pdo->sqliteCreateFunction('md5', 'md5', 1); 
     97        $this->_pdo->sqliteCreateFunction('now', 'time', 0); 
    9798    } 
    9899 
     
    126127    public function dropDatabase() 
    127128    { 
    128       try { 
    129           if ( ! $dsn = $this->getOption('dsn')) { 
    130               throw new Doctrine_Connection_Exception('You must create your Doctrine_Connection by using a valid Doctrine style dsn in order to use the create/drop database functionality'); 
    131           } 
    132            
    133           $info = $this->getManager()->parseDsn($dsn); 
     129        try { 
     130            if ( ! $dsn = $this->getOption('dsn')) { 
     131                throw new Doctrine_Connection_Exception('You must create your Doctrine_Connection by using a valid Doctrine style dsn in order to use the create/drop database functionality'); 
     132            } 
    134133 
    135           $this->export->dropDatabase($info['database']); 
     134            $info = $this->getManager()->parseDsn($dsn); 
    136135 
    137           return 'Successfully dropped database for connection "' . $this->getName() . '" at path "' . $info['database'] . '"'; 
    138       } catch (Exception $e) { 
    139           return $e; 
    140       } 
     136            $this->export->dropDatabase($info['database']); 
     137 
     138            return 'Successfully dropped database for connection "' . $this->getName() . '" at path "' . $info['database'] . '"'; 
     139        } catch (Exception $e) { 
     140            return $e; 
     141        } 
     142    } 
     143     
     144    /** 
     145     * Constructs the Sqlite PDO DSN. 
     146     *  
     147     * Overrides Connection#_constructPdoDsn(). 
     148     * 
     149     * @return string  The DSN. 
     150     */ 
     151    protected function _constructPdoDsn() 
     152    { 
     153        $dsn = 'sqlite:'; 
     154        if (isset($this->_params['path'])) { 
     155            $dsn .= $this->_params['path']; 
     156        } else if (isset($this->_params['memory'])) { 
     157            $dsn .= ':memory:'; 
     158        } 
     159         
     160        return $dsn; 
    141161    } 
    142162} 
  • trunk/lib/Doctrine/Connection/UnitOfWork.php

    <
    r4523 r4628  
    2323 
    2424/** 
    25  * The UnitOfWork is responsible for writing out changes to the database at 
    26  * the correct time and in the correct order. 
     25 * The UnitOfWork is responsible for tracking changes to objects during an 
     26 * "object-level" transaction and for writing out changes to the database at 
     27 * in the correct order. 
    2728 *  
    2829 * Some terminology: 
     
    3031 * <b>New entity</b>: A new entity is an entity that already has an identity but 
    3132 * is not yet persisted into the database. This is usually the case for all 
    32  * newly saved entities that use a SEQUENCE id generator. Entities with an 
     33 * newly saved/persisted entities that use a SEQUENCE id generator. Entities with an 
    3334 * IDENTITY id generator get persisted as soon as they're saved in order to 
    3435 * obtain the identifier. Therefore entities that use an IDENTITY id generator 
    3536 * never appear in the list of new entities of the UoW. 
     37 * New entities are inserted into the database when the is UnitOfWork committed. 
    3638 *  
    3739 * <b>Dirty entity</b>: A dirty entity is a managed entity whose values have 
     
    5456 * @todo package:orm. Figure out a useful implementation. 
    5557 */ 
    56 class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module 
     58class Doctrine_Connection_UnitOfWork 
    5759{     
    5860    /** 
     
    9496     */ 
    9597    protected $_commitOrderCalculator; 
     98     
     99    /** 
     100     * Constructor. 
     101     * Created a new UnitOfWork. 
     102     * 
     103     * @param Doctrine_EntityManager $em 
     104     */ 
     105    public function __construct(Doctrine_EntityManager $em) 
     106    { 
     107        $this->_em = $em; 
     108    } 
    96109     
    97110    /** 
     
    202215 
    203216    /** 
    204      * buildFlushTree 
    205217     * builds a flush tree that is used in transactions 
    206218     * 
     
    302314     
    303315    /** 
    304      * saveAll 
    305316     * persists all the pending records from all tables 
    306317     * 
     
    309320     * @deprecated 
    310321     */ 
    311     public function saveAll() 
     322    /*public function saveAll()