00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00022 final class Queue implements Query
00023 {
00024 private $queue = array();
00025
00029 public static function create()
00030 {
00031 return new self;
00032 }
00033
00034 public function getId()
00035 {
00036 return sha1(serialize($this->queue));
00037 }
00038
00039 public function setId($id)
00040 {
00041 throw new UnsupportedMethodException();
00042 }
00043
00044 public function getQueue()
00045 {
00046 return $this->queue;
00047 }
00048
00052 public function add(Query $query)
00053 {
00054 $this->queue[] = $query;
00055
00056 return $this;
00057 }
00058
00062 public function remove(Query $query)
00063 {
00064 if (!$id = array_search($query, $this->queue))
00065 throw new MissingElementException();
00066
00067 unset($this->queue[$id]);
00068
00069 return $this;
00070 }
00071
00075 public function drop()
00076 {
00077 $this->queue = array();
00078
00079 return $this;
00080 }
00081
00085 public function run(DB $db)
00086 {
00087 $db->queryRaw($this->toDialectString($db->getDialect()));
00088
00089 return $this;
00090 }
00091
00095 public function flush(DB $db)
00096 {
00097 return $this->run($db)->drop();
00098 }
00099
00100
00101 public function toString()
00102 {
00103 return $this->toDialectString(ImaginaryDialect::me());
00104 }
00105
00106 public function toDialectString(Dialect $dialect)
00107 {
00108 $out = array();
00109
00110 foreach ($this->queue as &$query)
00111 $out[] = $query->toDialectString($dialect);
00112
00113 return implode(";\n", $out);
00114 }
00115 }
00116 ?>