Represent a two-phase transaction. A new :class:`.TwoPhaseTransaction` object may be procured using the :meth:`_engine.Connection.begin_twophase` method. The interface is the same as that of :class:`.Transaction` with the addition of the :meth:`prepare` method.
| 2850 | |
| 2851 | |
| 2852 | class TwoPhaseTransaction(RootTransaction): |
| 2853 | """Represent a two-phase transaction. |
| 2854 | |
| 2855 | A new :class:`.TwoPhaseTransaction` object may be procured |
| 2856 | using the :meth:`_engine.Connection.begin_twophase` method. |
| 2857 | |
| 2858 | The interface is the same as that of :class:`.Transaction` |
| 2859 | with the addition of the :meth:`prepare` method. |
| 2860 | |
| 2861 | """ |
| 2862 | |
| 2863 | __slots__ = ("xid", "_is_prepared") |
| 2864 | |
| 2865 | xid: Any |
| 2866 | |
| 2867 | def __init__(self, connection: Connection, xid: Any): |
| 2868 | self._is_prepared = False |
| 2869 | self.xid = xid |
| 2870 | super().__init__(connection) |
| 2871 | |
| 2872 | def prepare(self) -> None: |
| 2873 | """Prepare this :class:`.TwoPhaseTransaction`. |
| 2874 | |
| 2875 | After a PREPARE, the transaction can be committed. |
| 2876 | |
| 2877 | """ |
| 2878 | if not self.is_active: |
| 2879 | raise exc.InvalidRequestError("This transaction is inactive") |
| 2880 | self.connection._prepare_twophase_impl(self.xid) |
| 2881 | self._is_prepared = True |
| 2882 | |
| 2883 | def _connection_begin_impl(self) -> None: |
| 2884 | self.connection._begin_twophase_impl(self) |
| 2885 | |
| 2886 | def _connection_rollback_impl(self) -> None: |
| 2887 | self.connection._rollback_twophase_impl(self.xid, self._is_prepared) |
| 2888 | |
| 2889 | def _connection_commit_impl(self) -> None: |
| 2890 | self.connection._commit_twophase_impl(self.xid, self._is_prepared) |
| 2891 | |
| 2892 | |
| 2893 | class Engine( |