Esempio n. 1
0
    def _do_exit(cls, state, decorator_args, exception):
        independent = decorator_args.get("independent", False)

        try:
            if state.transaction_started:
                if exception:
                    _GetConnection().rollback()
                else:
                    if not _GetConnection().commit():
                        raise TransactionFailedError()
        finally:
            if state.transaction_started:
                _PopConnection()

                 # Clear the context cache at the end of a transaction
                if exception:
                    caching.get_context().stack.pop(discard=True)
                else:
                    caching.get_context().stack.pop(apply_staged=True, clear_staged=True)

            # If we were in an independent transaction, put everything back
            # the way it was!
            if independent:
                while state.conn_stack:
                    _PushConnection(state.conn_stack.pop())

                # Restore the in-context cache as it was
                caching.get_context().stack = state.original_stack
Esempio n. 2
0
    def _do_exit(cls, state, decorator_args, exception):
        independent = decorator_args.get("independent", False)

        try:
            if state.transaction_started:
                if exception:
                    _GetConnection().rollback()
                else:
                    if not _GetConnection().commit():
                        raise TransactionFailedError()
        finally:
            if state.transaction_started:
                _PopConnection()

                # Clear the context cache at the end of a transaction
                if exception:
                    caching.get_context().stack.pop(discard=True)
                else:
                    caching.get_context().stack.pop(apply_staged=True,
                                                    clear_staged=True)

            # If we were in an independent transaction, put everything back
            # the way it was!
            if independent:
                while state.conn_stack:
                    _PushConnection(state.conn_stack.pop())

                # Restore the in-context cache as it was
                caching.get_context().stack = state.original_stack
Esempio n. 3
0
    def _do_exit(self, exception):
        if not self.transaction_started:
            # If we didn't start a transaction, then don't roll back or anything
            return

        try:
            if exception:
                _GetConnection().rollback()
            else:
                if not _GetConnection().commit():
                    raise TransactionFailedError()
        finally:
            _PopConnection()

            if self.independent:
                while self.conn_stack:
                    _PushConnection(self.conn_stack.pop())

             # Clear the context cache at the end of a transaction
            if exception:
                caching._context.stack.pop(discard=True)
            else:
                caching._context.stack.pop(apply_staged=True, clear_staged=True)

            # Reset this; in case this method is called again
            self.transaction_started = False
Esempio n. 4
0
    def _do_exit(self, exception):
        if not self.transaction_started:
            # If we didn't start a transaction, then don't roll back or anything
            return

        try:
            if exception:
                _GetConnection().rollback()
            else:
                if not _GetConnection().commit():
                    raise TransactionFailedError()
        finally:
            _PopConnection()

            if self.independent:
                while self.conn_stack:
                    _PushConnection(self.conn_stack.pop())

                 # Clear the context cache at the end of a transaction
                if exception:
                    caching._context.stack.pop(discard=True)
                else:
                    caching._context.stack.pop(apply_staged=False, clear_staged=False)
            else:
                if exception:
                    caching._context.stack.pop(discard=True)
                else:
                    caching._context.stack.pop(apply_staged=True, clear_staged=True)
Esempio n. 5
0
    def _enter(self):
        if IsInTransaction():
            self._previous_connection = _GetConnection()
            assert(isinstance(self._previous_connection, TransactionalConnection))

            _PopConnection()

        self._connection = _GetConnection().new_transaction(self._options)
        _PushConnection(self._connection)
Esempio n. 6
0
    def _finalize(self):
        _PopConnection()  #Pop the transaction connection
        if self.parent_conn:
            #If there was a parent transaction, now put that back
            _PushConnection(self.parent_conn)
            self.parent_conn = None

        #Clear the context cache at the end of a transaction
        caching.clear_context_cache()
Esempio n. 7
0
    def _enter(self):
        if IsInTransaction():
            self._previous_connection = _GetConnection()
            assert(isinstance(self._previous_connection, TransactionalConnection))

            _PopConnection()

        self._connection = _GetConnection().new_transaction(self._options)
        _PushConnection(self._connection)
    def _finalize(self):
        _PopConnection() #Pop the transaction connection
        if self.parent_conn:
            #If there was a parent transaction, now put that back
            _PushConnection(self.parent_conn)
            self.parent_conn = None

        #Clear the context cache at the end of a transaction
        caching.clear_context_cache()
