  update SDD_INP
     set TABLESPACE_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_INP fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.TABLESPACE_REF in (select parent_tab.IRID
                                                      from i$SDD_OTB parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_INP
     set TABLESPACE_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_INP fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.TABLESPACE_REF in (select parent_tab.IRID
                                                      from i$SDD_OTB parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_LST
     set TABLESPACE_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_LST fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.TABLESPACE_REF in (select parent_tab.IRID
                                                      from i$SDD_OTB parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_LST
     set TABLESPACE_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_LST fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.TABLESPACE_REF in (select parent_tab.IRID
                                                      from i$SDD_OTB parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_LST
     set INDEX_TABLESPACE_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_LST fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.INDEX_TABLESPACE_REF in (select parent_tab.IRID
                                                      from i$SDD_OTB parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_LST
     set INDEX_TABLESPACE_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_LST fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.INDEX_TABLESPACE_REF in (select parent_tab.IRID
                                                      from i$SDD_OTB parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_DOG
   where ivid in
   (select fktab.ivid
      from i$SDD_DOG fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.QUI_REF in (select parent_tab.IRID
                                                    from i$SDD_QUI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_DOG
   where ivid in
   (select fktab.ivid
      from i$SDD_DOG fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.QUI_REF in (select parent_tab.IRID
                                                    from i$SDD_QUI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_DOI
     set REPLICATION_GROUP_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_DOI fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.REPLICATION_GROUP_REF in (select parent_tab.IRID
                                                      from i$SDD_RPG parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_DOI
     set REPLICATION_GROUP_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_DOI fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.REPLICATION_GROUP_REF in (select parent_tab.IRID
                                                      from i$SDD_RPG parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_DOI
     set SNAPSHOT_GROUP_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_DOI fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.SNAPSHOT_GROUP_REF in (select parent_tab.IRID
                                                      from i$SDD_SRG parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_DOI
     set SNAPSHOT_GROUP_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_DOI fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.SNAPSHOT_GROUP_REF in (select parent_tab.IRID
                                                      from i$SDD_SRG 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_ODB_d;
/
create or replace trigger SDD_ODBODB_br
  before insert or update or delete on i$SDD_ODBODB
  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_REF_FROM is not null)
       )
    or (updating and (
        (:new.DATABASE_REF_FROM != :old.DATABASE_REF_FROM
        or (:new.DATABASE_REF_FROM is not null and :old.DATABASE_REF_FROM is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_ODB owning_tab
        where  owning_tab.IRID=:new.DATABASE_REF_FROM
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_ODBODB_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_ODBODB');
  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_ODBODB_br;
/
create or replace trigger SDD_ODBODB_inv
after insert or update of
  DATABASE_REF_TO
on i$SDD_ODBODB
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 := 384781276432529664870209396330219577;
  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_ODBODB_inv;
/
create or replace trigger SDD_ODBODB_val
after insert or update of
  DATABASE_REF_TO
on i$SDD_ODBODB
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 := 384781276432529664870209396330219577;
  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_ODBODB(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_ODBODB) violated');
    end if;
    if not FK_ODBODB_TO_ORC2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ODBODB_TO_ORC2) 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_ODBODB_val;
/
create or replace trigger SDD_ODBODB_d
  instead of delete on SDD_ODBODB 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_ODBODB 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_ODBODB
   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_ODBODB_d;
/
create or replace trigger SDD_OKY_br
  before insert or update or delete on i$SDD_OKY
  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.CONSTRAINT_REF is not null)
       )
    or (updating and (
        (:new.CONSTRAINT_REF != :old.CONSTRAINT_REF
        or (:new.CONSTRAINT_REF is not null and :old.CONSTRAINT_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_OCO owning_tab
        where  owning_tab.IRID=:new.CONSTRAINT_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_OKY_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_OKY');
  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_OKY_br;
/
create or replace trigger SDD_OKY_inv
after insert or update of
  COLUMN_REF
 ,FOREIGN_COLUMN_REF
 ,FOREIGN_COLUMN_REF2
 ,CQA_REF
 ,FOREIGN_CQA_REF
 ,FOREIGN_CQA_REF2
on i$SDD_OKY
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 := 384781276432770505560835748236118073;
  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_OKY_inv;
/
create or replace trigger SDD_OKY_val
after insert or update of
  COLUMN_REF
 ,FOREIGN_COLUMN_REF
 ,FOREIGN_COLUMN_REF2
 ,CQA_REF
 ,FOREIGN_CQA_REF
 ,FOREIGN_CQA_REF2
on i$SDD_OKY
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 := 384781276432770505560835748236118073;
  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_OKY(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_OKY) violated');
    end if;
    if not FK_OKY_TO_COL(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_OKY_TO_COL) violated - parent key not found');
    end if;
    if not FK_OKY_TO_COL2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_OKY_TO_COL2) violated - parent key not found');
    end if;
    if not FK_OKY_TO_COL3(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_OKY_TO_COL3) violated - parent key not found');
    end if;
    if not FK_OKY_TO_CQA(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_OKY_TO_CQA) violated - parent key not found');
    end if;
    if not FK_OKY_TO_CQA2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_OKY_TO_CQA2) violated - parent key not found');
    end if;
    if not FK_OKY_TO_CQA3(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_OKY_TO_CQA3) 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_OKY_val;
/
create or replace trigger SDD_OKY_d
  instead of delete on SDD_OKY 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_OKY 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_OKY
   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_OKY_d;
/
create or replace trigger SDD_ORG_br
  before insert or update or delete on i$SDD_ORG
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_ORG_br;
/
create or replace trigger SDD_ORG_ar
  after insert or update or delete on i$SDD_ORG
  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 => 384781276433398580303057411049539641
    );
  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_ORG'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_ORG_ar;
/
create or replace trigger SDD_ORG_inv
after insert or update of
  ICON_FILE_REF
 ,ORGANIZATION_UNIT_REF
on i$SDD_ORG
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 := 384781276433398580303057411049539641;
  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_ORG_inv;
/
create or replace trigger SDD_ORG_val
after insert or update of
  ICON_FILE_REF
 ,ORGANIZATION_UNIT_REF
on i$SDD_ORG
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 := 384781276433398580303057411049539641;
  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_ORG(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_ORG) violated');
    end if;
    if not FK_ORG_TO_FILES(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ORG_TO_FILES) violated - parent key not found');
    end if;
    if not FK_ORG_TO_ORG(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ORG_TO_ORG) 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_ORG_val;
/
create or replace trigger SDD_ORG_d
  instead of delete on SDD_ORG 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_ORG_TO_ORG_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
 elsif jr_wastebasket.force_flag then 
  jr_wastebasket.set_secondary_delete;
  update SDD_ORG fktab
     set 
         fktab.ORGANIZATION_UNIT_REF = NULL
   where 
         fktab.ORGANIZATION_UNIT_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
  ;
  delete SDD_ORG fktab
   where 
         fktab.ORGANIZATION_UNIT_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state='I')
  ;
 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 delete SDD_ACTORG fktab
  where 
        fktab.ORGANIZATION_UNIT_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_ORG_d;
/
create or replace trigger SDD_ORGPER_br
  before insert or update or delete on i$SDD_ORGPER
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.ORGANIZATION_UNIT_REF is not null)
       )
    or (updating and (
        (:new.ORGANIZATION_UNIT_REF != :old.ORGANIZATION_UNIT_REF
        or (:new.ORGANIZATION_UNIT_REF is not null and :old.ORGANIZATION_UNIT_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_ORG owning_tab
        where  owning_tab.IRID=:new.ORGANIZATION_UNIT_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_ORGPER_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_ORGPER');
  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_ORGPER_br;
/
create or replace trigger SDD_ORGPER_inv
after insert or update of
  PERSON_REF
on i$SDD_ORGPER
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 := 384781276433549696030509239696377913;
  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_ORGPER_inv;
/
create or replace trigger SDD_ORGPER_val
after insert or update of
  PERSON_REF
on i$SDD_ORGPER
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 := 384781276433549696030509239696377913;
  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_ORGPER(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_ORGPER) violated');
    end if;
    if not FK_ORGPER_TO_PER(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ORGPER_TO_PER) 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_ORGPER_val;
/
create or replace trigger SDD_ORGPER_d
  instead of delete on SDD_ORGPER 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_ORGPER 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_ORGPER
   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_ORGPER_d;
/
create or replace trigger SDD_ORS_br
  before insert or update or delete on i$SDD_ORS
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.ORACLE_DATABASE_REF is not null)
       )
    or (updating and (
        (:new.ORACLE_DATABASE_REF != :old.ORACLE_DATABASE_REF
        or (:new.ORACLE_DATABASE_REF is not null and :old.ORACLE_DATABASE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_ODB owning_tab
        where  owning_tab.IRID=:new.ORACLE_DATABASE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_ORS_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_ORS');
  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_ORS_br;
/
create or replace trigger SDD_ORS_inv
after insert or update of
  STORAGE_DEFINITION_REF
 ,TABLESPACE_REF
on i$SDD_ORS
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 := 384781276433696089391478198698002489;
  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_ORS_inv;
/
create or replace trigger SDD_ORS_val
after insert or update of
  STORAGE_DEFINITION_REF
 ,TABLESPACE_REF
on i$SDD_ORS
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 := 384781276433696089391478198698002489;
  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_ORS(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_ORS) violated');
    end if;
    if not FK_ORS_TO_OSP(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ORS_TO_OSP) violated - parent key not found');
    end if;
    if not FK_ORS_TO_OTB(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ORS_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_ORS_val;
/
create or replace trigger SDD_ORS_d
  instead of delete on SDD_ORS 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_ORS el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 if not jr_wastebasket.force_flag 
   and jr_wastebasket.repos_constraints_enabled then
   -- bug fix 2078916 - BLOCK DELETE IF USER EXTENDED ASSOCIATION EXISTS
   if not jr_ues_chk.check_ues_blocks_delete (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
 elsif jr_wastebasket.force_flag then 
  jr_wastebasket.set_secondary_delete;

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

 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 update SDD_SRG fktab
    set 
        fktab.ROLLBACK_SEGMENT_REF = NULL
  where 
        fktab.ROLLBACK_SEGMENT_REF = :old.IRID
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_ORS
   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_ORS_d;
/
create or replace trigger SDD_ORT_br
  before insert or update or delete on i$SDD_ORT
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_ORT_br;
/
create or replace trigger SDD_ORT_ar
  after insert or update or delete on i$SDD_ORT
  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 => 384781276433988876113416116701251641
    );
  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_ORT'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_ORT_ar;
/
create or replace trigger SDD_ORT_inv
after insert or update of
  ORACLE_OBJECT_TYPE_REF
on i$SDD_ORT
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 := 384781276433988876113416116701251641;
  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_ORT_inv;
/
create or replace trigger SDD_ORT_val
after insert or update of
  ORACLE_OBJECT_TYPE_REF
on i$SDD_ORT
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 := 384781276433988876113416116701251641;
  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_ORT(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_ORT) violated');
    end if;
    if not FK_ORT_TO_OOT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ORT_TO_OOT) 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_ORT_val;
/
create or replace trigger SDD_ORT_d
  instead of delete on SDD_ORT for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
  where ov.irid=:old.irid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  jr_wastebasket.remove(:old.ivid);
  if jr_context.workarea is NULL and not only_version then
   return;
  end if;
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
  if not jr_wastebasket.force_flag 
   and jr_wastebasket.repos_constraints_enabled then
   -- bug fix 2078916 - BLOCK DELETE IF USER EXTENDED ASSOCIATION EXISTS
   if not jr_ues_chk.check_ues_blocks_delete (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_ITM_TO_ORT_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_QTD_TO_ORT_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
 elsif jr_wastebasket.force_flag then 
  jr_wastebasket.set_secondary_delete;
  update SDD_ITM fktab
     set 
         fktab.ORACLE_TYPE_REF = NULL
   where 
         fktab.ORACLE_TYPE_REF = :old.IRID
  ;
  update SDD_QTD fktab
     set 
         fktab.ORACLE_TYPE_REF = NULL
   where 
         fktab.ORACLE_TYPE_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
  ;
  delete SDD_QTD fktab
   where 
         fktab.ORACLE_TYPE_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state='I')
  ;

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

 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 update SDD_ARG fktab
    set 
        fktab.ORACLE_TYPE_REF = NULL
  where 
        fktab.ORACLE_TYPE_REF = :old.IRID
 ;
 update SDD_COL fktab
    set 
        fktab.ORACLE_TYPE_REF = NULL
  where 
        fktab.ORACLE_TYPE_REF = :old.IRID
 ;
 update SDD_MOD fktab
    set 
        fktab.ORACLE_TYPE_REF = NULL
  where 
        fktab.ORACLE_TYPE_REF = :old.IRID
 ;
 update SDD_ORT fktab
    set 
        fktab.ORACLE_OBJECT_TYPE_REF = NULL
  where 
        fktab.ORACLE_OBJECT_TYPE_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
 ;
 delete SDD_ORT fktab
  where 
        fktab.ORACLE_OBJECT_TYPE_REF = :old.IRID
    and fktab.ivid in (select o.ivid
                        from I$SDD_OBJECT_VERSIONS o
                       where o.state='I')
 ;
 update SDD_PGD fktab
    set 
        fktab.ORACLE_TYPE_REF = NULL
  where 
        fktab.ORACLE_TYPE_REF = :old.IRID
 ;
 update SDD_TAB fktab
    set 
        fktab.ORACLE_OBJECT_TYPE_REF = NULL
  where 
        fktab.ORACLE_OBJECT_TYPE_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
 ;
 delete SDD_TAB fktab
  where 
        fktab.ORACLE_OBJECT_TYPE_REF = :old.IRID
    and fktab.ivid in (select o.ivid
                        from I$SDD_OBJECT_VERSIONS o
                       where o.state='I')
 ;
  if (NOT jr_wastebasket.force_flag) and jr_wastebasket.repos_constraints_enabled then
   if not FK_ITE_TO_COL_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_ITM_TO_COL_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_OKY_TO_COL2_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_TABENT_TO_COL_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_TRGCOL_TO_COL_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_ITM_TO_PLM_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_ITM_TO_PLM2_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_MODMOD_TO_MOD2_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_TRG_TO_PLM_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_PVL_TO_ARG2_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_ARG_TO_DAT_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_ITM_TO_DAT2_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_PGD_TO_DAT_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_MCN_TO_SUB_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_MTI_TO_MTI_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_ITM_TO_PGD_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;

   -- bug fix 2078916 - BLOCK DELETE IF USER EXTENDED ASSOCIATION FOR COL EXISTS
   if not jr_ues_chk.FK_UES_TO_DAT_cmd (:old.irid,:old.ivid) then
     delete_ok:=FALSE;
   end if;

 elsif jr_wastebasket.force_flag then
  delete SDD_ITE fktab
   where fktab.COLUMN_REF in (select parent_tab.IRID
                                                      from i$SDD_COL parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
  ;
  delete SDD_TRGCOL fktab
   where fktab.COLUMN_REF in (select parent_tab.IRID
                                                      from i$SDD_COL parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_ITM fktab
     set 
         fktab.COLUMN_REF = NULL
   where fktab.COLUMN_REF in (select parent_tab.IRID
                                                    from i$SDD_COL parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_OKY fktab
     set 
         fktab.FOREIGN_COLUMN_REF = NULL
   where fktab.FOREIGN_COLUMN_REF in (select parent_tab.IRID
                                                    from i$SDD_COL parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_TABENT fktab
     set 
         fktab.COLUMN_REF = NULL
   where fktab.COLUMN_REF in (select parent_tab.IRID
                                                    from i$SDD_COL parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  delete SDD_MODMOD fktab
   where fktab.CHILD_MODULE_REF in (select parent_tab.IRID
                                                      from i$SDD_MOD parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
  ;
  delete SDD_TRG fktab
   where fktab.PLSQL_MODULE_REF in (select parent_tab.IRID
                                                      from i$SDD_MOD parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_ITM fktab
     set 
         fktab.PLSQL_MODULE_REF = NULL
   where fktab.PLSQL_MODULE_REF in (select parent_tab.IRID
                                                    from i$SDD_MOD parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_ITM fktab
     set 
         fktab.CURSOR_REF = NULL
   where fktab.CURSOR_REF in (select parent_tab.IRID
                                                    from i$SDD_MOD parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  delete SDD_PVL fktab
   where fktab.CALLED_ARGUMENT_REF in (select parent_tab.IRID
                                                      from i$SDD_ARG parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_ARG fktab
     set 
         fktab.DATASTRUCTURE_REF = NULL
   where fktab.DATASTRUCTURE_REF in (select parent_tab.IRID
                                                    from i$SDD_DAT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_ITM fktab
     set 
         fktab.DATASTRUCTURE_REF2 = NULL
   where fktab.DATASTRUCTURE_REF2 in (select parent_tab.IRID
                                                    from i$SDD_DAT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_PGD fktab
     set 
         fktab.DATASTRUCTURE_REF = NULL
   where fktab.DATASTRUCTURE_REF in (select parent_tab.IRID
                                                    from i$SDD_DAT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  delete SDD_MCN fktab
   where fktab.SUBCOMPONENT_REF in (select parent_tab.IRID
                                                      from i$SDD_MUN parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_MTI fktab
     set 
         fktab.MTI_REF = NULL
   where fktab.MTI_REF in (select parent_tab.IRID
                                                    from i$SDD_MTI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_ITM fktab
     set 
         fktab.PROGRAM_DATUM_REF = NULL
   where fktab.PROGRAM_DATUM_REF in (select parent_tab.IRID
                                                    from i$SDD_PGD parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  -- bug fix 2078916 - FORCE DELETE IF USER EXTENDED ASSOCIATION EXISTS TO ANY DATASTRUCTURES
  delete SDD_UES fktab
  where fktab.USE_OF_REF in (select parent_tab.IRID
                             from i$SDD_DAT parent_tab
                             where parent_tab.parent_ivid=:old.ivid)
  ;
 end if;--force delete/purge
 if jr_context.workarea is not null then
  delete SDD_CQACOL
   where ivid in
   (select fktab.ivid
      from i$SDD_CQACOL 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.COLUMN_REF in (select parent_tab.IRID
                                                    from i$SDD_COL parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_CQACOL
   where ivid in
   (select fktab.ivid
      from i$SDD_CQACOL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.COLUMN_REF in (select parent_tab.IRID
                                                    from i$SDD_COL parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_CST
   where ivid in
   (select fktab.ivid
      from i$SDD_CST fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.COLUMN_REF in (select parent_tab.IRID
                                                    from i$SDD_COL parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_CST
   where ivid in
   (select fktab.ivid
      from i$SDD_CST fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.COLUMN_REF in (select parent_tab.IRID
                                                    from i$SDD_COL parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_INDCOL
   where ivid in
   (select fktab.ivid
      from i$SDD_INDCOL 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.COLUMN_REF in (select parent_tab.IRID
                                                    from i$SDD_COL parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_INDCOL
   where ivid in
   (select fktab.ivid
      from i$SDD_INDCOL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.COLUMN_REF in (select parent_tab.IRID
                                                    from i$SDD_COL parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_OKY
   where ivid in
   (select fktab.ivid
      from i$SDD_OKY 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.COLUMN_REF in (select parent_tab.IRID
                                                    from i$SDD_COL parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_OKY
   where ivid in
   (select fktab.ivid
      from i$SDD_OKY fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.COLUMN_REF in (select parent_tab.IRID
                                                    from i$SDD_COL parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_TBICOL
   where ivid in
   (select fktab.ivid
      from i$SDD_TBICOL 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.COLUMN_REF in (select parent_tab.IRID
                                                    from i$SDD_COL parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_TBICOL
   where ivid in
   (select fktab.ivid
      from i$SDD_TBICOL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.COLUMN_REF in (select parent_tab.IRID
                                                    from i$SDD_COL parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_ARG
     set COLUMN_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_ARG 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.COLUMN_REF in (select parent_tab.IRID
                                                      from i$SDD_COL parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_ARG
     set COLUMN_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_ARG fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.COLUMN_REF in (select parent_tab.IRID
                                                      from i$SDD_COL parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_COL
     set BASE_COLUMN_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_COL fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.BASE_COLUMN_REF in (select parent_tab.IRID
                                                      from i$SDD_COL parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_COL
     set BASE_COLUMN_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_COL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.BASE_COLUMN_REF in (select parent_tab.IRID
                                                      from i$SDD_COL parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_COL
     set COLUMN_DENORMALISED_FROM = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_COL fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.COLUMN_DENORMALISED_FROM in (select parent_tab.IRID
                                                      from i$SDD_COL parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_COL
     set COLUMN_DENORMALISED_FROM = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_COL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.COLUMN_DENORMALISED_FROM in (select parent_tab.IRID
                                                      from i$SDD_COL parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_OKY
     set FOREIGN_COLUMN_REF2 = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_OKY 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.FOREIGN_COLUMN_REF2 in (select parent_tab.IRID
                                                      from i$SDD_COL parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_OKY
     set FOREIGN_COLUMN_REF2 = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_OKY fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.FOREIGN_COLUMN_REF2 in (select parent_tab.IRID
                                                      from i$SDD_COL parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_PGD
     set COLUMN_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_PGD 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.COLUMN_REF in (select parent_tab.IRID
                                                      from i$SDD_COL parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_PGD
     set COLUMN_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_PGD fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.COLUMN_REF in (select parent_tab.IRID
                                                      from i$SDD_COL parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_A2
   where ivid in
   (select fktab.ivid
      from i$SDD_A2 fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.MODULE_REF in (select parent_tab.IRID
                                                    from i$SDD_MOD parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_A2
   where ivid in
   (select fktab.ivid
      from i$SDD_A2 fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.MODULE_REF in (select parent_tab.IRID
                                                    from i$SDD_MOD parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_A23
   where ivid in
   (select fktab.ivid
      from i$SDD_A23 fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.MODULE_REF in (select parent_tab.IRID
                                                    from i$SDD_MOD parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_A23
   where ivid in
   (select fktab.ivid
      from i$SDD_A23 fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.MODULE_REF in (select parent_tab.IRID
                                                    from i$SDD_MOD parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_A5
   where ivid in
   (select fktab.ivid
      from i$SDD_A5 fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.MODULE_REF in (select parent_tab.IRID
                                                    from i$SDD_MOD parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_A5
   where ivid in
   (select fktab.ivid
      from i$SDD_A5 fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.MODULE_REF in (select parent_tab.IRID
                                                    from i$SDD_MOD parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_A7
   where ivid in
   (select fktab.ivid
      from i$SDD_A7 fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.MODULE_REF in (select parent_tab.IRID
                                                    from i$SDD_MOD parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_A7
   where ivid in
   (select fktab.ivid
      from i$SDD_A7 fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.MODULE_REF in (select parent_tab.IRID
                                                    from i$SDD_MOD parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_DBUMOD
   where ivid in
   (select fktab.ivid
      from i$SDD_DBUMOD 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_MODULE_REF in (select parent_tab.IRID
                                                    from i$SDD_MOD parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_DBUMOD
   where ivid in
   (select fktab.ivid
      from i$SDD_DBUMOD fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.GENERAL_MODULE_REF in (select parent_tab.IRID
                                                    from i$SDD_MOD parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_DOI
   where ivid in
   (select fktab.ivid
      from i$SDD_DOI fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.JAVA_MODULE_REF in (select parent_tab.IRID
                                                    from i$SDD_MOD parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_DOI
   where ivid in
   (select fktab.ivid
      from i$SDD_DOI fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.JAVA_MODULE_REF in (select parent_tab.IRID
                                                    from i$SDD_MOD parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_DOI
   where ivid in
   (select fktab.ivid
      from i$SDD_DOI fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.PLSQL_MODULE_REF in (select parent_tab.IRID
                                                    from i$SDD_MOD parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_DOI
   where ivid in
   (select fktab.ivid
      from i$SDD_DOI fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.PLSQL_MODULE_REF in (select parent_tab.IRID
                                                    from i$SDD_MOD parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_GRPMOD
   where ivid in
   (select fktab.ivid
      from i$SDD_GRPMOD 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_MODULE_REF in (select parent_tab.IRID
                                                    from i$SDD_MOD parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_GRPMOD
   where ivid in
   (select fktab.ivid
      from i$SDD_GRPMOD fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.GENERAL_MODULE_REF in (select parent_tab.IRID
                                                    from i$SDD_MOD parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_MCL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCL fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.MODULE_REF_TO in (select parent_tab.IRID
                                                    from i$SDD_MOD parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_MCL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.MODULE_REF_TO in (select parent_tab.IRID
                                                    from i$SDD_MOD parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_BLI
     set GENERAL_MODULE_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_BLI fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.GENERAL_MODULE_REF in (select parent_tab.IRID
                                                      from i$SDD_MOD parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_BLI
     set GENERAL_MODULE_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_BLI fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.GENERAL_MODULE_REF in (select parent_tab.IRID
                                                      from i$SDD_MOD parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_MOD
     set JAVA_MODULE_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_MOD fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = NVL(fktab.parent_ivid,fktab.ivid)
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.JAVA_MODULE_REF in (select parent_tab.IRID
                                                      from i$SDD_MOD parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_MOD
     set JAVA_MODULE_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_MOD fktab
          ,i$sdd_object_versions ov
     where ov.ivid = NVL(fktab.parent_ivid,fktab.ivid)
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.JAVA_MODULE_REF in (select parent_tab.IRID
                                                      from i$SDD_MOD parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_PVL
     set MODULE_ARGUMENT_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_PVL fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.MODULE_ARGUMENT_REF in (select parent_tab.IRID
                                                      from i$SDD_ARG parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_PVL
     set MODULE_ARGUMENT_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_PVL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.MODULE_ARGUMENT_REF in (select parent_tab.IRID
                                                      from i$SDD_ARG parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_ACI
   where ivid in
   (select fktab.ivid
      from i$SDD_ACI fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.MCN_REF_TO in (select parent_tab.IRID
                                                    from i$SDD_MCN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_ACI
   where ivid in
   (select fktab.ivid
      from i$SDD_ACI fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.MCN_REF_TO in (select parent_tab.IRID
                                                    from i$SDD_MCN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_MCL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCL fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.MCN_REF_FROM in (select parent_tab.IRID
                                                    from i$SDD_MCN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_MCL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.MCN_REF_FROM in (select parent_tab.IRID
                                                    from i$SDD_MCN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_MCL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCL fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.MCN_REF_TO in (select parent_tab.IRID
                                                    from i$SDD_MCN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_MCL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.MCN_REF_TO in (select parent_tab.IRID
                                                    from i$SDD_MCN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_MCN
     set PARENT_MCN_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCN fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.PARENT_MCN_REF in (select parent_tab.IRID
                                                      from i$SDD_MCN parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_MCN
     set PARENT_MCN_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCN fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.PARENT_MCN_REF in (select parent_tab.IRID
                                                      from i$SDD_MCN parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_MCN
     set RIGHT_OF_MCN_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCN fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.RIGHT_OF_MCN_REF in (select parent_tab.IRID
                                                      from i$SDD_MCN parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_MCN
     set RIGHT_OF_MCN_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCN fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.RIGHT_OF_MCN_REF in (select parent_tab.IRID
                                                      from i$SDD_MCN parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_ACI
   where ivid in
   (select fktab.ivid
      from i$SDD_ACI fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.MODULE_NETWORK_REF in (select parent_tab.IRID
                                                    from i$SDD_MODMOD parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_ACI
   where ivid in
   (select fktab.ivid
      from i$SDD_ACI fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.MODULE_NETWORK_REF in (select parent_tab.IRID
                                                    from i$SDD_MODMOD parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_LVI
   where ivid in
   (select fktab.ivid
      from i$SDD_LVI fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.LIST_OF_VALUES_REF in (select parent_tab.IRID
                                                    from i$SDD_MUN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_LVI
   where ivid in
   (select fktab.ivid
      from i$SDD_LVI fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.LIST_OF_VALUES_REF in (select parent_tab.IRID
                                                    from i$SDD_MUN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_MCN
   where ivid in
   (select fktab.ivid
      from i$SDD_MCN fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.MODULE_COMPONENT_REF in (select parent_tab.IRID
                                                    from i$SDD_MUN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_MCN
   where ivid in
   (select fktab.ivid
      from i$SDD_MCN fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.MODULE_COMPONENT_REF in (select parent_tab.IRID
                                                    from i$SDD_MUN parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_IGR
     set ITEM_GROUP_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_IGR fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.ITEM_GROUP_REF in (select parent_tab.IRID
                                                      from i$SDD_IGR parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_IGR
     set ITEM_GROUP_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_IGR fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.ITEM_GROUP_REF in (select parent_tab.IRID
                                                      from i$SDD_IGR parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_ITE
     set ITEM_GROUP_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_ITE fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.ITEM_GROUP_REF in (select parent_tab.IRID
                                                      from i$SDD_IGR parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_ITE
     set ITEM_GROUP_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_ITE fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.ITEM_GROUP_REF in (select parent_tab.IRID
                                                      from i$SDD_IGR parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_ARGITE
   where ivid in
   (select fktab.ivid
      from i$SDD_ARGITE fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.ITEM_REF in (select parent_tab.IRID
                                                    from i$SDD_ITE parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_ARGITE
   where ivid in
   (select fktab.ivid
      from i$SDD_ARGITE fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.ITEM_REF in (select parent_tab.IRID
                                                    from i$SDD_ITE parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_LVI
     set ITEM_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_LVI fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.ITEM_REF in (select parent_tab.IRID
                                                      from i$SDD_ITE parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_LVI
     set ITEM_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_LVI fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.ITEM_REF in (select parent_tab.IRID
                                                      from i$SDD_ITE parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_PVL
     set ITEM_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_PVL fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.ITEM_REF in (select parent_tab.IRID
                                                      from i$SDD_ITE parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_PVL
     set ITEM_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_PVL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.ITEM_REF in (select parent_tab.IRID
                                                      from i$SDD_ITE parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_ITE
   where ivid in
   (select fktab.ivid
      from i$SDD_ITE fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.DETAIL_TABLE_USAGE_REF in (select parent_tab.IRID
                                                    from i$SDD_MTI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_ITE
   where ivid in
   (select fktab.ivid
      from i$SDD_ITE fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.DETAIL_TABLE_USAGE_REF in (select parent_tab.IRID
                                                    from i$SDD_MTI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_MCL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCL fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.TABLE_USAGE_REF_FROM in (select parent_tab.IRID
                                                    from i$SDD_MTI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_MCL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.TABLE_USAGE_REF_FROM in (select parent_tab.IRID
                                                    from i$SDD_MTI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_MCL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCL fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.TABLE_USAGE_REF_TO in (select parent_tab.IRID
                                                    from i$SDD_MTI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_MCL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.TABLE_USAGE_REF_TO in (select parent_tab.IRID
                                                    from i$SDD_MTI parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_MODPGD
   where ivid in
   (select fktab.ivid
      from i$SDD_MODPGD fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.PROGRAM_DATUM_REF in (select parent_tab.IRID
                                                    from i$SDD_PGD parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_MODPGD
   where ivid in
   (select fktab.ivid
      from i$SDD_MODPGD fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.PROGRAM_DATUM_REF in (select parent_tab.IRID
                                                    from i$SDD_PGD parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_MCN
     set WINDOW_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCN fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.WINDOW_REF in (select parent_tab.IRID
                                                      from i$SDD_WIN parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_MCN
     set WINDOW_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_MCN fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.WINDOW_REF in (select parent_tab.IRID
                                                      from i$SDD_WIN parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 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_ORT_d;
/
create or replace trigger SDD_OSP_br
  before insert or update or delete on i$SDD_OSP
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_OSP_br;
/
create or replace trigger SDD_OSP_ar
  after insert or update or delete on i$SDD_OSP
  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 => 384781276434248606269973947188004921
    );
  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_OSP'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_OSP_ar;
/
create or replace trigger SDD_OSP_inv
after insert
on i$SDD_OSP
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 := 384781276434248606269973947188004921;
  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_OSP_inv;
/
create or replace trigger SDD_OSP_val
after insert
on i$SDD_OSP
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 := 384781276434248606269973947188004921;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_OSP(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_OSP) 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_OSP_val;
/
create or replace trigger SDD_OSP_d
  instead of delete on SDD_OSP for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
  where ov.irid=:old.irid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  jr_wastebasket.remove(:old.ivid);
  if jr_context.workarea is NULL and not only_version then
   return;
  end if;
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
  if not jr_wastebasket.force_flag 
   and jr_wastebasket.repos_constraints_enabled then
   -- bug fix 2078916 - BLOCK DELETE IF USER EXTENDED ASSOCIATION EXISTS
   if not jr_ues_chk.check_ues_blocks_delete (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_DOI_TO_OSP_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_DOI_TO_OSP2_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_INS_TO_OSP_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_ORS_TO_OSP_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_OTB_TO_OSP_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
 elsif jr_wastebasket.force_flag then 
  jr_wastebasket.set_secondary_delete;
  update SDD_DOI fktab
     set 
         fktab.STORAGE_DEFINITION_REF = NULL
   where 
         fktab.STORAGE_DEFINITION_REF = :old.IRID
  ;
  update SDD_DOI fktab
     set 
         fktab.SNAP_LOG_STORAGE_REF = NULL
   where 
         fktab.SNAP_LOG_STORAGE_REF = :old.IRID
  ;
  update SDD_INS fktab
     set 
         fktab.STORAGE_DEFINITION_REF = NULL
   where 
         fktab.STORAGE_DEFINITION_REF = :old.IRID
  ;
  update SDD_ORS fktab
     set 
         fktab.STORAGE_DEFINITION_REF = NULL
   where 
         fktab.STORAGE_DEFINITION_REF = :old.IRID
  ;
  update SDD_OTB fktab
     set 
         fktab.STORAGE_DEFINITION_REF = NULL
   where 
         fktab.STORAGE_DEFINITION_REF = :old.IRID
  ;

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

 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 update SDD_CST fktab
    set 
        fktab.STORAGE_DEFINITION_REF = NULL
  where 
        fktab.STORAGE_DEFINITION_REF = :old.IRID
 ;
 update SDD_INP fktab
    set 
        fktab.STORAGE_DEFINITION_REF = NULL
  where 
        fktab.STORAGE_DEFINITION_REF = :old.IRID
 ;
 update SDD_LST fktab
    set 
        fktab.STORAGE_DEFINITION_REF = NULL
  where 
        fktab.STORAGE_DEFINITION_REF = :old.IRID
 ;
 update SDD_LST fktab
    set 
        fktab.INDEX_STORAGE_DEFN_REF = NULL
  where 
        fktab.INDEX_STORAGE_DEFN_REF = :old.IRID
 ;
 update SDD_TBP fktab
    set 
        fktab.STORAGE_DEFINITION_REF = NULL
  where 
        fktab.STORAGE_DEFINITION_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_OSP_d;
/
create or replace trigger SDD_OSQ_br
  before insert or update or delete on i$SDD_OSQ
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_OSQ_br;
/
create or replace trigger SDD_OSQ_ar
  after insert or update or delete on i$SDD_OSQ
  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 => 384781276434503614060048908029544505
    );
  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_OSQ'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_OSQ_ar;
/
create or replace trigger SDD_OSQ_inv
after insert
on i$SDD_OSQ
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 := 384781276434503614060048908029544505;
  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_OSQ_inv;
/
create or replace trigger SDD_OSQ_val
after insert
on i$SDD_OSQ
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 := 384781276434503614060048908029544505;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_OSQ(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_OSQ) 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_OSQ_val;
/
create or replace trigger SDD_OSQ_d
  instead of delete on SDD_OSQ for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
  where ov.irid=:old.irid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  jr_wastebasket.remove(:old.ivid);
  if jr_context.workarea is NULL and not only_version then
   return;
  end if;
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
  if not jr_wastebasket.force_flag 
   and jr_wastebasket.repos_constraints_enabled then
   -- bug fix 2078916 - BLOCK DELETE IF USER EXTENDED ASSOCIATION EXISTS
   if not jr_ues_chk.check_ues_blocks_delete (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_COL_TO_OSQ_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
 elsif jr_wastebasket.force_flag then 
  jr_wastebasket.set_secondary_delete;
  update SDD_COL fktab
     set 
         fktab.SEQUENCE_REF = NULL
   where 
         fktab.SEQUENCE_REF = :old.IRID
  ;

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

 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 delete SDD_DOI fktab
  where 
        fktab.SEQUENCE_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_OSQ_d;
/
create or replace trigger SDD_OST_br
  before insert or update or delete on i$SDD_OST
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.BUSINESS_OBJECT_REF is not null)
       )
    or (updating and (
        (:new.BUSINESS_OBJECT_REF != :old.BUSINESS_OBJECT_REF
        or (:new.BUSINESS_OBJECT_REF is not null and :old.BUSINESS_OBJECT_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_BOB owning_tab
        where  owning_tab.IRID=:new.BUSINESS_OBJECT_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_OST_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.CLASSIFIER_REF is not null)
       )
    or (updating and (
        (:new.CLASSIFIER_REF != :old.CLASSIFIER_REF
        or (:new.CLASSIFIER_REF is not null and :old.CLASSIFIER_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_CLA owning_tab
        where  owning_tab.IRID=:new.CLASSIFIER_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_OST_OWNER) violated - parent key not found');
      end;
    elsif (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_OST_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_OST_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_OST');
  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_OST_br;
/
create or replace trigger SDD_OST_inv
after insert or update of
  ICON_FILE_REF
on i$SDD_OST
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 := 384781276434720842918260911709374521;
  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_OST_inv;
/
create or replace trigger SDD_OST_val
after insert or update of
  ICON_FILE_REF
on i$SDD_OST
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 := 384781276434720842918260911709374521;
  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_OST(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_OST) violated');
    end if;
    if not FK_OST_TO_FILES(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_OST_TO_FILES) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_OST_val;
/
create or replace trigger SDD_OST_d
  instead of delete on SDD_OST 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_OST 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_CLA fktab
  where 
        fktab.OBJECT_STATE_REF = :old.IRID
    ;
 delete SDD_OSTOST fktab
  where 
        fktab.OBJECT_STATE_OF_REF = :old.IRID
    ;
 delete SDD_TRA fktab
  where 
        fktab.TARGET_OBJECT_STATE_REF = :old.IRID
    ;
  delete SDD_OSTOST fktab
   where 
         fktab.OBJECT_STATE_ON_REF = :old.IRID
    ;
  delete SDD_SRU fktab
   where 
         fktab.OBJECT_STATE_REF = :old.IRID
    ;
  delete SDD_TRA fktab
   where 
         fktab.SOURCE_OBJECT_STATE_REF = :old.IRID
    ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_OST
   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_OST_d;
/
create or replace trigger SDD_OSTOST_br
  before insert or update or delete on i$SDD_OSTOST
  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.OBJECT_STATE_ON_REF is not null)
       )
    or (updating and (
        (:new.OBJECT_STATE_ON_REF != :old.OBJECT_STATE_ON_REF
        or (:new.OBJECT_STATE_ON_REF is not null and :old.OBJECT_STATE_ON_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_OST owning_tab
        where  owning_tab.IRID=:new.OBJECT_STATE_ON_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_OSTOST_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_OSTOST');
  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_OSTOST_br;
/
create or replace trigger SDD_OSTOST_inv
after insert or update of
  OBJECT_STATE_OF_REF
on i$SDD_OSTOST
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 := 384781276434905015211092827872708665;
  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_OSTOST_inv;
/
create or replace trigger SDD_OSTOST_val
after insert or update of
  OBJECT_STATE_OF_REF
on i$SDD_OSTOST
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 := 384781276434905015211092827872708665;
  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_OSTOST(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_OSTOST) violated');
    end if;
    if not FK_OSTOST_TO_OST2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_OSTOST_TO_OST2) 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_OSTOST_val;
/
create or replace trigger SDD_OSTOST_d
  instead of delete on SDD_OSTOST 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_OSTOST 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_OSTOST
   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_OSTOST_d;
/
create or replace trigger SDD_OTB_br
  before insert or update or delete on i$SDD_OTB
  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_REF is not null)
       )
    or (updating and (
        (:new.DATABASE_REF != :old.DATABASE_REF
        or (:new.DATABASE_REF is not null and :old.DATABASE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_ODB owning_tab
        where  owning_tab.IRID=:new.DATABASE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_OTB_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_OTB');
  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_OTB_br;
/
create or replace trigger SDD_OTB_inv
after insert or update of
  STORAGE_DEFINITION_REF
on i$SDD_OTB
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 := 384781276435051408572061786874333241;
  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_OTB_inv;
/
create or replace trigger SDD_OTB_val
after insert or update of
  STORAGE_DEFINITION_REF
on i$SDD_OTB
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 := 384781276435051408572061786874333241;
  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_OTB(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_OTB) violated');
    end if;
    if not FK_OTB_TO_OSP(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_OTB_TO_OSP) 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_OTB_val;
/
create or replace trigger SDD_OTB_d
  instead of delete on SDD_OTB 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_OTB el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
  if not jr_wastebasket.force_flag 
   and jr_wastebasket.repos_constraints_enabled then
   -- bug fix 2078916 - BLOCK DELETE IF USER EXTENDED ASSOCIATION EXISTS
   if not jr_ues_chk.check_ues_blocks_delete (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_DBU_TO_OTB_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_DBU_TO_OTB2_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_DOI_TO_OTB_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_DOI_TO_OTB2_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_DOI_TO_OTB3_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_INS_TO_OTB_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_ORS_TO_OTB_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_TBP_TO_OTB_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_TSQ_TO_OTB_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_TSQ fktab
   where 
         fktab.TABLESPACE_REF = :old.IRID
    ;
  update SDD_DBU fktab
     set 
         fktab.DEFAULT_TABLESPACE_REF = NULL
   where 
         fktab.DEFAULT_TABLESPACE_REF = :old.IRID
  ;
  update SDD_DBU fktab
     set 
         fktab.TEMP_TABLESPACE_REF = NULL
   where 
         fktab.TEMP_TABLESPACE_REF = :old.IRID
  ;
  update SDD_DOI fktab
     set 
         fktab.TABLESPACE_REF = NULL
   where 
         fktab.TABLESPACE_REF = :old.IRID
  ;
  update SDD_DOI fktab
     set 
         fktab.OVERFLOW_TABLESPACE_REF = NULL
   where 
         fktab.OVERFLOW_TABLESPACE_REF = :old.IRID
  ;
  update SDD_DOI fktab
     set 
         fktab.SNAP_LOG_TABLESPACE_REF = NULL
   where 
         fktab.SNAP_LOG_TABLESPACE_REF = :old.IRID
  ;
  update SDD_INS fktab
     set 
         fktab.TABLESPACE_REF = NULL
   where 
         fktab.TABLESPACE_REF = :old.IRID
  ;
  update SDD_ORS fktab
     set 
         fktab.TABLESPACE_REF = NULL
   where 
         fktab.TABLESPACE_REF = :old.IRID
  ;
  update SDD_TBP fktab
     set 
         fktab.TABLESPACE_REF = NULL
   where 
         fktab.TABLESPACE_REF = :old.IRID
  ;

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

 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
  delete SDD_DFI fktab
   where 
         fktab.TABLESPACE_REF = :old.IRID
    ;
 update SDD_CST fktab
    set 
        fktab.TABLESPACE_REF = NULL
  where 
        fktab.TABLESPACE_REF = :old.IRID
 ;
 update SDD_INP fktab
    set 
        fktab.TABLESPACE_REF = NULL
  where 
        fktab.TABLESPACE_REF = :old.IRID
 ;
 update SDD_LST fktab
    set 
        fktab.TABLESPACE_REF = NULL
  where 
        fktab.TABLESPACE_REF = :old.IRID
 ;
 update SDD_LST fktab
    set 
        fktab.INDEX_TABLESPACE_REF = NULL
  where 
        fktab.INDEX_TABLESPACE_REF = :old.IRID
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_OTB
   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_OTB_d;
/
create or replace trigger SDD_PER_br
  before insert or update or delete on i$SDD_PER
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_PER_br;
/
create or replace trigger SDD_PER_ar
  after insert or update or delete on i$SDD_PER
  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 => 384781276435339472927516835232368697
    );
  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_PER'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_PER_ar;
/
create or replace trigger SDD_PER_inv
after insert
on i$SDD_PER
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 := 384781276435339472927516835232368697;
  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_PER_inv;
/
create or replace trigger SDD_PER_val
after insert
on i$SDD_PER
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 := 384781276435339472927516835232368697;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_PER(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_PER) 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_PER_val;
/
create or replace trigger SDD_PER_d
  instead of delete on SDD_PER 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_ORGPER fktab
  where 
        fktab.PERSON_REF = :old.IRID
    ;
 delete SDD_PERPER fktab
  where 
        fktab.MANAGED_PERSON_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_PER_d;
/
create or replace trigger SDD_PERACR_br
  before insert or update or delete on i$SDD_PERACR
  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.PERSON_REF is not null)
       )
    or (updating and (
        (:new.PERSON_REF != :old.PERSON_REF
        or (:new.PERSON_REF is not null and :old.PERSON_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_PER owning_tab
        where  owning_tab.IRID=:new.PERSON_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_PERACR_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_PERACR');
  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_PERACR_br;
/
create or replace trigger SDD_PERACR_inv
after insert or update of
  ACTOR_REF
on i$SDD_PERACR
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 := 384781276435443364990139967427070009;
  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_PERACR_inv;
/
create or replace trigger SDD_PERACR_val
after insert or update of
  ACTOR_REF
on i$SDD_PERACR
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 := 384781276435443364990139967427070009;
  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_PERACR(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_PERACR) violated');
    end if;
    if not FK_PERACR_TO_ACR(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_PERACR_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_PERACR_val;
/
create or replace trigger SDD_PERACR_d
  instead of delete on SDD_PERACR 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_PERACR 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_PERACR
   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_PERACR_d;
/
create or replace trigger SDD_PERPER_br
  before insert or update or delete on i$SDD_PERPER
  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.MANAGER_REF is not null)
       )
    or (updating and (
        (:new.MANAGER_REF != :old.MANAGER_REF
        or (:new.MANAGER_REF is not null and :old.MANAGER_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_PER owning_tab
        where  owning_tab.IRID=:new.MANAGER_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_PERPER_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_PERPER');
  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_PERPER_br;
/
create or replace trigger SDD_PERPER_inv
after insert or update of
  MANAGED_PERSON_REF
on i$SDD_PERPER
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 := 384781276435589758351108926428694585;
  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_PERPER_inv;
/
create or replace trigger SDD_PERPER_val
after insert or update of
  MANAGED_PERSON_REF
on i$SDD_PERPER
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 := 384781276435589758351108926428694585;
  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_PERPER(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_PERPER) violated');
    end if;
    if not FK_PERPER_TO_PER2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_PERPER_TO_PER2) 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_PERPER_val;
/
create or replace trigger SDD_PERPER_d
  instead of delete on SDD_PERPER 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_PERPER 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_PERPER
   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_PERPER_d;
/
create or replace trigger SDD_PGD_br
  before insert or update or delete on i$SDD_PGD
  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_PGD_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.PLSQL_MODULE_REF is not null)
       )
    or (updating and (
        (:new.PLSQL_MODULE_REF != :old.PLSQL_MODULE_REF
        or (:new.PLSQL_MODULE_REF is not null and :old.PLSQL_MODULE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select nvl(pac_ref, irid), nvl(parent_ivid, ivid)
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_MOD owning_tab
        where  owning_tab.IRID=:new.PLSQL_MODULE_REF
        and    jr_vn.context(nvl(owning_tab.parent_ivid, owning_tab.ivid)) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_PGD_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_PGD');
  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_PGD_br;
/
create or replace trigger SDD_PGD_inv
after insert or update of
  COLUMN_REF
 ,DATASTRUCTURE_REF
 ,DOMAIN_REF
 ,GENERAL_MODULE_REF
 ,ORACLE_TYPE_REF
 ,PLSQL_MODULE_REF
 ,TABLE_DEFINITION_REF
on i$SDD_PGD
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 := 384781276435736151712077885430319161;
  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_PGD_inv;
/
create or replace trigger SDD_PGD_val
after insert or update of
  COLUMN_REF
 ,DATASTRUCTURE_REF
 ,DOMAIN_REF
 ,GENERAL_MODULE_REF
 ,ORACLE_TYPE_REF
 ,PLSQL_MODULE_REF
 ,TABLE_DEFINITION_REF
on i$SDD_PGD
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 := 384781276435736151712077885430319161;
  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_PGD(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_PGD) violated');
    end if;
    if not FK_PGD_TO_COL(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_PGD_TO_COL) violated - parent key not found');
    end if;
    if not FK_PGD_TO_DAT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_PGD_TO_DAT) violated - parent key not found');
    end if;
    if not FK_PGD_TO_DOM(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_PGD_TO_DOM) violated - parent key not found');
    end if;
    if not FK_PGD_TO_GEM(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_PGD_TO_GEM) violated - parent key not found');
    end if;
    if not FK_PGD_TO_ORT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_PGD_TO_ORT) violated - parent key not found');
    end if;
    if not FK_PGD_TO_PLM(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_PGD_TO_PLM) violated - parent key not found');
    end if;
    if not FK_PGD_TO_TBL(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_PGD_TO_TBL) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_PGD_val;
/
create or replace trigger SDD_PGD_d
  instead of delete on SDD_PGD 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_PGD 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_ITM_TO_PGD_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
 elsif jr_wastebasket.force_flag then 
  jr_wastebasket.set_secondary_delete;
  update SDD_ITM fktab
     set 
         fktab.PROGRAM_DATUM_REF = NULL
   where 
         fktab.PROGRAM_DATUM_REF = :old.IRID
  ;
 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 delete SDD_MODPGD fktab
  where 
        fktab.PROGRAM_DATUM_REF = :old.IRID
    ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_PGD
   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_PGD_d;
/
create or replace trigger SDD_PRS_br
  before insert or update or delete on i$SDD_PRS
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_PRS_br;
/
create or replace trigger SDD_PRS_ar
  after insert or update or delete on i$SDD_PRS
  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 => 384781276436137552863121805273483321
    );
  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_PRS'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_PRS_ar;
/
create or replace trigger SDD_PRS_inv
after insert
on i$SDD_PRS
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 := 384781276436137552863121805273483321;
  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_PRS_inv;
/
create or replace trigger SDD_PRS_val
after insert
on i$SDD_PRS
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 := 384781276436137552863121805273483321;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_PRS(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_PRS) 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_PRS_val;
/
create or replace trigger SDD_PRS_d
  instead of delete on SDD_PRS for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
  where ov.irid=:old.irid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  jr_wastebasket.remove(:old.ivid);
  if jr_context.workarea is NULL and not only_version then
   return;
  end if;
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 if not jr_wastebasket.force_flag 
   and jr_wastebasket.repos_constraints_enabled then
   -- bug fix 2078916 - BLOCK DELETE IF USER EXTENDED ASSOCIATION EXISTS
   if not jr_ues_chk.check_ues_blocks_delete (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
 elsif jr_wastebasket.force_flag then 
  jr_wastebasket.set_secondary_delete;

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

 end if;--Constraints enabled/force

 jr_wastebasket.set_secondary_delete;
 delete SDD_PRU fktab
  where 
        fktab.PREFERENCE_SET_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_PRS_d;
/
create or replace trigger SDD_PRU_inv
after insert or update of
  PREFERENCE_SET_REF
 ,CIELEMENT_REF
on i$SDD_PRU
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 := 384781276436354781721333808953313337;
  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_PRU_inv;
/
create or replace trigger SDD_PRU_val
after insert or update of
  PREFERENCE_SET_REF
 ,CIELEMENT_REF
on i$SDD_PRU
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 := 384781276436354781721333808953313337;
  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_PRU(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_PRU) violated');
    end if;
    if not UK_PRU(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (UK_PRU) violated');
    end if;
    if not FK_PRU_TO_PRS(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_PRU_TO_PRS) 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_PRU_val;
/
create or replace trigger SDD_PRU_d
  instead of delete on SDD_PRU 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_PRU 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_PRU
   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_PRU_d;
/
create or replace trigger SDD_PSE_br
  before insert or update or delete on i$SDD_PSE
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_PSE_br;
/
create or replace trigger SDD_PSE_ar
  after insert or update or delete on i$SDD_PSE
  for each row 
begin
  -- Inserting
  if inserting then
    jr_object_version.ins ( :new.irid, :new.ivid
    , name => :new.TYPE
    , type_irid => :new.TYPES
    , table_irid => 384781276436501175082302767954937913
    );
  end if;  -- inserting
  -- Updating
  if updating then
    jr_object_version.upd ( :old.ivid
      , name => :new.TYPE
    );
  end if;  -- updating
  -- Deleting
  if deleting then
    jr_object_version.del ( :old.irid, :old.ivid, 'SDD_PSE'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_PSE_ar;
/
create or replace trigger SDD_PSE_inv
after insert or update of
  NAMED_RULE_REF
on i$SDD_PSE
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 := 384781276436501175082302767954937913;
  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_PSE_inv;
/
create or replace trigger SDD_PSE_val
after insert or update of
  NAMED_RULE_REF
on i$SDD_PSE
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 := 384781276436501175082302767954937913;
  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_PSE(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_PSE) violated');
    end if;
    if not FK_PSE_TO_RUL(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_PSE_TO_RUL) 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_PSE_val;
/
create or replace trigger SDD_PSE_d
  instead of delete on SDD_PSE 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_TRA fktab
  where 
        fktab.TARGET_PSEUDOSTATE_REF = :old.IRID
    ;
 if jr_context.workarea is not null then
  update SDD_TRA
     set TRANSITION_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_TRA fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.TRANSITION_REF in (select parent_tab.IRID
                                                      from i$SDD_TRA parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_TRA
     set TRANSITION_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_TRA fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.TRANSITION_REF in (select parent_tab.IRID
                                                      from i$SDD_TRA parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_PSE_d;
/
create or replace trigger SDD_PST_br
  before insert or update or delete on i$SDD_PST
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_PST_br;
/
create or replace trigger SDD_PST_ar
  after insert or update or delete on i$SDD_PST
  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 => 415825818397148963439505096499021881
    );
  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_PST'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_PST_ar;
/
create or replace trigger SDD_PST_inv
after insert
on i$SDD_PST
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 := 415825818397148963439505096499021881;
  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_PST_inv;
/
create or replace trigger SDD_PST_val
after insert
on i$SDD_PST
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 := 415825818397148963439505096499021881;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_PST(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_PST) 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_PST_val;
/
create or replace trigger SDD_PST_d
  instead of delete on SDD_PST 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_FOLDERS fktab
    set 
        fktab.CODING_STANDARD_REF = NULL
  where 
        fktab.CODING_STANDARD_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
 ;
 delete SDD_FOLDERS fktab
  where 
        fktab.CODING_STANDARD_REF = :old.IRID
    and fktab.ivid in (select o.ivid
                        from I$SDD_OBJECT_VERSIONS o
                       where o.state='I')
 ;
 update SDD_FOLDERS fktab
    set 
        fktab.TRANSFORMER_STANDARD_REF = NULL
  where 
        fktab.TRANSFORMER_STANDARD_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
 ;
 delete SDD_FOLDERS fktab
  where 
        fktab.TRANSFORMER_STANDARD_REF = :old.IRID
    and fktab.ivid in (select o.ivid
                        from I$SDD_OBJECT_VERSIONS o
                       where o.state='I')
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_PST_d;
/
create or replace trigger SDD_PSTADC_br
  before insert or update or delete on i$SDD_PSTADC
  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.PROJECT_STANDARD_REF is not null)
       )
    or (updating and (
        (:new.PROJECT_STANDARD_REF != :old.PROJECT_STANDARD_REF
        or (:new.PROJECT_STANDARD_REF is not null and :old.PROJECT_STANDARD_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_PST owning_tab
        where  owning_tab.IRID=:new.PROJECT_STANDARD_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_PSTADC_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_PSTADC');
  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_PSTADC_br;
/
create or replace trigger SDD_PSTADC_inv
after insert or update of
  ATTRIBUTE_DOMAIN_REF
on i$SDD_PSTADC
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 := 415825818397394526496614318050134073;
  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_PSTADC_inv;
/
create or replace trigger SDD_PSTADC_val
after insert or update of
  ATTRIBUTE_DOMAIN_REF
on i$SDD_PSTADC
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 := 415825818397394526496614318050134073;
  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_PSTADC(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_PSTADC) violated');
    end if;
    if not FK_PSTADC_TO_ADC(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_PSTADC_TO_ADC) 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_PSTADC_val;
/
create or replace trigger SDD_PSTADC_d
  instead of delete on SDD_PSTADC 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_PSTADC 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_PSTADC
   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_PSTADC_d;
/
create or replace trigger SDD_PVL_br
  before insert or update or delete on i$SDD_PVL
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.MODULE_NETWORK_REF is not null)
       )
    or (updating and (
        (:new.MODULE_NETWORK_REF != :old.MODULE_NETWORK_REF
        or (:new.MODULE_NETWORK_REF is not null and :old.MODULE_NETWORK_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_MODMOD owning_tab
        where  owning_tab.IRID=:new.MODULE_NETWORK_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_PVL_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_PVL');
  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_PVL_br;
/
create or replace trigger SDD_PVL_inv
after insert or update of
  MODULE_ARGUMENT_REF
 ,CALLED_ARGUMENT_REF
 ,ITEM_REF
on i$SDD_PVL
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 := 384781276436619234244374509085280313;
  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_PVL_inv;
/
create or replace trigger SDD_PVL_val
after insert or update of
  MODULE_ARGUMENT_REF
 ,CALLED_ARGUMENT_REF
 ,ITEM_REF
on i$SDD_PVL
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 := 384781276436619234244374509085280313;
  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_PVL(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_PVL) violated');
    end if;
    if not FK_PVL_TO_ARG(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_PVL_TO_ARG) violated - parent key not found');
    end if;
    if not FK_PVL_TO_ARG2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_PVL_TO_ARG2) violated - parent key not found');
    end if;
    if not FK_PVL_TO_ITE(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_PVL_TO_ITE) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_PVL_val;
/
create or replace trigger SDD_PVL_d
  instead of delete on SDD_PVL 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_PVL 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_PVL
   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_PVL_d;
/
create or replace trigger SDD_QSU_br
  before insert or update or delete on i$SDD_QSU
  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.QUEUE_IMPLEMENTATION_REF is not null)
       )
    or (updating and (
        (:new.QUEUE_IMPLEMENTATION_REF != :old.QUEUE_IMPLEMENTATION_REF
        or (:new.QUEUE_IMPLEMENTATION_REF is not null and :old.QUEUE_IMPLEMENTATION_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select pac_ref, parent_ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_QUI owning_tab
        where  owning_tab.IRID=:new.QUEUE_IMPLEMENTATION_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_QSU_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_QSU');
  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_QSU_br;
/
create or replace trigger SDD_QSU_inv
after insert
on i$SDD_QSU
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 := 415825818397838428946004064700221497;
  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_QSU_inv;
/
create or replace trigger SDD_QSU_val
after insert
on i$SDD_QSU
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 := 415825818397838428946004064700221497;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_QSU(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_QSU) 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_QSU_val;
/
create or replace trigger SDD_QSU_d
  instead of delete on SDD_QSU 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_QSU 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_QSU
   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_QSU_d;
/
create or replace trigger SDD_QTD_br
  before insert or update or delete on i$SDD_QTD
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_QTD_br;
/
create or replace trigger SDD_QTD_ar
  after insert or update or delete on i$SDD_QTD
  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 => 415825818397989544673455893347059769
    );
  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_QTD'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_QTD_ar;
/
create or replace trigger SDD_QTD_inv
after insert or update of
  ORACLE_TYPE_REF
on i$SDD_QTD
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 := 415825818397989544673455893347059769;
  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_QTD_inv;
/
create or replace trigger SDD_QTD_val
after insert or update of
  ORACLE_TYPE_REF
on i$SDD_QTD
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 := 415825818397989544673455893347059769;
  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_QTD(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_QTD) violated');
    end if;
    if not FK_QTD_TO_ORT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_QTD_TO_ORT) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_QTD_val;
/
create or replace trigger SDD_QTD_d
  instead of delete on SDD_QTD for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
  where ov.irid=:old.irid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  jr_wastebasket.remove(:old.ivid);
  if jr_context.workarea is NULL and not only_version then
   return;
  end if;
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
  if not jr_wastebasket.force_flag 
   and jr_wastebasket.repos_constraints_enabled then
   -- bug fix 2078916 - BLOCK DELETE IF USER EXTENDED ASSOCIATION EXISTS
   if not jr_ues_chk.check_ues_blocks_delete (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_QUE_TO_QTD_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
 elsif jr_wastebasket.force_flag then 
  jr_wastebasket.set_secondary_delete;
  update SDD_QUE fktab
     set 
         fktab.QUEUE_TABLE_DEF_REF = NULL
   where 
         fktab.QUEUE_TABLE_DEF_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
  ;
  delete SDD_QUE fktab
   where 
         fktab.QUEUE_TABLE_DEF_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state='I')
  ;

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

 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 delete SDD_DOI fktab
  where 
        fktab.QUEUE_TABLE_DEF_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_QTD_d;
/
create or replace trigger SDD_QUE_br
  before insert or update or delete on i$SDD_QUE
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_QUE_br;
/
create or replace trigger SDD_QUE_ar
  after insert or update or delete on i$SDD_QUE
  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 => 415825818398168994599804939865180217
    );
  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_QUE'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_QUE_ar;
/
create or replace trigger SDD_QUE_inv
after insert or update of
  QUEUE_TABLE_DEF_REF
on i$SDD_QUE
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 := 415825818398168994599804939865180217;
  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_QUE_inv;
/
create or replace trigger SDD_QUE_val
after insert or update of
  QUEUE_TABLE_DEF_REF
on i$SDD_QUE
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 := 415825818398168994599804939865180217;
  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_QUE(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_QUE) violated');
    end if;
    if not FK_QUE_TO_QTD(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_QUE_TO_QTD) 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_QUE_val;
/
create or replace trigger SDD_QUE_d
  instead of delete on SDD_QUE for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
  where ov.irid=:old.irid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  jr_wastebasket.remove(:old.ivid);
  if jr_context.workarea is NULL and not only_version then
   return;
  end if;
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
  if not jr_wastebasket.force_flag 
   and jr_wastebasket.repos_constraints_enabled then
   -- bug fix 2078916 - BLOCK DELETE IF USER EXTENDED ASSOCIATION EXISTS
   if not jr_ues_chk.check_ues_blocks_delete (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_QUI_TO_NPQ_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_QUI fktab
   where 
         fktab.NON_PERSISTENT_QUEUE_REF = :old.IRID
    ;

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

 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 delete SDD_QUI fktab
  where 
        fktab.PERSISTENT_QUEUE_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_QUE_d;
/
create or replace trigger SDD_QUI_br
  before insert or update or delete on i$SDD_QUI
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.ORACLE_DATABASE_REF is not null)
       )
    or (updating and (
        (:new.ORACLE_DATABASE_REF != :old.ORACLE_DATABASE_REF
        or (:new.ORACLE_DATABASE_REF is not null and :old.ORACLE_DATABASE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_ODB owning_tab
        where  owning_tab.IRID=:new.ORACLE_DATABASE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_QUI_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_QUI');
  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_QUI_br;
/
create or replace trigger SDD_QUI_inv
after insert or update of
  QUEUE_TABLE_DBU_REF
 ,NON_PERSISTENT_QUEUE_REF
 ,PERSISTENT_QUEUE_REF
on i$SDD_QUI
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 := 415825818398329555060222507802445881;
  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_QUI_inv;
/
create or replace trigger SDD_QUI_val
after insert or update of
  QUEUE_TABLE_DBU_REF
 ,NON_PERSISTENT_QUEUE_REF
 ,PERSISTENT_QUEUE_REF
on i$SDD_QUI
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 := 415825818398329555060222507802445881;
  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_QUI(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_QUI) violated');
    end if;
    if not FK_QUI_TO_DBU(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_QUI_TO_DBU) violated - parent key not found');
    end if;
    if not FK_QUI_TO_NPQ(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_QUI_TO_NPQ) violated - parent key not found');
    end if;
    if not FK_QUI_TO_PQU(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_QUI_TO_PQU) 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_QUI_val;
/
create or replace trigger SDD_QUI_d
  instead of delete on SDD_QUI 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_QUI 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_DOG fktab
  where 
        fktab.QUI_REF = :old.IRID
    ;
  delete SDD_QSU fktab
   where 
         fktab.QUEUE_IMPLEMENTATION_REF = :old.IRID
    ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_QUI
   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_QUI_d;
/
create or replace trigger SDD_RELEND_br
  before insert or update or delete on i$SDD_RELEND
  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.FROM_ENTITY_REF is not null)
       )
    or (updating and (
        (:new.FROM_ENTITY_REF != :old.FROM_ENTITY_REF
        or (:new.FROM_ENTITY_REF is not null and :old.FROM_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.FROM_ENTITY_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_RELEND_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
  -- CW 14-Dec-2001
  -- Fix bug 2021170, the function below can raise no_data_found during a copy of both relends when the Entity
  -- at one end is copied and the other is not yet copied.
  -- Fixed jr_copy so this does not happen but this is an extra failsafe so that processing will stop if the
  -- access rights checking call below raises the no_data_found exception.
  begin
    jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_RELEND');
  exception
    when no_data_found then
      raise_application_error(-20291, 'integrity constraint (SDD_RELEND_OWNER) violated - parent key not found');
  end;
  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_RELEND_br;
/
create or replace trigger SDD_RELEND_inv
after insert or update of
  TO_ENTITY_REF
on i$SDD_RELEND
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 := 384781276436912020966312427088529465;
  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_RELEND_inv;
/
create or replace trigger SDD_RELEND_val
after insert or update of
  TO_ENTITY_REF
on i$SDD_RELEND
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 := 384781276436912020966312427088529465;
  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_RELEND(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_RELEND) violated');
    end if;
    if not FK_RELEND_TO_ENT2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_RELEND_TO_ENT2) 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_RELEND_val;
/
create or replace trigger SDD_RELEND_d
  instead of delete on SDD_RELEND 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_RELEND 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_ENTUIE_TO_RELEND_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
 elsif jr_wastebasket.force_flag then 
  jr_wastebasket.set_secondary_delete;
  delete SDD_ENTUIE fktab
   where 
         fktab.RELATIONSHIP_END_REF = :old.IRID
    ;
 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 update SDD_OCO fktab
    set 
        fktab.RELATIONSHIP_END_REF = NULL
  where 
        fktab.RELATIONSHIP_END_REF = :old.IRID
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_RELEND
   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_RELEND_d;
/
create or replace trigger SDD_RGP_br
  before insert or update or delete on i$SDD_RGP
  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.REPLICATION_GROUP_REF is not null)
       )
    or (updating and (
        (:new.REPLICATION_GROUP_REF != :old.REPLICATION_GROUP_REF
        or (:new.REPLICATION_GROUP_REF is not null and :old.REPLICATION_GROUP_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_RPG owning_tab
        where  owning_tab.IRID=:new.REPLICATION_GROUP_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_RGP_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_RGP');
  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_RGP_br;
/
create or replace trigger SDD_RGP_inv
after insert or update of
  ORACLE_DATABASE_REF
on i$SDD_RGP
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 := 384781276437218974787698954027419705;
  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_RGP_inv;
/
create or replace trigger SDD_RGP_val
after insert or update of
  ORACLE_DATABASE_REF
on i$SDD_RGP
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 := 384781276437218974787698954027419705;
  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_RGP(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_RGP) violated');
    end if;
    if not FK_RGP_TO_ORC(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_RGP_TO_ORC) 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_RGP_val;
/
create or replace trigger SDD_RGP_d
  instead of delete on SDD_RGP 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_RGP 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_RGP
   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_RGP_d;
/
create or replace trigger SDD_RPG_br
  before insert or update or delete on i$SDD_RPG
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.ORACLE_DATABASE_REF is not null)
       )
    or (updating and (
        (:new.ORACLE_DATABASE_REF != :old.ORACLE_DATABASE_REF
        or (:new.ORACLE_DATABASE_REF is not null and :old.ORACLE_DATABASE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_ODB owning_tab
        where  owning_tab.IRID=:new.ORACLE_DATABASE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_RPG_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_RPG');
  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_RPG_br;
/
create or replace trigger SDD_RPG_inv
after insert
on i$SDD_RPG
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 := 384781276437478704944256784514172985;
  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_RPG_inv;
/
create or replace trigger SDD_RPG_val
after insert
on i$SDD_RPG
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 := 384781276437478704944256784514172985;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_RPG(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_RPG) 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_RPG_val;
/
create or replace trigger SDD_RPG_d
  instead of delete on SDD_RPG 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_RPG 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_RGP fktab
   where 
         fktab.REPLICATION_GROUP_REF = :old.IRID
    ;
 update SDD_DOI fktab
    set 
        fktab.REPLICATION_GROUP_REF = NULL
  where 
        fktab.REPLICATION_GROUP_REF = :old.IRID
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_RPG
   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_RPG_d;
/
create or replace trigger SDD_RUL_br
  before insert or update or delete on i$SDD_RUL
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_RUL_br;
/
create or replace trigger SDD_RUL_ar
  after insert or update or delete on i$SDD_RUL
  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 => 384781276437714823268400266774857785
    );
  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_RUL'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_RUL_ar;
/
create or replace trigger SDD_RUL_inv
after insert or update of
  EVENT_CLASSIFIER_REF
 ,LANGUAGE_REF
 ,METHOD_REF
on i$SDD_RUL
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 := 384781276437714823268400266774857785;
  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_RUL_inv;
/
create or replace trigger SDD_RUL_val
after insert or update of
  EVENT_CLASSIFIER_REF
 ,LANGUAGE_REF
 ,METHOD_REF
on i$SDD_RUL
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 := 384781276437714823268400266774857785;
  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_RUL(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_RUL) violated');
    end if;
    if not FK_RUL_TO_EVC(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_RUL_TO_EVC) violated - parent key not found');
    end if;
    if not FK_RUL_TO_LAN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_RUL_TO_LAN) violated - parent key not found');
    end if;
    if not FK_RUL_TO_MET(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_RUL_TO_MET) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_RUL_val;
/
create or replace trigger SDD_RUL_d
  instead of delete on SDD_RUL 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_METRUL fktab
  where 
        fktab.NAMED_RULE_REF = :old.IRID
    ;
 delete SDD_RULRUL fktab
  where 
        fktab.USE_OF_RULE_REF = :old.IRID
    ;
 update SDD_ACT fktab
    set 
        fktab.PRE_RULE_REF = NULL
  where 
        fktab.PRE_RULE_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.PRE_RULE_REF = :old.IRID
    and fktab.ivid in (select o.ivid
                        from I$SDD_OBJECT_VERSIONS o
                       where o.state='I')
 ;
 update SDD_ACT fktab
    set 
        fktab.POST_RULE_REF = NULL
  where 
        fktab.POST_RULE_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.POST_RULE_REF = :old.IRID
    and fktab.ivid in (select o.ivid
                        from I$SDD_OBJECT_VERSIONS o
                       where o.state='I')
 ;
 update SDD_PSE fktab
    set 
        fktab.NAMED_RULE_REF = NULL
  where 
        fktab.NAMED_RULE_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
 ;
 delete SDD_PSE fktab
  where 
        fktab.NAMED_RULE_REF = :old.IRID
    and fktab.ivid in (select o.ivid
                        from I$SDD_OBJECT_VERSIONS o
                       where o.state='I')
 ;
 update SDD_TRA fktab
    set 
        fktab.NAMED_RULE_REF = NULL
  where 
        fktab.NAMED_RULE_REF = :old.IRID
 ;
 update SDD_USC fktab
    set 
        fktab.PRE_RULE_REF = NULL
  where 
        fktab.PRE_RULE_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
 ;
 delete SDD_USC fktab
  where 
        fktab.PRE_RULE_REF = :old.IRID
    and fktab.ivid in (select o.ivid
                        from I$SDD_OBJECT_VERSIONS o
                       where o.state='I')
 ;
 update SDD_USC fktab
    set 
        fktab.POST_RULE_REF = NULL
  where 
        fktab.POST_RULE_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
 ;
 delete SDD_USC fktab
  where 
        fktab.POST_RULE_REF = :old.IRID
    and fktab.ivid in (select o.ivid
                        from I$SDD_OBJECT_VERSIONS o
                       where o.state='I')
 ;
 update SDD_USCEPA fktab
    set 
        fktab.NAMED_RULE_REF = NULL
  where 
        fktab.NAMED_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_RUL_d;
/
create or replace trigger SDD_RULRUL_br
  before insert or update or delete on i$SDD_RULRUL
  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.USED_IN_RULE_REF is not null)
       )
    or (updating and (
        (:new.USED_IN_RULE_REF != :old.USED_IN_RULE_REF
        or (:new.USED_IN_RULE_REF is not null and :old.USED_IN_RULE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_RUL owning_tab
        where  owning_tab.IRID=:new.USED_IN_RULE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_RULRUL_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_RULRUL');
  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_RULRUL_br;
/
create or replace trigger SDD_RULRUL_inv
after insert or update of
  USE_OF_RULE_REF
on i$SDD_RULRUL
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 := 384781276437865938995852095421696057;
  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_RULRUL_inv;
/
create or replace trigger SDD_RULRUL_val
after insert or update of
  USE_OF_RULE_REF
on i$SDD_RULRUL
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 := 384781276437865938995852095421696057;
  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_RULRUL(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_RULRUL) violated');
    end if;
    if not FK_RULRUL_TO_RUL2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_RULRUL_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_RULRUL_val;
/
create or replace trigger SDD_RULRUL_d
  instead of delete on SDD_RULRUL 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_RULRUL 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_RULRUL
   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_RULRUL_d;
/
create or replace trigger SDD_SBA_br
  before insert or update or delete on i$SDD_SBA
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.METHOD_REF is not null)
       )
    or (updating and (
        (:new.METHOD_REF != :old.METHOD_REF
        or (:new.METHOD_REF is not null and :old.METHOD_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select pac_ref, parent_ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_MET owning_tab
        where  owning_tab.IRID=:new.METHOD_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_SBA_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_SBA');
  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_SBA_br;
/
create or replace trigger SDD_SBA_inv
after insert or update of
  EVENT_SUBSCRIPTION_REF
 ,SUBSCRIPTION_DETAIL_REF
on i$SDD_SBA
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 := 384781276438021777089786793713748025;
  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_SBA_inv;
/
create or replace trigger SDD_SBA_val
after insert or update of
  EVENT_SUBSCRIPTION_REF
 ,SUBSCRIPTION_DETAIL_REF
on i$SDD_SBA
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 := 384781276438021777089786793713748025;
  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_SBA(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_SBA) violated');
    end if;
    if not FK_SBA_TO_EVS(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_SBA_TO_EVS) violated - parent key not found');
    end if;
    if not FK_SBA_TO_SUD(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_SBA_TO_SUD) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_SBA_val;
/
create or replace trigger SDD_SBA_d
  instead of delete on SDD_SBA 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_SBA 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_SBA
   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_SBA_d;
/
create or replace trigger SDD_SMI_br
  before insert or update or delete on i$SDD_SMI
  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.USER_DEFINED_SET_REF is not null)
       )
    or (updating and (
        (:new.USER_DEFINED_SET_REF != :old.USER_DEFINED_SET_REF
        or (:new.USER_DEFINED_SET_REF is not null and :old.USER_DEFINED_SET_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_UDS owning_tab
        where  owning_tab.IRID=:new.USER_DEFINED_SET_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_SMI_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_SMI');
  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_SMI_br;
/
create or replace trigger SDD_SMI_inv
after insert
on i$SDD_SMI
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 := 384781276438205949382618709877082169;
  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_SMI_inv;
/
create or replace trigger SDD_SMI_val
after insert
on i$SDD_SMI
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 := 384781276438205949382618709877082169;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_SMI(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_SMI) 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_SMI_val;
/
create or replace trigger SDD_SMI_d
  instead of delete on SDD_SMI 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_SMI 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_SMI
   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_SMI_d;
/
create or replace trigger SDD_SOU_br
  before insert or update or delete on i$SDD_SOU
  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.BATCHLINE_REF is not null)
       )
    or (updating and (
        (:new.BATCHLINE_REF != :old.BATCHLINE_REF
        or (:new.BATCHLINE_REF is not null and :old.BATCHLINE_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_BLI owning_tab
        where  owning_tab.IRID=:new.BATCHLINE_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_SOU_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_SOU');
  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_SOU_br;
/
create or replace trigger SDD_SOU_inv
after insert
on i$SDD_SOU
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 := 384781276438451512439727931428194361;
  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_SOU_inv;
/
create or replace trigger SDD_SOU_val
after insert
on i$SDD_SOU
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 := 384781276438451512439727931428194361;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_SOU(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_SOU) 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_SOU_val;
/
create or replace trigger SDD_SOU_d
  instead of delete on SDD_SOU 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_SOU 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_SOU
   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_SOU_d;
/
create or replace trigger SDD_SPV_br
  before insert or update or delete on i$SDD_SPV
  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_SPV_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.ROLE_REF is not null)
       )
    or (updating and (
        (:new.ROLE_REF != :old.ROLE_REF
        or (:new.ROLE_REF is not null and :old.ROLE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select pac_ref, parent_ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_GRP owning_tab
        where  owning_tab.IRID=:new.ROLE_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_SPV_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_SPV');
  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_SPV_br;
/
create or replace trigger SDD_SPV_inv
after insert
on i$SDD_SPV
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 := 384781276438687630763871413688879161;
  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_SPV_inv;
/
create or replace trigger SDD_SPV_val
after insert
on i$SDD_SPV
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 := 384781276438687630763871413688879161;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_SPV(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_SPV) 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_SPV_val;
/
create or replace trigger SDD_SPV_d
  instead of delete on SDD_SPV 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_SPV 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_SPV
   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_SPV_d;
/
create or replace trigger SDD_SQS_br
  before insert or update or delete on i$SDD_SQS
  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.LIST_OF_VALUES_REF is not null)
       )
    or (updating and (
        (:new.LIST_OF_VALUES_REF != :old.LIST_OF_VALUES_REF
        or (:new.LIST_OF_VALUES_REF is not null and :old.LIST_OF_VALUES_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select nvl(pac_ref, irid), nvl(parent_ivid, ivid)
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_MUN owning_tab
        where  owning_tab.IRID=:new.LIST_OF_VALUES_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_SQS_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.MODULE_COMPONENT_REF is not null)
       )
    or (updating and (
        (:new.MODULE_COMPONENT_REF != :old.MODULE_COMPONENT_REF
        or (:new.MODULE_COMPONENT_REF is not null and :old.MODULE_COMPONENT_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select nvl(pac_ref, irid), nvl(parent_ivid, ivid)
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_MUN owning_tab
        where  owning_tab.IRID=:new.MODULE_COMPONENT_REF
        and    jr_vn.context(nvl(owning_tab.parent_ivid, owning_tab.ivid)) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_SQS_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_SQS');
  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_SQS_br;
/
create or replace trigger SDD_SQS_inv
after insert or update of
  LIST_OF_VALUES_REF
 ,MODULE_COMPONENT_REF
on i$SDD_SQS
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 := 384781276438952083286912113820846137;
  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_SQS_inv;
/
create or replace trigger SDD_SQS_val
after insert or update of
  LIST_OF_VALUES_REF
 ,MODULE_COMPONENT_REF
on i$SDD_SQS
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 := 384781276438952083286912113820846137;
  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_SQS(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_SQS) violated');
    end if;
    if not FK_SQS_TO_LOV(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_SQS_TO_LOV) violated - parent key not found');
    end if;
    if not FK_SQS_TO_MCO(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_SQS_TO_MCO) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_SQS_val;
/
create or replace trigger SDD_SQS_d
  instead of delete on SDD_SQS 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_SQS 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_ITE fktab
   where 
         fktab.SQL_QUERY_SET_REF = :old.IRID
    ;
  delete SDD_MTI fktab
   where 
         fktab.SQL_QUERY_SET_REF = :old.IRID
    ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_SQS
   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_SQS_d;
/
create or replace trigger SDD_SRG_br
  before insert or update or delete on i$SDD_SRG
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.ORACLE_DATABASE_REF is not null)
       )
    or (updating and (
        (:new.ORACLE_DATABASE_REF != :old.ORACLE_DATABASE_REF
        or (:new.ORACLE_DATABASE_REF is not null and :old.ORACLE_DATABASE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_ODB owning_tab
        where  owning_tab.IRID=:new.ORACLE_DATABASE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_SRG_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_SRG');
  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_SRG_br;
/
create or replace trigger SDD_SRG_inv
after insert or update of
  ROLLBACK_SEGMENT_REF
on i$SDD_SRG
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 := 384781276439221258176435683598026809;
  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_SRG_inv;
/
create or replace trigger SDD_SRG_val
after insert or update of
  ROLLBACK_SEGMENT_REF
on i$SDD_SRG
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 := 384781276439221258176435683598026809;
  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_SRG(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_SRG) violated');
    end if;
    if not FK_SRG_TO_ORS(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_SRG_TO_ORS) 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_SRG_val;
/
create or replace trigger SDD_SRG_d
  instead of delete on SDD_SRG 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_SRG 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_DOI fktab
    set 
        fktab.SNAPSHOT_GROUP_REF = NULL
  where 
        fktab.SNAPSHOT_GROUP_REF = :old.IRID
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_SRG
   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_SRG_d;
/
create or replace trigger SDD_SRU_br
  before insert or update or delete on i$SDD_SRU
  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.OBJECT_STATE_REF is not null)
       )
    or (updating and (
        (:new.OBJECT_STATE_REF != :old.OBJECT_STATE_REF
        or (:new.OBJECT_STATE_REF is not null and :old.OBJECT_STATE_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_OST owning_tab
        where  owning_tab.IRID=:new.OBJECT_STATE_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_SRU_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_SRU');
  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_SRU_br;
/
create or replace trigger SDD_SRU_inv
after insert or update of
  LANGUAGE_REF
 ,METHOD_REF
on i$SDD_SRU
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 := 384781276439504600165407862310848569;
  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_SRU_inv;
/
create or replace trigger SDD_SRU_val
after insert or update of
  LANGUAGE_REF
 ,METHOD_REF
on i$SDD_SRU
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 := 384781276439504600165407862310848569;
  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_SRU(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_SRU) violated');
    end if;
    if not FK_SRU_TO_LAN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_SRU_TO_LAN) violated - parent key not found');
    end if;
    if not FK_SRU_TO_MET(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_SRU_TO_MET) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_SRU_val;
/
create or replace trigger SDD_SRU_d
  instead of delete on SDD_SRU 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_SRU el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 delete SDD_METRUL fktab
  where 
        fktab.STATE_RULE_REF = :old.IRID
    ;
  delete SDD_MEMCOM fktab
   where 
         fktab.STATE_RULE_REF = :old.IRID
    ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_SRU
   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_SRU_d;
/
create or replace trigger SDD_STE_br
  before insert or update or delete on i$SDD_STE
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_STE_br;
/
create or replace trigger SDD_STE_ar
  after insert or update or delete on i$SDD_STE
  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 => 415825818401238532813670209254082617
    );
  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_STE'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_STE_ar;
/
create or replace trigger SDD_STE_inv
after insert or update of
  ICON_FILE_REF
on i$SDD_STE
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 := 415825818401238532813670209254082617;
  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_STE_inv;
/
create or replace trigger SDD_STE_val
after insert or update of
  ICON_FILE_REF
on i$SDD_STE
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 := 415825818401238532813670209254082617;
  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_STE(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_STE) violated');
    end if;
    if not FK_STE_TO_FILES(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_STE_TO_FILES) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_STE_val;
/
create or replace trigger SDD_STE_d
  instead of delete on SDD_STE 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_STESTE_TO_STE2_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_STESTE fktab
   where 
         fktab.SUPERTYPE_REF = :old.IRID
    ;
 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 if jr_context.workarea is not null then
  delete SDD_TAGVAL
   where ivid in
   (select fktab.ivid
      from i$SDD_TAGVAL 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.TAG_REF in (select parent_tab.IRID
                                                    from i$SDD_TAG parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_TAGVAL
   where ivid in
   (select fktab.ivid
      from i$SDD_TAGVAL fktab
          ,i$sdd_object_versions ov
       where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.TAG_REF in (select parent_tab.IRID
                                                    from i$SDD_TAG 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_STE_d;
/
create or replace trigger SDD_STESTE_br
  before insert or update or delete on i$SDD_STESTE
  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_STE 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_STESTE_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_STESTE');
  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_STESTE_br;
/
create or replace trigger SDD_STESTE_inv
after insert or update of
  SUPERTYPE_REF
on i$SDD_STESTE
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 := 415825818401394370907604907546134585;
  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_STESTE_inv;
/
create or replace trigger SDD_STESTE_val
after insert or update of
  SUPERTYPE_REF
on i$SDD_STESTE
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 := 415825818401394370907604907546134585;
  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_STESTE(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_STESTE) violated');
    end if;
    if not FK_STESTE_TO_STE2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_STESTE_TO_STE2) 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_STESTE_val;
/
create or replace trigger SDD_STESTE_d
  instead of delete on SDD_STESTE 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_STESTE 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_STESTE
   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_STESTE_d;
/
create or replace trigger SDD_SUD_br
  before insert or update or delete on i$SDD_SUD
  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.EVENT_SUBSCRIPTION_REF is not null)
       )
    or (updating and (
        (:new.EVENT_SUBSCRIPTION_REF != :old.EVENT_SUBSCRIPTION_REF
        or (:new.EVENT_SUBSCRIPTION_REF is not null and :old.EVENT_SUBSCRIPTION_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_EVS owning_tab
        where  owning_tab.IRID=:new.EVENT_SUBSCRIPTION_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_SUD_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_SUD');
  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_SUD_br;
/
create or replace trigger SDD_SUD_inv
after insert or update of
  ASSOCIATION_END_REF
 ,EVENT_PUBLICATION_REF
on i$SDD_SUD
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 := 384781276439679327725274039183755321;
  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_SUD_inv;
/
create or replace trigger SDD_SUD_val
after insert or update of
  ASSOCIATION_END_REF
 ,EVENT_PUBLICATION_REF
on i$SDD_SUD
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 := 384781276439679327725274039183755321;
  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_SUD(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_SUD) violated');
    end if;
    if not FK_SUD_TO_AEN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_SUD_TO_AEN) violated - parent key not found');
    end if;
    if not FK_SUD_TO_CLAEVC(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_SUD_TO_CLAEVC) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_SUD_val;
/
create or replace trigger SDD_SUD_d
  instead of delete on SDD_SUD 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_SUD el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
  if not jr_wastebasket.force_flag 
   and jr_wastebasket.repos_constraints_enabled then
   if not FK_EVH_TO_SUD_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
 elsif jr_wastebasket.force_flag then 
  jr_wastebasket.set_secondary_delete;
  delete SDD_EVH fktab
   where 
         fktab.SUBSCRIPTION_DETAIL_REF = :old.IRID
    ;
 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 delete SDD_SBA fktab
  where 
        fktab.SUBSCRIPTION_DETAIL_REF = :old.IRID
    ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_SUD
   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_SUD_d;
/
create or replace trigger SDD_SYN_br
  before insert or update or delete on i$SDD_SYN
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_SYN_br;
/
create or replace trigger SDD_SYN_ar
  after insert or update or delete on i$SDD_SYN
  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 => 384781276439825721086242998185379897
    );
  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_SYN'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_SYN_ar;
/
create or replace trigger SDD_SYN_inv
after insert or update of
  ENTITY_REF
 ,TERM_REF
on i$SDD_SYN
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 := 384781276439825721086242998185379897;
  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_SYN_inv;
/
create or replace trigger SDD_SYN_val
after insert or update of
  ENTITY_REF
 ,TERM_REF
on i$SDD_SYN
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 := 384781276439825721086242998185379897;
  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_SYN(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_SYN) violated');
    end if;
    if not FK_SYN_TO_ENT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_SYN_TO_ENT) violated - parent key not found');
    end if;
    if not FK_SYN_TO_TER(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_SYN_TO_TER) 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_SYN_val;
/
create or replace trigger SDD_SYN_d
  instead of delete on SDD_SYN 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_SYN_d;
/
create or replace trigger SDD_TAB_br
  before insert or update or delete on i$SDD_TAB
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_TAB_br;
/
create or replace trigger SDD_TAB_ar
  after insert or update or delete on i$SDD_TAB
  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 => 384781276440061839410386480446064697
    );
  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_TAB'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_TAB_ar;
/
create or replace trigger SDD_TAB_inv
after insert or update of
  RECORD_FILE_REF
 ,CLUSTER_REF
 ,ORACLE_OBJECT_TYPE_REF
on i$SDD_TAB
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 := 384781276440061839410386480446064697;
  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_TAB_inv;
/
create or replace trigger SDD_TAB_val
after insert or update of
  RECORD_FILE_REF
 ,CLUSTER_REF
 ,ORACLE_OBJECT_TYPE_REF
on i$SDD_TAB
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 := 384781276440061839410386480446064697;
  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_TAB(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_TAB) violated');
    end if;
    if not FK_TAB_RFI(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_TAB_RFI) violated - parent key not found');
    end if;
    if not FK_TAB_TO_OCL(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_TAB_TO_OCL) violated - parent key not found');
    end if;
    if not FK_TAB_TO_OOT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_TAB_TO_OOT) 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_TAB_val;
/
create or replace trigger SDD_TAB_d
  instead of delete on SDD_TAB for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
  where ov.irid=:old.irid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  jr_wastebasket.remove(:old.ivid);
  if jr_context.workarea is NULL and not only_version then
   return;
  end if;
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
  if not jr_wastebasket.force_flag 
   and jr_wastebasket.repos_constraints_enabled then
   -- bug fix 2078916 - BLOCK DELETE IF USER EXTENDED ASSOCIATION EXISTS
   if not jr_ues_chk.check_ues_blocks_delete (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_ITM_TO_TBL_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_MTI_TO_TAB_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_VWTAB_TO_TAB2_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_MTI fktab
   where 
         fktab.TABLE_REF = :old.IRID
    ;
  delete SDD_VWTAB fktab
   where 
         fktab.TABLE_REF = :old.IRID
    ;
  update SDD_ITM fktab
     set 
         fktab.TABLE_DEFINITION_REF = NULL
   where 
         fktab.TABLE_DEFINITION_REF = :old.IRID
  ;

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

 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 delete SDD_A6 fktab
  where 
        fktab.TABLE_REF = :old.IRID
    ;
 delete SDD_DOI fktab
  where 
        fktab.SNAPSHOT_DEFINITION_REF = :old.IRID
    ;
 delete SDD_DOI fktab
  where 
        fktab.TABLE_DEFINITION_REF = :old.IRID
    ;
 delete SDD_DOI fktab
  where 
        fktab.VIEW_DEFINITION_REF = :old.IRID
    ;
 delete SDD_OCO fktab
  where 
        fktab.FOREIGN_TABLE_REF = :old.IRID
    ;
 update SDD_ARG fktab
    set 
        fktab.TABLE_DEFINITION_REF = NULL
  where 
        fktab.TABLE_DEFINITION_REF = :old.IRID
 ;
 update SDD_COL fktab
    set 
        fktab.SCOPE_TABLE_REF = NULL
  where 
        fktab.SCOPE_TABLE_REF = :old.IRID
 ;
 update SDD_CQA fktab
    set 
        fktab.SCOPE_TABLE_REF = NULL
  where 
        fktab.SCOPE_TABLE_REF = :old.IRID
 ;
 update SDD_PGD fktab
    set 
        fktab.TABLE_DEFINITION_REF = NULL
  where 
        fktab.TABLE_DEFINITION_REF = :old.IRID
 ;
  if (NOT jr_wastebasket.force_flag) and jr_wastebasket.repos_constraints_enabled then
   if not FK_ITE_TO_COL_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_ITM_TO_COL_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_OKY_TO_COL2_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_TABENT_TO_COL_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_TRGCOL_TO_COL_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_ITM_TO_CQA_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_OKY_TO_CQA2_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_MCL_TO_JCO_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_MCL_TO_PCO_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_MTI_TO_JCO_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   -- bug fix 2078916 - BLOCK DELETE IF USER EXTENDED ASSOCIATION FOR COL EXISTS
   if not jr_ues_chk.FK_UES_TO_COL_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
  elsif jr_wastebasket.force_flag then
  delete SDD_ITE fktab
   where fktab.COLUMN_REF in (select parent_tab.IRID
                                                      from i$SDD_COL parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
  ;
  delete SDD_TRGCOL fktab
   where fktab.COLUMN_REF in (select parent_tab.IRID
                                                      from i$SDD_COL parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_ITM fktab
     set 
         fktab.COLUMN_REF = NULL
   where fktab.COLUMN_REF in (select parent_tab.IRID
                                                    from i$SDD_COL parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_OKY fktab
     set 
         fktab.FOREIGN_COLUMN_REF = NULL
   where fktab.FOREIGN_COLUMN_REF in (select parent_tab.IRID
                                                    from i$SDD_COL parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_TABENT fktab
     set 
         fktab.COLUMN_REF = NULL
   where fktab.COLUMN_REF in (select parent_tab.IRID
                                                    from i$SDD_COL parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_ITM fktab
     set 
         fktab.CQA_REF = NULL
   where fktab.CQA_REF in (select parent_tab.IRID
                                                    from i$SDD_CQA parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_OKY fktab
     set 
         fktab.FOREIGN_CQA_REF = NULL
   where fktab.FOREIGN_CQA_REF in (select parent_tab.IRID
                                                    from i$SDD_CQA parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  delete SDD_MCL fktab
   where fktab.JOIN_CONSTRAINT_REF in (select parent_tab.IRID
                                                      from i$SDD_OCO parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
  ;
  delete SDD_MCL fktab
   where fktab.PRIMARY_KEY_REF in (select parent_tab.IRID
                                                      from i$SDD_OCO parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_MTI fktab
     set 
         fktab.CONSTRAINT_REF = NULL
   where fktab.CONSTRAINT_REF in (select parent_tab.IRID
                                                    from i$SDD_OCO parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  -- bug fix 2078916 - FORCE DELETE IF USER EXTENDED ASSOCIATION EXISTS TO ANY COLUMNS
  delete SDD_UES fktab
  where fktab.USE_OF_REF in (select parent_tab.IRID
                             from i$SDD_COL parent_tab
                             where parent_tab.parent_ivid=:old.ivid)
  ;
  end if;--force delete/purge
 if jr_context.workarea is not null then
  delete SDD_CQACOL
   where ivid in
   (select fktab.ivid
      from i$SDD_CQACOL 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.COLUMN_REF in (select parent_tab.IRID
                                                    from i$SDD_COL parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_CQACOL
   where ivid in
   (select fktab.ivid
      from i$SDD_CQACOL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.COLUMN_REF in (select parent_tab.IRID
                                                    from i$SDD_COL parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_CST
   where ivid in
   (select fktab.ivid
      from i$SDD_CST fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.COLUMN_REF in (select parent_tab.IRID
                                                    from i$SDD_COL parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_CST
   where ivid in
   (select fktab.ivid
      from i$SDD_CST fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.COLUMN_REF in (select parent_tab.IRID
                                                    from i$SDD_COL parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_INDCOL
   where ivid in
   (select fktab.ivid
      from i$SDD_INDCOL 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.COLUMN_REF in (select parent_tab.IRID
                                                    from i$SDD_COL parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_INDCOL
   where ivid in
   (select fktab.ivid
      from i$SDD_INDCOL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.COLUMN_REF in (select parent_tab.IRID
                                                    from i$SDD_COL parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_OKY
   where ivid in
   (select fktab.ivid
      from i$SDD_OKY 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.COLUMN_REF in (select parent_tab.IRID
                                                    from i$SDD_COL parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_OKY
   where ivid in
   (select fktab.ivid
      from i$SDD_OKY fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.COLUMN_REF in (select parent_tab.IRID
                                                    from i$SDD_COL parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_TBICOL
   where ivid in
   (select fktab.ivid
      from i$SDD_TBICOL 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.COLUMN_REF in (select parent_tab.IRID
                                                    from i$SDD_COL parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_TBICOL
   where ivid in
   (select fktab.ivid
      from i$SDD_TBICOL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.COLUMN_REF in (select parent_tab.IRID
                                                    from i$SDD_COL parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_ARG
     set COLUMN_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_ARG 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.COLUMN_REF in (select parent_tab.IRID
                                                      from i$SDD_COL parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_ARG
     set COLUMN_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_ARG fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.COLUMN_REF in (select parent_tab.IRID
                                                      from i$SDD_COL parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_COL
     set BASE_COLUMN_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_COL fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.BASE_COLUMN_REF in (select parent_tab.IRID
                                                      from i$SDD_COL parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_COL
     set BASE_COLUMN_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_COL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.BASE_COLUMN_REF in (select parent_tab.IRID
                                                      from i$SDD_COL parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_COL
     set COLUMN_DENORMALISED_FROM = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_COL fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.COLUMN_DENORMALISED_FROM in (select parent_tab.IRID
                                                      from i$SDD_COL parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_COL
     set COLUMN_DENORMALISED_FROM = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_COL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.COLUMN_DENORMALISED_FROM in (select parent_tab.IRID
                                                      from i$SDD_COL parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_OKY
     set FOREIGN_COLUMN_REF2 = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_OKY 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.FOREIGN_COLUMN_REF2 in (select parent_tab.IRID
                                                      from i$SDD_COL parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_OKY
     set FOREIGN_COLUMN_REF2 = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_OKY fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.FOREIGN_COLUMN_REF2 in (select parent_tab.IRID
                                                      from i$SDD_COL parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_PGD
     set COLUMN_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_PGD 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.COLUMN_REF in (select parent_tab.IRID
                                                      from i$SDD_COL parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_PGD
     set COLUMN_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_PGD fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.COLUMN_REF in (select parent_tab.IRID
                                                      from i$SDD_COL parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_CST
   where ivid in
   (select fktab.ivid
      from i$SDD_CST fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.CQA_REF in (select parent_tab.IRID
                                                    from i$SDD_CQA parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_CST
   where ivid in
   (select fktab.ivid
      from i$SDD_CST fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.CQA_REF in (select parent_tab.IRID
                                                    from i$SDD_CQA parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_INDCOL
   where ivid in
   (select fktab.ivid
      from i$SDD_INDCOL 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.CQA_REF in (select parent_tab.IRID
                                                    from i$SDD_CQA parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_INDCOL
   where ivid in
   (select fktab.ivid
      from i$SDD_INDCOL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.CQA_REF in (select parent_tab.IRID
                                                    from i$SDD_CQA parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_OKY
   where ivid in
   (select fktab.ivid
      from i$SDD_OKY 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.CQA_REF in (select parent_tab.IRID
                                                    from i$SDD_CQA parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_OKY
   where ivid in
   (select fktab.ivid
      from i$SDD_OKY fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.CQA_REF in (select parent_tab.IRID
                                                    from i$SDD_CQA parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_OKY
     set FOREIGN_CQA_REF2 = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_OKY 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.FOREIGN_CQA_REF2 in (select parent_tab.IRID
                                                      from i$SDD_CQA parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_OKY
     set FOREIGN_CQA_REF2 = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_OKY fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.FOREIGN_CQA_REF2 in (select parent_tab.IRID
                                                      from i$SDD_CQA parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_INS
   where ivid in
   (select fktab.ivid
      from i$SDD_INS fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.INDEX_REF in (select parent_tab.IRID
                                                    from i$SDD_IND parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_INS
   where ivid in
   (select fktab.ivid
      from i$SDD_INS fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.INDEX_REF in (select parent_tab.IRID
                                                    from i$SDD_IND parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_CNU
   where ivid in
   (select fktab.ivid
      from i$SDD_CNU 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.CONSTRAINT_REF in (select parent_tab.IRID
                                                    from i$SDD_OCO parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_CNU
   where ivid in
   (select fktab.ivid
      from i$SDD_CNU fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.CONSTRAINT_REF in (select parent_tab.IRID
                                                    from i$SDD_OCO parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_INS
   where ivid in
   (select fktab.ivid
      from i$SDD_INS fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.PRIMARY_KEY_REF in (select parent_tab.IRID
                                                    from i$SDD_OCO parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_INS
   where ivid in
   (select fktab.ivid
      from i$SDD_INS fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.PRIMARY_KEY_REF in (select parent_tab.IRID
                                                    from i$SDD_OCO parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_INS
   where ivid in
   (select fktab.ivid
      from i$SDD_INS fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.UNIQUE_KEY_REF in (select parent_tab.IRID
                                                    from i$SDD_OCO parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_INS
   where ivid in
   (select fktab.ivid
      from i$SDD_INS fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.UNIQUE_KEY_REF in (select parent_tab.IRID
                                                    from i$SDD_OCO parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_COL
     set CONSTRAINT_DENORMALISED_VIA = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_COL fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.CONSTRAINT_DENORMALISED_VIA in (select parent_tab.IRID
                                                      from i$SDD_OCO parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_COL
     set CONSTRAINT_DENORMALISED_VIA = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_COL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.CONSTRAINT_DENORMALISED_VIA in (select parent_tab.IRID
                                                      from i$SDD_OCO parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_IND
     set FOREIGN_KEY_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_IND 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.FOREIGN_KEY_REF in (select parent_tab.IRID
                                                      from i$SDD_OCO parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_IND
     set FOREIGN_KEY_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_IND fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.FOREIGN_KEY_REF in (select parent_tab.IRID
                                                      from i$SDD_OCO parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_MTI
     set CONSTRAINT_REF2 = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_MTI 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.CONSTRAINT_REF2 in (select parent_tab.IRID
                                                      from i$SDD_OCO parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_MTI
     set CONSTRAINT_REF2 = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_MTI fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.CONSTRAINT_REF2 in (select parent_tab.IRID
                                                      from i$SDD_OCO parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_MTI
     set TREEWALK_JOIN_CONSTRAINT = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_MTI 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.TREEWALK_JOIN_CONSTRAINT in (select parent_tab.IRID
                                                      from i$SDD_OCO parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_MTI
     set TREEWALK_JOIN_CONSTRAINT = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_MTI fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.TREEWALK_JOIN_CONSTRAINT in (select parent_tab.IRID
                                                      from i$SDD_OCO parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_OCO
     set PRIMARY_KEY_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_OCO 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.PRIMARY_KEY_REF in (select parent_tab.IRID
                                                      from i$SDD_OCO parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_OCO
     set PRIMARY_KEY_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_OCO fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.PRIMARY_KEY_REF in (select parent_tab.IRID
                                                      from i$SDD_OCO parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_OCO
     set UNIQUE_KEY_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_OCO 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.UNIQUE_KEY_REF in (select parent_tab.IRID
                                                      from i$SDD_OCO parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_OCO
     set UNIQUE_KEY_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_OCO fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.UNIQUE_KEY_REF in (select parent_tab.IRID
                                                      from i$SDD_OCO parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_BRL
   where ivid in
   (select fktab.ivid
      from i$SDD_BRL fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.RELATION_SELECTION_REF in (select parent_tab.IRID
                                                    from i$SDD_VWTAB parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_BRL
   where ivid in
   (select fktab.ivid
      from i$SDD_BRL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.RELATION_SELECTION_REF in (select parent_tab.IRID
                                                    from i$SDD_VWTAB parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_COL
     set RELATION_SELECTION_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_COL fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.RELATION_SELECTION_REF in (select parent_tab.IRID
                                                      from i$SDD_VWTAB parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_COL
     set RELATION_SELECTION_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_COL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.RELATION_SELECTION_REF in (select parent_tab.IRID
                                                      from i$SDD_VWTAB 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_TAB_d;
/
create or replace trigger SDD_TABENT_br
  before insert or update or delete on i$SDD_TABENT
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.TABLE_REF is not null)
       )
    or (updating and (
        (:new.TABLE_REF != :old.TABLE_REF
        or (:new.TABLE_REF is not null and :old.TABLE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_TAB owning_tab
        where  owning_tab.IRID=:new.TABLE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_TABENT_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_TABENT');
  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_TABENT_br;
/
create or replace trigger SDD_TABENT_inv
after insert or update of
  COLUMN_REF
 ,ENTITY_REF
on i$SDD_TABENT
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 := 384781276440387682697704485965809721;
  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_TABENT_inv;
/
create or replace trigger SDD_TABENT_val
after insert or update of
  COLUMN_REF
 ,ENTITY_REF
on i$SDD_TABENT
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 := 384781276440387682697704485965809721;
  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_TABENT(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_TABENT) violated');
    end if;
    if not FK_TABENT_TO_COL(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_TABENT_TO_COL) violated - parent key not found');
    end if;
    if not FK_TABENT_TO_ENT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_TABENT_TO_ENT) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_TABENT_val;
/
create or replace trigger SDD_TABENT_d
  instead of delete on SDD_TABENT 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_TABENT 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_TABENT
   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_TABENT_d;
/
create or replace trigger SDD_TAG_br
  before insert or update or delete on i$SDD_TAG
  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.STEREOTYPE_REF is not null)
       )
    or (updating and (
        (:new.STEREOTYPE_REF != :old.STEREOTYPE_REF
        or (:new.STEREOTYPE_REF is not null and :old.STEREOTYPE_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_STE owning_tab
        where  owning_tab.IRID=:new.STEREOTYPE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_TAG_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_TAG');
  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_TAG_br;
/
create or replace trigger SDD_TAG_inv
after insert
on i$SDD_TAG
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 := 415825818402518294130527883106994233;
  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_TAG_inv;
/
create or replace trigger SDD_TAG_val
after insert
on i$SDD_TAG
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 := 415825818402518294130527883106994233;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_TAG(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_TAG) 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_TAG_val;
/
create or replace trigger SDD_TAG_d
  instead of delete on SDD_TAG 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_TAG 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_TAGVAL fktab
  where 
        fktab.TAG_REF = :old.IRID
    ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_TAG
   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_TAG_d;
/
create or replace trigger SDD_TAGVAL_inv
after insert or update of
  ELEMENT_REF
 ,TAG_REF
on i$SDD_TAGVAL
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 := 415825818402655242758531102818191417;
  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_TAGVAL_inv;
/
create or replace trigger SDD_TAGVAL_val
after insert or update of
  ELEMENT_REF
 ,TAG_REF
on i$SDD_TAGVAL
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 := 415825818402655242758531102818191417;
  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_TAGVAL(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_TAGVAL) violated');
    end if;
    if not UK_TAGVAL(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (UK_TAGVAL) violated');
    end if;
    if not FK_TAGVAL_TO_TAG(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_TAGVAL_TO_TAG) 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_TAGVAL_val;
/
create or replace trigger SDD_TAGVAL_d
  instead of delete on SDD_TAGVAL 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_TAGVAL 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_TAGVAL
   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_TAGVAL_d;
/
create or replace trigger SDD_TBICOL_br
  before insert or update or delete on i$SDD_TBICOL
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.INDEX_STORAGE_REF is not null)
       )
    or (updating and (
        (:new.INDEX_STORAGE_REF != :old.INDEX_STORAGE_REF
        or (:new.INDEX_STORAGE_REF is not null and :old.INDEX_STORAGE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select pac_ref, parent_ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_INS owning_tab
        where  owning_tab.IRID=:new.INDEX_STORAGE_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_TBICOL_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.TABLE_IMPLEMENTATION_REF is not null)
       )
    or (updating and (
        (:new.TABLE_IMPLEMENTATION_REF != :old.TABLE_IMPLEMENTATION_REF
        or (:new.TABLE_IMPLEMENTATION_REF is not null and :old.TABLE_IMPLEMENTATION_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select pac_ref, parent_ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_DOI owning_tab
        where  owning_tab.IRID=:new.TABLE_IMPLEMENTATION_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_TBICOL_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_TBICOL');
  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_TBICOL_br;
/
create or replace trigger SDD_TBICOL_inv
after insert or update of
  COLUMN_REF
on i$SDD_TBICOL
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 := 384781276440661579953710925388204089;
  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_TBICOL_inv;
/
create or replace trigger SDD_TBICOL_val
after insert or update of
  COLUMN_REF
on i$SDD_TBICOL
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 := 384781276440661579953710925388204089;
  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_TBICOL(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_TBICOL) violated');
    end if;
    if not FK_TBICOL_TO_COL(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_TBICOL_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_TBICOL_val;
/
create or replace trigger SDD_TBICOL_d
  instead of delete on SDD_TBICOL 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_TBICOL 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_TBICOL
   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_TBICOL_d;
/
create or replace trigger SDD_TBP_br
  before insert or update or delete on i$SDD_TBP
  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_IMPLEMENTATION_REF is not null)
       )
    or (updating and (
        (:new.TABLE_IMPLEMENTATION_REF != :old.TABLE_IMPLEMENTATION_REF
        or (:new.TABLE_IMPLEMENTATION_REF is not null and :old.TABLE_IMPLEMENTATION_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select pac_ref, parent_ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_DOI owning_tab
        where  owning_tab.IRID=:new.TABLE_IMPLEMENTATION_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_TBP_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_TBP');
  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_TBP_br;
/
create or replace trigger SDD_TBP_inv
after insert or update of
  STORAGE_DEFINITION_REF
 ,TABLESPACE_REF
on i$SDD_TBP
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 := 384781276440940199576200234455812153;
  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_TBP_inv;
/
create or replace trigger SDD_TBP_val
after insert or update of
  STORAGE_DEFINITION_REF
 ,TABLESPACE_REF
on i$SDD_TBP
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 := 384781276440940199576200234455812153;
  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_TBP(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_TBP) violated');
    end if;
    if not FK_TBP_TO_OSP(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_TBP_TO_OSP) violated - parent key not found');
    end if;
    if not FK_TBP_TO_OTB(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_TBP_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_TBP_val;
/
create or replace trigger SDD_TBP_d
  instead of delete on SDD_TBP 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_TBP el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 delete SDD_INP fktab
  where 
        fktab.TABLE_PARTITION_REF = :old.IRID
    ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_TBP
   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_TBP_d;
/
create or replace trigger SDD_TER_br
  before insert or update or delete on i$SDD_TER
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_TER_br;
/
create or replace trigger SDD_TER_ar
  after insert or update or delete on i$SDD_TER
  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 => 384781276441766613710702422368208953
    );
  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_TER'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_TER_ar;
/
create or replace trigger SDD_TER_inv
after insert
on i$SDD_TER
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 := 384781276441766613710702422368208953;
  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_TER_inv;
/
create or replace trigger SDD_TER_val
after insert
on i$SDD_TER
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 := 384781276441766613710702422368208953;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_TER(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_TER) 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_TER_val;
/
create or replace trigger SDD_TER_d
  instead of delete on SDD_TER 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_SYN fktab
  where 
        fktab.TERM_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_TER_d;
/
create or replace trigger SDD_TMS_br
  before insert or update or delete on i$SDD_TMS
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_TMS_br;
/
create or replace trigger SDD_TMS_ar
  after insert or update or delete on i$SDD_TMS
  for each row 
begin
  -- Inserting
  if inserting then
    jr_object_version.ins ( :new.irid, :new.ivid
    , name => :new.TRANSFORMATION_TYPE
    , type_irid => :new.TYPES
    , table_irid => 384781276442413577918855563762485305
    );
  end if;  -- inserting
  -- Updating
  if updating then
    jr_object_version.upd ( :old.ivid
      , name => :new.TRANSFORMATION_TYPE
    );
  end if;  -- updating
  -- Deleting
  if deleting then
    jr_object_version.del ( :old.irid, :old.ivid, 'SDD_TMS'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_TMS_ar;
/
create or replace trigger SDD_TMS_inv
after insert
on i$SDD_TMS
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 := 384781276442413577918855563762485305;
  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_TMS_inv;
/
create or replace trigger SDD_TMS_val
after insert
on i$SDD_TMS
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 := 384781276442413577918855563762485305;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_TMS(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_TMS) 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_TMS_val;
/
create or replace trigger SDD_TMS_d
  instead of delete on SDD_TMS for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
  where ov.irid=:old.irid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  jr_wastebasket.remove(:old.ivid);
  if jr_context.workarea is NULL and not only_version then
   return;
  end if;
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 if jr_context.workarea is not null then
  update SDD_MAP
     set PRIMARY_MAPPING_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_MAP 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.PRIMARY_MAPPING_REF in (select parent_tab.IRID
                                                      from i$SDD_MAP parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_MAP
     set PRIMARY_MAPPING_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_MAP fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.PRIMARY_MAPPING_REF in (select parent_tab.IRID
                                                      from i$SDD_MAP 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_TMS_d;
/
create or replace trigger SDD_TRA_br
  before insert or update or delete on i$SDD_TRA
  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.SOURCE_EVENT_REF is not null)
       )
    or (updating and (
        (:new.SOURCE_EVENT_REF != :old.SOURCE_EVENT_REF
        or (:new.SOURCE_EVENT_REF is not null and :old.SOURCE_EVENT_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_CLA owning_tab
        where  owning_tab.IRID=:new.SOURCE_EVENT_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_TRA_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.SOURCE_OBJECT_STATE_REF is not null)
       )
    or (updating and (
        (:new.SOURCE_OBJECT_STATE_REF != :old.SOURCE_OBJECT_STATE_REF
        or (:new.SOURCE_OBJECT_STATE_REF is not null and :old.SOURCE_OBJECT_STATE_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_OST owning_tab
        where  owning_tab.IRID=:new.SOURCE_OBJECT_STATE_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_TRA_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.SOURCE_PSEUDOSTATE_REF is not null)
       )
    or (updating and (
        (:new.SOURCE_PSEUDOSTATE_REF != :old.SOURCE_PSEUDOSTATE_REF
        or (:new.SOURCE_PSEUDOSTATE_REF is not null and :old.SOURCE_PSEUDOSTATE_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_PSE owning_tab
        where  owning_tab.IRID=:new.SOURCE_PSEUDOSTATE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_TRA_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.SOURCE_ACTIVITY_REF is not null)
       )
    or (updating and (
        (:new.SOURCE_ACTIVITY_REF != :old.SOURCE_ACTIVITY_REF
        or (:new.SOURCE_ACTIVITY_REF is not null and :old.SOURCE_ACTIVITY_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_ACT owning_tab
        where  owning_tab.IRID=:new.SOURCE_ACTIVITY_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_TRA_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.SOURCE_ACT_USAGE_REF is not null)
       )
    or (updating and (
        (:new.SOURCE_ACT_USAGE_REF != :old.SOURCE_ACT_USAGE_REF
        or (:new.SOURCE_ACT_USAGE_REF is not null and :old.SOURCE_ACT_USAGE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select pac_ref, parent_ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_ACTORG owning_tab
        where  owning_tab.IRID=:new.SOURCE_ACT_USAGE_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_TRA_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_TRA');
  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_TRA_br;
/
create or replace trigger SDD_TRA_inv
after insert or update of
  TARGET_ACTIVITY_REF
 ,TARGET_ACT_USAGE_REF
 ,EVENT_PUBLICATION_REF
 ,TARGET_EVENT_REF
 ,TRIGGER_EVENT_REF
 ,EVENT_SUBSCRIPTION_REF
 ,TARGET_OBJECT_STATE_REF
 ,TARGET_PSEUDOSTATE_REF
 ,NAMED_RULE_REF
 ,TRANSITION_REF
on i$SDD_TRA
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 := 384781276442871647467693919348213817;
  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_TRA_inv;
/
create or replace trigger SDD_TRA_val
after insert or update of
  TARGET_ACTIVITY_REF
 ,TARGET_ACT_USAGE_REF
 ,EVENT_PUBLICATION_REF
 ,TARGET_EVENT_REF
 ,TRIGGER_EVENT_REF
 ,EVENT_SUBSCRIPTION_REF
 ,TARGET_OBJECT_STATE_REF
 ,TARGET_PSEUDOSTATE_REF
 ,NAMED_RULE_REF
 ,TRANSITION_REF
on i$SDD_TRA
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 := 384781276442871647467693919348213817;
  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_TRA(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_TRA) violated');
    end if;
    if not FK_TRA_TO_ACT2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_TRA_TO_ACT2) violated - parent key not found');
    end if;
    if not FK_TRA_TO_ACTORG2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_TRA_TO_ACTORG2) violated - parent key not found');
    end if;
    if not FK_TRA_TO_CLAEVC(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_TRA_TO_CLAEVC) violated - parent key not found');
    end if;
    if not FK_TRA_TO_EVC2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_TRA_TO_EVC2) violated - parent key not found');
    end if;
    if not FK_TRA_TO_EVC3(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_TRA_TO_EVC3) violated - parent key not found');
    end if;
    if not FK_TRA_TO_EVS(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_TRA_TO_EVS) violated - parent key not found');
    end if;
    if not FK_TRA_TO_OST2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_TRA_TO_OST2) violated - parent key not found');
    end if;
    if not FK_TRA_TO_PSE2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_TRA_TO_PSE2) violated - parent key not found');
    end if;
    if not FK_TRA_TO_RUL(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_TRA_TO_RUL) violated - parent key not found');
    end if;
    if not FK_TRA_TO_TRA(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_TRA_TO_TRA) violated - parent key not found');
    end if;
