Changeset 333

Show
Ignore:
Timestamp:
03/04/07 13:29:05 (2 years ago)
Author:
mikey
Message:

enabled ordering of columns

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/main/php/net/stubbles/rdbms/persistence/annotations/stubDBColumnAnnotation.php

    r246 r333  
    1919{ 
    2020    /** 
     21     * order of column within table 
     22     * 
     23     * @var  int 
     24     */ 
     25    protected $order        = 0; 
     26    /** 
    2127     * name of the column 
    2228     * 
     
    8187    { 
    8288        return stubAnnotation::TARGET_METHOD; 
     89    } 
     90     
     91    /** 
     92     * set the order within the table 
     93     * 
     94     * @param  int  $order 
     95     */ 
     96    public function setOrder($order) 
     97    { 
     98        $this->order = $order; 
     99    } 
     100     
     101    /** 
     102     * returns the order within the table 
     103     * 
     104     * @return  int 
     105     */ 
     106    public function getOrder() 
     107    { 
     108        return $this->order; 
    83109    } 
    84110     
  • trunk/src/main/php/net/stubbles/rdbms/persistence/creator/stubDatabaseCreator.php

    r324 r333  
    104104        $methods = $refClass->getMethods(); 
    105105        foreach ($methods as $method) { 
    106             if ($method->hasAnnotation('DBColumn') == false || $method->getDeclaringClass()->equals($refClass) == false) { 
     106            if ($method->hasAnnotation('DBColumn') == false) { 
    107107                continue; 
    108108            } elseif ($method->hasAnnotation('DBTable') == true && $method->getAnnotation('DBTable')->getName() != $tableDescription->getName()) { 
     
    112112            $dbColumn = $method->getAnnotation('DBColumn'); 
    113113            $columnDescription = new stubDatabaseTableColumn(); 
     114            $columnDescription->setOrder($dbColumn->getOrder()); 
    114115            $columnDescription->setName($dbColumn->getName()); 
    115116            $columnDescription->setType($dbColumn->getType()); 
  • trunk/src/main/php/net/stubbles/rdbms/querybuilder/stubDatabaseTableColumn.php

    r316 r333  
    1616{ 
    1717    /** 
     18     * order of column within table 
     19     * 
     20     * @var  int 
     21     */ 
     22    protected $order        = 0; 
     23    /** 
    1824     * name of the table 
    1925     * 
     
    7581     */ 
    7682    protected $isKey        = false; 
     83     
     84    /** 
     85     * set the order within the table 
     86     * 
     87     * @param  int  $order 
     88     */ 
     89    public function setOrder($order) 
     90    { 
     91        $this->order = $order; 
     92    } 
     93     
     94    /** 
     95     * returns the order within the table 
     96     * 
     97     * @return  int 
     98     */ 
     99    public function getOrder() 
     100    { 
     101        return $this->order; 
     102    } 
    77103     
    78104    /** 
  • trunk/src/main/php/net/stubbles/rdbms/querybuilder/stubDatabaseTableDescription.php

    r316 r333  
    2525     * columns of the table 
    2626     * 
    27      * @var  array<string,stubDatabaseTableColumn> 
     27     * @var  array<int,stubDatabaseTableColumn> 
    2828     */ 
    2929    protected $columns      = array(); 
    3030    /** 
     31     * columns of table sorted by name 
     32     * 
     33     * @var  array<string> 
     34     */ 
     35    protected $columnNames  = array(); 
     36    /** 
     37     * the column order counter 
     38     * 
     39     * @var  int 
     40     */ 
     41    protected $columnOrder  = 1; 
     42    /** 
    3143     * type of the table 
    3244     * 
     
    8092    public function addColumn(stubDatabaseTableColumn $column) 
    8193    { 
    82         $this->columns[$column->getName()] = $column; 
     94        if (in_array($column->getName(), $this->columnNames) == true) { 
     95            throw new stubDatabaseException('The column ' . $column->getName() . ' already exists in table ' . $this->getName()); 
     96        } 
     97         
     98        $this->columnNames[] = $column->getName(); 
     99        $order = $column->getOrder(); 
     100        if (0 == $order) { 
     101            $order = $this->columnOrder; 
     102            $this->columnOrder++; 
     103        } 
     104         
     105        if (isset($this->columns[$order]) == true) { 
     106            throw new stubDatabaseException('Can not add column ' . $column->getName() . ' with order ' . $order . ', there is already column ' . $this->columns[$order]->getName() . ' at this place.'); 
     107        } 
     108         
     109        $this->columns[$order] = $column; 
    83110    } 
    84111     
     
    90117    public function getColumns() 
    91118    { 
     119        ksort($this->columns); 
    92120        return $this->columns; 
    93121    }