Path: blob/master/src/infrastructure/storage/connection/AphrontDatabaseTransactionState.php
12241 views
<?php12/**3* Represents current transaction state of a connection.4*/5final class AphrontDatabaseTransactionState extends Phobject {67private $depth = 0;8private $readLockLevel = 0;9private $writeLockLevel = 0;1011public function getDepth() {12return $this->depth;13}1415public function increaseDepth() {16return ++$this->depth;17}1819public function decreaseDepth() {20if ($this->depth == 0) {21throw new Exception(22pht(23'Too many calls to %s or %s!',24'saveTransaction()',25'killTransaction()'));26}2728return --$this->depth;29}3031public function getSavepointName() {32return 'Aphront_Savepoint_'.$this->depth;33}3435public function beginReadLocking() {36$this->readLockLevel++;37return $this;38}3940public function endReadLocking() {41if ($this->readLockLevel == 0) {42throw new Exception(43pht(44'Too many calls to %s!',45__FUNCTION__.'()'));46}47$this->readLockLevel--;48return $this;49}5051public function isReadLocking() {52return ($this->readLockLevel > 0);53}5455public function beginWriteLocking() {56$this->writeLockLevel++;57return $this;58}5960public function endWriteLocking() {61if ($this->writeLockLevel == 0) {62throw new Exception(63pht(64'Too many calls to %s!',65__FUNCTION__.'()'));66}67$this->writeLockLevel--;68return $this;69}7071public function isWriteLocking() {72return ($this->writeLockLevel > 0);73}7475public function __destruct() {76if ($this->depth) {77throw new Exception(78pht(79'Process exited with an open transaction! The transaction '.80'will be implicitly rolled back. Calls to %s must always be '.81'paired with a call to %s or %s.',82'openTransaction()',83'saveTransaction()',84'killTransaction()'));85}86if ($this->readLockLevel) {87throw new Exception(88pht(89'Process exited with an open read lock! Call to %s '.90'must always be paired with a call to %s.',91'beginReadLocking()',92'endReadLocking()'));93}94if ($this->writeLockLevel) {95throw new Exception(96pht(97'Process exited with an open write lock! Call to %s '.98'must always be paired with a call to %s.',99'beginWriteLocking()',100'endWriteLocking()'));101}102}103104}105106107