indexing description: "Database access to commit workitem data." author: "Peter Wyss " date: "$Date$" revision: "$Revision$" class COMMIT_ACCESS inherit DATABASE_ACCESS create make feature -- Status is_found: BOOLEAN -- Did the last retrieve query find a commit? feature -- Access last_commit_workitem: WORKITEM_COMMIT -- Last retrieved commit by a retrieve query. feature -- Select queries retrieve_commit_workitem_by_id (a_id: INTEGER) is -- Retrieve a commit by a_id. require a_id_ok: a_id > 0 local l_selection: DB_SELECTION l_list_filling: DB_ACTION [WORKITEM_COMMIT] l_commit: WORKITEM_COMMIT l_commits: LIST [WORKITEM_COMMIT] do create l_commit.make create l_selection.make l_selection.set_map_name (a_id, "workitem_id") l_selection.query ("SELECT * FROM workitem_commit WHERE workitem_id=:workitem_id") handle_errors_and_warnings l_selection.object_convert (l_commit) create l_list_filling.make (l_selection, l_commit) l_selection.set_action (l_list_filling) l_selection.load_result l_selection.terminate l_commits := l_list_filling.list if l_commits.count = 1 then is_found := True last_commit_workitem := l_commits.first else is_found := False end ensure is_found_implies_commit: is_found implies last_commit_workitem /= Void end feature -- Insert queries insert_commit_workitem (a_commit: WORKITEM_COMMIT) is -- Add a_commit as a new commit workitem. require a_commit_not_void: a_commit /= Void local l_store: DB_CHANGE do -- insertion into database is done with manual SQL query because EIFFEL_STORE maps 0 and "" to NULL which is incorrect create l_store.make l_store.set_map_name(a_commit.revision, "revision") l_store.set_map_name(a_commit.workitem_id, "workitem_id") l_store.modify("INSERT INTO `workitem_commit` (`workitem_id`, `revision`) VALUES (:workitem_id, :revision)") handle_errors_and_warnings -- now insertion of (possibly) empty text - has to be done with an UPDATE statement because an -- INSERT statement would also lead to DB failure and a mapping to NULL create l_store.make l_store.set_map_name(a_commit.diff, "diff") l_store.set_map_name(a_commit.log, "log") l_store.set_map_name(a_commit.workitem_id, "workitem_id") l_store.set_map_name(a_commit.revision, "revision") l_store.modify("UPDATE `workitem_commit` SET `log`=:log, `diff`=:diff WHERE `workitem_id`=:workitem_id AND `revision`=:revision") handle_errors_and_warnings end end