create or replace trigger CK_APPLICATION_LOGIC_inv
after insert or update of
  AL_ID
on i$CK_APPLICATION_LOGIC
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 := 384781276379417209037374496611780665;
  this_type_irid  := 384781276385372113172273119226251321;
  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 CK_APPLICATION_LOGIC_inv;
/
create or replace trigger CK_APPLICATION_LOGIC_val
after insert or update of
  AL_ID
on i$CK_APPLICATION_LOGIC
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 := 384781276379417209037374496611780665;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not CK_APPLICATION_LOGIC_PK(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (CK_APPLICATION_LOGIC_PK) 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 CK_APPLICATION_LOGIC_val;
/
create or replace trigger CK_APPLICATION_LOGIC_d
  instead of delete on CK_APPLICATION_LOGIC 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$CK_APPLICATION_LOGIC 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(NULL, 384781276385372113172273119226251321, :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$CK_APPLICATION_LOGIC
   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(null, 384781276385372113172273119226251321);
  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 CK_APPLICATION_LOGIC_d;
/
create or replace trigger RM_TEXT_LINES_d
  instead of delete on RM_TEXT_LINES 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$RM_TEXT_LINES 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(NULL, 384781276385768791956834169424201785, :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$RM_TEXT_LINES
   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(null, 384781276385768791956834169424201785);
  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 RM_TEXT_LINES_d;
/
comment on column l$SDD_NLS_MESSAGES.MSGNO is 'Unique message identifier'
/
comment on column SDD_NLS_MESSAGES.MSGNO is 'Unique message identifier'
/
comment on column l$SDD_NLS_MESSAGES.MNEMONIC is 'Unique human readable identifier'
/
comment on column SDD_NLS_MESSAGES.MNEMONIC is 'Unique human readable identifier'
/
comment on column l$SDD_NLS_MESSAGES.FACILITY is '3 letter oracle facilty code'
/
comment on column SDD_NLS_MESSAGES.FACILITY is '3 letter oracle facilty code'
/
comment on column l$SDD_NLS_MESSAGES.SEVERITY is 'Severity: (I)nformational (W)arning (E)rror (F)atal'
/
comment on column SDD_NLS_MESSAGES.SEVERITY is 'Severity: (I)nformational (W)arning (E)rror (F)atal'
/
comment on column l$SDD_NLS_MESSAGES.MESSAGE_TEXT is 'Text of message'
/
comment on column SDD_NLS_MESSAGES.MESSAGE_TEXT is 'Text of message'
/
comment on column l$SDD_NLS_MESSAGES.TRANSLATION_NOTES is 'Translation notes (monolingual)'
/
comment on column SDD_NLS_MESSAGES.TRANSLATION_NOTES is 'Translation notes (monolingual)'
/
create or replace trigger SDD_NLS_MESSAGES_br
  before insert or update or delete on l$SDD_NLS_MESSAGES
  for each row 
declare
  dummy integer;
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
  if updating then
    -- Maintain audit columns
    jr_audit.pre_update_notm(:new.NOTM);
    jr_audit.pre_update_date_changed(:new.DATE_CHANGED);
    jr_audit.pre_update_changed_by(:new.CHANGED_BY);
  end if; -- updating
end SDD_NLS_MESSAGES_br;
/
create or replace trigger l$SDD_NLS_MESSAGES_l
  after insert or update of lid, slid on l$SDD_NLS_MESSAGES
  for each row 
declare
  bad_language exception;
  cant_change_language exception;
begin
  if inserting then
    if (not jr_language.is_enabled(:new.lid))
      or (not jr_language.is_enabled(:new.slid)) then
      raise bad_language;
    end if;
  elsif updating then
    if :new.lid != :old.lid then
      raise cant_change_language;
    end if;
    if not jr_language.is_enabled(:new.slid) then
      raise bad_language;
    end if;
  end if;
exception
  when bad_language then
    raise_application_error(-20000, 'Language not found');
  when cant_change_language then
    raise_application_error(-20000, 'Cannot change language');
end l$SDD_NLS_MESSAGES_l;
/
create or replace trigger SDD_NLS_MESSAGES_ar
  after insert or update or delete on l$SDD_NLS_MESSAGES
  for each row 
declare
  dummy integer;
begin
  select null
  into   dummy
  from   i$sdd_object_versions
  where  irid=:new.irid
  and    ivid=:new.ivid;
exception
  when NO_DATA_FOUND then
  -- Inserting
  if inserting then
    jr_object_version.ins ( :new.irid, :new.ivid
    , name => :new.MNEMONIC
    , type_irid => :new.TYPES
    , table_irid => 384781276383974292693343704242997305
    , date_created => :new.DATE_CREATED
    , created_by => :new.CREATED_BY
    , notm => :new.NOTM
    );
  end if;  -- inserting
  -- Updating
  if updating then
    jr_object_version.upd ( :old.ivid
      , name => :new.MNEMONIC
      , date_changed => :new.DATE_CHANGED
      , changed_by => :new.CHANGED_BY
      , notm => :new.NOTM
    );
  end if;  -- updating
  -- Deleting
  if deleting then
    jr_object_version.del ( :old.irid, :old.ivid, 'SDD_NLS_MESSAGES'
      , null   -- parent_ivid not applicable for primary object
      , false  -- Designer object
      );
  end if;  -- deleting
end SDD_NLS_MESSAGES_ar;
/
comment on table l$SDD_NLS_MESSAGES is 'NLSable messages'
/
comment on table SDD_NLS_MESSAGES is 'NLSable messages'
/
create or replace trigger SDD_NLS_MESSAGES_inv
after insert or update of
  MSGNO
 ,MNEMONIC
on l$SDD_NLS_MESSAGES
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 := 384781276383974292693343704242997305;
  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_NLS_MESSAGES_inv;
/
create or replace trigger SDD_NLS_MESSAGES_val
after insert or update of
  MSGNO
 ,MNEMONIC
on l$SDD_NLS_MESSAGES
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 := 384781276383974292693343704242997305;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not SDD_NLS_MESSAGES_PK(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (SDD_NLS_MESSAGES_PK) violated');
    end if;
    if not SDD_NLS_MESSAGES_NAME(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (SDD_NLS_MESSAGES_NAME) 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_NLS_MESSAGES_val;
/
create or replace trigger SDD_NLS_MESSAGES_d
  instead of delete on SDD_NLS_MESSAGES 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_NLS_MESSAGES_d;
/
comment on column l$SDD_NLS_PROMPTS.PMPTNO is 'Unique prompt identifier'
/
comment on column SDD_NLS_PROMPTS.PMPTNO is 'Unique prompt identifier'
/
comment on column l$SDD_NLS_PROMPTS.PROMPT_TEXT is 'Text of prompt'
/
comment on column SDD_NLS_PROMPTS.PROMPT_TEXT is 'Text of prompt'
/
comment on column l$SDD_NLS_PROMPTS.TRANSLATION_NOTES is 'Translation notes (monolingual)'
/
comment on column SDD_NLS_PROMPTS.TRANSLATION_NOTES is 'Translation notes (monolingual)'
/
create or replace trigger SDD_NLS_PROMPTS_br
  before insert or update or delete on l$SDD_NLS_PROMPTS
  for each row 
declare
  dummy integer;
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
  if updating then
    -- Maintain audit columns
    jr_audit.pre_update_notm(:new.NOTM);
    jr_audit.pre_update_date_changed(:new.DATE_CHANGED);
    jr_audit.pre_update_changed_by(:new.CHANGED_BY);
  end if; -- updating
end SDD_NLS_PROMPTS_br;
/
create or replace trigger l$SDD_NLS_PROMPTS_l
  after insert or update of lid, slid on l$SDD_NLS_PROMPTS
  for each row 
declare
  bad_language exception;
  cant_change_language exception;
begin
  if inserting then
    if (not jr_language.is_enabled(:new.lid))
      or (not jr_language.is_enabled(:new.slid)) then
      raise bad_language;
    end if;
  elsif updating then
    if :new.lid != :old.lid then
      raise cant_change_language;
    end if;
    if not jr_language.is_enabled(:new.slid) then
      raise bad_language;
    end if;
  end if;
exception
  when bad_language then
    raise_application_error(-20000, 'Language not found');
  when cant_change_language then
    raise_application_error(-20000, 'Cannot change language');
end l$SDD_NLS_PROMPTS_l;
/
create or replace trigger SDD_NLS_PROMPTS_ar
  after insert or update or delete on l$SDD_NLS_PROMPTS
  for each row 
declare
  dummy integer;
begin
  select null
  into   dummy
  from   i$sdd_object_versions
  where  irid=:new.irid
  and    ivid=:new.ivid;
exception
  when NO_DATA_FOUND then
  -- Inserting
  if inserting then
    jr_object_version.ins ( :new.irid, :new.ivid
    , type_irid => :new.TYPES
    , table_irid => 384781276384059295290035357856843833
    , date_created => :new.DATE_CREATED
    , created_by => :new.CREATED_BY
    , notm => :new.NOTM
    );
  end if;  -- inserting
  -- Updating
  if updating then
    jr_object_version.upd ( :old.ivid
      , date_changed => :new.DATE_CHANGED
      , changed_by => :new.CHANGED_BY
      , notm => :new.NOTM
    );
  end if;  -- updating
  -- Deleting
  if deleting then
    jr_object_version.del ( :old.irid, :old.ivid, 'SDD_NLS_PROMPTS'
      , null   -- parent_ivid not applicable for primary object
      , false  -- Designer object
      );
  end if;  -- deleting
end SDD_NLS_PROMPTS_ar;
/
comment on table l$SDD_NLS_PROMPTS is 'NLSable prompts'
/
comment on table SDD_NLS_PROMPTS is 'NLSable prompts'
/
create or replace trigger SDD_NLS_PROMPTS_inv
after insert or update of
  PMPTNO
on l$SDD_NLS_PROMPTS
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 := 384781276384059295290035357856843833;
  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_NLS_PROMPTS_inv;
/
create or replace trigger SDD_NLS_PROMPTS_val
after insert or update of
  PMPTNO
on l$SDD_NLS_PROMPTS
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 := 384781276384059295290035357856843833;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not SDD_PROMPTS_PK(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (SDD_PROMPTS_PK) 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_NLS_PROMPTS_val;
/
create or replace trigger SDD_NLS_PROMPTS_d
  instead of delete on SDD_NLS_PROMPTS 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_NLS_PROMPTS_d;
/
comment on column l$SDD_NLS_PROPLIST_ENTRIES.PLID is 'Parent property list'
/
comment on column SDD_NLS_PROPLIST_ENTRIES.PLID is 'Parent property list'
/
comment on column l$SDD_NLS_PROPLIST_ENTRIES.PROPERTY is 'Name of property'
/
comment on column SDD_NLS_PROPLIST_ENTRIES.PROPERTY is 'Name of property'
/
comment on column l$SDD_NLS_PROPLIST_ENTRIES.SEQ is 'Sequence within parent'
/
comment on column SDD_NLS_PROPLIST_ENTRIES.SEQ is 'Sequence within parent'
/
comment on column l$SDD_NLS_PROPLIST_ENTRIES.VALUE is 'Value of property (multilingual)'
/
comment on column SDD_NLS_PROPLIST_ENTRIES.VALUE is 'Value of property (multilingual)'
/
create or replace trigger SDD_NLS_PROPLIST_ENTRIES_br
  before insert or update or delete on l$SDD_NLS_PROPLIST_ENTRIES
  for each row 
declare
  dummy integer;
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
  if updating then
    -- Maintain audit columns
    jr_audit.pre_update_notm(:new.NOTM);
    jr_audit.pre_update_date_changed(:new.DATE_CHANGED);
    jr_audit.pre_update_changed_by(:new.CHANGED_BY);
  end if; -- updating
end SDD_NLS_PROPLIST_ENTRIES_br;
/
create or replace trigger l$SDD_NLS_PROPLIST_ENTRIES_l
  after insert or update of lid, slid on l$SDD_NLS_PROPLIST_ENTRIES
  for each row 
declare
  bad_language exception;
  cant_change_language exception;
begin
  if inserting then
    if (not jr_language.is_enabled(:new.lid))
      or (not jr_language.is_enabled(:new.slid)) then
      raise bad_language;
    end if;
  elsif updating then
    if :new.lid != :old.lid then
      raise cant_change_language;
    end if;
    if not jr_language.is_enabled(:new.slid) then
      raise bad_language;
    end if;
  end if;
exception
  when bad_language then
    raise_application_error(-20000, 'Language not found');
  when cant_change_language then
    raise_application_error(-20000, 'Cannot change language');
end l$SDD_NLS_PROPLIST_ENTRIES_l;
/
create or replace trigger SDD_NLS_PROPLIST_ENTRIES_ar
  after insert or update or delete on l$SDD_NLS_PROPLIST_ENTRIES
  for each row 
declare
  dummy integer;
begin
  select null
  into   dummy
  from   i$sdd_object_versions
  where  irid=:new.irid
  and    ivid=:new.ivid;
exception
  when NO_DATA_FOUND then
  -- Inserting
  if inserting then
    jr_object_version.ins ( :new.irid, :new.ivid
    , type_irid => :new.TYPES
    , table_irid => 384781276384101796588381184663767097
    , date_created => :new.DATE_CREATED
    , created_by => :new.CREATED_BY
    , notm => :new.NOTM
    );
  end if;  -- inserting
  -- Updating
  if updating then
    jr_object_version.upd ( :old.ivid
      , date_changed => :new.DATE_CHANGED
      , changed_by => :new.CHANGED_BY
      , notm => :new.NOTM
    );
  end if;  -- updating
  -- Deleting
  if deleting then
    jr_object_version.del ( :old.irid, :old.ivid, 'SDD_NLS_PROPLIST_ENTRIES'
      , null   -- parent_ivid not applicable for primary object
      , false  -- Designer object
      );
  end if;  -- deleting
end SDD_NLS_PROPLIST_ENTRIES_ar;
/
comment on table l$SDD_NLS_PROPLIST_ENTRIES is 'NLSable property list entries (owned by proplists)'
/
comment on table SDD_NLS_PROPLIST_ENTRIES is 'NLSable property list entries (owned by proplists)'
/
create or replace trigger SDD_NLS_PROPLIST_ENTRIES_inv
after insert or update of
  PLID
 ,PROPERTY
 ,SEQ
on l$SDD_NLS_PROPLIST_ENTRIES
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 := 384781276384101796588381184663767097;
  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_NLS_PROPLIST_ENTRIES_inv;
/
create or replace trigger SDD_NLS_PROPLIST_ENTRIES_val
after insert or update of
  PLID
 ,PROPERTY
 ,SEQ
on l$SDD_NLS_PROPLIST_ENTRIES
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 := 384781276384101796588381184663767097;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not SDD_NLS_PL_ENTRIES_PK(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (SDD_NLS_PL_ENTRIES_PK) violated');
    end if;
    if not SDD_NLS_PROPLIST_FK(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (SDD_NLS_PROPLIST_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_NLS_PROPLIST_ENTRIES_val;
/
create or replace trigger SDD_NLS_PROPLIST_ENTRIES_d
  instead of delete on SDD_NLS_PROPLIST_ENTRIES 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_NLS_PROPLIST_ENTRIES_d;
/
comment on column l$SDD_NLS_RESOURCES.RESID is 'Unique resource identifier'
/
comment on column SDD_NLS_RESOURCES.RESID is 'Unique resource identifier'
/
comment on column l$SDD_NLS_RESOURCES.MNEMONIC is 'Unique human readable identifier'
/
comment on column SDD_NLS_RESOURCES.MNEMONIC is 'Unique human readable identifier'
/
comment on column l$SDD_NLS_RESOURCES.KIND is 'Type of resource (eg: icon)'
/
comment on column SDD_NLS_RESOURCES.KIND is 'Type of resource (eg: icon)'
/
comment on column l$SDD_NLS_RESOURCES.RESOURCE_DATA is 'Text of prompt'
/
comment on column SDD_NLS_RESOURCES.RESOURCE_DATA is 'Text of prompt'
/
create or replace trigger SDD_NLS_RESOURCES_br
  before insert or update or delete on l$SDD_NLS_RESOURCES
  for each row 
declare
  dummy integer;
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
  if updating then
    -- Maintain audit columns
    jr_audit.pre_update_notm(:new.NOTM);
    jr_audit.pre_update_date_changed(:new.DATE_CHANGED);
    jr_audit.pre_update_changed_by(:new.CHANGED_BY);
  end if; -- updating
end SDD_NLS_RESOURCES_br;
/
create or replace trigger l$SDD_NLS_RESOURCES_l
  after insert or update of lid, slid on l$SDD_NLS_RESOURCES
  for each row 
declare
  bad_language exception;
  cant_change_language exception;
begin
  if inserting then
    if (not jr_language.is_enabled(:new.lid))
      or (not jr_language.is_enabled(:new.slid)) then
      raise bad_language;
    end if;
  elsif updating then
    if :new.lid != :old.lid then
      raise cant_change_language;
    end if;
    if not jr_language.is_enabled(:new.slid) then
      raise bad_language;
    end if;
  end if;
exception
  when bad_language then
    raise_application_error(-20000, 'Language not found');
  when cant_change_language then
    raise_application_error(-20000, 'Cannot change language');
end l$SDD_NLS_RESOURCES_l;
/
create or replace trigger SDD_NLS_RESOURCES_ar
  after insert or update or delete on l$SDD_NLS_RESOURCES
  for each row 
declare
  dummy integer;
begin
  select null
  into   dummy
  from   i$sdd_object_versions
  where  irid=:new.irid
  and    ivid=:new.ivid;
exception
  when NO_DATA_FOUND then
  -- Inserting
  if inserting then
    jr_object_version.ins ( :new.irid, :new.ivid
    , name => :new.MNEMONIC
    , type_irid => :new.TYPES
    , table_irid => 384781276384158464986175620406331449
    , date_created => :new.DATE_CREATED
    , created_by => :new.CREATED_BY
    , notm => :new.NOTM
    );
  end if;  -- inserting
  -- Updating
  if updating then
    jr_object_version.upd ( :old.ivid
      , name => :new.MNEMONIC
      , date_changed => :new.DATE_CHANGED
      , changed_by => :new.CHANGED_BY
      , notm => :new.NOTM
    );
  end if;  -- updating
  -- Deleting
  if deleting then
    jr_object_version.del ( :old.irid, :old.ivid, 'SDD_NLS_RESOURCES'
      , null   -- parent_ivid not applicable for primary object
      , false  -- Designer object
      );
  end if;  -- deleting
end SDD_NLS_RESOURCES_ar;
/
comment on table l$SDD_NLS_RESOURCES is 'NLSable resources'
/
comment on table SDD_NLS_RESOURCES is 'NLSable resources'
/
create or replace trigger SDD_NLS_RESOURCES_inv
after insert or update of
  RESID
 ,MNEMONIC
on l$SDD_NLS_RESOURCES
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 := 384781276384158464986175620406331449;
  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_NLS_RESOURCES_inv;
/
create or replace trigger SDD_NLS_RESOURCES_val
after insert or update of
  RESID
 ,MNEMONIC
on l$SDD_NLS_RESOURCES
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 := 384781276384158464986175620406331449;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not SDD_RESOURCES_PK(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (SDD_RESOURCES_PK) violated');
    end if;
    if not SDD_RESOURCES_MNEMONIC(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (SDD_RESOURCES_MNEMONIC) 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_NLS_RESOURCES_val;
/
create or replace trigger SDD_NLS_RESOURCES_d
  instead of delete on SDD_NLS_RESOURCES 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_NLS_RESOURCES_d;
/
comment on column i$SDD_PROPERTY_LISTS.PLID is 'Unique numeric identifier'
/
comment on column SDD_PROPERTY_LISTS.PLID is 'Unique numeric identifier'
/
comment on column i$SDD_PROPERTY_LISTS.NAME is 'Property list name'
/
comment on column SDD_PROPERTY_LISTS.NAME is 'Property list name'
/
comment on column i$SDD_PROPERTY_LISTS.TRANSLATION_NOTES is 'Notes for translators (for entry tables)'
/
comment on column SDD_PROPERTY_LISTS.TRANSLATION_NOTES is 'Notes for translators (for entry tables)'
/
create or replace trigger SDD_PROPERTY_LISTS_br
  before insert or update or delete on i$SDD_PROPERTY_LISTS
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
  if updating then
    -- Maintain audit columns
    jr_audit.pre_update_notm(:new.NOTM);
    jr_audit.pre_update_date_changed(:new.DATE_CHANGED);
    jr_audit.pre_update_changed_by(:new.CHANGED_BY);
  end if; -- updating
end SDD_PROPERTY_LISTS_br;
/
create or replace trigger SDD_PROPERTY_LISTS_ar
  after insert or update or delete on i$SDD_PROPERTY_LISTS
  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 => 384781276384356804378456145505306681
    , date_created => :new.DATE_CREATED
    , created_by => :new.CREATED_BY
    , notm => :new.NOTM
    );
  end if;  -- inserting
  -- Updating
  if updating then
    jr_object_version.upd ( :old.ivid
      , name => :new.NAME
      , date_changed => :new.DATE_CHANGED
      , changed_by => :new.CHANGED_BY
      , notm => :new.NOTM
    );
  end if;  -- updating
  -- Deleting
  if deleting then
    jr_object_version.del ( :old.irid, :old.ivid, 'SDD_PROPERTY_LISTS'
      , null   -- parent_ivid not applicable for primary object
      , false  -- Designer object
      );
  end if;  -- deleting
end SDD_PROPERTY_LISTS_ar;
/
comment on table i$SDD_PROPERTY_LISTS is 'Property list master - owns two collection tables'
/
comment on table SDD_PROPERTY_LISTS is 'Property list master - owns two collection tables'
/
create or replace trigger SDD_PROPERTY_LISTS_inv
after insert or update of
  PLID
on i$SDD_PROPERTY_LISTS
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 := 384781276384356804378456145505306681;
  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
    if :new.PLID != :old.PLID or (:new.PLID is null and :old.PLID is not null)
    then
      if not SDD_NLS_PROPLIST_FK_d (
        :old.ivid
      , :old.PLID
     , this_type_irid
     , action
      ) then
        raise_application_error(-20292, 'integrity constraint (SDD_NLS_PROPLIST_FK) violated - child record found');
      end if;
    end if;
    if :new.PLID != :old.PLID or (:new.PLID is null and :old.PLID is not null)
    then
      if not SDD_PROPLIST_FK_d (
        :old.ivid
      , :old.PLID
     , this_type_irid
     , action
      ) then
        raise_application_error(-20292, 'integrity constraint (SDD_PROPLIST_FK) violated - child record found');
      end if;
    end if;
  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_PROPERTY_LISTS_inv;
/
create or replace trigger SDD_PROPERTY_LISTS_val
after insert or update of
  PLID
on i$SDD_PROPERTY_LISTS
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 := 384781276384356804378456145505306681;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not SDD_PROPLISTS_PK(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (SDD_PROPLISTS_PK) 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_PROPERTY_LISTS_val;
/
create or replace trigger SDD_PROPERTY_LISTS_d
  instead of delete on SDD_PROPERTY_LISTS 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_NLS_PROPLIST_ENTRIES fktab
  where 
        fktab.PLID = :old.PLID
    ;
 delete SDD_PROPLIST_ENTRIES fktab
  where 
        fktab.PLID = :old.PLID
    ;
 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_PROPERTY_LISTS_d;
/
comment on column i$SDD_PROPLIST_ENTRIES.PLID is 'Parent property list'
/
comment on column SDD_PROPLIST_ENTRIES.PLID is 'Parent property list'
/
comment on column i$SDD_PROPLIST_ENTRIES.PROPERTY is 'Name of property'
/
comment on column SDD_PROPLIST_ENTRIES.PROPERTY is 'Name of property'
/
comment on column i$SDD_PROPLIST_ENTRIES.SEQ is 'Sequence within parent'
/
comment on column SDD_PROPLIST_ENTRIES.SEQ is 'Sequence within parent'
/
comment on column i$SDD_PROPLIST_ENTRIES.VALUE is 'Value of property'
/
comment on column SDD_PROPLIST_ENTRIES.VALUE is 'Value of property'
/
create or replace trigger SDD_PROPLIST_ENTRIES_br
  before insert or update or delete on i$SDD_PROPLIST_ENTRIES
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
  if updating then
    -- Maintain audit columns
    jr_audit.pre_update_notm(:new.NOTM);
    jr_audit.pre_update_date_changed(:new.DATE_CHANGED);
    jr_audit.pre_update_changed_by(:new.CHANGED_BY);
  end if; -- updating
end SDD_PROPLIST_ENTRIES_br;
/
create or replace trigger SDD_PROPLIST_ENTRIES_ar
  after insert or update or delete on i$SDD_PROPLIST_ENTRIES
  for each row 
begin
  -- Inserting
  if inserting then
    jr_object_version.ins ( :new.irid, :new.ivid
    , type_irid => :new.TYPES
    , table_irid => 384781276384404028043284841957443641
    , date_created => :new.DATE_CREATED
    , created_by => :new.CREATED_BY
    , notm => :new.NOTM
    );
  end if;  -- inserting
  -- Updating
  if updating then
    jr_object_version.upd ( :old.ivid
      , date_changed => :new.DATE_CHANGED
      , changed_by => :new.CHANGED_BY
      , notm => :new.NOTM
    );
  end if;  -- updating
  -- Deleting
  if deleting then
    jr_object_version.del ( :old.irid, :old.ivid, 'SDD_PROPLIST_ENTRIES'
      , null   -- parent_ivid not applicable for primary object
      , false  -- Designer object
      );
  end if;  -- deleting
end SDD_PROPLIST_ENTRIES_ar;
/
comment on table i$SDD_PROPLIST_ENTRIES is 'property list entries (owned by sdd_property_lists)'
/
comment on table SDD_PROPLIST_ENTRIES is 'property list entries (owned by sdd_property_lists)'
/
create or replace trigger SDD_PROPLIST_ENTRIES_inv
after insert or update of
  PLID
 ,PROPERTY
 ,SEQ
on i$SDD_PROPLIST_ENTRIES
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 := 384781276384404028043284841957443641;
  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_PROPLIST_ENTRIES_inv;
/
create or replace trigger SDD_PROPLIST_ENTRIES_val
after insert or update of
  PLID
 ,PROPERTY
 ,SEQ
on i$SDD_PROPLIST_ENTRIES
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 := 384781276384404028043284841957443641;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not SDD_PL_ENTRIES_PK(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (SDD_PL_ENTRIES_PK) violated');
    end if;
    if not SDD_PROPLIST_FK(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (SDD_PROPLIST_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_PROPLIST_ENTRIES_val;
/
create or replace trigger SDD_PROPLIST_ENTRIES_d
  instead of delete on SDD_PROPLIST_ENTRIES 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_PROPLIST_ENTRIES_d;
/
/*comment on column i$SDD_WIDGETS.WID is 'Widget identifier'
/
comment on column SDD_WIDGETS.WID is 'Widget identifier'
/
comment on column i$SDD_WIDGETS.WIDGET_NAME is 'Common name of widget'
/
comment on column SDD_WIDGETS.WIDGET_NAME is 'Common name of widget'
/
comment on column i$SDD_WIDGETS.DESCRIPTION is 'Description of widget'
/
comment on column SDD_WIDGETS.DESCRIPTION is 'Description of widget'
/
create or replace trigger SDD_WIDGETS_br
  before insert or update or delete on i$SDD_WIDGETS
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
  if updating then
    -- Maintain audit columns
    jr_audit.pre_update_notm(:new.NOTM);
    jr_audit.pre_update_date_changed(:new.DATE_CHANGED);
    jr_audit.pre_update_changed_by(:new.CHANGED_BY);
  end if; -- updating
end SDD_WIDGETS_br;
/
create or replace trigger SDD_WIDGETS_ar
  after insert or update or delete on i$SDD_WIDGETS
  for each row 
begin
  -- Inserting
  if inserting then
    jr_object_version.ins ( :new.irid, :new.ivid
    , name => :new.WIDGET_NAME
    , type_irid => :new.TYPES
    , table_irid => 384781276384607089802048236701632569
    , date_created => :new.DATE_CREATED
    , created_by => :new.CREATED_BY
    , notm => :new.NOTM
    );
  end if;  -- inserting
  -- Updating
  if updating then
    jr_object_version.upd ( :old.ivid
      , name => :new.WIDGET_NAME
      , date_changed => :new.DATE_CHANGED
      , changed_by => :new.CHANGED_BY
      , notm => :new.NOTM
    );
  end if;  -- updating
  -- Deleting
  if deleting then
    jr_object_version.del ( :old.irid, :old.ivid, 'SDD_WIDGETS'
      , null   -- parent_ivid not applicable for primary object
      , false  -- Designer object
      );
  end if;  -- deleting
end SDD_WIDGETS_ar;
/
comment on table i$SDD_WIDGETS is 'Vanilla relational object'
/
comment on table SDD_WIDGETS is 'Vanilla relational object'
/
create or replace trigger SDD_WIDGETS_inv
after insert or update of
  WID
 ,WIDGET_NAME
on i$SDD_WIDGETS
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 := 384781276384607089802048236701632569;
  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_WIDGETS_inv;
/
create or replace trigger SDD_WIDGETS_val
after insert or update of
  WID
 ,WIDGET_NAME
on i$SDD_WIDGETS
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 := 384781276384607089802048236701632569;
  if inserting then
    action := 'INS';
  elsif updating then
    action := 'UPD';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not SDD_WIDGETS_PK(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (SDD_WIDGETS_PK) violated');
    end if;
    if not SDD_WIDGET_UNIQUE_NAME(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (SDD_WIDGET_UNIQUE_NAME) 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_WIDGETS_val;
/
create or replace trigger SDD_WIDGETS_d
  instead of delete on SDD_WIDGETS 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_WIDGETS_d;
/*/
create or replace trigger SDD_A1_br
  before insert or update or delete on i$SDD_A1
  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.OBJECTIVE_REF is not null)
       )
    or (updating and (
        (:new.OBJECTIVE_REF != :old.OBJECTIVE_REF
        or (:new.OBJECTIVE_REF is not null and :old.OBJECTIVE_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_E1 owning_tab
        where  owning_tab.IRID=:new.OBJECTIVE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_A1_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_A1');
  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_A1_br;
/
create or replace trigger SDD_A1_inv
after insert or update of
  CSF_REF
on i$SDD_A1
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 := 384781276392994012675624726601156665;
  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_A1_inv;
/
create or replace trigger SDD_A1_val
after insert or update of
  CSF_REF
on i$SDD_A1
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 := 384781276392994012675624726601156665;
  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_A1(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_A1) violated');
    end if;
    if not FK_A1_TO_E2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_A1_TO_E2) 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_A1_val;
/
create or replace trigger SDD_A1_d
  instead of delete on SDD_A1 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_A1 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_A1
   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_A1_d;
/
create or replace trigger SDD_A10_br
  before insert or update or delete on i$SDD_A10
  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.BUSINESS_UNIT_REF is not null)
       )
    or (updating and (
        (:new.BUSINESS_UNIT_REF != :old.BUSINESS_UNIT_REF
        or (:new.BUSINESS_UNIT_REF is not null and :old.BUSINESS_UNIT_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_BUN owning_tab
        where  owning_tab.IRID=:new.BUSINESS_UNIT_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_A10_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_A10');
  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_A10_br;
/
create or replace trigger SDD_A10_inv
after insert or update of
  PROBLEM_REF
on i$SDD_A10
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 := 384781276393239575732733948152268857;
  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_A10_inv;
/
create or replace trigger SDD_A10_val
after insert or update of
  PROBLEM_REF
on i$SDD_A10
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 := 384781276393239575732733948152268857;
  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_A10(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_A10) violated');
    end if;
    if not FK_A10_TO_E5(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_A10_TO_E5) 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_A10_val;
/
create or replace trigger SDD_A10_d
  instead of delete on SDD_A10 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_A10 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_A10
   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_A10_d;
/
create or replace trigger SDD_A11_br
  before insert or update or delete on i$SDD_A11
  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.KPI_REF is not null)
       )
    or (updating and (
        (:new.KPI_REF != :old.KPI_REF
        or (:new.KPI_REF is not null and :old.KPI_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_E3 owning_tab
        where  owning_tab.IRID=:new.KPI_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_A11_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_A11');
  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_A11_br;
/
create or replace trigger SDD_A11_inv
after insert or update of
  FUNCTION_REF
on i$SDD_A11
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 := 384781276393485138789843169703381049;
  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_A11_inv;
/
create or replace trigger SDD_A11_val
after insert or update of
  FUNCTION_REF
on i$SDD_A11
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 := 384781276393485138789843169703381049;
  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_A11(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_A11) violated');
    end if;
    if not FK_A11_TO_FUN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_A11_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_A11_val;
/
create or replace trigger SDD_A11_d
  instead of delete on SDD_A11 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_A11 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_A11
   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_A11_d;
/
create or replace trigger SDD_A2_br
  before insert or update or delete on i$SDD_A2
  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.OBJECTIVE_REF is not null)
       )
    or (updating and (
        (:new.OBJECTIVE_REF != :old.OBJECTIVE_REF
        or (:new.OBJECTIVE_REF is not null and :old.OBJECTIVE_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_E1 owning_tab
        where  owning_tab.IRID=:new.OBJECTIVE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_A2_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_A2');
  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_A2_br;
/
create or replace trigger SDD_A2_inv
after insert or update of
  MODULE_REF
on i$SDD_A2
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 := 384781276393730701846952391254493241;
  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_A2_inv;
/
create or replace trigger SDD_A2_val
after insert or update of
  MODULE_REF
on i$SDD_A2
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 := 384781276393730701846952391254493241;
  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_A2(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_A2) violated');
    end if;
    if not FK_A2_TO_MOD(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_A2_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_A2_val;
/
create or replace trigger SDD_A2_d
  instead of delete on SDD_A2 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_A2 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_A2
   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_A2_d;
/
create or replace trigger SDD_A20_br
  before insert or update or delete on i$SDD_A20
  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.PART_OF_NODE_REF is not null)
       )
    or (updating and (
        (:new.PART_OF_NODE_REF != :old.PART_OF_NODE_REF
        or (:new.PART_OF_NODE_REF is not null and :old.PART_OF_NODE_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_E20 owning_tab
        where  owning_tab.IRID=:new.PART_OF_NODE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_A20_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_A20');
  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_A20_br;
/
create or replace trigger SDD_A20_inv
after insert or update of
  USE_OF_NODE_REF
on i$SDD_A20
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 := 384781276393976264904061612805605433;
  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_A20_inv;
/
create or replace trigger SDD_A20_val
after insert or update of
  USE_OF_NODE_REF
on i$SDD_A20
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 := 384781276393976264904061612805605433;
  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_A20(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_A20) violated');
    end if;
    if not FK_A20_TO_E202(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_A20_TO_E202) 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_A20_val;
/
create or replace trigger SDD_A20_d
  instead of delete on SDD_A20 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_A20 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_A20
   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_A20_d;
/
create or replace trigger SDD_A21_br
  before insert or update or delete on i$SDD_A21
  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.LOCATION_REF is not null)
       )
    or (updating and (
        (:new.LOCATION_REF != :old.LOCATION_REF
        or (:new.LOCATION_REF is not null and :old.LOCATION_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_E6 owning_tab
        where  owning_tab.IRID=:new.LOCATION_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_A21_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_A21');
  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_A21_br;
/
create or replace trigger SDD_A21_inv
after insert or update of
  NODE_REF
on i$SDD_A21
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 := 384781276394221827961170834356717625;
  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_A21_inv;
/
create or replace trigger SDD_A21_val
after insert or update of
  NODE_REF
on i$SDD_A21
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 := 384781276394221827961170834356717625;
  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_A21(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_A21) violated');
    end if;
    if not FK_A21_TO_E20(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_A21_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_A21_val;
/
create or replace trigger SDD_A21_d
  instead of delete on SDD_A21 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_A21 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_A21
   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_A21_d;
/
create or replace trigger SDD_A23_br
  before insert or update or delete on i$SDD_A23
  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.NODE_REF is not null)
       )
    or (updating and (
        (:new.NODE_REF != :old.NODE_REF
        or (:new.NODE_REF is not null and :old.NODE_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_E20 owning_tab
        where  owning_tab.IRID=:new.NODE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_A23_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_A23');
  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_A23_br;
/
create or replace trigger SDD_A23_inv
after insert or update of
  MODULE_REF
on i$SDD_A23
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 := 384781276394467391018280055907829817;
  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_A23_inv;
/
create or replace trigger SDD_A23_val
after insert or update of
  MODULE_REF
on i$SDD_A23
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 := 384781276394467391018280055907829817;
  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_A23(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_A23) violated');
    end if;
    if not FK_A23_TO_MOD(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_A23_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_A23_val;
/
create or replace trigger SDD_A23_d
  instead of delete on SDD_A23 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_A23 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_A23
   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_A23_d;
/
create or replace trigger SDD_A24_br
  before insert or update or delete on i$SDD_A24
  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.NODE_REF is not null)
       )
    or (updating and (
        (:new.NODE_REF != :old.NODE_REF
        or (:new.NODE_REF is not null and :old.NODE_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_E20 owning_tab
        where  owning_tab.IRID=:new.NODE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_A24_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_A24');
  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_A24_br;
/
create or replace trigger SDD_A24_inv
after insert or update of
  BUSINESS_UNIT_REF
on i$SDD_A24
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 := 384781276394712954075389277458942009;
  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_A24_inv;
/
create or replace trigger SDD_A24_val
after insert or update of
  BUSINESS_UNIT_REF
on i$SDD_A24
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 := 384781276394712954075389277458942009;
  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_A24(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_A24) violated');
    end if;
    if not FK_A24_TO_BUN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_A24_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_A24_val;
/
create or replace trigger SDD_A24_d
  instead of delete on SDD_A24 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_A24 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_A24
   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_A24_d;
/
create or replace trigger SDD_A3_br
  before insert or update or delete on i$SDD_A3
  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.OBJECTIVE_REF is not null)
       )
    or (updating and (
        (:new.OBJECTIVE_REF != :old.OBJECTIVE_REF
        or (:new.OBJECTIVE_REF is not null and :old.OBJECTIVE_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_E1 owning_tab
        where  owning_tab.IRID=:new.OBJECTIVE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_A3_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_A3');
  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_A3_br;
/
create or replace trigger SDD_A3_inv
after insert or update of
  KPI_REF
on i$SDD_A3
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 := 384781276394958517132498499010054201;
  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_A3_inv;
/
create or replace trigger SDD_A3_val
after insert or update of
  KPI_REF
on i$SDD_A3
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 := 384781276394958517132498499010054201;
  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_A3(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_A3) violated');
    end if;
    if not FK_A3_TO_E3(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_A3_TO_E3) 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_A3_val;
/
create or replace trigger SDD_A3_d
  instead of delete on SDD_A3 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_A3 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_A3
   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_A3_d;
/
create or replace trigger SDD_A4_br
  before insert or update or delete on i$SDD_A4
  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.OBJECTIVE_REF is not null)
       )
    or (updating and (
        (:new.OBJECTIVE_REF != :old.OBJECTIVE_REF
        or (:new.OBJECTIVE_REF is not null and :old.OBJECTIVE_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_E1 owning_tab
        where  owning_tab.IRID=:new.OBJECTIVE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_A4_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_A4');
  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_A4_br;
/
create or replace trigger SDD_A4_inv
after insert or update of
  FUNCTION_REF
on i$SDD_A4
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 := 384781276395204080189607720561166393;
  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_A4_inv;
/
create or replace trigger SDD_A4_val
after insert or update of
  FUNCTION_REF
on i$SDD_A4
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 := 384781276395204080189607720561166393;
  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_A4(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_A4) violated');
    end if;
    if not FK_A4_TO_FUN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_A4_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_A4_val;
/
create or replace trigger SDD_A4_d
  instead of delete on SDD_A4 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_A4 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_A4
   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_A4_d;
/
create or replace trigger SDD_A5_br
  before insert or update or delete on i$SDD_A5
  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.ASSUMPTION_REF is not null)
       )
    or (updating and (
        (:new.ASSUMPTION_REF != :old.ASSUMPTION_REF
        or (:new.ASSUMPTION_REF is not null and :old.ASSUMPTION_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_E4 owning_tab
        where  owning_tab.IRID=:new.ASSUMPTION_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_A5_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_A5');
  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_A5_br;
/
create or replace trigger SDD_A5_inv
after insert or update of
  MODULE_REF
on i$SDD_A5
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 := 384781276395454365613199811757492281;
  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_A5_inv;
/
create or replace trigger SDD_A5_val
after insert or update of
  MODULE_REF
on i$SDD_A5
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 := 384781276395454365613199811757492281;
  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_A5(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_A5) violated');
    end if;
    if not FK_A5_TO_MOD(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_A5_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_A5_val;
/
create or replace trigger SDD_A5_d
  instead of delete on SDD_A5 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_A5 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_A5
   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_A5_d;
/
create or replace trigger SDD_A6_br
  before insert or update or delete on i$SDD_A6
  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.ASSUMPTION_REF is not null)
       )
    or (updating and (
        (:new.ASSUMPTION_REF != :old.ASSUMPTION_REF
        or (:new.ASSUMPTION_REF is not null and :old.ASSUMPTION_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_E4 owning_tab
        where  owning_tab.IRID=:new.ASSUMPTION_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_A6_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_A6');
  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_A6_br;
/
create or replace trigger SDD_A6_inv
after insert or update of
  TABLE_REF
on i$SDD_A6
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 := 384781276395699928670309033308604473;
  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_A6_inv;
/
create or replace trigger SDD_A6_val
after insert or update of
  TABLE_REF
on i$SDD_A6
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 := 384781276395699928670309033308604473;
  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_A6(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_A6) violated');
    end if;
    if not FK_A6_TO_TAB(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_A6_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_A6_val;
/
create or replace trigger SDD_A6_d
  instead of delete on SDD_A6 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_A6 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_A6
   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_A6_d;
/
create or replace trigger SDD_A7_br
  before insert or update or delete on i$SDD_A7
  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.PROBLEM_REF is not null)
       )
    or (updating and (
        (:new.PROBLEM_REF != :old.PROBLEM_REF
        or (:new.PROBLEM_REF is not null and :old.PROBLEM_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_E5 owning_tab
        where  owning_tab.IRID=:new.PROBLEM_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_A7_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_A7');
  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_A7_br;
/
create or replace trigger SDD_A7_inv
after insert or update of
  MODULE_REF
on i$SDD_A7
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 := 384781276395945491727418254859716665;
  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_A7_inv;
/
create or replace trigger SDD_A7_val
after insert or update of
  MODULE_REF
on i$SDD_A7
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 := 384781276395945491727418254859716665;
  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_A7(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_A7) violated');
    end if;
    if not FK_A7_TO_MOD(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_A7_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_A7_val;
/
create or replace trigger SDD_A7_d
  instead of delete on SDD_A7 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_A7 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_A7
   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_A7_d;
/
create or replace trigger SDD_A8_br
  before insert or update or delete on i$SDD_A8
  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.BUSINESS_UNIT_REF is not null)
       )
    or (updating and (
        (:new.BUSINESS_UNIT_REF != :old.BUSINESS_UNIT_REF
        or (:new.BUSINESS_UNIT_REF is not null and :old.BUSINESS_UNIT_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_BUN owning_tab
        where  owning_tab.IRID=:new.BUSINESS_UNIT_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_A8_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_A8');
  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_A8_br;
/
create or replace trigger SDD_A8_inv
after insert or update of
  OBJECTIVE_REF
on i$SDD_A8
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 := 384781276396191054784527476410828857;
  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_A8_inv;
/
create or replace trigger SDD_A8_val
after insert or update of
  OBJECTIVE_REF
on i$SDD_A8
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 := 384781276396191054784527476410828857;
  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_A8(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_A8) violated');
    end if;
    if not FK_A8_TO_E1(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_A8_TO_E1) 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_A8_val;
/
create or replace trigger SDD_A8_d
  instead of delete on SDD_A8 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_A8 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_A8
   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_A8_d;
/
create or replace trigger SDD_A9_br
  before insert or update or delete on i$SDD_A9
  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.LOCATION_REF is not null)
       )
    or (updating and (
        (:new.LOCATION_REF != :old.LOCATION_REF
        or (:new.LOCATION_REF is not null and :old.LOCATION_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_E6 owning_tab
        where  owning_tab.IRID=:new.LOCATION_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_A9_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_A9');
  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_A9_br;
/
create or replace trigger SDD_A9_inv
after insert or update of
  BUSINESS_UNIT_REF
on i$SDD_A9
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 := 384781276396436617841636697961941049;
  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_A9_inv;
/
create or replace trigger SDD_A9_val
after insert or update of
  BUSINESS_UNIT_REF
on i$SDD_A9
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 := 384781276396436617841636697961941049;
  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_A9(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_A9) violated');
    end if;
    if not FK_A9_TO_BUN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_A9_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_A9_val;
/
create or replace trigger SDD_A9_d
  instead of delete on SDD_A9 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_A9 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_A9
   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_A9_d;
/
create or replace trigger SDD_ACI_br
  before insert or update or delete on i$SDD_ACI
  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.MCN_REF is not null)
       )
    or (updating and (
        (:new.MCN_REF != :old.MCN_REF
        or (:new.MCN_REF is not null and :old.MCN_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_MCN owning_tab
        where  owning_tab.IRID=:new.MCN_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_ACI_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.WINDOW_REF is not null)
       )
    or (updating and (
        (:new.WINDOW_REF != :old.WINDOW_REF
        or (:new.WINDOW_REF is not null and :old.WINDOW_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_WIN owning_tab
        where  owning_tab.IRID=:new.WINDOW_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_ACI_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_ACI');
  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_ACI_br;
/
create or replace trigger SDD_ACI_inv
after insert or update of
  MCN_REF_TO
 ,MODULE_NETWORK_REF
on i$SDD_ACI
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 := 384781276397258309609656016229124153;
  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_ACI_inv;
/
create or replace trigger SDD_ACI_val
after insert or update of
  MCN_REF_TO
 ,MODULE_NETWORK_REF
on i$SDD_ACI
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 := 384781276397258309609656016229124153;
  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_ACI(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_ACI) violated');
    end if;
    if not FK_ACI_TO_MCN2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ACI_TO_MCN2) violated - parent key not found');
    end if;
    if not FK_ACI_TO_MODMOD(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ACI_TO_MODMOD) 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_ACI_val;
/
create or replace trigger SDD_ACI_d
  instead of delete on SDD_ACI 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_ACI 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_ACI
   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_ACI_d;
/
create or replace trigger SDD_ACR_br
  before insert or update or delete on i$SDD_ACR
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_ACR_br;
/
create or replace trigger SDD_ACR_ar
  after insert or update or delete on i$SDD_ACR
  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 => 384781276397603042362905500329723961
    );
  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_ACR'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_ACR_ar;
/
create or replace trigger SDD_ACR_inv
after insert or update of
  ICON_FILE_REF
on i$SDD_ACR
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 := 384781276397603042362905500329723961;
  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_ACR_inv;
/
create or replace trigger SDD_ACR_val
after insert or update of
  ICON_FILE_REF
on i$SDD_ACR
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 := 384781276397603042362905500329723961;
  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_ACR(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_ACR) violated');
    end if;
    if not FK_ACR_TO_FILES(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ACR_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_ACR_val;
/
create or replace trigger SDD_ACR_d
  instead of delete on SDD_ACR 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
   if not FK_ACRACR_TO_ACR2_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_ACRACR fktab
   where 
         fktab.SUPERTYPE_ACTOR_REF = :old.IRID
    ;
 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 delete SDD_ACRORG fktab
  where 
        fktab.ACTOR_REF = :old.IRID
    ;
 delete SDD_ACUACR fktab
  where 
        fktab.ACTOR_REF = :old.IRID
    ;
 delete SDD_CLA fktab
  where 
        fktab.ACTOR_REF = :old.IRID
    ;
 delete SDD_PERACR fktab
  where 
        fktab.ACTOR_REF = :old.IRID
    ;
 delete SDD_USCACR fktab
  where 
        fktab.ACTOR_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_ACR_d;
/
create or replace trigger SDD_ACRACR_br
  before insert or update or delete on i$SDD_ACRACR
  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.SUBTYPE_ACTOR_REF is not null)
       )
    or (updating and (
        (:new.SUBTYPE_ACTOR_REF != :old.SUBTYPE_ACTOR_REF
        or (:new.SUBTYPE_ACTOR_REF is not null and :old.SUBTYPE_ACTOR_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_ACR owning_tab
        where  owning_tab.IRID=:new.SUBTYPE_ACTOR_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_ACRACR_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_ACRACR');
  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_ACRACR_br;
/
create or replace trigger SDD_ACRACR_inv
after insert or update of
  SUPERTYPE_ACTOR_REF
 ,SEQUENCE
on i$SDD_ACRACR
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 := 384781276397749435723874459331348537;
  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_ACRACR_inv;
/
create or replace trigger SDD_ACRACR_val
after insert or update of
  SUPERTYPE_ACTOR_REF
 ,SEQUENCE
on i$SDD_ACRACR
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 := 384781276397749435723874459331348537;
  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_ACRACR(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_ACRACR) violated');
    end if;
    if not UK_ACRACR_2(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (UK_ACRACR_2) violated');
    end if;
    if not FK_ACRACR_TO_ACR2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ACRACR_TO_ACR2) 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_ACRACR_val;
/
create or replace trigger SDD_ACRACR_d
  instead of delete on SDD_ACRACR 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_ACRACR 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_ACRACR
   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_ACRACR_d;
/
create or replace trigger SDD_ACRORG_br
  before insert or update or delete on i$SDD_ACRORG
  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.ORGANIZATION_UNIT_REF is not null)
       )
    or (updating and (
        (:new.ORGANIZATION_UNIT_REF != :old.ORGANIZATION_UNIT_REF
        or (:new.ORGANIZATION_UNIT_REF is not null and :old.ORGANIZATION_UNIT_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_ORG owning_tab
        where  owning_tab.IRID=:new.ORGANIZATION_UNIT_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_ACRORG_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_ACRORG');
  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_ACRORG_br;
/
create or replace trigger SDD_ACRORG_inv
after insert or update of
  ACTOR_REF
on i$SDD_ACRORG
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 := 384781276397919440917257766559041593;
  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_ACRORG_inv;
/
create or replace trigger SDD_ACRORG_val
after insert or update of
  ACTOR_REF
on i$SDD_ACRORG
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 := 384781276397919440917257766559041593;
  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_ACRORG(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_ACRORG) violated');
    end if;
    if not FK_ACRORG_TO_ACR(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ACRORG_TO_ACR) 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_ACRORG_val;
/
create or replace trigger SDD_ACRORG_d
  instead of delete on SDD_ACRORG 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_ACRORG 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_ACRORG
   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_ACRORG_d;
/
create or replace trigger SDD_ACT_br
  before insert or update or delete on i$SDD_ACT
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_ACT_br;
/
create or replace trigger SDD_ACT_ar
  after insert or update or delete on i$SDD_ACT
  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 => 384781276398065834278226725560666169
    );
  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_ACT'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_ACT_ar;
/
create or replace trigger SDD_ACT_inv
after insert or update of
  ICON_FILE_REF
 ,EXECUTABLE_FILE_REF
 ,MAPPING_FILE_REF
 ,GENERAL_ACTION_REF
 ,METHOD_REF
 ,PACKAGE_REF
 ,PRE_RULE_REF
 ,POST_RULE_REF
 ,USE_CASE_REF
on i$SDD_ACT
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 := 384781276398065834278226725560666169;
  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_ACT_inv;
/
create or replace trigger SDD_ACT_val
after insert or update of
  ICON_FILE_REF
 ,EXECUTABLE_FILE_REF
 ,MAPPING_FILE_REF
 ,GENERAL_ACTION_REF
 ,METHOD_REF
 ,PACKAGE_REF
 ,PRE_RULE_REF
 ,POST_RULE_REF
 ,USE_CASE_REF
on i$SDD_ACT
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 := 384781276398065834278226725560666169;
  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_ACT(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_ACT) violated');
    end if;
    if not FK_ACT_TO_FILES(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ACT_TO_FILES) violated - parent key not found');
    end if;
    if not FK_ACT_TO_FILES2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ACT_TO_FILES2) violated - parent key not found');
    end if;
    if not FK_ACT_TO_FILES3(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ACT_TO_FILES3) violated - parent key not found');
    end if;
    if not FK_ACT_TO_GEA(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ACT_TO_GEA) violated - parent key not found');
    end if;
    if not FK_ACT_TO_MET(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ACT_TO_MET) violated - parent key not found');
    end if;
    if not FK_ACT_TO_PCK(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ACT_TO_PCK) violated - parent key not found');
    end if;
    if not FK_ACT_TO_RUL(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ACT_TO_RUL) violated - parent key not found');
    end if;
    if not FK_ACT_TO_RUL2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ACT_TO_RUL2) violated - parent key not found');
    end if;
    if not FK_ACT_TO_USC(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ACT_TO_USC) 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_ACT_val;
/
create or replace trigger SDD_ACT_d
  instead of delete on SDD_ACT 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_ACTACT fktab
  where 
        fktab.CHILD_ACTIVITY_REF = :old.IRID
    ;
 delete SDD_TRA fktab
  where 
        fktab.TARGET_ACTIVITY_REF = :old.IRID
    ;
 if jr_context.workarea is not null then
  delete SDD_TRA
   where ivid in
   (select fktab.ivid
      from i$SDD_TRA 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.TARGET_ACT_USAGE_REF in (select parent_tab.IRID
                                                    from i$SDD_ACTORG parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_TRA
   where ivid in
   (select fktab.ivid
      from i$SDD_TRA fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.TARGET_ACT_USAGE_REF in (select parent_tab.IRID
                                                    from i$SDD_ACTORG parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_ACTORG
     set ACTIVITY_USAGE_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_ACTORG 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.ACTIVITY_USAGE_REF in (select parent_tab.IRID
                                                      from i$SDD_ACTORG parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_ACTORG
     set ACTIVITY_USAGE_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_ACTORG fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.ACTIVITY_USAGE_REF in (select parent_tab.IRID
                                                      from i$SDD_ACTORG parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_ACTORG
     set ACTIVITY_USAGE_ERROR_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_ACTORG 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.ACTIVITY_USAGE_ERROR_REF in (select parent_tab.IRID
                                                      from i$SDD_ACTORG parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_ACTORG
     set ACTIVITY_USAGE_ERROR_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_ACTORG fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.ACTIVITY_USAGE_ERROR_REF in (select parent_tab.IRID
                                                      from i$SDD_ACTORG parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_TRA
     set TRANSITION_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_TRA 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.TRANSITION_REF in (select parent_tab.IRID
                                                      from i$SDD_TRA parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_TRA
     set TRANSITION_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_TRA fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.TRANSITION_REF in (select parent_tab.IRID
                                                      from i$SDD_TRA 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_ACT_d;
/
create or replace trigger SDD_ACTACT_br
  before insert or update or delete on i$SDD_ACTACT
  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_ACTIVITY_REF is not null)
       )
    or (updating and (
        (:new.PARENT_ACTIVITY_REF != :old.PARENT_ACTIVITY_REF
        or (:new.PARENT_ACTIVITY_REF is not null and :old.PARENT_ACTIVITY_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_ACT owning_tab
        where  owning_tab.IRID=:new.PARENT_ACTIVITY_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_ACTACT_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_ACTACT');
  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_ACTACT_br;
/
create or replace trigger SDD_ACTACT_inv
after insert or update of
  CHILD_ACTIVITY_REF
on i$SDD_ACTACT
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 := 384781276398316119701818816756992057;
  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_ACTACT_inv;
/
create or replace trigger SDD_ACTACT_val
after insert or update of
  CHILD_ACTIVITY_REF
on i$SDD_ACTACT
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 := 384781276398316119701818816756992057;
  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_ACTACT(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_ACTACT) violated');
    end if;
    if not FK_ACTACT_TO_ACT2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ACTACT_TO_ACT2) 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_ACTACT_val;
/
create or replace trigger SDD_ACTACT_d
  instead of delete on SDD_ACTACT 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_ACTACT 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_ACTACT
   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_ACTACT_d;
/
create or replace trigger SDD_ACTE1_br
  before insert or update or delete on i$SDD_ACTE1
  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.ACTIVITY_DEFINITION_REF is not null)
       )
    or (updating and (
        (:new.ACTIVITY_DEFINITION_REF != :old.ACTIVITY_DEFINITION_REF
        or (:new.ACTIVITY_DEFINITION_REF is not null and :old.ACTIVITY_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_ACT owning_tab
        where  owning_tab.IRID=:new.ACTIVITY_DEFINITION_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_ACTE1_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_ACTE1');
  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_ACTE1_br;
/
create or replace trigger SDD_ACTE1_inv
after insert or update of
  OBJECTIVE_REF
on i$SDD_ACTE1
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 := 415825818357693591475129210738591801;
  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_ACTE1_inv;
/
create or replace trigger SDD_ACTE1_val
after insert or update of
  OBJECTIVE_REF
on i$SDD_ACTE1
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 := 415825818357693591475129210738591801;
  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_ACTE1(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_ACTE1) violated');
    end if;
    if not FK_ACTE1_TO_E1(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ACTE1_TO_E1) 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_ACTE1_val;
/
create or replace trigger SDD_ACTE1_d
  instead of delete on SDD_ACTE1 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_ACTE1 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_ACTE1
   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_ACTE1_d;
/
create or replace trigger SDD_ACTORG_br
  before insert or update or delete on i$SDD_ACTORG
  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.ACTIVITY_REF is not null)
       )
    or (updating and (
        (:new.ACTIVITY_REF != :old.ACTIVITY_REF
        or (:new.ACTIVITY_REF is not null and :old.ACTIVITY_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_ACT owning_tab
        where  owning_tab.IRID=:new.ACTIVITY_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_ACTORG_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_ACTORG');
  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_ACTORG_br;
/
create or replace trigger SDD_ACTORG_inv
after insert or update of
  ACTIVITY_USAGE_REF
 ,ACTIVITY_USAGE_ERROR_REF
 ,ORGANIZATION_UNIT_REF
 ,WORKFLOW_ITEM_TYPE_REF
 ,WORKFLOW_MESS_TYPE_REF
on i$SDD_ACTORG
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 := 384781276398462513062787775758616633;
  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_ACTORG_inv;
/
create or replace trigger SDD_ACTORG_val
after insert or update of
  ACTIVITY_USAGE_REF
 ,ACTIVITY_USAGE_ERROR_REF
 ,ORGANIZATION_UNIT_REF
 ,WORKFLOW_ITEM_TYPE_REF
 ,WORKFLOW_MESS_TYPE_REF
on i$SDD_ACTORG
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 := 384781276398462513062787775758616633;
  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_ACTORG(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_ACTORG) violated');
    end if;
    if not FK_ACTORG_TO_ACTORG(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ACTORG_TO_ACTORG) violated - parent key not found');
    end if;
    if not FK_ACTORG_TO_ACTORG2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ACTORG_TO_ACTORG2) violated - parent key not found');
    end if;
    if not FK_ACTORG_TO_ORG(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ACTORG_TO_ORG) violated - parent key not found');
    end if;
    if not FK_ACTORG_TO_WIT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ACTORG_TO_WIT) violated - parent key not found');
    end if;
    if not FK_ACTORG_TO_WMT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ACTORG_TO_WMT) 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_ACTORG_val;
/
create or replace trigger SDD_ACTORG_d
  instead of delete on SDD_ACTORG 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_ACTORG 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_TRA fktab
  where 
        fktab.TARGET_ACT_USAGE_REF = :old.IRID
    ;
  delete SDD_ACUACR fktab
   where 
         fktab.ACTIVITY_USAGE_REF = :old.IRID
    ;
  delete SDD_TRA fktab
   where 
         fktab.SOURCE_ACT_USAGE_REF = :old.IRID
    ;
 update SDD_ACTORG fktab
    set 
        fktab.ACTIVITY_USAGE_REF = NULL
  where 
        fktab.ACTIVITY_USAGE_REF = :old.IRID
 ;
 update SDD_ACTORG fktab
    set 
        fktab.ACTIVITY_USAGE_ERROR_REF = NULL
  where 
        fktab.ACTIVITY_USAGE_ERROR_REF = :old.IRID
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_ACTORG
   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_ACTORG_d;
/
create or replace trigger SDD_ACUACR_br
  before insert or update or delete on i$SDD_ACUACR
  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.ACTIVITY_USAGE_REF is not null)
       )
    or (updating and (
        (:new.ACTIVITY_USAGE_REF != :old.ACTIVITY_USAGE_REF
        or (:new.ACTIVITY_USAGE_REF is not null and :old.ACTIVITY_USAGE_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_ACTORG owning_tab
        where  owning_tab.IRID=:new.ACTIVITY_USAGE_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_ACUACR_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_ACUACR');
  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_ACUACR_br;
/
create or replace trigger SDD_ACUACR_inv
after insert or update of
  ACTOR_REF
on i$SDD_ACUACR
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 := 384781276398741132685277084826224697;
  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_ACUACR_inv;
/
create or replace trigger SDD_ACUACR_val
after insert or update of
  ACTOR_REF
on i$SDD_ACUACR
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 := 384781276398741132685277084826224697;
  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_ACUACR(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_ACUACR) violated');
    end if;
    if not FK_ACUACR_TO_ACR(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ACUACR_TO_ACR) 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_ACUACR_val;
/
create or replace trigger SDD_ACUACR_d
  instead of delete on SDD_ACUACR 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_ACUACR 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_ACUACR
   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_ACUACR_d;
/
create or replace trigger SDD_ADR_br
  before insert or update or delete on i$SDD_ADR
  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_ATTRIBUTE_REF is not null)
       )
    or (updating and (
        (:new.CLASSIFIER_ATTRIBUTE_REF != :old.CLASSIFIER_ATTRIBUTE_REF
        or (:new.CLASSIFIER_ATTRIBUTE_REF is not null and :old.CLASSIFIER_ATTRIBUTE_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_CAT owning_tab
        where  owning_tab.IRID=:new.CLASSIFIER_ATTRIBUTE_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_ADR_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_ADR');
  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_ADR_br;
/
create or replace trigger SDD_ADR_inv
after insert or update of
  LANGUAGE_REF
 ,METHOD_REF
on i$SDD_ADR
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 := 384781276398896970779211783118276665;
  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_ADR_inv;
/
create or replace trigger SDD_ADR_val
after insert or update of
  LANGUAGE_REF
 ,METHOD_REF
on i$SDD_ADR
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 := 384781276398896970779211783118276665;
  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_ADR(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_ADR) violated');
    end if;
    if not FK_ADR_TO_LAN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ADR_TO_LAN) violated - parent key not found');
    end if;
    if not FK_ADR_TO_MET(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ADR_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_ADR_val;
/
create or replace trigger SDD_ADR_d
  instead of delete on SDD_ADR 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_ADR 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_METRUL fktab
  where 
        fktab.ATTRIBUTE_DERIV_RULE_REF = :old.IRID
    ;
  delete SDD_MEMCOM fktab
   where 
         fktab.ATTRIBUTE_DERIV_RULE_REF = :old.IRID
    ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_ADR
   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_ADR_d;
/
create or replace trigger SDD_AEN_br
  before insert or update or delete on i$SDD_AEN
  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_AEN_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_AEN');
  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_AEN_br;
/
create or replace trigger SDD_AEN_inv
after insert or update of
  CLASSIFIER_REF
 ,ENTITY_OBJECT_REF
 ,GENERIC_CLASS_REF
 ,INTERFACE_CLASSIFIER_REF
 ,UNIQUENESS_RULE_REF
on i$SDD_AEN
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 := 384781276399071698339077959991183417;
  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_AEN_inv;
/
create or replace trigger SDD_AEN_val
after insert or update of
  CLASSIFIER_REF
 ,ENTITY_OBJECT_REF
 ,GENERIC_CLASS_REF
 ,INTERFACE_CLASSIFIER_REF
 ,UNIQUENESS_RULE_REF
on i$SDD_AEN
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 := 384781276399071698339077959991183417;
  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_AEN(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_AEN) violated');
    end if;
    if not FK_AEN_TO_CLA(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_AEN_TO_CLA) violated - parent key not found');
    end if;
    if not FK_AEN_TO_EOC(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_AEN_TO_EOC) violated - parent key not found');
    end if;
    if not FK_AEN_TO_GEC(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_AEN_TO_GEC) violated - parent key not found');
    end if;
    if not FK_AEN_TO_INC(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_AEN_TO_INC) violated - parent key not found');
    end if;
    if not FK_AEN_TO_UNR(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_AEN_TO_UNR) 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_AEN_val;
/
create or replace trigger SDD_AEN_d
  instead of delete on SDD_AEN 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_AEN 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_AEU_TO_AEN_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_CMA_TO_AEN_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_AEU fktab
   where 
         fktab.ASSOCIATION_END_REF = :old.IRID
    ;
  update SDD_CMA fktab
     set 
         fktab.ASSOCIATION_END_REF = NULL
   where 
         fktab.ASSOCIATION_END_REF = :old.IRID
  ;
 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 delete SDD_ASSASS fktab
  where 
        fktab.USE_OF_ASSOC_END_REF = :old.IRID
    ;
 delete SDD_CLAAEN fktab
  where 
        fktab.ASSOCIATION_END_REF = :old.IRID
    ;
 delete SDD_DATCOM fktab
  where 
        fktab.ASSOCIATION_END_REF = :old.IRID
    ;
 delete SDD_MEMCOM fktab
  where 
        fktab.ASSOCIATION_END_REF = :old.IRID
    ;
  delete SDD_AENEAT fktab
   where 
         fktab.ASSOCIATION_END_REF = :old.IRID
    ;
  delete SDD_ASSASS fktab
   where 
         fktab.PART_OF_ASSOC_END_REF = :old.IRID
    ;
  delete SDD_CATAEN fktab
   where 
         fktab.ASSOCIATION_END_REF = :old.IRID
    ;
 update SDD_SUD fktab
    set 
        fktab.ASSOCIATION_END_REF = NULL
  where 
        fktab.ASSOCIATION_END_REF = :old.IRID
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_AEN
   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_AEN_d;
/
create or replace trigger SDD_AENEAT_br
  before insert or update or delete on i$SDD_AENEAT
  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_END_REF is not null)
       )
    or (updating and (
        (:new.ASSOCIATION_END_REF != :old.ASSOCIATION_END_REF
        or (:new.ASSOCIATION_END_REF is not null and :old.ASSOCIATION_END_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_AEN owning_tab
        where  owning_tab.IRID=:new.ASSOCIATION_END_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_AENEAT_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_AENEAT');
  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_AENEAT_br;
/
create or replace trigger SDD_AENEAT_inv
after insert or update of
  EO_ATTRIBUTE_FROM_REF
 ,EO_ATTRIBUTE_TO_REF
on i$SDD_AENEAT
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 := 415825818358930851493641057784580153;
  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_AENEAT_inv;
/
create or replace trigger SDD_AENEAT_val
after insert or update of
  EO_ATTRIBUTE_FROM_REF
 ,EO_ATTRIBUTE_TO_REF
on i$SDD_AENEAT
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 := 415825818358930851493641057784580153;
  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_AENEAT(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_AENEAT) violated');
    end if;
    if not FK_AENEAT_TO_EAT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_AENEAT_TO_EAT) violated - parent key not found');
    end if;
    if not FK_AENEAT_TO_EAT2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_AENEAT_TO_EAT2) 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_AENEAT_val;
/
create or replace trigger SDD_AENEAT_d
  instead of delete on SDD_AENEAT 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_AENEAT 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_AENEAT
   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_AENEAT_d;
/
create or replace trigger SDD_AEU_br
  before insert or update or delete on i$SDD_AEU
  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.ENTITY_OBJECT_USAGE_REF is not null)
       )
    or (updating and (
        (:new.ENTITY_OBJECT_USAGE_REF != :old.ENTITY_OBJECT_USAGE_REF
        or (:new.ENTITY_OBJECT_USAGE_REF is not null and :old.ENTITY_OBJECT_USAGE_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_EOU owning_tab
        where  owning_tab.IRID=:new.ENTITY_OBJECT_USAGE_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_AEU_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_AEU');
  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_AEU_br;
/
create or replace trigger SDD_AEU_inv
after insert or update of
  ASSOCIATION_END_REF
on i$SDD_AEU
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 := 384781276399355040328050138704005177;
  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_AEU_inv;
/
create or replace trigger SDD_AEU_val
after insert or update of
  ASSOCIATION_END_REF
on i$SDD_AEU
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 := 384781276399355040328050138704005177;
  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_AEU(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_AEU) violated');
    end if;
    if not FK_AEU_TO_AEN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_AEU_TO_AEN) 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_AEU_val;
/
create or replace trigger SDD_AEU_d
  instead of delete on SDD_AEU 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_AEU 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_VLE_TO_AEU_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_VLE fktab
     set 
         fktab.ASSOC_END_USAGE_REF = NULL
   where 
         fktab.ASSOC_END_USAGE_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_AEU
   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_AEU_d;
/
create or replace trigger SDD_AMCAMC_br
  before insert or update or delete on i$SDD_AMCAMC
  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_APP_MODULE_REF is not null)
       )
    or (updating and (
        (:new.PARENT_APP_MODULE_REF != :old.PARENT_APP_MODULE_REF
        or (:new.PARENT_APP_MODULE_REF is not null and :old.PARENT_APP_MODULE_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.PARENT_APP_MODULE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_AMCAMC_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_AMCAMC');
  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_AMCAMC_br;
/
create or replace trigger SDD_AMCAMC_inv
after insert or update of
  CHILD_APP_MODULE_REF
on i$SDD_AMCAMC
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 := 384781276399501433689019097705629753;
  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_AMCAMC_inv;
/
create or replace trigger SDD_AMCAMC_val
after insert or update of
  CHILD_APP_MODULE_REF
on i$SDD_AMCAMC
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 := 384781276399501433689019097705629753;
  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_AMCAMC(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_AMCAMC) violated');
    end if;
    if not FK_AMCAMC_TO_AMC2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_AMCAMC_TO_AMC2) 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_AMCAMC_val;
/
create or replace trigger SDD_AMCAMC_d
  instead of delete on SDD_AMCAMC 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_AMCAMC 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_AMCAMC
   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_AMCAMC_d;
/
create or replace trigger SDD_AMCBOB_br
  before insert or update or delete on i$SDD_AMCBOB
  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.APPLICATION_MODULE_REF is not null)
       )
    or (updating and (
        (:new.APPLICATION_MODULE_REF != :old.APPLICATION_MODULE_REF
        or (:new.APPLICATION_MODULE_REF is not null and :old.APPLICATION_MODULE_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.APPLICATION_MODULE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_AMCBOB_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_AMCBOB');
  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_AMCBOB_br;
/
create or replace trigger SDD_AMCBOB_inv
after insert or update of
  BUSINESS_OBJECT_REF
on i$SDD_AMCBOB
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 := 415825818359417255241376631241590841;
  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_AMCBOB_inv;
/
create or replace trigger SDD_AMCBOB_val
after insert or update of
  BUSINESS_OBJECT_REF
on i$SDD_AMCBOB
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 := 415825818359417255241376631241590841;
  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_AMCBOB(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_AMCBOB) violated');
    end if;
    if not FK_AMCBOB_TO_BOB(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_AMCBOB_TO_BOB) 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_AMCBOB_val;
/
create or replace trigger SDD_AMCBOB_d
  instead of delete on SDD_AMCBOB 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_AMCBOB 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_AMCBOB
   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_AMCBOB_d;
/
create or replace trigger SDD_AMCPRJ_br
  before insert or update or delete on i$SDD_AMCPRJ
  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.APPLICATION_MODULE_REF is not null)
       )
    or (updating and (
        (:new.APPLICATION_MODULE_REF != :old.APPLICATION_MODULE_REF
        or (:new.APPLICATION_MODULE_REF is not null and :old.APPLICATION_MODULE_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.APPLICATION_MODULE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_AMCPRJ_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_AMCPRJ');
  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_AMCPRJ_br;
/
create or replace trigger SDD_AMCPRJ_inv
after insert or update of
  PROJECT_REF
on i$SDD_AMCPRJ
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 := 446766184098957235592952663718250553;
  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_AMCPRJ_inv;
/
create or replace trigger SDD_AMCPRJ_val
after insert or update of
  PROJECT_REF
on i$SDD_AMCPRJ
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 := 446766184098957235592952663718250553;
  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_AMCPRJ(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_AMCPRJ) violated');
    end if;
    if not FK_AMCPRJ_TO_PRJ(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_AMCPRJ_TO_PRJ) 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_AMCPRJ_val;
/
create or replace trigger SDD_AMCPRJ_d
  instead of delete on SDD_AMCPRJ 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_AMCPRJ 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_AMCPRJ
   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_AMCPRJ_d;
/
create or replace trigger SDD_ARG_br
  before insert or update or delete on i$SDD_ARG
  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_ARG_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_ARG_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_ARG');
  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_ARG_br;
/
create or replace trigger SDD_ARG_inv
after insert or update of
  COLUMN_REF
 ,DATASTRUCTURE_REF
 ,DOMAIN_REF
 ,GENERAL_MODULE_REF
 ,ORACLE_TYPE_REF
 ,PLSQL_MODULE_REF
 ,TABLE_DEFINITION_REF
on i$SDD_ARG
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 := 384781276399666716515919535288109113;
  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_ARG_inv;
/
create or replace trigger SDD_ARG_val
after insert or update of
  COLUMN_REF
 ,DATASTRUCTURE_REF
 ,DOMAIN_REF
 ,GENERAL_MODULE_REF
 ,ORACLE_TYPE_REF
 ,PLSQL_MODULE_REF
 ,TABLE_DEFINITION_REF
on i$SDD_ARG
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 := 384781276399666716515919535288109113;
  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_ARG(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_ARG) violated');
    end if;
    if not FK_ARG_TO_COL(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ARG_TO_COL) violated - parent key not found');
    end if;
    if not FK_ARG_TO_DAT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ARG_TO_DAT) violated - parent key not found');
    end if;
    if not FK_ARG_TO_DOM(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ARG_TO_DOM) violated - parent key not found');
    end if;
    if not FK_ARG_TO_GEM(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ARG_TO_GEM) violated - parent key not found');
    end if;
    if not FK_ARG_TO_ORT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ARG_TO_ORT) violated - parent key not found');
    end if;
    if not FK_ARG_TO_PLM(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ARG_TO_PLM) violated - parent key not found');
    end if;
    if not FK_ARG_TO_TBL(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ARG_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_ARG_val;
/
create or replace trigger SDD_ARG_d
  instead of delete on SDD_ARG 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_ARG 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_PVL_TO_ARG2_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_PVL fktab
   where 
         fktab.CALLED_ARGUMENT_REF = :old.IRID
    ;
 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
  delete SDD_ARGITE fktab
   where 
         fktab.MODULE_ARGUMENT_REF = :old.IRID
    ;
  delete SDD_ATV fktab
   where 
         fktab.MODULE_ARGUMENT_REF = :old.IRID
    ;
 update SDD_PVL fktab
    set 
        fktab.MODULE_ARGUMENT_REF = NULL
  where 
        fktab.MODULE_ARGUMENT_REF = :old.IRID
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_ARG
   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_ARG_d;
/
create or replace trigger SDD_ARGITE_br
  before insert or update or delete on i$SDD_ARGITE
  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_ARGUMENT_REF is not null)
       )
    or (updating and (
        (:new.MODULE_ARGUMENT_REF != :old.MODULE_ARGUMENT_REF
        or (:new.MODULE_ARGUMENT_REF is not null and :old.MODULE_ARGUMENT_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_ARG owning_tab
        where  owning_tab.IRID=:new.MODULE_ARGUMENT_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_ARGITE_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_ARGITE');
  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_ARGITE_br;
/
create or replace trigger SDD_ARGITE_inv
after insert or update of
  ITEM_REF
on i$SDD_ARGITE
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 := 384781276400087007132894933712128057;
  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_ARGITE_inv;
/
create or replace trigger SDD_ARGITE_val
after insert or update of
  ITEM_REF
on i$SDD_ARGITE
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 := 384781276400087007132894933712128057;
  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_ARGITE(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_ARGITE) violated');
    end if;
    if not FK_ARGITE_TO_ITE(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ARGITE_TO_ITE) 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_ARGITE_val;
/
create or replace trigger SDD_ARGITE_d
  instead of delete on SDD_ARGITE 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_ARGITE 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_ARGITE
   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_ARGITE_d;
/
create or replace trigger SDD_ASS_br
  before insert or update or delete on i$SDD_ASS
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_ASS_br;
/
create or replace trigger SDD_ASS_ar
  after insert or update or delete on i$SDD_ASS
  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 => 384781276400512020116353201781360697
    );
  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_ASS'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_ASS_ar;
/
create or replace trigger SDD_ASS_inv
after insert or update of
  ASSOCIATION_REF
 ,BUSINESS_OBJECT_REF
 ,ENTITY_OBJECT_REF
 ,ICON_FILE_REF
 ,GENERIC_CLASS_REF
on i$SDD_ASS
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 := 384781276400512020116353201781360697;
  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_ASS_inv;
/
create or replace trigger SDD_ASS_val
after insert or update of
  ASSOCIATION_REF
 ,BUSINESS_OBJECT_REF
 ,ENTITY_OBJECT_REF
 ,ICON_FILE_REF
 ,GENERIC_CLASS_REF
on i$SDD_ASS
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 := 384781276400512020116353201781360697;
  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_ASS(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_ASS) violated');
    end if;
    if not FK_ASS_TO_ASS(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ASS_TO_ASS) violated - parent key not found');
    end if;
    if not FK_ASS_TO_BOB(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ASS_TO_BOB) violated - parent key not found');
    end if;
    if not FK_ASS_TO_EOC(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ASS_TO_EOC) violated - parent key not found');
    end if;
    if not FK_ASS_TO_FILES(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ASS_TO_FILES) violated - parent key not found');
    end if;
    if not FK_ASS_TO_GEC(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ASS_TO_GEC) 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_ASS_val;
/
create or replace trigger SDD_ASS_d
  instead of delete on SDD_ASS 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;
 update SDD_ASS fktab
    set 
        fktab.ASSOCIATION_REF = NULL
  where 
        fktab.ASSOCIATION_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
 ;
 delete SDD_ASS fktab
  where 
        fktab.ASSOCIATION_REF = :old.IRID
    and fktab.ivid in (select o.ivid
                        from I$SDD_OBJECT_VERSIONS o
                       where o.state='I')
 ;
  if (NOT jr_wastebasket.force_flag) and jr_wastebasket.repos_constraints_enabled then
   if not FK_AEU_TO_AEN_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_CMA_TO_AEN_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
  elsif jr_wastebasket.force_flag then
  delete SDD_AEU fktab
   where fktab.ASSOCIATION_END_REF in (select parent_tab.IRID
                                                      from i$SDD_AEN parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_CMA fktab
     set 
         fktab.ASSOCIATION_END_REF = NULL
   where fktab.ASSOCIATION_END_REF in (select parent_tab.IRID
                                                    from i$SDD_AEN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  end if;--force delete/purge
 if jr_context.workarea is not null then
  delete SDD_ASSASS
   where ivid in
   (select fktab.ivid
      from i$SDD_ASSASS 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.USE_OF_ASSOC_END_REF in (select parent_tab.IRID
                                                    from i$SDD_AEN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_ASSASS
   where ivid in
   (select fktab.ivid
      from i$SDD_ASSASS fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.USE_OF_ASSOC_END_REF in (select parent_tab.IRID
                                                    from i$SDD_AEN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_CLAAEN
   where ivid in
   (select fktab.ivid
      from i$SDD_CLAAEN 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.ASSOCIATION_END_REF in (select parent_tab.IRID
                                                    from i$SDD_AEN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_CLAAEN
   where ivid in
   (select fktab.ivid
      from i$SDD_CLAAEN fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.ASSOCIATION_END_REF in (select parent_tab.IRID
                                                    from i$SDD_AEN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_DATCOM
   where ivid in
   (select fktab.ivid
      from i$SDD_DATCOM 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.ASSOCIATION_END_REF in (select parent_tab.IRID
                                                    from i$SDD_AEN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_DATCOM
   where ivid in
   (select fktab.ivid
      from i$SDD_DATCOM fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.ASSOCIATION_END_REF in (select parent_tab.IRID
                                                    from i$SDD_AEN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_MEMCOM
   where ivid in
   (select fktab.ivid
      from i$SDD_MEMCOM 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.ASSOCIATION_END_REF in (select parent_tab.IRID
                                                    from i$SDD_AEN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_MEMCOM
   where ivid in
   (select fktab.ivid
      from i$SDD_MEMCOM fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.ASSOCIATION_END_REF in (select parent_tab.IRID
                                                    from i$SDD_AEN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_SUD
     set ASSOCIATION_END_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_SUD 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.ASSOCIATION_END_REF in (select parent_tab.IRID
                                                      from i$SDD_AEN parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_SUD
     set ASSOCIATION_END_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_SUD fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.ASSOCIATION_END_REF in (select parent_tab.IRID
                                                      from i$SDD_AEN 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_ASS_d;
/
create or replace trigger SDD_ASSASS_br
  before insert or update or delete on i$SDD_ASSASS
  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.PART_OF_ASSOC_END_REF is not null)
       )
    or (updating and (
        (:new.PART_OF_ASSOC_END_REF != :old.PART_OF_ASSOC_END_REF
        or (:new.PART_OF_ASSOC_END_REF is not null and :old.PART_OF_ASSOC_END_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_AEN owning_tab
        where  owning_tab.IRID=:new.PART_OF_ASSOC_END_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_ASSASS_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_ASSASS');
  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_ASSASS_br;
/
create or replace trigger SDD_ASSASS_inv
after insert or update of
  USE_OF_ASSOC_END_REF
on i$SDD_ASSASS
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 := 384781276400729248974565205461190713;
  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_ASSASS_inv;
/
create or replace trigger SDD_ASSASS_val
after insert or update of
  USE_OF_ASSOC_END_REF
on i$SDD_ASSASS
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 := 384781276400729248974565205461190713;
  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_ASSASS(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_ASSASS) violated');
    end if;
    if not FK_ASSASS_TO_AEN2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ASSASS_TO_AEN2) 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_ASSASS_val;
/
create or replace trigger SDD_ASSASS_d
  instead of delete on SDD_ASSASS 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_ASSASS 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_ASSASS
   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_ASSASS_d;
/
create or replace trigger SDD_ATT_br
  before insert or update or delete on i$SDD_ATT
  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.ENTITY_REF is not null)
       )
    or (updating and (
        (:new.ENTITY_REF != :old.ENTITY_REF
        or (:new.ENTITY_REF is not null and :old.ENTITY_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_ENT owning_tab
        where  owning_tab.IRID=:new.ENTITY_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_ATT_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_ATT');
  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_ATT_br;
/
create or replace trigger SDD_ATT_inv
after insert or update of
  DOMAIN_REF
on i$SDD_ATT
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 := 384781276401083426460780428852217913;
  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_ATT_inv;
/
create or replace trigger SDD_ATT_val
after insert or update of
  DOMAIN_REF
on i$SDD_ATT
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 := 384781276401083426460780428852217913;
  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_ATT(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_ATT) violated');
    end if;
    if not FK_ATT_TO_DOM(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ATT_TO_DOM) 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_ATT_val;
/
create or replace trigger SDD_ATT_d
  instead of delete on SDD_ATT 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_ATT 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;
   if not FK_ENTUIE_TO_ATT_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_EVT_TO_ATT_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_ENTUIE fktab
   where 
         fktab.ATTRIBUTE_REF = :old.IRID
    ;
  update SDD_EVT fktab
     set 
         fktab.ATTRIBUTE_REF = NULL
   where 
         fktab.ATTRIBUTE_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
  ;
  delete SDD_EVT fktab
   where 
         fktab.ATTRIBUTE_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_DFLATT fktab
  where 
        fktab.ATTRIBUTE_REF = :old.IRID
    ;
 delete SDD_DSTATT fktab
  where 
        fktab.ATTRIBUTE_REF = :old.IRID
    ;
 delete SDD_FUNATT fktab
  where 
        fktab.ATTRIBUTE_REF = :old.IRID
    ;
  delete SDD_ATV fktab
   where 
         fktab.ATTRIBUTE_REF = :old.IRID
    ;
 update SDD_COL fktab
    set 
        fktab.SOURCE_ATTRIBUTE_REF = NULL
  where 
        fktab.SOURCE_ATTRIBUTE_REF = :old.IRID
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_ATT
   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_ATT_d;
/
create or replace trigger SDD_ATV_br
  before insert or update or delete on i$SDD_ATV
  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.DOMAIN_REF is not null)
       )
    or (updating and (
        (:new.DOMAIN_REF != :old.DOMAIN_REF
        or (:new.DOMAIN_REF is not null and :old.DOMAIN_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_DOM owning_tab
        where  owning_tab.IRID=:new.DOMAIN_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_ATV_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.UNBOUND_ITEM_REF is not null)
       )
    or (updating and (
        (:new.UNBOUND_ITEM_REF != :old.UNBOUND_ITEM_REF
        or (:new.UNBOUND_ITEM_REF is not null and :old.UNBOUND_ITEM_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_ITE owning_tab
        where  owning_tab.IRID=:new.UNBOUND_ITEM_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_ATV_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.MODULE_ARGUMENT_REF is not null)
       )
    or (updating and (
        (:new.MODULE_ARGUMENT_REF != :old.MODULE_ARGUMENT_REF
        or (:new.MODULE_ARGUMENT_REF is not null and :old.MODULE_ARGUMENT_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_ARG owning_tab
        where  owning_tab.IRID=:new.MODULE_ARGUMENT_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_ATV_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.ATTRIBUTE_REF is not null)
       )
    or (updating and (
        (:new.ATTRIBUTE_REF != :old.ATTRIBUTE_REF
        or (:new.ATTRIBUTE_REF is not null and :old.ATTRIBUTE_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_ATT owning_tab
        where  owning_tab.IRID=:new.ATTRIBUTE_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_ATV_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.COLUMN_REF is not null)
       )
    or (updating and (
        (:new.COLUMN_REF != :old.COLUMN_REF
        or (:new.COLUMN_REF is not null and :old.COLUMN_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_COL owning_tab
        where  owning_tab.IRID=:new.COLUMN_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_ATV_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_ATV');
  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_ATV_br;
/
create or replace trigger SDD_ATV_inv
after insert
on i$SDD_ATV
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 := 384781276401442326313478521888458809;
  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_ATV_inv;
/
create or replace trigger SDD_ATV_val
after insert
on i$SDD_ATV
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 := 384781276401442326313478521888458809;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_ATV(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_ATV) 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_ATV_val;
/
create or replace trigger SDD_ATV_d
  instead of delete on SDD_ATV 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_ATV 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_ATV
   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_ATV_d;
/
create or replace trigger SDD_BAT_br
  before insert or update or delete on i$SDD_BAT
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_BAT_br;
/
create or replace trigger SDD_BAT_ar
  after insert or update or delete on i$SDD_BAT
  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 => 384781276401758724867830788117776441
    );
  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_BAT'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_BAT_ar;
/
create or replace trigger SDD_BAT_inv
after insert
on i$SDD_BAT
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 := 384781276401758724867830788117776441;
  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_BAT_inv;
/
create or replace trigger SDD_BAT_val
after insert
on i$SDD_BAT
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 := 384781276401758724867830788117776441;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_BAT(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_BAT) 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_BAT_val;
/
create or replace trigger SDD_BAT_d
  instead of delete on SDD_BAT 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 jr_context.workarea is not null then
  delete SDD_BRUBLI
   where ivid in
   (select fktab.ivid
      from i$SDD_BRUBLI 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.BATCHLINE_REF in (select parent_tab.IRID
                                                    from i$SDD_BLI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_BRUBLI
   where ivid in
   (select fktab.ivid
      from i$SDD_BRUBLI fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.BATCHLINE_REF in (select parent_tab.IRID
                                                    from i$SDD_BLI 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_BAT_d;
/
create or replace trigger SDD_BLI_br
  before insert or update or delete on i$SDD_BLI
  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.BATCH_REF is not null)
       )
    or (updating and (
        (:new.BATCH_REF != :old.BATCH_REF
        or (:new.BATCH_REF is not null and :old.BATCH_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_BAT owning_tab
        where  owning_tab.IRID=:new.BATCH_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_BLI_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_BLI');
  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_BLI_br;
/
create or replace trigger SDD_BLI_inv
after insert or update of
  DATABASE_USER_REF
 ,GENERAL_MODULE_REF
on i$SDD_BLI
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 := 384781276401971231359559922152392761;
  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_BLI_inv;
/
create or replace trigger SDD_BLI_val
after insert or update of
  DATABASE_USER_REF
 ,GENERAL_MODULE_REF
on i$SDD_BLI
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 := 384781276401971231359559922152392761;
  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_BLI(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_BLI) violated');
    end if;
    if not FK_BLI_TO_DBU(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_BLI_TO_DBU) violated - parent key not found');
    end if;
    if not FK_BLI_TO_GEM(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_BLI_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_BLI_val;
/
create or replace trigger SDD_BLI_d
  instead of delete on SDD_BLI 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_BLI 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_BRUBLI fktab
  where 
        fktab.BATCHLINE_REF = :old.IRID
    ;
  delete SDD_COB fktab
   where 
         fktab.BATCHLINE_REF = :old.IRID
    ;
  delete SDD_SOU fktab
   where 
         fktab.BATCHLINE_REF = :old.IRID
    ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_BLI
   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_BLI_d;
/
create or replace trigger SDD_BOB_br
  before insert or update or delete on i$SDD_BOB
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_BOB_br;
/
create or replace trigger SDD_BOB_ar
  after insert or update or delete on i$SDD_BOB
  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 => 384781276402268740447980709800855609
    );
  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_BOB'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_BOB_ar;
/
create or replace trigger SDD_BOB_inv
after insert or update of
  ENTITY_OBJECT_REF
 ,ICON_FILE_REF
 ,GENERIC_CLASS_REF
on i$SDD_BOB
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 := 384781276402268740447980709800855609;
  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_BOB_inv;
/
create or replace trigger SDD_BOB_val
after insert or update of
  ENTITY_OBJECT_REF
 ,ICON_FILE_REF
 ,GENERIC_CLASS_REF
on i$SDD_BOB
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 := 384781276402268740447980709800855609;
  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_BOB(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_BOB) violated');
    end if;
    if not FK_BOB_TO_EOC(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_BOB_TO_EOC) violated - parent key not found');
    end if;
    if not FK_BOB_TO_FILES(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_BOB_TO_FILES) violated - parent key not found');
    end if;
    if not FK_BOB_TO_GEC(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_BOB_TO_GEC) 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_BOB_val;
/
create or replace trigger SDD_BOB_d
  instead of delete on SDD_BOB 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_AMCBOB fktab
  where 
        fktab.BUSINESS_OBJECT_REF = :old.IRID
    ;
 update SDD_ASS fktab
    set 
        fktab.BUSINESS_OBJECT_REF = NULL
  where 
        fktab.BUSINESS_OBJECT_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
 ;
 delete SDD_ASS fktab
  where 
        fktab.BUSINESS_OBJECT_REF = :old.IRID
    and fktab.ivid in (select o.ivid
                        from I$SDD_OBJECT_VERSIONS o
                       where o.state='I')
 ;
 update SDD_CLA fktab
    set 
        fktab.BUSINESS_OBJECT_REF = NULL
  where 
        fktab.BUSINESS_OBJECT_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
 ;
 delete SDD_CLA fktab
  where 
        fktab.BUSINESS_OBJECT_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_CLA
   where ivid in
   (select fktab.ivid
      from i$SDD_CLA fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.OBJECT_STATE_REF in (select parent_tab.IRID
                                                    from i$SDD_OST parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_CLA
   where ivid in
   (select fktab.ivid
      from i$SDD_CLA fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.OBJECT_STATE_REF in (select parent_tab.IRID
                                                    from i$SDD_OST parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_OSTOST
   where ivid in
   (select fktab.ivid
      from i$SDD_OSTOST 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.OBJECT_STATE_OF_REF in (select parent_tab.IRID
                                                    from i$SDD_OST parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_OSTOST
   where ivid in
   (select fktab.ivid
      from i$SDD_OSTOST fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.OBJECT_STATE_OF_REF in (select parent_tab.IRID
                                                    from i$SDD_OST parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_TRA
   where ivid in
   (select fktab.ivid
      from i$SDD_TRA 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.TARGET_OBJECT_STATE_REF in (select parent_tab.IRID
                                                    from i$SDD_OST parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_TRA
   where ivid in
   (select fktab.ivid
      from i$SDD_TRA fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.TARGET_OBJECT_STATE_REF in (select parent_tab.IRID
                                                    from i$SDD_OST parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_METRUL
   where ivid in
   (select fktab.ivid
      from i$SDD_METRUL 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.STATE_RULE_REF in (select parent_tab.IRID
                                                    from i$SDD_SRU parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_METRUL
   where ivid in
   (select fktab.ivid
      from i$SDD_METRUL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.STATE_RULE_REF in (select parent_tab.IRID
                                                    from i$SDD_SRU parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_TRA
     set TRANSITION_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_TRA 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.TRANSITION_REF in (select parent_tab.IRID
                                                      from i$SDD_TRA parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_TRA
     set TRANSITION_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_TRA fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.TRANSITION_REF in (select parent_tab.IRID
                                                      from i$SDD_TRA 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_BOB_d;
/
create or replace trigger SDD_BOBINC_br
  before insert or update or delete on i$SDD_BOBINC
  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.BUSINESS_OBJECT_REF is not null)
       )
    or (updating and (
        (:new.BUSINESS_OBJECT_REF != :old.BUSINESS_OBJECT_REF
        or (:new.BUSINESS_OBJECT_REF is not null and :old.BUSINESS_OBJECT_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_BOB owning_tab
        where  owning_tab.IRID=:new.BUSINESS_OBJECT_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_BOBINC_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_BOBINC');
  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_BOBINC_br;
/
create or replace trigger SDD_BOBINC_inv
after insert or update of
  INTERFACE_CLASSIFIER_REF
on i$SDD_BOBINC
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 := 384781276402410411442466799157266489;
  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_BOBINC_inv;
/
create or replace trigger SDD_BOBINC_val
after insert or update of
  INTERFACE_CLASSIFIER_REF
on i$SDD_BOBINC
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 := 384781276402410411442466799157266489;
  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_BOBINC(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_BOBINC) violated');
    end if;
    if not FK_BOBINC_TO_INC(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_BOBINC_TO_INC) 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_BOBINC_val;
/
create or replace trigger SDD_BOBINC_d
  instead of delete on SDD_BOBINC 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_BOBINC 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_BOBINC
   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_BOBINC_d;
/
create or replace trigger SDD_BRL_br
  before insert or update or delete on i$SDD_BRL
  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.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_BRL_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.VIEW_IMPLEMENTATION_REF is not null)
       )
    or (updating and (
        (:new.VIEW_IMPLEMENTATION_REF != :old.VIEW_IMPLEMENTATION_REF
        or (:new.VIEW_IMPLEMENTATION_REF is not null and :old.VIEW_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.VIEW_IMPLEMENTATION_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_BRL_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_BRL');
  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_BRL_br;
/
create or replace trigger SDD_BRL_inv
after insert or update of
  DATABASE_USER_REF
 ,RELATION_SELECTION_REF
on i$SDD_BRL
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 := 384781276402566249536401497449318457;
  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_BRL_inv;
/
create or replace trigger SDD_BRL_val
after insert or update of
  DATABASE_USER_REF
 ,RELATION_SELECTION_REF
on i$SDD_BRL
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 := 384781276402566249536401497449318457;
  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_BRL(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_BRL) violated');
    end if;
    if not FK_BRL_TO_DBU(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_BRL_TO_DBU) violated - parent key not found');
    end if;
    if not FK_BRL_TO_VWTAB(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_BRL_TO_VWTAB) 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_BRL_val;
/
create or replace trigger SDD_BRL_d
  instead of delete on SDD_BRL 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_BRL 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_BRL
   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_BRL_d;
/
create or replace trigger SDD_BRU_br
  before insert or update or delete on i$SDD_BRU
  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.BATCH_REF is not null)
       )
    or (updating and (
        (:new.BATCH_REF != :old.BATCH_REF
        or (:new.BATCH_REF is not null and :old.BATCH_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_BAT owning_tab
        where  owning_tab.IRID=:new.BATCH_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_BRU_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_BRU');
  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_BRU_br;
/
create or replace trigger SDD_BRU_inv
after insert
on i$SDD_BRU
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 := 384781276402844869158890806516926521;
  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_BRU_inv;
/
create or replace trigger SDD_BRU_val
after insert
on i$SDD_BRU
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 := 384781276402844869158890806516926521;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_BRU(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_BRU) 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_BRU_val;
/
create or replace trigger SDD_BRU_d
  instead of delete on SDD_BRU 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_BRU 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_BRUBLI fktab
   where 
         fktab.BATCH_RUN_REF = :old.IRID
    ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_BRU
   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_BRU_d;
/
create or replace trigger SDD_BRUBLI_br
  before insert or update or delete on i$SDD_BRUBLI
  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.BATCH_RUN_REF is not null)
       )
    or (updating and (
        (:new.BATCH_RUN_REF != :old.BATCH_RUN_REF
        or (:new.BATCH_RUN_REF is not null and :old.BATCH_RUN_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_BRU owning_tab
        where  owning_tab.IRID=:new.BATCH_RUN_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_BRUBLI_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_BRUBLI');
  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_BRUBLI_br;
/
create or replace trigger SDD_BRUBLI_inv
after insert or update of
  BATCHLINE_REF
on i$SDD_BRUBLI
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 := 384781276403095154582482897713252409;
  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_BRUBLI_inv;
/
create or replace trigger SDD_BRUBLI_val
after insert or update of
  BATCHLINE_REF
on i$SDD_BRUBLI
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 := 384781276403095154582482897713252409;
  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_BRUBLI(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_BRUBLI) violated');
    end if;
    if not FK_BRUBLI_TO_BLI(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_BRUBLI_TO_BLI) 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_BRUBLI_val;
/
create or replace trigger SDD_BRUBLI_d
  instead of delete on SDD_BRUBLI 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_BRUBLI 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_BRUBLI
   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_BRUBLI_d;
/
create or replace trigger SDD_BUN_br
  before insert or update or delete on i$SDD_BUN
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_BUN_br;
/
create or replace trigger SDD_BUN_ar
  after insert or update or delete on i$SDD_BUN
  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 => 384781276403354884739040728200005689
    );
  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_BUN'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_BUN_ar;
/
create or replace trigger SDD_BUN_inv
after insert or update of
  PARENT_REF
on i$SDD_BUN
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 := 384781276403354884739040728200005689;
  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_BUN_inv;
/
create or replace trigger SDD_BUN_val
after insert or update of
  PARENT_REF
on i$SDD_BUN
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 := 384781276403354884739040728200005689;
  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_BUN(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_BUN) violated');
    end if;
    if not FK_BUN_TO_BUN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_BUN_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_BUN_val;
/
create or replace trigger SDD_BUN_d
  instead of delete on SDD_BUN 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_A24_TO_BUN_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_A9_TO_BUN_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_DST_TO_BUN_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_ENTBUN_TO_BUN_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_EXT_TO_BUN_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_FUNBUN_TO_BUN_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_MODBUN_TO_BUN_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_A24 fktab
   where 
         fktab.BUSINESS_UNIT_REF = :old.IRID
    ;
  delete SDD_A9 fktab
   where 
         fktab.BUSINESS_UNIT_REF = :old.IRID
    ;
  delete SDD_ENTBUN fktab
   where 
         fktab.BUSINESS_UNIT_REF = :old.IRID
    ;
  delete SDD_FUNBUN fktab
   where 
         fktab.BUSINESS_UNIT_REF = :old.IRID
    ;
  delete SDD_MODBUN fktab
   where 
         fktab.BUSINESS_UNIT_REF = :old.IRID
    ;
  update SDD_DST fktab
     set 
         fktab.BUSINESS_UNIT_REF = NULL
   where 
         fktab.BUSINESS_UNIT_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.BUSINESS_UNIT_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state='I')
  ;
  update SDD_EXT fktab
     set 
         fktab.BUSINESS_UNIT_REF = NULL
   where 
         fktab.BUSINESS_UNIT_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
  ;
  delete SDD_EXT fktab
   where 
         fktab.BUSINESS_UNIT_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;
 update SDD_BUN 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_BUN fktab
  where 
        fktab.PARENT_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_BUN_d;
/
create or replace trigger SDD_CAT_br
  before insert or update or delete on i$SDD_CAT
  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_DOMAIN_REF is not null)
       )
    or (updating and (
        (:new.ATTRIBUTE_DOMAIN_REF != :old.ATTRIBUTE_DOMAIN_REF
        or (:new.ATTRIBUTE_DOMAIN_REF is not null and :old.ATTRIBUTE_DOMAIN_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.ATTRIBUTE_DOMAIN_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_CAT_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.ENTITY_OBJECT_REF is not null)
       )
    or (updating and (
        (:new.ENTITY_OBJECT_REF != :old.ENTITY_OBJECT_REF
        or (:new.ENTITY_OBJECT_REF is not null and :old.ENTITY_OBJECT_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.ENTITY_OBJECT_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_CAT_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.EVENT_CLASSIFIER_REF is not null)
       )
    or (updating and (
        (:new.EVENT_CLASSIFIER_REF != :old.EVENT_CLASSIFIER_REF
        or (:new.EVENT_CLASSIFIER_REF is not null and :old.EVENT_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.EVENT_CLASSIFIER_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_CAT_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.GENERIC_CLASS_REF is not null)
       )
    or (updating and (
        (:new.GENERIC_CLASS_REF != :old.GENERIC_CLASS_REF
        or (:new.GENERIC_CLASS_REF is not null and :old.GENERIC_CLASS_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.GENERIC_CLASS_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_CAT_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.INTERFACE_CLASSIFIER_REF is not null)
       )
    or (updating and (
        (:new.INTERFACE_CLASSIFIER_REF != :old.INTERFACE_CLASSIFIER_REF
        or (:new.INTERFACE_CLASSIFIER_REF is not null and :old.INTERFACE_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.INTERFACE_CLASSIFIER_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_CAT_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.VIEW_OBJECT_REF is not null)
       )
    or (updating and (
        (:new.VIEW_OBJECT_REF != :old.VIEW_OBJECT_REF
        or (:new.VIEW_OBJECT_REF is not null and :old.VIEW_OBJECT_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.VIEW_OBJECT_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_CAT_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_CAT');
  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_CAT_br;
/
create or replace trigger SDD_CAT_inv
after insert or update of
  GENERIC_CLASS_REF
 ,EVENT_CLASSIFIER_REF
 ,INTERFACE_CLASSIFIER_REF
 ,ENTITY_OBJECT_REF
 ,VIEW_OBJECT_REF
 ,NAME
 ,CLASSIFIER_REF
 ,COLLECT_CLASSSIFIER_REF
 ,EO_ATTRIBUTE_REF
 ,ENTITY_OBJECT_USAGE_REF
on i$SDD_CAT
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 := 384781276403709062225255951591032889;
  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_CAT_inv;
/
create or replace trigger SDD_CAT_val
after insert or update of
  GENERIC_CLASS_REF
 ,EVENT_CLASSIFIER_REF
 ,INTERFACE_CLASSIFIER_REF
 ,ENTITY_OBJECT_REF
 ,VIEW_OBJECT_REF
 ,NAME
 ,CLASSIFIER_REF
 ,COLLECT_CLASSSIFIER_REF
 ,EO_ATTRIBUTE_REF
 ,ENTITY_OBJECT_USAGE_REF
on i$SDD_CAT
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 := 384781276403709062225255951591032889;
  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_CAT(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_CAT) violated');
    end if;
    if not UK_HANDCRAFTED_CAT(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (UK_HANDCRAFTED_CAT) violated');
    end if;
    if not FK_CAT_TO_CLA(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CAT_TO_CLA) violated - parent key not found');
    end if;
    if not FK_CAT_TO_CLA2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CAT_TO_CLA2) violated - parent key not found');
    end if;
    if not FK_CAT_TO_EAT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CAT_TO_EAT) violated - parent key not found');
    end if;
    if not FK_CAT_TO_EOU(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CAT_TO_EOU) 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_CAT_val;
/
create or replace trigger SDD_CAT_d
  instead of delete on SDD_CAT 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_CAT 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_CAT_TO_EAT_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_CMA_TO_CAT2_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_VALGAT_TO_GAT_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_VALGAT fktab
   where 
         fktab.GENERAL_ATTRIBUTE_REF = :old.IRID
    ;
  update SDD_CAT fktab
     set 
         fktab.EO_ATTRIBUTE_REF = NULL
   where 
         fktab.EO_ATTRIBUTE_REF = :old.IRID
  ;
  update SDD_CMA fktab
     set 
         fktab.CLASSIFIER_ATT_FROM_REF = NULL
   where 
         fktab.CLASSIFIER_ATT_FROM_REF = :old.IRID
  ;
 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 delete SDD_AENEAT fktab
  where 
        fktab.EO_ATTRIBUTE_FROM_REF = :old.IRID
    ;
 delete SDD_AENEAT fktab
  where 
        fktab.EO_ATTRIBUTE_TO_REF = :old.IRID
    ;
 delete SDD_CATAEN fktab
  where 
        fktab.EO_ATTRIBUTE_REF = :old.IRID
    ;
 delete SDD_CATAEN fktab
  where 
        fktab.GENERAL_ATTRIBUTE_REF = :old.IRID
    ;
 delete SDD_CATEAT fktab
  where 
        fktab.EO_ATTRIBUTE_REF = :old.IRID
    ;
 delete SDD_CMA fktab
  where 
        fktab.CLASSIFIER_ATTRIBUTE_REF = :old.IRID
    ;
 delete SDD_CORI fktab
  where 
        fktab.CLASSIFIER_ATTRIBUTE_REF = :old.IRID
    ;
 delete SDD_CRU fktab
  where 
        fktab.CLASSIFIER_ATTRIBUTE_REF = :old.IRID
    ;
 delete SDD_DATCOM fktab
  where 
        fktab.CLASSIFIER_ATTRIBUTE_REF = :old.IRID
    ;
 delete SDD_MEMCOM fktab
  where 
        fktab.CLASSIFIER_ATTRIBUTE_REF = :old.IRID
    ;
 delete SDD_VLEVOA fktab
  where 
        fktab.VIEW_OBJECT_ATT_REF = :old.IRID
    ;
  delete SDD_ADR fktab
   where 
         fktab.CLASSIFIER_ATTRIBUTE_REF = :old.IRID
    ;
  delete SDD_CATEAT fktab
   where 
         fktab.GENERAL_ATTRIBUTE_REF = :old.IRID
    ;
 update SDD_WAT fktab
    set 
        fktab.CLASSIFIER_ATTRIBUTE_REF = NULL
  where 
        fktab.CLASSIFIER_ATTRIBUTE_REF = :old.IRID
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_CAT
   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_CAT_d;
/
create or replace trigger SDD_CATAEN_br
  before insert or update or delete on i$SDD_CATAEN
  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_END_REF is not null)
       )
    or (updating and (
        (:new.ASSOCIATION_END_REF != :old.ASSOCIATION_END_REF
        or (:new.ASSOCIATION_END_REF is not null and :old.ASSOCIATION_END_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_AEN owning_tab
        where  owning_tab.IRID=:new.ASSOCIATION_END_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_CATAEN_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_CATAEN');
  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_CATAEN_br;
/
create or replace trigger SDD_CATAEN_inv
after insert or update of
  EO_ATTRIBUTE_REF
 ,GENERAL_ATTRIBUTE_REF
on i$SDD_CATAEN
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 := 384781276404124630475748480369838137;
  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_CATAEN_inv;
/
create or replace trigger SDD_CATAEN_val
after insert or update of
  EO_ATTRIBUTE_REF
 ,GENERAL_ATTRIBUTE_REF
on i$SDD_CATAEN
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 := 384781276404124630475748480369838137;
  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_CATAEN(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_CATAEN) violated');
    end if;
    if not FK_CATAEN_TO_EAT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CATAEN_TO_EAT) violated - parent key not found');
    end if;
    if not FK_CATAEN_TO_GAT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CATAEN_TO_GAT) 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_CATAEN_val;
/
create or replace trigger SDD_CATAEN_d
  instead of delete on SDD_CATAEN 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_CATAEN 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_CATAEN
   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_CATAEN_d;
/
create or replace trigger SDD_CATEAT_br
  before insert or update or delete on i$SDD_CATEAT
  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_ATTRIBUTE_REF is not null)
       )
    or (updating and (
        (:new.GENERAL_ATTRIBUTE_REF != :old.GENERAL_ATTRIBUTE_REF
        or (:new.GENERAL_ATTRIBUTE_REF is not null and :old.GENERAL_ATTRIBUTE_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_CAT owning_tab
        where  owning_tab.IRID=:new.GENERAL_ATTRIBUTE_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_CATEAT_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_CATEAT');
  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_CATEAT_br;
/
create or replace trigger SDD_CATEAT_inv
after insert or update of
  EO_ATTRIBUTE_REF
on i$SDD_CATEAT
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 := 415825818364073508593486101422295097;
  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_CATEAT_inv;
/
create or replace trigger SDD_CATEAT_val
after insert or update of
  EO_ATTRIBUTE_REF
on i$SDD_CATEAT
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 := 415825818364073508593486101422295097;
  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_CATEAT(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_CATEAT) violated');
    end if;
    if not FK_CATEAT_TO_EAT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CATEAT_TO_EAT) 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_CATEAT_val;
/
create or replace trigger SDD_CATEAT_d
  instead of delete on SDD_CATEAT 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_CATEAT 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_CATEAT
   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_CATEAT_d;
/
create or replace trigger SDD_CCD_br
  before insert or update or delete on i$SDD_CCD
  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_CCD_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_CCD');
  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_CCD_br;
/
create or replace trigger SDD_CCD_inv
after insert
on i$SDD_CCD
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 := 384781276404280468569683178661890105;
  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_CCD_inv;
/
create or replace trigger SDD_CCD_val
after insert
on i$SDD_CCD
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 := 384781276404280468569683178661890105;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_CCD(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_CCD) 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_CCD_val;
/
create or replace trigger SDD_CCD_d
  instead of delete on SDD_CCD 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_CCD 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_COL fktab
    set 
        fktab.CLUSTER_COLUMN_REF = NULL
  where 
        fktab.CLUSTER_COLUMN_REF = :old.IRID
 ;
 update SDD_CQA fktab
    set 
        fktab.CLUSTER_COLUMN_REF = NULL
  where 
        fktab.CLUSTER_COLUMN_REF = :old.IRID
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_CCD
   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_CCD_d;
/
create or replace trigger SDD_CDE_br
  before insert or update or delete on i$SDD_CDE
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_CDE_br;
/
create or replace trigger SDD_CDE_ar
  after insert or update or delete on i$SDD_CDE
  for each row 
begin
  -- Inserting
  if inserting then
    jr_object_version.ins ( :new.irid, :new.ivid
    , name => :new.DEFINITION_TYPE
    , type_irid => :new.TYPES
    , table_irid => 397116117430509304423268667310491705
    );
  end if;  -- inserting
  -- Updating
  if updating then
    jr_object_version.upd ( :old.ivid
      , name => :new.DEFINITION_TYPE
    );
  end if;  -- updating
  -- Deleting
  if deleting then
    jr_object_version.del ( :old.irid, :old.ivid, 'SDD_CDE'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_CDE_ar;
/
create or replace trigger SDD_CDE_inv
after insert or update of
  PRIMARY_ACCESS_FILE_REF
on i$SDD_CDE
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 := 397116117430509304423268667310491705;
  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_CDE_inv;
/
create or replace trigger SDD_CDE_val
after insert or update of
  PRIMARY_ACCESS_FILE_REF
on i$SDD_CDE
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 := 397116117430509304423268667310491705;
  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_CDE(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_CDE) violated');
    end if;
    if not FK_CDE_TO_FILES(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CDE_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_CDE_val;
/
create or replace trigger SDD_CDE_d
  instead of delete on SDD_CDE 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_CDE_d;
/
create or replace trigger SDD_CLA_br
  before insert or update or delete on i$SDD_CLA
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_CLA_br;
/
create or replace trigger SDD_CLA_ar
  after insert or update or delete on i$SDD_CLA
  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 => 384781276404719648652590055666763833
    );
  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_CLA'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_CLA_ar;
/
create or replace trigger SDD_CLA_inv
after insert or update of
  ACTOR_REF
 ,BUSINESS_OBJECT_REF
 ,CLASSIFIER_REF
 ,ICON_FILE_REF
 ,GENERIC_CLASS_REF
 ,INTERFACE_CLASSIFIER_REF
 ,OBJECT_STATE_REF
 ,USE_CASE_REF
on i$SDD_CLA
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 := 384781276404719648652590055666763833;
  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_CLA_inv;
/
create or replace trigger SDD_CLA_val
after insert or update of
  ACTOR_REF
 ,BUSINESS_OBJECT_REF
 ,CLASSIFIER_REF
 ,ICON_FILE_REF
 ,GENERIC_CLASS_REF
 ,INTERFACE_CLASSIFIER_REF
 ,OBJECT_STATE_REF
 ,USE_CASE_REF
on i$SDD_CLA
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 := 384781276404719648652590055666763833;
  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_CLA(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_CLA) violated');
    end if;
    if not FK_CLA_TO_ACR(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CLA_TO_ACR) violated - parent key not found');
    end if;
    if not FK_CLA_TO_BOB(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CLA_TO_BOB) violated - parent key not found');
    end if;
    if not FK_CLA_TO_CLA(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CLA_TO_CLA) violated - parent key not found');
    end if;
    if not FK_CLA_TO_FILES(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CLA_TO_FILES) violated - parent key not found');
    end if;
    if not FK_CLA_TO_GEC(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CLA_TO_GEC) violated - parent key not found');
    end if;
    if not FK_CLA_TO_INC(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CLA_TO_INC) violated - parent key not found');
    end if;
    if not FK_CLA_TO_OST(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CLA_TO_OST) violated - parent key not found');
    end if;
    if not FK_CLA_TO_USC(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CLA_TO_USC) 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_CLA_val;
/
create or replace trigger SDD_CLA_d
  instead of delete on SDD_CLA 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
   if not FK_AMCAMC_TO_AMC2_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_BOB_TO_EOC_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_BOB_TO_GEC_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_CAT_TO_CLA_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_CLA_TO_CLA_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_CLA_TO_GEC_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_CLACLA_TO_CLA2_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_CLAINC_TO_INC_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_EOU_TO_EOC_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_EVS_TO_EVC_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_MET_TO_CLA2_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_MPA_TO_CLA_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_PSTADC_TO_ADC_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_VAL_TO_GEC_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_VOU_TO_VOB_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_AMCAMC fktab
   where 
         fktab.CHILD_APP_MODULE_REF = :old.IRID
    ;
  delete SDD_CLACLA fktab
   where 
         fktab.SUPERTYPE_REF = :old.IRID
    ;
  delete SDD_CLAINC fktab
   where 
         fktab.INTERFACE_CLASSIFIER_REF = :old.IRID
    ;
  delete SDD_EOU fktab
   where 
         fktab.ENTITY_OBJECT_REF = :old.IRID
    ;
  delete SDD_EVS fktab
   where 
         fktab.EVENT_CLASSIFIER_REF = :old.IRID
    ;
  delete SDD_PSTADC fktab
   where 
         fktab.ATTRIBUTE_DOMAIN_REF = :old.IRID
    ;
  delete SDD_VAL fktab
   where 
         fktab.GENERIC_CLASS_REF = :old.IRID
    ;
  delete SDD_VOU fktab
   where 
         fktab.VIEW_OBJECT_REF = :old.IRID
    ;
  update SDD_BOB fktab
     set 
         fktab.ENTITY_OBJECT_REF = NULL
   where 
         fktab.ENTITY_OBJECT_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
  ;
  delete SDD_BOB fktab
   where 
         fktab.ENTITY_OBJECT_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state='I')
  ;
  update SDD_BOB fktab
     set 
         fktab.GENERIC_CLASS_REF = NULL
   where 
         fktab.GENERIC_CLASS_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
  ;
  delete SDD_BOB fktab
   where 
         fktab.GENERIC_CLASS_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state='I')
  ;
  update SDD_CAT fktab
     set 
         fktab.CLASSIFIER_REF = NULL
   where 
         fktab.CLASSIFIER_REF = :old.IRID
  ;
  update SDD_CLA fktab
     set 
         fktab.CLASSIFIER_REF = NULL
   where 
         fktab.CLASSIFIER_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
  ;
  delete SDD_CLA fktab
   where 
         fktab.CLASSIFIER_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state='I')
  ;
  update SDD_CLA fktab
     set 
         fktab.GENERIC_CLASS_REF = NULL
   where 
         fktab.GENERIC_CLASS_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
  ;
  delete SDD_CLA fktab
   where 
         fktab.GENERIC_CLASS_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state='I')
  ;
  update SDD_MET fktab
     set 
         fktab.RETURN_CLASSIFIER_REF = NULL
   where 
         fktab.RETURN_CLASSIFIER_REF = :old.IRID
  ;
  update SDD_MPA fktab
     set 
         fktab.CLASSIFIER_REF = NULL
   where 
         fktab.CLASSIFIER_REF = :old.IRID
  ;
 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 delete SDD_AEN fktab
  where 
        fktab.ENTITY_OBJECT_REF = :old.IRID
    ;
 delete SDD_AEN fktab
  where 
        fktab.GENERIC_CLASS_REF = :old.IRID
    ;
 delete SDD_AEN fktab
  where 
        fktab.INTERFACE_CLASSIFIER_REF = :old.IRID
    ;
 delete SDD_BOBINC fktab
  where 
        fktab.INTERFACE_CLASSIFIER_REF = :old.IRID
    ;
 delete SDD_CLA fktab
  where 
        fktab.INTERFACE_CLASSIFIER_REF = :old.IRID
    ;
 delete SDD_CLAEVC fktab
  where 
        fktab.EVENT_CLASSIFIER_REF = :old.IRID
    ;
 delete SDD_CMA fktab
  where 
        fktab.EVENT_CLASSIFIER_REF = :old.IRID
    ;
 delete SDD_TRA fktab
  where 
        fktab.TARGET_EVENT_REF = :old.IRID
    ;
 delete SDD_USCEVI fktab
  where 
        fktab.EVENT_CLASSIFIER_REF = :old.IRID
    ;
 delete SDD_USCEVO fktab
  where 
        fktab.EVENT_CLASSIFIER_REF = :old.IRID
    ;
 delete SDD_VLE fktab
  where 
        fktab.VIEW_OBJECT_REF = :old.IRID
    ;
 update SDD_AEN fktab
    set 
        fktab.CLASSIFIER_REF = NULL
  where 
        fktab.CLASSIFIER_REF = :old.IRID
 ;
 update SDD_ASS fktab
    set 
        fktab.ENTITY_OBJECT_REF = NULL
  where 
        fktab.ENTITY_OBJECT_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
 ;
 delete SDD_ASS fktab
  where 
        fktab.ENTITY_OBJECT_REF = :old.IRID
    and fktab.ivid in (select o.ivid
                        from I$SDD_OBJECT_VERSIONS o
                       where o.state='I')
 ;
 update SDD_ASS fktab
    set 
        fktab.GENERIC_CLASS_REF = NULL
  where 
        fktab.GENERIC_CLASS_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
 ;
 delete SDD_ASS fktab
  where 
        fktab.GENERIC_CLASS_REF = :old.IRID
    and fktab.ivid in (select o.ivid
                        from I$SDD_OBJECT_VERSIONS o
                       where o.state='I')
 ;
 update SDD_CAT fktab
    set 
        fktab.COLLECT_CLASSSIFIER_REF = NULL
  where 
        fktab.COLLECT_CLASSSIFIER_REF = :old.IRID
 ;
 update SDD_FOLDERS fktab
    set 
        fktab.CLASSIFIER_REF = NULL
  where 
        fktab.CLASSIFIER_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.CLASSIFIER_REF = :old.IRID
    and fktab.ivid in (select o.ivid
                        from I$SDD_OBJECT_VERSIONS o
                       where o.state='I')
 ;
 update SDD_MET fktab
    set 
        fktab.COLLECT_CLASSIFIER_REF = NULL
  where 
        fktab.COLLECT_CLASSIFIER_REF = :old.IRID
 ;
 update SDD_MPA fktab
    set 
        fktab.COLLECT_CLASSIFIER_REF = NULL
  where 
        fktab.COLLECT_CLASSIFIER_REF = :old.IRID
 ;
 update SDD_RUL fktab
    set 
        fktab.EVENT_CLASSIFIER_REF = NULL
  where 
        fktab.EVENT_CLASSIFIER_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.EVENT_CLASSIFIER_REF = :old.IRID
    and fktab.ivid in (select o.ivid
                        from I$SDD_OBJECT_VERSIONS o
                       where o.state='I')
 ;
 update SDD_TRA fktab
    set 
        fktab.TRIGGER_EVENT_REF = NULL
  where 
        fktab.TRIGGER_EVENT_REF = :old.IRID
 ;
 update SDD_WAT fktab
    set 
        fktab.ATTRIBUTE_DOMAIN_REF = NULL
  where 
        fktab.ATTRIBUTE_DOMAIN_REF = :old.IRID
 ;
  if (NOT jr_wastebasket.force_flag) and jr_wastebasket.repos_constraints_enabled then
   if not FK_CAT_TO_EAT_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_CMA_TO_CAT2_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_VALGAT_TO_GAT_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_EVR_TO_CLAEVC_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_VLE_TO_AEU_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_EVH_TO_EVS_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_EVH_TO_SUD_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_CMA_TO_EVR2_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_CMA_TO_MPA_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
  elsif jr_wastebasket.force_flag then
  delete SDD_VALGAT fktab
   where fktab.GENERAL_ATTRIBUTE_REF in (select parent_tab.IRID
                                                      from i$SDD_CAT parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
  ;
