/** * Rollback the whole transaction, even if this is a nested rollback * and reset the nested transaction count to 0. * @return boolean Whether operation was successful. */ public function forceRollBack() { $return = true; $opcount = $this->getNestedTransactionCount(); if ($opcount > 0) { if (class_exists("KalturaLog")) { KalturaLog::Log("called forceRollback"); } // If we're in a transaction, always roll it back // regardless of nesting level. $return = parent::rollBack(); // reset nested transaction count to 0 so that we don't // try to commit (or rollback) the transaction outside this scope. $this->nestedTransactionCount = 0; } return $return; }
/** * Opens a new PDO connection for passed-in db name. * * @param array $conparams Connection paramters. * @param string $name Datasource name. * @param string $defaultClass The PDO subclass to instantiate if there is no explicit classname * specified in the connection params (default is Propel::CLASS_PROPEL_PDO) * * @return PDO A database connection of the given class (PDO, PropelPDO, SlavePDO or user-defined) * * @throws PropelException - if lower-level exception caught when trying to connect. */ public static function initConnection($conparams, $name, $defaultClass = Propel::CLASS_PROPEL_PDO) { $dsn = $conparams['dsn']; if ($dsn === null) { throw new PropelException('No dsn specified in your connection parameters for datasource [' . $name . ']'); } if (isset($conparams['classname']) && !empty($conparams['classname'])) { $classname = $conparams['classname']; if (!class_exists($classname)) { throw new PropelException('Unable to load specified PDO subclass: ' . $classname); } } else { $classname = $defaultClass; } $user = isset($conparams['user']) ? $conparams['user'] : null; $password = isset($conparams['password']) ? $conparams['password'] : null; // load any driver options from the config file // driver options are those PDO settings that have to be passed during the connection construction $driver_options = array(); if (isset($conparams['options']) && is_array($conparams['options'])) { try { self::processDriverOptions($conparams['options'], $driver_options); } catch (PropelException $e) { throw new PropelException('Error processing driver options for datasource [' . $name . ']', $e); } } // add profiling info and multiple retries for initiating a connection // since we do not expect connection time to exceed 1 second and we do encounter tcp SYN packet drop // which results in 3 second connection (the retry on the SYN is set to 3 seconds in the linux kernel) // we try to connect up to 3 times setting a 1 second timeout on the first two attempts // if there already was a timeout setting on the connection we wont activate the above logic and continue with // the original flow of one connection attempt $connStartTime = microtime(true); if (!array_key_exists(PDO::ATTR_TIMEOUT, $driver_options)) { $driver_options[PDO::ATTR_TIMEOUT] = 1; $count = 3; } else { $count = 1; } for ($i = 1; $i <= $count; $i++) { try { if ($i > 1 && $i == $count) { // remove the timeout on the last attempt of the a attempt loop unset($driver_options[PDO::ATTR_TIMEOUT]); } $startTime = microtime(true); $con = new $classname($dsn, $user, $password, $driver_options); $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); break; } catch (PDOException $e) { $timeTook = microtime(true) - $startTime; if (class_exists("KalturaLog")) { KalturaLog::Log("failed to connect [{$i}] [{$timeTook}] {$dsn}"); } if ($i == $count || $timeTook < 1) { throw new PropelException("Unable to open PDO connection dsn[{$dsn}] user[{$user}] password[{$password}]", $e); } } } if (class_exists("KalturaLog")) { KalturaLog::Log("total conn took " . (microtime(true) - $connStartTime) . " {$dsn}"); } // load any connection options from the config file // connection attributes are those PDO flags that have to be set on the initialized connection if (isset($conparams['attributes']) && is_array($conparams['attributes'])) { $attributes = array(); try { self::processDriverOptions($conparams['attributes'], $attributes); } catch (PropelException $e) { throw new PropelException('Error processing connection attributes for datasource [' . $name . ']', $e); } foreach ($attributes as $key => $value) { $con->setAttribute($key, $value); } } // initialize the connection using the settings provided in the config file. this could be a "SET NAMES <charset>" query for MySQL, for instance $adapter = self::getDB($name); $adapter->initConnection($con, isset($conparams['settings']) && is_array($conparams['settings']) ? $conparams['settings'] : array()); return $con; }