Skip to content

Commit 0896c70

Browse files
committed
ADD Transaction stacking count support.
1 parent 0d05a5d commit 0896c70

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

src/DatabaseHandler.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class DatabaseHandler
3030
private $nestTranslator;
3131
private $nestMerger;
3232

33+
private $transactionStack = 0;
34+
3335
public function __construct(DriverInterface $driver)
3436
{
3537
$this->driver = $driver;
@@ -269,7 +271,15 @@ public function executeUpsert(UpsertQuery $query): UpsertResult
269271
*/
270272
public function startTransaction()
271273
{
272-
return $this->driver->startTransaction();
274+
$tx = true;
275+
if ($this->transactionStack == 0) {
276+
$tx = $this->driver->startTransaction();
277+
}
278+
if ($tx) {
279+
$this->transactionStack++;
280+
}
281+
return $tx;
282+
273283
}
274284

275285
/**
@@ -291,7 +301,14 @@ public function inTransaction()
291301
*/
292302
public function rollback()
293303
{
294-
return $this->driver->rollback();
304+
$rb = true;
305+
if ($this->transactionStack > 0) {
306+
$rb = $this->driver->rollback();
307+
}
308+
if ($rb) {
309+
$this->transactionStack = 0;
310+
}
311+
return $rb;
295312
}
296313

297314
/**
@@ -302,6 +319,13 @@ public function rollback()
302319
*/
303320
public function commit()
304321
{
305-
return $this->driver->commit();
322+
$cm = true;
323+
if ($this->transactionStack == 1) {
324+
$cm = $this->driver->commit();
325+
}
326+
if ($cm) {
327+
$this->transactionStack = max(0, $this->transactionStack - 1);
328+
}
329+
return $cm;
306330
}
307331
}

0 commit comments

Comments
 (0)