00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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 ?>