コード例 #1
0
 /**
  * Converts the last record set into epObject object(s) with class map
  * @param epClassMap $cm the class map for the conversion
  * @param array (of integers) object ids to be excluded
  * @return false|array (of epObject)
  * @throws epExceptionDbObject
  */
 protected function _rs2obj($cm, $oids_ex = null)
 {
     // !!!important!!! with a large db, the list of oid to be excluded
     // $oids_ex can grown really large and can significantly slow down
     // queries. so it is suppressed in the select statement and moved
     // to this method to process.
     // get epManager instance and cache it
     if (!$this->ep_m) {
         $this->ep_m =& epManager::instance();
     }
     // get the class name
     $class = $cm->getName();
     // get all mapped vars
     if (!($fms = $cm->getAllFields())) {
         return self::$false;
     }
     // reset counter and return value
     $ret = array();
     // go through reach record
     $okay = $this->db->rsRestart();
     while ($okay) {
         // get oid column
         $oid = $this->db->rsGetCol($cn = $cm->getOidColumn(), $class . '.' . $cn);
         // exclude it?
         if ($oids_ex && in_array($oid, $oids_ex)) {
             // next row
             $okay = $this->db->rsNext();
             // exclude it
             continue;
         }
         // call epManager to create an instance (false: no caching; false: no event dispatching)
         if (!($o =& $this->ep_m->_create($class, false, false))) {
             // next row
             $okay = $this->db->rsNext();
             continue;
         }
         // go through each field
         foreach ($fms as $fname => $fm) {
             // skip non-primivite field
             if (!$fm->isPrimitive()) {
                 continue;
             }
             // get var value and set to object
             $val = $this->db->rsGetCol($cn = $fm->getColumnName(), $class . '.' . $cn);
             // set value to var (true: no dirty flag change)
             $o->epSet($fm->getName(), $this->_castType($val, $fm->getType()), true);
         }
         // set oid
         $o->epSetObjectId($oid);
         // collect return result
         $ret[] = $o;
         // next row
         $okay = $this->db->rsNext();
     }
     return $ret;
 }