public function persist(IEntity $entity)
{
$this->beginTransaction();
$data = $this->entityToArray($entity);
$data = $this->getStorageReflection()->convertEntityToStorage($data);
if (!$entity->isPersisted()) {
$this->processInsert($entity, $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->processUpdate($entity, $data, $primary);
return $entity->getPersistedId();
}
}