Exemplo n.º 1
0
 /**
  * @param Sabel_Db_Driver $driver
  *
  * @throws Sabel_Db_Exception_Connection
  * @return Sabel_Db_Driver
  */
 protected static function _connect(Sabel_Db_Driver $driver)
 {
     $connectionName = $driver->getConnectionName();
     $names = Sabel_Db_Config::getConnectionNamesOfSameSetting($connectionName);
     foreach ($names as $name) {
         if (isset(self::$connections[$name])) {
             $driver->setConnection(self::$connections[$name]);
             return $driver;
         }
     }
     if (!isset(self::$connections[$connectionName])) {
         $result = $driver->connect(Sabel_Db_Config::get($connectionName));
         if (is_string($result)) {
             throw new Sabel_Db_Exception_Connection($result);
         } else {
             self::$connections[$connectionName] = $result;
         }
     }
     $driver->setConnection(self::$connections[$connectionName]);
     return $driver;
 }
Exemplo n.º 2
0
 /**
  * @param Sabel_Db_Driver $driver
  *
  * @throws Sabel_Db_Exception_Transaction
  * @return void
  */
 public static function begin(Sabel_Db_Driver $driver)
 {
     switch (self::$isolationLevel) {
         case self::READ_UNCOMMITTED:
             $iLevel = Sabel_Db_Driver::TRANS_READ_UNCOMMITTED;
             break;
         case self::READ_COMMITTED:
             $iLevel = Sabel_Db_Driver::TRANS_READ_COMMITTED;
             break;
         case self::REPEATABLE_READ:
             $iLevel = Sabel_Db_Driver::TRANS_REPEATABLE_READ;
             break;
         case self::SERIALIZABLE:
             $iLevel = Sabel_Db_Driver::TRANS_SERIALIZABLE;
             break;
         default:
             $iLevel = null;
     }
     $connectionName = $driver->getConnectionName();
     try {
         self::$transactions[$connectionName]["conn"] = $driver->begin($iLevel);
         self::$transactions[$connectionName]["driver"] = $driver;
         self::$active = true;
     } catch (Exception $e) {
         throw new Sabel_Db_Exception_Transaction($e->getMessage());
     }
 }