示例#1
0
 /**
  * Stores a cleaned bean; i.e. only scalar values. This is the core of the store()
  * method. When all lists and embedded beans (parent objects) have been processed and
  * removed from the original bean the bean is passed to this method to be stored
  * in the database.
  *
  * @param OODBBean $bean the clean bean
  *
  * @return void
  */
 private function storeBean(OODBBean $bean)
 {
     if ($bean->getMeta('tainted')) {
         if (!$this->isFrozen) {
             $this->check($bean);
             $table = $bean->getMeta('type');
             $this->createTableIfNotExists($bean, $table);
             $updateValues = $this->getUpdateValues($bean);
             $this->addUniqueConstraints($bean);
             $bean->id = $this->writer->updateRecord($table, $updateValues, $bean->id);
             $bean->setMeta('tainted', FALSE);
         } else {
             list($properties, $table) = $bean->getPropertiesAndType();
             $id = $properties['id'];
             unset($properties['id']);
             $updateValues = array();
             $k1 = 'property';
             $k2 = 'value';
             foreach ($properties as $key => $value) {
                 $updateValues[] = array($k1 => $key, $k2 => $value);
             }
             $bean->id = $this->writer->updateRecord($table, $updateValues, $id);
             $bean->setMeta('tainted', FALSE);
         }
     }
 }