Skip to content

Commit 19c129d

Browse files
committed
Add adapter capability methods for transaction support
1 parent b2cc352 commit 19c129d

File tree

5 files changed

+46
-3
lines changed

5 files changed

+46
-3
lines changed

src/Database/Adapter.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,4 +1529,18 @@ public function getSupportForTTLIndexes(): bool
15291529
{
15301530
return false;
15311531
}
1532+
1533+
/**
1534+
* Does the adapter support transaction retries?
1535+
*
1536+
* @return bool
1537+
*/
1538+
abstract public function getSupportForTransactionRetries(): bool;
1539+
1540+
/**
1541+
* Does the adapter support nested transactions?
1542+
*
1543+
* @return bool
1544+
*/
1545+
abstract public function getSupportForNestedTransactions(): bool;
15321546
}

src/Database/Adapter/Mongo.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3692,6 +3692,16 @@ public function getSupportForTTLIndexes(): bool
36923692
return true;
36933693
}
36943694

3695+
public function getSupportForTransactionRetries(): bool
3696+
{
3697+
return false;
3698+
}
3699+
3700+
public function getSupportForNestedTransactions(): bool
3701+
{
3702+
return false;
3703+
}
3704+
36953705
protected function isExtendedISODatetime(string $val): bool
36963706
{
36973707
/**

src/Database/Adapter/Pool.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,4 +703,14 @@ public function getSupportForTTLIndexes(): bool
703703
{
704704
return $this->delegate(__FUNCTION__, \func_get_args());
705705
}
706+
707+
public function getSupportForTransactionRetries(): bool
708+
{
709+
return $this->delegate(__FUNCTION__, \func_get_args());
710+
}
711+
712+
public function getSupportForNestedTransactions(): bool
713+
{
714+
return $this->delegate(__FUNCTION__, \func_get_args());
715+
}
706716
}

src/Database/Adapter/SQL.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3577,4 +3577,14 @@ public function getLockType(): string
35773577

35783578
return '';
35793579
}
3580+
3581+
public function getSupportForTransactionRetries(): bool
3582+
{
3583+
return true;
3584+
}
3585+
3586+
public function getSupportForNestedTransactions(): bool
3587+
{
3588+
return true;
3589+
}
35803590
}

tests/e2e/Adapter/Scopes/GeneralTests.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Utopia\Cache\Adapter\Redis as RedisAdapter;
88
use Utopia\Cache\Cache;
99
use Utopia\CLI\Console;
10-
use Utopia\Database\Adapter\Mongo;
1110
use Utopia\Database\Database;
1211
use Utopia\Database\Document;
1312
use Utopia\Database\Exception as DatabaseException;
@@ -907,7 +906,7 @@ public function testTransactionStateAfterRetriesExhausted(): void
907906
/** @var Database $database */
908907
$database = $this->getDatabase();
909908

910-
if ($database->getAdapter() instanceof Mongo) {
909+
if (!$database->getAdapter()->getSupportForTransactionRetries()) {
911910
$this->expectNotToPerformAssertions();
912911
return;
913912
}
@@ -945,7 +944,7 @@ public function testNestedTransactionState(): void
945944
/** @var Database $database */
946945
$database = $this->getDatabase();
947946

948-
if ($database->getAdapter() instanceof Mongo) {
947+
if (!$database->getAdapter()->getSupportForNestedTransactions()) {
949948
$this->expectNotToPerformAssertions();
950949
return;
951950
}

0 commit comments

Comments
 (0)