Esempio n. 9
0
    def _do_enter(self):
        if IsInTransaction():
            if self.independent:
                self.conn_stack.append(_PopConnection())
                try:
                    return self._do_enter()
                except:
                    _PushConnection(self.conn_stack.pop())
                    raise
            else:
                # App Engine doesn't support nested transactions, so if there is a nested
                # atomic() call we just don't do anything. This is how RunInTransaction does it
                return
        elif self.mandatory:
            raise TransactionFailedError(
                "You've specified that an outer transaction is mandatory, but one doesn't exist"
            )

        options = CreateTransactionOptions(
            xg=self.xg,
            propagation=TransactionOptions.INDEPENDENT
            if self.independent else None)

        conn = _GetConnection()

        self.transaction_started = True
        new_conn = conn.new_transaction(options)

        _PushConnection(None)
        _SetConnection(new_conn)

        assert (_GetConnection())

        # Clear the context cache at the start of a transaction
        caching._context.stack.push()
Esempio n. 10
0
    def _do_enter(self):
        if IsInTransaction():
            if self.independent:
                self.conn_stack.append(_PopConnection())
                try:
                    return self._do_enter()
                except:
                    _PushConnection(self.conn_stack.pop())
                    raise
            else:
                # App Engine doesn't support nested transactions, so if there is a nested
                # atomic() call we just don't do anything. This is how RunInTransaction does it
                return
        elif self.mandatory:
            raise TransactionFailedError("You've specified that an outer transaction is mandatory, but one doesn't exist")

        options = CreateTransactionOptions(
            xg=self.xg,
            propagation=TransactionOptions.INDEPENDENT if self.independent else None
        )

        conn = _GetConnection()

        self.transaction_started = True
        new_conn = conn.new_transaction(options)

        _PushConnection(None)
        _SetConnection(new_conn)

        assert(_GetConnection())

        # Clear the context cache at the start of a transaction
        caching._context.stack.push()
Esempio n. 11
0
    def _do_enter(self):
        self._original_connection = None

        if not in_atomic_block():
            return # Do nothing if we aren't even in a transaction

        self._original_connection = _PopConnection()
        self._original_context = copy.deepcopy(caching._context)

        while len(caching._context.stack.stack) > 1:
            caching._context.stack.pop(discard=True)
Esempio n. 12
0
    def _do_enter(cls, state, decorator_args):
        state.conn_stack = []

        # We aren't in a transaction, do nothing!
        if not in_atomic_block():
            return

        # Store the current in-context stack
        state.original_stack = copy.deepcopy(caching.get_context().stack)

        # Similar to independent transactions, unwind the connection statck
        # until we aren't in a transaction
        while in_atomic_block():
            state.conn_stack.append(_PopConnection())

        # Unwind the in-context stack
        while len(caching.get_context().stack.stack) > 1:
            caching.get_context().stack.pop(discard=True)
Esempio n. 13
0
    def _do_enter(cls, state, decorator_args):
        state.conn_stack = []

        # We aren't in a transaction, do nothing!
        if not in_atomic_block():
            return

        # Store the current in-context stack
        state.original_stack = copy.deepcopy(caching.get_context().stack)

        # Similar to independent transactions, unwind the connection statck
        # until we aren't in a transaction
        while in_atomic_block():
            state.conn_stack.append(_PopConnection())

        # Unwind the in-context stack
        while len(caching.get_context().stack.stack) > 1:
            caching.get_context().stack.pop(discard=True)
    def _begin(self):
        options = CreateTransactionOptions(
            xg = True if self.xg else False,
            propagation = TransactionOptions.INDEPENDENT if self.independent else None
        )

        if IsInTransaction() and not self.independent:
            raise RuntimeError("Nested transactions are not supported")
        elif self.independent:
            #If we're running an independent transaction, pop the current one
            self.parent_conn = _PopConnection()

        #Push a new connection, start a new transaction
        conn = _GetConnection()
        _PushConnection(None)
        _SetConnection(conn.new_transaction(options))

        #Clear the context cache at the start of a transaction
        caching.clear_context_cache()
