예제 #1
0
파일: api.py 프로젝트: chessbyte/congress
def rollback_unlock_tables(session):
    """Rollback and unlock tables

    supported backends: MySQL and PostgreSQL
    """
    session.rollback()

    # unlock
    if is_mysql():
        session.execute('UNLOCK TABLES')
예제 #2
0
def commit_unlock_tables(session):
    """Commit and unlock tables for supported backends: MySQL and PostgreSQL"""
    session.commit()
    session.execute('COMMIT')  # execute COMMIT on DB backend
    # because sqlalchemy session does not guarantee
    # exact boundary correspondence to DB backend transactions
    # We must guarantee DB commits transaction before UNLOCK

    # unlock
    if is_mysql():
        session.execute('UNLOCK TABLES')
예제 #3
0
def rollback_unlock_tables(session):
    """Rollback and unlock tables

    supported backends: MySQL and PostgreSQL
    """
    # unlock
    if is_mysql():
        session.execute('UNLOCK TABLES')

    # postgres automatically releases lock at transaction end

    session.rollback()
예제 #4
0
파일: api.py 프로젝트: openstack/congress
def rollback_unlock_tables(session):
    """Rollback and unlock tables

    supported backends: MySQL and PostgreSQL
    """
    # unlock
    if is_mysql():
        session.execute('UNLOCK TABLES')

    # postgres automatically releases lock at transaction end

    session.rollback()
예제 #5
0
def commit_unlock_tables(session):
    """Commit and unlock tables for supported backends: MySQL and PostgreSQL"""
    try:
        session.execute('COMMIT')  # execute COMMIT on DB backend
        session.commit()
        # because sqlalchemy session does not guarantee
        # exact boundary correspondence to DB backend transactions
        # We must guarantee DB commits transaction before UNLOCK

        # unlock
        if is_mysql():
            session.execute('UNLOCK TABLES')
        # postgres automatically releases lock at transaction end
    except db_exc.DBDataError as exc:
        LOG.exception('Database backend experienced data error.')
        raise congress_exc.DatabaseDataError(data=exc)
예제 #6
0
파일: api.py 프로젝트: openstack/congress
def commit_unlock_tables(session):
    """Commit and unlock tables for supported backends: MySQL and PostgreSQL"""
    try:
        session.execute('COMMIT')  # execute COMMIT on DB backend
        session.commit()
        # because sqlalchemy session does not guarantee
        # exact boundary correspondence to DB backend transactions
        # We must guarantee DB commits transaction before UNLOCK

        # unlock
        if is_mysql():
            session.execute('UNLOCK TABLES')
        # postgres automatically releases lock at transaction end
    except db_exc.DBDataError as exc:
        LOG.exception('Database backend experienced data error.')
        raise congress_exc.DatabaseDataError(data=exc)
예제 #7
0
def lock_tables(session, tables):
    """Write-lock tables for supported backends: MySQL and PostgreSQL"""
    session.begin(subtransactions=True)
    if is_mysql():  # Explicitly LOCK TABLES for MySQL
        session.execute('SET autocommit=0')
        session.execute('LOCK TABLES {}'.format(
            ','.join([table + ' WRITE' for table in tables])))
    elif is_postgres():  # Explicitly LOCK TABLE for Postgres
        session.execute('BEGIN TRANSACTION')
        for table in tables:
            session.execute('LOCK TABLE {} IN EXCLUSIVE MODE'.format(table))
예제 #8
0
파일: api.py 프로젝트: openstack/congress
def lock_tables(session, tables):
    """Write-lock tables for supported backends: MySQL and PostgreSQL"""
    session.begin(subtransactions=True)
    if is_mysql():  # Explicitly LOCK TABLES for MySQL
        session.execute('SET autocommit=0')
        session.execute('LOCK TABLES {}'.format(
            ','.join([table + ' WRITE' for table in tables])))
    elif is_postgres():  # Explicitly LOCK TABLE for Postgres
        session.execute('BEGIN TRANSACTION')
        for table in tables:
            session.execute('LOCK TABLE {} IN EXCLUSIVE MODE'.format(table))