Exemple #1
0
 /**
  * Cancel any database changes done during the current transaction.
  *
  * this method can be listened with onPreTransactionRollback and onTransactionRollback
  * eventlistener methods
  *
  * @throws ConnectionException If the rollback operation failed.
  */
 public function rollBack()
 {
     if ($this->_transactionNestingLevel == 0) {
         throw ConnectionException::noActiveTransaction();
     }
     $this->connect();
     $logger = $this->_config->getSQLLogger();
     if ($this->_transactionNestingLevel == 1) {
         if ($logger) {
             $logger->startQuery('"ROLLBACK"');
         }
         $this->_transactionNestingLevel = 0;
         $this->_conn->rollback();
         $this->_isRollbackOnly = false;
         if ($logger) {
             $logger->stopQuery();
         }
     } else {
         if ($this->_nestTransactionsWithSavepoints) {
             if ($logger) {
                 $logger->startQuery('"ROLLBACK TO SAVEPOINT"');
             }
             $this->rollbackSavepoint($this->_getNestedTransactionSavePointName());
             --$this->_transactionNestingLevel;
             if ($logger) {
                 $logger->stopQuery();
             }
         } else {
             $this->_isRollbackOnly = true;
             --$this->_transactionNestingLevel;
         }
     }
 }
 protected function executeQueries(array $queries, \Closure $logger = null)
 {
     $this->conn->beginTransaction();
     try {
         foreach ($queries as $query) {
             if (null !== $logger) {
                 $logger($query);
             }
             $this->conn->query($query);
         }
         $this->conn->commit();
     } catch (\Exception $e) {
         $this->conn->rollback();
         throw $e;
     }
 }
Exemple #3
0
 /**
  * Cancel any database changes done during the current transaction.
  *
  * this method can be listened with onPreTransactionRollback and onTransactionRollback
  * eventlistener methods
  *
  * @throws ConnectionException If the rollback operation failed.
  */
 public function rollback()
 {
     if ($this->_transactionNestingLevel == 0) {
         throw ConnectionException::noActiveTransaction();
     }
     $this->connect();
     if ($this->_transactionNestingLevel == 1) {
         $this->_transactionNestingLevel = 0;
         $this->_conn->rollback();
         $this->_isRollbackOnly = false;
     } else {
         $this->_isRollbackOnly = true;
         --$this->_transactionNestingLevel;
     }
 }
Exemple #4
0
 /**
  * Cancel any database changes done during the current transaction.
  *
  * this method can be listened with onPreTransactionRollback and onTransactionRollback
  * eventlistener methods
  *
  * @throws ConnectionException If the rollback operation failed.
  */
 public function rollback()
 {
     if ($this->_transactionNestingLevel == 0) {
         throw ConnectionException::noActiveTransaction();
     }
     $this->connect();
     if ($this->_transactionNestingLevel == 1) {
         $this->_transactionNestingLevel = 0;
         $this->_conn->rollback();
         $this->_isRollbackOnly = false;
     } else {
         if ($this->_nestTransactionsWithSavepoints) {
             $this->rollbackSavepoint($this->_getNestedTransactionSavePointName());
             --$this->_transactionNestingLevel;
         } else {
             $this->_isRollbackOnly = true;
             --$this->_transactionNestingLevel;
         }
     }
 }