Esempio n. 1
0
 /**
  *
  *
  * @param object $entity
  * @return {string:mixed}
  */
 private function exportEntity($entity)
 {
     $row = $this->entityExporter->export($this->entityMetadata, $entity);
     // Remove primary key columns from updatable columns
     foreach ($this->entityMetadata->getPrimaryKey()->getColumns() as $column) {
         $columnName = $column->getColumnName();
         unset($row[$columnName]);
     }
     if (count($row) < 1) {
         throw new \RuntimeException('Nothing to update.');
     }
     return $row;
 }
Esempio n. 2
0
 /**
  * Inserts provided entity into storage.
  *
  * @param object $entity
  * @return void
  * @throws \DomainException
  * @throws \RuntimeException
  */
 public function insert($entity)
 {
     $entityMetadata = $this->getEntityMetadata($entity);
     $storage = $entityMetadata->getStorage();
     $connectionId = $storage->getConnectionId();
     $connection = $this->getConnection($connectionId);
     $dbTable = $storage->getTable();
     $row = $this->entityExporter->export($entityMetadata, $entity);
     $sqlTable = $connection->escapeAndQuoteTable($dbTable);
     $sqlFields = array();
     $sqlTokens = array();
     $parameters = array();
     foreach ($row as $columnName => $value) {
         $sqlFields[] = $connection->escapeAndQuoteField($columnName);
         $sqlTokens[] = '?';
         $parameters[] = $value;
     }
     $sql = "INSERT INTO {$sqlTable} (" . join(', ', $sqlFields) . ") VALUES (" . join(', ', $sqlTokens) . ")";
     $connection->execute($sql, $parameters);
     $entityMetadata->getPrimaryKey()->bind($connection, $entity);
 }