MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
mtransaction.class
Ir para a documentação deste ficheiro.
1<?php
3{
4 var $conn; // connection identifier
5 var $commands = array(); // commands to execute
6 var $level; // a counter for the transaction level
7 var $error;
8 var $_miolo; // MIOLO object
9
11 {
12 $this->conn = $conn;
13 $this->level = 0;
14 $this->_miolo = MIOLO::GetInstance();
15 }
16
17 // Virtual methods - to be implemented by the specific drivers
18 public function _begintransaction()
19 {
20 }
21
22 public function _commit()
23 {
24 }
25
26 public function _rollback()
27 {
28 }
29
30 public function begin()
31 {
32 $this->_begintransaction();
33 }
34
35 public function commit()
36 {
37 $this->_commit();
38 }
39
40 public function rollback()
41 {
42 $this->_rollback();
43 }
44
45 public function process()
46 {
47 $this->_miolo->LogSQL("Begin Transaction", false, $this->conn->conf);
48 try
49 {
50 $transactionId = $this->conn->db->query("SELECT txid_current();");
51 $transactionId2 = $this->conn->db->query("SELECT txid_current();");
52
53 if( $transactionId != $transactionId2 )
54 {
55 $this->_begintransaction();
56 }
57 $this->level++;
58 $this->error = '';
59 $i = 0;
60 $n = count($this->commands);
61 try
62 {
63 $ok = true;
64 while ($i < $n)
65 {
66 $sql = $this->commands[$i++];
67 $ok = $ok && $this->conn->Execute($sql);
68 }
69
70 if( $transactionId != $transactionId2 )
71 {
72 $this->_commit();
73 $this->_miolo->LogSQL("End Transaction - Commit", false, $this->conn->conf);
74 }
75 $this->level--;
76 }
77 catch( Exception $e )
78 {
79 if( $transactionId != $transactionId2 )
80 {
81 $this->_rollback();
82 $this->_miolo->LogSQL("End Transaction - Rollback", false, $this->conn->conf);
83 }
84 $this->level--;
85
86 throw new EDatabaseTransactionException($e->GetMessage());
87 }
88 }
89 catch( Exception $e )
90 {
91 throw new EDatabaseTransactionException($e->GetMessage());
92 }
93
94 return $ok;
95 }
96
97 public function addCommand($sql)
98 {
99 $this->commands[] = $sql;
100 }
101
102 public function getError()
103 {
104 return $this->error;
105 }
106
107 public static function getNameTransaction($action, $module)
108 {
109 $MIOLO = MIOLO::GetInstance();
110 $nameTransaction = '';
111
112 $isCache = $MIOLO->getConf('options.cachedata') == 'true';
113 if ( $isCache )
114 {
115 $cacheData = new SCacheData();
116 $idParaCache = "getNameTransaction[{$action}|{$module}]";
117
118 if ( $cacheData->fetch($idParaCache) )
119 {
120 return $cacheData->fetch($idParaCache);
121 }
122 }
123
124 if( $MIOLO->getConf('db.admin.system') == 'postgres')
125 {
126 $exist = $MIOLO->GetDatabase()->query("SELECT COUNT(*) > 0 from pg_proc where proname = 'getnametransaction'");
127
128 if ( $exist[0][0] == DB_TRUE)
129 {
130 $transaction = $MIOLO->GetDatabase()->query("SELECT getNameTransaction('".$action."','" . $module . "')");
131 $nameTransaction = $transaction[0][0];
132 }
133 }
134
135 if ( $isCache )
136 {
137 $cacheData->add($idParaCache, $nameTransaction);
138 }
139
140 return $nameTransaction;
141 }
142}
143?>
static getNameTransaction($action, $module)
__construct($conn)
$action
Definição base.php:4