Represent the "root" transaction on a :class:`_engine.Connection`. This corresponds to the current "BEGIN/COMMIT/ROLLBACK" that's occurring for the :class:`_engine.Connection`. The :class:`_engine.RootTransaction` is created by calling upon the :meth:`_engine.Connection.begin` method, a
| 2628 | |
| 2629 | |
| 2630 | class RootTransaction(Transaction): |
| 2631 | """Represent the "root" transaction on a :class:`_engine.Connection`. |
| 2632 | |
| 2633 | This corresponds to the current "BEGIN/COMMIT/ROLLBACK" that's occurring |
| 2634 | for the :class:`_engine.Connection`. The :class:`_engine.RootTransaction` |
| 2635 | is created by calling upon the :meth:`_engine.Connection.begin` method, and |
| 2636 | remains associated with the :class:`_engine.Connection` throughout its |
| 2637 | active span. The current :class:`_engine.RootTransaction` in use is |
| 2638 | accessible via the :attr:`_engine.Connection.get_transaction` method of |
| 2639 | :class:`_engine.Connection`. |
| 2640 | |
| 2641 | In :term:`2.0 style` use, the :class:`_engine.Connection` also employs |
| 2642 | "autobegin" behavior that will create a new |
| 2643 | :class:`_engine.RootTransaction` whenever a connection in a |
| 2644 | non-transactional state is used to emit commands on the DBAPI connection. |
| 2645 | The scope of the :class:`_engine.RootTransaction` in 2.0 style |
| 2646 | use can be controlled using the :meth:`_engine.Connection.commit` and |
| 2647 | :meth:`_engine.Connection.rollback` methods. |
| 2648 | |
| 2649 | |
| 2650 | """ |
| 2651 | |
| 2652 | _is_root = True |
| 2653 | |
| 2654 | __slots__ = ("connection", "is_active") |
| 2655 | |
| 2656 | def __init__(self, connection: Connection): |
| 2657 | assert connection._transaction is None |
| 2658 | if connection._trans_context_manager: |
| 2659 | TransactionalContext._trans_ctx_check(connection) |
| 2660 | self.connection = connection |
| 2661 | self._connection_begin_impl() |
| 2662 | connection._transaction = self |
| 2663 | |
| 2664 | self.is_active = True |
| 2665 | |
| 2666 | def _deactivate_from_connection(self) -> None: |
| 2667 | if self.is_active: |
| 2668 | assert self.connection._transaction is self |
| 2669 | self.is_active = False |
| 2670 | |
| 2671 | elif self.connection._transaction is not self: |
| 2672 | util.warn("transaction already deassociated from connection") |
| 2673 | |
| 2674 | @property |
| 2675 | def _deactivated_from_connection(self) -> bool: |
| 2676 | return self.connection._transaction is not self |
| 2677 | |
| 2678 | def _connection_begin_impl(self) -> None: |
| 2679 | self.connection._begin_impl(self) |
| 2680 | |
| 2681 | def _connection_rollback_impl(self) -> None: |
| 2682 | self.connection._rollback_impl() |
| 2683 | |
| 2684 | def _connection_commit_impl(self) -> None: |
| 2685 | self.connection._commit_impl() |
| 2686 | |
| 2687 | def _close_impl(self, try_deactivate: bool = False) -> None: |