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
파일 보기 프로젝트 열기: malkusch/lock

공개 메소드들

메소드 설명
__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.