Provide a transactional scope around a series of operations.
194595
def session_scope(nullpool):
    """"""
    if nullpool:
        engine = sqlalchemy.create_engine(
            app.config.get('SQLALCHEMY_DATABASE_URI'), poolclass=NullPool)
        session_class = sessionmaker()
        session_class.configure(bind=engine)
        session = session_class()
    else:
        session = db.session()
        session.commit()  # HACK

    try:
        yield session
        session.commit()
    except Exception as e:
        session.rollback()
        logging.exception(e)
        raise
    finally:
        session.close()
615795
def canonical_ops(ops):
    ''' 
    '''
    new_ops = sorted(set(ops), key=lambda x: (x.entity, x.action))
    return new_ops
234644
function(cb) {
      //console.log('tx running for ' + scope);
      // me.not_ready_ = true;
      // transaction should be active now
      var tx = me.mu_tx_.getTx();
      me.r_no_++;
      req.setTx(tx, me.getLabel() + 'R' + me.r_no_);
    }
459910
def _apply_scope(self, scope, builder):
        
        if callable(scope):
            scope(builder)
        elif isinstance(scope, Scope):
            scope.apply(builder, self.get_model())
1324310
def scoped_session_decorator(func):
    """"""

    @wraps(func)
    def wrapper(*args, **kwargs):
        with sessions_scope(session):
            # The session used in func comes from the funcs globals, but
            # it will be a proxied thread local var from the session
            # registry, and will therefore be identical to the one returned
            # by the context manager above.
            logger.debug("Running worker %s in scoped DB session", func.__name__)
            return func(*args, **kwargs)

    return wrapper
459603
public void doFinally() {
        if (conn != null) {
            try {
                if ((isolation != Connection.TRANSACTION_NONE)
                        && (isolation != origIsolation)) {
                    conn.setTransactionIsolation(origIsolation);
                }
                conn.setAutoCommit(true);
                conn.close();
            } catch (SQLException e) {
                // Not much we can do
            }
        }
        conn = null;
        isolation = Connection.TRANSACTION_NONE;
    }
270727
def tasks_in_scope(scope)
      prefix = scope.join(":")
      tasks.select { |t|
        /^#{prefix}:/ =~ t.name
      }
    end
877302
def Transactional(fn, self, *argv, **argd):
    
    return self._transactional(fn, *argv, **argd)
963966
def scoped_session_decorator(func):
    """"""
    @wraps(func)
    def wrapper(*args, **kwargs):
        from wallace.db import session as wallace_session
        with sessions_scope(wallace_session) as session:
            from psiturk.db import db_session as psi_session
            with sessions_scope(psi_session) as session_psiturk:
                # The sessions used in func come from the funcs globals, but
                # they will be proxied thread locals vars from the session
                # registry, and will therefore be identical to those returned
                # by the context managers above.
                logger.debug('Running worker %s in scoped DB sessions',
                             func.__name__)
                return func(*args, **kwargs)
    return wrapper
789745
function processScope(scope) {
  if (!isObject(scope) || scope._bsontype === 'ObjectID') {
    return scope;
  }

  const keys = Object.keys(scope);
  let key;
  const new_scope = {};

  for (let i = keys.length - 1; i >= 0; i--) {
    key = keys[i];
    if ('function' === typeof scope[key]) {
      new_scope[key] = new Code(String(scope[key]));
    } else {
      new_scope[key] = processScope(scope[key]);
    }
  }

  return new_scope;
}
594093
def commit(self):
        """"""
        if (not self._add_cache and
                not self._remove_cache and
                not self._undefined_cache):
            return

        for store_key, hash_values in self._add_cache.items():
            for hash_value in hash_values:
                super(TransactionalIndex, self).add_hashed_value(
                    hash_value, store_key)
        for store_key in self._remove_cache:
            super(TransactionalIndex, self).remove_key(store_key)
        for store_key in self._undefined_cache:
            super(TransactionalIndex, self).add_undefined(store_key)
        if not self.ephemeral:
            self.save_to_store()

        self._init_cache()
        self._in_transaction = True
513481
def scopes_as(self, new_scopes):
        
        old_scopes, self.scopes = self.scopes, new_scopes
        yield
        self.scopes = old_scopes
980944
def scopes(self, **kwargs):
        """"""
        return self._client.scopes(team=self.id, **kwargs)
1010768
def apply_ordering_to_scope(scope, user_params)
      sort_name, direction = calculate_sort_name_and_direction(user_params)
      order = configuration[:sort_orders].fetch(sort_name, {})[:value]

      ordered_scope = case order
        when Proc
          fresh_helper_instance.instance_exec(scope, direction, &order)
        when nil
          scope
        else
          scope.reorder(order.to_s + " " + direction)
      end

      fallback_deterministic_sort = assemble_primary_key_sort(scope)
      # Chain on a tiebreaker sort to ensure deterministic ordering of multiple pages of data

      if fallback_deterministic_sort
        ordered_scope.order(fallback_deterministic_sort)
      else
        ordered_scope
      end
    end
341473
def scoped_connection(func):
  '''
  
  '''
  def _with(series, *args, **kwargs):
    connection = None
    try:
      connection = series._connection()
      return func(series, connection, *args, **kwargs)
    finally:
      series._return( connection )
  return _with
83764
def _create_with_scope(body, kwargs):
    '''
    
    '''
    return ast.With(
        items=[
            ast.withitem(
                context_expr=_a.Call(
                    _a.Name('ContextScope'),
                    [_a.Name('context')],
                    keywords=kwargs,
                ),
                optional_vars=_a.Name('context', ctx=ast.Store())
            ),
        ],
        body=body,
    )
667771
def transactional_tasklet(func, args, kwds, **options):
  
  from . import tasklets
  func = tasklets.tasklet(func)
  return transactional_async.wrapped_decorator(func, args, kwds, **options)