PHP Класс malkusch\lock\mutex\TransactionalMutex

The critical code is executed within a transaction. The DBS will decide which parts of that code need to be locked (if at all). A failing transaction will be replayed.
Автор: Markus Malkusch ([email protected])
Наследование: extends Mutex
Показать файл Открыть проект

Открытые методы

Метод Описание
__construct ( PDO $pdo, integer $timeout = 3 ) Sets the PDO.
synchronized ( callable $code ) : mixed Executes the critical code within a transaction.

Приватные методы

Метод Описание
checkAutocommit ( PDO $pdo ) Checks that the AUTOCOMMIT mode is turned off.
hasPDOException ( Exception $exception ) : boolean Checks if an exception or any of its previous exceptions is a PDOException.
rollBack ( Exception $exception ) Rolls back a transaction.

Описание методов

__construct() публичный Метод

The PDO object MUST be configured with PDO::ATTR_ERRMODE to throw exceptions on errors. As this implementation spans a transaction over a unit of work, PDO::ATTR_AUTOCOMMIT SHOULD not be enabled.
public __construct ( PDO $pdo, integer $timeout = 3 )
$pdo PDO The PDO.
$timeout integer The timeout in seconds, default is 3.

synchronized() публичный Метод

It's up to the user to set the correct transaction isolation level. However if the transaction fails, the code will be executed again in a new transaction. Therefore the code must not have any side effects besides SQL statements. Also the isolation level should be conserved for the repeated transaction. A transaction is considered as failed if a PDOException or an exception which has a PDOException as any previous exception was raised. If the code throws any other exception, the transaction is rolled back and won't be replayed.
public synchronized ( callable $code ) : mixed
$code callable The synchronized execution block.
Результат mixed The return value of the execution block.