Skip to content

Commit 3b60a2c

Browse files
committed
Merge pull request #103 from AlexeyDsov/innerTransactionUsing
CarefulDatabaseRunner and UnifiedContainer will use InnerTransaction
2 parents c4a49e4 + 37162c5 commit 3b60a2c

File tree

3 files changed

+19
-41
lines changed

3 files changed

+19
-41
lines changed

doc/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2012-24-10 Alexey S. Denisov
2+
* main/Flow/CarefulDatabaseRunner.class.php
3+
main/UnifiedContainer/UnifiedContainer.class.php:
4+
CarefulDatabaseRunner and UnifiedContainer will use InnerTransaction
5+
16
2012-24-10 Alexey S. Denisov
27
* global.inc.php.tpl
38
main/Autoloader/Autoloader.class.php

main/Flow/CarefulDatabaseRunner.class.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
1414
**/
1515
final class CarefulDatabaseRunner implements CarefulCommand
1616
{
17-
private $command = null;
18-
private $db = null;
17+
private $command = null;
18+
/**
19+
* @var InnerTransaction
20+
*/
21+
private $transaction = null;
1922

2023
private $running = false;
2124

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

36-
$this->db = DBPool::getByDao($subject->dao());
37-
38-
$this->db->begin();
39+
$this->transaction = InnerTransaction::begin($subject->dao());
3940

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

4546
return $mav;
4647
} catch (BaseException $e) {
47-
$this->db->rollback();
48+
$this->transaction->rollback();
4849

4950
throw $e;
5051
}
@@ -58,7 +59,7 @@ public function run(Prototyped $subject, Form $form, HttpRequest $request)
5859
public function commit()
5960
{
6061
if ($this->running) {
61-
$this->db->commit();
62+
$this->transaction->commit();
6263
$this->running = false;
6364
}
6465

@@ -72,7 +73,7 @@ public function rollback()
7273
{
7374
if ($this->running) {
7475
try {
75-
$this->db->rollback();
76+
$this->transaction->rollback();
7677
} catch (DatabaseException $e) {
7778
// keep silence
7879
}
@@ -86,11 +87,7 @@ public function rollback()
8687
public function __destruct()
8788
{
8889
if ($this->running) {
89-
try {
90-
$this->db->rollback();
91-
} catch (BaseException $e) {
92-
// fear of fatal error's
93-
}
90+
$this->rollback();
9491
}
9592
}
9693
}

main/UnifiedContainer/UnifiedContainer.class.php

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -299,34 +299,10 @@ public function save()
299299
}
300300
}
301301

302-
$db = DBPool::getByDao($this->getDao());
303-
304-
if (!$db->inTransaction()) {
305-
$outerQueue = $db->isQueueActive();
306-
307-
if (!$outerQueue)
308-
$db->queueStart();
309-
310-
$db->begin();
311-
312-
try {
313-
$this->worker->sync($insert, $update, $delete);
314-
315-
$db->commit();
316-
317-
if (!$outerQueue)
318-
$db->queueFlush();
319-
} catch (DatabaseException $e) {
320-
if (!$outerQueue)
321-
$db->queueDrop()->queueStop();
322-
323-
$db->rollback();
324-
325-
throw $e;
326-
}
327-
} else {
328-
$this->worker->sync($insert, $update, $delete);
329-
}
302+
InnerTransactionWrapper::create()->
303+
setDao($this->getDao())->
304+
setFunction(array($this->worker, 'sync'))->
305+
run($insert, $update, $delete);
330306

331307
$this->clones = array();
332308
$this->syncClones();

0 commit comments

Comments
 (0)