This returns a context guard which will automatically open and close a transaction
482979
def transaction(self,implicit = False):
        

        class TransactionManager(object):

            def __init__(self,backend,implicit = False):
                self.backend = backend
                self.implicit =  implicit

            def __enter__(self):
                self.within_transaction = True if self.backend.current_transaction else False
                self.transaction = self.backend.begin()

            def __exit__(self,exc_type,exc_value,traceback_obj):
                if exc_type:
                    self.backend.rollback(self.transaction)
                    return False
                else:
                    #if the transaction has been created implicitly and we are not within
                    #another transaction, we leave it open (the user needs to call commit manually)
                    #if self.implicit and not self.within_transaction:
                    #    return
                    self.backend.commit(self.transaction)

        return TransactionManager(self,implicit = implicit)
197042
function _tE(e, c) {
        var eT = new Y.EventTarget().publish('transaction:' + e),
            a = c.arguments,
            cT = c.context || Y;

        if (a) {
            eT.on(c.on[e], cT, a);
        }
        else {
            eT.on(c.on[e], cT);
        }

        return eT;
    }
1130730
private void initCld(final TransactionImpl tx)
    {
        final IndirectionHandler handler = ProxyHelper.getIndirectionHandler(obj);
        if(handler != null)
        {
            this.handler = handler;
            isNew = Boolean.FALSE;
            identity = handler.getIdentity();
            if(handler.alreadyMaterialized())
            {
                cld = tx.getBroker().getClassDescriptor(handler.getRealSubject().getClass());
            }
            else
            {
                cld = tx.getBroker().getClassDescriptor(identity.getObjectsRealClass());
            }
        }
        else
        {
            cld = tx.getBroker().getClassDescriptor(obj.getClass());
        }
    }
1094178
def commit(self):
        
        self._assert_open()
        if self._autocommit:
            return
        if not self._conn.tds72_transaction:
            return
        self._main_cursor._commit(cont=True, isolation_level=self._isolation_level)
659462
public TransactionContext createTransactionContext() {
    transactionContext = dataFabricFacade.createTransactionManager();
    for (TransactionAware transactionAware : transactionAwares) {
      this.transactionContext.addTransactionAware(transactionAware);
    }
    return transactionContext;
  }
332332
def before
      return if WineBouncer.configuration.disable_block.call

      set_auth_strategy(WineBouncer.configuration.auth_strategy)
      auth_strategy.api_context = context
      #extend the context with auth methods.
      context.extend(WineBouncer::AuthMethods)
      context.protected_endpoint = endpoint_protected?
      return unless context.protected_endpoint?
      self.doorkeeper_request = env # set request for later use.
      doorkeeper_authorize!(*auth_scopes)
      context.doorkeeper_access_token = doorkeeper_token
    end
705455
def _start_separate_timer(self, transaction):
        
        t = threading.Timer(defines.ACK_TIMEOUT, self._send_ack, (transaction,))
        t.start()
        return t
1295032
public final T execute()
   {
      boolean txOwner = !TransactionElf.hasTransactionManager() || TransactionElf.beginOrJoinTransaction();
      Connection connection = null;
      try {
         connection = ConnectionProxy.wrapConnection(dataSource.getConnection());
         if (txOwner) {
            // disable autoCommit mode as we are going to handle transaction by ourselves
            connection.setAutoCommit(false);
         }
         return (args == null)
            ? execute(connection)
            : execute(connection, args);
      }
      catch (SQLException e) {
         if (e.getNextException() != null) {
            e = e.getNextException();
         }
         if (txOwner) {
            // set the txOwner to false as we no longer own the transaction and we shouldn't try to commit it later
            txOwner = false;
            rollback(connection);
         }
         throw new RuntimeException(e);
      } catch (Throwable e) {
         if (txOwner) {
            txOwner = false;
            rollback(connection);
         }
         throw e;
      }
      finally {
         try {
            if (txOwner) {
               commit(connection);
            }
         }
         finally {
            quietClose(connection);
         }
      }
   }
1184969
def lock(self, fail_on_lock=False, cleanup=False):
        
        return self.connection.lock(self, fail_on_lock, cleanup)
744307
def _callInTransaction(self, func, *args, **kwargs):
        """"""
        # No nesting of transactions
        self.conn.rollback()

        try:
            self.cur = self.conn.cursor()
            try:
                ret = func(*args, **kwargs)
            finally:
                self.cur.close()
                self.cur = None
        except:
            self.conn.rollback()
            raise
        else:
            self.conn.commit()

        return ret
284284
void doCloseConnection(DirContext context, ContextSource contextSource)
            throws javax.naming.NamingException {
        DirContextHolder transactionContextHolder = (DirContextHolder) TransactionSynchronizationManager
                .getResource(contextSource);
        if (transactionContextHolder == null
                || transactionContextHolder.getCtx() != context) {
            log.debug("Closing context");
            // This is not the transactional context or the transaction is
            // no longer active - we should close it.
            context.close();
        } else {
            log.debug("Leaving transactional context open");
        }
    }
260041
async def start(self):
        """"""
        self.__check_state_base('start')
        if self._state is TransactionState.STARTED:
            raise apg_errors.InterfaceError(
                'cannot start; the transaction is already started')

        con = self._connection

        if con._top_xact is None:
            if con._protocol.is_in_transaction():
                raise apg_errors.InterfaceError(
                    'cannot use Connection.transaction() in '
                    'a manually started transaction')
            con._top_xact = self
        else:
            # Nested transaction block
            top_xact = con._top_xact
            if self._isolation != top_xact._isolation:
                raise apg_errors.InterfaceError(
                    'nested transaction has a different isolation level: '
                    'current {!r} != outer {!r}'.format(
                        self._isolation, top_xact._isolation))
            self._nested = True

        if self._nested:
            self._id = con._get_unique_id('savepoint')
            query = 'SAVEPOINT {};'.format(self._id)
        else:
            if self._isolation == 'read_committed':
                query = 'BEGIN;'
            elif self._isolation == 'repeatable_read':
                query = 'BEGIN ISOLATION LEVEL REPEATABLE READ;'
            else:
                query = 'BEGIN ISOLATION LEVEL SERIALIZABLE'
                if self._readonly:
                    query += ' READ ONLY'
                if self._deferrable:
                    query += ' DEFERRABLE'
                query += ';'

        try:
            await self._connection.execute(query)
        except BaseException:
            self._state = TransactionState.FAILED
            raise
        else:
            self._state = TransactionState.STARTED
27665
def transaction(data_access):
  
  old_autocommit = data_access.autocommit
  data_access.autocommit = False
  try:
    yield data_access
  except RollbackTransaction as ex:
    data_access.rollback()
  except Exception as ex:
    data_access.rollback()
    raise ex
  else:
    data_access.commit()
  finally:
    data_access.autocommit = old_autocommit
922836
void entered(Transaction txn, Transaction parent) {
        TransactionMonitor monitor = mMonitor;
        if (monitor != null) {
            monitor.entered(txn, parent);
        }
    }
882598
private TransactionContext getOrCreateTransactionContext()
   {
      TransactionContext ctx = contexts.get();
      if (ctx == null)
      {
         // No transaction context exists so we create a new one
         ctx = new TransactionContext();
         contexts.set(ctx);
      }
      return ctx;
   }
244666
def context(self, name, ctx):
        
        self.enter_context(name, ctx)
        try:
            yield
        finally:
            self.exit_context(name)
729806
def create_transaction(self, *args: Any, **kwargs: Any) -> BaseTransaction:
        
        return self.get_transaction_class()(*args, **kwargs)