示例#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 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()
示例#3
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()
示例#4
0
    def create_from(self, entity, session=None):
        """Sub-class hook: create from entity."""
        if not entity:
            msg = u._(
                "Must supply non-None {entity_name}."
            ).format(entity_name=self._do_entity_name())
            raise Exception(msg)

        if entity.id:
            msg = u._(
                "Must supply {entity_name} with id=None (i.e. new entity)."
            ).format(entity_name=self._do_entity_name())
            raise Exception(msg)

        LOG.debug("Begin create from...")
        session = self.get_session(session)
        start = time.time()  # DEBUG

        # Validate the attributes before we go any further. From my
        # (unknown Glance developer) investigation, the @validates
        # decorator does not validate
        # on new records, only on existing records, which is, well,
        # idiotic.
        self._do_validate(entity.to_dict())

        try:
            LOG.debug("Saving entity...")
            entity.save(session=session)
        except db_exc.DBDuplicateEntry as e:
            session.rollback()
            LOG.exception('Problem saving entity for create')
            error_msg = re.sub('[()]', '', str(e.args))
            raise Exception(error_msg)

        LOG.debug('Elapsed repo '
                  'create vmexpire:%s', (time.time() - start))  # DEBUG

        return entity