Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2012-24-10 Alexey S. Denisov
* main/Flow/CarefulDatabaseRunner.class.php
main/UnifiedContainer/UnifiedContainer.class.php:
CarefulDatabaseRunner and UnifiedContainer will use InnerTransaction

2012-24-10 Alexey S. Denisov
* global.inc.php.tpl
main/Autoloader/Autoloader.class.php
Expand Down
23 changes: 10 additions & 13 deletions main/Flow/CarefulDatabaseRunner.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
**/
final class CarefulDatabaseRunner implements CarefulCommand
{
private $command = null;
private $db = null;
private $command = null;
/**
* @var InnerTransaction
*/
private $transaction = null;

private $running = false;

Expand All @@ -33,9 +36,7 @@ public function run(Prototyped $subject, Form $form, HttpRequest $request)
Assert::isFalse($this->running, 'command already running');
Assert::isTrue($subject instanceof DAOConnected);

$this->db = DBPool::getByDao($subject->dao());

$this->db->begin();
$this->transaction = InnerTransaction::begin($subject->dao());

try {
$mav = $this->command->run($subject, $form, $request);
Expand All @@ -44,7 +45,7 @@ public function run(Prototyped $subject, Form $form, HttpRequest $request)

return $mav;
} catch (BaseException $e) {
$this->db->rollback();
$this->transaction->rollback();

throw $e;
}
Expand All @@ -58,7 +59,7 @@ public function run(Prototyped $subject, Form $form, HttpRequest $request)
public function commit()
{
if ($this->running) {
$this->db->commit();
$this->transaction->commit();
$this->running = false;
}

Expand All @@ -72,7 +73,7 @@ public function rollback()
{
if ($this->running) {
try {
$this->db->rollback();
$this->transaction->rollback();
} catch (DatabaseException $e) {
// keep silence
}
Expand All @@ -86,11 +87,7 @@ public function rollback()
public function __destruct()
{
if ($this->running) {
try {
$this->db->rollback();
} catch (BaseException $e) {
// fear of fatal error's
}
$this->rollback();
}
}
}
Expand Down
32 changes: 4 additions & 28 deletions main/UnifiedContainer/UnifiedContainer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,34 +299,10 @@ public function save()
}
}

$db = DBPool::getByDao($this->getDao());

if (!$db->inTransaction()) {
$outerQueue = $db->isQueueActive();

if (!$outerQueue)
$db->queueStart();

$db->begin();

try {
$this->worker->sync($insert, $update, $delete);

$db->commit();

if (!$outerQueue)
$db->queueFlush();
} catch (DatabaseException $e) {
if (!$outerQueue)
$db->queueDrop()->queueStop();

$db->rollback();

throw $e;
}
} else {
$this->worker->sync($insert, $update, $delete);
}
InnerTransactionWrapper::create()->
setDao($this->getDao())->
setFunction(array($this->worker, 'sync'))->
run($insert, $update, $delete);

$this->clones = array();
$this->syncClones();
Expand Down