rem rem $Header: L:\\\\model\\repman40\\api\\RCS\\cimap.hpb 1.3 1998/11/11 11:38:53 cvanes Exp $ rem Rem Copyright (c) 1997 by Oracle Corporation Rem NAME Rem cimap.hpb - Rem DESCRIPTION Rem Rem RETURNS Rem Rem NOTES Rem Rem MODIFIED (MM/DD/YY) Rem cvanes 06/19/97 - Creation Rem wstallar 12/04/97 - Modified to get str_type_of for source and target elements Rem from sdd_strucutre_elements if element not found in sdd_elements Rem (For INS only) Rem wstallar 12/18/97 - Modified to cascade delete mapping elements associated with Rem COL/FCOs of tables and attribs (COLs) of OOTs when mapping Rem element between a table & OOT is deleted from a DBRELN->DBOBJ Rem transformation set. (Function Rel_to_obj_map & proc cascade_del_mapping) Rem BUG 571311 Rem REM *************************************************************************** REM Hand-carved package body for MAPPING ELEMENT created on 19-MAY-97 REM *************************************************************************** CREATE OR REPLACE PACKAGE BODY cihmap IS -- Pre-process routines FUNCTION rel_to_obj_map(id number) return boolean; PROCEDURE cascade_del_mapping(id number); -- Generic post-process routines PROCEDURE check_delete(id number); sac_type constant varchar2(6) := 'MAP'; pac_type constant varchar2(6) := 'TMS'; --======================== PRE-PROCESS (INS,UPD) ============================-- PROCEDURE pre_process(operation varchar2,id number, pl in out NOCOPY ciomapping_element.data) IS BEGIN -- Access rights for mapping element derive from the transformation mapping set -- Access rights checking performed by triggers in config 4.0.9 -- ciiacc.check_access_rights(pl.v.transformation_set_reference,pac_type, -- 'UPD','NSHR'); -- Initialize unassigned properties with default values on INSERT if operation = 'INS' then if pl.v.source_element_type is null then ciierr.fatal(1301,'SOURCE_ELEMENT_TYPE'); elsif pl.v.target_element_type is null then ciierr.fatal(1301,'TARGET_ELEMENT_TYPE'); end if; pl.v.element_type_name := sac_type; pl.i.element_type_name := true; end if; END; --======================== PRE-PROCESS (DEL,SEL) ============================-- PROCEDURE pre_process(operation varchar2,id number) IS BEGIN -- Access rights for mapping element derive from the transformation mapping set -- Access rights checking performed by triggers in config 4.0.9 -- ciiacc.check_access_rights(id,sac_type,operation,'SAC'); -- if operation is 'DELETE', make sure no non-cascading references exist if operation = 'DEL' then check_delete(id); -- BUG571311 -- If deleting mapping element from obj type to relational table, where MAP is in -- a mapping set for transforming Relational to Object Database, then want to -- cascade delete all the mapping elements that map the table columns/foreign keys -- to the object attributes. if (rel_to_obj_map(id)) then cascade_del_mapping(id); end if; end if; END; --===================== POST-PROCESS (INS,UPD,SEL) ==========================-- PROCEDURE post_process(operation varchar2,id number, pl ciomapping_element.data) IS BEGIN null; END; --========================= POST PROCESS (DEL) ==============================-- PROCEDURE post_process(operation varchar2,id number) IS BEGIN if operation = 'DEL' then -- Delete the mapping element and all it's related sub-bits ciiutl.delete_element(id,sac_type); end if; END; --============================= CHECK DELETE ================================-- PROCEDURE check_delete(id number) IS dummy number; error_count number := 0; BEGIN null; END; --======================== REL-TO-OBJ-MAP ============================-- FUNCTION rel_to_obj_map(id number) return boolean IS dummy number; source_type varchar2(17); target_type varchar2(17); target_subtype varchar2(17); BEGIN select max(tab.element_type_name) into source_type from ci_relation_definitions tab ,ci_mapping_elements map where map.id = rel_to_obj_map.id and tab.id = map.source_cielement_reference; select max(ort.element_type_name), max(ort.ort_type) into target_type, target_subtype from ci_oracle_types ort ,ci_mapping_elements map where map.id = rel_to_obj_map.id and ort.id = map.target_cielement_reference; -- Check if mapping element is from table or view to oracle object type. if ((target_type= 'ORT' and target_subtype = 'OOT') and source_type = 'TAB' ) then -- Check if mapping set is for DBRELN->DBOBJ BEGIN select count(*) into dummy from ci_mapping_elements map, ci_transformation_mapping_sets tms where tms.transformation_type = 'REL2OVW' and tms.id=map.transformation_set_reference and map.id=rel_to_obj_map.id; EXCEPTION WHEN no_data_found THEN NULL; END; if dummy > 0 then return true; end if; end if; return false; END; --======================== CASCADE-DEL-MAPPING ==============================-- PROCEDURE cascade_del_mapping(id number) IS -- Removed reference to sdd_sac_elements CvE 11-Nov-98 (has this ever worked?) CURSOR map1 (tms_id number, rel_table_id number, oot_id number) IS select map.id id from ci_mapping_elements map ,ci_columns target where target.relation_type = 'OOT' -- OOT attributes and target.table_reference = oot_id -- associated with the table/oot being mapped and target.id = map.target_cielement_reference and map.transformation_set_reference = tms_id -- only select MAPs from current TMS and (exists (select null from ci_columns source where source.relation_type = 'TABLE' and source.id = map.target_cielement_reference and source.table_reference = oot_id) or exists (select null from ci_foreign_key_constraints source where source.id = map.target_cielement_reference and source.table_reference = oot_id) ); tms_id_no number; table_id_no number; oot_id_no number; del_id number; BEGIN -- Get id numbers for transformation mapping set, reln table and oot for this mapping element select transformation_set_reference, source_cielement_reference, target_cielement_reference into tms_id_no, table_id_no, oot_id_no from ci_mapping_elements map where map.id = cascade_del_mapping.id; -- Cursor for loop to delete all the elements in the set that map table COLs or FCOs -- to OOT COLs. FOR map_el_id IN map1 (tms_id_no,table_id_no,oot_id_no) LOOP del_id:=map_el_id.id; ciiutl.delete_element(del_id,sac_type); -- Delete all sub-bits. /* replace code with delete from sdd_map but I suspect this code is obsolete as the actual delete will be performed by the triggers at 4.0.9 delete sdd_elements where el_id=del_id; */ -- Delete MAP itself. delete from sdd_map where irid = del_id; END LOOP; END; --================================== END ====================================-- -- -- Package instantiation block -- BEGIN is_installed := true; END; /