/usr/local/miolo2/classes/database/mtransaction.class

Go to the documentation of this file.
00001 <?php
00002 class MTransaction
00003 {
00004     var $conn; // connection identifier
00005     var $commands = array(); // commands to execute
00006     var $level; // a counter for the transaction level
00007     var $error;
00008     var $_miolo;     // MIOLO object
00009 
00010     function __construct($conn)
00011     {
00012         $this->conn = $conn;
00013         $this->level = 0;
00014         $this->_miolo = MIOLO::GetInstance();
00015     }
00016 
00017     // Virtual methods - to be implemented by the specific drivers
00018     public function _begintransaction()
00019     {
00020     }
00021 
00022     public function _commit()
00023     {
00024     }
00025 
00026     public function _rollback()
00027     {
00028     }
00029 
00030     public function begin()
00031     {
00032         $this->_begintransaction();
00033     }
00034 
00035     public function commit()
00036     {
00037         $this->_commit();
00038     }
00039 
00040     public function rollback()
00041     {
00042         $this->_rollback();
00043     }
00044 
00045     public function process()
00046     {
00047         $this->_miolo->LogSQL("Begin Transaction", false, $this->conn->conf);
00048         try
00049         {
00050             $this->_begintransaction();
00051             $this->level++;
00052             $this->error = '';
00053             $i = 0;
00054             $n = count($this->commands);
00055             try
00056             {
00057                 $ok = true;
00058                 while ($i < $n)
00059                 {
00060                     $sql = $this->commands[$i++];
00061                     $ok = $ok && $this->conn->Execute($sql);
00062                 }
00063 
00064                 $this->_commit();
00065                 $this->_miolo->LogSQL("End Transaction - Commit", false, $this->conn->conf);
00066                 $this->level--;
00067             }
00068             catch( Exception $e )
00069             {
00070                 $this->_rollback();
00071                 $this->_miolo->LogSQL("End Transaction - Rollback", false, $this->conn->conf);
00072                 $this->level--;
00073 
00074                 throw new EDatabaseTransactionException($e->GetMessage());
00075             }
00076         }
00077         catch( Exception $e )
00078         {
00079             throw new EDatabaseTransactionException($e->GetMessage());
00080         }
00081 
00082         return $ok;
00083     }
00084 
00085     public function addCommand($sql)
00086     {
00087         $this->commands[] = $sql;
00088     }
00089 
00090     public function getError()
00091     {
00092         return $this->error;
00093     }
00094 }
00095 ?>
CopyLeft (L) 2001-2006 - [MIOLO Development Team] SOLIS - Cooperativa de Soluções Livres - Lajeado/RS - Brasil