REM *************************************************************************** REM Hand-carved package body for ACTOR USAGE created on 20-OCT-98 REM *************************************************************************** CREATE OR REPLACE PACKAGE BODY cihacuacr IS -- Generic post-process routines PROCEDURE check_delete(id number); str_type constant varchar2(6) := 'ACUACR'; part_type constant varchar2(6) := 'ACTORG'; use_type constant varchar2(6) := 'ACR'; internal_update_mode boolean := false; -- Retrieve an acuacr in the specified Activity Usage, with a particular value -- of PRIMARY_FLAG -- Returns null if there are none -- Returns only one ID if there are more than one (when searching for a 'N') FUNCTION get_acuacr(activity_usage_reference in number, primary_flag in varchar2) return number IS primary_id number; BEGIN select max(irid) into primary_id from ci_actor_usages acuacr where acuacr.primary_flag = get_acuacr.primary_flag and acuacr.activity_usage_reference = get_acuacr.activity_usage_reference; return primary_id; END; procedure update_acuacr(acuacr_id in number, value in varchar2) IS other_acuacr cioactor_usage.data; begin other_acuacr.v.primary_flag := value; other_acuacr.i.primary_flag := true; internal_update_mode := true; cioactor_usage.upd(acuacr_id, other_acuacr); internal_update_mode := false; end; --======================== PRE-PROCESS (INS,UPD) ============================-- PROCEDURE pre_process(operation varchar2,id number, pl in out NOCOPY cioactor_usage.data) IS primary_acuacr_id number; other_acuacr cioactor_usage.data; BEGIN if operation = 'INS' then -- Initialize unassigned properties with default values on INSERT pl.v.element_type_name := str_type; pl.i.element_type_name := true; primary_acuacr_id := get_acuacr(pl.v.activity_usage_reference, 'Y'); if primary_acuacr_id is null then -- Can't find any others, so set this one to 'Y', whether user asked for it or not! pl.v.primary_flag := 'Y'; pl.i.primary_flag := true; else -- Can find an existing primary if pl.v.primary_flag is null then pl.v.primary_flag := 'N'; pl.i.primary_flag := true; elsif pl.v.primary_flag = 'Y' then -- User trying to set this one to 'Y', so set other one to 'N' update_acuacr(primary_acuacr_id, 'N'); end if; end if; else -- operation = 'UPD' if internal_update_mode = false then if pl.i.primary_flag = false then null; elsif pl.v.primary_flag = 'Y' then primary_acuacr_id := get_acuacr(pl.v.activity_usage_reference, 'Y'); -- User trying to set this one to 'Y', so set other one to 'N' update_acuacr(primary_acuacr_id, 'N'); else -- User trying to update the only row where primary_flag = Y, to N -- %0!s: May not set the primary Actor Usage to be non-primary ciierr.fatal(1100,ciiutl.identify(pl.v.id, str_type)); end if; end if; end if; END; --======================== PRE-PROCESS (DEL,SEL) ============================-- PROCEDURE pre_process(operation varchar2,id number) IS BEGIN -- Access rights checking performed by triggers in config 4.0.9 -- if operation = 'DEL' then -- ciiacc.check_access_rights(id,str_type,'UPD','MM'); -- else -- ciiacc.check_access_rights(id,str_type,operation,'MM'); -- end if; -- if operation is 'DELETE', make sure no non-cascading references exist if operation = 'DEL' then check_delete(id); end if; END; --===================== POST-PROCESS (INS,UPD,SEL) ==========================-- PROCEDURE post_process(operation varchar2,id number, pl cioactor_usage.data) IS BEGIN null; END; --========================= POST PROCESS (DEL) ==============================-- PROCEDURE post_process(operation varchar2,id number) IS BEGIN null; END; --============================= CHECK DELETE ================================-- PROCEDURE check_delete(id number) IS BEGIN -- Call public function (also called by actor - ciacr.hpb) on_delete(id); END; --============================= ON DELETE ================================-- -- PUBLIC -- Also called by delete on ACTOR PROCEDURE on_delete(id number) IS primary_flag varchar2(1); other_acuacr_id number; activity_usage_reference number; BEGIN select acuacr.primary_flag, acuacr.activity_usage_reference into primary_flag, activity_usage_reference from ci_actor_usages acuacr where acuacr.irid = on_delete.id; if primary_flag = 'Y' then -- Find one of the other ACUACRs which is not primary ... other_acuacr_id := get_acuacr(activity_usage_reference, 'N'); if other_acuacr_id is not null then -- ...and if there is one, make it the primary. update_acuacr(other_acuacr_id, 'Y'); end if; end if; END; --================================== END ====================================-- -- -- Package instantiation block -- BEGIN is_installed := true; END; /