00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00028 abstract class Sequenceless extends DB
00029 {
00030 protected $sequencePool = array();
00031
00032 abstract protected function getInsertId();
00033
00037 final public function obtainSequence($sequence)
00038 {
00039 $id = Identifier::create();
00040
00041 $this->sequencePool[$sequence][] = $id;
00042
00043 return $id;
00044 }
00045
00046 final public function query(Query $query)
00047 {
00048 $result = $this->queryRaw(
00049 $query->toDialectString($this->getDialect())
00050 );
00051
00052 if (
00053 ($query instanceof InsertQuery)
00054 && !empty($this->sequencePool[$name = $query->getTable().'_id'])
00055 ) {
00056 $id = current($this->sequencePool[$name]);
00057
00058 Assert::isTrue(
00059 $id instanceof Identifier,
00060 'identifier was lost in the way'
00061 );
00062
00063 $id->setId($this->getInsertId())->finalize();
00064
00065 unset(
00066 $this->sequencePool[
00067 $name
00068 ][
00069 key($this->sequencePool[$name])
00070 ]
00071 );
00072 }
00073
00074 return $result;
00075 }
00076 }
00077 ?>