/usr/local/miolo2/classes/persistence/cursor.class

Go to the documentation of this file.
00001 <?php
00002 
00003 class Cursor
00004 {
00005     private $position;
00006 
00007     private $rows;
00008     private $classMap;
00009     private $proxy;
00010     private $size;
00011     private $manager;
00012     private $baseObject;
00013 
00014     public function __construct($query, Classmap $classMap, $proxy = FALSE, PersistentManager $manager)
00015     {
00016         $this->position = 0;
00017         $this->query = $query;
00018         $this->query->moveFirst();
00019         $this->rows = $query->result;
00020         $this->size = (is_array($result)) ? count($result) : 0;
00021         $this->classMap = $classMap;
00022         $this->baseObject = $this->classMap->getObject();
00023         $this->proxy = $proxy;
00024         $this->manager = $manager;
00025     }
00026 
00027     public function getRow()
00028     {
00029         $row = NULL;
00030         if (!$this->query->eof())
00031         {
00032             $row = $this->query->getRowValues();
00033             $this->query->moveNext();
00034         }
00035         return $row;
00036     }
00037  
00038     public function retrieveObject($object)
00039     {
00040         if ($this->proxy)
00041             $this->classMap->retrieveProxyObject($object, $this->query);
00042         else
00043             $this->classMap->retrieveObject($object, $this->query);
00044 
00045         // Associations
00046         if ($this->classMap->getAssociationSize() > 0)
00047         {
00048             $db = $this->manager->getConnection($this->classMap->getDatabase());
00049             $this->manager->_retrieveAssociations($object, $this->classMap, $db);
00050         }
00051     }
00052 
00053     public function getObject()
00054     {
00055         $object = NULL;
00056         if (!$this->query->eof())
00057         {
00058             if ($this->baseObject == NULL)
00059             {
00060                 $object = $this->getRow();
00061             }
00062             else
00063             {
00064                 $object = clone $this->baseObject;
00065                 $this->retrieveObject($object);
00066             }
00067             $this->query->moveNext();
00068         }
00069         return $object;
00070     }
00071 
00072     public function getObjects()
00073     {
00074         $array = array();
00075         $this->query->moveFirst();
00076         while (!$this->query->eof())
00077         {
00078             $object = clone $this->baseObject;
00079             $this->retrieveObject($object);
00080             $array[] = $object;
00081             $this->query->moveNext();
00082         }
00083         return $array;
00084     }
00085 
00086     public function getSize()
00087     {
00088         return $this->size;
00089     }
00090 }
00091 ?>
CopyLeft (L) 2001-2006 - [MIOLO Development Team] SOLIS - Cooperativa de Soluções Livres - Lajeado/RS - Brasil