note description: "Objects that provide an interface to access information in the database." author: "Patrick Ruckstuhl " date: "$Date$" revision: "$Revision$" deferred class DATABASE_ACCESS inherit A_SHARED_LOGGERS EXCEPTIONS O_ERRORS feature {NONE} -- Initialization make (a_db_handler: like db_handler; a_db_interface: like db_interface) -- Initialize Access Layer Object. -- If `a_db_interface' is provided, it can be used to call other access-layer functions require a_db_handler_ok: a_db_handler /= Void do db_handler := a_db_handler db_interface := a_db_interface create select_query.make (Current) ensure db_handler_set: db_handler = a_db_handler interface_set: db_interface = a_db_interface end feature {DATABASE_ACCESS, WI_FULL_WORKITEM} -- Interface access db_interface: BASE_INTERFACE -- Common Interface to all DB-Access classes feature {DATABASE_QUERY} -- Database access db_handler: DATABASE_HANDLER -- Database handler. handle_errors_and_warnings -- Check for database errors and warnings and log them. local l_control: DB_CONTROL l_warning: STRING do l_control := db_handler.db_control -- any errors? if not l_control.is_ok then node_logger.fatal ("Database error: "+l_control.error_message) l_control.reset -- reconnect to the db as this may have been a connection lost error l_control.disconnect l_control.connect raise (except_database_error) end l_warning := l_control.warning_message if l_warning /= Void and then not l_warning.is_empty then node_logger.warn ("Database warning: "+l_control.warning_message) end l_control.reset end feature {NONE} -- Implementation helper select_query: DATABASE_SELECT_QUERY -- Query object for select queries. feature -- Select queries last_insert_id: INTEGER -- Get id of last autoincrement local l_res: SELECTION_RESULT do l_res := select_query.execute_query ("SELECT LAST_INSERT_ID() AS id") handle_errors_and_warnings l_res.start Result := l_res.read_integer ("id") end invariant db_handler_not_void: db_handler /= Void select_query_not_void: select_query /= Void end