# Path: HPCStats/Exceptions.py
# class HPCStatsDBIntegrityError(HPCStatsException):
# 
#     """Class for DB intregrity errors exceptions in HPCStats"""
# 
#     def __init__(self, msg):
# 
#         super(HPCStatsDBIntegrityError, self).__init__(msg)
# 
# class HPCStatsRuntimeError(HPCStatsException):
# 
#     """Class for runtime errors exceptions in HPCStats"""
# 
#     def __init__(self, msg):
# 
#         super(HPCStatsRuntimeError, self).__init__(msg)


import logging
from HPCStats.Exceptions import HPCStatsDBIntegrityError, HPCStatsRuntimeError
        req = """
                SELECT domain_id
                  FROM Domain
                 WHERE domain_id = %s
              """
        params = ( self.key, )
        db.execute(req, params)
        nb_rows = db.cur.rowcount
        if nb_rows == 0:
            logger.debug("domain %s not found in DB", str(self))
            self.exists = False
        elif nb_rows > 1:
            raise HPCStatsDBIntegrityError(
                    "several domain found in DB for domain %s" \
                      % (str(self)))
        else:
            logger.debug("domain %s found in DB", str(self))
            self.exists = True
        return self.exists

    def save(self, db):
        """Insert Domain in database. It first makes sure that the Domain does
           not already exist in database yet by calling Domain.existing()
           method if needed. If the domain already exists in database, it
           raises HPCStatsRuntimeError.
        """

        if self.exists is None: # not checked yet
            self.existing(db)
        if self.exists is True:

# Path: HPCStats/Exceptions.py
# class HPCStatsDBIntegrityError(HPCStatsException):
# 
#     """Class for DB intregrity errors exceptions in HPCStats"""
# 
#     def __init__(self, msg):
# 
#         super(HPCStatsDBIntegrityError, self).__init__(msg)
# 
# class HPCStatsRuntimeError(HPCStatsException):
# 
#     """Class for runtime errors exceptions in HPCStats"""
# 
#     def __init__(self, msg):
# 
#         super(HPCStatsRuntimeError, self).__init__(msg)


# Path: HPCStats/Model/Domain.py
import logging
from HPCStats.Exceptions import HPCStatsDBIntegrityError, HPCStatsRuntimeError

        req = """
                SELECT domain_id
                  FROM Domain
                 WHERE domain_id = %s
              """
        params = ( self.key, )
        db.execute(req, params)
        nb_rows = db.cur.rowcount
        if nb_rows == 0:
            logger.debug("domain %s not found in DB", str(self))
            self.exists = False
        elif nb_rows > 1:
            raise HPCStatsDBIntegrityError(
                    "several domain found in DB for domain %s" \
                      % (str(self)))
        else:
            logger.debug("domain %s found in DB", str(self))
            self.exists = True
        return self.exists

    def save(self, db):
        """Insert Domain in database. It first makes sure that the Domain does
           not already exist in database yet by calling Domain.existing()
           method if needed. If the domain already exists in database, it
           raises HPCStatsRuntimeError.
        """

        if self.exists is None: # not checked yet
            self.existing(db)
        if self.exists is True:

            raise HPCStatsRuntimeError(