      begin
        select pac_ref, parent_ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_MET owning_tab
        where  owning_tab.IRID=:new.METHOD_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_EVH_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_EVH');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_EVH_br;
/
create or replace trigger SDD_EVH_inv
after insert or update of
  EVENT_SUBSCRIPTION_REF
 ,SUBSCRIPTION_DETAIL_REF
on i$SDD_EVH
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276418848969169336034146142265;
  this_type_irid  := :new.TYPES;
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_EVH_inv;
/
create or replace trigger SDD_EVH_val
after insert or update of
  EVENT_SUBSCRIPTION_REF
 ,SUBSCRIPTION_DETAIL_REF
on i$SDD_EVH
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276418848969169336034146142265;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_EVH(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_EVH) violated');
    end if;
    if not FK_EVH_TO_EVS(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_EVH_TO_EVS) violated - parent key not found');
    end if;
    if not FK_EVH_TO_SUD(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_EVH_TO_SUD) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_EVH_val;
/
create or replace trigger SDD_EVH_d
  instead of delete on SDD_EVH for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_EVH el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
  delete SDD_CMA fktab
   where 
         fktab.EVENT_HANDLER_REF = :old.IRID
    ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_EVH
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_EVH_d;
/
create or replace trigger SDD_EVR_br
  before insert or update or delete on i$SDD_EVR
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.METHOD_REF is not null)
       )
    or (updating and (
        (:new.METHOD_REF != :old.METHOD_REF
        or (:new.METHOD_REF is not null and :old.METHOD_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select pac_ref, parent_ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_MET owning_tab
        where  owning_tab.IRID=:new.METHOD_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_EVR_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_EVR');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_EVR_br;
/
create or replace trigger SDD_EVR_inv
after insert or update of
  EVENT_PUBLICATION_REF
on i$SDD_EVR
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276419014251996236471728621625;
  this_type_irid  := :new.TYPES;
  if updating then
    action := 'UPD';
    -- Check child objects when primary or unique key is changed
    -- Note, the called functions consider whether constraints are immediate or deferred
  end if;   -- updating
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_EVR_inv;
/
create or replace trigger SDD_EVR_val
after insert or update of
  EVENT_PUBLICATION_REF
on i$SDD_EVR
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276419014251996236471728621625;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_EVR(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_EVR) violated');
    end if;
    if not FK_EVR_TO_CLAEVC(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_EVR_TO_CLAEVC) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_EVR_val;
/
create or replace trigger SDD_EVR_d
  instead of delete on SDD_EVR for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_EVR el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
  if not jr_wastebasket.force_flag 
   and jr_wastebasket.repos_constraints_enabled then
   if not FK_CMA_TO_EVR2_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
 elsif jr_wastebasket.force_flag then 
  jr_wastebasket.set_secondary_delete;
  update SDD_CMA fktab
     set 
         fktab.EVENT_RAISER_FROM_REF = NULL
   where 
         fktab.EVENT_RAISER_FROM_REF = :old.IRID
  ;
 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
  delete SDD_CMA fktab
   where 
         fktab.EVENT_RAISER_REF = :old.IRID
    ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_EVR
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_EVR_d;
/
create or replace trigger SDD_EVS_br
  before insert or update or delete on i$SDD_EVS
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.CLASSIFIER_REF is not null)
       )
    or (updating and (
        (:new.CLASSIFIER_REF != :old.CLASSIFIER_REF
        or (:new.CLASSIFIER_REF is not null and :old.CLASSIFIER_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_CLA owning_tab
        where  owning_tab.IRID=:new.CLASSIFIER_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_EVS_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_EVS');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_EVS_br;
/
create or replace trigger SDD_EVS_inv
after insert or update of
  EVENT_CLASSIFIER_REF
on i$SDD_EVS
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276419170090090171170020673593;
  this_type_irid  := :new.TYPES;
  if updating then
    action := 'UPD';
    -- Check child objects when primary or unique key is changed
    -- Note, the called functions consider whether constraints are immediate or deferred
  end if;   -- updating
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_EVS_inv;
/
create or replace trigger SDD_EVS_val
after insert or update of
  EVENT_CLASSIFIER_REF
on i$SDD_EVS
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276419170090090171170020673593;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_EVS(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_EVS) violated');
    end if;
    if not FK_EVS_TO_EVC(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_EVS_TO_EVC) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_EVS_val;
/
create or replace trigger SDD_EVS_d
  instead of delete on SDD_EVS for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_EVS el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
  if not jr_wastebasket.force_flag 
   and jr_wastebasket.repos_constraints_enabled then
   if not FK_EVH_TO_EVS_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
 elsif jr_wastebasket.force_flag then 
  jr_wastebasket.set_secondary_delete;
  delete SDD_EVH fktab
   where 
         fktab.EVENT_SUBSCRIPTION_REF = :old.IRID
    ;
 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 delete SDD_SBA fktab
  where 
        fktab.EVENT_SUBSCRIPTION_REF = :old.IRID
    ;
  delete SDD_SUD fktab
   where 
         fktab.EVENT_SUBSCRIPTION_REF = :old.IRID
    ;
 update SDD_TRA fktab
    set 
        fktab.EVENT_SUBSCRIPTION_REF = NULL
  where 
        fktab.EVENT_SUBSCRIPTION_REF = :old.IRID
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_EVS
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_EVS_d;
/
create or replace trigger SDD_EVT_br
  before insert or update or delete on i$SDD_EVT
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_EVT_br;
/
create or replace trigger SDD_EVT_ar
  after insert or update or delete on i$SDD_EVT
  for each row 
begin
  -- Inserting
  if inserting then
    jr_object_version.ins ( :new.irid, :new.ivid
    , name => :new.NAME
    , type_irid => :new.TYPES
    , table_irid => 384781276419335372917071607603152953
    );
  end if;  -- inserting
  -- Updating
  if updating then
    jr_object_version.upd ( :old.ivid
      , name => :new.NAME
    );
  end if;  -- updating
  -- Deleting
  if deleting then
    jr_object_version.del ( :old.irid, :old.ivid, 'SDD_EVT'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_EVT_ar;
/
create or replace trigger SDD_EVT_inv
after insert or update of
  ATTRIBUTE_REF
 ,ENTITY_REF
on i$SDD_EVT
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276419335372917071607603152953;
  this_type_irid  := :new.TYPES;
  if updating then
    action := 'UPD';
    -- Check child objects when primary or unique key is changed
    -- Note, the called functions consider whether constraints are immediate or deferred
  end if;   -- updating
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_EVT_inv;
/
create or replace trigger SDD_EVT_val
after insert or update of
  ATTRIBUTE_REF
 ,ENTITY_REF
on i$SDD_EVT
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276419335372917071607603152953;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_EVT(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_EVT) violated');
    end if;
    if not FK_EVT_TO_ATT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_EVT_TO_ATT) violated - parent key not found');
    end if;
    if not FK_EVT_TO_ENT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_EVT_TO_ENT) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_EVT_val;
/
create or replace trigger SDD_EVT_d
  instead of delete on SDD_EVT for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
  where ov.irid=:old.irid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  jr_wastebasket.remove(:old.ivid);
  if jr_context.workarea is NULL and not only_version then
   return;
  end if;
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 delete SDD_FUNEVT fktab
  where 
        fktab.TRIGGERING_EVENT_REF = :old.IRID
    ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_EVT_d;
/
create or replace trigger SDD_EXT_br
  before insert or update or delete on i$SDD_EXT
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_EXT_br;
/
create or replace trigger SDD_EXT_ar
  after insert or update or delete on i$SDD_EXT
  for each row 
begin
  -- Inserting
  if inserting then
    jr_object_version.ins ( :new.irid, :new.ivid
    , name => :new.NAME
    , type_irid => :new.TYPES
    , table_irid => 384781276419642326738458134542043193
    );
  end if;  -- inserting
  -- Updating
  if updating then
    jr_object_version.upd ( :old.ivid
      , name => :new.NAME
    );
  end if;  -- updating
  -- Deleting
  if deleting then
    jr_object_version.del ( :old.irid, :old.ivid, 'SDD_EXT'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_EXT_ar;
/
create or replace trigger SDD_EXT_inv
after insert or update of
  BUSINESS_UNIT_REF
 ,ENTITY_REF
on i$SDD_EXT
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276419642326738458134542043193;
  this_type_irid  := :new.TYPES;
  if updating then
    action := 'UPD';
    -- Check child objects when primary or unique key is changed
    -- Note, the called functions consider whether constraints are immediate or deferred
  end if;   -- updating
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_EXT_inv;
/
create or replace trigger SDD_EXT_val
after insert or update of
  BUSINESS_UNIT_REF
 ,ENTITY_REF
on i$SDD_EXT
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276419642326738458134542043193;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_EXT(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_EXT) violated');
    end if;
    if not FK_EXT_TO_BUN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_EXT_TO_BUN) violated - parent key not found');
    end if;
    if not FK_EXT_TO_ENT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_EXT_TO_ENT) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_EXT_val;
/
create or replace trigger SDD_EXT_d
  instead of delete on SDD_EXT for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
  where ov.irid=:old.irid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  jr_wastebasket.remove(:old.ivid);
  if jr_context.workarea is NULL and not only_version then
   return;
  end if;
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
  if not jr_wastebasket.force_flag 
   and jr_wastebasket.repos_constraints_enabled then
   -- bug fix 2078916 - BLOCK DELETE IF USER EXTENDED ASSOCIATION EXISTS
   if not jr_ues_chk.check_ues_blocks_delete (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_DFL_TO_EXT2_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
 elsif jr_wastebasket.force_flag then 
  jr_wastebasket.set_secondary_delete;
  delete SDD_DFL fktab
   where 
         fktab.EXTERNAL_DEST_REF = :old.IRID
    ;

  -- bug fix 2078916 - FORCE DELETE IF USER EXTENDED ASSOCIATION EXISTS
  delete SDD_UES fktab
  where fktab.USE_OF_REF = :old.IRID;

 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_EXT_d;
/
create or replace trigger SDD_FIL_br
  before insert or update or delete on i$SDD_FIL
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_FIL_br;
/
create or replace trigger SDD_FIL_ar
  after insert or update or delete on i$SDD_FIL
  for each row 
begin
  -- Inserting
  if inserting then
    jr_object_version.ins ( :new.irid, :new.ivid
    , name => :new.NAME
    , type_irid => :new.TYPES
    , table_irid => 384781276419883167429084486447941689
    );
  end if;  -- inserting
  -- Updating
  if updating then
    jr_object_version.upd ( :old.ivid
      , name => :new.NAME
    );
  end if;  -- updating
  -- Deleting
  if deleting then
    jr_object_version.del ( :old.irid, :old.ivid, 'SDD_FIL'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_FIL_ar;
/
create or replace trigger SDD_FIL_inv
after insert or update of
  LANGUAGE_REF
on i$SDD_FIL
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276419883167429084486447941689;
  this_type_irid  := :new.TYPES;
  if updating then
    action := 'UPD';
    -- Check child objects when primary or unique key is changed
    -- Note, the called functions consider whether constraints are immediate or deferred
  end if;   -- updating
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_FIL_inv;
/
create or replace trigger SDD_FIL_val
after insert or update of
  LANGUAGE_REF
on i$SDD_FIL
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276419883167429084486447941689;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_FIL(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_FIL) violated');
    end if;
    if not FK_FIL_TO_LAN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_FIL_TO_LAN) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_FIL_val;
/
create or replace trigger SDD_FIL_d
  instead of delete on SDD_FIL for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
  where ov.irid=:old.irid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  jr_wastebasket.remove(:old.ivid);
  if jr_context.workarea is NULL and not only_version then
   return;
  end if;
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
  if not jr_wastebasket.force_flag 
   and jr_wastebasket.repos_constraints_enabled then
   -- bug fix 2078916 - BLOCK DELETE IF USER EXTENDED ASSOCIATION EXISTS
   if not jr_ues_chk.check_ues_blocks_delete (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_TAB_RFI_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
 elsif jr_wastebasket.force_flag then 
  jr_wastebasket.set_secondary_delete;
  delete SDD_TAB fktab
   where 
         fktab.RECORD_FILE_REF = :old.IRID
    ;

  -- bug fix 2078916 - FORCE DELETE IF USER EXTENDED ASSOCIATION EXISTS
  delete SDD_UES fktab
  where fktab.USE_OF_REF = :old.IRID;

 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_FIL_d;
/
create or replace trigger SDD_FILES_br
  before insert or update or delete on i$SDD_FILES
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_FILES_br;
/
create or replace trigger SDD_FILES_ar
  after insert or update or delete on i$SDD_FILES
  for each row 
begin
  -- Inserting
  if inserting then
    jr_object_version.ins ( :new.irid, :new.ivid
    , name => :new.NAME
    , type_irid => :new.TYPES
    , table_irid => 384781276420152342318608056225122361
    );
  end if;  -- inserting
  -- Updating
  if updating then
    jr_object_version.upd ( :old.ivid
      , name => :new.NAME
    );
  end if;  -- updating
  -- Deleting
  if deleting then
    jr_object_version.del ( :old.irid, :old.ivid, 'SDD_FILES'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_FILES_ar;
/
create or replace trigger SDD_FILES_inv
after insert
on i$SDD_FILES
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276420152342318608056225122361;
  this_type_irid  := :new.TYPES;
  if updating then
    action := 'UPD';
    -- Check child objects when primary or unique key is changed
    -- Note, the called functions consider whether constraints are immediate or deferred
  end if;   -- updating
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_FILES_inv;
/
create or replace trigger SDD_FILES_val
after insert
on i$SDD_FILES
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276420152342318608056225122361;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_FILES(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_FILES) violated');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_FILES_val;
/
create or replace trigger SDD_FILES_d
  instead of delete on SDD_FILES for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
  where ov.irid=:old.irid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  jr_wastebasket.remove(:old.ivid);
  if jr_context.workarea is NULL and not only_version then
   return;
  end if;
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 if not jr_wastebasket.force_flag 
   and jr_wastebasket.repos_constraints_enabled then
   -- bug fix 2078916 - BLOCK DELETE IF USER EXTENDED ASSOCIATION EXISTS
   if not jr_ues_chk.check_ues_blocks_delete (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
 elsif jr_wastebasket.force_flag then 
  jr_wastebasket.set_secondary_delete;

  -- bug fix 2078916 - FORCE DELETE IF USER EXTENDED ASSOCIATION EXISTS
  delete SDD_UES fktab
  where fktab.USE_OF_REF = :old.IRID;

 end if;--Constraints enabled/force

 jr_wastebasket.set_secondary_delete;
 update SDD_FOLDERS fktab
    set 
        fktab.ICON_FILE_REF = NULL
  where 
        fktab.ICON_FILE_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
 ;
 delete SDD_FOLDERS fktab
  where 
        fktab.ICON_FILE_REF = :old.IRID
    and fktab.ivid in (select o.ivid
                        from I$SDD_OBJECT_VERSIONS o
                       where o.state='I')
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_FILES_d;
/
create or replace trigger SDD_FILPAC_br
  before insert or update or delete on i$SDD_FILPAC
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.ASSOCIATION_REF is not null)
       )
    or (updating and (
        (:new.ASSOCIATION_REF != :old.ASSOCIATION_REF
        or (:new.ASSOCIATION_REF is not null and :old.ASSOCIATION_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_ASS owning_tab
        where  owning_tab.IRID=:new.ASSOCIATION_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_FILPAC_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.CLASSIFIER_REF is not null)
       )
    or (updating and (
        (:new.CLASSIFIER_REF != :old.CLASSIFIER_REF
        or (:new.CLASSIFIER_REF is not null and :old.CLASSIFIER_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_CLA owning_tab
        where  owning_tab.IRID=:new.CLASSIFIER_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_FILPAC_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.DIAGRAM_REF is not null)
       )
    or (updating and (
        (:new.DIAGRAM_REF != :old.DIAGRAM_REF
        or (:new.DIAGRAM_REF is not null and :old.DIAGRAM_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_DIA owning_tab
        where  owning_tab.IRID=:new.DIAGRAM_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_FILPAC_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.VIEW_LINK_REF is not null)
       )
    or (updating and (
        (:new.VIEW_LINK_REF != :old.VIEW_LINK_REF
        or (:new.VIEW_LINK_REF is not null and :old.VIEW_LINK_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_VLI owning_tab
        where  owning_tab.IRID=:new.VIEW_LINK_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_FILPAC_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_FILPAC');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_FILPAC_br;
/
create or replace trigger SDD_FILPAC_inv
after insert or update of
  PRIMARY_ACCESS_FILE_REF
on i$SDD_FILPAC
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 397116117446343399240330587712014393;
  this_type_irid  := :new.TYPES;
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_FILPAC_inv;
/
create or replace trigger SDD_FILPAC_val
after insert or update of
  PRIMARY_ACCESS_FILE_REF
on i$SDD_FILPAC
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 397116117446343399240330587712014393;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_FILPAC(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_FILPAC) violated');
    end if;
    if not FK_FILPAC_TO_FILES(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_FILPAC_TO_FILES) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_FILPAC_val;
/
create or replace trigger SDD_FILPAC_d
  instead of delete on SDD_FILPAC for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_FILPAC el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_FILPAC
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_FILPAC_d;
/
create or replace trigger SDD_FOLDERS_br
  before insert or update or delete on i$SDD_FOLDERS
  for each row 
begin
  null; -- processing done in sdd_folders_i trigger
end SDD_FOLDERS_br;
/
create or replace trigger SDD_FOLDERS_ar
  after insert or update or delete on i$SDD_FOLDERS
  for each row 
begin
  -- Inserting
  if inserting then
    -- Create the row in object versions
    if jr_context.is_enabled(jr_context.OBJECT_VERSIONS) then

      insert into i$sdd_object_versions
      ( irid
      , ivid
      , name
      , logical_type_id
      , table_irid
      )
      values
      ( :new.irid
      , :new.ivid
      , :new.name
      , :new.types
      , 384781276420308180412542754517174329 -- table irid
      ); 

    end if;
  end if;  -- inserting
  -- Updating
  if updating then
    jr_object_version.upd ( :old.ivid
      , null -- no parent ivid column
      , :new.NAME -- name column
      , null -- no date_changed column
      , null -- no changed_by column
      , null -- no notm column
    );
  end if;  -- updating
  -- Deleting
  if deleting then
    jr_object_version.del ( :old.irid, :old.ivid, 'SDD_FOLDERS'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_FOLDERS_ar;
/
create or replace trigger SDD_FOLDERS_i
  instead of insert on SDD_FOLDERS for each row
declare
  new_irid number;
  new_ivid number;
  no_workarea_context exception;
begin
  if jr_context.is_enabled(jr_context.CHECK_WORKAREA_CONTEXT) and jr_context.workarea is null then
    -- No workarea context set
    rmmes.post('CDR',100); raise jr_wastebasket.delete_error;
    raise no_workarea_context;
  end if;

  new_irid := :new.irid;
  new_ivid := :new.ivid;
  -- Assign new ids if NOT supplied
  jr_audit.pre_insert(new_irid, new_ivid);

  insert into i$SDD_FOLDERS (irid, ivid
,TYPES
,ELEMENT_TYPE_NAME
,DATE_CREATED
,CREATED_BY
,DATE_CHANGED
,CHANGED_BY
,NOTM
,OWNING_USER
,CONTAINER_SUBTYPE
,AUTHORITY
,CONSTRAINTS
,DATAWAREHOUSE_FLAG
,PRIORITIES
,REMARK
,generate_classes_flag
,USRX0
,USRX1
,USRX10
,USRX11
,USRX12
,USRX13
,USRX14
,USRX15
,USRX16
,USRX17
,USRX18
,USRX19
,USRX2
,USRX3
,USRX4
,USRX5
,USRX6
,USRX7
,USRX8
,USRX9
,NAME
,APPLICATION_TYPE
,TYPE
,CLASSIFIER_REF
,EXTERNAL_FLAG
,INSTANTIABLE_FLAG
,LANGUAGE_REF
,AUTHOR
,CODING_STANDARD_REF
,IMPLEMENTATION_TARGET
,DISPLAY_TITLE
,TRANSFORMER_STANDARD_REF
,ICON_FILE_REF
,DEVELOPMENT_LEVEL
,OS_TIMESTAMP
,ROOT_FLAG
,O8I_TARGET_FLAG
,VISIBROKER_TARGET_FLAG
,ejb_TARGET_FLAG
,GENERATE_IDL_FLAG
,GENERATE_METADATA_FLAG
,METADATA_CLASS_NAME
,SYSTEM_ELEMENT_FLAG
) values (new_irid, new_ivid
,:new.TYPES
,:new.ELEMENT_TYPE_NAME
,nvl(:new.DATE_CREATED, SYSDATE)
,nvl(:new.CREATED_BY, USER)
,:new.DATE_CHANGED
,:new.CHANGED_BY
,nvl(:new.NOTM, 0)
,:new.OWNING_USER
,:new.CONTAINER_SUBTYPE
,:new.AUTHORITY
,:new.CONSTRAINTS
,:new.DATAWAREHOUSE_FLAG
,:new.PRIORITIES
,:new.REMARK
,:new.generate_classes_flag
,:new.USRX0
,:new.USRX1
,:new.USRX10
,:new.USRX11
,:new.USRX12
,:new.USRX13
,:new.USRX14
,:new.USRX15
,:new.USRX16
,:new.USRX17
,:new.USRX18
,:new.USRX19
,:new.USRX2
,:new.USRX3
,:new.USRX4
,:new.USRX5
,:new.USRX6
,:new.USRX7
,:new.USRX8
,:new.USRX9
,:new.NAME
,:new.APPLICATION_TYPE
,:new.TYPE
,:new.CLASSIFIER_REF
,:new.EXTERNAL_FLAG
,:new.INSTANTIABLE_FLAG
,:new.LANGUAGE_REF
,:new.AUTHOR
,:new.CODING_STANDARD_REF
,:new.IMPLEMENTATION_TARGET
,:new.DISPLAY_TITLE
,:new.TRANSFORMER_STANDARD_REF
,:new.ICON_FILE_REF
,:new.DEVELOPMENT_LEVEL
,:new.OS_TIMESTAMP
,:new.ROOT_FLAG
,:new.O8I_TARGET_FLAG
,:new.VISIBROKER_TARGET_FLAG
,:new.ejb_TARGET_FLAG
,:new.GENERATE_IDL_FLAG
,:new.GENERATE_METADATA_FLAG
,:new.METADATA_CLASS_NAME
,:new.SYSTEM_ELEMENT_FLAG
); 
jr_folder.bind(new_irid);
end SDD_FOLDERS_i;
/
create or replace trigger SDD_FOLDERS_inv
after insert or update of
  CLASSIFIER_REF
 ,CODING_STANDARD_REF
 ,ICON_FILE_REF
 ,LANGUAGE_REF
 ,TRANSFORMER_STANDARD_REF
on i$SDD_FOLDERS
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276420308180412542754517174329;
  this_type_irid  := :new.TYPES;
  if updating then
    action := 'UPD';
    -- Check child objects when primary or unique key is changed
    -- Note, the called functions consider whether constraints are immediate or deferred
  end if;   -- updating
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_FOLDERS_inv;
/
create or replace trigger SDD_FOLDERS_val
after insert or update of
  CLASSIFIER_REF
 ,CODING_STANDARD_REF
 ,ICON_FILE_REF
 ,LANGUAGE_REF
 ,TRANSFORMER_STANDARD_REF
on i$SDD_FOLDERS
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276420308180412542754517174329;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_FOLDERS(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_FOLDERS) violated');
    end if;
    if not FK_CEL_TO_CLA(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CEL_TO_CLA) violated - parent key not found');
    end if;
    if not FK_CEL_TO_COS(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CEL_TO_COS) violated - parent key not found');
    end if;
    if not FK_CEL_TO_FILES(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CEL_TO_FILES) violated - parent key not found');
    end if;
    if not FK_CEL_TO_LAN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CEL_TO_LAN) violated - parent key not found');
    end if;
    if not FK_CEL_TO_TRS(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CEL_TO_TRS) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_FOLDERS_val;
/
create or replace trigger SDD_FOLDERS_d
  instead of delete on SDD_FOLDERS for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
  where ov.irid=:old.irid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  jr_wastebasket.remove(:old.ivid);
  if jr_context.workarea is NULL and not only_version then
   return;
  end if;
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_FOLDERS_d;
/
create or replace trigger SDD_FOLDER_MEMBERS_br
  before insert or update or delete on i$SDD_FOLDER_MEMBERS
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.FOLDER_REFERENCE is not null)
       )
    or (updating and (
        (:new.FOLDER_REFERENCE != :old.FOLDER_REFERENCE
        or (:new.FOLDER_REFERENCE is not null and :old.FOLDER_REFERENCE is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_FOLDERS owning_tab
        where  owning_tab.IRID=:new.FOLDER_REFERENCE
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_FOLDER_MEMBERS_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_FOLDER_MEMBERS');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_FOLDER_MEMBERS_br;
/
create or replace trigger SDD_FOLDER_MEMBERS_inv
after insert or update of
  MEMBER_OBJECT
on i$SDD_FOLDER_MEMBERS
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276420624578966895020746491961;
  this_type_irid  := :new.TYPES;
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_FOLDER_MEMBERS_inv;
/
create or replace trigger SDD_FOLDER_MEMBERS_val
after insert or update of
  MEMBER_OBJECT
on i$SDD_FOLDER_MEMBERS
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276420624578966895020746491961;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_FOLDER_MEMBERS(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_FOLDER_MEMBERS) violated');
    end if;
    if not SDD_FOLDER_MEMBER_OBJ_FK(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (SDD_FOLDER_MEMBER_OBJ_FK) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_FOLDER_MEMBERS_val;
/
create or replace trigger SDD_FOLDER_MEMBERS_d
  instead of delete on SDD_FOLDER_MEMBERS for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_FOLDER_MEMBERS el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_FOLDER_MEMBERS
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_FOLDER_MEMBERS_d;
/
create or replace trigger SDD_FSE_br
  before insert or update or delete on i$SDD_FSE
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.CLASSIFIER_REF is not null)
       )
    or (updating and (
        (:new.CLASSIFIER_REF != :old.CLASSIFIER_REF
        or (:new.CLASSIFIER_REF is not null and :old.CLASSIFIER_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_CLA owning_tab
        where  owning_tab.IRID=:new.CLASSIFIER_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_FSE_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_FSE');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_FSE_br;
/
create or replace trigger SDD_FSE_inv
after insert or update of
  PRIMARY_ACCESS_FILE_REF
on i$SDD_FSE
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 397116117447037587113312425558427705;
  this_type_irid  := :new.TYPES;
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_FSE_inv;
/
create or replace trigger SDD_FSE_val
after insert or update of
  PRIMARY_ACCESS_FILE_REF
on i$SDD_FSE
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 397116117447037587113312425558427705;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_FSE(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_FSE) violated');
    end if;
    if not FK_FSE_TO_FILES(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_FSE_TO_FILES) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_FSE_val;
/
create or replace trigger SDD_FSE_d
  instead of delete on SDD_FSE for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_FSE el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_FSE
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_FSE_d;
/
create or replace trigger SDD_FUN_br
  before insert or update or delete on i$SDD_FUN
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_FUN_br;
/
create or replace trigger SDD_FUN_ar
  after insert or update or delete on i$SDD_FUN
  for each row 
begin
  -- Inserting
  if inserting then
    jr_object_version.ins ( :new.irid, :new.ivid
    , name => :new.FUNCTION_LABEL
    , type_irid => :new.TYPES
    , table_irid => 384781276420775694694346849393330233
    );
  end if;  -- inserting
  -- Updating
  if updating then
    jr_object_version.upd ( :old.ivid
      , name => :new.FUNCTION_LABEL
    );
  end if;  -- updating
  -- Deleting
  if deleting then
    jr_object_version.del ( :old.irid, :old.ivid, 'SDD_FUN'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_FUN_ar;
/
create or replace trigger SDD_FUN_inv
after insert or update of
  PARENT_REF
 ,COMMON_FUNCTION_REF
on i$SDD_FUN
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276420775694694346849393330233;
  this_type_irid  := :new.TYPES;
  if updating then
    action := 'UPD';
    -- Check child objects when primary or unique key is changed
    -- Note, the called functions consider whether constraints are immediate or deferred
  end if;   -- updating
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_FUN_inv;
/
create or replace trigger SDD_FUN_val
after insert or update of
  PARENT_REF
 ,COMMON_FUNCTION_REF
on i$SDD_FUN
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276420775694694346849393330233;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_FUN(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_FUN) violated');
    end if;
    if not FK_FUN_TO_FUN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_FUN_TO_FUN) violated - parent key not found');
    end if;
    if not FK_FUN_TO_FUN2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_FUN_TO_FUN2) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_FUN_val;
/
create or replace trigger SDD_FUN_d
  instead of delete on SDD_FUN for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
  where ov.irid=:old.irid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  jr_wastebasket.remove(:old.ivid);
  if jr_context.workarea is NULL and not only_version then
   return;
  end if;
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
  if not jr_wastebasket.force_flag 
   and jr_wastebasket.repos_constraints_enabled then
   -- bug fix 2078916 - BLOCK DELETE IF USER EXTENDED ASSOCIATION EXISTS
   if not jr_ues_chk.check_ues_blocks_delete (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_DFL_TO_FUN2_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_FUN_TO_FUN_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_FUN_TO_FUN2_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_FUNEVT_TO_FUN_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_MODFUN_TO_FUN_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
 elsif jr_wastebasket.force_flag then 
  jr_wastebasket.set_secondary_delete;
  delete SDD_DFL fktab
   where 
         fktab.FUNCTION_DEST_REF = :old.IRID
    ;
  delete SDD_FUNEVT fktab
   where 
         fktab.TRIGGERING_FUNCTION_REF = :old.IRID
    ;
  delete SDD_MODFUN fktab
   where 
         fktab.FUNCTION_REF = :old.IRID
    ;
  update SDD_FUN fktab
     set 
         fktab.PARENT_REF = NULL
   where 
         fktab.PARENT_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
  ;
  delete SDD_FUN fktab
   where 
         fktab.PARENT_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state='I')
  ;
  update SDD_FUN fktab
     set 
         fktab.COMMON_FUNCTION_REF = NULL
   where 
         fktab.COMMON_FUNCTION_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
  ;
  delete SDD_FUN fktab
   where 
         fktab.COMMON_FUNCTION_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state='I')
  ;

  -- bug fix 2078916 - FORCE DELETE IF USER EXTENDED ASSOCIATION EXISTS
  delete SDD_UES fktab
  where fktab.USE_OF_REF = :old.IRID;

 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 delete SDD_A11 fktab
  where 
        fktab.FUNCTION_REF = :old.IRID
    ;
 delete SDD_A4 fktab
  where 
        fktab.FUNCTION_REF = :old.IRID
    ;
 update SDD_DST fktab
    set 
        fktab.FUNCTION_REF = NULL
  where 
        fktab.FUNCTION_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
 ;
 delete SDD_DST fktab
  where 
        fktab.FUNCTION_REF = :old.IRID
    and fktab.ivid in (select o.ivid
                        from I$SDD_OBJECT_VERSIONS o
                       where o.state='I')
 ;
 if jr_context.workarea is not null then
  delete SDD_FUNATT
   where ivid in
   (select fktab.ivid
      from i$SDD_FUNATT fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.FUNENT_REF in (select parent_tab.IRID
                                                    from i$SDD_FUNENT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_FUNATT
   where ivid in
   (select fktab.ivid
      from i$SDD_FUNATT fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.FUNENT_REF in (select parent_tab.IRID
                                                    from i$SDD_FUNENT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_FUN_d;
/
create or replace trigger SDD_FUNATT_br
  before insert or update or delete on i$SDD_FUNATT
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.FUNCTION_REF is not null)
       )
    or (updating and (
        (:new.FUNCTION_REF != :old.FUNCTION_REF
        or (:new.FUNCTION_REF is not null and :old.FUNCTION_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_FUN owning_tab
        where  owning_tab.IRID=:new.FUNCTION_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_FUNATT_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_FUNATT');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_FUNATT_br;
/
create or replace trigger SDD_FUNATT_inv
after insert or update of
  ATTRIBUTE_REF
 ,FUNENT_REF
on i$SDD_FUNATT
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276421299877373945380012050489;
  this_type_irid  := :new.TYPES;
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_FUNATT_inv;
/
create or replace trigger SDD_FUNATT_val
after insert or update of
  ATTRIBUTE_REF
 ,FUNENT_REF
on i$SDD_FUNATT
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276421299877373945380012050489;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_FUNATT(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_FUNATT) violated');
    end if;
    if not FK_FUNATT_TO_ATT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_FUNATT_TO_ATT) violated - parent key not found');
    end if;
    if not FK_FUNATT_TO_FUNENT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_FUNATT_TO_FUNENT) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_FUNATT_val;
/
create or replace trigger SDD_FUNATT_d
  instead of delete on SDD_FUNATT for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_FUNATT el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_FUNATT
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_FUNATT_d;
/
create or replace trigger SDD_FUNBUN_br
  before insert or update or delete on i$SDD_FUNBUN
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.FUNCTION_REF is not null)
       )
    or (updating and (
        (:new.FUNCTION_REF != :old.FUNCTION_REF
        or (:new.FUNCTION_REF is not null and :old.FUNCTION_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_FUN owning_tab
        where  owning_tab.IRID=:new.FUNCTION_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_FUNBUN_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_FUNBUN');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_FUNBUN_br;
/
create or replace trigger SDD_FUNBUN_inv
after insert or update of
  BUSINESS_UNIT_REF
on i$SDD_FUNBUN
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276421630443027746255177009209;
  this_type_irid  := :new.TYPES;
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_FUNBUN_inv;
/
create or replace trigger SDD_FUNBUN_val
after insert or update of
  BUSINESS_UNIT_REF
on i$SDD_FUNBUN
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276421630443027746255177009209;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_FUNBUN(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_FUNBUN) violated');
    end if;
    if not FK_FUNBUN_TO_BUN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_FUNBUN_TO_BUN) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_FUNBUN_val;
/
create or replace trigger SDD_FUNBUN_d
  instead of delete on SDD_FUNBUN for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_FUNBUN el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_FUNBUN
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_FUNBUN_d;
/
create or replace trigger SDD_FUNENT_br
  before insert or update or delete on i$SDD_FUNENT
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.FUNCTION_REF is not null)
       )
    or (updating and (
        (:new.FUNCTION_REF != :old.FUNCTION_REF
        or (:new.FUNCTION_REF is not null and :old.FUNCTION_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_FUN owning_tab
        where  owning_tab.IRID=:new.FUNCTION_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_FUNENT_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_FUNENT');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_FUNENT_br;
/
create or replace trigger SDD_FUNENT_inv
after insert or update of
  ENTITY_REF
on i$SDD_FUNENT
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276421904340283752694599403577;
  this_type_irid  := :new.TYPES;
  if updating then
    action := 'UPD';
    -- Check child objects when primary or unique key is changed
    -- Note, the called functions consider whether constraints are immediate or deferred
  end if;   -- updating
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_FUNENT_inv;
/
create or replace trigger SDD_FUNENT_val
after insert or update of
  ENTITY_REF
on i$SDD_FUNENT
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276421904340283752694599403577;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_FUNENT(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_FUNENT) violated');
    end if;
    if not FK_FUNENT_TO_ENT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_FUNENT_TO_ENT) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_FUNENT_val;
/
create or replace trigger SDD_FUNENT_d
  instead of delete on SDD_FUNENT for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_FUNENT el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 delete SDD_FUNATT fktab
  where 
        fktab.FUNENT_REF = :old.IRID
    ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_FUNENT
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_FUNENT_d;
/
create or replace trigger SDD_FUNEVT_br
  before insert or update or delete on i$SDD_FUNEVT
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.TRIGGERED_EVENT_REF is not null)
       )
    or (updating and (
        (:new.TRIGGERED_EVENT_REF != :old.TRIGGERED_EVENT_REF
        or (:new.TRIGGERED_EVENT_REF is not null and :old.TRIGGERED_EVENT_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_EVT owning_tab
        where  owning_tab.IRID=:new.TRIGGERED_EVENT_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_FUNEVT_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.TRIGGERED_FUNCTION_REF is not null)
       )
    or (updating and (
        (:new.TRIGGERED_FUNCTION_REF != :old.TRIGGERED_FUNCTION_REF
        or (:new.TRIGGERED_FUNCTION_REF is not null and :old.TRIGGERED_FUNCTION_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_FUN owning_tab
        where  owning_tab.IRID=:new.TRIGGERED_FUNCTION_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_FUNEVT_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_FUNEVT');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_FUNEVT_br;
/
create or replace trigger SDD_FUNEVT_inv
after insert or update of
  TRIGGERING_EVENT_REF
 ,TRIGGERING_FUNCTION_REF
on i$SDD_FUNEVT
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276422206571738656351893080121;
  this_type_irid  := :new.TYPES;
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_FUNEVT_inv;
/
create or replace trigger SDD_FUNEVT_val
after insert or update of
  TRIGGERING_EVENT_REF
 ,TRIGGERING_FUNCTION_REF
on i$SDD_FUNEVT
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276422206571738656351893080121;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_FUNEVT(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_FUNEVT) violated');
    end if;
    if not FK_FUNEVT_TO_EVT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_FUNEVT_TO_EVT) violated - parent key not found');
    end if;
    if not FK_FUNEVT_TO_FUN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_FUNEVT_TO_FUN) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_FUNEVT_val;
/
create or replace trigger SDD_FUNEVT_d
  instead of delete on SDD_FUNEVT for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_FUNEVT el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_FUNEVT
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_FUNEVT_d;
/
create or replace trigger SDD_GRP_br
  before insert or update or delete on i$SDD_GRP
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.ORACLE_DATABASE_REF is not null)
       )
    or (updating and (
        (:new.ORACLE_DATABASE_REF != :old.ORACLE_DATABASE_REF
        or (:new.ORACLE_DATABASE_REF is not null and :old.ORACLE_DATABASE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_ODB owning_tab
        where  owning_tab.IRID=:new.ORACLE_DATABASE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_GRP_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_GRP');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_GRP_br;
/
create or replace trigger SDD_GRP_inv
after insert
on i$SDD_GRP
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276422494636094111400251115577;
  this_type_irid  := :new.TYPES;
  if updating then
    action := 'UPD';
    -- Check child objects when primary or unique key is changed
    -- Note, the called functions consider whether constraints are immediate or deferred
  end if;   -- updating
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_GRP_inv;
/
create or replace trigger SDD_GRP_val
after insert
on i$SDD_GRP
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276422494636094111400251115577;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_GRP(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_GRP) violated');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_GRP_val;
/
create or replace trigger SDD_GRP_d
  instead of delete on SDD_GRP for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_GRP el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 if not jr_wastebasket.force_flag 
   and jr_wastebasket.repos_constraints_enabled then
   -- bug fix 2078916 - BLOCK DELETE IF USER EXTENDED ASSOCIATION EXISTS
   if not jr_ues_chk.check_ues_blocks_delete (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
 elsif jr_wastebasket.force_flag then 
  jr_wastebasket.set_secondary_delete;

  -- bug fix 2078916 - FORCE DELETE IF USER EXTENDED ASSOCIATION EXISTS
  delete SDD_UES fktab
  where fktab.USE_OF_REF = :old.IRID;

 end if;--Constraints enabled/force

 jr_wastebasket.set_secondary_delete;
 delete SDD_DBUGRP fktab
  where 
        fktab.ROLE_REF = :old.IRID
    ;
 delete SDD_GRPGRP fktab
  where 
        fktab.GRANTOR_ROLE_REF = :old.IRID
    ;
  delete SDD_DOG fktab
   where 
         fktab.ROLE_REF = :old.IRID
    ;
  delete SDD_GRPGRP fktab
   where 
         fktab.GRANTEE_ROLE_REF = :old.IRID
    ;
  delete SDD_GRPMOD fktab
   where 
         fktab.ROLE_REF = :old.IRID
    ;
  delete SDD_SPV fktab
   where 
         fktab.ROLE_REF = :old.IRID
    ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_GRP
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_GRP_d;
/
create or replace trigger SDD_GRPGRP_br
  before insert or update or delete on i$SDD_GRPGRP
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.GRANTEE_ROLE_REF is not null)
       )
    or (updating and (
        (:new.GRANTEE_ROLE_REF != :old.GRANTEE_ROLE_REF
        or (:new.GRANTEE_ROLE_REF is not null and :old.GRANTEE_ROLE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select pac_ref, parent_ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_GRP owning_tab
        where  owning_tab.IRID=:new.GRANTEE_ROLE_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_GRPGRP_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_GRPGRP');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_GRPGRP_br;
/
create or replace trigger SDD_GRPGRP_inv
after insert or update of
  GRANTOR_ROLE_REF
on i$SDD_GRPGRP
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276422749643884186361092655161;
  this_type_irid  := :new.TYPES;
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_GRPGRP_inv;
/
create or replace trigger SDD_GRPGRP_val
after insert or update of
  GRANTOR_ROLE_REF
on i$SDD_GRPGRP
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276422749643884186361092655161;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_GRPGRP(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_GRPGRP) violated');
    end if;
    if not FK_GRPGRP_TO_GRP(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_GRPGRP_TO_GRP) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_GRPGRP_val;
/
create or replace trigger SDD_GRPGRP_d
  instead of delete on SDD_GRPGRP for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_GRPGRP el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_GRPGRP
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_GRPGRP_d;
/
create or replace trigger SDD_GRPMOD_br
  before insert or update or delete on i$SDD_GRPMOD
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.ROLE_REF is not null)
       )
    or (updating and (
        (:new.ROLE_REF != :old.ROLE_REF
        or (:new.ROLE_REF is not null and :old.ROLE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select pac_ref, parent_ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_GRP owning_tab
        where  owning_tab.IRID=:new.ROLE_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_GRPMOD_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_GRPMOD');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_GRPMOD_br;
/
create or replace trigger SDD_GRPMOD_inv
after insert or update of
  GENERAL_MODULE_REF
on i$SDD_GRPMOD
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276422999929307778452288981049;
  this_type_irid  := :new.TYPES;
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_GRPMOD_inv;
/
create or replace trigger SDD_GRPMOD_val
after insert or update of
  GENERAL_MODULE_REF
on i$SDD_GRPMOD
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276422999929307778452288981049;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_GRPMOD(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_GRPMOD) violated');
    end if;
    if not FK_GRPMOD_TO_GEM(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_GRPMOD_TO_GEM) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_GRPMOD_val;
/
create or replace trigger SDD_GRPMOD_d
  instead of delete on SDD_GRPMOD for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_GRPMOD el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_GRPMOD
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_GRPMOD_d;
/
create or replace trigger SDD_IGR_br
  before insert or update or delete on i$SDD_IGR
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.MODULE_COMPONENT_REF is not null)
       )
    or (updating and (
        (:new.MODULE_COMPONENT_REF != :old.MODULE_COMPONENT_REF
        or (:new.MODULE_COMPONENT_REF is not null and :old.MODULE_COMPONENT_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select nvl(pac_ref, irid), nvl(parent_ivid, ivid)
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_MUN owning_tab
        where  owning_tab.IRID=:new.MODULE_COMPONENT_REF
        and    jr_vn.context(nvl(owning_tab.parent_ivid, owning_tab.ivid)) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_IGR_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.SUBCOMPONENT_REF is not null)
       )
    or (updating and (
        (:new.SUBCOMPONENT_REF != :old.SUBCOMPONENT_REF
        or (:new.SUBCOMPONENT_REF is not null and :old.SUBCOMPONENT_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select nvl(pac_ref, irid), nvl(parent_ivid, ivid)
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_MUN owning_tab
        where  owning_tab.IRID=:new.SUBCOMPONENT_REF
        and    jr_vn.context(nvl(owning_tab.parent_ivid, owning_tab.ivid)) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_IGR_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_IGR');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_IGR_br;
/
create or replace trigger SDD_IGR_inv
after insert or update of
  ITEM_GROUP_REF
 ,MODULE_COMPONENT_REF
 ,SUBCOMPONENT_REF
on i$SDD_IGR
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276423250214731370543485306937;
  this_type_irid  := :new.TYPES;
  if updating then
    action := 'UPD';
    -- Check child objects when primary or unique key is changed
    -- Note, the called functions consider whether constraints are immediate or deferred
  end if;   -- updating
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_IGR_inv;
/
create or replace trigger SDD_IGR_val
after insert or update of
  ITEM_GROUP_REF
 ,MODULE_COMPONENT_REF
 ,SUBCOMPONENT_REF
on i$SDD_IGR
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276423250214731370543485306937;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_IGR(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_IGR) violated');
    end if;
    if not FK_IGR_TO_IGR(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_IGR_TO_IGR) violated - parent key not found');
    end if;
    if not FK_IGR_TO_MCO(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_IGR_TO_MCO) violated - parent key not found');
    end if;
    if not FK_IGR_TO_SUB(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_IGR_TO_SUB) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_IGR_val;
/
create or replace trigger SDD_IGR_d
  instead of delete on SDD_IGR for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_IGR el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 update SDD_IGR fktab
    set 
        fktab.ITEM_GROUP_REF = NULL
  where 
        fktab.ITEM_GROUP_REF = :old.IRID
 ;
 update SDD_ITE fktab
    set 
        fktab.ITEM_GROUP_REF = NULL
  where 
        fktab.ITEM_GROUP_REF = :old.IRID
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_IGR
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_IGR_d;
/
create or replace trigger SDD_IND_br
  before insert or update or delete on i$SDD_IND
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.CLUSTER_REF is not null)
       )
    or (updating and (
        (:new.CLUSTER_REF != :old.CLUSTER_REF
        or (:new.CLUSTER_REF is not null and :old.CLUSTER_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_OCL owning_tab
        where  owning_tab.IRID=:new.CLUSTER_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_IND_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.SNAPSHOT_DEFINITION_REF is not null)
       )
    or (updating and (
        (:new.SNAPSHOT_DEFINITION_REF != :old.SNAPSHOT_DEFINITION_REF
        or (:new.SNAPSHOT_DEFINITION_REF is not null and :old.SNAPSHOT_DEFINITION_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_TAB owning_tab
        where  owning_tab.IRID=:new.SNAPSHOT_DEFINITION_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_IND_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.TABLE_DEFINITION_REF is not null)
       )
    or (updating and (
        (:new.TABLE_DEFINITION_REF != :old.TABLE_DEFINITION_REF
        or (:new.TABLE_DEFINITION_REF is not null and :old.TABLE_DEFINITION_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_TAB owning_tab
        where  owning_tab.IRID=:new.TABLE_DEFINITION_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_IND_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_IND');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_IND_br;
/
create or replace trigger SDD_IND_inv
after insert or update of
  FOREIGN_KEY_REF
on i$SDD_IND
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276423585502751654288295479353;
  this_type_irid  := :new.TYPES;
  if updating then
    action := 'UPD';
    -- Check child objects when primary or unique key is changed
    -- Note, the called functions consider whether constraints are immediate or deferred
  end if;   -- updating
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_IND_inv;
/
create or replace trigger SDD_IND_val
after insert or update of
  FOREIGN_KEY_REF
on i$SDD_IND
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276423585502751654288295479353;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_IND(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_IND) violated');
    end if;
    if not FK_IND_TO_FCO(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_IND_TO_FCO) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_IND_val;
/
create or replace trigger SDD_IND_d
  instead of delete on SDD_IND for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_IND el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 delete SDD_INS fktab
  where 
        fktab.INDEX_REF = :old.IRID
    ;
  delete SDD_INDCOL fktab
   where 
         fktab.RELATION_INDEX_REF = :old.IRID
    ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_IND
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_IND_d;
/
create or replace trigger SDD_INDCOL_br
  before insert or update or delete on i$SDD_INDCOL
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.RELATION_INDEX_REF is not null)
       )
    or (updating and (
        (:new.RELATION_INDEX_REF != :old.RELATION_INDEX_REF
        or (:new.RELATION_INDEX_REF is not null and :old.RELATION_INDEX_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select pac_ref, parent_ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_IND owning_tab
        where  owning_tab.IRID=:new.RELATION_INDEX_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_INDCOL_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_INDCOL');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_INDCOL_br;
/
create or replace trigger SDD_INDCOL_inv
after insert or update of
  COLUMN_REF
 ,CQA_REF
on i$SDD_INDCOL
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276423892456573040815234369593;
  this_type_irid  := :new.TYPES;
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_INDCOL_inv;
/
create or replace trigger SDD_INDCOL_val
after insert or update of
  COLUMN_REF
 ,CQA_REF
on i$SDD_INDCOL
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276423892456573040815234369593;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_INDCOL(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_INDCOL) violated');
    end if;
    if not FK_INDCOL_TO_COL(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_INDCOL_TO_COL) violated - parent key not found');
    end if;
    if not FK_INDCOL_TO_CQA(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_INDCOL_TO_CQA) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_INDCOL_val;
/
create or replace trigger SDD_INDCOL_d
  instead of delete on SDD_INDCOL for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_INDCOL el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_INDCOL
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_INDCOL_d;
/
create or replace trigger SDD_INP_br
  before insert or update or delete on i$SDD_INP
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.INDEX_STORAGE_REF is not null)
       )
    or (updating and (
        (:new.INDEX_STORAGE_REF != :old.INDEX_STORAGE_REF
        or (:new.INDEX_STORAGE_REF is not null and :old.INDEX_STORAGE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select pac_ref, parent_ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_INS owning_tab
        where  owning_tab.IRID=:new.INDEX_STORAGE_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_INP_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_INP');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_INP_br;
/
create or replace trigger SDD_INP_inv
after insert or update of
  STORAGE_DEFINITION_REF
 ,TABLESPACE_REF
 ,TABLE_PARTITION_REF
on i$SDD_INP
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276424189965661461602882832441;
  this_type_irid  := :new.TYPES;
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_INP_inv;
/
create or replace trigger SDD_INP_val
after insert or update of
  STORAGE_DEFINITION_REF
 ,TABLESPACE_REF
 ,TABLE_PARTITION_REF
on i$SDD_INP
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276424189965661461602882832441;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_INP(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_INP) violated');
    end if;
    if not FK_INP_TO_OSP(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_INP_TO_OSP) violated - parent key not found');
    end if;
    if not FK_INP_TO_OTB(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_INP_TO_OTB) violated - parent key not found');
    end if;
    if not FK_INP_TO_TBP(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_INP_TO_TBP) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_INP_val;
/
create or replace trigger SDD_INP_d
  instead of delete on SDD_INP for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_INP el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_INP
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_INP_d;
/
create or replace trigger SDD_INS_br
  before insert or update or delete on i$SDD_INS
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.CLUSTER_REF is not null)
       )
    or (updating and (
        (:new.CLUSTER_REF != :old.CLUSTER_REF
        or (:new.CLUSTER_REF is not null and :old.CLUSTER_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select pac_ref, parent_ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_DOI owning_tab
        where  owning_tab.IRID=:new.CLUSTER_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_INS_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.SNAPSHOT_REF is not null)
       )
    or (updating and (
        (:new.SNAPSHOT_REF != :old.SNAPSHOT_REF
        or (:new.SNAPSHOT_REF is not null and :old.SNAPSHOT_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select pac_ref, parent_ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_DOI owning_tab
        where  owning_tab.IRID=:new.SNAPSHOT_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_INS_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.TABLE_IMPLEMENTATION_REF is not null)
       )
    or (updating and (
        (:new.TABLE_IMPLEMENTATION_REF != :old.TABLE_IMPLEMENTATION_REF
        or (:new.TABLE_IMPLEMENTATION_REF is not null and :old.TABLE_IMPLEMENTATION_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select pac_ref, parent_ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_DOI owning_tab
        where  owning_tab.IRID=:new.TABLE_IMPLEMENTATION_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_INS_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_INS');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_INS_br;
/
create or replace trigger SDD_INS_inv
after insert or update of
  INDEX_REF
 ,STORAGE_DEFINITION_REF
 ,TABLESPACE_REF
 ,PRIMARY_KEY_REF
 ,UNIQUE_KEY_REF
on i$SDD_INS
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276424506364215813869112150073;
  this_type_irid  := :new.TYPES;
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_INS_inv;
/
create or replace trigger SDD_INS_val
after insert or update of
  INDEX_REF
 ,STORAGE_DEFINITION_REF
 ,TABLESPACE_REF
 ,PRIMARY_KEY_REF
 ,UNIQUE_KEY_REF
on i$SDD_INS
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276424506364215813869112150073;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_INS(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_INS) violated');
    end if;
    if not FK_INS_TO_IND(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_INS_TO_IND) violated - parent key not found');
    end if;
    if not FK_INS_TO_OSP(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_INS_TO_OSP) violated - parent key not found');
    end if;
    if not FK_INS_TO_OTB(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_INS_TO_OTB) violated - parent key not found');
    end if;
    if not FK_INS_TO_PCO(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_INS_TO_PCO) violated - parent key not found');
    end if;
    if not FK_INS_TO_UCO(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_INS_TO_UCO) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_INS_val;
/
create or replace trigger SDD_INS_d
  instead of delete on SDD_INS for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_INS el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
  delete SDD_INP fktab
   where 
         fktab.INDEX_STORAGE_REF = :old.IRID
    ;
  delete SDD_TBICOL fktab
   where 
         fktab.INDEX_STORAGE_REF = :old.IRID
    ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_INS
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_INS_d;
/
create or replace trigger SDD_ITE_br
  before insert or update or delete on i$SDD_ITE
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.MODULE_UNIT_REF is not null)
       )
    or (updating and (
        (:new.MODULE_UNIT_REF != :old.MODULE_UNIT_REF
        or (:new.MODULE_UNIT_REF is not null and :old.MODULE_UNIT_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select nvl(pac_ref, irid), nvl(parent_ivid, ivid)
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_MUN owning_tab
        where  owning_tab.IRID=:new.MODULE_UNIT_REF
        and    jr_vn.context(nvl(owning_tab.parent_ivid, owning_tab.ivid)) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_ITE_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.SQL_QUERY_SET_REF is not null)
       )
    or (updating and (
        (:new.SQL_QUERY_SET_REF != :old.SQL_QUERY_SET_REF
        or (:new.SQL_QUERY_SET_REF is not null and :old.SQL_QUERY_SET_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select pac_ref, parent_ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_SQS owning_tab
        where  owning_tab.IRID=:new.SQL_QUERY_SET_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_ITE_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_ITE');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_ITE_br;
/
create or replace trigger SDD_ITE_inv
after insert or update of
  COLUMN_REF
 ,DOMAIN_REF
 ,ITEM_GROUP_REF
 ,DETAIL_TABLE_USAGE_REF
 ,MODULE_UNIT_REF
on i$SDD_ITE
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276424907765366857788955314233;
  this_type_irid  := :new.TYPES;
  if updating then
    action := 'UPD';
    -- Check child objects when primary or unique key is changed
    -- Note, the called functions consider whether constraints are immediate or deferred
  end if;   -- updating
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_ITE_inv;
/
create or replace trigger SDD_ITE_val
after insert or update of
  COLUMN_REF
 ,DOMAIN_REF
 ,ITEM_GROUP_REF
 ,DETAIL_TABLE_USAGE_REF
 ,MODULE_UNIT_REF
on i$SDD_ITE
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276424907765366857788955314233;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_ITE(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_ITE) violated');
    end if;
    if not FK_ITE_TO_COL(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ITE_TO_COL) violated - parent key not found');
    end if;
    if not FK_ITE_TO_DOM(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ITE_TO_DOM) violated - parent key not found');
    end if;
    if not FK_ITE_TO_IGR(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ITE_TO_IGR) violated - parent key not found');
    end if;
    if not FK_ITE_TO_MTI(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ITE_TO_MTI) violated - parent key not found');
    end if;
    if not FK_ITE_TO_MUN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ITE_TO_MUN) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_ITE_val;
/
create or replace trigger SDD_ITE_d
  instead of delete on SDD_ITE for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_ITE el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 delete SDD_ARGITE fktab
  where 
        fktab.ITEM_REF = :old.IRID
    ;
  delete SDD_ATV fktab
   where 
         fktab.UNBOUND_ITEM_REF = :old.IRID
    ;
 update SDD_LVI fktab
    set 
        fktab.ITEM_REF = NULL
  where 
        fktab.ITEM_REF = :old.IRID
 ;
 update SDD_PVL fktab
    set 
        fktab.ITEM_REF = NULL
  where 
        fktab.ITEM_REF = :old.IRID
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_ITE
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_ITE_d;
/
create or replace trigger SDD_ITM_br
  before insert or update or delete on i$SDD_ITM
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.DATASTRUCTURE_REF is not null)
       )
    or (updating and (
        (:new.DATASTRUCTURE_REF != :old.DATASTRUCTURE_REF
        or (:new.DATASTRUCTURE_REF is not null and :old.DATASTRUCTURE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select pac_ref, parent_ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_DAT owning_tab
        where  owning_tab.IRID=:new.DATASTRUCTURE_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_ITM_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_ITM');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_ITM_br;
/
create or replace trigger SDD_ITM_inv
after insert or update of
  COLUMN_REF
 ,CQA_REF
 ,DATASTRUCTURE_REF2
 ,DOMAIN_REF
 ,ORACLE_TYPE_REF
 ,PROGRAM_DATUM_REF
 ,PLSQL_MODULE_REF
 ,CURSOR_REF
 ,TABLE_DEFINITION_REF
on i$SDD_ITM
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276425436670412939189219248185;
  this_type_irid  := :new.TYPES;
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_ITM_inv;
/
create or replace trigger SDD_ITM_val
after insert or update of
  COLUMN_REF
 ,CQA_REF
 ,DATASTRUCTURE_REF2
 ,DOMAIN_REF
 ,ORACLE_TYPE_REF
 ,PROGRAM_DATUM_REF
 ,PLSQL_MODULE_REF
 ,CURSOR_REF
 ,TABLE_DEFINITION_REF
on i$SDD_ITM
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276425436670412939189219248185;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_ITM(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_ITM) violated');
    end if;
    if not FK_ITM_TO_COL(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ITM_TO_COL) violated - parent key not found');
    end if;
    if not FK_ITM_TO_CQA(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ITM_TO_CQA) violated - parent key not found');
    end if;
    if not FK_ITM_TO_DAT2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ITM_TO_DAT2) violated - parent key not found');
    end if;
    if not FK_ITM_TO_DOM(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ITM_TO_DOM) violated - parent key not found');
    end if;
    if not FK_ITM_TO_ORT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ITM_TO_ORT) violated - parent key not found');
    end if;
    if not FK_ITM_TO_PGD(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ITM_TO_PGD) violated - parent key not found');
    end if;
    if not FK_ITM_TO_PLM(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ITM_TO_PLM) violated - parent key not found');
    end if;
    if not FK_ITM_TO_PLM2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ITM_TO_PLM2) violated - parent key not found');
    end if;
    if not FK_ITM_TO_TBL(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ITM_TO_TBL) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_ITM_val;
/
create or replace trigger SDD_ITM_d
  instead of delete on SDD_ITM for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_ITM el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_ITM
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_ITM_d;
/
create or replace trigger SDD_LAN_br
  before insert or update or delete on i$SDD_LAN
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_LAN_br;
/
create or replace trigger SDD_LAN_ar
  after insert or update or delete on i$SDD_LAN
  for each row 
begin
  -- Inserting
  if inserting then
    jr_object_version.ins ( :new.irid, :new.ivid
    , name => :new.NAME
    , type_irid => :new.TYPES
    , table_irid => 384781276426083634621092330613524537
    );
  end if;  -- inserting
  -- Updating
  if updating then
    jr_object_version.upd ( :old.ivid
      , name => :new.NAME
    );
  end if;  -- updating
  -- Deleting
  if deleting then
    jr_object_version.del ( :old.irid, :old.ivid, 'SDD_LAN'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_LAN_ar;
/
create or replace trigger SDD_LAN_inv
after insert
on i$SDD_LAN
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276426083634621092330613524537;
  this_type_irid  := :new.TYPES;
  if updating then
    action := 'UPD';
    -- Check child objects when primary or unique key is changed
    -- Note, the called functions consider whether constraints are immediate or deferred
  end if;   -- updating
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_LAN_inv;
/
create or replace trigger SDD_LAN_val
after insert
on i$SDD_LAN
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276426083634621092330613524537;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_LAN(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_LAN) violated');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_LAN_val;
/
create or replace trigger SDD_LAN_d
  instead of delete on SDD_LAN for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
  where ov.irid=:old.irid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  jr_wastebasket.remove(:old.ivid);
  if jr_context.workarea is NULL and not only_version then
   return;
  end if;
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
  if not jr_wastebasket.force_flag 
   and jr_wastebasket.repos_constraints_enabled then
   -- bug fix 2078916 - BLOCK DELETE IF USER EXTENDED ASSOCIATION EXISTS
   if not jr_ues_chk.check_ues_blocks_delete (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_MOD_TO_LAN_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_MUN_TO_LAN_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
 elsif jr_wastebasket.force_flag then 
  jr_wastebasket.set_secondary_delete;
  delete SDD_MUN fktab
   where 
         fktab.LANGUAGE_REF = :old.IRID
    ;
  update SDD_MOD fktab
     set 
         fktab.LANGUAGE_REF = NULL
   where 
         fktab.LANGUAGE_REF = :old.IRID
  ;

  -- bug fix 2078916 - FORCE DELETE IF USER EXTENDED ASSOCIATION EXISTS
  delete SDD_UES fktab
  where fktab.USE_OF_REF = :old.IRID;

 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 update SDD_FIL fktab
    set 
        fktab.LANGUAGE_REF = NULL
  where 
        fktab.LANGUAGE_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
 ;
 delete SDD_FIL fktab
  where 
        fktab.LANGUAGE_REF = :old.IRID
    and fktab.ivid in (select o.ivid
                        from I$SDD_OBJECT_VERSIONS o
                       where o.state='I')
 ;
 update SDD_FOLDERS fktab
    set 
        fktab.LANGUAGE_REF = NULL
  where 
        fktab.LANGUAGE_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
 ;
 delete SDD_FOLDERS fktab
  where 
        fktab.LANGUAGE_REF = :old.IRID
    and fktab.ivid in (select o.ivid
                        from I$SDD_OBJECT_VERSIONS o
                       where o.state='I')
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_LAN_d;
/
create or replace trigger SDD_LST_br
  before insert or update or delete on i$SDD_LST
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.ORACLE_DATABASE_REF is not null)
       )
    or (updating and (
        (:new.ORACLE_DATABASE_REF != :old.ORACLE_DATABASE_REF
        or (:new.ORACLE_DATABASE_REF is not null and :old.ORACLE_DATABASE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_ODB owning_tab
        where  owning_tab.IRID=:new.ORACLE_DATABASE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_LST_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_LST');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_LST_br;
/
create or replace trigger SDD_LST_inv
after insert or update of
  STORAGE_DEFINITION_REF
 ,INDEX_STORAGE_DEFN_REF
 ,TABLESPACE_REF
 ,INDEX_TABLESPACE_REF
on i$SDD_LST
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276426329197678201552164636729;
  this_type_irid  := :new.TYPES;
  if updating then
    action := 'UPD';
    -- Check child objects when primary or unique key is changed
    -- Note, the called functions consider whether constraints are immediate or deferred
  end if;   -- updating
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_LST_inv;
/
create or replace trigger SDD_LST_val
after insert or update of
  STORAGE_DEFINITION_REF
 ,INDEX_STORAGE_DEFN_REF
 ,TABLESPACE_REF
 ,INDEX_TABLESPACE_REF
on i$SDD_LST
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276426329197678201552164636729;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_LST(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_LST) violated');
    end if;
    if not FK_LST_TO_OSP(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_LST_TO_OSP) violated - parent key not found');
    end if;
    if not FK_LST_TO_OSP2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_LST_TO_OSP2) violated - parent key not found');
    end if;
    if not FK_LST_TO_OTB(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_LST_TO_OTB) violated - parent key not found');
    end if;
    if not FK_LST_TO_OTB2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_LST_TO_OTB2) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_LST_val;
/
create or replace trigger SDD_LST_d
  instead of delete on SDD_LST for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_LST el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
  if not jr_wastebasket.force_flag 
   and jr_wastebasket.repos_constraints_enabled then
   if not FK_CST_TO_LST_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
 elsif jr_wastebasket.force_flag then 
  jr_wastebasket.set_secondary_delete;
  delete SDD_CST fktab
   where 
         fktab.LOB_STORAGE_REF = :old.IRID
    ;
 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_LST
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_LST_d;
/
create or replace trigger SDD_LVI_br
  before insert or update or delete on i$SDD_LVI
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.GENERAL_MODULE_REF is not null)
       )
    or (updating and (
        (:new.GENERAL_MODULE_REF != :old.GENERAL_MODULE_REF
        or (:new.GENERAL_MODULE_REF is not null and :old.GENERAL_MODULE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select nvl(pac_ref, irid), nvl(parent_ivid, ivid)
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_MOD owning_tab
        where  owning_tab.IRID=:new.GENERAL_MODULE_REF
        and    jr_vn.context(nvl(owning_tab.parent_ivid, owning_tab.ivid)) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_LVI_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_LVI');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_LVI_br;
/
create or replace trigger SDD_LVI_inv
after insert or update of
  GENERAL_MODULE_REF
 ,ITEM_REF
 ,LIST_OF_VALUES_REF
on i$SDD_LVI
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276426659763332002427329595449;
  this_type_irid  := :new.TYPES;
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_LVI_inv;
/
create or replace trigger SDD_LVI_val
after insert or update of
  GENERAL_MODULE_REF
 ,ITEM_REF
 ,LIST_OF_VALUES_REF
on i$SDD_LVI
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276426659763332002427329595449;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_LVI(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_LVI) violated');
    end if;
    if not FK_LVI_TO_GEM(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_LVI_TO_GEM) violated - parent key not found');
    end if;
    if not FK_LVI_TO_ITE(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_LVI_TO_ITE) violated - parent key not found');
    end if;
    if not FK_LVI_TO_LOV(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_LVI_TO_LOV) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_LVI_val;
/
create or replace trigger SDD_LVI_d
  instead of delete on SDD_LVI for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_LVI el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_LVI
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_LVI_d;
/
create or replace trigger SDD_MAP_br
  before insert or update or delete on i$SDD_MAP
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.TRANSFORMATION_SET_REF is not null)
       )
    or (updating and (
        (:new.TRANSFORMATION_SET_REF != :old.TRANSFORMATION_SET_REF
        or (:new.TRANSFORMATION_SET_REF is not null and :old.TRANSFORMATION_SET_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_TMS owning_tab
        where  owning_tab.IRID=:new.TRANSFORMATION_SET_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_MAP_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_MAP');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_MAP_br;
/
create or replace trigger SDD_MAP_inv
after insert or update of
  PRIMARY_MAPPING_REF
on i$SDD_MAP
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276426966717153388954268485689;
  this_type_irid  := :new.TYPES;
  if updating then
    action := 'UPD';
    -- Check child objects when primary or unique key is changed
    -- Note, the called functions consider whether constraints are immediate or deferred
  end if;   -- updating
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_MAP_inv;
/
create or replace trigger SDD_MAP_val
after insert or update of
  PRIMARY_MAPPING_REF
on i$SDD_MAP
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276426966717153388954268485689;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_MAP(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_MAP) violated');
    end if;
    if not FK_MAP_TO_MAP(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MAP_TO_MAP) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_MAP_val;
/
create or replace trigger SDD_MAP_d
  instead of delete on SDD_MAP for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_MAP el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 update SDD_MAP fktab
    set 
        fktab.PRIMARY_MAPPING_REF = NULL
  where 
        fktab.PRIMARY_MAPPING_REF = :old.IRID
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_MAP
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_MAP_d;
/
create or replace trigger SDD_MCH_br
  before insert or update or delete on i$SDD_MCH
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.MODULE_REF is not null)
       )
    or (updating and (
        (:new.MODULE_REF != :old.MODULE_REF
        or (:new.MODULE_REF is not null and :old.MODULE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select nvl(pac_ref, irid), nvl(parent_ivid, ivid)
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_MOD owning_tab
        where  owning_tab.IRID=:new.MODULE_REF
        and    jr_vn.context(nvl(owning_tab.parent_ivid, owning_tab.ivid)) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_MCH_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_MCH');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_MCH_br;
/
create or replace trigger SDD_MCH_inv
after insert or update of
  MODULE_REF
on i$SDD_MCH
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276427150889446220870431819833;
  this_type_irid  := :new.TYPES;
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_MCH_inv;
/
create or replace trigger SDD_MCH_val
after insert or update of
  MODULE_REF
on i$SDD_MCH
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276427150889446220870431819833;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_MCH(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_MCH) violated');
    end if;
    if not FK_MCH_TO_MOD(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MCH_TO_MOD) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_MCH_val;
/
create or replace trigger SDD_MCH_d
  instead of delete on SDD_MCH for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_MCH el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_MCH
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_MCH_d;
/
create or replace trigger SDD_MCL_br
  before insert or update or delete on i$SDD_MCL
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.MODULE_REF_FROM is not null)
       )
    or (updating and (
        (:new.MODULE_REF_FROM != :old.MODULE_REF_FROM
        or (:new.MODULE_REF_FROM is not null and :old.MODULE_REF_FROM is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select nvl(pac_ref, irid), nvl(parent_ivid, ivid)
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_MOD owning_tab
        where  owning_tab.IRID=:new.MODULE_REF_FROM
        and    jr_vn.context(nvl(owning_tab.parent_ivid, owning_tab.ivid)) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_MCL_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_MCL');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_MCL_br;
/
create or replace trigger SDD_MCL_inv
after insert or update of
  MCN_REF_FROM
 ,MCN_REF_TO
 ,MODULE_REF_FROM
 ,MODULE_REF_TO
 ,JOIN_CONSTRAINT_REF
 ,TABLE_USAGE_REF_FROM
 ,TABLE_USAGE_REF_TO
 ,PRIMARY_KEY_REF
on i$SDD_MCL
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276427443676168158788435068985;
  this_type_irid  := :new.TYPES;
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_MCL_inv;
/
create or replace trigger SDD_MCL_val
after insert or update of
  MCN_REF_FROM
 ,MCN_REF_TO
 ,MODULE_REF_FROM
 ,MODULE_REF_TO
 ,JOIN_CONSTRAINT_REF
 ,TABLE_USAGE_REF_FROM
 ,TABLE_USAGE_REF_TO
 ,PRIMARY_KEY_REF
on i$SDD_MCL
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276427443676168158788435068985;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_MCL(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_MCL) violated');
    end if;
    if not UK_MCL(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (UK_MCL) violated');
    end if;
    if not FK_MCL_TO_GEM(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MCL_TO_GEM) violated - parent key not found');
    end if;
    if not FK_MCL_TO_GEM2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MCL_TO_GEM2) violated - parent key not found');
    end if;
    if not FK_MCL_TO_JCO(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MCL_TO_JCO) violated - parent key not found');
    end if;
    if not FK_MCL_TO_MCN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MCL_TO_MCN) violated - parent key not found');
    end if;
    if not FK_MCL_TO_MCN2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MCL_TO_MCN2) violated - parent key not found');
    end if;
    if not FK_MCL_TO_MTI(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MCL_TO_MTI) violated - parent key not found');
    end if;
    if not FK_MCL_TO_MTI2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MCL_TO_MTI2) violated - parent key not found');
    end if;
    if not FK_MCL_TO_PCO(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MCL_TO_PCO) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_MCL_val;
/
create or replace trigger SDD_MCL_d
  instead of delete on SDD_MCL for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_MCL el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_MCL
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_MCL_d;
/
create or replace trigger SDD_MCN_br
  before insert or update or delete on i$SDD_MCN
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.GENERAL_MODULE_REF is not null)
       )
    or (updating and (
        (:new.GENERAL_MODULE_REF != :old.GENERAL_MODULE_REF
        or (:new.GENERAL_MODULE_REF is not null and :old.GENERAL_MODULE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select nvl(pac_ref, irid), nvl(parent_ivid, ivid)
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_MOD owning_tab
        where  owning_tab.IRID=:new.GENERAL_MODULE_REF
        and    jr_vn.context(nvl(owning_tab.parent_ivid, owning_tab.ivid)) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_MCN_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_MCN');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_MCN_br;
/
create or replace trigger SDD_MCN_inv
after insert or update of
  GENERAL_MODULE_REF
 ,PARENT_MCN_REF
 ,RIGHT_OF_MCN_REF
 ,MODULE_COMPONENT_REF
 ,SUBCOMPONENT_REF
 ,WINDOW_REF
on i$SDD_MCN
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276427807298387339751116523577;
  this_type_irid  := :new.TYPES;
  if updating then
    action := 'UPD';
    -- Check child objects when primary or unique key is changed
    -- Note, the called functions consider whether constraints are immediate or deferred
  end if;   -- updating
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_MCN_inv;
/
create or replace trigger SDD_MCN_val
after insert or update of
  GENERAL_MODULE_REF
 ,PARENT_MCN_REF
 ,RIGHT_OF_MCN_REF
 ,MODULE_COMPONENT_REF
 ,SUBCOMPONENT_REF
 ,WINDOW_REF
on i$SDD_MCN
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276427807298387339751116523577;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_MCN(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_MCN) violated');
    end if;
    if not FK_MCN_TO_GEM(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MCN_TO_GEM) violated - parent key not found');
    end if;
    if not FK_MCN_TO_MCN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MCN_TO_MCN) violated - parent key not found');
    end if;
    if not FK_MCN_TO_MCN2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MCN_TO_MCN2) violated - parent key not found');
    end if;
    if not FK_MCN_TO_MCO(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MCN_TO_MCO) violated - parent key not found');
    end if;
    if not FK_MCN_TO_SUB(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MCN_TO_SUB) violated - parent key not found');
    end if;
    if not FK_MCN_TO_WIN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MCN_TO_WIN) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_MCN_val;
/
create or replace trigger SDD_MCN_d
  instead of delete on SDD_MCN for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_MCN el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 delete SDD_ACI fktab
  where 
        fktab.MCN_REF_TO = :old.IRID
    ;
 delete SDD_MCL fktab
  where 
        fktab.MCN_REF_FROM = :old.IRID
    ;
 delete SDD_MCL fktab
  where 
        fktab.MCN_REF_TO = :old.IRID
    ;
  delete SDD_ACI fktab
   where 
         fktab.MCN_REF = :old.IRID
    ;
 update SDD_MCN fktab
    set 
        fktab.PARENT_MCN_REF = NULL
  where 
        fktab.PARENT_MCN_REF = :old.IRID
 ;
 update SDD_MCN fktab
    set 
        fktab.RIGHT_OF_MCN_REF = NULL
  where 
        fktab.RIGHT_OF_MCN_REF = :old.IRID
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_MCN
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_MCN_d;
/
create or replace trigger SDD_MEMCOM_br
  before insert or update or delete on i$SDD_MEMCOM
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.ATTRIBUTE_DERIV_RULE_REF is not null)
       )
    or (updating and (
        (:new.ATTRIBUTE_DERIV_RULE_REF != :old.ATTRIBUTE_DERIV_RULE_REF
        or (:new.ATTRIBUTE_DERIV_RULE_REF is not null and :old.ATTRIBUTE_DERIV_RULE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select pac_ref, parent_ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_ADR owning_tab
        where  owning_tab.IRID=:new.ATTRIBUTE_DERIV_RULE_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_MEMCOM_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.CROSS_OBJECT_RULE_REF is not null)
       )
    or (updating and (
        (:new.CROSS_OBJECT_RULE_REF != :old.CROSS_OBJECT_RULE_REF
        or (:new.CROSS_OBJECT_RULE_REF is not null and :old.CROSS_OBJECT_RULE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_COR owning_tab
        where  owning_tab.IRID=:new.CROSS_OBJECT_RULE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_MEMCOM_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.INTEGRITY_RULE_REF is not null)
       )
    or (updating and (
        (:new.INTEGRITY_RULE_REF != :old.INTEGRITY_RULE_REF
        or (:new.INTEGRITY_RULE_REF is not null and :old.INTEGRITY_RULE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select pac_ref, parent_ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_CRU owning_tab
        where  owning_tab.IRID=:new.INTEGRITY_RULE_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_MEMCOM_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.NAMED_RULE_REF is not null)
       )
    or (updating and (
        (:new.NAMED_RULE_REF != :old.NAMED_RULE_REF
        or (:new.NAMED_RULE_REF is not null and :old.NAMED_RULE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_RUL owning_tab
        where  owning_tab.IRID=:new.NAMED_RULE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_MEMCOM_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.STATE_RULE_REF is not null)
       )
    or (updating and (
        (:new.STATE_RULE_REF != :old.STATE_RULE_REF
        or (:new.STATE_RULE_REF is not null and :old.STATE_RULE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select pac_ref, parent_ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_SRU owning_tab
        where  owning_tab.IRID=:new.STATE_RULE_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_MEMCOM_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_MEMCOM');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_MEMCOM_br;
/
create or replace trigger SDD_MEMCOM_inv
after insert or update of
  ASSOCIATION_END_REF
 ,CLASSIFIER_ATTRIBUTE_REF
 ,METHOD_REF
on i$SDD_MEMCOM
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276428147308774106365571909689;
  this_type_irid  := :new.TYPES;
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_MEMCOM_inv;
/
create or replace trigger SDD_MEMCOM_val
after insert or update of
  ASSOCIATION_END_REF
 ,CLASSIFIER_ATTRIBUTE_REF
 ,METHOD_REF
on i$SDD_MEMCOM
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276428147308774106365571909689;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_MEMCOM(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_MEMCOM) violated');
    end if;
    if not FK_MEMCOM_TO_AEN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MEMCOM_TO_AEN) violated - parent key not found');
    end if;
    if not FK_MEMCOM_TO_CAT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MEMCOM_TO_CAT) violated - parent key not found');
    end if;
    if not FK_MEMCOM_TO_MET(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MEMCOM_TO_MET) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_MEMCOM_val;
/
create or replace trigger SDD_MEMCOM_d
  instead of delete on SDD_MEMCOM for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_MEMCOM el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_MEMCOM
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_MEMCOM_d;
/
create or replace trigger SDD_MET_br
  before insert or update or delete on i$SDD_MET
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.CLASSIFIER_REF is not null)
       )
    or (updating and (
        (:new.CLASSIFIER_REF != :old.CLASSIFIER_REF
        or (:new.CLASSIFIER_REF is not null and :old.CLASSIFIER_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_CLA owning_tab
        where  owning_tab.IRID=:new.CLASSIFIER_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_MET_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_MET');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_MET_br;
/
create or replace trigger SDD_MET_inv
after insert or update of
  RETURN_CLASSIFIER_REF
 ,COLLECT_CLASSIFIER_REF
 ,ELEVATED_METHOD_REF
 ,OVERRIDING_METHOD_REF
on i$SDD_MET
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276428388149464732717477808185;
  this_type_irid  := :new.TYPES;
  if updating then
    action := 'UPD';
    -- Check child objects when primary or unique key is changed
    -- Note, the called functions consider whether constraints are immediate or deferred
  end if;   -- updating
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_MET_inv;
/
create or replace trigger SDD_MET_val
after insert or update of
  RETURN_CLASSIFIER_REF
 ,COLLECT_CLASSIFIER_REF
 ,ELEVATED_METHOD_REF
 ,OVERRIDING_METHOD_REF
on i$SDD_MET
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276428388149464732717477808185;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_MET(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_MET) violated');
    end if;
    if not FK_MET_TO_CLA2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MET_TO_CLA2) violated - parent key not found');
    end if;
    if not FK_MET_TO_CLA3(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MET_TO_CLA3) violated - parent key not found');
    end if;
    if not FK_MET_TO_MET(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MET_TO_MET) violated - parent key not found');
    end if;
    if not FK_MET_TO_MET2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MET_TO_MET2) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_MET_val;
/
create or replace trigger SDD_MET_d
  instead of delete on SDD_MET for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_MET el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 delete SDD_MEMCOM fktab
  where 
        fktab.METHOD_REF = :old.IRID
    ;
  delete SDD_EVH fktab
   where 
         fktab.METHOD_REF = :old.IRID
    ;
  delete SDD_EVR fktab
   where 
         fktab.METHOD_REF = :old.IRID
    ;
  delete SDD_METRUL fktab
   where 
         fktab.METHOD_REF = :old.IRID
    ;
  delete SDD_MPA fktab
   where 
         fktab.METHOD_REF = :old.IRID
    ;
  delete SDD_SBA fktab
   where 
         fktab.METHOD_REF = :old.IRID
    ;
 update SDD_ACT fktab
    set 
        fktab.METHOD_REF = NULL
  where 
        fktab.METHOD_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
 ;
 delete SDD_ACT fktab
  where 
        fktab.METHOD_REF = :old.IRID
    and fktab.ivid in (select o.ivid
                        from I$SDD_OBJECT_VERSIONS o
                       where o.state='I')
 ;
 update SDD_ADR fktab
    set 
        fktab.METHOD_REF = NULL
  where 
        fktab.METHOD_REF = :old.IRID
 ;
 update SDD_CORI fktab
    set 
        fktab.METHOD_REF = NULL
  where 
        fktab.METHOD_REF = :old.IRID
 ;
 update SDD_CRU fktab
    set 
        fktab.METHOD_REF = NULL
  where 
        fktab.METHOD_REF = :old.IRID
 ;
 update SDD_MET fktab
    set 
        fktab.ELEVATED_METHOD_REF = NULL
  where 
        fktab.ELEVATED_METHOD_REF = :old.IRID
 ;
 update SDD_MET fktab
    set 
        fktab.OVERRIDING_METHOD_REF = NULL
  where 
        fktab.OVERRIDING_METHOD_REF = :old.IRID
 ;
 update SDD_RUL fktab
    set 
        fktab.METHOD_REF = NULL
  where 
        fktab.METHOD_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
 ;
 delete SDD_RUL fktab
  where 
        fktab.METHOD_REF = :old.IRID
    and fktab.ivid in (select o.ivid
                        from I$SDD_OBJECT_VERSIONS o
                       where o.state='I')
 ;
 update SDD_SRU fktab
    set 
        fktab.METHOD_REF = NULL
  where 
        fktab.METHOD_REF = :old.IRID
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_MET
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_MET_d;
/
create or replace trigger SDD_METRUL_br
  before insert or update or delete on i$SDD_METRUL
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.METHOD_REF is not null)
       )
    or (updating and (
        (:new.METHOD_REF != :old.METHOD_REF
        or (:new.METHOD_REF is not null and :old.METHOD_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select pac_ref, parent_ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_MET owning_tab
        where  owning_tab.IRID=:new.METHOD_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_METRUL_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_METRUL');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_METRUL_br;
/
create or replace trigger SDD_METRUL_inv
after insert or update of
  ATTRIBUTE_DERIV_RULE_REF
 ,CROSS_OBJECT_RULE_REF
 ,CLASSIFIER_RULE_REF
 ,NAMED_RULE_REF
 ,STATE_RULE_REF
on i$SDD_METRUL
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276428671491453704896190629945;
  this_type_irid  := :new.TYPES;
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_METRUL_inv;
/
create or replace trigger SDD_METRUL_val
after insert or update of
  ATTRIBUTE_DERIV_RULE_REF
 ,CROSS_OBJECT_RULE_REF
 ,CLASSIFIER_RULE_REF
 ,NAMED_RULE_REF
 ,STATE_RULE_REF
on i$SDD_METRUL
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276428671491453704896190629945;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_METRUL(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_METRUL) violated');
    end if;
    if not FK_METRUL_TO_ADR(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_METRUL_TO_ADR) violated - parent key not found');
    end if;
    if not FK_METRUL_TO_COR(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_METRUL_TO_COR) violated - parent key not found');
    end if;
    if not FK_METRUL_TO_CRU(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_METRUL_TO_CRU) violated - parent key not found');
    end if;
    if not FK_METRUL_TO_RUL(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_METRUL_TO_RUL) violated - parent key not found');
    end if;
    if not FK_METRUL_TO_SRU(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_METRUL_TO_SRU) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_METRUL_val;
/
create or replace trigger SDD_METRUL_d
  instead of delete on SDD_METRUL for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_METRUL el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_METRUL
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_METRUL_d;
/
create or replace trigger SDD_MOD_br
  before insert or update or delete on i$SDD_MOD
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.ORACLE_OBJECT_TYPE_REF is not null)
       )
    or (updating and (
        (:new.ORACLE_OBJECT_TYPE_REF != :old.ORACLE_OBJECT_TYPE_REF
        or (:new.ORACLE_OBJECT_TYPE_REF is not null and :old.ORACLE_OBJECT_TYPE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_ORT owning_tab
        where  owning_tab.IRID=:new.ORACLE_OBJECT_TYPE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_MOD_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_MOD');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_MOD_br;
/
create or replace trigger SDD_MOD_ar
  after insert or update or delete on i$SDD_MOD
  for each row 
begin
  -- Inserting
  if inserting then
    jr_object_version.ins ( :new.irid, :new.ivid
    , name => :new.SHORT_NAME
    , type_irid => :new.TYPES
    , table_irid => 384781276428874553212468290934818873
    , parent_ivid => :new.parent_ivid
    );
  end if;  -- inserting
  -- Updating
  if updating then
    jr_object_version.upd ( :old.ivid
      , parent_ivid => :old.parent_ivid
      , name => :new.SHORT_NAME
    );
  end if;  -- updating
  -- Deleting
  if deleting then
    jr_object_version.del ( :old.irid, :old.ivid, 'SDD_MOD'
      , :old.parent_ivid  -- optional primary object instance
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_MOD_ar;
/
create or replace trigger SDD_MOD_inv
after insert or update of
  JAVA_MODULE_REF
 ,LANGUAGE_REF
 ,ORACLE_TYPE_REF
on i$SDD_MOD
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276428874553212468290934818873;
  this_type_irid  := :new.TYPES;
  if updating then
    action := 'UPD';
    -- Check child objects when primary or unique key is changed
    -- Note, the called functions consider whether constraints are immediate or deferred
  end if;   -- updating
  if updating then
    action := 'UPD';
    -- If PK updateable, check all owned objects
  end if; -- updating
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_MOD_inv;
/
create or replace trigger SDD_MOD_val
after insert or update of
  JAVA_MODULE_REF
 ,LANGUAGE_REF
 ,ORACLE_TYPE_REF
on i$SDD_MOD
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276428874553212468290934818873;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_MOD(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_MOD) violated');
    end if;
    if not FK_MOD_TO_JAM(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MOD_TO_JAM) violated - parent key not found');
    end if;
    if not FK_MOD_TO_LAN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MOD_TO_LAN) violated - parent key not found');
    end if;
    if not FK_MOD_TO_ORT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MOD_TO_ORT) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_MOD_val;
/
create or replace trigger SDD_MOD_d
  instead of delete on SDD_MOD for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_MOD el
  where el.irid=:old.irid
    and ov.ivid=NVL(el.parent_ivid, el.ivid)
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
 if :old.parent_ivid is null then
  -- Primary instance
  jr_wastebasket.remove(:old.ivid);
  if jr_context.workarea is NULL and not only_version then
   return;
  end if;
 else
  -- Secondary instance
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 end if;
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
  if not jr_wastebasket.force_flag 
   and jr_wastebasket.repos_constraints_enabled then
   -- bug fix 2078916 - BLOCK DELETE IF USER EXTENDED ASSOCIATION EXISTS
   if not jr_ues_chk.check_ues_blocks_delete (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_ITM_TO_PLM_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_ITM_TO_PLM2_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_MODMOD_TO_MOD2_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_TRG_TO_PLM_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
 elsif jr_wastebasket.force_flag then 
  jr_wastebasket.set_secondary_delete;
  delete SDD_MODMOD fktab
   where 
         fktab.CHILD_MODULE_REF = :old.IRID
    ;
  delete SDD_TRG fktab
   where 
         fktab.PLSQL_MODULE_REF = :old.IRID
    ;
  update SDD_ITM fktab
     set 
         fktab.PLSQL_MODULE_REF = NULL
   where 
         fktab.PLSQL_MODULE_REF = :old.IRID
  ;
  update SDD_ITM fktab
     set 
         fktab.CURSOR_REF = NULL
   where 
         fktab.CURSOR_REF = :old.IRID
  ;

  -- bug fix 2078916 - FORCE DELETE IF USER EXTENDED ASSOCIATION EXISTS
  delete SDD_UES fktab
  where fktab.USE_OF_REF = :old.IRID;

 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 delete SDD_A2 fktab
  where 
        fktab.MODULE_REF = :old.IRID
    ;
 delete SDD_A23 fktab
  where 
        fktab.MODULE_REF = :old.IRID
    ;
 delete SDD_A5 fktab
  where 
        fktab.MODULE_REF = :old.IRID
    ;
 delete SDD_A7 fktab
  where 
        fktab.MODULE_REF = :old.IRID
    ;
 delete SDD_DBUMOD fktab
  where 
        fktab.GENERAL_MODULE_REF = :old.IRID
    ;
 delete SDD_DOI fktab
  where 
        fktab.JAVA_MODULE_REF = :old.IRID
    ;
 delete SDD_DOI fktab
  where 
        fktab.PLSQL_MODULE_REF = :old.IRID
    ;
 delete SDD_GRPMOD fktab
  where 
        fktab.GENERAL_MODULE_REF = :old.IRID
    ;
 delete SDD_MCL fktab
  where 
        fktab.MODULE_REF_TO = :old.IRID
    ;
 --Secondary instance
 if :old.parent_ivid is not null then
  delete SDD_ARG fktab
   where 
         fktab.GENERAL_MODULE_REF = :old.IRID
    ;
  delete SDD_ARG fktab
   where 
         fktab.PLSQL_MODULE_REF = :old.IRID
    ;
  delete SDD_DAT fktab
   where 
         fktab.PLSQL_MODULE_REF = :old.IRID
    ;
  delete SDD_DSY fktab
   where 
         fktab.JAVA_MODULE_REF = :old.IRID
    ;
  delete SDD_DSY fktab
   where 
         fktab.PLSQL_MODULE_REF = :old.IRID
    ;
  delete SDD_LVI fktab
   where 
         fktab.GENERAL_MODULE_REF = :old.IRID
    ;
  delete SDD_MCH fktab
   where 
         fktab.MODULE_REF = :old.IRID
    ;
  delete SDD_MCL fktab
   where 
         fktab.MODULE_REF_FROM = :old.IRID
    ;
  delete SDD_MCN fktab
   where 
         fktab.GENERAL_MODULE_REF = :old.IRID
    ;
  delete SDD_MODBUN fktab
   where 
         fktab.MODULE_REF = :old.IRID
    ;
  delete SDD_MODFUN fktab
   where 
         fktab.MODULE_REF = :old.IRID
    ;
  delete SDD_MODMOD fktab
   where 
         fktab.PARENT_MODULE_REF = :old.IRID
    ;
  delete SDD_MODPGD fktab
   where 
         fktab.GENERAL_MODULE_REF = :old.IRID
    ;
  delete SDD_MODPGD fktab
   where 
         fktab.PLSQL_MODULE_REF = :old.IRID
    ;
  delete SDD_MUN fktab
   where 
         fktab.GENERAL_MODULE_REF = :old.IRID
    ;
  delete SDD_PGD fktab
   where 
         fktab.GENERAL_MODULE_REF = :old.IRID
    ;
  delete SDD_PGD fktab
   where 
         fktab.PLSQL_MODULE_REF = :old.IRID
    ;
  delete SDD_WIN fktab
   where 
         fktab.GENERAL_MODULE_REF = :old.IRID
    ;
 end if; --Secondary instance
 update SDD_BLI fktab
    set 
        fktab.GENERAL_MODULE_REF = NULL
  where 
        fktab.GENERAL_MODULE_REF = :old.IRID
 ;
 update SDD_MOD fktab
    set 
        fktab.JAVA_MODULE_REF = NULL
  where 
        fktab.JAVA_MODULE_REF = :old.IRID
 ;
 if :old.parent_ivid is null then
  -- Primary instance
  if (NOT jr_wastebasket.force_flag) and jr_wastebasket.repos_constraints_enabled then
   if not FK_PVL_TO_ARG2_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_ARG_TO_DAT_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_ITM_TO_DAT2_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_PGD_TO_DAT_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_MCN_TO_SUB_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_MTI_TO_MTI_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_ITM_TO_PGD_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   -- bug fix 2078916 - BLOCK DELETE IF USER EXTENDED ASSOCIATION FOR MUN EXISTS
   if not jr_ues_chk.FK_UES_TO_MUN_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   
  elsif jr_wastebasket.force_flag then
  delete SDD_PVL fktab
   where fktab.CALLED_ARGUMENT_REF in (select parent_tab.IRID
                                                      from i$SDD_ARG parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_ARG fktab
     set 
         fktab.DATASTRUCTURE_REF = NULL
   where fktab.DATASTRUCTURE_REF in (select parent_tab.IRID
                                                    from i$SDD_DAT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_ITM fktab
     set 
         fktab.DATASTRUCTURE_REF2 = NULL
   where fktab.DATASTRUCTURE_REF2 in (select parent_tab.IRID
                                                    from i$SDD_DAT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_PGD fktab
     set 
         fktab.DATASTRUCTURE_REF = NULL
   where fktab.DATASTRUCTURE_REF in (select parent_tab.IRID
                                                    from i$SDD_DAT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  delete SDD_MCN fktab
   where fktab.SUBCOMPONENT_REF in (select parent_tab.IRID
                                                      from i$SDD_MUN parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_MTI fktab
     set 
         fktab.MTI_REF = NULL
   where fktab.MTI_REF in (select parent_tab.IRID
                                                    from i$SDD_MTI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_ITM fktab
     set 
         fktab.PROGRAM_DATUM_REF = NULL
   where fktab.PROGRAM_DATUM_REF in (select parent_tab.IRID
                                                    from i$SDD_PGD parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  -- bug fix 2078916 - FORCE DELETE IF USER EXTENDED ASSOCIATION EXISTS TO ANY MODULE UNITS
  delete SDD_UES fktab
  where fktab.USE_OF_REF in (select parent_tab.IRID
                             from i$SDD_MUN parent_tab
                             where parent_tab.parent_ivid=:old.ivid)
  ;

  end if;--force delete/purge
 if jr_context.workarea is not null then
  update SDD_PVL
     set MODULE_ARGUMENT_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_PVL fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.MODULE_ARGUMENT_REF in (select parent_tab.IRID
                                                      from i$SDD_ARG parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_PVL
     set MODULE_ARGUMENT_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_PVL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.MODULE_ARGUMENT_REF in (select parent_tab.IRID
                                                      from i$SDD_ARG parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_ACI
   where ivid in
   (select fktab.ivid
      from i$SDD_ACI fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.MCN_REF_TO in (select parent_tab.IRID
                                                    from i$SDD_MCN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_ACI
   where ivid in
   (select fktab.ivid
      from i$SDD_ACI fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.MCN_REF_TO in (select parent_tab.IRID
                                                    from i$SDD_MCN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_MCL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCL fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.MCN_REF_FROM in (select parent_tab.IRID
                                                    from i$SDD_MCN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_MCL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.MCN_REF_FROM in (select parent_tab.IRID
                                                    from i$SDD_MCN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_MCL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCL fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.MCN_REF_TO in (select parent_tab.IRID
                                                    from i$SDD_MCN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_MCL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.MCN_REF_TO in (select parent_tab.IRID
                                                    from i$SDD_MCN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_MCN
     set PARENT_MCN_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCN fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.PARENT_MCN_REF in (select parent_tab.IRID
                                                      from i$SDD_MCN parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_MCN
     set PARENT_MCN_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCN fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.PARENT_MCN_REF in (select parent_tab.IRID
                                                      from i$SDD_MCN parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_MCN
     set RIGHT_OF_MCN_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCN fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.RIGHT_OF_MCN_REF in (select parent_tab.IRID
                                                      from i$SDD_MCN parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_MCN
     set RIGHT_OF_MCN_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCN fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.RIGHT_OF_MCN_REF in (select parent_tab.IRID
                                                      from i$SDD_MCN parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_ACI
   where ivid in
   (select fktab.ivid
      from i$SDD_ACI fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.MODULE_NETWORK_REF in (select parent_tab.IRID
                                                    from i$SDD_MODMOD parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_ACI
   where ivid in
   (select fktab.ivid
      from i$SDD_ACI fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.MODULE_NETWORK_REF in (select parent_tab.IRID
                                                    from i$SDD_MODMOD parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_LVI
   where ivid in
   (select fktab.ivid
      from i$SDD_LVI fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.LIST_OF_VALUES_REF in (select parent_tab.IRID
                                                    from i$SDD_MUN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_LVI
   where ivid in
   (select fktab.ivid
      from i$SDD_LVI fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.LIST_OF_VALUES_REF in (select parent_tab.IRID
                                                    from i$SDD_MUN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_MCN
   where ivid in
   (select fktab.ivid
      from i$SDD_MCN fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.MODULE_COMPONENT_REF in (select parent_tab.IRID
                                                    from i$SDD_MUN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_MCN
   where ivid in
   (select fktab.ivid
      from i$SDD_MCN fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.MODULE_COMPONENT_REF in (select parent_tab.IRID
                                                    from i$SDD_MUN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_IGR
     set ITEM_GROUP_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_IGR fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.ITEM_GROUP_REF in (select parent_tab.IRID
                                                      from i$SDD_IGR parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_IGR
     set ITEM_GROUP_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_IGR fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.ITEM_GROUP_REF in (select parent_tab.IRID
                                                      from i$SDD_IGR parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_ITE
     set ITEM_GROUP_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_ITE fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.ITEM_GROUP_REF in (select parent_tab.IRID
                                                      from i$SDD_IGR parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_ITE
     set ITEM_GROUP_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_ITE fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.ITEM_GROUP_REF in (select parent_tab.IRID
                                                      from i$SDD_IGR parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_ARGITE
   where ivid in
   (select fktab.ivid
      from i$SDD_ARGITE fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.ITEM_REF in (select parent_tab.IRID
                                                    from i$SDD_ITE parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_ARGITE
   where ivid in
   (select fktab.ivid
      from i$SDD_ARGITE fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.ITEM_REF in (select parent_tab.IRID
                                                    from i$SDD_ITE parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_LVI
     set ITEM_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_LVI fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.ITEM_REF in (select parent_tab.IRID
                                                      from i$SDD_ITE parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_LVI
     set ITEM_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_LVI fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.ITEM_REF in (select parent_tab.IRID
                                                      from i$SDD_ITE parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_PVL
     set ITEM_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_PVL fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.ITEM_REF in (select parent_tab.IRID
                                                      from i$SDD_ITE parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_PVL
     set ITEM_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_PVL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.ITEM_REF in (select parent_tab.IRID
                                                      from i$SDD_ITE parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_ITE
   where ivid in
   (select fktab.ivid
      from i$SDD_ITE fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.DETAIL_TABLE_USAGE_REF in (select parent_tab.IRID
                                                    from i$SDD_MTI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_ITE
   where ivid in
   (select fktab.ivid
      from i$SDD_ITE fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.DETAIL_TABLE_USAGE_REF in (select parent_tab.IRID
                                                    from i$SDD_MTI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_MCL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCL fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.TABLE_USAGE_REF_FROM in (select parent_tab.IRID
                                                    from i$SDD_MTI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_MCL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.TABLE_USAGE_REF_FROM in (select parent_tab.IRID
                                                    from i$SDD_MTI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_MCL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCL fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.TABLE_USAGE_REF_TO in (select parent_tab.IRID
                                                    from i$SDD_MTI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_MCL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.TABLE_USAGE_REF_TO in (select parent_tab.IRID
                                                    from i$SDD_MTI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_MODPGD
   where ivid in
   (select fktab.ivid
      from i$SDD_MODPGD fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.PROGRAM_DATUM_REF in (select parent_tab.IRID
                                                    from i$SDD_PGD parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_MODPGD
   where ivid in
   (select fktab.ivid
      from i$SDD_MODPGD fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.PROGRAM_DATUM_REF in (select parent_tab.IRID
                                                    from i$SDD_PGD parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_MCN
     set WINDOW_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCN fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.WINDOW_REF in (select parent_tab.IRID
                                                      from i$SDD_WIN parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_MCN
     set WINDOW_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCN fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.WINDOW_REF in (select parent_tab.IRID
                                                      from i$SDD_WIN parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 end if; --Primary instance
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
 if :old.parent_ivid is NOT NULL then 
  --Secondary instance
  delete i$SDD_MOD
   where ivid = :old.ivid;
 end if;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_MOD_d;
/
create or replace trigger SDD_MODBUN_br
  before insert or update or delete on i$SDD_MODBUN
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.MODULE_REF is not null)
       )
    or (updating and (
        (:new.MODULE_REF != :old.MODULE_REF
        or (:new.MODULE_REF is not null and :old.MODULE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select nvl(pac_ref, irid), nvl(parent_ivid, ivid)
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_MOD owning_tab
        where  owning_tab.IRID=:new.MODULE_REF
        and    jr_vn.context(nvl(owning_tab.parent_ivid, owning_tab.ivid)) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_MODBUN_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_MODBUN');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_MODBUN_br;
/
create or replace trigger SDD_MODBUN_inv
after insert or update of
  BUSINESS_UNIT_REF
 ,MODULE_REF
on i$SDD_MODBUN
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276429365679326686734037043257;
  this_type_irid  := :new.TYPES;
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_MODBUN_inv;
/
create or replace trigger SDD_MODBUN_val
after insert or update of
  BUSINESS_UNIT_REF
 ,MODULE_REF
on i$SDD_MODBUN
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276429365679326686734037043257;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_MODBUN(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_MODBUN) violated');
    end if;
    if not FK_MODBUN_TO_BUN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MODBUN_TO_BUN) violated - parent key not found');
    end if;
    if not FK_MODBUN_TO_MOD(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MODBUN_TO_MOD) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_MODBUN_val;
/
create or replace trigger SDD_MODBUN_d
  instead of delete on SDD_MODBUN for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_MODBUN el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_MODBUN
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_MODBUN_d;
/
create or replace trigger SDD_MODFUN_br
  before insert or update or delete on i$SDD_MODFUN
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.MODULE_REF is not null)
       )
    or (updating and (
        (:new.MODULE_REF != :old.MODULE_REF
        or (:new.MODULE_REF is not null and :old.MODULE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select nvl(pac_ref, irid), nvl(parent_ivid, ivid)
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_MOD owning_tab
        where  owning_tab.IRID=:new.MODULE_REF
        and    jr_vn.context(nvl(owning_tab.parent_ivid, owning_tab.ivid)) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_MODFUN_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_MODFUN');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_MODFUN_br;
/
create or replace trigger SDD_MODFUN_inv
after insert or update of
  FUNCTION_REF
 ,MODULE_REF
on i$SDD_MODFUN
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276429611242383795955588155449;
  this_type_irid  := :new.TYPES;
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_MODFUN_inv;
/
create or replace trigger SDD_MODFUN_val
after insert or update of
  FUNCTION_REF
 ,MODULE_REF
on i$SDD_MODFUN
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276429611242383795955588155449;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_MODFUN(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_MODFUN) violated');
    end if;
    if not FK_MODFUN_TO_FUN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MODFUN_TO_FUN) violated - parent key not found');
    end if;
    if not FK_MODFUN_TO_MOD(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MODFUN_TO_MOD) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_MODFUN_val;
/
create or replace trigger SDD_MODFUN_d
  instead of delete on SDD_MODFUN for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_MODFUN el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_MODFUN
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_MODFUN_d;
/
create or replace trigger SDD_MODMOD_br
  before insert or update or delete on i$SDD_MODMOD
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.PARENT_MODULE_REF is not null)
       )
    or (updating and (
        (:new.PARENT_MODULE_REF != :old.PARENT_MODULE_REF
        or (:new.PARENT_MODULE_REF is not null and :old.PARENT_MODULE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select nvl(pac_ref, irid), nvl(parent_ivid, ivid)
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_MOD owning_tab
        where  owning_tab.IRID=:new.PARENT_MODULE_REF
        and    jr_vn.context(nvl(owning_tab.parent_ivid, owning_tab.ivid)) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_MODMOD_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_MODMOD');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_MODMOD_br;
/
create or replace trigger SDD_MODMOD_inv
after insert or update of
  PARENT_MODULE_REF
 ,CHILD_MODULE_REF
on i$SDD_MODMOD
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276429856805440905177139267641;
  this_type_irid  := :new.TYPES;
  if updating then
    action := 'UPD';
    -- Check child objects when primary or unique key is changed
    -- Note, the called functions consider whether constraints are immediate or deferred
  end if;   -- updating
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_MODMOD_inv;
/
create or replace trigger SDD_MODMOD_val
after insert or update of
  PARENT_MODULE_REF
 ,CHILD_MODULE_REF
on i$SDD_MODMOD
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276429856805440905177139267641;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_MODMOD(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_MODMOD) violated');
    end if;
    if not FK_MODMOD_TO_MOD(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MODMOD_TO_MOD) violated - parent key not found');
    end if;
    if not FK_MODMOD_TO_MOD2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MODMOD_TO_MOD2) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_MODMOD_val;
/
create or replace trigger SDD_MODMOD_d
  instead of delete on SDD_MODMOD for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_MODMOD el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 delete SDD_ACI fktab
  where 
        fktab.MODULE_NETWORK_REF = :old.IRID
    ;
  delete SDD_PVL fktab
   where 
         fktab.MODULE_NETWORK_REF = :old.IRID
    ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_MODMOD
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_MODMOD_d;
/
create or replace trigger SDD_MODPGD_br
  before insert or update or delete on i$SDD_MODPGD
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.GENERAL_MODULE_REF is not null)
       )
    or (updating and (
        (:new.GENERAL_MODULE_REF != :old.GENERAL_MODULE_REF
        or (:new.GENERAL_MODULE_REF is not null and :old.GENERAL_MODULE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select nvl(pac_ref, irid), nvl(parent_ivid, ivid)
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_MOD owning_tab
        where  owning_tab.IRID=:new.GENERAL_MODULE_REF
        and    jr_vn.context(nvl(owning_tab.parent_ivid, owning_tab.ivid)) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_MODPGD_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.PLSQL_MODULE_REF is not null)
       )
    or (updating and (
        (:new.PLSQL_MODULE_REF != :old.PLSQL_MODULE_REF
        or (:new.PLSQL_MODULE_REF is not null and :old.PLSQL_MODULE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select nvl(pac_ref, irid), nvl(parent_ivid, ivid)
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_MOD owning_tab
        where  owning_tab.IRID=:new.PLSQL_MODULE_REF
        and    jr_vn.context(nvl(owning_tab.parent_ivid, owning_tab.ivid)) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_MODPGD_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_MODPGD');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_MODPGD_br;
/
create or replace trigger SDD_MODPGD_inv
after insert or update of
  GENERAL_MODULE_REF
 ,PROGRAM_DATUM_REF
 ,PLSQL_MODULE_REF
on i$SDD_MODPGD
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276430111813230980137980807225;
  this_type_irid  := :new.TYPES;
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_MODPGD_inv;
/
create or replace trigger SDD_MODPGD_val
after insert or update of
  GENERAL_MODULE_REF
 ,PROGRAM_DATUM_REF
 ,PLSQL_MODULE_REF
on i$SDD_MODPGD
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276430111813230980137980807225;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_MODPGD(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_MODPGD) violated');
    end if;
    if not FK_MODPGD_TO_GEM(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MODPGD_TO_GEM) violated - parent key not found');
    end if;
    if not FK_MODPGD_TO_PGD(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MODPGD_TO_PGD) violated - parent key not found');
    end if;
    if not FK_MODPGD_TO_PLM(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MODPGD_TO_PLM) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_MODPGD_val;
/
create or replace trigger SDD_MODPGD_d
  instead of delete on SDD_MODPGD for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_MODPGD el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_MODPGD
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_MODPGD_d;
/
create or replace trigger SDD_MPA_br
  before insert or update or delete on i$SDD_MPA
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.METHOD_REF is not null)
       )
    or (updating and (
        (:new.METHOD_REF != :old.METHOD_REF
        or (:new.METHOD_REF is not null and :old.METHOD_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select pac_ref, parent_ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_MET owning_tab
        where  owning_tab.IRID=:new.METHOD_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_MPA_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_MPA');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_MPA_br;
/
create or replace trigger SDD_MPA_inv
after insert or update of
  CLASSIFIER_REF
 ,COLLECT_CLASSIFIER_REF
on i$SDD_MPA
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276430409322319400925629270073;
  this_type_irid  := :new.TYPES;
  if updating then
    action := 'UPD';
    -- Check child objects when primary or unique key is changed
    -- Note, the called functions consider whether constraints are immediate or deferred
  end if;   -- updating
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_MPA_inv;
/
create or replace trigger SDD_MPA_val
after insert or update of
  CLASSIFIER_REF
 ,COLLECT_CLASSIFIER_REF
on i$SDD_MPA
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276430409322319400925629270073;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_MPA(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_MPA) violated');
    end if;
    if not FK_MPA_TO_CLA(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MPA_TO_CLA) violated - parent key not found');
    end if;
    if not FK_MPA_TO_CLA2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MPA_TO_CLA2) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_MPA_val;
/
create or replace trigger SDD_MPA_d
  instead of delete on SDD_MPA for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_MPA el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
  if not jr_wastebasket.force_flag 
   and jr_wastebasket.repos_constraints_enabled then
   if not FK_CMA_TO_MPA_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
 elsif jr_wastebasket.force_flag then 
  jr_wastebasket.set_secondary_delete;
  update SDD_CMA fktab
     set 
         fktab.METHOD_PARAMETER_REF = NULL
   where 
         fktab.METHOD_PARAMETER_REF = :old.IRID
  ;
 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_MPA
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_MPA_d;
/
create or replace trigger SDD_MTI_br
  before insert or update or delete on i$SDD_MTI
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.MODULE_UNIT_REF is not null)
       )
    or (updating and (
        (:new.MODULE_UNIT_REF != :old.MODULE_UNIT_REF
        or (:new.MODULE_UNIT_REF is not null and :old.MODULE_UNIT_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select nvl(pac_ref, irid), nvl(parent_ivid, ivid)
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_MUN owning_tab
        where  owning_tab.IRID=:new.MODULE_UNIT_REF
        and    jr_vn.context(nvl(owning_tab.parent_ivid, owning_tab.ivid)) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_MTI_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.SQL_QUERY_SET_REF is not null)
       )
    or (updating and (
        (:new.SQL_QUERY_SET_REF != :old.SQL_QUERY_SET_REF
        or (:new.SQL_QUERY_SET_REF is not null and :old.SQL_QUERY_SET_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select pac_ref, parent_ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_SQS owning_tab
        where  owning_tab.IRID=:new.SQL_QUERY_SET_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_MTI_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_MTI');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_MTI_br;
/
create or replace trigger SDD_MTI_inv
after insert or update of
  CONSTRAINT_REF
 ,CONSTRAINT_REF2
 ,TREEWALK_JOIN_CONSTRAINT
 ,MTI_REF
 ,MODULE_UNIT_REF
 ,TABLE_REF
on i$SDD_MTI
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276430593494612232841792604217;
  this_type_irid  := :new.TYPES;
  if updating then
    action := 'UPD';
    -- Check child objects when primary or unique key is changed
    -- Note, the called functions consider whether constraints are immediate or deferred
  end if;   -- updating
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_MTI_inv;
/
create or replace trigger SDD_MTI_val
after insert or update of
  CONSTRAINT_REF
 ,CONSTRAINT_REF2
 ,TREEWALK_JOIN_CONSTRAINT
 ,MTI_REF
 ,MODULE_UNIT_REF
 ,TABLE_REF
on i$SDD_MTI
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276430593494612232841792604217;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_MTI(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_MTI) violated');
    end if;
    if not FK_MTI_TO_JCO(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MTI_TO_JCO) violated - parent key not found');
    end if;
    if not FK_MTI_TO_JCO2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MTI_TO_JCO2) violated - parent key not found');
    end if;
    if not FK_MTI_TO_JCO3(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MTI_TO_JCO3) violated - parent key not found');
    end if;
    if not FK_MTI_TO_MTI(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MTI_TO_MTI) violated - parent key not found');
    end if;
    if not FK_MTI_TO_MUN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MTI_TO_MUN) violated - parent key not found');
    end if;
    if not FK_MTI_TO_TAB(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MTI_TO_TAB) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_MTI_val;
/
create or replace trigger SDD_MTI_d
  instead of delete on SDD_MTI for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_MTI el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
  if not jr_wastebasket.force_flag 
   and jr_wastebasket.repos_constraints_enabled then
   if not FK_MTI_TO_MTI_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
 elsif jr_wastebasket.force_flag then 
  jr_wastebasket.set_secondary_delete;
  --
  --  Bug 2070752 ineall 8-11-2001
  --  FK is not optional except for BASE mti so always delete MTIs that 
  --  reference this one.  Cascading should take care of ones that are
  --  conected to these.
  --
  delete from SDD_MTI fktab
  where  fktab.MTI_REF = :old.IRID
  ;
  /*
  update SDD_MTI fktab
     set 
         fktab.MTI_REF = NULL
   where 
         fktab.MTI_REF = :old.IRID
  ;
  */
 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 delete SDD_ITE fktab
  where 
        fktab.DETAIL_TABLE_USAGE_REF = :old.IRID
    ;
 delete SDD_MCL fktab
  where 
        fktab.TABLE_USAGE_REF_FROM = :old.IRID
    ;
 delete SDD_MCL fktab
  where 
        fktab.TABLE_USAGE_REF_TO = :old.IRID
    ;
  delete SDD_CNU fktab
   where 
         fktab.TABLE_USAGE_REF = :old.IRID
    ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_MTI
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_MTI_d;
/
create or replace trigger SDD_MUN_br
  before insert or update or delete on i$SDD_MUN
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.GENERAL_MODULE_REF is not null)
       )
    or (updating and (
        (:new.GENERAL_MODULE_REF != :old.GENERAL_MODULE_REF
        or (:new.GENERAL_MODULE_REF is not null and :old.GENERAL_MODULE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select nvl(pac_ref, irid), nvl(parent_ivid, ivid)
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_MOD owning_tab
        where  owning_tab.IRID=:new.GENERAL_MODULE_REF
        and    jr_vn.context(nvl(owning_tab.parent_ivid, owning_tab.ivid)) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_MUN_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.MODULE_COMPONENT_REF is not null)
       )
    or (updating and (
        (:new.MODULE_COMPONENT_REF != :old.MODULE_COMPONENT_REF
        or (:new.MODULE_COMPONENT_REF is not null and :old.MODULE_COMPONENT_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select nvl(pac_ref, irid), nvl(parent_ivid, ivid)
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_MUN owning_tab
        where  owning_tab.IRID=:new.MODULE_COMPONENT_REF
        and    jr_vn.context(nvl(owning_tab.parent_ivid, owning_tab.ivid)) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_MUN_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_MUN');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_MUN_br;
/
create or replace trigger SDD_MUN_ar
  after insert or update or delete on i$SDD_MUN
  for each row 
begin
  -- Inserting
  if inserting then
    jr_object_version.ins ( :new.irid, :new.ivid
    , name => :new.NAME
    , type_irid => :new.TYPES
    , table_irid => 384781276430985451030311022345340985
    , parent_ivid => :new.parent_ivid
    );
  end if;  -- inserting
  -- Updating
  if updating then
    jr_object_version.upd ( :old.ivid
      , parent_ivid => :old.parent_ivid
      , name => :new.NAME
    );
  end if;  -- updating
  -- Deleting
  if deleting then
    jr_object_version.del ( :old.irid, :old.ivid, 'SDD_MUN'
      , :old.parent_ivid  -- optional primary object instance
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_MUN_ar;
/
create or replace trigger SDD_MUN_inv
after insert or update of
  GENERAL_MODULE_REF
 ,LANGUAGE_REF
 ,MODULE_COMPONENT_REF
on i$SDD_MUN
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276430985451030311022345340985;
  this_type_irid  := :new.TYPES;
  if updating then
    action := 'UPD';
    -- Check child objects when primary or unique key is changed
    -- Note, the called functions consider whether constraints are immediate or deferred
  end if;   -- updating
  if updating then
    action := 'UPD';
    -- If PK updateable, check all owned objects
  end if; -- updating
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_MUN_inv;
/
create or replace trigger SDD_MUN_val
after insert or update of
  GENERAL_MODULE_REF
 ,LANGUAGE_REF
 ,MODULE_COMPONENT_REF
on i$SDD_MUN
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276430985451030311022345340985;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_MUN(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_MUN) violated');
    end if;
    if not FK_MUN_TO_GEM(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MUN_TO_GEM) violated - parent key not found');
    end if;
    if not FK_MUN_TO_LAN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MUN_TO_LAN) violated - parent key not found');
    end if;
    if not FK_MUN_TO_MCO(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_MUN_TO_MCO) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_MUN_val;
/
CREATE OR REPLACE TRIGGER SDD_MUN_d
  instead of delete on SDD_MUN for each row
declare
 secondary boolean:=jr_wastebasket.secondary_delete;
 delete_ok boolean:=TRUE;
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_MUN el
  where el.irid=:old.irid
    and ov.ivid=NVL(el.parent_ivid, el.ivid)
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
 if :old.parent_ivid is null then
  -- Primary instance
  jr_wastebasket.remove(:old.ivid);
  if jr_context.workarea is NULL and not only_version then
   return;
  end if;
 else
  -- Secondary instance
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 end if;
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
  if not jr_wastebasket.force_flag
   and jr_wastebasket.repos_constraints_enabled then
--Bug 995057 - MCN_TO_SUB blocking for re-usable MCOs is handled by CDAPI
--             at the trigger level, we now cascade the delete.      
--   if not FK_MCN_TO_SUB_d (
--        :old.ivid
--      , :old.IRID
--      , :old.TYPES
--      , 'DEL'
--      ) then
--     delete_ok:=FALSE;
--   end if;

   -- bug fix 2078916 - BLOCK DELETE IF USER EXTENDED ASSOCIATION EXISTS
   if not jr_ues_chk.check_ues_blocks_delete (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
 elsif jr_wastebasket.force_flag then
  jr_wastebasket.set_secondary_delete;
--  delete SDD_MCN fktab
--   where
--         fktab.SUBCOMPONENT_REF = :old.IRID
--    ;

  -- bug fix 2078916 - FORCE DELETE IF USER EXTENDED ASSOCIATION EXISTS
  delete SDD_UES fktab
  where fktab.USE_OF_REF = :old.IRID;

 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 delete SDD_LVI fktab
  where
        fktab.LIST_OF_VALUES_REF = :old.IRID
    ;
 delete SDD_MCN fktab
  where
        fktab.MODULE_COMPONENT_REF = :old.IRID
    ;
 --Bug 995057 - triggers now cascade delete MCNs for SUBCOMPONENTS
 delete SDD_MCN fktab
  where
         fktab.SUBCOMPONENT_REF = :old.IRID
	;
 --Secondary instance
 if :old.parent_ivid is not null then
  delete SDD_IGR fktab
   where
         fktab.MODULE_COMPONENT_REF = :old.IRID
    ;
  delete SDD_IGR fktab
   where
         fktab.SUBCOMPONENT_REF = :old.IRID
    ;
  delete SDD_ITE fktab
   where
         fktab.MODULE_UNIT_REF = :old.IRID
    ;
  delete SDD_MTI fktab
   where
         fktab.MODULE_UNIT_REF = :old.IRID
    ;
  delete SDD_MUN fktab
   where
         fktab.MODULE_COMPONENT_REF = :old.IRID
    ;
  delete SDD_SQS fktab
   where
         fktab.LIST_OF_VALUES_REF = :old.IRID
    ;
  delete SDD_SQS fktab
   where
         fktab.MODULE_COMPONENT_REF = :old.IRID
    ;
 end if; --Secondary instance
 if :old.parent_ivid is null then
  -- Primary instance
  if (NOT jr_wastebasket.force_flag) and jr_wastebasket.repos_constraints_enabled then
   if not FK_MTI_TO_MTI_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
--Bug 995057 - MCN_TO_SUB blocking for re-usable MCOs is handled by CDAPI
--             at the trigger level, we now cascade the delete.   
--   if not FK_MCN_TO_SUB_cmd (:old.irid,:old.ivid) then
--    delete_ok:=FALSE;
--   end if;
  elsif jr_wastebasket.force_flag then
  update SDD_MTI fktab
     set
         fktab.MTI_REF = NULL
   where fktab.MTI_REF in (select parent_tab.IRID
                                                    from i$SDD_MTI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
--  delete SDD_MCN fktab
--   where fktab.SUBCOMPONENT_REF in (select parent_tab.IRID
--                                                      from i$SDD_MUN parent_tab
--                                                     where parent_tab.parent_ivid=:old.ivid)
--  ;
  end if;--force delete/purge
 if jr_context.workarea is not null then
  update SDD_IGR
     set ITEM_GROUP_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_IGR fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.ITEM_GROUP_REF in (select parent_tab.IRID
                                                      from i$SDD_IGR parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_IGR
     set ITEM_GROUP_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_IGR fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.ITEM_GROUP_REF in (select parent_tab.IRID
                                                      from i$SDD_IGR parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_ITE
     set ITEM_GROUP_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_ITE fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.ITEM_GROUP_REF in (select parent_tab.IRID
                                                      from i$SDD_IGR parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_ITE
     set ITEM_GROUP_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_ITE fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.ITEM_GROUP_REF in (select parent_tab.IRID
                                                      from i$SDD_IGR parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_ARGITE
   where ivid in
   (select fktab.ivid
      from i$SDD_ARGITE fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.ITEM_REF in (select parent_tab.IRID
                                                    from i$SDD_ITE parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_ARGITE
   where ivid in
   (select fktab.ivid
      from i$SDD_ARGITE fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.ITEM_REF in (select parent_tab.IRID
                                                    from i$SDD_ITE parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_LVI
     set ITEM_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_LVI fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.ITEM_REF in (select parent_tab.IRID
                                                      from i$SDD_ITE parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_LVI
     set ITEM_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_LVI fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.ITEM_REF in (select parent_tab.IRID
                                                      from i$SDD_ITE parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_PVL
     set ITEM_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_PVL fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.ITEM_REF in (select parent_tab.IRID
                                                      from i$SDD_ITE parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_PVL
     set ITEM_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_PVL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.ITEM_REF in (select parent_tab.IRID
                                                      from i$SDD_ITE parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_ITE
   where ivid in
   (select fktab.ivid
      from i$SDD_ITE fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.DETAIL_TABLE_USAGE_REF in (select parent_tab.IRID
                                                    from i$SDD_MTI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_ITE
   where ivid in
   (select fktab.ivid
      from i$SDD_ITE fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.DETAIL_TABLE_USAGE_REF in (select parent_tab.IRID
                                                    from i$SDD_MTI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_MCL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCL fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.TABLE_USAGE_REF_FROM in (select parent_tab.IRID
                                                    from i$SDD_MTI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_MCL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.TABLE_USAGE_REF_FROM in (select parent_tab.IRID
                                                    from i$SDD_MTI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_MCL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCL fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.TABLE_USAGE_REF_TO in (select parent_tab.IRID
                                                    from i$SDD_MTI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_MCL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.TABLE_USAGE_REF_TO in (select parent_tab.IRID
                                                    from i$SDD_MTI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_LVI
   where ivid in
   (select fktab.ivid
      from i$SDD_LVI fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.LIST_OF_VALUES_REF in (select parent_tab.IRID
                                                    from i$SDD_MUN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_LVI
   where ivid in
   (select fktab.ivid
      from i$SDD_LVI fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.LIST_OF_VALUES_REF in (select parent_tab.IRID
                                                    from i$SDD_MUN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_MCN
   where ivid in
   (select fktab.ivid
      from i$SDD_MCN fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.MODULE_COMPONENT_REF in (select parent_tab.IRID
                                                    from i$SDD_MUN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_MCN
   where ivid in
   (select fktab.ivid
      from i$SDD_MCN fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.MODULE_COMPONENT_REF in (select parent_tab.IRID
                                                    from i$SDD_MUN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 --Bug 995057 - Now cascade delete of MCNs for SUBCOMPONENTS
 if jr_context.workarea is not null then
  delete SDD_MCN
   where ivid in
   (select fktab.ivid
      from i$SDD_MCN fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.SUBCOMPONENT_REF in (select parent_tab.IRID
                                                    from i$SDD_MUN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_MCN
   where ivid in
   (select fktab.ivid
      from i$SDD_MCN fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.SUBCOMPONENT_REF in (select parent_tab.IRID
                                                    from i$SDD_MUN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 end if; --Primary instance
 if not delete_ok then
  RAISE jr_wastebasket.delete_error;
 end if;
 if :old.parent_ivid is NOT NULL then
  --Secondary instance
  delete i$SDD_MUN
   where ivid = :old.ivid;
 end if;
 if not secondary then
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if;
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception
 when others then
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE;
end SDD_MUN_d;
/
create or replace trigger SDD_MWF_br
  before insert or update or delete on i$SDD_MWF
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.LANGUAGE_REF is not null)
       )
    or (updating and (
        (:new.LANGUAGE_REF != :old.LANGUAGE_REF
        or (:new.LANGUAGE_REF is not null and :old.LANGUAGE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_LAN owning_tab
        where  owning_tab.IRID=:new.LANGUAGE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_MWF_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_MWF');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_MWF_br;
/
create or replace trigger SDD_MWF_inv
after insert
on i$SDD_MWF
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276431344350883009115381581881;
  this_type_irid  := :new.TYPES;
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_MWF_inv;
/
create or replace trigger SDD_MWF_val
after insert
on i$SDD_MWF
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276431344350883009115381581881;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_MWF(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_MWF) violated');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_MWF_val;
/
create or replace trigger SDD_MWF_d
  instead of delete on SDD_MWF for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_MWF el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_MWF
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_MWF_d;
/
create or replace trigger SDD_OCL_br
  before insert or update or delete on i$SDD_OCL
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_OCL_br;
/
create or replace trigger SDD_OCL_ar
  after insert or update or delete on i$SDD_OCL
  for each row 
begin
  -- Inserting
  if inserting then
    jr_object_version.ins ( :new.irid, :new.ivid
    , name => :new.NAME
    , type_irid => :new.TYPES
    , table_irid => 384781276431594636306601206577907769
    );
  end if;  -- inserting
  -- Updating
  if updating then
    jr_object_version.upd ( :old.ivid
      , name => :new.NAME
    );
  end if;  -- updating
  -- Deleting
  if deleting then
    jr_object_version.del ( :old.irid, :old.ivid, 'SDD_OCL'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_OCL_ar;
/
create or replace trigger SDD_OCL_inv
after insert
on i$SDD_OCL
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276431594636306601206577907769;
  this_type_irid  := :new.TYPES;
  if updating then
    action := 'UPD';
    -- Check child objects when primary or unique key is changed
    -- Note, the called functions consider whether constraints are immediate or deferred
  end if;   -- updating
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_OCL_inv;
/
create or replace trigger SDD_OCL_val
after insert
on i$SDD_OCL
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276431594636306601206577907769;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_OCL(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_OCL) violated');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_OCL_val;
/
create or replace trigger SDD_OCL_d
  instead of delete on SDD_OCL for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
  where ov.irid=:old.irid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  jr_wastebasket.remove(:old.ivid);
  if jr_context.workarea is NULL and not only_version then
   return;
  end if;
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
  if not jr_wastebasket.force_flag 
   and jr_wastebasket.repos_constraints_enabled then
   -- bug fix 2078916 - BLOCK DELETE IF USER EXTENDED ASSOCIATION EXISTS
   if not jr_ues_chk.check_ues_blocks_delete (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_TAB_TO_OCL_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
 elsif jr_wastebasket.force_flag then 
  jr_wastebasket.set_secondary_delete;
  update SDD_TAB fktab
     set 
         fktab.CLUSTER_REF = NULL
   where 
         fktab.CLUSTER_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
  ;
  delete SDD_TAB fktab
   where 
         fktab.CLUSTER_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state='I')
  ;

  -- bug fix 2078916 - FORCE DELETE IF USER EXTENDED ASSOCIATION EXISTS
  delete SDD_UES fktab
  where fktab.USE_OF_REF = :old.IRID;

 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 delete SDD_DOI fktab
  where 
        fktab.CLUSTER_REF = :old.IRID
    ;
 if jr_context.workarea is not null then
  update SDD_COL
     set CLUSTER_COLUMN_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_COL fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.CLUSTER_COLUMN_REF in (select parent_tab.IRID
                                                      from i$SDD_CCD parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_COL
     set CLUSTER_COLUMN_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_COL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.CLUSTER_COLUMN_REF in (select parent_tab.IRID
                                                      from i$SDD_CCD parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_CQA
     set CLUSTER_COLUMN_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_CQA fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.CLUSTER_COLUMN_REF in (select parent_tab.IRID
                                                      from i$SDD_CCD parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_CQA
     set CLUSTER_COLUMN_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_CQA fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.CLUSTER_COLUMN_REF in (select parent_tab.IRID
                                                      from i$SDD_CCD parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_INS
   where ivid in
   (select fktab.ivid
      from i$SDD_INS fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.INDEX_REF in (select parent_tab.IRID
                                                    from i$SDD_IND parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_INS
   where ivid in
   (select fktab.ivid
      from i$SDD_INS fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.INDEX_REF in (select parent_tab.IRID
                                                    from i$SDD_IND parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_OCL_d;
/
create or replace trigger SDD_OCO_br
  before insert or update or delete on i$SDD_OCO
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.TABLE_REF is not null)
       )
    or (updating and (
        (:new.TABLE_REF != :old.TABLE_REF
        or (:new.TABLE_REF is not null and :old.TABLE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_TAB owning_tab
        where  owning_tab.IRID=:new.TABLE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_OCO_OWNER) violated - parent key not found');
      end;
    end if;
  else
    :new.pac_ref     := -1;
    :new.parent_ivid := -1;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_OCO');
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
    jr_secondary_object.pre_insert(:new.irid, :new.ivid, :new.parent_ivid);
  end if;  -- inserting
  if updating then
    jr_secondary_object.pre_update(:new.irid, :new.ivid, :new.parent_ivid);
  end if; -- updating
  if deleting then
    jr_secondary_object.pre_delete(:old.irid, :old.ivid, :old.parent_ivid);
  end if;  -- deleting
end SDD_OCO_br;
/
create or replace trigger SDD_OCO_inv
after insert or update of
  PRIMARY_KEY_REF
 ,RELATIONSHIP_END_REF
 ,FOREIGN_TABLE_REF
 ,UNIQUE_KEY_REF
 ,UNIQUE_IDENTIFIER_REF
on i$SDD_OCO
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276431821309897778949548165177;
  this_type_irid  := :new.TYPES;
  if updating then
    action := 'UPD';
    -- Check child objects when primary or unique key is changed
    -- Note, the called functions consider whether constraints are immediate or deferred
  end if;   -- updating
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_OCO_inv;
/
create or replace trigger SDD_OCO_val
after insert or update of
  PRIMARY_KEY_REF
 ,RELATIONSHIP_END_REF
 ,FOREIGN_TABLE_REF
 ,UNIQUE_KEY_REF
 ,UNIQUE_IDENTIFIER_REF
on i$SDD_OCO
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276431821309897778949548165177;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_OCO(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_OCO) violated');
    end if;
    if not FK_OCO_TO_PCO(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_OCO_TO_PCO) violated - parent key not found');
    end if;
    if not FK_OCO_TO_RELEND(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_OCO_TO_RELEND) violated - parent key not found');
    end if;
    if not FK_OCO_TO_TAB2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_OCO_TO_TAB2) violated - parent key not found');
    end if;
    if not FK_OCO_TO_UCO(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_OCO_TO_UCO) violated - parent key not found');
    end if;
    if not FK_OCO_TO_UID(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_OCO_TO_UID) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_OCO_val;
/
create or replace trigger SDD_OCO_d
  instead of delete on SDD_OCO for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
       ,I$SDD_OCO el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
  if not jr_wastebasket.force_flag 
   and jr_wastebasket.repos_constraints_enabled then
   if not FK_MCL_TO_JCO_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_MCL_TO_PCO_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_MTI_TO_JCO_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
 elsif jr_wastebasket.force_flag then 
  jr_wastebasket.set_secondary_delete;
  delete SDD_MCL fktab
   where 
         fktab.JOIN_CONSTRAINT_REF = :old.IRID
    ;
  delete SDD_MCL fktab
   where 
         fktab.PRIMARY_KEY_REF = :old.IRID
    ;
  update SDD_MTI fktab
     set 
         fktab.CONSTRAINT_REF = NULL
   where 
         fktab.CONSTRAINT_REF = :old.IRID
  ;
 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 delete SDD_CNU fktab
  where 
        fktab.CONSTRAINT_REF = :old.IRID
    ;
 delete SDD_INS fktab
  where 
        fktab.PRIMARY_KEY_REF = :old.IRID
    ;
 delete SDD_INS fktab
  where 
        fktab.UNIQUE_KEY_REF = :old.IRID
    ;
  delete SDD_OKY fktab
   where 
         fktab.CONSTRAINT_REF = :old.IRID
    ;
 update SDD_COL fktab
    set 
        fktab.CONSTRAINT_DENORMALISED_VIA = NULL
  where 
        fktab.CONSTRAINT_DENORMALISED_VIA = :old.IRID
 ;
 update SDD_IND fktab
    set 
        fktab.FOREIGN_KEY_REF = NULL
  where 
        fktab.FOREIGN_KEY_REF = :old.IRID
 ;
 update SDD_MTI fktab
    set 
        fktab.CONSTRAINT_REF2 = NULL
  where 
        fktab.CONSTRAINT_REF2 = :old.IRID
 ;
 update SDD_MTI fktab
    set 
        fktab.TREEWALK_JOIN_CONSTRAINT = NULL
  where 
        fktab.TREEWALK_JOIN_CONSTRAINT = :old.IRID
 ;
 update SDD_OCO fktab
    set 
        fktab.PRIMARY_KEY_REF = NULL
  where 
        fktab.PRIMARY_KEY_REF = :old.IRID
 ;
 update SDD_OCO fktab
    set 
        fktab.UNIQUE_KEY_REF = NULL
  where 
        fktab.UNIQUE_KEY_REF = :old.IRID
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_OCO
   where ivid = :old.ivid;
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_OCO_d;
/
create or replace trigger SDD_ODB_br
  before insert or update or delete on i$SDD_ODB
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_ODB_br;
/
create or replace trigger SDD_ODB_ar
  after insert or update or delete on i$SDD_ODB
  for each row 
begin
  -- Inserting
  if inserting then
    jr_object_version.ins ( :new.irid, :new.ivid
    , name => :new.NAME
    , type_irid => :new.TYPES
    , table_irid => 384781276432222711048822869391329337
    );
  end if;  -- inserting
  -- Updating
  if updating then
    jr_object_version.upd ( :old.ivid
      , name => :new.NAME
    );
  end if;  -- updating
  -- Deleting
  if deleting then
    jr_object_version.del ( :old.irid, :old.ivid, 'SDD_ODB'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_ODB_ar;
/
create or replace trigger SDD_ODB_inv
after insert or update of
  NODE_REF
on i$SDD_ODB
for each row
declare
  this_table_irid number;
  this_type_irid  number;
  action          varchar2(3);
begin
  if not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276432222711048822869391329337;
  this_type_irid  := :new.TYPES;
  if updating then
    action := 'UPD';
    -- Check child objects when primary or unique key is changed
    -- Note, the called functions consider whether constraints are immediate or deferred
  end if;   -- updating
  insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
  values (:new.irid, :new.ivid, this_table_irid, this_type_irid);
end SDD_ODB_inv;
/
create or replace trigger SDD_ODB_val
after insert or update of
  NODE_REF
on i$SDD_ODB
declare
  this_table_irid number;
  action          varchar2(3);
  cursor inv_cur (table_irid number) is
    select io.object_irid, io.object_ivid, io.type_irid
    from   i$sdd_invalid_objects io
    where  io.table_irid = inv_cur.table_irid;
begin
  if jr_context.constraints = jr_context.CONSTRAINTS_DEFERRED
    or not jr_context.constraints_enabled then return; end if;
  this_table_irid := 384781276432222711048822869391329337;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_ODB(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_ODB) violated');
    end if;
    if not FK_ODB_TO_E20(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ODB_TO_E20) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_ODB_val;
/
create or replace trigger SDD_ODB_d
  instead of delete on SDD_ODB for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
  where ov.irid=:old.irid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  jr_wastebasket.remove(:old.ivid);
  if jr_context.workarea is NULL and not only_version then
   return;
  end if;
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 if (NOT jr_wastebasket.force_flag) and jr_wastebasket.repos_constraints_enabled then
   -- bug fix 2078916 - BLOCK DELETE IF USER EXTENDED ASSOCIATION EXISTS
   if not jr_ues_chk.check_ues_blocks_delete (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
 elsif jr_wastebasket.force_flag then 
  jr_wastebasket.set_secondary_delete;

  -- bug fix 2078916 - FORCE DELETE IF USER EXTENDED ASSOCIATION EXISTS
  delete SDD_UES fktab
  where fktab.USE_OF_REF = :old.IRID;

 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 delete SDD_COMODB fktab
  where 
        fktab.ORACLE_DATABASE_REF = :old.IRID
    ;
 delete SDD_ODBODB fktab
  where 
        fktab.DATABASE_REF_TO = :old.IRID
    ;
 delete SDD_RGP fktab
  where 
        fktab.ORACLE_DATABASE_REF = :old.IRID
    ;
  if (NOT jr_wastebasket.force_flag) and jr_wastebasket.repos_constraints_enabled then
   if not FK_CST_TO_LST_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_DBU_TO_OTB_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_DBU_TO_OTB2_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_DOI_TO_OTB_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_DOI_TO_OTB2_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_DOI_TO_OTB3_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_INS_TO_OTB_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_ORS_TO_OTB_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_TBP_TO_OTB_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_TSQ_TO_OTB_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not jr_ues_chk.FK_UES_TO_DBU_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not jr_ues_chk.FK_UES_TO_GRP_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not jr_ues_chk.FK_UES_TO_ORS_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not jr_ues_chk.FK_UES_TO_OTB_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not jr_ues_chk.FK_UES_TO_DFI_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
  elsif jr_wastebasket.force_flag then
  jr_wastebasket.set_secondary_delete;
  delete SDD_CST fktab
   where fktab.LOB_STORAGE_REF in (select parent_tab.IRID
                                                      from i$SDD_LST parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
  ;
  delete SDD_TSQ fktab
   where fktab.TABLESPACE_REF in (select parent_tab.IRID
                                                      from i$SDD_OTB parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_DBU fktab
     set 
         fktab.DEFAULT_TABLESPACE_REF = NULL
   where fktab.DEFAULT_TABLESPACE_REF in (select parent_tab.IRID
                                                    from i$SDD_OTB parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_DBU fktab
     set 
         fktab.TEMP_TABLESPACE_REF = NULL
   where fktab.TEMP_TABLESPACE_REF in (select parent_tab.IRID
                                                    from i$SDD_OTB parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_DOI fktab
     set 
         fktab.TABLESPACE_REF = NULL
   where fktab.TABLESPACE_REF in (select parent_tab.IRID
                                                    from i$SDD_OTB parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_DOI fktab
     set 
         fktab.OVERFLOW_TABLESPACE_REF = NULL
   where fktab.OVERFLOW_TABLESPACE_REF in (select parent_tab.IRID
                                                    from i$SDD_OTB parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_DOI fktab
     set 
         fktab.SNAP_LOG_TABLESPACE_REF = NULL
   where fktab.SNAP_LOG_TABLESPACE_REF in (select parent_tab.IRID
                                                    from i$SDD_OTB parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_INS fktab
     set 
         fktab.TABLESPACE_REF = NULL
   where fktab.TABLESPACE_REF in (select parent_tab.IRID
                                                    from i$SDD_OTB parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_ORS fktab
     set 
         fktab.TABLESPACE_REF = NULL
   where fktab.TABLESPACE_REF in (select parent_tab.IRID
                                                    from i$SDD_OTB parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_TBP fktab
     set 
         fktab.TABLESPACE_REF = NULL
   where fktab.TABLESPACE_REF in (select parent_tab.IRID
                                                    from i$SDD_OTB parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;

  -- bug fix 2078916 - FORCE DELETE IF USER EXTENDED ASSOCIATION EXISTS TO ANY DATABASE USERS
  delete SDD_UES fktab
  where fktab.USE_OF_REF in (select parent_tab.IRID
                             from i$SDD_DBU parent_tab
                             where parent_tab.parent_ivid=:old.ivid)
  ;

  -- bug fix 2078916 - FORCE DELETE IF USER EXTENDED ASSOCIATION EXISTS TO ANY ROLES
  delete SDD_UES fktab
  where fktab.USE_OF_REF in (select parent_tab.IRID
                             from i$SDD_GRP parent_tab
                             where parent_tab.parent_ivid=:old.ivid)
  ;
  -- bug fix 2078916 - FORCE DELETE IF USER EXTENDED ASSOCIATION EXISTS TO ANY ROLLBACK SEGMENTS
  delete SDD_UES fktab
  where fktab.USE_OF_REF in (select parent_tab.IRID
                             from i$SDD_ORS parent_tab
                             where parent_tab.parent_ivid=:old.ivid)
  ;
  -- bug fix 2078916 - FORCE DELETE IF USER EXTENDED ASSOCIATION EXISTS TO ANY TABLESPACES   
  delete SDD_UES fktab
  where fktab.USE_OF_REF in (select parent_tab.IRID
                             from i$SDD_OTB parent_tab
                             where parent_tab.parent_ivid=:old.ivid)
  ;
  -- bug fix 2078916 - FORCE DELETE IF USER EXTENDED ASSOCIATION EXISTS TO ANY DATABASE FILES
  delete SDD_UES fktab
  where fktab.USE_OF_REF in (select parent_tab.IRID
                             from i$SDD_DFI parent_tab
                             where parent_tab.parent_ivid=:old.ivid)
  ;
 end if;--Constraints enabled/force
 if jr_context.workarea is not null then
  delete SDD_BRL
   where ivid in
   (select fktab.ivid
      from i$SDD_BRL fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.DATABASE_USER_REF in (select parent_tab.IRID
                                                    from i$SDD_DBU parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_BRL
   where ivid in
   (select fktab.ivid
      from i$SDD_BRL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.DATABASE_USER_REF in (select parent_tab.IRID
                                                    from i$SDD_DBU parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_BLI
     set DATABASE_USER_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_BLI fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.DATABASE_USER_REF in (select parent_tab.IRID
                                                      from i$SDD_DBU parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_BLI
     set DATABASE_USER_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_BLI fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.DATABASE_USER_REF in (select parent_tab.IRID
                                                      from i$SDD_DBU parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_DOI
     set DATABASE_USER_REF2 = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_DOI fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.DATABASE_USER_REF2 in (select parent_tab.IRID
                                                      from i$SDD_DBU parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_DOI
     set DATABASE_USER_REF2 = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_DOI fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.DATABASE_USER_REF2 in (select parent_tab.IRID
                                                      from i$SDD_DBU parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_DOI
     set ORACLE_TYPE_DBU_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_DOI fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.ORACLE_TYPE_DBU_REF in (select parent_tab.IRID
                                                      from i$SDD_DBU parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_DOI
     set ORACLE_TYPE_DBU_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_DOI fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.ORACLE_TYPE_DBU_REF in (select parent_tab.IRID
                                                      from i$SDD_DBU parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_QUI
     set QUEUE_TABLE_DBU_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_QUI fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.QUEUE_TABLE_DBU_REF in (select parent_tab.IRID
                                                      from i$SDD_DBU parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_QUI
     set QUEUE_TABLE_DBU_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_QUI fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.QUEUE_TABLE_DBU_REF in (select parent_tab.IRID
                                                      from i$SDD_DBU parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_DOG
   where ivid in
   (select fktab.ivid
      from i$SDD_DOG fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.JMI_REF in (select parent_tab.IRID
                                                    from i$SDD_DOI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_DOG
   where ivid in
   (select fktab.ivid
      from i$SDD_DOG fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.JMI_REF in (select parent_tab.IRID
                                                    from i$SDD_DOI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_DOG
   where ivid in
   (select fktab.ivid
      from i$SDD_DOG fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.PLSQL_MODULE_REF in (select parent_tab.IRID
                                                    from i$SDD_DOI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_DOG
   where ivid in
   (select fktab.ivid
      from i$SDD_DOG fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.PLSQL_MODULE_REF in (select parent_tab.IRID
                                                    from i$SDD_DOI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_DOG
   where ivid in
   (select fktab.ivid
      from i$SDD_DOG fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.SNAPSHOT_REF in (select parent_tab.IRID
                                                    from i$SDD_DOI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_DOG
   where ivid in
   (select fktab.ivid
      from i$SDD_DOG fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.SNAPSHOT_REF in (select parent_tab.IRID
                                                    from i$SDD_DOI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_DOG
   where ivid in
   (select fktab.ivid
      from i$SDD_DOG fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.SEQUENCE_REF in (select parent_tab.IRID
                                                    from i$SDD_DOI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_DOG
   where ivid in
   (select fktab.ivid
      from i$SDD_DOG fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.SEQUENCE_REF in (select parent_tab.IRID
                                                    from i$SDD_DOI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_DOG
   where ivid in
   (select fktab.ivid
      from i$SDD_DOG fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.TABLE_REF in (select parent_tab.IRID
                                                    from i$SDD_DOI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_DOG
   where ivid in
   (select fktab.ivid
      from i$SDD_DOG fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.TABLE_REF in (select parent_tab.IRID
                                                    from i$SDD_DOI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_DOG
   where ivid in
   (select fktab.ivid
      from i$SDD_DOG fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.VIEW_REF in (select parent_tab.IRID
                                                    from i$SDD_DOI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_DOG
   where ivid in
   (select fktab.ivid
      from i$SDD_DOG fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.VIEW_REF in (select parent_tab.IRID
                                                    from i$SDD_DOI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_INP
   where ivid in
   (select fktab.ivid
      from i$SDD_INP fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.TABLE_PARTITION_REF in (select parent_tab.IRID
                                                    from i$SDD_TBP parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_INP
   where ivid in
   (select fktab.ivid
      from i$SDD_INP fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.TABLE_PARTITION_REF in (select parent_tab.IRID
                                                    from i$SDD_TBP parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_DOG
   where ivid in
   (select fktab.ivid
      from i$SDD_DOG fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.DIRECTORY_REF in (select parent_tab.IRID
                                                    from i$SDD_DIR parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_DOG
   where ivid in
   (select fktab.ivid
      from i$SDD_DOG fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.DIRECTORY_REF in (select parent_tab.IRID
                                                    from i$SDD_DIR parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_DOI
     set DIRECTORY_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_DOI fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.DIRECTORY_REF in (select parent_tab.IRID
                                                      from i$SDD_DIR parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_DOI
     set DIRECTORY_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_DOI fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.DIRECTORY_REF in (select parent_tab.IRID
                                                      from i$SDD_DIR parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_DBU
     set DATABASE_PROFILE_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_DBU fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.DATABASE_PROFILE_REF in (select parent_tab.IRID
                                                      from i$SDD_DPR parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_DBU
     set DATABASE_PROFILE_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_DBU fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.DATABASE_PROFILE_REF in (select parent_tab.IRID
                                                      from i$SDD_DPR parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_DBUGRP
   where ivid in
   (select fktab.ivid
      from i$SDD_DBUGRP fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.ROLE_REF in (select parent_tab.IRID
                                                    from i$SDD_GRP parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_DBUGRP
   where ivid in
   (select fktab.ivid
      from i$SDD_DBUGRP fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.ROLE_REF in (select parent_tab.IRID
                                                    from i$SDD_GRP parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_GRPGRP
   where ivid in
   (select fktab.ivid
      from i$SDD_GRPGRP fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.GRANTOR_ROLE_REF in (select parent_tab.IRID
                                                    from i$SDD_GRP parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_GRPGRP
   where ivid in
   (select fktab.ivid
      from i$SDD_GRPGRP fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.GRANTOR_ROLE_REF in (select parent_tab.IRID
                                                    from i$SDD_GRP parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_SRG
     set ROLLBACK_SEGMENT_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_SRG fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.ROLLBACK_SEGMENT_REF in (select parent_tab.IRID
                                                      from i$SDD_ORS parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_SRG
     set ROLLBACK_SEGMENT_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_SRG fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.ROLLBACK_SEGMENT_REF in (select parent_tab.IRID
                                                      from i$SDD_ORS parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_CST
     set TABLESPACE_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_CST fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.TABLESPACE_REF in (select parent_tab.IRID
                                                      from i$SDD_OTB parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_CST
     set TABLESPACE_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_CST fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.TABLESPACE_REF in (select parent_tab.IRID
                                                      from i$SDD_OTB parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
