public function commit()
{
if (!$this->driverTransaction->isOpen() && !in_array($this->driverTransaction->status(), ['COMMITED', 'ROLLED_BACK'])) {
$this->driverTransaction->begin();
}
if (!empty($this->queue)) {
$stack = [];
foreach ($this->queue as $element) {
if ($element instanceof StackInterface) {
foreach ($element->statements() as $statement) {
$stack[] = $statement;
}
} else {
$stack[] = $element;
}
}
$result = $this->driverTransaction->runMultiple($stack);
$this->driverTransaction->commit();
$this->queue = [];
return $result;
}
return $this->driverTransaction->commit();
}