Sequenceless.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: Sequenceless.class.php 4687 2007-12-09 18:57:18Z voxus $ */
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 ?>

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