1 | <?php |
||
46 | class Transaction extends \yii\base\BaseObject |
||
47 | { |
||
48 | /** |
||
49 | * A constant representing the transaction isolation level `READ UNCOMMITTED`. |
||
50 | * @see http://en.wikipedia.org/wiki/Isolation_%28database_systems%29#Isolation_levels |
||
51 | */ |
||
52 | const READ_UNCOMMITTED = 'READ UNCOMMITTED'; |
||
53 | /** |
||
54 | * A constant representing the transaction isolation level `READ COMMITTED`. |
||
55 | * @see http://en.wikipedia.org/wiki/Isolation_%28database_systems%29#Isolation_levels |
||
56 | */ |
||
57 | const READ_COMMITTED = 'READ COMMITTED'; |
||
58 | /** |
||
59 | * A constant representing the transaction isolation level `REPEATABLE READ`. |
||
60 | * @see http://en.wikipedia.org/wiki/Isolation_%28database_systems%29#Isolation_levels |
||
61 | */ |
||
62 | const REPEATABLE_READ = 'REPEATABLE READ'; |
||
63 | /** |
||
64 | * A constant representing the transaction isolation level `SERIALIZABLE`. |
||
65 | * @see http://en.wikipedia.org/wiki/Isolation_%28database_systems%29#Isolation_levels |
||
66 | */ |
||
67 | const SERIALIZABLE = 'SERIALIZABLE'; |
||
68 | |||
69 | /** |
||
70 | * @var Connection the database connection that this transaction is associated with. |
||
71 | */ |
||
72 | public $db; |
||
73 | |||
74 | /** |
||
75 | * @var int the nesting level of the transaction. 0 means the outermost level. |
||
76 | */ |
||
77 | private $_level = 0; |
||
78 | |||
79 | |||
80 | public function __construct(Connection $db) |
||
84 | |||
85 | /** |
||
86 | * Returns a value indicating whether this transaction is active. |
||
87 | * @return bool whether this transaction is active. Only an active transaction |
||
88 | * can [[commit()]] or [[rollBack()]]. |
||
89 | */ |
||
90 | public function getIsActive() |
||
94 | |||
95 | /** |
||
96 | * Begins a transaction. |
||
97 | * @param string|null $isolationLevel The [isolation level][] to use for this transaction. |
||
98 | * This can be one of [[READ_UNCOMMITTED]], [[READ_COMMITTED]], [[REPEATABLE_READ]] and [[SERIALIZABLE]] but |
||
99 | * also a string containing DBMS specific syntax to be used after `SET TRANSACTION ISOLATION LEVEL`. |
||
100 | * If not specified (`null`) the isolation level will not be set explicitly and the DBMS default will be used. |
||
101 | * |
||
102 | * > Note: This setting does not work for PostgreSQL, where setting the isolation level before the transaction |
||
103 | * has no effect. You have to call [[setIsolationLevel()]] in this case after the transaction has started. |
||
104 | * |
||
105 | * > Note: Some DBMS allow setting of the isolation level only for the whole connection so subsequent transactions |
||
106 | * may get the same isolation level even if you did not specify any. When using this feature |
||
107 | * you may need to set the isolation level for all transactions explicitly to avoid conflicting settings. |
||
108 | * At the time of this writing affected DBMS are MSSQL and SQLite. |
||
109 | * |
||
110 | * [isolation level]: http://en.wikipedia.org/wiki/Isolation_%28database_systems%29#Isolation_levels |
||
111 | * |
||
112 | * Starting from version 2.0.16, this method throws exception when beginning nested transaction and underlying DBMS |
||
113 | * does not support savepoints. |
||
114 | * @throws InvalidConfigException if [[db]] is `null` |
||
115 | * @throws NotSupportedException if the DBMS does not support nested transactions |
||
116 | * @throws Exception if DB connection fails |
||
117 | */ |
||
118 | public function begin($isolationLevel = null) |
||
148 | |||
149 | /** |
||
150 | * Commits a transaction. |
||
151 | * @throws Exception if the transaction is not active |
||
152 | */ |
||
153 | public function commit() |
||
175 | |||
176 | /** |
||
177 | * Rolls back a transaction. |
||
178 | */ |
||
179 | public function rollBack() |
||
203 | |||
204 | /** |
||
205 | * Sets the transaction isolation level for this transaction. |
||
206 | * |
||
207 | * This method can be used to set the isolation level while the transaction is already active. |
||
208 | * However this is not supported by all DBMS so you might rather specify the isolation level directly |
||
209 | * when calling [[begin()]]. |
||
210 | * @param string $level The transaction isolation level to use for this transaction. |
||
211 | * This can be one of [[READ_UNCOMMITTED]], [[READ_COMMITTED]], [[REPEATABLE_READ]] and [[SERIALIZABLE]] but |
||
212 | * also a string containing DBMS specific syntax to be used after `SET TRANSACTION ISOLATION LEVEL`. |
||
213 | * @throws Exception if the transaction is not active |
||
214 | * @see http://en.wikipedia.org/wiki/Isolation_%28database_systems%29#Isolation_levels |
||
215 | */ |
||
216 | public function setIsolationLevel($level) |
||
224 | |||
225 | /** |
||
226 | * @return int The current nesting level of the transaction. |
||
227 | * @since 2.0.8 |
||
228 | */ |
||
229 | public function getLevel() |
||
233 | } |
||
234 |