コード例 #1
0
 /**
  * @return CarefulDatabaseRunner
  **/
 public function rollback()
 {
     if ($this->running) {
         try {
             $this->transaction->rollback();
         } catch (DatabaseException $e) {
             // keep silence
         }
         $this->running = false;
     }
     return $this;
 }
コード例 #2
0
 public function testRollbackInt()
 {
     //setup
     $db = $this->spawnDb(array('savepointBegin' => 1, 'savepointRollback' => 1, 'inTransaction' => true));
     //execute
     $transaction = InnerTransaction::begin($db);
     $transaction->rollback();
     //test Exception on second commit
     try {
         $transaction->commit();
         $this->fail('expecting exception on second transaction commit');
     } catch (WrongStateException $e) {
         /* all ok */
     }
 }
 public function run()
 {
     Assert::isTrue(!is_null($this->dao) || !is_null($this->db), 'set first dao or db');
     Assert::isNotNull($this->function, 'set first function');
     $transaction = InnerTransaction::begin($this->dao ?: $this->db, $this->level, $this->mode);
     try {
         $result = call_user_func_array($this->function, func_get_args());
         $transaction->commit();
         return $result;
     } catch (Exception $e) {
         $transaction->rollback();
         if ($this->exceptionFunction) {
             $args = func_get_args();
             array_unshift($args, $e);
             return call_user_func_array($this->exceptionFunction, $args);
         }
         throw $e;
     }
 }