transactionManager = $transactionManager; if (!$queryComposer instanceof MysqlQueryComposer) { throw new RuntimeException(); } $this->queryComposer = $queryComposer; } /** * {@inheritdoc} */ public function isLocked(): bool { return $this->isLocked; } /** * {@inheritdoc} */ public function lockExclusive(string $entityType): void { $this->isLocked = true; $query = (new LockTableBuilder()) ->table($entityType) ->inExclusiveMode() ->build(); $sql = $this->queryComposer->composeLockTable($query); $this->pdo->exec($sql); } /** * {@inheritdoc} */ public function lockShare(string $entityType): void { $this->isLocked = true; $query = (new LockTableBuilder()) ->table($entityType) ->inShareMode() ->build(); $sql = $this->queryComposer->composeLockTable($query); $this->pdo->exec($sql); } /** * {@inheritdoc} */ public function commit(): void { if (!$this->isLocked) { throw new RuntimeException("Can't commit, it was not locked."); } $this->isLocked = false; $sql = $this->queryComposer->composeUnlockTables(); $this->pdo->exec($sql); } /** * Lift locking. * Rolling back within locking is not supported for MySQL. */ public function rollback(): void { if (!$this->isLocked) { throw new RuntimeException("Can't rollback, it was not locked."); } $this->isLocked = false; $sql = $this->queryComposer->composeUnlockTables(); $this->pdo->exec($sql); } }