Show
Ignore:
Timestamp:
05/30/08 11:12:34 (4 months ago)
Author:
mikey
Message:

removed possibility of setting arguments via constructor on entities fetched from database: an entity's constructor should not require any arguments

Files:

Legend:

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

    r1311 r1611  
    8181     * get an entity from database by its primary keys 
    8282     * 
    83      * @param   stubBaseReflectionClass      $entityClass  class information about the entity 
    84      * @param   array                        $primaryKeys  list of primary keys (name => value) 
    85      * @param   array                        $arguments    arguments for the constructor 
     83     * @param   stubBaseReflectionClass   $entityClass  class information about the entity 
     84     * @param   array                     $primaryKeys  list of primary keys (name => value) 
    8685     * @return  object 
    8786     * @throws  stubPersistenceException 
    8887     */ 
    89     public function findByPrimaryKeys(stubBaseReflectionClass $entityClass, array $primaryKeys, array $arguments = null
     88    public function findByPrimaryKeys(stubBaseReflectionClass $entityClass, array $primaryKeys
    9089    { 
    9190        if ($entityClass->hasAnnotation('Entity') === false) { 
     
    9998        } 
    10099         
    101         $entity = ((null === $arguments) ? ($entityClass->newInstance()) : ($entityClass->newInstanceArgs($arguments))); 
     100        $entity = $entityClass->newInstance(); 
    102101        $setterMethodHelper->applySetterMethods($entity, $data); 
    103102        return $entity; 
     
    107106     * finds all instances of $entityClass by given criterion 
    108107     * 
    109      * @param   stubCriterion                $criterion 
    110      * @param   string                       $entityClass  entity class to find instances of 
    111      * @param   array                        $arguments    optional  arguments for constructor 
    112      * @return  stubDatabaseFinderResult     list of instances of $entityClass found with $criterion 
     108     * @param   stubCriterion             $criterion 
     109     * @param   string                    $entityClass  entity class to find instances of 
     110     * @return  stubDatabaseFinderResult  list of instances of $entityClass found with $criterion 
    113111     * @throws  stubPersistenceException 
    114112     */ 
    115     public function findByCriterion(stubCriterion $criterion, stubBaseReflectionClass $entityClass, array $arguments = null
     113    public function findByCriterion(stubCriterion $criterion, stubBaseReflectionClass $entityClass
    116114    { 
    117115        if ($entityClass->hasAnnotation('Entity') === false) { 
     
    121119        $setterMethodHelper = new stubSetterMethodHelper($entityClass); 
    122120        $data               = $this->fetchData($entityClass, $setterMethodHelper, $criterion); 
    123         $finderResult       = new stubDatabaseFinderResult($entityClass, $data, $setterMethodHelper, $arguments); 
     121        $finderResult       = new stubDatabaseFinderResult($entityClass, $data, $setterMethodHelper); 
    124122        return $finderResult; 
    125123    } 
     
    128126     * finds all instances of $entityClass 
    129127     * 
    130      * @param   string                       $entityClass  entity class to find instances of 
    131      * @param   array                        $arguments    optional  arguments for constructor 
    132      * @return  stubDatabaseFinderResult     list of instances of $entityClass found 
     128     * @param   string                    $entityClass  entity class to find instances of 
     129     * @return  stubDatabaseFinderResult  list of instances of $entityClass found 
    133130     * @throws  stubPersistenceException 
    134131     */ 
    135     public function findAll(stubBaseReflectionClass $entityClass, array $arguments = null
     132    public function findAll(stubBaseReflectionClass $entityClass
    136133    { 
    137134        if ($entityClass->hasAnnotation('Entity') === false) { 
     
    141138        $setterMethodHelper = new stubSetterMethodHelper($entityClass); 
    142139        $data               = $this->fetchData($entityClass, $setterMethodHelper); 
    143         $finderResult       = new stubDatabaseFinderResult($entityClass, $data, $setterMethodHelper, $arguments); 
     140        $finderResult       = new stubDatabaseFinderResult($entityClass, $data, $setterMethodHelper); 
    144141        return $finderResult; 
    145142    } 
  • trunk/src/main/php/net/stubbles/rdbms/persistence/finder/stubDatabaseFinderResult.php

    r1311 r1611  
    3636     */ 
    3737    protected $setterMethodHelper; 
    38     /** 
    39      * list of arguments for entity constructor 
    40      * 
    41      * @var  array<mixed> 
    42      */ 
    43     protected $arguments; 
    4438 
    4539    /** 
     
    4943     * @param  array                    $result              result set from the database query 
    5044     * @param  stubSetterMethodHelper   $setterMethodHelper  list of setter methods for entity 
    51      * @param  array                    $arguments           optional  list of arguments for entity constructor 
    5245     */ 
    53     public function __construct(stubBaseReflectionClass $entityClass, array $result, stubSetterMethodHelper $setterMethodHelper, array $arguments = null
     46    public function __construct(stubBaseReflectionClass $entityClass, array $result, stubSetterMethodHelper $setterMethodHelper
    5447    { 
    5548        $this->entityClass        = $entityClass; 
    5649        $this->resultIterator     = new ArrayIterator($result); 
    5750        $this->setterMethodHelper = $setterMethodHelper; 
    58         $this->arguments          = $arguments; 
    5951    } 
    6052 
     
    8880    { 
    8981        try { 
    90             $entity = ((null === $this->arguments) ? ($this->entityClass->newInstance()) : ($this->entityClass->newInstanceArgs($this->arguments))); 
     82            $entity = $this->entityClass->newInstance(); 
    9183        } catch (ReflectionException $re) { 
    9284            throw new stubDatabaseFinderException('Can not create a new instance of ' . $this->entityClass->getFullQualifiedClassName(), $re);