Remove product literal strings in "pht()", part 18
[phabricator.git] / src / infrastructure / storage / connection / AphrontDatabaseTransactionState.php
blob67f8b5b65bbdf3b6952babba1d25cd3591f1d317
1 <?php
3 /**
4 * Represents current transaction state of a connection.
5 */
6 final class AphrontDatabaseTransactionState extends Phobject {
8 private $depth = 0;
9 private $readLockLevel = 0;
10 private $writeLockLevel = 0;
12 public function getDepth() {
13 return $this->depth;
16 public function increaseDepth() {
17 return ++$this->depth;
20 public function decreaseDepth() {
21 if ($this->depth == 0) {
22 throw new Exception(
23 pht(
24 'Too many calls to %s or %s!',
25 'saveTransaction()',
26 'killTransaction()'));
29 return --$this->depth;
32 public function getSavepointName() {
33 return 'Aphront_Savepoint_'.$this->depth;
36 public function beginReadLocking() {
37 $this->readLockLevel++;
38 return $this;
41 public function endReadLocking() {
42 if ($this->readLockLevel == 0) {
43 throw new Exception(
44 pht(
45 'Too many calls to %s!',
46 __FUNCTION__.'()'));
48 $this->readLockLevel--;
49 return $this;
52 public function isReadLocking() {
53 return ($this->readLockLevel > 0);
56 public function beginWriteLocking() {
57 $this->writeLockLevel++;
58 return $this;
61 public function endWriteLocking() {
62 if ($this->writeLockLevel == 0) {
63 throw new Exception(
64 pht(
65 'Too many calls to %s!',
66 __FUNCTION__.'()'));
68 $this->writeLockLevel--;
69 return $this;
72 public function isWriteLocking() {
73 return ($this->writeLockLevel > 0);
76 public function __destruct() {
77 if ($this->depth) {
78 throw new Exception(
79 pht(
80 'Process exited with an open transaction! The transaction '.
81 'will be implicitly rolled back. Calls to %s must always be '.
82 'paired with a call to %s or %s.',
83 'openTransaction()',
84 'saveTransaction()',
85 'killTransaction()'));
87 if ($this->readLockLevel) {
88 throw new Exception(
89 pht(
90 'Process exited with an open read lock! Call to %s '.
91 'must always be paired with a call to %s.',
92 'beginReadLocking()',
93 'endReadLocking()'));
95 if ($this->writeLockLevel) {
96 throw new Exception(
97 pht(
98 'Process exited with an open write lock! Call to %s '.
99 'must always be paired with a call to %s.',
100 'beginWriteLocking()',
101 'endWriteLocking()'));