Changeset 5158 for branches/experimental

Show
Ignore:
Timestamp:
11/06/08 21:26:15 (2 months ago)
Author:
guilhermeblanco
Message:

Branched 1.1 and imported already done stuff for CTI implementation.

Location:
branches/experimental/gblanco
Files:
5 added
7 modified
1 copied

Legend:

Unmodified
Added
Removed
  • branches/experimental/gblanco

  • branches/experimental/gblanco/lib/Doctrine/Hydrator.php

    r5073 r5158  
    335335            } 
    336336 
    337             if ($cache[$key]['isSimpleType']) { 
    338                 $rowData[$dqlAlias][$fieldName] = $value; 
    339             } else { 
    340                 $rowData[$dqlAlias][$fieldName] = $table->prepareValue( 
    341                         $fieldName, $value, $cache[$key]['type']); 
     337            // CTI field assignment 
     338            $fieldValue = ($cache[$key]['isSimpleType']) ? $value  
     339                : $table->prepareValue($fieldName, $value, $cache[$key]['type']); 
     340 
     341            if (isset($map['joinedParentComponentAlias'])) {  
     342                $rowData[$map['joinedParentComponentAlias']][$table->getComponentName()][$fieldName] = $fieldValue;  
     343            } else {  
     344                $rowData[$dqlAlias][$fieldName] = $fieldValue; 
    342345            } 
    343346 
     
    346349            // So we know that all aggregate values will always be available in the root component 
    347350            if ($agg) { 
    348                 $rowData[$this->_rootAlias][$fieldName] = $rowData[$dqlAlias][$fieldName]; 
     351                $rowData[$this->_rootAlias][$fieldName] = $fieldValue; 
    349352            } 
    350353 
  • branches/experimental/gblanco/lib/Doctrine/Hydrator/RecordDriver.php

    r5016 r5158  
    7878    public function getElement(array $data, $component) 
    7979    { 
     80        $parentTable =  Doctrine::getTable($component); 
    8081        $component = $this->_getClassNameToReturn($data, $component); 
     82 
    8183        if ( ! isset($this->_tables[$component])) { 
    8284            $this->_tables[$component] = Doctrine::getTable($component); 
    8385            $this->_tables[$component]->setAttribute(Doctrine::ATTR_LOAD_REFERENCES, false); 
     86        } 
     87 
     88        $componentTable = $this->_tables[$component];  
     89 
     90        foreach($parentTable->getJoinedInheritanceMapChildren() as $child) {  
     91            if ( 
     92                    isset($data[$child]) &&  
     93                (in_array($child, $componentTable->getOption('joinedParents')) || $child == $componentTable->getComponentName()) 
     94            ) {  
     95                $data = array_merge($data, $data[$child]);  
     96            } 
     97 
     98            if (isset($data[$child])) {  
     99                unset($data[$child]);  
     100            }  
    84101        } 
    85102 
     
    151168            $this->_tables[$component]->setAttribute(Doctrine::ATTR_LOAD_REFERENCES, false); 
    152169        } 
     170 
     171        if (($joinedClasses = $this->_tables[$component]->getOption('joinedInheritanceMap'))) {  
     172            foreach ($joinedClasses as $class=>$conditions) {  
     173                list($key, $value) = each($conditions); 
     174  
     175                if (isset($data[$key]) && $data[$key] == $value) {  
     176                    return $class;  
     177                }   
     178            }  
     179        } 
    153180         
    154181        if ( ! ($subclasses = $this->_tables[$component]->getOption('subclasses'))) { 
  • branches/experimental/gblanco/lib/Doctrine/Query.php

    r5126 r5158  
    494494 
    495495        $fields = $this->_pendingFields[$componentAlias]; 
     496        $childFields = array(); 
    496497 
    497498        // check for wildcards 
    498499        if (in_array('*', $fields)) { 
    499500            $fields = $table->getFieldNames(); 
     501 
     502            // CTI fields lookup 
     503            if ($children = $table->getJoinedInheritanceMapChildren()) {  
     504                foreach ($children as $child) {  
     505                    $childTable = $this->_conn->getTable($child);  
     506                    $ownedColumns =  $childTable->getOwnedColumns();  
     507                    $childFields[$child] = $ownedColumns;  
     508                }  
     509            } 
    500510        } else { 
    501511            // only auto-add the primary key fields if this query object is not 
     
    509519 
    510520        $sql = array(); 
     521 
    511522        foreach ($fields as $fieldName) { 
    512523            $columnName = $table->getColumnName($fieldName); 
     
    526537                       . $this->_conn->quoteIdentifier($tableAlias . '__' . $columnName); 
    527538            } 
     539        } 
     540 
     541        // CTI fields inclusion in SQL 
     542        foreach ($childFields as $childTableName=>$childColumns) {  
     543            foreach ($childColumns as $fieldName) {  
     544                $columnName = $table->getColumnName($fieldName);  
     545                $child = $this->_conn->getTable($childTableName);  
     546                $columnName = $child->getColumnName($fieldName);  
     547                $childAlias = $this->getTableAlias($componentAlias . '.' . $child->getComponentName());  
     548                $sql[] = $this->_conn->quoteIdentifier($childAlias . '.' . $columnName)  
     549                       . ' AS '  
     550                       . $this->_conn->quoteIdentifier($childAlias . '__' . $columnName);  
     551            }  
    528552        } 
    529553 
     
    17901814        $this->_tableAliasMap[$tableAlias] = $componentAlias; 
    17911815 
     1816        $this->_queryComponents[$componentAlias] = array('table' => $table, 'map' => null); 
     1817 
    17921818        $queryPart .= $this->buildInheritanceJoinSql($name, $componentAlias); 
    17931819 
    17941820        $this->_sqlParts['from'][] = $queryPart; 
    1795  
    1796         $this->_queryComponents[$componentAlias] = array('table' => $table, 'map' => null); 
    17971821 
    17981822        return $table; 
     
    18261850            $parentTableAlias = $this->getTableAlias($parentAlias, $parentTable->getTableName()); 
    18271851 
    1828             $queryPart .= ' LEFT JOIN ' . $this->_conn->quoteIdentifier($parentTable->getTableName()) 
     1852            $queryPart .= ' INNER JOIN ' . $this->_conn->quoteIdentifier($parentTable->getTableName()) 
    18291853                        . ' ' . $this->_conn->quoteIdentifier($parentTableAlias) . ' ON '; 
    18301854 
     
    18381862                            . '.' . $this->_conn->quoteIdentifier($column); 
    18391863            } 
     1864        } 
     1865 
     1866        // CTI table relation join building 
     1867        if ($subchildren = $table->getJoinedInheritanceMapChildren()) {  
     1868            foreach ($subchildren as $subchild) {  
     1869                $subchildTable = $this->_conn->getTable($subchild);  
     1870                $subchildAlias = $componentAlias . '.' . $subchild;  
     1871 
     1872                // Get the short alias for the parent table  
     1873                $subchildTableAlias = $this->getTableAlias($subchildAlias, $subchildTable->getTableName());  
     1874                         
     1875                $queryPart .= ' LEFT JOIN ' . $this->_conn->quoteIdentifier($subchildTable->getTableName())  
     1876                           . ' ' . $this->_conn->quoteIdentifier($subchildTableAlias) . ' ON ';  
     1877 
     1878                $this->_queryComponents[$subchildAlias] = array('table' => $subchildTable, 'map' => null, 'joinedParentComponentAlias' => $componentAlias);  
     1879 
     1880                //Doctrine::dump($table->getIdentifier());  
     1881                foreach ((array) $table->getIdentifier() as $identifier) {  
     1882                    $column = $table->getColumnName($identifier);  
     1883 
     1884                    $queryPart .= $this->_conn->quoteIdentifier($tableAlias)   
     1885                               . '.' . $this->_conn->quoteIdentifier($column)  
     1886                               . ' = ' . $this->_conn->quoteIdentifier($subchildTableAlias)  
     1887                               . '.' . $this->_conn->quoteIdentifier($column);  
     1888                }  
     1889            }  
    18401890        } 
    18411891 
  • branches/experimental/gblanco/lib/Doctrine/Record.php

    r5098 r5158  
    15561556                    if ($this->_data[$field] instanceof Doctrine_Record) { 
    15571557                        $a[$field] = $this->_data[$field]->getIncremented(); 
     1558 
    15581559                        if ($a[$field] !== null) { 
    15591560                            $this->_data[$field] = $a[$field]; 
     
    15671568                    } 
    15681569                    */ 
     1570            } 
     1571        } 
     1572 
     1573        // CTI modified fields inclusion  
     1574        $map = $this->_table->joinedInheritanceMap; 
     1575 
     1576        if ($map != null) { 
     1577            $map = (isset($map[get_class($this)])) ? $map[get_class($this)] : array(); 
     1578        } else { 
     1579            $map = $this->_table->inheritanceMap; 
     1580        } 
     1581 
     1582        foreach ($map as $k => $v) { 
     1583            $old = $this->get($k, false); 
     1584 
     1585            if ((string) $old !== (string) $v || $old === null) { 
     1586                $a[$k] = $v; 
     1587                $this->_data[$k] = $v; 
    15691588            } 
    15701589        } 
  • branches/experimental/gblanco/lib/Doctrine/Record/Abstract.php

    r5033 r5158  
    147147    } 
    148148 
     149    public function setJoinedInheritanceMap($map)  
     150    {  
     151        $this->_table->setOption('joinedInheritanceMap', $map);  
     152    } 
     153 
    149154    public function setSubclasses($map) 
    150155    { 
  • branches/experimental/gblanco/tests/ClassTableInheritanceTestCase.php

    r4211 r5158  
    112112        $q->from('CTITest c')->where('c.id = 1'); 
    113113 
    114         $this->assertEqual($q->getSql(), 'SELECT c.id AS c__id, c3.added AS c__added, c2.name AS c__name, c2.verified AS c__verified, c.age AS c__age FROM c_t_i_test_parent4 c LEFT JOIN c_t_i_test_parent2 c2 ON c.id = c2.id LEFT JOIN c_t_i_test_parent3 c3 ON c.id = c3.id WHERE c.id = 1'); 
     114        $this->assertEqual($q->getSql(), 'SELECT c.id AS c__id, c3.added AS c__added, c2.name AS c__name, c2.verified AS c__verified, c.age AS c__age FROM c_t_i_test_parent4 c INNER JOIN c_t_i_test_parent2 c2 ON c.id = c2.id INNER JOIN c_t_i_test_parent3 c3 ON c.id = c3.id WHERE c.id = 1'); 
    115115 
    116116        $record = $q->fetchOne(); 
     
    128128        $q->from('CTITest c')->where("c.name = 'Jack'"); 
    129129 
    130         $this->assertEqual($q->getSql(), "SELECT c.id AS c__id, c3.added AS c__added, c2.name AS c__name, c2.verified AS c__verified, c.age AS c__age FROM c_t_i_test_parent4 c LEFT JOIN c_t_i_test_parent2 c2 ON c.id = c2.id LEFT JOIN c_t_i_test_parent3 c3 ON c.id = c3.id WHERE c2.name = 'Jack'"); 
     130        $this->assertEqual($q->getSql(), "SELECT c.id AS c__id, c3.added AS c__added, c2.name AS c__name, c2.verified AS c__verified, c.age AS c__age FROM c_t_i_test_parent4 c INNER JOIN c_t_i_test_parent2 c2 ON c.id = c2.id INNER JOIN c_t_i_test_parent3 c3 ON c.id = c3.id WHERE c2.name = 'Jack'"); 
    131131 
    132132        $q = new Doctrine_Query(); 
    133133        $q->from('CTITest c')->where("name = 'Jack'"); 
    134134 
    135         $this->assertEqual($q->getSql(), "SELECT c.id AS c__id, c3.added AS c__added, c2.name AS c__name, c2.verified AS c__verified, c.age AS c__age FROM c_t_i_test_parent4 c LEFT JOIN c_t_i_test_parent2 c2 ON c.id = c2.id LEFT JOIN c_t_i_test_parent3 c3 ON c.id = c3.id WHERE c2.name = 'Jack'"); 
     135        $this->assertEqual($q->getSql(), "SELECT c.id AS c__id, c3.added AS c__added, c2.name AS c__name, c2.verified AS c__verified, c.age AS c__age FROM c_t_i_test_parent4 c INNER JOIN c_t_i_test_parent2 c2 ON c.id = c2.id INNER JOIN c_t_i_test_parent3 c3 ON c.id = c3.id WHERE c2.name = 'Jack'"); 
    136136    } 
    137137 
  • branches/experimental/gblanco/tests/run.php

    r5122 r5158  
    258258$inheritance->addTestCase(new Doctrine_ColumnAggregationInheritance_TestCase()); 
    259259$inheritance->addTestCase(new Doctrine_ClassTableInheritance_TestCase()); 
     260$inheritance->addTestCase(new Doctrine_NewClassTableInheritance_TestCase()); 
     261$inheritance->addTestCase(new Doctrine_CTITreeStructure_TestCase()); 
     262$inheritance->addTestCase(new Doctrine_CTII18n_TestCase()); 
    260263$inheritance->addTestCase(new Doctrine_Query_ApplyInheritance_TestCase()); 
    261264$test->addTestCase($inheritance);