indexing description: "Database access to release and release workitem data." author: "Peter Wyss " date: "$Date$" revision: "$Revision$" class RELEASE_ACCESS inherit DATABASE_ACCESS create make feature -- Status is_found: BOOLEAN -- Did the last retrieve query find a release? feature -- Access last_release_workitem: TUPLE[workitem_id: INTEGER; release_id: INTEGER; name: STRING; description: STRING; version: STRING; files: ARRAYED_LIST[TUPLE[name: STRING; platform: STRING]]] -- Last retrieved release workitem by a retrieve query. last_release: TUPLE[release_id: INTEGER; project_id: INTEGER; creation_time: INTEGER; name: STRING; description: STRING; version: STRING; files: ARRAYED_LIST[TUPLE[name: STRING; platform: STRING]]] -- Last retrieved release by a retrieve query. feature -- Select queries retrieve_releases (a_project: INTEGER): ARRAYED_LIST[TUPLE [release_id: INTEGER; project: INTEGER; creation_time: INTEGER; name: STRING; description: STRING; version: STRING; files: ARRAYED_LIST [TUPLE [name: STRING; platform: STRING]]]] is -- Retrieve releases for a_project require a_project_valid: a_project > 0 local l_selection: SELECTION_RESULT l_selection_files: SELECTION_RESULT l_tuple: TUPLE [release_id: INTEGER; project: INTEGER; creation_time: INTEGER; name: STRING; description: STRING; version: STRING; files: ARRAYED_LIST [TUPLE [name: STRING; platform: STRING]]] l_files: ARRAYED_LIST [TUPLE [name: STRING; platform: STRING]] l_file: TUPLE [name: STRING; platform: STRING] do select_query.set_map_name (a_project, "project_id") l_selection := select_query.execute_query ("[ SELECT `release_id`, `creation_time`, `name`, `description`, `version` FROM `release` WHERE `project_id` = :project_id ]") -- get result and put it into an arrayed list as named tuples from create Result.make (l_selection.count) l_selection.start until l_selection.after loop create l_tuple l_tuple.release_id := l_selection.read_integer ("release_id") l_tuple.project := a_project l_tuple.creation_time := l_selection.read_integer ("creation_time") l_tuple.name := l_selection.read_string ("name") l_tuple.description := l_selection.read_string ("description") l_tuple.version := l_selection.read_string ("version") create l_files.make (1) select_query.set_map_name (l_tuple.release_id, "release_id") l_selection_files := select_query.execute_query ("[ SELECT `name`, `platform` FROM `release_file` WHERE `release_id` = :release_id ]") from l_selection_files.start until l_selection_files.after loop create l_file l_file.name := l_selection_files.read_string ("name") l_file.platform := l_selection_files.read_string ("platform") l_files.force (l_file) l_selection_files.forth end l_tuple.files := l_files Result.force (l_tuple) l_selection.forth end ensure Result_set: Result /= Void end retrieve_release_by_id (a_id: INTEGER) is -- Retrieve a release by a_id. require a_id_ok: a_id > 0 local l_selection: DB_SELECTION l_release_list_filling: DB_ACTION [RELEASE] l_release: RELEASE l_last_release: RELEASE l_release_file_list_filling: DB_ACTION [RELEASE_FILE] l_release_file: RELEASE_FILE l_release_files: LIST [RELEASE_FILE] l_files: ARRAYED_LIST[TUPLE[name: STRING; platform: STRING]] l_file: TUPLE[name: STRING; platform: STRING] do create l_release.make create l_selection.make l_selection.set_map_name (a_id, "release_id") l_selection.query ("SELECT * FROM `release` WHERE release_id=:release_id") handle_errors_and_warnings l_selection.object_convert (l_release) create l_release_list_filling.make (l_selection, l_release) l_selection.set_action (l_release_list_filling) l_selection.load_result l_selection.terminate if l_release_list_filling.list.count = 1 then l_last_release := l_release_list_filling.list.first -- get files for release create l_release_file.make create l_selection.make l_selection.set_map_name (a_id, "release_id") l_selection.query ("SELECT * FROM release_file WHERE release_id=:release_id") handle_errors_and_warnings l_selection.object_convert (l_release_file) create l_release_file_list_filling.make (l_selection, l_release_file) l_selection.set_action (l_release_file_list_filling) l_selection.load_result l_selection.terminate -- create the complete workitem create last_release last_release.release_id := a_id last_release.project_id := l_last_release.project_id last_release.creation_time := l_last_release.creation_time last_release.name := l_last_release.name last_release.description := l_last_release.description last_release.version := l_last_release.version l_release_files := l_release_file_list_filling.list create l_files.make (l_release_files.count) from l_release_files.start until l_release_files.after loop create l_file l_file.name := l_release_files.item.name l_file.platform := l_release_files.item.platform l_files.force (l_file) l_release_files.forth end last_release.files := l_files is_found := True else is_found := False end ensure is_found_implies_release: is_found implies last_release /= Void end retrieve_release_workitem_by_id (a_id: INTEGER) is -- Retrieve a release workitem by a_id. require a_id_ok: a_id > 0 local l_selection: DB_SELECTION l_release_workitem_list_filling: DB_ACTION [WORKITEM_RELEASE] l_release_workitem: WORKITEM_RELEASE l_last_release_workitem: WORKITEM_RELEASE l_release_list_filling: DB_ACTION [RELEASE] l_release: RELEASE l_last_release: RELEASE l_release_file_list_filling: DB_ACTION [RELEASE_FILE] l_release_file: RELEASE_FILE l_release_files: LIST [RELEASE_FILE] l_files: ARRAYED_LIST[TUPLE[name: STRING; platform: STRING]] l_file: TUPLE[name: STRING; platform: STRING] do -- get release id create l_release_workitem.make create l_selection.make l_selection.set_map_name (a_id, "workitem_id") l_selection.query ("SELECT * FROM workitem_release WHERE workitem_id=:workitem_id") handle_errors_and_warnings l_selection.object_convert (l_release_workitem) create l_release_workitem_list_filling.make (l_selection, l_release_workitem) l_selection.set_action (l_release_workitem_list_filling) l_selection.load_result l_selection.terminate if l_release_workitem_list_filling.list.count = 1 then l_last_release_workitem := l_release_workitem_list_filling.list.first -- get release base data create l_release.make create l_selection.make l_selection.set_map_name (l_last_release_workitem.release_id, "release_id") l_selection.query ("SELECT * FROM `release` WHERE release_id=:release_id") handle_errors_and_warnings l_selection.object_convert (l_release) create l_release_list_filling.make (l_selection, l_release) l_selection.set_action (l_release_list_filling) l_selection.load_result l_selection.terminate if l_release_list_filling.list.count = 1 then l_last_release := l_release_list_filling.list.first -- get files for release create l_release_file.make create l_selection.make l_selection.set_map_name (l_last_release_workitem.release_id, "release_id") l_selection.query ("SELECT * FROM release_file WHERE release_id=:release_id") handle_errors_and_warnings l_selection.object_convert (l_release_file) create l_release_file_list_filling.make (l_selection, l_release_file) l_selection.set_action (l_release_file_list_filling) l_selection.load_result l_selection.terminate if l_release_file_list_filling.list.count > 0 then -- create the complete workitem create last_release_workitem last_release_workitem.workitem_id := a_id last_release_workitem.release_id := l_last_release_workitem.release_id last_release_workitem.name := l_last_release.name last_release_workitem.description := l_last_release.description last_release_workitem.version := l_last_release.version l_release_files := l_release_file_list_filling.list create l_files.make (l_release_files.count) from l_release_files.start until l_release_files.after loop create l_file l_file.name := l_release_files.item.name l_file.platform := l_release_files.item.platform l_files.force (l_file) l_release_files.forth end last_release_workitem.files := l_files is_found := True else is_found := False end else is_found := False end else is_found := False end ensure is_found_implies_release: is_found implies last_release_workitem /= Void end feature -- Insert queries insert_release_workitem (a_release: WORKITEM_RELEASE) is -- Add a_release as a new release workitem. require a_release_not_void: a_release /= Void local l_store: DB_STORE do create l_store.make l_store.set_repository (db_handler.db_repositories.item ("workitem_release")) l_store.put (a_release) handle_errors_and_warnings end insert_release (a_release: RELEASE) is -- Add a_release as a new release. require a_release_not_void: a_release /= Void local l_store: DB_CHANGE do create l_store.make l_store.set_map_name (a_release.project_id, "project_id") l_store.set_map_name (a_release.name, "name") l_store.set_map_name (a_release.description, "description") l_store.set_map_name (a_release.version, "version") l_store.modify ("INSERT `release` SET `project_id`=:project_id, `name`=:name, `description`=:description, `version`=:version, `creation_time`=UNIX_TIMESTAMP()") handle_errors_and_warnings end insert_release_file (a_file: RELEASE_FILE) is -- Add a_file as a new release file. require a_file_not_void: a_file /= Void local l_store: DB_STORE do create l_store.make l_store.set_repository (db_handler.db_repositories.item ("release_file")) l_store.put (a_file) handle_errors_and_warnings end feature -- Delete queries delete_release (a_release_id: INTEGER) is -- Delete release with a_release_id. require a_release_id_ok: a_release_id > 0 local l_change: DB_CHANGE do create l_change.make l_change.set_map_name (a_release_id, "release_id") l_change.modify ("DELETE FROM `release` WHERE `release_id`=:release_id") handle_errors_and_warnings end end