DBTransaction.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2005-2007 by Konstantin V. Arkhipov                     *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  ***************************************************************************/
00011 /* $Id: DBTransaction.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00018     final class DBTransaction extends BaseTransaction
00019     {
00020         private $started    = false;
00021         
00022         public function __destruct()
00023         {
00024             if ($this->isStarted())
00025                 $this->db->queryRaw("rollback;\n");
00026         }
00027         
00031         public function setDB(DB $db)
00032         {
00033             if ($this->isStarted())
00034                 throw new WrongStateException(
00035                     'transaction already started, can not switch to another db'
00036                 );
00037 
00038             return parent::setDB($db);
00039         }
00040         
00041         public function isStarted()
00042         {
00043             return $this->started;
00044         }
00045         
00049         public function add(Query $query)
00050         {
00051             if (!$this->isStarted()) {
00052                 $this->db->queryRaw($this->getBeginString());
00053                 $this->started = true;
00054             }
00055             
00056             $this->db->queryNull($query);
00057             
00058             return $this;
00059         }
00060         
00064         public function flush()
00065         {
00066             $this->started = false;
00067             
00068             try {
00069                 $this->db->queryRaw("commit;\n");
00070             } catch (DatabaseException $e) {
00071                 $this->db->queryRaw("rollback;\n");
00072                 throw $e;
00073             }
00074             
00075             return $this;
00076         }
00077     }
00078 ?>

Generated on Sun Dec 9 21:56:23 2007 for onPHP by  doxygen 1.5.4