transaction

@param callable $callback
@param bool     $autoCommit

@return  AbstractTransaction

@throws \Throwable

@since  3.5.3
322685
public function transaction(callable $callback, bool $autoCommit = true): self
    {
        $this->start();

        try {
            $callback($this->db, $this);

            if ($autoCommit) {
                $this->commit();
            }
        } catch (\Throwable $e) {
            $this->rollback();

            throw $e;
        }

        return $this;
    }
935560
public function put($key, $value, $autocommit = false)
    {
        $this->data[$key] = $value;

        if ($autocommit) {
            $this->commit();
        }
    }
109824
public function commit($throw=true)
	{
		if (!$this->transactionOpen && $throw) { $this->throwError("Transaction not open to commit()",""); return false; }
		if (!$this->isOpen) { $this->throwError("It's not connected to the database",""); return false; }
		$this->transactionOpen = false;
		return @$this->conn1->commit();
	}
798431
public function withTransaction(callable $callable)
    {
        try {
            $nested = $this->transactionStarted;
            if (!$nested) {
                $this->startTransaction();
            }
            $this->transactionStarted = true;
            $result = $callable();
            if (!$nested) {
                $this->commit();
            }
            $this->transactionStarted = $nested;
            return $result;
        } catch (Throwable $e) {
            if ($this->transactionStarted) {
                $this->rollback();
                $this->transactionStarted = false;
            }
            throw $e;
        }
    }
451441
public function tryWithTransaction(callable $callable, int $maxAttempts)
    {
        for ($attempt = 1; $attempt <= $maxAttempts; $attempt++) {
            try {
                return $this->withTransaction($callable);
            } catch (Throwable $e) {
                if ($attempt == $maxAttempts) {
                    throw $e;
                }
            }
        }
        throw new RuntimeException('Number of attempts must be greater than 0');
    }
512117
public function commit($xid)
    {
        if ($this->activeTransaction != $xid || $this->activeTransaction === false) {
            return;
        }

        $this->activeTransaction = false;

        if (!$this->connection->commit()) {
            throw new DbException("Commit failed");
        }

        $this->connection->autocommit(true);
    }
132033
public function transaction( \Closure $callback, $attempts = 1 )
	{
		$this->beginTransaction();
		try {
			$data = $callback();
			$this->commit();

			return $data;
		} catch ( \Exception $e ) {
			$this->rollBack();
			throw $e;
		}
	}
509703
def _set_autocommit(connection):
        """"""
        if hasattr(connection.connection, "autocommit"):
            if callable(connection.connection.autocommit):
                connection.connection.autocommit(True)
            else:
                connection.connection.autocommit = True
        elif hasattr(connection.connection, "set_isolation_level"):
            connection.connection.set_isolation_level(0)
61747
public boolean getAutoCommit() throws SQLException {
        Statement stmt = createStatement();
        ResultSet rs = stmt.executeQuery("select @@autocommit");
        rs.next();
        boolean autocommit = rs.getBoolean(1);
        rs.close();
        stmt.close();
        return autocommit;
    }
1354615
public function transaction(Closure $callback)
	{
		if ($this->getDriverName() == 'sqlsrv')
		{
			return parent::transaction($callback);
		}

		$this->pdo->exec('BEGIN TRAN');

		// We'll simply execute the given callback within a try / catch block
		// and if we catch any exception we can rollback the transaction
		// so that none of the changes are persisted to the database.
		try
		{
			$result = $callback($this);

			$this->pdo->exec('COMMIT TRAN');
		}

		// If we catch an exception, we will roll back so nothing gets messed
		// up in the database. Then we'll re-throw the exception so it can
		// be handled how the developer sees fit for their applications.
		catch (\Exception $e)
		{
			$this->pdo->exec('ROLLBACK TRAN');

			throw $e;
		}

		return $result;
	}
569328
public function confirmSelect(callable $callback = null, $nowait = false)
    {
        if ($this->mode !== ChannelModeEnum::REGULAR) {
            throw new ChannelException("Channel not in regular mode, cannot change to transactional mode.");
        }

        $response = $this->confirmSelectImpl($nowait);

        if ($response instanceof PromiseInterface) {
            return $response->then(function ($response) use ($callback) {
                $this->enterConfirmMode($callback);
                return $response;
            });

        } else {
            $this->enterConfirmMode($callback);
            return $response;
        }
    }
258156
function(options, callback) {
    // var self = this

    if (typeof options === 'function') {
      callback = options
      options = {}
    }

    if (options.transaction) {
      return callback(options.transaction)
    } else {
      return this.connection
        .transaction(function(transaction) {
          options.transaction = transaction
          return callback(transaction)
        })
        .then(function(result) {
          debug('commit')
          return result
        })
        .catch(function(e) {
          // TODO: do something with e.g. 'afterSave' rollback message!?!
          debug('rollback')
          throw e
        })
    }
  }
651542
public function beginTransaction()
    {
        if (!$this->activeTransaction === false) {
            return;
        }

        if ($this->connection->autocommit(false)) {
            $this->activeTransaction = uniqid();
            return $this->activeTransaction;
        }
    }
553736
function commit()
    {
        if ($this->transaction_level > 0){
            $this->transaction_level--;
            if ($this->transaction_level == 0){
                return parent::commit();
            }
            return true;
        }
        return false;
    }
1001498
def autocommit(f):
    ""
    @wraps(f)
    def wrapper(self, *args, **kwargs):
        result = f(self, *args, **kwargs)
        if self._meta.commit_ready():
            self.commit()
        return result
    return wrapper
1346008
public static function startTransaction(callable $callback = null)
    {
        static::verifyConnection();

        if (!static::$adapter->getConnection()->inTransaction()) {
            static::$adapter->getConnection()->beginTransaction();
        }

        if (is_callable($callback)) {
            try {
                call_user_func_array($callback, []);

                static::commit();
            } catch (DatabaseException $e) {
                static::rollback();
            }
        }
    }
987531
protected function beginTransaction($autoCommit = false): void
    {
        if (!$autoCommit && null !== $this->connection) {
            $this->connection->beginTransaction();
        }
    }