コード例 #1
0
ファイル: IdBroker.php プロジェクト: jbzdak/wikidot
 public function nextId($tableName)
 {
     $db = Database::connection();
     $idbpeer = DB_IdBrokerPeer::instance();
     $db->begin();
     $t = $idbpeer->selectOneByExplicitQuery("WHERE table_name = '{$tableName}' FOR UPDATE");
     $index = $t->getNextFreeIndex();
     $t->setNextFreeIndex($index + 1);
     $t->save();
     $db->commit();
     return $index;
 }
コード例 #2
0
 public function setupIdBroker()
 {
     // for each table with a INT-LIKE primary key let the pk be
     // handled by the IdBroker.
     foreach ($this->tables as $table) {
         $pkColumn = $table->getPkColumn();
         if ($pkColumn != null && $pkColumn->isIntLike()) {
             echo $pkColumn->getName();
             // check if not already there
             $c = new Criteria();
             $c->add('column_name', $pkColumn->getName());
             $c->add('table_name', $table->getName());
             $r = DB_IdBrokerPeer::instance()->selectOne($c);
             if ($r == null) {
                 $idbe = new DB_IdBroker();
                 $idbe->setTableName($table->getName());
                 $idbe->setColumnName($pkColumn->getName());
                 $idbe->save();
             }
         }
     }
     //in case of regeneration - update the indexes:
     $idbp = DB_IdBrokerPeer::instance();
     $idbp->updateIndexes();
 }