note description: "Database handler" author: "Patrick Ruckstuhl " date: "$Date$" revision: "$Revision$" class DATABASE_HANDLER inherit A_SHARED_LOGGERS create make feature {NONE} -- Initialization make (a_host, a_data_source, a_user, a_password: STRING) -- Initialize. require a_host_ok: a_host /= Void and then not a_host.is_empty a_data_source_ok: a_data_source /= Void and then not a_data_source.is_empty a_user_ok: a_user /= Void and then not a_user.is_empty a_password_ok: a_password /= Void and then not a_password.is_empty do create db_application db_application.set_hostname (a_host) db_application.set_data_source (a_data_source) db_application.login (a_user, a_password) db_application.set_base create db_control.make db_control.connect if not db_control.is_connected then node_logger.fatal ("Could not connect to database") else node_logger.info ("Connected to database") end load_repositories end feature -- Access feature {DATABASE_ACCESS} -- Database access db_application: DATABASE_APPL [ODBC] -- Database application to use. db_control: DB_CONTROL -- Database control. db_repositories: HASH_TABLE [DB_REPOSITORY, STRING] -- Database repositories mapped to the table name. feature {NONE} -- Implementation load_repositories -- Load repository for each table into db_repositories. local l_query: DB_SELECTION l_tables: ARRAYED_LIST [DB_RESULT] l_result: DB_DATA_SQL l_table: STRING l_repo: DB_REPOSITORY do create db_repositories.make (10) -- get available tables create l_query.make l_query.set_query ("SHOW TABLES") l_query.execute_query if not db_control.is_ok then node_logger.fatal (db_control.error_message) else create l_tables.make (10) l_query.set_container (l_tables) l_query.load_result from l_tables.start until l_tables.after loop -- foreach table, create the repository l_result ?= l_tables.item.data l_table := l_result.item (1).out create l_repo.make (l_table) l_repo.load if not l_repo.exists then node_logger.fatal ("Could not retrieve repository for table "+l_table) else db_repositories.force (l_repo, l_table) node_logger.debugging ("Retrieved repository for table "+l_table) end l_tables.forth end end ensure db_repositories_set: db_repositories /= Void end invariant db_application_not_void: db_application /= Void db_control_not_void: db_control /= Void db_repositories_not_void: db_repositories /= Void end