public function commit()
    {
        if (!$this->getIsActive()) {
            throw new Exception('Failed to commit transaction: transaction was inactive.');
        }

        $connection = $this->getConnection();
        $this->_level--;
        if ($this->_level === 0) {
            Reaction::debug('Commit transaction');
            return $connection->commitTransaction()
                ->thenLazy(function() { $this->closeConnection(); });
        }

        $schema = $this->db->getSchema();
        if ($schema->supportsSavepoint()) {
            Reaction::debug('Release savepoint ' . $this->_level);
            return $connection->releaseSavepoint('LEVEL' . $this->_level);
        } else {
            Reaction::info('Transaction not committed: nested transaction not supported');
        }
        return Reaction\Promise\rejectLazy(null);
    }