示例#1
0
 def __check_state_base(self, opname):
     if self._state is TransactionState.COMMITTED:
         raise errors.InterfaceError(
             f'cannot {opname}; the transaction is already committed')
     if self._state is TransactionState.ROLLEDBACK:
         raise errors.InterfaceError(
             f'cannot {opname}; the transaction is already rolled back')
     if self._state is TransactionState.FAILED:
         raise errors.InterfaceError(
             f'cannot {opname}; the transaction is in error state')
示例#2
0
 async def __aenter__(self):
     if self._managed:
         raise errors.InterfaceError(
             'cannot enter context: already in an `async with` block')
     self._managed = True
     await self.start()
     return self
示例#3
0
 async def _ensure_transaction(self):
     if not self._managed:
         raise errors.InterfaceError(
             "Only managed retriable transactions are supported. "
             "Use `async with transaction:`")
     if not self.__started:
         self.__started = True
         if self._connection.is_closed():
             await self._connection.connect(
                 single_attempt=self.__iteration != 0)
         await self.start()
示例#4
0
 def _make_start_query(self):
     self.__check_state_base('start')
     if self._state is TransactionState.STARTED:
         raise errors.InterfaceError(
             'cannot start; the transaction is already started')
     return self._make_start_query_inner()
示例#5
0
 def __check_state(self, opname):
     if self._state is not TransactionState.STARTED:
         if self._state is TransactionState.NEW:
             raise errors.InterfaceError(
                 f'cannot {opname}; the transaction is not yet started')
         self.__check_state_base(opname)
示例#6
0
 async def rollback(self) -> None:
     if self._managed:
         raise errors.InterfaceError(
             'cannot manually rollback from within an `async with` block')
     await self._rollback()
示例#7
0
 async def commit(self) -> None:
     if self._managed:
         raise errors.InterfaceError(
             'cannot manually commit from within an `async with` block')
     await self._commit()