TransactionQueue.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 
00019     final class TransactionQueue extends BaseTransaction implements Query
00020     {
00021         private $queue = null;
00022         
00023         public function __construct(DB $db)
00024         {
00025             parent::__construct($db);
00026             $this->queue = new Queue();
00027         }
00028         
00029         public function getId()
00030         {
00031             return sha1(serialize($this));
00032         }
00033         
00034         public function setId($id)
00035         {
00036             throw new UnsupportedMethodException();
00037         }
00038         
00042         public function add(Query $query)
00043         {
00044             $this->queue->add($query);
00045             
00046             return $this;
00047         }
00048         
00053         public function flush()
00054         {
00055             try {
00056                 $this->db->queryRaw($this->getBeginString());
00057                 $this->queue->flush($this->db);
00058                 $this->db->queryRaw("commit;\n");
00059             } catch (DatabaseException $e) {
00060                 $this->db->queryRaw("rollback;\n");
00061                 throw $e;
00062             }
00063             
00064             return $this;
00065         }
00066         
00067         // to satisfy Query interface
00068         public function toDialectString(Dialect $dialect)
00069         {
00070             return $this->queue->toDialectString($dialect);
00071         }
00072         
00073         public function toString()
00074         {
00075             return $this->queue->toDialectString(ImaginaryDialect::me());
00076         }
00077     }
00078 ?>