# Coverage for Doctrine_Transaction_Firebird

Back to coverage report

1 | <?php
2 | /*
3 | * $Id: Firebird.php 2963 2007-10-21 06:23:59Z Jonathan.Wage $
4 | *
5 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16 | *
17 | * This software consists of voluntary contributions made by many individuals
18 | * and is licensed under the LGPL. For more information, see
19 | * <http://www.phpdoctrine.org>.
20 | */
21 | Doctrine::autoload('Doctrine_Transaction');
22 | /**
23 | *
24 | * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
25 | * @author Lukas Smith <smith@pooteeweet.org> (PEAR MDB2 library)
26 | * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
27 | * @package Doctrine
28 | * @subpackage Transaction
29 | * @link www.phpdoctrine.org
30 | * @since 1.0
31 | * @version $Revision: 2963 $
32 | */
33 | class Doctrine_Transaction_Firebird extends Doctrine_Transaction
34 | {
35 | /**
36 | * createSavepoint
37 | * creates a new savepoint
38 | *
39 | * @param string $savepoint name of a savepoint to set
40 | * @return void
41 | */
42 | protected function createSavePoint($savepoint)
43 | {
44 | $query = 'SAVEPOINT ' . $savepoint;
45 |
46 | return $this->conn->execute($query);
47 | }
48 |
49 | /**
50 | * releaseSavePoint
51 | * releases given savepoint
52 | *
53 | * @param string $savepoint name of a savepoint to release
54 | * @return void
55 | */
56 | protected function releaseSavePoint($savepoint)
57 | {
58 | $query = 'RELEASE SAVEPOINT ' . $savepoint;
59 |
60 | return $this->conn->execute($query);
61 | }
62 |
63 | /**
64 | * rollbackSavePoint
65 | * releases given savepoint
66 | *
67 | * @param string $savepoint name of a savepoint to rollback to
68 | * @return void
69 | */
70 | protected function rollbackSavePoint($savepoint)
71 | {
72 | $query = 'ROLLBACK TO SAVEPOINT '.$savepoint;
73 |
74 | return $this->conn->execute($query);
75 | }
76 |
77 | /**
78 | * Set the transacton isolation level.
79 | *
80 | * @param string standard isolation level (SQL-92)
81 | * READ UNCOMMITTED (allows dirty reads)
82 | * READ COMMITTED (prevents dirty reads)
83 | * REPEATABLE READ (prevents nonrepeatable reads)
84 | * SERIALIZABLE (prevents phantom reads)
85 | *
86 | * @param array some transaction options:
87 | * 'wait' => 'WAIT' | 'NO WAIT'
88 | * 'rw' => 'READ WRITE' | 'READ ONLY'
89 | *
90 | * @throws PDOException if something fails at the PDO level
91 | * @throws Doctrine_Transaction_Exception if using unknown isolation level or unknown wait option
92 | * @return void
93 | */
94 | public function setIsolation($isolation, $options = array()) {
95 | switch ($isolation) {
96 | case 'READ UNCOMMITTED':
97 | $nativeIsolation = 'READ COMMITTED RECORD_VERSION';
98 | break;
99 | case 'READ COMMITTED':
100 | $nativeIsolation = 'READ COMMITTED NO RECORD_VERSION';
101 | break;
102 | case 'REPEATABLE READ':
103 | $nativeIsolation = 'SNAPSHOT';
104 | break;
105 | case 'SERIALIZABLE':
106 | $nativeIsolation = 'SNAPSHOT TABLE STABILITY';
107 | break;
108 | default:
109 | throw new Doctrine_Transaction_Exception('isolation level is not supported: ' . $isolation);
110 | }
111 |
112 | $rw = $wait = '';
113 |
114 | if (isset($options['wait'])) {
115 | switch ($options['wait']) {
116 | case 'WAIT':
117 | case 'NO WAIT':
118 | $wait = ' ' . $options['wait'];
119 | break;
120 | default:
121 | throw new Doctrine_Transaction_Exception('wait option is not supported: ' . $options['wait']);
122 | }
123 | }
124 |
125 | if (isset($options['rw'])) {
126 | switch ($options['rw']) {
127 | case 'READ ONLY':
128 | case 'READ WRITE':
129 | $rw = ' ' . $options['rw'];
130 | break;
131 | default:
132 | throw new Doctrine_Transaction_Exception('wait option is not supported: ' . $options['rw']);
133 | }
134 | }
135 |
136 | $query = 'SET TRANSACTION' . $rw . $wait .' ISOLATION LEVEL ' . $nativeIsolation;
137 |
138 | $this->conn->execute($query);
139 | }
140 | }