예제 #1
0
 /**
  * Find matching objects.
  */
 function query()
 {
     $sql = new SQLGenerator($this->example->getCore());
     $ds = $this->example->datasource;
     $sb = $this->example->storage_method->config->copyObject();
     if (!is_null($this->joinedExamples)) {
         foreach ($this->joinedExamples as $je) {
             $sb->joinTo($je->storage_method->config, TRUE);
         }
     }
     $ds->connect();
     $res = $ds->query($sql->select($sb, $this->getCore()));
     $cs =& $res->getNext();
     $rv = array();
     while ($cs) {
         $score =& $cs->getCore();
         assert(is_array($score));
         $clone = $this->example;
         // copy
         $clone->is_loaded = TRUE;
         $clone->set($score);
         $rv[] = $clone;
         $cs =& $res->getNext();
     }
     return $rv;
 }
예제 #2
0
 /**
  * Implementation of load and import varies only slight, so both
  * methods refer to this helper method.
  * @param bool $do_load TRUE for load, FALSE for import.
  * @param ChunsuObject $loadme The object to load.
  * @param DataSource $source The data source to load the object from.
  * @return bool TRUE is successful, FALSE otherwise.
  */
 function loadOrImport($do_load, &$loadme, $source)
 {
     $pkfield =& $this->config->get('primary-key');
     $pka =& $pkfield->get('alias');
     $core =& $loadme->getCore();
     if (is_array($core) || is_object($core)) {
         $dummy =& $loadme->getDummy();
         $pkval = $dummy->get($pka);
     } else {
         $pkval = $core;
     }
     if (!is_null($pkval)) {
         $gen = new SQLGenerator($loadme->getCore());
         $cursor = $source->query($gen->select($this->config));
         if ($cursor->getNext()) {
             $rec =& $cursor->get();
             if ($do_load) {
                 $loadme->setref($rec);
                 $loadme->is_new = FALSE;
             } else {
                 $loadme->bulkSet($rec);
             }
             return TRUE;
             // TODO: keep reading and handle conflicts if >1 record
         }
     }
     if (!$loadme->config->get('create-on-save')) {
         LogError("Cannot load object: no records found.\n" . $loadme->trace());
         LogFatal("Cannot load object: no records found. ");
     }
     return TRUE;
 }