Provide a transactional scope around a series of operations.

        By default, ``expire_on_commit`` is set to False so that instances
        can be used outside the session.
163664
def begin(self, close=True, expire_on_commit=False, session=None,
              commit=False, **options):
        
        if not session:
            commit = True
            session = self.session(expire_on_commit=expire_on_commit,
                                   **options)
        else:
            close = False
        try:
            yield session
            if commit:
                session.commit()
        except Exception:
            session.rollback()
            raise
        finally:
            if close:
                session.close()
115653
def commit(self) -> None:
        
        now = datetime.now(timezone.utc)
        if self.first_commit_at is None:
            self.first_commit_at = now

        if self.mode == "r":
            response = self.engine.session.transaction_read(self._request)
        elif self.mode == "w":
            if now - self.first_commit_at > MAX_TOKEN_LIFETIME:
                raise TransactionTokenExpired
            response = self.engine.session.transaction_write(self._request, self.tx_id)
        else:
            raise ValueError(f"unrecognized mode {self.mode}")

        self._handle_response(response)
576375
def commit_manually(using=None):
    
    def entering(using):
        enter_transaction_management(using=using)

    def exiting(exc_value, using):
        leave_transaction_management(using=using)

    return _transaction_func(entering, exiting, using)
811408
def commit(self):
        
        self._check_state()
        database = self._session._database
        api = database.spanner_api
        metadata = _metadata_with_prefix(database.name)
        txn_options = TransactionOptions(read_write=TransactionOptions.ReadWrite())
        response = api.commit(
            self._session.name,
            self._mutations,
            single_use_transaction=txn_options,
            metadata=metadata,
        )
        self.committed = _pb_timestamp_to_datetime(response.commit_timestamp)
        return self.committed
1083853
def save(self, commit=True):
        

        db.session.add(self)
        if commit:
            db.session.commit()
        return self
286088
def commit(self):
		
		try:
			if self.connection is not None:
				self.connection.commit()
				self._updateCheckTime()
				self.release()
		except Exception, e:
			pass
271768
def save(self, must_create=False):
        
        obj = Session(
            session_key=self._get_or_create_session_key(),
            session_data=self.encode(self._get_session(no_load=must_create)),
            expire_date=self.get_expiry_date(),
            user_agent=self.user_agent,
            user_id=self.user_id,
            ip=self.ip,
        )
        using = router.db_for_write(Session, instance=obj)
        try:
            with transaction.atomic(using):
                obj.save(force_insert=must_create, using=using)
        except IntegrityError as e:
            if must_create and 'session_key' in str(e):
                raise CreateError
            raise
514402
def close_session(self, commit=True):
        
        if self._session is not None:
            if commit:
                self._session.commit()
            self._session.close()
            self._session = None
245989
def execute_until_in_scope(
    expr, scope, aggcontext=None, clients=None, post_execute_=None, **kwargs
):
    
    # these should never be None
    assert aggcontext is not None, 'aggcontext is None'
    assert clients is not None, 'clients is None'
    assert post_execute_ is not None, 'post_execute_ is None'

    # base case: our op has been computed (or is a leaf data node), so
    # return the corresponding value
    op = expr.op()
    if op in scope:
        return scope[op]

    new_scope = execute_bottom_up(
        expr,
        scope,
        aggcontext=aggcontext,
        post_execute_=post_execute_,
        clients=clients,
        **kwargs,
    )
    new_scope = toolz.merge(
        new_scope, pre_execute(op, *clients, scope=scope, **kwargs)
    )
    return execute_until_in_scope(
        expr,
        new_scope,
        aggcontext=aggcontext,
        clients=clients,
        post_execute_=post_execute_,
        **kwargs,
    )
1211023
def pexpire(self, ttl=None):
        
        if ttl is not None:
            self.database.pexpire(self.key, ttl)
        else:
            self.database.persist(self.key)
144834
def save_instance(self, instance, using_transactions=True, dry_run=False):
        
        self.before_save_instance(instance, using_transactions, dry_run)
        if not using_transactions and dry_run:
            # we don't have transactions and we want to do a dry_run
            pass
        else:
            instance.save()
        self.after_save_instance(instance, using_transactions, dry_run)
59377
def expire(self, name):
    '''
    
    '''
    for interval,config in self._intervals.items():
      if config['expire']:
        # Because we're storing the bucket time, expiry has the same
        # "skew" as whatever the buckets are.
        expire_from = config['i_calc'].to_bucket(time.time() - config['expire'])
        conn = self._client.connect()

        conn.execute( self._table.delete().where(
          and_(
            self._table.c.name==name,
            self._table.c.interval==interval,
            self._table.c.i_time<=expire_from
          )
        ))
11809
def commit(self, frame):
        
        if not frame.transaction:
            raise ProtocolError("Missing transaction for COMMIT command.")

        if not frame.transaction in self.engine.transactions:
            raise ProtocolError("Invalid transaction: %s" % frame.transaction)

        for tframe in self.engine.transactions[frame.transaction]:
            del tframe.headers['transaction']
            self.process_frame(tframe)

        self.engine.queue_manager.clear_transaction_frames(
            self.engine.connection, frame.transaction)
        del self.engine.transactions[frame.transaction]
1364478
def maybe_transactional(func):
    
    @wraps(func)
    def wrapper(*args, **kwargs):
        commit = kwargs.get("commit", True)
        with transaction(commit=commit):
            return func(*args, **kwargs)
    return wrapper
810390
def delete(self, session, commit=True, soft=True):
        
        if soft:
            self.time_removed = sqlalchemy.func.unix_timestamp()
        else:
            session.delete(self)

        if commit:
            session.commit()
414981
def commit_transaction(self):
        
        self._assert_open()
        if not self._transaction:
            raise TransactionError("No transaction to commit")
        metadata = {}
        try:
            self._connection.commit(on_success=metadata.update)
        finally:
            self._disconnect(sync=True)
            self._transaction = None
        bookmark = metadata.get("bookmark")
        self._bookmarks_in = tuple([bookmark])
        self._bookmark_out = bookmark
        return bookmark
1148399
def committed!(should_run_callbacks: true) #:nodoc:
      if should_run_callbacks && trigger_transactional_callbacks?
        @_committed_already_called = true
        _run_commit_without_transaction_enrollment_callbacks
        _run_commit_callbacks
      end
    ensure
      @_committed_already_called = false
      force_clear_transaction_record_state
    end