Wrap statements in a transaction. If the statements succeed, commit, otherwise rollback.

  :param data_access: a DataAccess instance

def transaction(data_access):
  """Wrap statements in a transaction. If the statements succeed, commit, otherwise rollback.

  :param data_access: a DataAccess instance
  """
  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