    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_TRA_val;
/
create or replace trigger SDD_TRA_d
  instead of delete on SDD_TRA 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_TRA 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_TRA fktab
    set 
        fktab.TRANSITION_REF = NULL
  where 
        fktab.TRANSITION_REF = :old.IRID
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_TRA
   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_TRA_d;
/
create or replace trigger SDD_TRG_br
  before insert or update or delete on i$SDD_TRG
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.TABLE_DEFINITION_REF is not null)
       )
    or (updating and (
        (:new.TABLE_DEFINITION_REF != :old.TABLE_DEFINITION_REF
        or (:new.TABLE_DEFINITION_REF is not null and :old.TABLE_DEFINITION_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_TAB owning_tab
        where  owning_tab.IRID=:new.TABLE_DEFINITION_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_TRG_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.VIEW_DEFINITION_REF is not null)
       )
    or (updating and (
        (:new.VIEW_DEFINITION_REF != :old.VIEW_DEFINITION_REF
        or (:new.VIEW_DEFINITION_REF is not null and :old.VIEW_DEFINITION_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_TAB owning_tab
        where  owning_tab.IRID=:new.VIEW_DEFINITION_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_TRG_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_TRG');
  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_TRG_br;
/
create or replace trigger SDD_TRG_inv
after insert or update of
  PLSQL_MODULE_REF
on i$SDD_TRG
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 := 384781276443173878922597576641890361;
  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_TRG_inv;
/
create or replace trigger SDD_TRG_val
after insert or update of
  PLSQL_MODULE_REF
on i$SDD_TRG
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 := 384781276443173878922597576641890361;
  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_TRG(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_TRG) violated');
    end if;
    if not FK_TRG_TO_PLM(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_TRG_TO_PLM) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_TRG_val;
/
create or replace trigger SDD_TRG_d
  instead of delete on SDD_TRG 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_TRG 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_TRGCOL fktab
   where 
         fktab.DATABASE_TRIGGER_REF = :old.IRID
    ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_TRG
   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_TRG_d;
/
create or replace trigger SDD_TRGCOL_br
  before insert or update or delete on i$SDD_TRGCOL
  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.DATABASE_TRIGGER_REF is not null)
       )
    or (updating and (
        (:new.DATABASE_TRIGGER_REF != :old.DATABASE_TRIGGER_REF
        or (:new.DATABASE_TRIGGER_REF is not null and :old.DATABASE_TRIGGER_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_TRG owning_tab
        where  owning_tab.IRID=:new.DATABASE_TRIGGER_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_TRGCOL_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_TRGCOL');
  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_TRGCOL_br;
/
create or replace trigger SDD_TRGCOL_inv
after insert or update of
  COLUMN_REF
on i$SDD_TRGCOL
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 := 384769782406787758048943861698938937;
  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_TRGCOL_inv;
/
create or replace trigger SDD_TRGCOL_val
after insert or update of
  COLUMN_REF
on i$SDD_TRGCOL
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 := 384769782406787758048943861698938937;
  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_TRGCOL(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_TRGCOL) violated');
    end if;
    if not FK_TRGCOL_TO_COL(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_TRGCOL_TO_COL) 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_TRGCOL_val;
/
create or replace trigger SDD_TRGCOL_d
  instead of delete on SDD_TRGCOL 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_TRGCOL 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_TRGCOL
   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_TRGCOL_d;
/
create or replace trigger SDD_TSQ_br
  before insert or update or delete on i$SDD_TSQ
  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.DATABASE_USER_REF is not null)
       )
    or (updating and (
        (:new.DATABASE_USER_REF != :old.DATABASE_USER_REF
        or (:new.DATABASE_USER_REF is not null and :old.DATABASE_USER_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_DBU owning_tab
        where  owning_tab.IRID=:new.DATABASE_USER_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_TSQ_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_TSQ');
  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_TSQ_br;
/
create or replace trigger SDD_TSQ_inv
after insert or update of
  TABLESPACE_REF
on i$SDD_TSQ
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 := 384769782407033321106053083250051129;
  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_TSQ_inv;
/
create or replace trigger SDD_TSQ_val
after insert or update of
  TABLESPACE_REF
on i$SDD_TSQ
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 := 384769782407033321106053083250051129;
  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_TSQ(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_TSQ) violated');
    end if;
    if not FK_TSQ_TO_OTB(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_TSQ_TO_OTB) 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_TSQ_val;
/
create or replace trigger SDD_TSQ_d
  instead of delete on SDD_TSQ 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_TSQ 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_TSQ
   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_TSQ_d;
/
create or replace trigger SDD_UCA_br
  before insert or update or delete on i$SDD_UCA
  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.USE_CASE_REF is not null)
       )
    or (updating and (
        (:new.USE_CASE_REF != :old.USE_CASE_REF
        or (:new.USE_CASE_REF is not null and :old.USE_CASE_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_USC owning_tab
        where  owning_tab.IRID=:new.USE_CASE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_UCA_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_UCA');
  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_UCA_br;
/
create or replace trigger SDD_UCA_inv
after insert or update of
  GENERAL_ACTION_REF
 ,USE_CASE_INVOKED_REF
 ,USE_CASE_EVENT_OUT_REF
on i$SDD_UCA
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 := 384769782407288328896128044091590713;
  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_UCA_inv;
/
create or replace trigger SDD_UCA_val
after insert or update of
  GENERAL_ACTION_REF
 ,USE_CASE_INVOKED_REF
 ,USE_CASE_EVENT_OUT_REF
on i$SDD_UCA
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 := 384769782407288328896128044091590713;
  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_UCA(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_UCA) violated');
    end if;
    if not FK_UCA_TO_GEA(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_UCA_TO_GEA) violated - parent key not found');
    end if;
    if not FK_UCA_TO_USC2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_UCA_TO_USC2) violated - parent key not found');
    end if;
    if not FK_UCA_TO_USCEVO(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_UCA_TO_USCEVO) 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_UCA_val;
/
create or replace trigger SDD_UCA_d
  instead of delete on SDD_UCA 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_UCA 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_UCA fktab
  where 
        fktab.GENERAL_ACTION_REF = :old.IRID
    ;
 delete SDD_USCEPA fktab
  where 
        fktab.EXTENSION_POINT_REF = :old.IRID
    ;
 update SDD_ACT fktab
    set 
        fktab.GENERAL_ACTION_REF = NULL
  where 
        fktab.GENERAL_ACTION_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
 ;
 delete SDD_ACT fktab
  where 
        fktab.GENERAL_ACTION_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; 
  delete i$SDD_UCA
   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_UCA_d;
/
create or replace trigger SDD_UDE_br
  before insert or update or delete on i$SDD_UDE
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_UDE_br;
/
create or replace trigger SDD_UDE_ar
  after insert or update or delete on i$SDD_UDE
  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 => 415853084456660423872489983451875385
    );
  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_UDE'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_UDE_ar;
/
create or replace trigger SDD_UDE_inv
after insert
on i$SDD_UDE
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 := 415853084456660423872489983451875385;
  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_UDE_inv;
/
create or replace trigger SDD_UDE_val
after insert
on i$SDD_UDE
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 := 415853084456660423872489983451875385;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_UDE(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_UDE) 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_UDE_val;
/
create or replace trigger SDD_UDE_d
  instead of delete on SDD_UDE 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_UDE_d;
/
create or replace trigger SDD_UDECLI_br
  before insert or update or delete on i$SDD_UDECLI
  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.UML_DEPENDENCY_REF is not null)
       )
    or (updating and (
        (:new.UML_DEPENDENCY_REF != :old.UML_DEPENDENCY_REF
        or (:new.UML_DEPENDENCY_REF is not null and :old.UML_DEPENDENCY_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_UDE owning_tab
        where  owning_tab.IRID=:new.UML_DEPENDENCY_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_UDECLI_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_UDECLI');
  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_UDECLI_br;
/
create or replace trigger SDD_UDECLI_inv
after insert
on i$SDD_UDECLI
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 := 415853084456773760668078854937004089;
  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_UDECLI_inv;
/
create or replace trigger SDD_UDECLI_val
after insert
on i$SDD_UDECLI
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 := 415853084456773760668078854937004089;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_UDECLI(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_UDECLI) 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_UDECLI_val;
/
create or replace trigger SDD_UDECLI_d
  instead of delete on SDD_UDECLI 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_UDECLI 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_UDECLI
   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_UDECLI_d;
/
create or replace trigger SDD_UDESUP_br
  before insert or update or delete on i$SDD_UDESUP
  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.UML_DEPENDENCY_REF is not null)
       )
    or (updating and (
        (:new.UML_DEPENDENCY_REF != :old.UML_DEPENDENCY_REF
        or (:new.UML_DEPENDENCY_REF is not null and :old.UML_DEPENDENCY_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_UDE owning_tab
        where  owning_tab.IRID=:new.UML_DEPENDENCY_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_UDESUP_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_UDESUP');
  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_UDESUP_br;
/
create or replace trigger SDD_UDESUP_inv
after insert
on i$SDD_UDESUP
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 := 415853084456920154029047813938628665;
  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_UDESUP_inv;
/
create or replace trigger SDD_UDESUP_val
after insert
on i$SDD_UDESUP
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 := 415853084456920154029047813938628665;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_UDESUP(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_UDESUP) 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_UDESUP_val;
/
create or replace trigger SDD_UDESUP_d
  instead of delete on SDD_UDESUP 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_UDESUP 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_UDESUP
   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_UDESUP_d;
/
create or replace trigger SDD_UDS_br
  before insert or update or delete on i$SDD_UDS
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_UDS_br;
/
create or replace trigger SDD_UDS_ar
  after insert or update or delete on i$SDD_UDS
  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 => 384769782407496113021374308480993337
    );
  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_UDS'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_UDS_ar;
/
create or replace trigger SDD_UDS_inv
after insert
on i$SDD_UDS
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 := 384769782407496113021374308480993337;
  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_UDS_inv;
/
create or replace trigger SDD_UDS_val
after insert
on i$SDD_UDS
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 := 384769782407496113021374308480993337;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_UDS(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_UDS) 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_UDS_val;
/
create or replace trigger SDD_UDS_d
  instead of delete on SDD_UDS 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_UDS_d;
/
create or replace trigger SDD_UEE_br
  before insert or update or delete on i$SDD_UEE
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_UEE_br;
/
create or replace trigger SDD_UEE_ar
  after insert or update or delete on i$SDD_UEE
  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 => 384769782407708619513103442515609657
    );
  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_UEE'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_UEE_ar;
/
create or replace trigger SDD_UEE_inv
after insert
on i$SDD_UEE
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 := 384769782407708619513103442515609657;
  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_UEE_inv;
/
create or replace trigger SDD_UEE_val
after insert
on i$SDD_UEE
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 := 384769782407708619513103442515609657;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_UEE(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_UEE) 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_UEE_val;
/
create or replace trigger SDD_UEE_d
  instead of delete on SDD_UEE for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
  where ov.irid=:old.irid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  jr_wastebasket.remove(:old.ivid);
  if jr_context.workarea is NULL and not only_version then
   return;
  end if;
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 if not jr_wastebasket.force_flag 
   and jr_wastebasket.repos_constraints_enabled then
   -- bug fix 2078916 - BLOCK DELETE IF USER EXTENDED ASSOCIATION EXISTS
   if not jr_ues_chk.check_ues_blocks_delete (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
 elsif jr_wastebasket.force_flag then 
  jr_wastebasket.set_secondary_delete;

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

 end if;--Constraints enabled/force
 
 jr_wastebasket.set_secondary_delete;
 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_UEE_d;
/
create or replace trigger SDD_UES_inv
after insert or update of
  PART_OF_REF
 ,USE_OF_REF
 ,ELEMENT_TYPE_NAME
on i$SDD_UES
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 := 384769782407911681271866837259798585;
  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_UES_inv;
/
create or replace trigger SDD_UES_val
after insert or update of
  PART_OF_REF
 ,USE_OF_REF
 ,ELEMENT_TYPE_NAME
on i$SDD_UES
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 := 384769782407911681271866837259798585;
  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_UES(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_UES) violated');
    end if;
    if not UK_UES(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (UK_UES) 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_UES_val;
/
create or replace trigger SDD_UES_d
  instead of delete on SDD_UES 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_UES 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_UES
   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_UES_d;
/
create or replace trigger SDD_UID_br
  before insert or update or delete on i$SDD_UID
  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_UID_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_UID');
  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_UID_br;
/
create or replace trigger SDD_UID_inv
after insert
on i$SDD_UID
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 := 384769782408147799596010319520483385;
  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_UID_inv;
/
create or replace trigger SDD_UID_val
after insert
on i$SDD_UID
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 := 384769782408147799596010319520483385;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_UID(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_UID) 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_UID_val;
/
create or replace trigger SDD_UID_d
  instead of delete on SDD_UID 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_UID 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_ENTUIE fktab
   where 
         fktab.UNIQUE_IDENTIFIER_REF = :old.IRID
    ;
 update SDD_OCO fktab
    set 
        fktab.UNIQUE_IDENTIFIER_REF = NULL
  where 
        fktab.UNIQUE_IDENTIFIER_REF = :old.IRID
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_UID
   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_UID_d;
/
create or replace trigger SDD_UPR_inv
after insert or update of
  CIELEMENT_REF
 ,PRODUCT_FLAVOR
 ,PREFERENCE_NAME
on i$SDD_UPR
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 := 384769782408388640286636671426381881;
  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_UPR_inv;
/
create or replace trigger SDD_UPR_val
after insert or update of
  CIELEMENT_REF
 ,PRODUCT_FLAVOR
 ,PREFERENCE_NAME
on i$SDD_UPR
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 := 384769782408388640286636671426381881;
  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_UPR(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_UPR) violated');
    end if;
    if not UK_UPR(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (UK_UPR) 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_UPR_val;
/
create or replace trigger SDD_UPR_d
  instead of delete on SDD_UPR 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_UPR 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_UPR
   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_UPR_d;
/
create or replace trigger SDD_URU_br
  before insert or update or delete on i$SDD_URU
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_URU_br;
/
create or replace trigger SDD_URU_ar
  after insert or update or delete on i$SDD_URU
  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 => 384769782408549200747054239363647545
    );
  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_URU'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_URU_ar;
/
create or replace trigger SDD_URU_inv
after insert
on i$SDD_URU
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 := 384769782408549200747054239363647545;
  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_URU_inv;
/
create or replace trigger SDD_URU_val
after insert
on i$SDD_URU
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 := 384769782408549200747054239363647545;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_URU(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_URU) 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_URU_val;
/
create or replace trigger SDD_URU_d
  instead of delete on SDD_URU 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_ERU fktab
  where 
        fktab.UML_RULE_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_URU_d;
/
create or replace trigger SDD_USC_br
  before insert or update or delete on i$SDD_USC
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_USC_br;
/
create or replace trigger SDD_USC_ar
  after insert or update or delete on i$SDD_USC
  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 => 384769782408653092809677371558348857
    );
  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_USC'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_USC_ar;
/
create or replace trigger SDD_USC_inv
after insert or update of
  ICON_FILE_REF
 ,PRE_RULE_REF
 ,POST_RULE_REF
on i$SDD_USC
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 := 384769782408653092809677371558348857;
  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_USC_inv;
/
create or replace trigger SDD_USC_val
after insert or update of
  ICON_FILE_REF
 ,PRE_RULE_REF
 ,POST_RULE_REF
on i$SDD_USC
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 := 384769782408653092809677371558348857;
  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_USC(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_USC) violated');
    end if;
    if not FK_USC_TO_FILES(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_USC_TO_FILES) violated - parent key not found');
    end if;
    if not FK_USC_TO_RUL(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_USC_TO_RUL) violated - parent key not found');
    end if;
    if not FK_USC_TO_RUL2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_USC_TO_RUL2) 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_USC_val;
/
create or replace trigger SDD_USC_d
  instead of delete on SDD_USC 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_UCA_TO_USC2_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_USCUSC_TO_USC2_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_UCA fktab
   where 
         fktab.USE_CASE_INVOKED_REF = :old.IRID
    ;
  delete SDD_USCUSC fktab
   where 
         fktab.SUPERTYPE_REF = :old.IRID
    ;
 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 delete SDD_CLA fktab
  where 
        fktab.USE_CASE_REF = :old.IRID
    ;
 delete SDD_USCEPA fktab
  where 
        fktab.USE_CASE_FROM_REF = :old.IRID
    ;
 update SDD_ACT fktab
    set 
        fktab.USE_CASE_REF = NULL
  where 
        fktab.USE_CASE_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
 ;
 delete SDD_ACT fktab
  where 
        fktab.USE_CASE_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_UCA
   where ivid in
   (select fktab.ivid
      from i$SDD_UCA 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.GENERAL_ACTION_REF in (select parent_tab.IRID
                                                    from i$SDD_UCA parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_UCA
   where ivid in
   (select fktab.ivid
      from i$SDD_UCA fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.GENERAL_ACTION_REF in (select parent_tab.IRID
                                                    from i$SDD_UCA parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_USCEPA
   where ivid in
   (select fktab.ivid
      from i$SDD_USCEPA 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.EXTENSION_POINT_REF in (select parent_tab.IRID
                                                    from i$SDD_UCA parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_USCEPA
   where ivid in
   (select fktab.ivid
      from i$SDD_USCEPA fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.EXTENSION_POINT_REF in (select parent_tab.IRID
                                                    from i$SDD_UCA parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_ACT
     set GENERAL_ACTION_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_ACT fktab
          ,i$sdd_wa_context ctxt
          ,i$sdd_object_versions ov
     where ctxt.object_ivid = fktab.ivid
       and ov.ivid=fktab.ivid
       and ov.state!='I'
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.GENERAL_ACTION_REF in (select parent_tab.IRID
                                                      from i$SDD_UCA parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
  delete SDD_ACT
   where ivid in
   (select fktab.ivid
      from i$SDD_ACT fktab
          ,i$sdd_wa_context ctxt
          ,i$sdd_object_versions ov
     where ctxt.object_ivid = fktab.ivid
       and ov.ivid=fktab.ivid
       and ov.state='I'
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.GENERAL_ACTION_REF in (select parent_tab.IRID
                                                      from i$SDD_UCA parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_ACT
     set GENERAL_ACTION_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_ACT fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.ivid
       and ov.state!='I'
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.GENERAL_ACTION_REF in (select parent_tab.IRID
                                                      from i$SDD_UCA parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
  delete SDD_ACT
   where ivid in
   (select fktab.ivid
      from i$SDD_ACT fktab
          ,i$sdd_object_versions ov
     where ov.ivid=fktab.ivid
       and ov.state='I'
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.GENERAL_ACTION_REF in (select parent_tab.IRID
                                                      from i$SDD_UCA parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_UCA
   where ivid in
   (select fktab.ivid
      from i$SDD_UCA 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_CASE_EVENT_OUT_REF in (select parent_tab.IRID
                                                    from i$SDD_USCEVO parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_UCA
   where ivid in
   (select fktab.ivid
      from i$SDD_UCA fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.USE_CASE_EVENT_OUT_REF in (select parent_tab.IRID
                                                    from i$SDD_USCEVO 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_USC_d;
/
create or replace trigger SDD_USCACR_br
  before insert or update or delete on i$SDD_USCACR
  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.USE_CASE_REF is not null)
       )
    or (updating and (
        (:new.USE_CASE_REF != :old.USE_CASE_REF
        or (:new.USE_CASE_REF is not null and :old.USE_CASE_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_USC owning_tab
        where  owning_tab.IRID=:new.USE_CASE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_USCACR_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_USCACR');
  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_USCACR_br;
/
create or replace trigger SDD_USCACR_inv
after insert or update of
  ACTOR_REF
on i$SDD_USCACR
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 := 384769782408799486170646330559973433;
  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_USCACR_inv;
/
create or replace trigger SDD_USCACR_val
after insert or update of
  ACTOR_REF
on i$SDD_USCACR
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 := 384769782408799486170646330559973433;
  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_USCACR(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_USCACR) violated');
    end if;
    if not FK_USCACR_TO_ACR(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_USCACR_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_USCACR_val;
/
create or replace trigger SDD_USCACR_d
  instead of delete on SDD_USCACR 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_USCACR 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_USCACR
   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_USCACR_d;
/
create or replace trigger SDD_USCE1_br
  before insert or update or delete on i$SDD_USCE1
  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.USE_CASE_REF is not null)
       )
    or (updating and (
        (:new.USE_CASE_REF != :old.USE_CASE_REF
        or (:new.USE_CASE_REF is not null and :old.USE_CASE_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_USC owning_tab
        where  owning_tab.IRID=:new.USE_CASE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_USCE1_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_USCE1');
  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_USCE1_br;
/
create or replace trigger SDD_USCE1_inv
after insert or update of
  OBJECTIVE_REF
on i$SDD_USCE1
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 := 384769782408955324264581028852025401;
  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_USCE1_inv;
/
create or replace trigger SDD_USCE1_val
after insert or update of
  OBJECTIVE_REF
on i$SDD_USCE1
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 := 384769782408955324264581028852025401;
  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_USCE1(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_USCE1) violated');
    end if;
    if not FK_USCE1_TO_E1(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_USCE1_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_USCE1_val;
/
create or replace trigger SDD_USCE1_d
  instead of delete on SDD_USCE1 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_USCE1 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_USCE1
   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_USCE1_d;
/
create or replace trigger SDD_USCEPA_br
  before insert or update or delete on i$SDD_USCEPA
  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.USE_CASE_REF is not null)
       )
    or (updating and (
        (:new.USE_CASE_REF != :old.USE_CASE_REF
        or (:new.USE_CASE_REF is not null and :old.USE_CASE_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_USC owning_tab
        where  owning_tab.IRID=:new.USE_CASE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_USCEPA_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_USCEPA');
  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_USCEPA_br;
/
create or replace trigger SDD_USCEPA_inv
after insert or update of
  EXTENSION_POINT_REF
 ,NAMED_RULE_REF
 ,USE_CASE_FROM_REF
on i$SDD_USCEPA
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 := 384769782409101717625549987853649977;
  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_USCEPA_inv;
/
create or replace trigger SDD_USCEPA_val
after insert or update of
  EXTENSION_POINT_REF
 ,NAMED_RULE_REF
 ,USE_CASE_FROM_REF
on i$SDD_USCEPA
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 := 384769782409101717625549987853649977;
  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_USCEPA(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_USCEPA) violated');
    end if;
    if not FK_USCEPA_TO_EPA(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_USCEPA_TO_EPA) violated - parent key not found');
    end if;
    if not FK_USCEPA_TO_RUL(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_USCEPA_TO_RUL) violated - parent key not found');
    end if;
    if not FK_USCEPA_TO_USC2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_USCEPA_TO_USC2) 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_USCEPA_val;
/
create or replace trigger SDD_USCEPA_d
  instead of delete on SDD_USCEPA 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_USCEPA 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_USCEPA
   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_USCEPA_d;
/
create or replace trigger SDD_USCEVI_br
  before insert or update or delete on i$SDD_USCEVI
  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.USE_CASE_REF is not null)
       )
    or (updating and (
        (:new.USE_CASE_REF != :old.USE_CASE_REF
        or (:new.USE_CASE_REF is not null and :old.USE_CASE_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_USC owning_tab
        where  owning_tab.IRID=:new.USE_CASE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_USCEVI_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_USCEVI');
  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_USCEVI_br;
/
create or replace trigger SDD_USCEVI_inv
after insert or update of
  EVENT_CLASSIFIER_REF
on i$SDD_USCEVI
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 := 384769782409295334651347643307411513;
  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_USCEVI_inv;
/
create or replace trigger SDD_USCEVI_val
after insert or update of
  EVENT_CLASSIFIER_REF
on i$SDD_USCEVI
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 := 384769782409295334651347643307411513;
  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_USCEVI(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_USCEVI) violated');
    end if;
    if not FK_USCEVI_TO_EVC(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_USCEVI_TO_EVC) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_USCEVI_val;
/
create or replace trigger SDD_USCEVI_d
  instead of delete on SDD_USCEVI 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_USCEVI 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_USCEVI
   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_USCEVI_d;
/
create or replace trigger SDD_USCEVO_br
  before insert or update or delete on i$SDD_USCEVO
  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.USE_CASE_REF is not null)
       )
    or (updating and (
        (:new.USE_CASE_REF != :old.USE_CASE_REF
        or (:new.USE_CASE_REF is not null and :old.USE_CASE_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_USC owning_tab
        where  owning_tab.IRID=:new.USE_CASE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_USCEVO_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_USCEVO');
  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_USCEVO_br;
/
create or replace trigger SDD_USCEVO_inv
after insert or update of
  EVENT_CLASSIFIER_REF
on i$SDD_USCEVO
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 := 384769782409441728012316602309036089;
  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_USCEVO_inv;
/
create or replace trigger SDD_USCEVO_val
after insert or update of
  EVENT_CLASSIFIER_REF
on i$SDD_USCEVO
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 := 384769782409441728012316602309036089;
  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_USCEVO(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_USCEVO) violated');
    end if;
    if not FK_USCEVO_TO_EVC(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_USCEVO_TO_EVC) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_USCEVO_val;
/
create or replace trigger SDD_USCEVO_d
  instead of delete on SDD_USCEVO 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_USCEVO 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_UCA fktab
  where 
        fktab.USE_CASE_EVENT_OUT_REF = :old.IRID
    ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_USCEVO
   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_USCEVO_d;
/
create or replace trigger SDD_USCUSC_br
  before insert or update or delete on i$SDD_USCUSC
  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_REF is not null)
       )
    or (updating and (
        (:new.SUBTYPE_REF != :old.SUBTYPE_REF
        or (:new.SUBTYPE_REF is not null and :old.SUBTYPE_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_USC owning_tab
        where  owning_tab.IRID=:new.SUBTYPE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_USCUSC_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_USCUSC');
  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_USCUSC_br;
/
create or replace trigger SDD_USCUSC_inv
after insert or update of
  SUPERTYPE_REF
 ,SEQUENCE
on i$SDD_USCUSC
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 := 384769782409588121373285561310660665;
  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_USCUSC_inv;
/
create or replace trigger SDD_USCUSC_val
after insert or update of
  SUPERTYPE_REF
 ,SEQUENCE
on i$SDD_USCUSC
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 := 384769782409588121373285561310660665;
  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_USCUSC(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_USCUSC) violated');
    end if;
    if not UK_USCUSC_2(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (UK_USCUSC_2) violated');
    end if;
    if not FK_USCUSC_TO_USC2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_USCUSC_TO_USC2) 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_USCUSC_val;
/
create or replace trigger SDD_USCUSC_d
  instead of delete on SDD_USCUSC 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_USCUSC 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_USCUSC
   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_USCUSC_d;
/
create or replace trigger SDD_VAL_br
  before insert or update or delete on i$SDD_VAL
  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_VAL_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.INTEGRITY_RULE_REF is not null)
       )
    or (updating and (
        (:new.INTEGRITY_RULE_REF != :old.INTEGRITY_RULE_REF
        or (:new.INTEGRITY_RULE_REF is not null and :old.INTEGRITY_RULE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select pac_ref, parent_ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_CRU owning_tab
        where  owning_tab.IRID=:new.INTEGRITY_RULE_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_VAL_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_VAL');
  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_VAL_br;
/
create or replace trigger SDD_VAL_inv
after insert or update of
  GENERIC_CLASS_REF
on i$SDD_VAL
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 := 398199735910649209448168081713547321;
  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_VAL_inv;
/
create or replace trigger SDD_VAL_val
after insert or update of
  GENERIC_CLASS_REF
on i$SDD_VAL
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 := 398199735910649209448168081713547321;
  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_VAL(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_VAL) violated');
    end if;
    if not FK_VAL_TO_GEC(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_VAL_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_VAL_val;
/
create or replace trigger SDD_VAL_d
  instead of delete on SDD_VAL 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_VAL 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_VALGAT fktab
   where 
         fktab.VALIDATOR_REF = :old.IRID
    ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_VAL
   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_VAL_d;
/
create or replace trigger SDD_VALGAT_br
  before insert or update or delete on i$SDD_VALGAT
  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.VALIDATOR_REF is not null)
       )
    or (updating and (
        (:new.VALIDATOR_REF != :old.VALIDATOR_REF
        or (:new.VALIDATOR_REF is not null and :old.VALIDATOR_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_VAL owning_tab
        where  owning_tab.IRID=:new.VALIDATOR_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_VALGAT_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_VALGAT');
  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_VALGAT_br;
/
create or replace trigger SDD_VALGAT_inv
after insert or update of
  GENERAL_ATTRIBUTE_REF
on i$SDD_VALGAT
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 := 398199735910776713343205562134317113;
  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_VALGAT_inv;
/
create or replace trigger SDD_VALGAT_val
after insert or update of
  GENERAL_ATTRIBUTE_REF
on i$SDD_VALGAT
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 := 398199735910776713343205562134317113;
  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_VALGAT(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_VALGAT) violated');
    end if;
    if not FK_VALGAT_TO_GAT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_VALGAT_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_VALGAT_val;
/
create or replace trigger SDD_VALGAT_d
  instead of delete on SDD_VALGAT 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_VALGAT 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_VALGAT
   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_VALGAT_d;
/
create or replace trigger SDD_VLE_br
  before insert or update or delete on i$SDD_VLE
  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.VIEW_LINK_REF is not null)
       )
    or (updating and (
        (:new.VIEW_LINK_REF != :old.VIEW_LINK_REF
        or (:new.VIEW_LINK_REF is not null and :old.VIEW_LINK_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_VLI owning_tab
        where  owning_tab.IRID=:new.VIEW_LINK_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_VLE_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_VLE');
  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_VLE_br;
/
create or replace trigger SDD_VLE_inv
after insert or update of
  ASSOC_END_USAGE_REF
 ,VIEW_OBJECT_REF
on i$SDD_VLE
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 := 384769782409734514734254520312285241;
  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_VLE_inv;
/
create or replace trigger SDD_VLE_val
after insert or update of
  ASSOC_END_USAGE_REF
 ,VIEW_OBJECT_REF
on i$SDD_VLE
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 := 384769782409734514734254520312285241;
  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_VLE(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_VLE) violated');
    end if;
    if not FK_VLE_TO_AEU(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_VLE_TO_AEU) violated - parent key not found');
    end if;
    if not FK_VLE_TO_VOB(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_VLE_TO_VOB) 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_VLE_val;
/
create or replace trigger SDD_VLE_d
  instead of delete on SDD_VLE 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_VLE 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_VLEU_TO_VLE_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_VLEU fktab
   where 
         fktab.VIEW_LINK_END_REF = :old.IRID
    ;
 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
  delete SDD_VLEVOA fktab
   where 
         fktab.VIEW_LINK_END_REF = :old.IRID
    ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_VLE
   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_VLE_d;
/
create or replace trigger SDD_VLEU_br
  before insert or update or delete on i$SDD_VLEU
  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.VIEW_LINK_USAGE_REF is not null)
       )
    or (updating and (
        (:new.VIEW_LINK_USAGE_REF != :old.VIEW_LINK_USAGE_REF
        or (:new.VIEW_LINK_USAGE_REF is not null and :old.VIEW_LINK_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_VLU owning_tab
        where  owning_tab.IRID=:new.VIEW_LINK_USAGE_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_VLEU_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_VLEU');
  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_VLEU_br;
/
create or replace trigger SDD_VLEU_inv
after insert or update of
  VIEW_LINK_END_REF
 ,VIEW_USAGE_REF
on i$SDD_VLEU
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 := 384769782409923409393569306120833081;
  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_VLEU_inv;
/
create or replace trigger SDD_VLEU_val
after insert or update of
  VIEW_LINK_END_REF
 ,VIEW_USAGE_REF
on i$SDD_VLEU
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 := 384769782409923409393569306120833081;
  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_VLEU(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_VLEU) violated');
    end if;
    if not FK_VLEU_TO_VLE(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_VLEU_TO_VLE) violated - parent key not found');
    end if;
    if not FK_VLEU_TO_VOU(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_VLEU_TO_VOU) 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_VLEU_val;
/
create or replace trigger SDD_VLEU_d
  instead of delete on SDD_VLEU 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_VLEU 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_VLEU
   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_VLEU_d;
/
create or replace trigger SDD_VLEVOA_br
  before insert or update or delete on i$SDD_VLEVOA
  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.VIEW_LINK_END_REF is not null)
       )
    or (updating and (
        (:new.VIEW_LINK_END_REF != :old.VIEW_LINK_END_REF
        or (:new.VIEW_LINK_END_REF is not null and :old.VIEW_LINK_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_VLE owning_tab
        where  owning_tab.IRID=:new.VIEW_LINK_END_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_VLEVOA_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_VLEVOA');
  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_VLEVOA_br;
/
create or replace trigger SDD_VLEVOA_inv
after insert or update of
  VIEW_OBJECT_ATT_REF
on i$SDD_VLEVOA
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 := 446785506305207960038734780046002233;
  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_VLEVOA_inv;
/
create or replace trigger SDD_VLEVOA_val
after insert or update of
  VIEW_OBJECT_ATT_REF
on i$SDD_VLEVOA
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 := 446785506305207960038734780046002233;
  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_VLEVOA(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_VLEVOA) violated');
    end if;
    if not FK_VLEVOA_TO_VOA(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_VLEVOA_TO_VOA) 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_VLEVOA_val;
/
create or replace trigger SDD_VLEVOA_d
  instead of delete on SDD_VLEVOA 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_VLEVOA 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_VLEVOA
   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_VLEVOA_d;
/
create or replace trigger SDD_VLI_br
  before insert or update or delete on i$SDD_VLI
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_VLI_br;
/
create or replace trigger SDD_VLI_ar
  after insert or update or delete on i$SDD_VLI
  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 => 384769782410088692220469743703312441
    );
  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_VLI'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_VLI_ar;
/
create or replace trigger SDD_VLI_inv
after insert
on i$SDD_VLI
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 := 384769782410088692220469743703312441;
  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_VLI_inv;
/
create or replace trigger SDD_VLI_val
after insert
on i$SDD_VLI
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 := 384769782410088692220469743703312441;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_VLI(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_VLI) 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_VLI_val;
/
create or replace trigger SDD_VLI_d
  instead of delete on SDD_VLI 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_VLU_TO_VLI_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_VLU fktab
   where 
         fktab.VIEW_LINK_REF = :old.IRID
    ;
 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
  if (NOT jr_wastebasket.force_flag) and jr_wastebasket.repos_constraints_enabled then
   if not FK_VLEU_TO_VLE_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
  elsif jr_wastebasket.force_flag then
  delete SDD_VLEU fktab
   where fktab.VIEW_LINK_END_REF in (select parent_tab.IRID
                                                      from i$SDD_VLE parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
  ;
  end if;--force delete/purge
 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_VLI_d;
/
create or replace trigger SDD_VLU_br
  before insert or update or delete on i$SDD_VLU
  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_VLU_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_VLU');
  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_VLU_br;
/
create or replace trigger SDD_VLU_inv
after insert or update of
  VIEW_LINK_REF
on i$SDD_VLU
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 := 384769782410206751382541484833654841;
  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_VLU_inv;
/
create or replace trigger SDD_VLU_val
after insert or update of
  VIEW_LINK_REF
on i$SDD_VLU
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 := 384769782410206751382541484833654841;
  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_VLU(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_VLU) violated');
    end if;
    if not FK_VLU_TO_VLI(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_VLU_TO_VLI) 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_VLU_val;
/
create or replace trigger SDD_VLU_d
  instead of delete on SDD_VLU 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_VLU 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_VLEU fktab
   where 
         fktab.VIEW_LINK_USAGE_REF = :old.IRID
    ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_VLU
   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_VLU_d;
/
create or replace trigger SDD_VOU_br
  before insert or update or delete on i$SDD_VOU
  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_VOU_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_VOU');
  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_VOU_br;
/
create or replace trigger SDD_VOU_inv
after insert or update of
  VIEW_OBJECT_REF
on i$SDD_VOU
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 := 384769782410362589476476183125706809;
  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_VOU_inv;
/
create or replace trigger SDD_VOU_val
after insert or update of
  VIEW_OBJECT_REF
on i$SDD_VOU
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 := 384769782410362589476476183125706809;
  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_VOU(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_VOU) violated');
    end if;
    if not FK_VOU_TO_VOB(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_VOU_TO_VOB) 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_VOU_val;
/
create or replace trigger SDD_VOU_d
  instead of delete on SDD_VOU 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_VOU 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_VLEU fktab
  where 
        fktab.VIEW_USAGE_REF = :old.IRID
    ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_VOU
   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_VOU_d;
/
create or replace trigger SDD_VWTAB_br
  before insert or update or delete on i$SDD_VWTAB
  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.VIEW_REF is not null)
       )
    or (updating and (
        (:new.VIEW_REF != :old.VIEW_REF
        or (:new.VIEW_REF is not null and :old.VIEW_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_TAB owning_tab
        where  owning_tab.IRID=:new.VIEW_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_VWTAB_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_VWTAB');
  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_VWTAB_br;
/
create or replace trigger SDD_VWTAB_inv
after insert or update of
  TABLE_REF
on i$SDD_VWTAB
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 := 384769782410768712994002972614084665;
  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_VWTAB_inv;
/
create or replace trigger SDD_VWTAB_val
after insert or update of
  TABLE_REF
on i$SDD_VWTAB
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 := 384769782410768712994002972614084665;
  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_VWTAB(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_VWTAB) violated');
    end if;
    if not FK_VWTAB_TO_TAB2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_VWTAB_TO_TAB2) 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_VWTAB_val;
/
create or replace trigger SDD_VWTAB_d
  instead of delete on SDD_VWTAB 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_VWTAB 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_BRL fktab
  where 
        fktab.RELATION_SELECTION_REF = :old.IRID
    ;
 update SDD_COL fktab
    set 
        fktab.RELATION_SELECTION_REF = NULL
  where 
        fktab.RELATION_SELECTION_REF = :old.IRID
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_VWTAB
   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_VWTAB_d;
/
create or replace trigger SDD_WAT_br
  before insert or update or delete on i$SDD_WAT
  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.WORKFLOW_ITEM_TYPE_REF is not null)
       )
    or (updating and (
        (:new.WORKFLOW_ITEM_TYPE_REF != :old.WORKFLOW_ITEM_TYPE_REF
        or (:new.WORKFLOW_ITEM_TYPE_REF is not null and :old.WORKFLOW_ITEM_TYPE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_WIT owning_tab
        where  owning_tab.IRID=:new.WORKFLOW_ITEM_TYPE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_WAT_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.WORKFLOW_MESS_TYPE_REF is not null)
       )
    or (updating and (
        (:new.WORKFLOW_MESS_TYPE_REF != :old.WORKFLOW_MESS_TYPE_REF
        or (:new.WORKFLOW_MESS_TYPE_REF is not null and :old.WORKFLOW_MESS_TYPE_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_WMT owning_tab
        where  owning_tab.IRID=:new.WORKFLOW_MESS_TYPE_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_WAT_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_WAT');
  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_WAT_br;
/
create or replace trigger SDD_WAT_inv
after insert or update of
  ATTRIBUTE_DOMAIN_REF
 ,CLASSIFIER_ATTRIBUTE_REF
on i$SDD_WAT
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 := 415853084460868052408726837337278521;
  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_WAT_inv;
/
create or replace trigger SDD_WAT_val
after insert or update of
  ATTRIBUTE_DOMAIN_REF
 ,CLASSIFIER_ATTRIBUTE_REF
on i$SDD_WAT
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 := 415853084460868052408726837337278521;
  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_WAT(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_WAT) violated');
    end if;
    if not FK_WAT_TO_ADC(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_WAT_TO_ADC) violated - parent key not found');
    end if;
    if not FK_WAT_TO_CAT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_WAT_TO_CAT) 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_WAT_val;
/
create or replace trigger SDD_WAT_d
  instead of delete on SDD_WAT 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_WAT 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_WAT
   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_WAT_d;
/
create or replace trigger SDD_WIN_br
  before insert or update or delete on i$SDD_WIN
  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_WIN_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_WIN');
  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_WIN_br;
/
create or replace trigger SDD_WIN_inv
after insert or update of
  GENERAL_MODULE_REF
on i$SDD_WIN
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 := 384769782411033165517043672746051641;
  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_WIN_inv;
/
create or replace trigger SDD_WIN_val
after insert or update of
  GENERAL_MODULE_REF
on i$SDD_WIN
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 := 384769782411033165517043672746051641;
  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_WIN(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_WIN) violated');
    end if;
    if not FK_WIN_TO_GEM(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_WIN_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_WIN_val;
/
create or replace trigger SDD_WIN_d
  instead of delete on SDD_WIN 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_WIN el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
  delete SDD_ACI fktab
   where 
         fktab.WINDOW_REF = :old.IRID
    ;
 update SDD_MCN fktab
    set 
        fktab.WINDOW_REF = NULL
  where 
        fktab.WINDOW_REF = :old.IRID
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_WIN
   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_WIN_d;
/
create or replace trigger SDD_WIT_br
  before insert or update or delete on i$SDD_WIT
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_WIT_br;
/
create or replace trigger SDD_WIT_ar
  after insert or update or delete on i$SDD_WIT
  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 => 415853084461368623255911019729930297
    );
  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_WIT'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_WIT_ar;
/
create or replace trigger SDD_WIT_inv
after insert
on i$SDD_WIT
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 := 415853084461368623255911019729930297;
  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_WIT_inv;
/
create or replace trigger SDD_WIT_val
after insert
on i$SDD_WIT
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 := 415853084461368623255911019729930297;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_WIT(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_WIT) 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_WIT_val;
/
create or replace trigger SDD_WIT_d
  instead of delete on SDD_WIT 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_ACTORG fktab
    set 
        fktab.WORKFLOW_ITEM_TYPE_REF = NULL
  where 
        fktab.WORKFLOW_ITEM_TYPE_REF = :old.IRID
 ;
 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 jr_context.workarea is not null then
  update SDD_ACTORG
     set WORKFLOW_MESS_TYPE_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.WORKFLOW_MESS_TYPE_REF in (select parent_tab.IRID
                                                      from i$SDD_WMT parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_ACTORG
     set WORKFLOW_MESS_TYPE_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.WORKFLOW_MESS_TYPE_REF in (select parent_tab.IRID
                                                      from i$SDD_WMT 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_WIT_d;
/
create or replace trigger SDD_WMT_br
  before insert or update or delete on i$SDD_WMT
  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.WORKFLOW_ITEM_TYPE_REF is not null)
       )
    or (updating and (
        (:new.WORKFLOW_ITEM_TYPE_REF != :old.WORKFLOW_ITEM_TYPE_REF
        or (:new.WORKFLOW_ITEM_TYPE_REF is not null and :old.WORKFLOW_ITEM_TYPE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_WIT owning_tab
        where  owning_tab.IRID=:new.WORKFLOW_ITEM_TYPE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_WMT_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_WMT');
  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_WMT_br;
/
create or replace trigger SDD_WMT_inv
after insert
on i$SDD_WMT
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 := 415853084461486682417982760860272697;
  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_WMT_inv;
/
create or replace trigger SDD_WMT_val
after insert
on i$SDD_WMT
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 := 415853084461486682417982760860272697;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_WMT(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_WMT) 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_WMT_val;
/
create or replace trigger SDD_WMT_d
  instead of delete on SDD_WMT 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_WMT 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_OST fktab
   where 
         fktab.WORKFLOW_MESS_TYPE_REF = :old.IRID
    ;
  delete SDD_WAT fktab
   where 
         fktab.WORKFLOW_MESS_TYPE_REF = :old.IRID
    ;
 update SDD_ACTORG fktab
    set 
        fktab.WORKFLOW_MESS_TYPE_REF = NULL
  where 
        fktab.WORKFLOW_MESS_TYPE_REF = :old.IRID
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_WMT
   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_WMT_d;
/
create or replace trigger SDD_FOLDER_MEMBERS_CHKBIND 
  BEFORE INSERT ON i$SDD_FOLDER_MEMBERS
  FOR EACH ROW
    declare
    dummy integer;
  begin if not jr_context.constraints_enabled then return; end if; 
    select 1
    into   dummy
    from   sdd_folder_members
    where  member_object       = :new.member_object
    and    parent_ivid         = :new.parent_ivid
    and    ownership_flag      = 'Y'
    and    :new.ownership_flag = 'Y'
    ;
    raise_application_error(-20000, 'Object can only be owned by 1 Folder');
  exception
    when no_data_found then
      null;
end sdd_folder_members_chkbind;
/