Esempio n. 15
0
    def _begin(self):
        options = CreateTransactionOptions(
            xg=True if self.xg else False,
            propagation=TransactionOptions.INDEPENDENT
            if self.independent else None)

        if IsInTransaction() and not self.independent:
            raise RuntimeError("Nested transactions are not supported")
        elif self.independent:
            #If we're running an independent transaction, pop the current one
            self.parent_conn = _PopConnection()

        #Push a new connection, start a new transaction
        conn = _GetConnection()
        _PushConnection(None)
        _SetConnection(conn.new_transaction(options))

        #Clear the context cache at the start of a transaction
        caching.clear_context_cache()
Esempio n. 16
0
    def _do_enter(cls, state, decorator_args):
        mandatory = decorator_args.get("mandatory", False)
        independent = decorator_args.get("independent", False)
        xg = decorator_args.get("xg", False)

        # Reset the state
        state.conn_stack = []
        state.transaction_started = False
        state.original_stack = None

        if independent:
            # Unwind the connection stack and store it on the state so that
            # we can replace it on exit
            while in_atomic_block():
                state.conn_stack.append(_PopConnection())
            state.original_stack = copy.deepcopy(caching.get_context().stack)

        elif in_atomic_block():
            # App Engine doesn't support nested transactions, so if there is a nested
            # atomic() call we just don't do anything. This is how RunInTransaction does it
            return
        elif mandatory:
            raise TransactionFailedError(
                "You've specified that an outer transaction is mandatory, but one doesn't exist"
            )

        options = CreateTransactionOptions(
            xg=xg,
            propagation=TransactionOptions.INDEPENDENT
            if independent else None)

        conn = _GetConnection()
        new_conn = conn.new_transaction(options)
        _PushConnection(new_conn)

        assert (_GetConnection())

        # Clear the context cache at the start of a transaction
        caching.ensure_context()
        caching.get_context().stack.push()
        state.transaction_started = True
Esempio n. 17
0
    def _do_enter(cls, state, decorator_args):
        mandatory = decorator_args.get("mandatory", False)
        independent = decorator_args.get("independent", False)
        xg = decorator_args.get("xg", False)

        # Reset the state
        state.conn_stack = []
        state.transaction_started = False
        state.original_stack = None

        if independent:
            # Unwind the connection stack and store it on the state so that
            # we can replace it on exit
            while in_atomic_block():
                state.conn_stack.append(_PopConnection())
            state.original_stack = copy.deepcopy(caching.get_context().stack)

        elif in_atomic_block():
            # App Engine doesn't support nested transactions, so if there is a nested
            # atomic() call we just don't do anything. This is how RunInTransaction does it
            return
        elif mandatory:
            raise TransactionFailedError("You've specified that an outer transaction is mandatory, but one doesn't exist")

        options = CreateTransactionOptions(
            xg=xg,
            propagation=TransactionOptions.INDEPENDENT if independent else None
        )

        conn = _GetConnection()
        new_conn = conn.new_transaction(options)
        _PushConnection(new_conn)

        assert(_GetConnection())

        # Clear the context cache at the start of a transaction
        caching.ensure_context()
        caching.get_context().stack.push()
        state.transaction_started = True
Esempio n. 18
0
 def _exit(self):
     _PopConnection()
Esempio n. 19
0
 def _exit(self):
     _PopConnection()
     if self._previous_connection:
         _PushConnection(self._previous_connection)
Esempio n. 20
0
 def _exit(self):
     _PopConnection()
Esempio n. 21
0
 def _enter(self):
     if IsInTransaction():
         self._previous_connection = _GetConnection()
         _PopConnection()
Esempio n. 22
0
 def _enter(self):
     if IsInTransaction():
         self._previous_connection = _GetConnection()
         _PopConnection()
Esempio n. 23
0
 def _exit(self):
     _PopConnection()
     if self._previous_connection:
         _PushConnection(self._previous_connection)