def __init__(self, dbName, username, password, schema): self.db = db2util.db() try: self.db.connect(dbName, username, password) except: #logger.error("Failed to open a connection to database %s as user %s" %(dbName, username)) raise self.schema = schema table_names = [ 'RESERVATION_DATA', 'RESERVATION_PARTS', 'RESERVATION_EVENTS', 'RESERVATION_USERS', 'RESERVATION_PROG', 'JOB_DATA', 'JOB_ATTR', 'JOB_DEPS', 'JOB_EVENTS', 'JOB_COBALT_STATES', 'JOB_PROG', 'JOB_SUMMARY' ] #Handle tables, There is probably a better way to do this. self.tables = {} self.daos = {} try: for table_name in table_names: #logger.info("Accessing table: %s" % table_name) self.tables[table_name] = db2util.table( self.db, schema, table_name) if table_name in [ 'RESERVATION_EVENTS', 'JOB_EVENTS', 'JOB_COBALT_STATES' ]: self.daos[table_name] = StateTableData( self.db, schema, self.tables[table_name].table) elif table_name == 'RESERVATION_DATA': self.daos[table_name] = ResDataData( self.db, schema, self.tables[table_name].table) elif table_name == 'JOB_DATA': self.daos[table_name] = JobDataData( self.db, schema, self.tables[table_name].table) elif table_name == 'JOB_DEPS': self.daos[table_name] = JobDepsData( self.db, schema, self.tables[table_name].table) elif table_name == 'JOB_PROG': self.daos[table_name] = JobProgData( self.db, schema, self.tables[table_name].table) elif table_name == 'JOB_SUMMARY': self.daos[table_name] = JobSummaryData( self.db, schema, self.tables[table_name].table) else: self.daos[table_name] = AccessOnlyDAO( self.db, schema, self.tables[table_name].table) except: #logger.error("Error accessing table %s!" % table_name) self.db.close() raise #we opened with a schema, let's make that the default for now. self.db.prepExec("set current schema %s" % schema)
def __init__(self, dbName, username, password, schema): self.db = db2util.db() try: self.db.connect(dbName, username, password) except: logger.error("Failed to open a connection to database %s as user %s" %(dbName, username)) raise self.schema = schema table_names = ['RESERVATION_DATA', 'RESERVATION_PARTS', 'RESERVATION_EVENTS', 'RESERVATION_USERS', 'RESERVATION_PROG', 'JOB_DATA', 'JOB_ATTR', 'JOB_DEPS', 'JOB_EVENTS','JOB_COBALT_STATES', 'JOB_PROG', 'JOB_RUN_USERS'] no_pk_tables = ['RESERVATION_PARTS', 'RESERVATION_USERS', 'JOB_ATTR', 'JOB_RUN_USERS'] #Handle tables, There is probably a better way to do this. self.daos = {} try: for table_name in table_names: logger.info("Accessing table: %s" % table_name) if table_name in ['RESERVATION_EVENTS', 'JOB_EVENTS', 'JOB_COBALT_STATES']: self.daos[table_name] = StateTableData(self.db, schema, table_name) elif table_name == 'RESERVATION_DATA': self.daos[table_name] = ResDataData(self.db, schema, table_name) elif table_name == 'JOB_DATA': self.daos[table_name] = JobDataData(self.db, schema, table_name) elif table_name == 'JOB_DEPS': self.daos[table_name] = JobDepsData(self.db, schema, table_name) elif table_name == 'JOB_PROG': self.daos[table_name] = JobProgData(self.db, schema, table_name) elif table_name in no_pk_tables: self.daos[table_name] = no_pk_dao(self.db, schema, table_name) else: self.daos[table_name] = db2util.dao(self.db, schema, table_name) except: logger.error("Error accessing table %s!" % table_name) self.db.close() raise #we opened with a schema, let's make that the default for now. self.db.prepExec("set current schema %s" % schema)
def __db_startup(self): Cobalt.Util.init_cobalt_config() if 'db2util' not in sys.modules: global db2util import db2util self.hostname = socket.getfqdn() self.resource_name = Cobalt.Util.get_config_option(DB_SECTION, "resource_name") self.db = db2util.db() try: # No defaults here; if the param doesn't exist we may as well bomb out self.db.connect(Cobalt.Util.get_config_option(DB_SECTION, "database"), Cobalt.Util.get_config_option(DB_SECTION, "user"), Cobalt.Util.get_config_option(DB_SECTION, "pwd")) except db2util.dbError, err: # We wanted to log here, but no logging available (yet) raise