1 |
<?php
|
2 |
/*
|
3 |
* $Id: Firebird.php 2702 2007-10-03 21:43:22Z 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.com>.
|
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.com
|
30 |
* @since 1.0
|
31 |
* @version $Revision: 2702 $
|
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 |
* releaseSavePoint
|
50 |
* releases given savepoint
|
51 |
*
|
52 |
* @param string $savepoint name of a savepoint to release
|
53 |
* @return void
|
54 |
*/
|
55 |
protected function releaseSavePoint($savepoint)
|
56 |
{
|
57 |
$query = 'RELEASE SAVEPOINT ' . $savepoint;
|
58 |
|
59 |
return $this->conn->execute($query);
|
60 |
}
|
61 |
/**
|
62 |
* rollbackSavePoint
|
63 |
* releases given savepoint
|
64 |
*
|
65 |
* @param string $savepoint name of a savepoint to rollback to
|
66 |
* @return void
|
67 |
*/
|
68 |
protected function rollbackSavePoint($savepoint)
|
69 |
{
|
70 |
$query = 'ROLLBACK TO SAVEPOINT '.$savepoint;
|
71 |
|
72 |
return $this->conn->execute($query);
|
73 |
}
|
74 |
/**
|
75 |
* Set the transacton isolation level.
|
76 |
*
|
77 |
* @param string standard isolation level (SQL-92)
|
78 |
* READ UNCOMMITTED (allows dirty reads)
|
79 |
* READ COMMITTED (prevents dirty reads)
|
80 |
* REPEATABLE READ (prevents nonrepeatable reads)
|
81 |
* SERIALIZABLE (prevents phantom reads)
|
82 |
*
|
83 |
* @param array some transaction options:
|
84 |
* 'wait' => 'WAIT' | 'NO WAIT'
|
85 |
* 'rw' => 'READ WRITE' | 'READ ONLY'
|
86 |
*
|
87 |
* @throws PDOException if something fails at the PDO level
|
88 |
* @throws Doctrine_Transaction_Exception if using unknown isolation level or unknown wait option
|
89 |
* @return void
|
90 |
*/
|
91 |
public function setIsolation($isolation, $options = array()) {
|
92 |
switch ($isolation) {
|
93 |
case 'READ UNCOMMITTED':
|
94 |
$nativeIsolation = 'READ COMMITTED RECORD_VERSION';
|
95 |
break;
|
96 |
case 'READ COMMITTED':
|
97 |
$nativeIsolation = 'READ COMMITTED NO RECORD_VERSION';
|
98 |
break;
|
99 |
case 'REPEATABLE READ':
|
100 |
$nativeIsolation = 'SNAPSHOT';
|
101 |
break;
|
102 |
case 'SERIALIZABLE':
|
103 |
$nativeIsolation = 'SNAPSHOT TABLE STABILITY';
|
104 |
break;
|
105 |
default:
|
106 |
throw new Doctrine_Transaction_Exception('isolation level is not supported: ' . $isolation);
|
107 |
}
|
108 |
|
109 |
$rw = $wait = '';
|
110 |
|
111 |
if (isset($options['wait'])) {
|
112 |
switch ($options['wait']) {
|
113 |
case 'WAIT':
|
114 |
case 'NO WAIT':
|
115 |
$wait = ' ' . $options['wait'];
|
116 |
break;
|
117 |
default:
|
118 |
throw new Doctrine_Transaction_Exception('wait option is not supported: ' . $options['wait']);
|
119 |
}
|
120 |
}
|
121 |
|
122 |
if (isset($options['rw'])) {
|
123 |
switch ($options['rw']) {
|
124 |
case 'READ ONLY':
|
125 |
case 'READ WRITE':
|
126 |
$rw = ' ' . $options['rw'];
|
127 |
break;
|
128 |
default:
|
129 |
throw new Doctrine_Transaction_Exception('wait option is not supported: ' . $options['rw']);
|
130 |
}
|
131 |
}
|
132 |
|
133 |
$query = 'SET TRANSACTION' . $rw . $wait .' ISOLATION LEVEL ' . $nativeIsolation;
|
134 |
|
135 |
$this->conn->execute($query);
|
136 |
}
|
137 |
} |