protected function processMySQLAutoupdate(IEntity $entity, array $args) { $this->connection->queryArgs($args); $primary = []; $id = (array) ($entity->isPersisted() ? $entity->getPersistedId() : $this->connection->getLastInsertedId()); foreach ($this->getStorageReflection()->getStoragePrimaryKey() as $key) { $primary[$key] = array_shift($id); } $row = $this->connection->query('SELECT %ex FROM %table WHERE %and', $this->getAutoupdateReselectExpression(), $this->getTableName(), $primary)->fetch(); $data = $this->getStorageReflection()->convertStorageToEntity($row->toArray()); $entity->fireEvent('onRefresh', [$data]); }
public function persist(IEntity $entity) { $this->beginTransaction(); $data = $this->entityToArray($entity); $data = $this->getStorageReflection()->convertEntityToStorage($data); if (!$entity->isPersisted()) { $this->connection->query('INSERT INTO %table %values', $this->getTableName(), $data); return $entity->hasValue('id') ? $entity->getValue('id') : $this->connection->getLastInsertedId($this->getStorageReflection()->getPrimarySequenceName()); } else { $primary = []; $id = (array) $entity->getPersistedId(); foreach ($this->getStorageReflection()->getStoragePrimaryKey() as $key) { $primary[$key] = array_shift($id); } $this->connection->query('UPDATE %table SET %set WHERE %and', $this->getTableName(), $data, $primary); return $entity->getPersistedId(); } }