  update SDD_CAT fktab
     set 
         fktab.EO_ATTRIBUTE_REF = NULL
   where fktab.EO_ATTRIBUTE_REF in (select parent_tab.IRID
                                                    from i$SDD_CAT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_CMA fktab
     set 
         fktab.CLASSIFIER_ATT_FROM_REF = NULL
   where fktab.CLASSIFIER_ATT_FROM_REF in (select parent_tab.IRID
                                                    from i$SDD_CAT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  delete SDD_EVR fktab
   where fktab.EVENT_PUBLICATION_REF in (select parent_tab.IRID
                                                      from i$SDD_CLAEVC parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_VLE fktab
     set 
         fktab.ASSOC_END_USAGE_REF = NULL
   where fktab.ASSOC_END_USAGE_REF in (select parent_tab.IRID
                                                    from i$SDD_AEU parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  delete SDD_EVH fktab
   where fktab.EVENT_SUBSCRIPTION_REF in (select parent_tab.IRID
                                                      from i$SDD_EVS parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
  ;
  delete SDD_EVH fktab
   where fktab.SUBSCRIPTION_DETAIL_REF in (select parent_tab.IRID
                                                      from i$SDD_SUD parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_CMA fktab
     set 
         fktab.EVENT_RAISER_FROM_REF = NULL
   where fktab.EVENT_RAISER_FROM_REF in (select parent_tab.IRID
                                                    from i$SDD_EVR parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_CMA fktab
     set 
         fktab.METHOD_PARAMETER_REF = NULL
   where fktab.METHOD_PARAMETER_REF in (select parent_tab.IRID
                                                    from i$SDD_MPA parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
  ;
  end if;--force delete/purge
 if jr_context.workarea is not null then
  delete SDD_AENEAT
   where ivid in
   (select fktab.ivid
      from i$SDD_AENEAT 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.EO_ATTRIBUTE_FROM_REF in (select parent_tab.IRID
                                                    from i$SDD_CAT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_AENEAT
   where ivid in
   (select fktab.ivid
      from i$SDD_AENEAT fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.EO_ATTRIBUTE_FROM_REF in (select parent_tab.IRID
                                                    from i$SDD_CAT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_AENEAT
   where ivid in
   (select fktab.ivid
      from i$SDD_AENEAT 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.EO_ATTRIBUTE_TO_REF in (select parent_tab.IRID
                                                    from i$SDD_CAT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_AENEAT
   where ivid in
   (select fktab.ivid
      from i$SDD_AENEAT fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.EO_ATTRIBUTE_TO_REF in (select parent_tab.IRID
                                                    from i$SDD_CAT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_CATAEN
   where ivid in
   (select fktab.ivid
      from i$SDD_CATAEN 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.EO_ATTRIBUTE_REF in (select parent_tab.IRID
                                                    from i$SDD_CAT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_CATAEN
   where ivid in
   (select fktab.ivid
      from i$SDD_CATAEN fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.EO_ATTRIBUTE_REF in (select parent_tab.IRID
                                                    from i$SDD_CAT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_CATAEN
   where ivid in
   (select fktab.ivid
      from i$SDD_CATAEN 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_ATTRIBUTE_REF in (select parent_tab.IRID
                                                    from i$SDD_CAT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_CATAEN
   where ivid in
   (select fktab.ivid
      from i$SDD_CATAEN fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.GENERAL_ATTRIBUTE_REF in (select parent_tab.IRID
                                                    from i$SDD_CAT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_CATEAT
   where ivid in
   (select fktab.ivid
      from i$SDD_CATEAT 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.EO_ATTRIBUTE_REF in (select parent_tab.IRID
                                                    from i$SDD_CAT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_CATEAT
   where ivid in
   (select fktab.ivid
      from i$SDD_CATEAT fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.EO_ATTRIBUTE_REF in (select parent_tab.IRID
                                                    from i$SDD_CAT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_CMA
   where ivid in
   (select fktab.ivid
      from i$SDD_CMA 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.CLASSIFIER_ATTRIBUTE_REF in (select parent_tab.IRID
                                                    from i$SDD_CAT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_CMA
   where ivid in
   (select fktab.ivid
      from i$SDD_CMA fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.CLASSIFIER_ATTRIBUTE_REF in (select parent_tab.IRID
                                                    from i$SDD_CAT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_CORI
   where ivid in
   (select fktab.ivid
      from i$SDD_CORI 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.CLASSIFIER_ATTRIBUTE_REF in (select parent_tab.IRID
                                                    from i$SDD_CAT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_CORI
   where ivid in
   (select fktab.ivid
      from i$SDD_CORI fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.CLASSIFIER_ATTRIBUTE_REF in (select parent_tab.IRID
                                                    from i$SDD_CAT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_CRU
   where ivid in
   (select fktab.ivid
      from i$SDD_CRU 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.CLASSIFIER_ATTRIBUTE_REF in (select parent_tab.IRID
                                                    from i$SDD_CAT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_CRU
   where ivid in
   (select fktab.ivid
      from i$SDD_CRU fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.CLASSIFIER_ATTRIBUTE_REF in (select parent_tab.IRID
                                                    from i$SDD_CAT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_DATCOM
   where ivid in
   (select fktab.ivid
      from i$SDD_DATCOM fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.CLASSIFIER_ATTRIBUTE_REF in (select parent_tab.IRID
                                                    from i$SDD_CAT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_DATCOM
   where ivid in
   (select fktab.ivid
      from i$SDD_DATCOM fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.CLASSIFIER_ATTRIBUTE_REF in (select parent_tab.IRID
                                                    from i$SDD_CAT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_MEMCOM
   where ivid in
   (select fktab.ivid
      from i$SDD_MEMCOM fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.CLASSIFIER_ATTRIBUTE_REF in (select parent_tab.IRID
                                                    from i$SDD_CAT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_MEMCOM
   where ivid in
   (select fktab.ivid
      from i$SDD_MEMCOM fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.CLASSIFIER_ATTRIBUTE_REF in (select parent_tab.IRID
                                                    from i$SDD_CAT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_VLEVOA
   where ivid in
   (select fktab.ivid
      from i$SDD_VLEVOA fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.VIEW_OBJECT_ATT_REF in (select parent_tab.IRID
                                                    from i$SDD_CAT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_VLEVOA
   where ivid in
   (select fktab.ivid
      from i$SDD_VLEVOA fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.VIEW_OBJECT_ATT_REF in (select parent_tab.IRID
                                                    from i$SDD_CAT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_WAT
     set CLASSIFIER_ATTRIBUTE_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_WAT 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.CLASSIFIER_ATTRIBUTE_REF in (select parent_tab.IRID
                                                      from i$SDD_CAT parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_WAT
     set CLASSIFIER_ATTRIBUTE_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_WAT fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.CLASSIFIER_ATTRIBUTE_REF in (select parent_tab.IRID
                                                      from i$SDD_CAT parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_METRUL
   where ivid in
   (select fktab.ivid
      from i$SDD_METRUL fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.ATTRIBUTE_DERIV_RULE_REF in (select parent_tab.IRID
                                                    from i$SDD_ADR parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_METRUL
   where ivid in
   (select fktab.ivid
      from i$SDD_METRUL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.ATTRIBUTE_DERIV_RULE_REF in (select parent_tab.IRID
                                                    from i$SDD_ADR parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_SUD
   where ivid in
   (select fktab.ivid
      from i$SDD_SUD fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.EVENT_PUBLICATION_REF in (select parent_tab.IRID
                                                    from i$SDD_CLAEVC parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_SUD
   where ivid in
   (select fktab.ivid
      from i$SDD_SUD fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.EVENT_PUBLICATION_REF in (select parent_tab.IRID
                                                    from i$SDD_CLAEVC parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_TRA
     set EVENT_PUBLICATION_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.EVENT_PUBLICATION_REF in (select parent_tab.IRID
                                                      from i$SDD_CLAEVC parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_TRA
     set EVENT_PUBLICATION_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.EVENT_PUBLICATION_REF in (select parent_tab.IRID
                                                      from i$SDD_CLAEVC parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_METRUL
   where ivid in
   (select fktab.ivid
      from i$SDD_METRUL fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.CLASSIFIER_RULE_REF in (select parent_tab.IRID
                                                    from i$SDD_CRU parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_METRUL
   where ivid in
   (select fktab.ivid
      from i$SDD_METRUL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.CLASSIFIER_RULE_REF in (select parent_tab.IRID
                                                    from i$SDD_CRU parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_AEN
     set UNIQUENESS_RULE_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_AEN 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.UNIQUENESS_RULE_REF in (select parent_tab.IRID
                                                      from i$SDD_CRU parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_AEN
     set UNIQUENESS_RULE_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_AEN fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.UNIQUENESS_RULE_REF in (select parent_tab.IRID
                                                      from i$SDD_CRU parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_CLACLA
     set SPEC_GROUP_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_CLACLA 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.SPEC_GROUP_REF in (select parent_tab.IRID
                                                      from i$SDD_CSG parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_CLACLA
     set SPEC_GROUP_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_CLACLA fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.SPEC_GROUP_REF in (select parent_tab.IRID
                                                      from i$SDD_CSG parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_CAT
   where ivid in
   (select fktab.ivid
      from i$SDD_CAT 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.ENTITY_OBJECT_USAGE_REF in (select parent_tab.IRID
                                                    from i$SDD_EOU parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_CAT
   where ivid in
   (select fktab.ivid
      from i$SDD_CAT fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.ENTITY_OBJECT_USAGE_REF in (select parent_tab.IRID
                                                    from i$SDD_EOU parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_SBA
   where ivid in
   (select fktab.ivid
      from i$SDD_SBA 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.EVENT_SUBSCRIPTION_REF in (select parent_tab.IRID
                                                    from i$SDD_EVS parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_SBA
   where ivid in
   (select fktab.ivid
      from i$SDD_SBA fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.EVENT_SUBSCRIPTION_REF in (select parent_tab.IRID
                                                    from i$SDD_EVS parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_TRA
     set EVENT_SUBSCRIPTION_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.EVENT_SUBSCRIPTION_REF in (select parent_tab.IRID
                                                      from i$SDD_EVS parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_TRA
     set EVENT_SUBSCRIPTION_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.EVENT_SUBSCRIPTION_REF in (select parent_tab.IRID
                                                      from i$SDD_EVS parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_SBA
   where ivid in
   (select fktab.ivid
      from i$SDD_SBA 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.SUBSCRIPTION_DETAIL_REF in (select parent_tab.IRID
                                                    from i$SDD_SUD parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_SBA
   where ivid in
   (select fktab.ivid
      from i$SDD_SBA fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.SUBSCRIPTION_DETAIL_REF in (select parent_tab.IRID
                                                    from i$SDD_SUD parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_MEMCOM
   where ivid in
   (select fktab.ivid
      from i$SDD_MEMCOM fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.METHOD_REF in (select parent_tab.IRID
                                                    from i$SDD_MET parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_MEMCOM
   where ivid in
   (select fktab.ivid
      from i$SDD_MEMCOM fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.METHOD_REF in (select parent_tab.IRID
                                                    from i$SDD_MET parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_ACT
     set METHOD_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_ACT fktab
          ,i$sdd_wa_context ctxt
          ,i$sdd_object_versions ov
     where ctxt.object_ivid = fktab.ivid
       and ov.ivid=fktab.ivid
       and ov.state!='I'
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.METHOD_REF in (select parent_tab.IRID
                                                      from i$SDD_MET parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
  delete SDD_ACT
   where ivid in
   (select fktab.ivid
      from i$SDD_ACT fktab
          ,i$sdd_wa_context ctxt
          ,i$sdd_object_versions ov
     where ctxt.object_ivid = fktab.ivid
       and ov.ivid=fktab.ivid
       and ov.state='I'
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.METHOD_REF in (select parent_tab.IRID
                                                      from i$SDD_MET parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_ACT
     set METHOD_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_ACT fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.ivid
       and ov.state!='I'
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.METHOD_REF in (select parent_tab.IRID
                                                      from i$SDD_MET parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
  delete SDD_ACT
   where ivid in
   (select fktab.ivid
      from i$SDD_ACT fktab
          ,i$sdd_object_versions ov
     where ov.ivid=fktab.ivid
       and ov.state='I'
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.METHOD_REF in (select parent_tab.IRID
                                                      from i$SDD_MET parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_ADR
     set METHOD_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_ADR 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.METHOD_REF in (select parent_tab.IRID
                                                      from i$SDD_MET parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_ADR
     set METHOD_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_ADR fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.METHOD_REF in (select parent_tab.IRID
                                                      from i$SDD_MET parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_CORI
     set METHOD_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_CORI 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.METHOD_REF in (select parent_tab.IRID
                                                      from i$SDD_MET parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_CORI
     set METHOD_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_CORI fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.METHOD_REF in (select parent_tab.IRID
                                                      from i$SDD_MET parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_CRU
     set METHOD_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_CRU 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.METHOD_REF in (select parent_tab.IRID
                                                      from i$SDD_MET parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_CRU
     set METHOD_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_CRU fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.METHOD_REF in (select parent_tab.IRID
                                                      from i$SDD_MET parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_MET
     set ELEVATED_METHOD_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_MET 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.ELEVATED_METHOD_REF in (select parent_tab.IRID
                                                      from i$SDD_MET parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_MET
     set ELEVATED_METHOD_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_MET fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.ELEVATED_METHOD_REF in (select parent_tab.IRID
                                                      from i$SDD_MET parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_MET
     set OVERRIDING_METHOD_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_MET 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.OVERRIDING_METHOD_REF in (select parent_tab.IRID
                                                      from i$SDD_MET parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_MET
     set OVERRIDING_METHOD_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_MET fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.OVERRIDING_METHOD_REF in (select parent_tab.IRID
                                                      from i$SDD_MET parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_RUL
     set METHOD_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_RUL fktab
          ,i$sdd_wa_context ctxt
          ,i$sdd_object_versions ov
     where ctxt.object_ivid = fktab.ivid
       and ov.ivid=fktab.ivid
       and ov.state!='I'
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.METHOD_REF in (select parent_tab.IRID
                                                      from i$SDD_MET parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
  delete SDD_RUL
   where ivid in
   (select fktab.ivid
      from i$SDD_RUL fktab
          ,i$sdd_wa_context ctxt
          ,i$sdd_object_versions ov
     where ctxt.object_ivid = fktab.ivid
       and ov.ivid=fktab.ivid
       and ov.state='I'
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.METHOD_REF in (select parent_tab.IRID
                                                      from i$SDD_MET parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_RUL
     set METHOD_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_RUL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.ivid
       and ov.state!='I'
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.METHOD_REF in (select parent_tab.IRID
                                                      from i$SDD_MET parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
  delete SDD_RUL
   where ivid in
   (select fktab.ivid
      from i$SDD_RUL fktab
          ,i$sdd_object_versions ov
     where ov.ivid=fktab.ivid
       and ov.state='I'
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.METHOD_REF in (select parent_tab.IRID
                                                      from i$SDD_MET parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_SRU
     set METHOD_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_SRU 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.METHOD_REF in (select parent_tab.IRID
                                                      from i$SDD_MET parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_SRU
     set METHOD_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_SRU fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.METHOD_REF in (select parent_tab.IRID
                                                      from i$SDD_MET parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_CLA
   where ivid in
   (select fktab.ivid
      from i$SDD_CLA fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.OBJECT_STATE_REF in (select parent_tab.IRID
                                                    from i$SDD_OST parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_CLA
   where ivid in
   (select fktab.ivid
      from i$SDD_CLA fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.OBJECT_STATE_REF in (select parent_tab.IRID
                                                    from i$SDD_OST parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_OSTOST
   where ivid in
   (select fktab.ivid
      from i$SDD_OSTOST fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.OBJECT_STATE_OF_REF in (select parent_tab.IRID
                                                    from i$SDD_OST parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_OSTOST
   where ivid in
   (select fktab.ivid
      from i$SDD_OSTOST fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.OBJECT_STATE_OF_REF in (select parent_tab.IRID
                                                    from i$SDD_OST parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_TRA
   where ivid in
   (select fktab.ivid
      from i$SDD_TRA fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.TARGET_OBJECT_STATE_REF in (select parent_tab.IRID
                                                    from i$SDD_OST parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_TRA
   where ivid in
   (select fktab.ivid
      from i$SDD_TRA fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.TARGET_OBJECT_STATE_REF in (select parent_tab.IRID
                                                    from i$SDD_OST parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_METRUL
   where ivid in
   (select fktab.ivid
      from i$SDD_METRUL fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.STATE_RULE_REF in (select parent_tab.IRID
                                                    from i$SDD_SRU parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_METRUL
   where ivid in
   (select fktab.ivid
      from i$SDD_METRUL fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.STATE_RULE_REF in (select parent_tab.IRID
                                                    from i$SDD_SRU parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_TRA
     set TRANSITION_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_TRA fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
       and fktab.TRANSITION_REF in (select parent_tab.IRID
                                                      from i$SDD_TRA parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_TRA
     set TRANSITION_REF = NULL
   where ivid in
   (select fktab.ivid
      from i$SDD_TRA fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
       and fktab.TRANSITION_REF in (select parent_tab.IRID
                                                      from i$SDD_TRA parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_VLEU
   where ivid in
   (select fktab.ivid
      from i$SDD_VLEU fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.VIEW_USAGE_REF in (select parent_tab.IRID
                                                    from i$SDD_VOU parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_VLEU
   where ivid in
   (select fktab.ivid
      from i$SDD_VLEU fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.VIEW_USAGE_REF in (select parent_tab.IRID
                                                    from i$SDD_VOU 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_CLA_d;
/
create or replace trigger SDD_CLAAEN_br
  before insert or update or delete on i$SDD_CLAAEN
  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.INTERFACE_CLASSIFIER_REF is not null)
       )
    or (updating and (
        (:new.INTERFACE_CLASSIFIER_REF != :old.INTERFACE_CLASSIFIER_REF
        or (:new.INTERFACE_CLASSIFIER_REF is not null and :old.INTERFACE_CLASSIFIER_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_CLA owning_tab
        where  owning_tab.IRID=:new.INTERFACE_CLASSIFIER_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_CLAAEN_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_CLAAEN');
  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_CLAAEN_br;
/
create or replace trigger SDD_CLAAEN_inv
after insert or update of
  ASSOCIATION_END_REF
on i$SDD_CLAAEN
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 := 384781276405158828735496932671637561;
  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_CLAAEN_inv;
/
create or replace trigger SDD_CLAAEN_val
after insert or update of
  ASSOCIATION_END_REF
on i$SDD_CLAAEN
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 := 384781276405158828735496932671637561;
  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_CLAAEN(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_CLAAEN) violated');
    end if;
    if not FK_CLAAEN_TO_AEN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CLAAEN_TO_AEN) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_CLAAEN_val;
/
create or replace trigger SDD_CLAAEN_d
  instead of delete on SDD_CLAAEN 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_CLAAEN 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_CLAAEN
   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_CLAAEN_d;
/
create or replace trigger SDD_CLACLA_br
  before insert or update or delete on i$SDD_CLACLA
  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_CLA 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_CLACLA_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_CLACLA');
  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_CLACLA_br;
/
create or replace trigger SDD_CLACLA_inv
after insert or update of
  SUPERTYPE_REF
 ,SEQUENCE
 ,SPEC_GROUP_REF
on i$SDD_CLACLA
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 := 384781276405295777363500152382834745;
  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_CLACLA_inv;
/
create or replace trigger SDD_CLACLA_val
after insert or update of
  SUPERTYPE_REF
 ,SEQUENCE
 ,SPEC_GROUP_REF
on i$SDD_CLACLA
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 := 384781276405295777363500152382834745;
  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_CLACLA(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_CLACLA) violated');
    end if;
    if not UK_CLACLA_2(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (UK_CLACLA_2) violated');
    end if;
    if not FK_CLACLA_TO_CLA2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CLACLA_TO_CLA2) violated - parent key not found');
    end if;
    if not FK_CLACLA_TO_CSG(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CLACLA_TO_CSG) 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_CLACLA_val;
/
create or replace trigger SDD_CLACLA_d
  instead of delete on SDD_CLACLA 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_CLACLA 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_CLACLA
   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_CLACLA_d;
/
create or replace trigger SDD_CLAEVC_br
  before insert or update or delete on i$SDD_CLAEVC
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.CLASSIFIER_REF is not null)
       )
    or (updating and (
        (:new.CLASSIFIER_REF != :old.CLASSIFIER_REF
        or (:new.CLASSIFIER_REF is not null and :old.CLASSIFIER_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_CLA owning_tab
        where  owning_tab.IRID=:new.CLASSIFIER_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_CLAEVC_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_CLAEVC');
  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_CLAEVC_br;
/
create or replace trigger SDD_CLAEVC_inv
after insert or update of
  EVENT_CLASSIFIER_REF
on i$SDD_CLAEVC
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 := 384781276405470504923366329255741497;
  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_CLAEVC_inv;
/
create or replace trigger SDD_CLAEVC_val
after insert or update of
  EVENT_CLASSIFIER_REF
on i$SDD_CLAEVC
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 := 384781276405470504923366329255741497;
  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_CLAEVC(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_CLAEVC) violated');
    end if;
    if not FK_CLAEVC_TO_EVC(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CLAEVC_TO_EVC) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_CLAEVC_val;
/
create or replace trigger SDD_CLAEVC_d
  instead of delete on SDD_CLAEVC 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_CLAEVC 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_EVR_TO_CLAEVC_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_EVR fktab
   where 
         fktab.EVENT_PUBLICATION_REF = :old.IRID
    ;
 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 delete SDD_SUD fktab
  where 
        fktab.EVENT_PUBLICATION_REF = :old.IRID
    ;
 update SDD_TRA fktab
    set 
        fktab.EVENT_PUBLICATION_REF = NULL
  where 
        fktab.EVENT_PUBLICATION_REF = :old.IRID
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_CLAEVC
   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_CLAEVC_d;
/
create or replace trigger SDD_CLAINC_br
  before insert or update or delete on i$SDD_CLAINC
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.CLASSIFIER_REF is not null)
       )
    or (updating and (
        (:new.CLASSIFIER_REF != :old.CLASSIFIER_REF
        or (:new.CLASSIFIER_REF is not null and :old.CLASSIFIER_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_CLA owning_tab
        where  owning_tab.IRID=:new.CLASSIFIER_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_CLAINC_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_CLAINC');
  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_CLAINC_br;
/
create or replace trigger SDD_CLAINC_inv
after insert or update of
  INTERFACE_CLASSIFIER_REF
on i$SDD_CLAINC
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 := 384781276405616898284335288257366073;
  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_CLAINC_inv;
/
create or replace trigger SDD_CLAINC_val
after insert or update of
  INTERFACE_CLASSIFIER_REF
on i$SDD_CLAINC
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 := 384781276405616898284335288257366073;
  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_CLAINC(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_CLAINC) violated');
    end if;
    if not FK_CLAINC_TO_INC(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CLAINC_TO_INC) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_CLAINC_val;
/
create or replace trigger SDD_CLAINC_d
  instead of delete on SDD_CLAINC 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_CLAINC 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_CLAINC
   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_CLAINC_d;
/
create or replace trigger SDD_CMA_br
  before insert or update or delete on i$SDD_CMA
  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_HANDLER_REF is not null)
       )
    or (updating and (
        (:new.EVENT_HANDLER_REF != :old.EVENT_HANDLER_REF
        or (:new.EVENT_HANDLER_REF is not null and :old.EVENT_HANDLER_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_EVH owning_tab
        where  owning_tab.IRID=:new.EVENT_HANDLER_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_CMA_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.EVENT_RAISER_REF is not null)
       )
    or (updating and (
        (:new.EVENT_RAISER_REF != :old.EVENT_RAISER_REF
        or (:new.EVENT_RAISER_REF is not null and :old.EVENT_RAISER_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_EVR owning_tab
        where  owning_tab.IRID=:new.EVENT_RAISER_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_CMA_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_CMA');
  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_CMA_br;
/
create or replace trigger SDD_CMA_inv
after insert or update of
  ASSOCIATION_END_REF
 ,CLASSIFIER_ATTRIBUTE_REF
 ,CLASSIFIER_ATT_FROM_REF
 ,EVENT_CLASSIFIER_REF
 ,EVENT_RAISER_FROM_REF
 ,METHOD_PARAMETER_REF
on i$SDD_CMA
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 := 397116117431666284211571730387847225;
  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_CMA_inv;
/
create or replace trigger SDD_CMA_val
after insert or update of
  ASSOCIATION_END_REF
 ,CLASSIFIER_ATTRIBUTE_REF
 ,CLASSIFIER_ATT_FROM_REF
 ,EVENT_CLASSIFIER_REF
 ,EVENT_RAISER_FROM_REF
 ,METHOD_PARAMETER_REF
on i$SDD_CMA
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 := 397116117431666284211571730387847225;
  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_CMA(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_CMA) violated');
    end if;
    if not FK_CMA_TO_AEN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CMA_TO_AEN) violated - parent key not found');
    end if;
    if not FK_CMA_TO_CAT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CMA_TO_CAT) violated - parent key not found');
    end if;
    if not FK_CMA_TO_CAT2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CMA_TO_CAT2) violated - parent key not found');
    end if;
    if not FK_CMA_TO_EVC(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CMA_TO_EVC) violated - parent key not found');
    end if;
    if not FK_CMA_TO_EVR2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CMA_TO_EVR2) violated - parent key not found');
    end if;
    if not FK_CMA_TO_MPA(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CMA_TO_MPA) 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_CMA_val;
/
create or replace trigger SDD_CMA_d
  instead of delete on SDD_CMA 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_CMA 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_CMA
   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_CMA_d;
/
create or replace trigger SDD_CNU_br
  before insert or update or delete on i$SDD_CNU
  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_USAGE_REF is not null)
       )
    or (updating and (
        (:new.TABLE_USAGE_REF != :old.TABLE_USAGE_REF
        or (:new.TABLE_USAGE_REF is not null and :old.TABLE_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_MTI owning_tab
        where  owning_tab.IRID=:new.TABLE_USAGE_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_CNU_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_CNU');
  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_CNU_br;
/
create or replace trigger SDD_CNU_inv
after insert or update of
  CONSTRAINT_REF
on i$SDD_CNU
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 := 384781276405763291645304247258990649;
  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_CNU_inv;
/
create or replace trigger SDD_CNU_val
after insert or update of
  CONSTRAINT_REF
on i$SDD_CNU
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 := 384781276405763291645304247258990649;
  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_CNU(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_CNU) violated');
    end if;
    if not FK_CNU_TO_OCO(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CNU_TO_OCO) 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_CNU_val;
/
create or replace trigger SDD_CNU_d
  instead of delete on SDD_CNU 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_CNU 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_CNU
   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_CNU_d;
/
create or replace trigger SDD_COB_br
  before insert or update or delete on i$SDD_COB
  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_COB_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_COB');
  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_COB_br;
/
create or replace trigger SDD_COB_inv
after insert
on i$SDD_COB
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 := 384781276405909685006273206260615225;
  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_COB_inv;
/
create or replace trigger SDD_COB_val
after insert
on i$SDD_COB
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 := 384781276405909685006273206260615225;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_COB(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_COB) 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_COB_val;
/
create or replace trigger SDD_COB_d
  instead of delete on SDD_COB 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_COB 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_COB
   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_COB_d;
/
create or replace trigger SDD_COL_br
  before insert or update or delete on i$SDD_COL
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.ORACLE_OBJECT_TYPE_REF is not null)
       )
    or (updating and (
        (:new.ORACLE_OBJECT_TYPE_REF != :old.ORACLE_OBJECT_TYPE_REF
        or (:new.ORACLE_OBJECT_TYPE_REF is not null and :old.ORACLE_OBJECT_TYPE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_ORT owning_tab
        where  owning_tab.IRID=:new.ORACLE_OBJECT_TYPE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_COL_OWNER) violated - parent key not found');
      end;
    elsif (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_COL_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_COL');
  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_COL_br;
/
create or replace trigger SDD_COL_inv
after insert or update of
  SOURCE_ATTRIBUTE_REF
 ,CLUSTER_COLUMN_REF
 ,BASE_COLUMN_REF
 ,COLUMN_DENORMALISED_FROM
 ,DOMAIN_REF
 ,CONSTRAINT_DENORMALISED_VIA
 ,ORACLE_TYPE_REF
 ,SEQUENCE_REF
 ,SCOPE_TABLE_REF
 ,RELATION_SELECTION_REF
on i$SDD_COL
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 := 384781276406159970429865297456941113;
  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_COL_inv;
/
create or replace trigger SDD_COL_val
after insert or update of
  SOURCE_ATTRIBUTE_REF
 ,CLUSTER_COLUMN_REF
 ,BASE_COLUMN_REF
 ,COLUMN_DENORMALISED_FROM
 ,DOMAIN_REF
 ,CONSTRAINT_DENORMALISED_VIA
 ,ORACLE_TYPE_REF
 ,SEQUENCE_REF
 ,SCOPE_TABLE_REF
 ,RELATION_SELECTION_REF
on i$SDD_COL
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 := 384781276406159970429865297456941113;
  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_COL(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_COL) violated');
    end if;
    if not FK_COL_TO_ATT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_COL_TO_ATT) violated - parent key not found');
    end if;
    if not FK_COL_TO_CCD(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_COL_TO_CCD) violated - parent key not found');
    end if;
    if not FK_COL_TO_COL(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_COL_TO_COL) violated - parent key not found');
    end if;
    if not FK_COL_TO_COL2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_COL_TO_COL2) violated - parent key not found');
    end if;
    if not FK_COL_TO_DOM(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_COL_TO_DOM) violated - parent key not found');
    end if;
    if not FK_COL_TO_JCO(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_COL_TO_JCO) violated - parent key not found');
    end if;
    if not FK_COL_TO_ORT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_COL_TO_ORT) violated - parent key not found');
    end if;
    if not FK_COL_TO_OSQ(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_COL_TO_OSQ) violated - parent key not found');
    end if;
    if not FK_COL_TO_TBL(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_COL_TO_TBL) violated - parent key not found');
    end if;
    if not FK_COL_TO_VWTAB(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_COL_TO_VWTAB) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_COL_val;
/
create or replace trigger SDD_COL_d
  instead of delete on SDD_COL 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_COL 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_ITE_TO_COL_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_ITM_TO_COL_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_OKY_TO_COL2_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_TABENT_TO_COL_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_TRGCOL_TO_COL_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_ITE fktab
   where 
         fktab.COLUMN_REF = :old.IRID
    ;
  delete SDD_TRGCOL fktab
   where 
         fktab.COLUMN_REF = :old.IRID
    ;
  update SDD_ITM fktab
     set 
         fktab.COLUMN_REF = NULL
   where 
         fktab.COLUMN_REF = :old.IRID
  ;
  update SDD_OKY fktab
     set 
         fktab.FOREIGN_COLUMN_REF = NULL
   where 
         fktab.FOREIGN_COLUMN_REF = :old.IRID
  ;
  update SDD_TABENT fktab
     set 
         fktab.COLUMN_REF = NULL
   where 
         fktab.COLUMN_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_CQACOL fktab
  where 
        fktab.COLUMN_REF = :old.IRID
    ;
 delete SDD_CST fktab
  where 
        fktab.COLUMN_REF = :old.IRID
    ;
 delete SDD_INDCOL fktab
  where 
        fktab.COLUMN_REF = :old.IRID
    ;
 delete SDD_OKY fktab
  where 
        fktab.COLUMN_REF = :old.IRID
    ;
 delete SDD_TBICOL fktab
  where 
        fktab.COLUMN_REF = :old.IRID
    ;
  delete SDD_ATV fktab
   where 
         fktab.COLUMN_REF = :old.IRID
    ;
 update SDD_ARG fktab
    set 
        fktab.COLUMN_REF = NULL
  where 
        fktab.COLUMN_REF = :old.IRID
 ;
 update SDD_COL fktab
    set 
        fktab.BASE_COLUMN_REF = NULL
  where 
        fktab.BASE_COLUMN_REF = :old.IRID
 ;
 update SDD_COL fktab
    set 
        fktab.COLUMN_DENORMALISED_FROM = NULL
  where 
        fktab.COLUMN_DENORMALISED_FROM = :old.IRID
 ;
 update SDD_OKY fktab
    set 
        fktab.FOREIGN_COLUMN_REF2 = NULL
  where 
        fktab.FOREIGN_COLUMN_REF2 = :old.IRID
 ;
 update SDD_PGD fktab
    set 
        fktab.COLUMN_REF = NULL
  where 
        fktab.COLUMN_REF = :old.IRID
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_COL
   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_COL_d;
/
create or replace trigger SDD_COM_br
  before insert or update or delete on i$SDD_COM
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_COM_br;
/
create or replace trigger SDD_COM_ar
  after insert or update or delete on i$SDD_COM
  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 => 384781276406849435936364265658140729
    );
  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_COM'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_COM_ar;
/
create or replace trigger SDD_COM_inv
after insert
on i$SDD_COM
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 := 384781276406849435936364265658140729;
  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_COM_inv;
/
create or replace trigger SDD_COM_val
after insert
on i$SDD_COM
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 := 384781276406849435936364265658140729;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_COM(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_COM) 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_COM_val;
/
create or replace trigger SDD_COM_d
  instead of delete on SDD_COM 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_COM_d;
/
create or replace trigger SDD_COMNOD_br
  before insert or update or delete on i$SDD_COMNOD
  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.COMMUNITY_REF is not null)
       )
    or (updating and (
        (:new.COMMUNITY_REF != :old.COMMUNITY_REF
        or (:new.COMMUNITY_REF is not null and :old.COMMUNITY_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_COM owning_tab
        where  owning_tab.IRID=:new.COMMUNITY_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_COMNOD_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_COMNOD');
  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_COMNOD_br;
/
create or replace trigger SDD_COMNOD_inv
after insert or update of
  NODE_REF
on i$SDD_COMNOD
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 := 384781276407061942428093399692757049;
  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_COMNOD_inv;
/
create or replace trigger SDD_COMNOD_val
after insert or update of
  NODE_REF
on i$SDD_COMNOD
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 := 384781276407061942428093399692757049;
  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_COMNOD(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_COMNOD) violated');
    end if;
    if not FK_COMNOD_TO_E20(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_COMNOD_TO_E20) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_COMNOD_val;
/
create or replace trigger SDD_COMNOD_d
  instead of delete on SDD_COMNOD 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_COMNOD 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_COMNOD
   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_COMNOD_d;
/
create or replace trigger SDD_COMODB_br
  before insert or update or delete on i$SDD_COMODB
  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.COMMUNITY_REF is not null)
       )
    or (updating and (
        (:new.COMMUNITY_REF != :old.COMMUNITY_REF
        or (:new.COMMUNITY_REF is not null and :old.COMMUNITY_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_COM owning_tab
        where  owning_tab.IRID=:new.COMMUNITY_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_COMODB_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_COMODB');
  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_COMODB_br;
/
create or replace trigger SDD_COMODB_inv
after insert or update of
  ORACLE_DATABASE_REF
on i$SDD_COMODB
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 := 384781276407302783118719751598655545;
  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_COMODB_inv;
/
create or replace trigger SDD_COMODB_val
after insert or update of
  ORACLE_DATABASE_REF
on i$SDD_COMODB
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 := 384781276407302783118719751598655545;
  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_COMODB(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_COMODB) violated');
    end if;
    if not FK_COMODB_TO_ORC(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_COMODB_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_COMODB_val;
/
create or replace trigger SDD_COMODB_d
  instead of delete on SDD_COMODB 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_COMODB 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_COMODB
   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_COMODB_d;
/
create or replace trigger SDD_COR_br
  before insert or update or delete on i$SDD_COR
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_COR_br;
/
create or replace trigger SDD_COR_ar
  after insert or update or delete on i$SDD_COR
  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 => 397116117433654400500859851022813241
    );
  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_COR'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_COR_ar;
/
create or replace trigger SDD_COR_inv
after insert
on i$SDD_COR
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 := 397116117433654400500859851022813241;
  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_COR_inv;
/
create or replace trigger SDD_COR_val
after insert
on i$SDD_COR
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 := 397116117433654400500859851022813241;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_COR(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_COR) 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_COR_val;
/
create or replace trigger SDD_COR_d
  instead of delete on SDD_COR 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.CROSS_OBJECT_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_COR_d;
/
create or replace trigger SDD_CORI_br
  before insert or update or delete on i$SDD_CORI
  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.CROSS_OBJECT_RULE_REF is not null)
       )
    or (updating and (
        (:new.CROSS_OBJECT_RULE_REF != :old.CROSS_OBJECT_RULE_REF
        or (:new.CROSS_OBJECT_RULE_REF is not null and :old.CROSS_OBJECT_RULE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_COR owning_tab
        where  owning_tab.IRID=:new.CROSS_OBJECT_RULE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_CORI_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_CORI');
  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_CORI_br;
/
create or replace trigger SDD_CORI_inv
after insert or update of
  CLASSIFIER_ATTRIBUTE_REF
 ,LANGUAGE_REF
 ,METHOD_REF
on i$SDD_CORI
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 := 397116117433763014929965852862728249;
  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_CORI_inv;
/
create or replace trigger SDD_CORI_val
after insert or update of
  CLASSIFIER_ATTRIBUTE_REF
 ,LANGUAGE_REF
 ,METHOD_REF
on i$SDD_CORI
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 := 397116117433763014929965852862728249;
  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_CORI(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_CORI) violated');
    end if;
    if not FK_CORI_TO_CAT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CORI_TO_CAT) violated - parent key not found');
    end if;
    if not FK_CORI_TO_LAN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CORI_TO_LAN) violated - parent key not found');
    end if;
    if not FK_CORI_TO_MET(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CORI_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_CORI_val;
/
create or replace trigger SDD_CORI_d
  instead of delete on SDD_CORI 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_CORI 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_CORI
   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_CORI_d;
/
create or replace trigger SDD_CQA_br
  before insert or update or delete on i$SDD_CQA
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.TABLE_DEFINITION_REF is not null)
       )
    or (updating and (
        (:new.TABLE_DEFINITION_REF != :old.TABLE_DEFINITION_REF
        or (:new.TABLE_DEFINITION_REF is not null and :old.TABLE_DEFINITION_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_TAB owning_tab
        where  owning_tab.IRID=:new.TABLE_DEFINITION_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_CQA_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_CQA');
  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_CQA_br;
/
create or replace trigger SDD_CQA_inv
after insert or update of
  CLUSTER_COLUMN_REF
 ,SCOPE_TABLE_REF
on i$SDD_CQA
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 := 384781276407543623809346103504554041;
  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_CQA_inv;
/
create or replace trigger SDD_CQA_val
after insert or update of
  CLUSTER_COLUMN_REF
 ,SCOPE_TABLE_REF
on i$SDD_CQA
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 := 384781276407543623809346103504554041;
  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_CQA(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_CQA) violated');
    end if;
    if not FK_CQA_TO_CCD(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CQA_TO_CCD) violated - parent key not found');
    end if;
    if not FK_CQA_TO_TBL2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CQA_TO_TBL2) 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_CQA_val;
/
create or replace trigger SDD_CQA_d
  instead of delete on SDD_CQA 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_CQA 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_CQA_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_OKY_TO_CQA2_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.CQA_REF = NULL
   where 
         fktab.CQA_REF = :old.IRID
  ;
  update SDD_OKY fktab
     set 
         fktab.FOREIGN_CQA_REF = NULL
   where 
         fktab.FOREIGN_CQA_REF = :old.IRID
  ;
 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 delete SDD_CST fktab
  where 
        fktab.CQA_REF = :old.IRID
    ;
 delete SDD_INDCOL fktab
  where 
        fktab.CQA_REF = :old.IRID
    ;
 delete SDD_OKY fktab
  where 
        fktab.CQA_REF = :old.IRID
    ;
  delete SDD_CQACOL fktab
   where 
         fktab.CQA_REF = :old.IRID
    ;
 update SDD_OKY fktab
    set 
        fktab.FOREIGN_CQA_REF2 = NULL
  where 
        fktab.FOREIGN_CQA_REF2 = :old.IRID
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_CQA
   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_CQA_d;
/
create or replace trigger SDD_CQACOL_br
  before insert or update or delete on i$SDD_CQACOL
  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.CQA_REF is not null)
       )
    or (updating and (
        (:new.CQA_REF != :old.CQA_REF
        or (:new.CQA_REF is not null and :old.CQA_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_CQA owning_tab
        where  owning_tab.IRID=:new.CQA_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_CQACOL_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_CQACOL');
  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_CQACOL_br;
/
create or replace trigger SDD_CQACOL_inv
after insert or update of
  COLUMN_REF
on i$SDD_CQACOL
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 := 384781276407826965798318282217375801;
  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_CQACOL_inv;
/
create or replace trigger SDD_CQACOL_val
after insert or update of
  COLUMN_REF
on i$SDD_CQACOL
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 := 384781276407826965798318282217375801;
  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_CQACOL(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_CQACOL) violated');
    end if;
    if not FK_CQACOL_TO_COL(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CQACOL_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_CQACOL_val;
/
create or replace trigger SDD_CQACOL_d
  instead of delete on SDD_CQACOL 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_CQACOL 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_CQACOL
   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_CQACOL_d;
/
create or replace trigger SDD_CRU_br
  before insert or update or delete on i$SDD_CRU
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.ENTITY_OBJECT_REF is not null)
       )
    or (updating and (
        (:new.ENTITY_OBJECT_REF != :old.ENTITY_OBJECT_REF
        or (:new.ENTITY_OBJECT_REF is not null and :old.ENTITY_OBJECT_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_CLA owning_tab
        where  owning_tab.IRID=:new.ENTITY_OBJECT_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_CRU_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.GENERIC_CLASS_REF is not null)
       )
    or (updating and (
        (:new.GENERIC_CLASS_REF != :old.GENERIC_CLASS_REF
        or (:new.GENERIC_CLASS_REF is not null and :old.GENERIC_CLASS_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_CLA owning_tab
        where  owning_tab.IRID=:new.GENERIC_CLASS_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_CRU_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.INTERFACE_CLASSIFIER_REF is not null)
       )
    or (updating and (
        (:new.INTERFACE_CLASSIFIER_REF != :old.INTERFACE_CLASSIFIER_REF
        or (:new.INTERFACE_CLASSIFIER_REF is not null and :old.INTERFACE_CLASSIFIER_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_CLA owning_tab
        where  owning_tab.IRID=:new.INTERFACE_CLASSIFIER_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_CRU_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.VIEW_OBJECT_REF is not null)
       )
    or (updating and (
        (:new.VIEW_OBJECT_REF != :old.VIEW_OBJECT_REF
        or (:new.VIEW_OBJECT_REF is not null and :old.VIEW_OBJECT_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_CLA owning_tab
        where  owning_tab.IRID=:new.VIEW_OBJECT_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_CRU_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_CRU');
  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_CRU_br;
/
create or replace trigger SDD_CRU_inv
after insert or update of
  CLASSIFIER_ATTRIBUTE_REF
 ,LANGUAGE_REF
 ,METHOD_REF
on i$SDD_CRU
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 := 384781276407992248625218719799855161;
  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_CRU_inv;
/
create or replace trigger SDD_CRU_val
after insert or update of
  CLASSIFIER_ATTRIBUTE_REF
 ,LANGUAGE_REF
 ,METHOD_REF
on i$SDD_CRU
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 := 384781276407992248625218719799855161;
  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_CRU(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_CRU) violated');
    end if;
    if not FK_CRU_TO_CAT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CRU_TO_CAT) violated - parent key not found');
    end if;
    if not FK_CRU_TO_LAN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CRU_TO_LAN) violated - parent key not found');
    end if;
    if not FK_CRU_TO_MET(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CRU_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_CRU_val;
/
create or replace trigger SDD_CRU_d
  instead of delete on SDD_CRU 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_CRU 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.CLASSIFIER_RULE_REF = :old.IRID
    ;
  delete SDD_DATCOM fktab
   where 
         fktab.ARC_RULE_REF = :old.IRID
    ;
  delete SDD_DATCOM fktab
   where 
         fktab.UNIQUENESS_RULE_REF = :old.IRID
    ;
  delete SDD_MEMCOM fktab
   where 
         fktab.INTEGRITY_RULE_REF = :old.IRID
    ;
  delete SDD_VAL fktab
   where 
         fktab.INTEGRITY_RULE_REF = :old.IRID
    ;
 update SDD_AEN fktab
    set 
        fktab.UNIQUENESS_RULE_REF = NULL
  where 
        fktab.UNIQUENESS_RULE_REF = :old.IRID
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_CRU
   where ivid in (select :old.ivid from sys.dual);
 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_CRU_d;
/
create or replace trigger SDD_CSG_br
  before insert or update or delete on i$SDD_CSG
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.CLASSIFIER_REF is not null)
       )
    or (updating and (
        (:new.CLASSIFIER_REF != :old.CLASSIFIER_REF
        or (:new.CLASSIFIER_REF is not null and :old.CLASSIFIER_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_CLA owning_tab
        where  owning_tab.IRID=:new.CLASSIFIER_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_CSG_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_CSG');
  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_CSG_br;
/
create or replace trigger SDD_CSG_inv
after insert
on i$SDD_CSG
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 := 384781276408214199849913593124898873;
  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_CSG_inv;
/
create or replace trigger SDD_CSG_val
after insert
on i$SDD_CSG
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 := 384781276408214199849913593124898873;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_CSG(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_CSG) 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_CSG_val;
/
create or replace trigger SDD_CSG_d
  instead of delete on SDD_CSG 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_CSG 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_CLACLA fktab
    set 
        fktab.SPEC_GROUP_REF = NULL
  where 
        fktab.SPEC_GROUP_REF = :old.IRID
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_CSG
   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_CSG_d;
/
create or replace trigger SDD_CST_br
  before insert or update or delete on i$SDD_CST
  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_CST_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_CST');
  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_CST_br;
/
create or replace trigger SDD_CST_inv
after insert or update of
  COLUMN_REF
 ,CQA_REF
 ,LOB_STORAGE_REF
 ,STORAGE_DEFINITION_REF
 ,TABLESPACE_REF
on i$SDD_CST
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 := 384781276408544765503714468289857593;
  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_CST_inv;
/
create or replace trigger SDD_CST_val
after insert or update of
  COLUMN_REF
 ,CQA_REF
 ,LOB_STORAGE_REF
 ,STORAGE_DEFINITION_REF
 ,TABLESPACE_REF
on i$SDD_CST
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 := 384781276408544765503714468289857593;
  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_CST(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_CST) violated');
    end if;
    if not FK_CST_TO_COL(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CST_TO_COL) violated - parent key not found');
    end if;
    if not FK_CST_TO_CQA(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CST_TO_CQA) violated - parent key not found');
    end if;
    if not FK_CST_TO_LST(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CST_TO_LST) violated - parent key not found');
    end if;
    if not FK_CST_TO_OSP(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CST_TO_OSP) violated - parent key not found');
    end if;
    if not FK_CST_TO_OTB(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_CST_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_CST_val;
/
create or replace trigger SDD_CST_d
  instead of delete on SDD_CST 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_CST 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_CST
   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_CST_d;
/
create or replace trigger SDD_DAT_br
  before insert or update or delete on i$SDD_DAT
  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.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_DAT_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_DAT');
  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_DAT_br;
/
create or replace trigger SDD_DAT_inv
after insert or update of
  PLSQL_MODULE_REF
on i$SDD_DAT
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 := 384781276408875331157515343454816313;
  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_DAT_inv;
/
create or replace trigger SDD_DAT_val
after insert or update of
  PLSQL_MODULE_REF
on i$SDD_DAT
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 := 384781276408875331157515343454816313;
  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_DAT(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_DAT) violated');
    end if;
    if not FK_DAT_TO_PLM(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DAT_TO_PLM) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_DAT_val;
/
create or replace trigger SDD_DAT_d
  instead of delete on SDD_DAT 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_DAT 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_ARG_TO_DAT_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_ITM_TO_DAT2_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_PGD_TO_DAT_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_ARG fktab
     set 
         fktab.DATASTRUCTURE_REF = NULL
   where 
         fktab.DATASTRUCTURE_REF = :old.IRID
  ;
  update SDD_ITM fktab
     set 
         fktab.DATASTRUCTURE_REF2 = NULL
   where 
         fktab.DATASTRUCTURE_REF2 = :old.IRID
  ;
  update SDD_PGD fktab
     set 
         fktab.DATASTRUCTURE_REF = NULL
   where 
         fktab.DATASTRUCTURE_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_ITM fktab
   where 
         fktab.DATASTRUCTURE_REF = :old.IRID
    ;
if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_DAT
   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_DAT_d;
/
create or replace trigger SDD_DATCOM_br
  before insert or update or delete on i$SDD_DATCOM
  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.ARC_RULE_REF is not null)
       )
    or (updating and (
        (:new.ARC_RULE_REF != :old.ARC_RULE_REF
        or (:new.ARC_RULE_REF is not null and :old.ARC_RULE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select pac_ref, parent_ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_CRU owning_tab
        where  owning_tab.IRID=:new.ARC_RULE_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_DATCOM_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.UNIQUENESS_RULE_REF is not null)
       )
    or (updating and (
        (:new.UNIQUENESS_RULE_REF != :old.UNIQUENESS_RULE_REF
        or (:new.UNIQUENESS_RULE_REF is not null and :old.UNIQUENESS_RULE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select pac_ref, parent_ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_CRU owning_tab
        where  owning_tab.IRID=:new.UNIQUENESS_RULE_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_DATCOM_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_DATCOM');
  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_DATCOM_br;
/
create or replace trigger SDD_DATCOM_inv
after insert or update of
  ASSOCIATION_END_REF
 ,CLASSIFIER_ATTRIBUTE_REF
on i$SDD_DATCOM
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 := 384781276409135061314073173941569593;
  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_DATCOM_inv;
/
create or replace trigger SDD_DATCOM_val
after insert or update of
  ASSOCIATION_END_REF
 ,CLASSIFIER_ATTRIBUTE_REF
on i$SDD_DATCOM
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 := 384781276409135061314073173941569593;
  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_DATCOM(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_DATCOM) violated');
    end if;
    if not FK_DATCOM_TO_AEN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DATCOM_TO_AEN) violated - parent key not found');
    end if;
    if not FK_DATCOM_TO_CAT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DATCOM_TO_CAT) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_DATCOM_val;
/
create or replace trigger SDD_DATCOM_d
  instead of delete on SDD_DATCOM 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_DATCOM 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_DATCOM
   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_DATCOM_d;
/
create or replace trigger SDD_DBU_br
  before insert or update or delete on i$SDD_DBU
  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_DBU_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_DBU');
  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_DBU_br;
/
create or replace trigger SDD_DBU_inv
after insert or update of
  DATABASE_PROFILE_REF
 ,DEFAULT_TABLESPACE_REF
 ,TEMP_TABLESPACE_REF
on i$SDD_DBU
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 := 384781276409328678339870829395331129;
  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_DBU_inv;
/
create or replace trigger SDD_DBU_val
after insert or update of
  DATABASE_PROFILE_REF
 ,DEFAULT_TABLESPACE_REF
 ,TEMP_TABLESPACE_REF
on i$SDD_DBU
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 := 384781276409328678339870829395331129;
  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_DBU(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_DBU) violated');
    end if;
    if not FK_DBU_TO_DPR(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DBU_TO_DPR) violated - parent key not found');
    end if;
    if not FK_DBU_TO_OTB(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DBU_TO_OTB) violated - parent key not found');
    end if;
    if not FK_DBU_TO_OTB2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DBU_TO_OTB2) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_DBU_val;
/
create or replace trigger SDD_DBU_d
  instead of delete on SDD_DBU 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_DBU el
  where el.irid=:old.irid
    and ov.ivid=el.parent_ivid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  if jr_version.is_checked_in(NULL,:old.parent_ivid) then
    jr_error.post_del_ci_sac_error(:old.ivid,:old.types,:old.parent_ivid);
    raise jr_wastebasket.delete_error;
  end if;
  jr_acc_rights.check_update(:old.parent_ivid);
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 if not jr_wastebasket.force_flag 
   and jr_wastebasket.repos_constraints_enabled then
   -- bug fix 2078916 - BLOCK DELETE IF USER EXTENDED ASSOCIATION EXISTS
   if not jr_ues_chk.check_ues_blocks_delete (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
 elsif jr_wastebasket.force_flag then 
  jr_wastebasket.set_secondary_delete;

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

 end if;--Constraints enabled/force

 jr_wastebasket.set_secondary_delete;
 delete SDD_BRL fktab
  where 
        fktab.DATABASE_USER_REF = :old.IRID
    ;
  delete SDD_DBUGRP fktab
   where 
         fktab.DATABASE_USER_REF = :old.IRID
    ;
  delete SDD_DBUMOD fktab
   where 
         fktab.DATABASE_USER_REF = :old.IRID
    ;
  delete SDD_DOG fktab
   where 
         fktab.DATABASE_USER_REF = :old.IRID
    ;
  delete SDD_DOI fktab
   where 
         fktab.DATABASE_USER_REF = :old.IRID
    ;
  delete SDD_SPV fktab
   where 
         fktab.DATABASE_USER_REF = :old.IRID
    ;
  delete SDD_TSQ fktab
   where 
         fktab.DATABASE_USER_REF = :old.IRID
    ;
 update SDD_BLI fktab
    set 
        fktab.DATABASE_USER_REF = NULL
  where 
        fktab.DATABASE_USER_REF = :old.IRID
 ;
 update SDD_DOI fktab
    set 
        fktab.DATABASE_USER_REF2 = NULL
  where 
        fktab.DATABASE_USER_REF2 = :old.IRID
 ;
 update SDD_DOI fktab
    set 
        fktab.ORACLE_TYPE_DBU_REF = NULL
  where 
        fktab.ORACLE_TYPE_DBU_REF = :old.IRID
 ;
 update SDD_QUI fktab
    set 
        fktab.QUEUE_TABLE_DBU_REF = NULL
  where 
        fktab.QUEUE_TABLE_DBU_REF = :old.IRID
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_DBU
   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_DBU_d;
/
create or replace trigger SDD_DBUGRP_br
  before insert or update or delete on i$SDD_DBUGRP
  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_DBUGRP_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_DBUGRP');
  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_DBUGRP_br;
/
create or replace trigger SDD_DBUGRP_inv
after insert or update of
  ROLE_REF
on i$SDD_DBUGRP
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 := 384781276409621465061808747398580281;
  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_DBUGRP_inv;
/
create or replace trigger SDD_DBUGRP_val
after insert or update of
  ROLE_REF
on i$SDD_DBUGRP
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 := 384781276409621465061808747398580281;
  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_DBUGRP(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_DBUGRP) violated');
    end if;
    if not FK_DBUGRP_TO_GRP(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DBUGRP_TO_GRP) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_DBUGRP_val;
/
create or replace trigger SDD_DBUGRP_d
  instead of delete on SDD_DBUGRP 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_DBUGRP 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_DBUGRP
   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_DBUGRP_d;
/
create or replace trigger SDD_DBUMOD_br
  before insert or update or delete on i$SDD_DBUMOD
  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_DBUMOD_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_DBUMOD');
  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_DBUMOD_br;
/
create or replace trigger SDD_DBUMOD_inv
after insert or update of
  GENERAL_MODULE_REF
on i$SDD_DBUMOD
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 := 384781276409871750485400838594906169;
  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_DBUMOD_inv;
/
create or replace trigger SDD_DBUMOD_val
after insert or update of
  GENERAL_MODULE_REF
on i$SDD_DBUMOD
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 := 384781276409871750485400838594906169;
  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_DBUMOD(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_DBUMOD) violated');
    end if;
    if not FK_DBUMOD_TO_GEM(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DBUMOD_TO_GEM) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_DBUMOD_val;
/
create or replace trigger SDD_DBUMOD_d
  instead of delete on SDD_DBUMOD 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_DBUMOD 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_DBUMOD
   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_DBUMOD_d;
/
create or replace trigger SDD_DEU_br
  before insert or update or delete on i$SDD_DEU
  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.DIAGRAM_REF is not null)
       )
    or (updating and (
        (:new.DIAGRAM_REF != :old.DIAGRAM_REF
        or (:new.DIAGRAM_REF is not null and :old.DIAGRAM_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_DIA owning_tab
        where  owning_tab.IRID=:new.DIAGRAM_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_DEU_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_DEU');
  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_DEU_br;
/
create or replace trigger SDD_DEU_inv
after insert
on i$SDD_DEU
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 := 384781276410122035908992929791232057;
  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_DEU_inv;
/
create or replace trigger SDD_DEU_val
after insert
on i$SDD_DEU
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 := 384781276410122035908992929791232057;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_DEU(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_DEU) 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_DEU_val;
/
create or replace trigger SDD_DEU_d
  instead of delete on SDD_DEU 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_DEU 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_DEU
   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_DEU_d;
/
create or replace trigger SDD_DFI_br
  before insert or update or delete on i$SDD_DFI
  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_DFI_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.TABLESPACE_REF is not null)
       )
    or (updating and (
        (:new.TABLESPACE_REF != :old.TABLESPACE_REF
        or (:new.TABLESPACE_REF is not null and :old.TABLESPACE_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_OTB owning_tab
        where  owning_tab.IRID=:new.TABLESPACE_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_DFI_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_DFI');
  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_DFI_br;
/
create or replace trigger SDD_DFI_inv
after insert
on i$SDD_DFI
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 := 384781276410287318735893367373711417;
  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_DFI_inv;
/
create or replace trigger SDD_DFI_val
after insert
on i$SDD_DFI
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 := 384781276410287318735893367373711417;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_DFI(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_DFI) 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_DFI_val;
/
create or replace trigger SDD_DFI_d
  instead of delete on SDD_DFI 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_DFI 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;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_DFI
   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_DFI_d;
/
create or replace trigger SDD_DFL_br
  before insert or update or delete on i$SDD_DFL
  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.DATASTORE_SOURCE_REF is not null)
       )
    or (updating and (
        (:new.DATASTORE_SOURCE_REF != :old.DATASTORE_SOURCE_REF
        or (:new.DATASTORE_SOURCE_REF is not null and :old.DATASTORE_SOURCE_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_DST owning_tab
        where  owning_tab.IRID=:new.DATASTORE_SOURCE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_DFL_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.EXTERNAL_SOURCE_REF is not null)
       )
    or (updating and (
        (:new.EXTERNAL_SOURCE_REF != :old.EXTERNAL_SOURCE_REF
        or (:new.EXTERNAL_SOURCE_REF is not null and :old.EXTERNAL_SOURCE_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_EXT owning_tab
        where  owning_tab.IRID=:new.EXTERNAL_SOURCE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_DFL_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.FUNCTION_SOURCE_REF is not null)
       )
    or (updating and (
        (:new.FUNCTION_SOURCE_REF != :old.FUNCTION_SOURCE_REF
        or (:new.FUNCTION_SOURCE_REF is not null and :old.FUNCTION_SOURCE_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_FUN owning_tab
        where  owning_tab.IRID=:new.FUNCTION_SOURCE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_DFL_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_DFL');
  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_DFL_br;
/
create or replace trigger SDD_DFL_inv
after insert or update of
  DATASTORE_DEST_REF
 ,EXTERNAL_DEST_REF
 ,FUNCTION_DEST_REF
on i$SDD_DFL
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 := 384781276410598994923762763957815353;
  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_DFL_inv;
/
create or replace trigger SDD_DFL_val
after insert or update of
  DATASTORE_DEST_REF
 ,EXTERNAL_DEST_REF
 ,FUNCTION_DEST_REF
on i$SDD_DFL
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 := 384781276410598994923762763957815353;
  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_DFL(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_DFL) violated');
    end if;
    if not FK_DFL_TO_DST2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DFL_TO_DST2) violated - parent key not found');
    end if;
    if not FK_DFL_TO_EXT2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DFL_TO_EXT2) violated - parent key not found');
    end if;
    if not FK_DFL_TO_FUN2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DFL_TO_FUN2) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_DFL_val;
/
create or replace trigger SDD_DFL_d
  instead of delete on SDD_DFL 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_DFL 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_DFLATT fktab
   where 
         fktab.DATAFLOW_REF = :old.IRID
    ;
  delete SDD_DFLDIT fktab
   where 
         fktab.DATAFLOW_REF = :old.IRID
    ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_DFL
   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_DFL_d;
/
create or replace trigger SDD_DFLATT_br
  before insert or update or delete on i$SDD_DFLATT
  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.DATAFLOW_REF is not null)
       )
    or (updating and (
        (:new.DATAFLOW_REF != :old.DATAFLOW_REF
        or (:new.DATAFLOW_REF is not null and :old.DATAFLOW_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_DFL owning_tab
        where  owning_tab.IRID=:new.DATAFLOW_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_DFLATT_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_DFLATT');
  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_DFLATT_br;
/
create or replace trigger SDD_DFLATT_inv
after insert or update of
  ATTRIBUTE_REF
on i$SDD_DFLATT
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 := 384781276411203457833570078545168441;
  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_DFLATT_inv;
/
create or replace trigger SDD_DFLATT_val
after insert or update of
  ATTRIBUTE_REF
on i$SDD_DFLATT
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 := 384781276411203457833570078545168441;
  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_DFLATT(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_DFLATT) violated');
    end if;
    if not FK_DFLATT_TO_ATT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DFLATT_TO_ATT) 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_DFLATT_val;
/
create or replace trigger SDD_DFLATT_d
  instead of delete on SDD_DFLATT 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_DFLATT 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_DFLATT
   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_DFLATT_d;
/
create or replace trigger SDD_DFLDIT_br
  before insert or update or delete on i$SDD_DFLDIT
  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.DATAFLOW_REF is not null)
       )
    or (updating and (
        (:new.DATAFLOW_REF != :old.DATAFLOW_REF
        or (:new.DATAFLOW_REF is not null and :old.DATAFLOW_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_DFL owning_tab
        where  owning_tab.IRID=:new.DATAFLOW_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_DFLDIT_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_DFLDIT');
  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_DFLDIT_br;
/
create or replace trigger SDD_DFLDIT_inv
after insert or update of
  DATA_ITEM_REF
on i$SDD_DFLDIT
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 := 384781276411453743257162169741494329;
  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_DFLDIT_inv;
/
create or replace trigger SDD_DFLDIT_val
after insert or update of
  DATA_ITEM_REF
on i$SDD_DFLDIT
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 := 384781276411453743257162169741494329;
  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_DFLDIT(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_DFLDIT) violated');
    end if;
    if not FK_DFLDIT_TO_DIT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DFLDIT_TO_DIT) 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_DFLDIT_val;
/
create or replace trigger SDD_DFLDIT_d
  instead of delete on SDD_DFLDIT 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_DFLDIT 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_DFLDIT
   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_DFLDIT_d;
/
create or replace trigger SDD_DIA_br
  before insert or update or delete on i$SDD_DIA
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_DIA_br;
/
create or replace trigger SDD_DIA_ar
  after insert or update or delete on i$SDD_DIA
  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 => 384781276411694583947788521647392825
    );
  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_DIA'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_DIA_ar;
/
create or replace trigger SDD_DIA_inv
after insert or update of
  PACKAGE_REF
on i$SDD_DIA
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 := 384781276411694583947788521647392825;
  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_DIA_inv;
/
create or replace trigger SDD_DIA_val
after insert or update of
  PACKAGE_REF
on i$SDD_DIA
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 := 384781276411694583947788521647392825;
  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_DIA(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_DIA) violated');
    end if;
    if not FK_DIA_TO_PCK(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DIA_TO_PCK) 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_DIA_val;
/
create or replace trigger SDD_DIA_d
  instead of delete on SDD_DIA for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
  where ov.irid=:old.irid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  jr_wastebasket.remove(:old.ivid);
  if jr_context.workarea is NULL and not only_version then
   return;
  end if;
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 jr_wastebasket.set_secondary_delete;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_DIA_d;
/
create or replace trigger SDD_DIAGRAM_SEGMENTS_br
  before insert or update or delete on i$SDD_DIAGRAM_SEGMENTS
  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.DIAGRAM_REF is not null)
       )
    or (updating and (
        (:new.DIAGRAM_REF != :old.DIAGRAM_REF
        or (:new.DIAGRAM_REF is not null and :old.DIAGRAM_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_DIA owning_tab
        where  owning_tab.IRID=:new.DIAGRAM_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_DIAGRAM_SEGMENTS_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_DIAGRAM_SEGMENTS');
  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_DIAGRAM_SEGMENTS_br;
/
create or replace trigger SDD_DIAGRAM_SEGMENTS_inv
after insert
on i$SDD_DIAGRAM_SEGMENTS
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 := 384781276411963758837312091424573497;
  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_DIAGRAM_SEGMENTS_inv;
/
create or replace trigger SDD_DIAGRAM_SEGMENTS_val
after insert
on i$SDD_DIAGRAM_SEGMENTS
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 := 384781276411963758837312091424573497;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_DIAGRAM_SEGMENTS(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_DIAGRAM_SEGMENTS) 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_DIAGRAM_SEGMENTS_val;
/
create or replace trigger SDD_DIAGRAM_SEGMENTS_d
  instead of delete on SDD_DIAGRAM_SEGMENTS 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_DIAGRAM_SEGMENTS 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;
  -- Do not check access rights for diagram segments
  null;
 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_DIAGRAM_SEGMENTS
   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_DIAGRAM_SEGMENTS_d;
/
create or replace trigger SDD_DIR_br
  before insert or update or delete on i$SDD_DIR
  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_DIR_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_DIR');
  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_DIR_br;
/
create or replace trigger SDD_DIR_inv
after insert
on i$SDD_DIR
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 := 384781276412081817999383832554915897;
  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_DIR_inv;
/
create or replace trigger SDD_DIR_val
after insert
on i$SDD_DIR
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 := 384781276412081817999383832554915897;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_DIR(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_DIR) 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_DIR_val;
/
create or replace trigger SDD_DIR_d
  instead of delete on SDD_DIR 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_DIR 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.DIRECTORY_REF = :old.IRID
    ;
 update SDD_DOI fktab
    set 
        fktab.DIRECTORY_REF = NULL
  where 
        fktab.DIRECTORY_REF = :old.IRID
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_DIR
   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_DIR_d;
/
create or replace trigger SDD_DIT_br
  before insert or update or delete on i$SDD_DIT
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_DIT_br;
/
create or replace trigger SDD_DIT_ar
  after insert or update or delete on i$SDD_DIT
  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 => 384781276412332103422975923751241785
    );
  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_DIT'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_DIT_ar;
/
create or replace trigger SDD_DIT_inv
after insert
on i$SDD_DIT
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 := 384781276412332103422975923751241785;
  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_DIT_inv;
/
create or replace trigger SDD_DIT_val
after insert
on i$SDD_DIT
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 := 384781276412332103422975923751241785;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_DIT(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_DIT) 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_DIT_val;
/
create or replace trigger SDD_DIT_d
  instead of delete on SDD_DIT 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_DFLDIT fktab
  where 
        fktab.DATA_ITEM_REF = :old.IRID
    ;
 delete SDD_DSTDIT fktab
  where 
        fktab.DATA_ITEM_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_DIT_d;
/
create or replace trigger SDD_DOC_br
  before insert or update or delete on i$SDD_DOC
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_DOC_br;
/
create or replace trigger SDD_DOC_ar
  after insert or update or delete on i$SDD_DOC
  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 => 384781276412582388846568014947567673
    );
  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_DOC'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_DOC_ar;
/
create or replace trigger SDD_DOC_inv
after insert
on i$SDD_DOC
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 := 384781276412582388846568014947567673;
  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_DOC_inv;
/
create or replace trigger SDD_DOC_val
after insert
on i$SDD_DOC
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 := 384781276412582388846568014947567673;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_DOC(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_DOC) 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_DOC_val;
/
create or replace trigger SDD_DOC_d
  instead of delete on SDD_DOC 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_DOC_d;
/
create or replace trigger SDD_DOCXXX_br
  before insert or update or delete on i$SDD_DOCXXX
  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.DOCUMENT_REF is not null)
       )
    or (updating and (
        (:new.DOCUMENT_REF != :old.DOCUMENT_REF
        or (:new.DOCUMENT_REF is not null and :old.DOCUMENT_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_DOC owning_tab
        where  owning_tab.IRID=:new.DOCUMENT_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_DOCXXX_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_DOCXXX');
  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_DOCXXX_br;
/
create or replace trigger SDD_DOCXXX_inv
after insert
on i$SDD_DOCXXX
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 := 384781276412856286102574454369962041;
  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_DOCXXX_inv;
/
create or replace trigger SDD_DOCXXX_val
after insert
on i$SDD_DOCXXX
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 := 384781276412856286102574454369962041;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_DOCXXX(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_DOCXXX) 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_DOCXXX_val;
/
create or replace trigger SDD_DOCXXX_d
  instead of delete on SDD_DOCXXX 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_DOCXXX 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_DOCXXX
   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_DOCXXX_d;
/
create or replace trigger SDD_DOG_br
  before insert or update or delete on i$SDD_DOG
  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_DOG_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_DOG_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_DOG');
  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_DOG_br;
/
create or replace trigger SDD_DOG_inv
after insert or update of
  DIRECTORY_REF
 ,JMI_REF
 ,PLSQL_MODULE_REF
 ,QUI_REF
 ,SNAPSHOT_REF
 ,SEQUENCE_REF
 ,TABLE_REF
 ,VIEW_REF
on i$SDD_DOG
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 := 384781276413097126793200806275860537;
  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_DOG_inv;
/
create or replace trigger SDD_DOG_val
after insert or update of
  DIRECTORY_REF
 ,JMI_REF
 ,PLSQL_MODULE_REF
 ,QUI_REF
 ,SNAPSHOT_REF
 ,SEQUENCE_REF
 ,TABLE_REF
 ,VIEW_REF
on i$SDD_DOG
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 := 384781276413097126793200806275860537;
  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_DOG(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_DOG) violated');
    end if;
    if not FK_DOG_TO_DIR(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DOG_TO_DIR) violated - parent key not found');
    end if;
    if not FK_DOG_TO_JMI(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DOG_TO_JMI) violated - parent key not found');
    end if;
    if not FK_DOG_TO_PMI(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DOG_TO_PMI) violated - parent key not found');
    end if;
    if not FK_DOG_TO_QUI(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DOG_TO_QUI) violated - parent key not found');
    end if;
    if not FK_DOG_TO_SNI(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DOG_TO_SNI) violated - parent key not found');
    end if;
    if not FK_DOG_TO_SQI(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DOG_TO_SQI) violated - parent key not found');
    end if;
    if not FK_DOG_TO_TBI(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DOG_TO_TBI) violated - parent key not found');
    end if;
    if not FK_DOG_TO_VWI(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DOG_TO_VWI) 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_DOG_val;
/
create or replace trigger SDD_DOG_d
  instead of delete on SDD_DOG 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_DOG 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_DOG
   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_DOG_d;
/
create or replace trigger SDD_DOI_br
  before insert or update or delete on i$SDD_DOI
  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_DOI_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_DOI');
  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_DOI_br;
/
create or replace trigger SDD_DOI_inv
after insert or update of
  DATABASE_USER_REF2
 ,ORACLE_TYPE_DBU_REF
 ,DIRECTORY_REF
 ,JAVA_MODULE_REF
 ,CLUSTER_REF
 ,STORAGE_DEFINITION_REF
 ,SNAP_LOG_STORAGE_REF
 ,SEQUENCE_REF
 ,TABLESPACE_REF
 ,OVERFLOW_TABLESPACE_REF
 ,SNAP_LOG_TABLESPACE_REF
 ,PLSQL_MODULE_REF
 ,QUEUE_TABLE_DEF_REF
 ,REPLICATION_GROUP_REF
 ,SNAPSHOT_DEFINITION_REF
 ,SNAPSHOT_GROUP_REF
 ,TABLE_DEFINITION_REF
 ,VIEW_DEFINITION_REF
on i$SDD_DOI
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 := 384781276413564641075004901152016441;
  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_DOI_inv;
/
create or replace trigger SDD_DOI_val
after insert or update of
  DATABASE_USER_REF2
 ,ORACLE_TYPE_DBU_REF
 ,DIRECTORY_REF
 ,JAVA_MODULE_REF
 ,CLUSTER_REF
 ,STORAGE_DEFINITION_REF
 ,SNAP_LOG_STORAGE_REF
 ,SEQUENCE_REF
 ,TABLESPACE_REF
 ,OVERFLOW_TABLESPACE_REF
 ,SNAP_LOG_TABLESPACE_REF
 ,PLSQL_MODULE_REF
 ,QUEUE_TABLE_DEF_REF
 ,REPLICATION_GROUP_REF
 ,SNAPSHOT_DEFINITION_REF
 ,SNAPSHOT_GROUP_REF
 ,TABLE_DEFINITION_REF
 ,VIEW_DEFINITION_REF
on i$SDD_DOI
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 := 384781276413564641075004901152016441;
  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_DOI(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_DOI) violated');
    end if;
    if not FK_DOI_TO_DBU2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DOI_TO_DBU2) violated - parent key not found');
    end if;
    if not FK_DOI_TO_DBU3(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DOI_TO_DBU3) violated - parent key not found');
    end if;
    if not FK_DOI_TO_DIR(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DOI_TO_DIR) violated - parent key not found');
    end if;
    if not FK_DOI_TO_JAM(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DOI_TO_JAM) violated - parent key not found');
    end if;
    if not FK_DOI_TO_OCL(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DOI_TO_OCL) violated - parent key not found');
    end if;
    if not FK_DOI_TO_OSP(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DOI_TO_OSP) violated - parent key not found');
    end if;
    if not FK_DOI_TO_OSP2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DOI_TO_OSP2) violated - parent key not found');
    end if;
    if not FK_DOI_TO_OSQ(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DOI_TO_OSQ) violated - parent key not found');
    end if;
    if not FK_DOI_TO_OTB(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DOI_TO_OTB) violated - parent key not found');
    end if;
    if not FK_DOI_TO_OTB2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DOI_TO_OTB2) violated - parent key not found');
    end if;
    if not FK_DOI_TO_OTB3(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DOI_TO_OTB3) violated - parent key not found');
    end if;
    if not FK_DOI_TO_PLM(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DOI_TO_PLM) violated - parent key not found');
    end if;
    if not FK_DOI_TO_QTD(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DOI_TO_QTD) violated - parent key not found');
    end if;
    if not FK_DOI_TO_RPG(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DOI_TO_RPG) violated - parent key not found');
    end if;
    if not FK_DOI_TO_SNP(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DOI_TO_SNP) violated - parent key not found');
    end if;
    if not FK_DOI_TO_SRG(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DOI_TO_SRG) violated - parent key not found');
    end if;
    if not FK_DOI_TO_TBL(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DOI_TO_TBL) violated - parent key not found');
    end if;
    if not FK_DOI_TO_VW(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DOI_TO_VW) 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_DOI_val;
/
create or replace trigger SDD_DOI_d
  instead of delete on SDD_DOI 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_DOI 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.JMI_REF = :old.IRID
    ;
 delete SDD_DOG fktab
  where 
        fktab.PLSQL_MODULE_REF = :old.IRID
    ;
 delete SDD_DOG fktab
  where 
        fktab.SNAPSHOT_REF = :old.IRID
    ;
 delete SDD_DOG fktab
  where 
        fktab.SEQUENCE_REF = :old.IRID
    ;
 delete SDD_DOG fktab
  where 
        fktab.TABLE_REF = :old.IRID
    ;
 delete SDD_DOG fktab
  where 
        fktab.VIEW_REF = :old.IRID
    ;
  delete SDD_BRL fktab
   where 
         fktab.SNAPSHOT_REF = :old.IRID
    ;
  delete SDD_BRL fktab
   where 
         fktab.VIEW_IMPLEMENTATION_REF = :old.IRID
    ;
  delete SDD_CST fktab
   where 
         fktab.TABLE_IMPLEMENTATION_REF = :old.IRID
    ;
  delete SDD_INS fktab
   where 
         fktab.CLUSTER_REF = :old.IRID
    ;
  delete SDD_INS fktab
   where 
         fktab.SNAPSHOT_REF = :old.IRID
    ;
  delete SDD_INS fktab
   where 
         fktab.TABLE_IMPLEMENTATION_REF = :old.IRID
    ;
  delete SDD_TBICOL fktab
   where 
         fktab.TABLE_IMPLEMENTATION_REF = :old.IRID
    ;
  delete SDD_TBP fktab
   where 
         fktab.TABLE_IMPLEMENTATION_REF = :old.IRID
    ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_DOI
   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_DOI_d;
/
create or replace trigger SDD_DOM_br
  before insert or update or delete on i$SDD_DOM
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_DOM_br;
/
create or replace trigger SDD_DOM_ar
  after insert or update or delete on i$SDD_DOM
  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 => 384781276414187993450743694320224313
    );
  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_DOM'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_DOM_ar;
/
create or replace trigger SDD_DOM_inv
after insert or update of
  SUPERTYPE_REF
on i$SDD_DOM
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 := 384781276414187993450743694320224313;
  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_DOM_inv;
/
create or replace trigger SDD_DOM_val
after insert or update of
  SUPERTYPE_REF
on i$SDD_DOM
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 := 384781276414187993450743694320224313;
  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_DOM(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_DOM) violated');
    end if;
    if not FK_DOM_TO_DOM(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DOM_TO_DOM) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_DOM_val;
/
create or replace trigger SDD_DOM_d
  instead of delete on SDD_DOM 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_ARG_TO_DOM_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_ATT_TO_DOM_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_COL_TO_DOM_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_DOM_TO_DOM_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_ITE_TO_DOM_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_ITM_TO_DOM_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_PGD_TO_DOM_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_ARG fktab
     set 
         fktab.DOMAIN_REF = NULL
   where 
         fktab.DOMAIN_REF = :old.IRID
  ;
  update SDD_ATT fktab
     set 
         fktab.DOMAIN_REF = NULL
   where 
         fktab.DOMAIN_REF = :old.IRID
  ;
  update SDD_COL fktab
     set 
         fktab.DOMAIN_REF = NULL
   where 
         fktab.DOMAIN_REF = :old.IRID
  ;
  update SDD_DOM fktab
     set 
         fktab.SUPERTYPE_REF = NULL
   where 
         fktab.SUPERTYPE_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
  ;
  delete SDD_DOM fktab
   where 
         fktab.SUPERTYPE_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state='I')
  ;
  update SDD_ITE fktab
     set 
         fktab.DOMAIN_REF = NULL
   where 
         fktab.DOMAIN_REF = :old.IRID
  ;
  update SDD_ITM fktab
     set 
         fktab.DOMAIN_REF = NULL
   where 
         fktab.DOMAIN_REF = :old.IRID
  ;
  update SDD_PGD fktab
     set 
         fktab.DOMAIN_REF = NULL
   where 
         fktab.DOMAIN_REF = :old.IRID
  ;

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

 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_DOM_d;
/
create or replace trigger SDD_DPR_br
  before insert or update or delete on i$SDD_DPR
  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_DPR_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_DPR');
  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_DPR_br;
/
create or replace trigger SDD_DPR_inv
after insert
on i$SDD_DPR
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 := 384781276414499669638613090904328249;
  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_DPR_inv;
/
create or replace trigger SDD_DPR_val
after insert
on i$SDD_DPR
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 := 384781276414499669638613090904328249;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_DPR(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_DPR) 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_DPR_val;
/
create or replace trigger SDD_DPR_d
  instead of delete on SDD_DPR 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_DPR 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_DBU fktab
    set 
        fktab.DATABASE_PROFILE_REF = NULL
  where 
        fktab.DATABASE_PROFILE_REF = :old.IRID
 ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_DPR
   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_DPR_d;
/
create or replace trigger SDD_DST_br
  before insert or update or delete on i$SDD_DST
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_DST_br;
/
create or replace trigger SDD_DST_ar
  after insert or update or delete on i$SDD_DST
  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 => 384781276414886903690208401811851321
    );
  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_DST'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_DST_ar;
/
create or replace trigger SDD_DST_inv
after insert or update of
  BUSINESS_UNIT_REF
 ,FUNCTION_REF
on i$SDD_DST
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 := 384781276414886903690208401811851321;
  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_DST_inv;
/
create or replace trigger SDD_DST_val
after insert or update of
  BUSINESS_UNIT_REF
 ,FUNCTION_REF
on i$SDD_DST
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 := 384781276414886903690208401811851321;
  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_DST(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_DST) violated');
    end if;
    if not FK_DST_TO_BUN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DST_TO_BUN) violated - parent key not found');
    end if;
    if not FK_DST_TO_FUN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DST_TO_FUN) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_DST_val;
/
create or replace trigger SDD_DST_d
  instead of delete on SDD_DST for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
  where ov.irid=:old.irid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  jr_wastebasket.remove(:old.ivid);
  if jr_context.workarea is NULL and not only_version then
   return;
  end if;
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
  if not jr_wastebasket.force_flag 
   and jr_wastebasket.repos_constraints_enabled then
   -- bug fix 2078916 - BLOCK DELETE IF USER EXTENDED ASSOCIATION EXISTS
   if not jr_ues_chk.check_ues_blocks_delete (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_DFL_TO_DST2_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
 elsif jr_wastebasket.force_flag then 
  jr_wastebasket.set_secondary_delete;
  delete SDD_DFL fktab
   where 
         fktab.DATASTORE_DEST_REF = :old.IRID
    ;

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

 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
 if not secondary then 
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
 end if; 
 if nulled_wa_ctxt then
  jr_context.set_workarea(jr_wastebasket.saved_wa_context);
 end if;
 if reset_wa_ctxt then
  jr_context.set_workarea(jr_context.NULL_WORKAREA);
 end if;
exception 
 when others then 
  --CDR-2000 Cannot delete %0!s %1!s
  jr_error.post_del_error(:old.ivid, :old.TYPES);
  jr_wastebasket.unset_secondary_delete;  jr_wastebasket.RESET_REPOS_CONSTRAINTS;
  if nulled_wa_ctxt then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
  end if;
  if reset_wa_ctxt then
   jr_context.set_workarea(jr_context.NULL_WORKAREA);
  end if;
  RAISE; 
end SDD_DST_d;
/
create or replace trigger SDD_DSTATT_br
  before insert or update or delete on i$SDD_DSTATT
  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.DATASTORE_REF is not null)
       )
    or (updating and (
        (:new.DATASTORE_REF != :old.DATASTORE_REF
        or (:new.DATASTORE_REF is not null and :old.DATASTORE_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_DST owning_tab
        where  owning_tab.IRID=:new.DATASTORE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_DSTATT_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_DSTATT');
  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_DSTATT_br;
/
create or replace trigger SDD_DSTATT_inv
after insert or update of
  ATTRIBUTE_REF
on i$SDD_DSTATT
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 := 384781276415378029804426844914075705;
  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_DSTATT_inv;
/
create or replace trigger SDD_DSTATT_val
after insert or update of
  ATTRIBUTE_REF
on i$SDD_DSTATT
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 := 384781276415378029804426844914075705;
  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_DSTATT(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_DSTATT) violated');
    end if;
    if not FK_DSTATT_TO_ATT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DSTATT_TO_ATT) 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_DSTATT_val;
/
create or replace trigger SDD_DSTATT_d
  instead of delete on SDD_DSTATT 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_DSTATT 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_DSTATT
   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_DSTATT_d;
/
create or replace trigger SDD_DSTDIT_br
  before insert or update or delete on i$SDD_DSTDIT
  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.DATASTORE_REF is not null)
       )
    or (updating and (
        (:new.DATASTORE_REF != :old.DATASTORE_REF
        or (:new.DATASTORE_REF is not null and :old.DATASTORE_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_DST owning_tab
        where  owning_tab.IRID=:new.DATASTORE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_DSTDIT_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_DSTDIT');
  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_DSTDIT_br;
/
create or replace trigger SDD_DSTDIT_inv
after insert or update of
  DATA_ITEM_REF
on i$SDD_DSTDIT
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 := 384781276415628315228018936110401593;
  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_DSTDIT_inv;
/
create or replace trigger SDD_DSTDIT_val
after insert or update of
  DATA_ITEM_REF
on i$SDD_DSTDIT
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 := 384781276415628315228018936110401593;
  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_DSTDIT(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_DSTDIT) violated');
    end if;
    if not FK_DSTDIT_TO_DIT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DSTDIT_TO_DIT) 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_DSTDIT_val;
/
create or replace trigger SDD_DSTDIT_d
  instead of delete on SDD_DSTDIT 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_DSTDIT 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_DSTDIT
   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_DSTDIT_d;
/
create or replace trigger SDD_DSY_br
  before insert or update or delete on i$SDD_DSY
  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.SEQUENCE_REF is not null)
       )
    or (updating and (
        (:new.SEQUENCE_REF != :old.SEQUENCE_REF
        or (:new.SEQUENCE_REF is not null and :old.SEQUENCE_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_OSQ owning_tab
        where  owning_tab.IRID=:new.SEQUENCE_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_DSY_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_DSY_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.SNAPSHOT_DEFINITION_REF is not null)
       )
    or (updating and (
        (:new.SNAPSHOT_DEFINITION_REF != :old.SNAPSHOT_DEFINITION_REF
        or (:new.SNAPSHOT_DEFINITION_REF is not null and :old.SNAPSHOT_DEFINITION_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_TAB owning_tab
        where  owning_tab.IRID=:new.SNAPSHOT_DEFINITION_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_DSY_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.TABLE_DEFINITION_REF is not null)
       )
    or (updating and (
        (:new.TABLE_DEFINITION_REF != :old.TABLE_DEFINITION_REF
        or (:new.TABLE_DEFINITION_REF is not null and :old.TABLE_DEFINITION_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_TAB owning_tab
        where  owning_tab.IRID=:new.TABLE_DEFINITION_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_DSY_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.VIEW_DEFINITION_REF is not null)
       )
    or (updating and (
        (:new.VIEW_DEFINITION_REF != :old.VIEW_DEFINITION_REF
        or (:new.VIEW_DEFINITION_REF is not null and :old.VIEW_DEFINITION_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_TAB owning_tab
        where  owning_tab.IRID=:new.VIEW_DEFINITION_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_DSY_OWNER) violated - parent key not found');
      end;
    elsif (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.JAVA_MODULE_REF is not null)
       )
    or (updating and (
        (:new.JAVA_MODULE_REF != :old.JAVA_MODULE_REF
        or (:new.JAVA_MODULE_REF is not null and :old.JAVA_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.JAVA_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_DSY_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_DSY');
  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_DSY_br;
/
create or replace trigger SDD_DSY_inv
after insert or update of
  JAVA_MODULE_REF
 ,PLSQL_MODULE_REF
on i$SDD_DSY
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 := 384781276415869155918645288016300089;
  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_DSY_inv;
/
create or replace trigger SDD_DSY_val
after insert or update of
  JAVA_MODULE_REF
 ,PLSQL_MODULE_REF
on i$SDD_DSY
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 := 384781276415869155918645288016300089;
  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_DSY(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_DSY) violated');
    end if;
    if not FK_DSY_TO_JAM(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DSY_TO_JAM) violated - parent key not found');
    end if;
    if not FK_DSY_TO_PLM(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_DSY_TO_PLM) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_DSY_val;
/
create or replace trigger SDD_DSY_d
  instead of delete on SDD_DSY 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_DSY 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_DSY
   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_DSY_d;
/
create or replace trigger SDD_E1_br
  before insert or update or delete on i$SDD_E1
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_E1_br;
/
create or replace trigger SDD_E1_ar
  after insert or update or delete on i$SDD_E1
  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 => 384781276416190276839480423890831417
    );
  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_E1'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_E1_ar;
/
create or replace trigger SDD_E1_inv
after insert or update of
  OBJECTIVE_REF
on i$SDD_E1
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 := 384781276416190276839480423890831417;
  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_E1_inv;
/
create or replace trigger SDD_E1_val
after insert or update of
  OBJECTIVE_REF
on i$SDD_E1
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 := 384781276416190276839480423890831417;
  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_E1(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_E1) violated');
    end if;
    if not FK_E1_TO_E1(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_E1_TO_E1) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_E1_val;
/
create or replace trigger SDD_E1_d
  instead of delete on SDD_E1 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_A8 fktab
  where 
        fktab.OBJECTIVE_REF = :old.IRID
    ;
 delete SDD_ACTE1 fktab
  where 
        fktab.OBJECTIVE_REF = :old.IRID
    ;
 delete SDD_USCE1 fktab
  where 
        fktab.OBJECTIVE_REF = :old.IRID
    ;
 update SDD_E1 fktab
    set 
        fktab.OBJECTIVE_REF = NULL
  where 
        fktab.OBJECTIVE_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
 ;
 delete SDD_E1 fktab
  where 
        fktab.OBJECTIVE_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_E1_d;
/
create or replace trigger SDD_E2_br
  before insert or update or delete on i$SDD_E2
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_E2_br;
/
create or replace trigger SDD_E2_ar
  after insert or update or delete on i$SDD_E2
  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 => 384781276416412228064175297215875129
    );
  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_E2'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_E2_ar;
/
create or replace trigger SDD_E2_inv
after insert or update of
  CSF_REF
on i$SDD_E2
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 := 384781276416412228064175297215875129;
  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_E2_inv;
/
create or replace trigger SDD_E2_val
after insert or update of
  CSF_REF
on i$SDD_E2
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 := 384781276416412228064175297215875129;
  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_E2(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_E2) violated');
    end if;
    if not FK_E2_TO_E2(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_E2_TO_E2) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_E2_val;
/
create or replace trigger SDD_E2_d
  instead of delete on SDD_E2 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_A1 fktab
  where 
        fktab.CSF_REF = :old.IRID
    ;
 update SDD_E2 fktab
    set 
        fktab.CSF_REF = NULL
  where 
        fktab.CSF_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
 ;
 delete SDD_E2 fktab
  where 
        fktab.CSF_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_E2_d;
/
create or replace trigger SDD_E20_br
  before insert or update or delete on i$SDD_E20
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_E20_br;
/
create or replace trigger SDD_E20_ar
  after insert or update or delete on i$SDD_E20
  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 => 384781276416634179288870170540918841
    );
  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_E20'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_E20_ar;
/
create or replace trigger SDD_E20_inv
after insert
on i$SDD_E20
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 := 384781276416634179288870170540918841;
  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_E20_inv;
/
create or replace trigger SDD_E20_val
after insert
on i$SDD_E20
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 := 384781276416634179288870170540918841;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_E20(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_E20) 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_E20_val;
/
create or replace trigger SDD_E20_d
  instead of delete on SDD_E20 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_A20 fktab
  where 
        fktab.USE_OF_NODE_REF = :old.IRID
    ;
 delete SDD_A21 fktab
  where 
        fktab.NODE_REF = :old.IRID
    ;
 delete SDD_COMNOD fktab
  where 
        fktab.NODE_REF = :old.IRID
    ;
 update SDD_ODB fktab
    set 
        fktab.NODE_REF = NULL
  where 
        fktab.NODE_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
 ;
 delete SDD_ODB fktab
  where 
        fktab.NODE_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_E20_d;
/
create or replace trigger SDD_E3_br
  before insert or update or delete on i$SDD_E3
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_E3_br;
/
create or replace trigger SDD_E3_ar
  after insert or update or delete on i$SDD_E3
  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 => 384781276416841963414116434930321465
    );
  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_E3'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_E3_ar;
/
create or replace trigger SDD_E3_inv
after insert or update of
  KPI_REF
on i$SDD_E3
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 := 384781276416841963414116434930321465;
  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_E3_inv;
/
create or replace trigger SDD_E3_val
after insert or update of
  KPI_REF
on i$SDD_E3
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 := 384781276416841963414116434930321465;
  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_E3(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_E3) violated');
    end if;
    if not FK_E3_TO_E3(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_E3_TO_E3) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_E3_val;
/
create or replace trigger SDD_E3_d
  instead of delete on SDD_E3 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_A3 fktab
  where 
        fktab.KPI_REF = :old.IRID
    ;
 update SDD_E3 fktab
    set 
        fktab.KPI_REF = NULL
  where 
        fktab.KPI_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
 ;
 delete SDD_E3 fktab
  where 
        fktab.KPI_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_E3_d;
/
create or replace trigger SDD_E4_br
  before insert or update or delete on i$SDD_E4
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_E4_br;
/
create or replace trigger SDD_E4_ar
  after insert or update or delete on i$SDD_E4
  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 => 384781276417059192272328438610151481
    );
  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_E4'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_E4_ar;
/
create or replace trigger SDD_E4_inv
after insert
on i$SDD_E4
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 := 384781276417059192272328438610151481;
  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_E4_inv;
/
create or replace trigger SDD_E4_val
after insert
on i$SDD_E4
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 := 384781276417059192272328438610151481;
  if inserting then
    action := 'INS';
  end if;
  for inv_rec in inv_cur(this_table_irid) loop
    if not PK_SDD_E4(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_E4) 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_E4_val;
/
create or replace trigger SDD_E4_d
  instead of delete on SDD_E4 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_E4_d;
/
create or replace trigger SDD_E5_br
  before insert or update or delete on i$SDD_E5
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_E5_br;
/
create or replace trigger SDD_E5_ar
  after insert or update or delete on i$SDD_E5
  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 => 384781276417266976397574702999554105
    );
  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_E5'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_E5_ar;
/
create or replace trigger SDD_E5_inv
after insert or update of
  PROBLEM_REF
on i$SDD_E5
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 := 384781276417266976397574702999554105;
  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_E5_inv;
/
create or replace trigger SDD_E5_val
after insert or update of
  PROBLEM_REF
on i$SDD_E5
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 := 384781276417266976397574702999554105;
  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_E5(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_E5) violated');
    end if;
    if not FK_E5_TO_E5(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_E5_TO_E5) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_E5_val;
/
create or replace trigger SDD_E5_d
  instead of delete on SDD_E5 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_A10 fktab
  where 
        fktab.PROBLEM_REF = :old.IRID
    ;
 update SDD_E5 fktab
    set 
        fktab.PROBLEM_REF = NULL
  where 
        fktab.PROBLEM_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
 ;
 delete SDD_E5 fktab
  where 
        fktab.PROBLEM_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_E5_d;
/
create or replace trigger SDD_E6_br
  before insert or update or delete on i$SDD_E6
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_E6_br;
/
create or replace trigger SDD_E6_ar
  after insert or update or delete on i$SDD_E6
  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 => 384781276417488927622269576324597817
    );
  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_E6'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_E6_ar;
/
create or replace trigger SDD_E6_inv
after insert or update of
  LOCATION_REF
on i$SDD_E6
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 := 384781276417488927622269576324597817;
  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_E6_inv;
/
create or replace trigger SDD_E6_val
after insert or update of
  LOCATION_REF
on i$SDD_E6
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 := 384781276417488927622269576324597817;
  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_E6(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_E6) violated');
    end if;
    if not FK_E6_TO_E6(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_E6_TO_E6) 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_E6_val;
/
create or replace trigger SDD_E6_d
  instead of delete on SDD_E6 for each row
declare 
 secondary boolean:=jr_wastebasket.secondary_delete; 
 delete_ok boolean:=TRUE; 
 only_version   boolean:=TRUE;
 nulled_wa_ctxt boolean:=FALSE;
 reset_wa_ctxt  boolean:=FALSE;
 dummy pls_integer;
begin
 if not secondary then
  jr_wastebasket.saved_wa_context:=NULL; jr_wastebasket.DISABLE_REPOS_CONSTRAINTS;
 end if;
 begin
 select 1
   into dummy
   from I$SDD_OBJECT_VERSIONS ov
  where ov.irid=:old.irid
    and ov.wastebasket='N';
 exception
  when TOO_MANY_ROWS then
   only_version:=FALSE;
 end;
  jr_wastebasket.remove(:old.ivid);
  if jr_context.workarea is NULL and not only_version then
   return;
  end if;
 if not jr_wastebasket.remove_fm_flag and only_version and jr_context.workarea is not null then
  jr_wastebasket.saved_wa_context:=jr_context.workarea;
  jr_context.set_workarea(JR_CONTEXT.NULL_WORKAREA);
  nulled_wa_ctxt:=TRUE;
 end if;
 if secondary and (not only_version or jr_wastebasket.remove_fm_flag)
  and jr_wastebasket.saved_wa_context is not null
  and jr_context.workarea is null then
   jr_context.set_workarea(jr_wastebasket.saved_wa_context);
   reset_wa_ctxt:=TRUE;
 end if;
 if not jr_wastebasket.force_flag 
   and jr_wastebasket.repos_constraints_enabled then
   -- bug fix 2078916 - BLOCK DELETE IF USER EXTENDED ASSOCIATION EXISTS
   if not jr_ues_chk.check_ues_blocks_delete (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
 elsif jr_wastebasket.force_flag then 
  jr_wastebasket.set_secondary_delete;

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

 end if;--Constraints enabled/force
 jr_wastebasket.set_secondary_delete;
 update SDD_E6 fktab
    set 
        fktab.LOCATION_REF = NULL
  where 
        fktab.LOCATION_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
 ;
 delete SDD_E6 fktab
  where 
        fktab.LOCATION_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_E6_d;
/
create or replace trigger SDD_ENT_br
  before insert or update or delete on i$SDD_ENT
  for each row 
begin
  if inserting then
    jr_audit.pre_insert(:new.irid, :new.ivid);
  end if;  -- inserting
end SDD_ENT_br;
/
create or replace trigger SDD_ENT_ar
  after insert or update or delete on i$SDD_ENT
  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 => 384781276417710878846964449649641529
    );
  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_ENT'
      , null   -- parent_ivid not applicable for primary object
      , true   -- Designer object
      );
  end if;  -- deleting
end SDD_ENT_ar;
/
create or replace trigger SDD_ENT_inv
after insert or update of
  SUPERTYPE_REF
on i$SDD_ENT
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 := 384781276417710878846964449649641529;
  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_ENT_inv;
/
create or replace trigger SDD_ENT_val
after insert or update of
  SUPERTYPE_REF
on i$SDD_ENT
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 := 384781276417710878846964449649641529;
  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_ENT(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_ENT) violated');
    end if;
    if not FK_ENT_TO_ENT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ENT_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_ENT_val;
/
create or replace trigger SDD_ENT_d
  instead of delete on SDD_ENT 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_ENT_TO_ENT_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_EVT_TO_ENT_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_EXT_TO_ENT_d (
        :old.ivid
      , :old.IRID
      , :old.TYPES
      , 'DEL'
      ) then
     delete_ok:=FALSE;
   end if;
   if not FK_FUNENT_TO_ENT_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_FUNENT fktab
   where 
         fktab.ENTITY_REF = :old.IRID
    ;
  update SDD_ENT fktab
     set 
         fktab.SUPERTYPE_REF = NULL
   where 
         fktab.SUPERTYPE_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
  ;
  delete SDD_ENT fktab
   where 
         fktab.SUPERTYPE_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state='I')
  ;
  update SDD_EVT fktab
     set 
         fktab.ENTITY_REF = NULL
   where 
         fktab.ENTITY_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
  ;
  delete SDD_EVT fktab
   where 
         fktab.ENTITY_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state='I')
  ;
  update SDD_EXT fktab
     set 
         fktab.ENTITY_REF = NULL
   where 
         fktab.ENTITY_REF = :old.IRID
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
  ;
  delete SDD_EXT fktab
   where 
         fktab.ENTITY_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;
  if jr_wastebasket.force_flag and jr_wastebasket.purge_flag then
   -- Fix for Bug 1984967 - Force purge of entities does not work
   -- Don't do instead of trigger for relend but record that
   -- relend is invalid. Constraints are deferred so providing
   -- the entity at the other end of the relationship is also
   -- force purged then when the invalid objects are checked at
   -- commit time everything should be OK.
   -- If the entity at the other end of the relationship is not
   -- force purged in the same commit unit then the commit will fail
   -- because there will still be invalid relationships. This is what 
   -- you want to happen.
   Rmdbg.trace('Fix for Bug 1984967 - let database cascade delete relationships '); 
   insert into i$sdd_invalid_objects (object_irid, object_ivid, table_irid, type_irid)
   ( select  fktab.irid
     ,       fktab.ivid
     ,       384781276436912020966312427088529465
     ,       fktab.types
     from    sdd_relend    fktab
     where   fktab.TO_ENTITY_REF = :old.IRID
   );
  else
    delete SDD_RELEND fktab
    where  fktab.TO_ENTITY_REF = :old.IRID;
  end if;
 
 delete SDD_SYN fktab
  where 
        fktab.ENTITY_REF = :old.IRID
    ;
 delete SDD_TABENT fktab
  where 
        fktab.ENTITY_REF = :old.IRID
    ;
  if (NOT jr_wastebasket.force_flag) and jr_wastebasket.repos_constraints_enabled then
   if not FK_ENTUIE_TO_ATT_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_EVT_TO_ATT_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   if not FK_ENTUIE_TO_RELEND_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
   -- bug fix 2078916 - BLOCK DELETE IF USER EXTENDED ASSOCIATION FOR ATT EXISTS
   if not jr_ues_chk.FK_UES_TO_ATT_cmd (:old.irid,:old.ivid) then
    delete_ok:=FALSE;
   end if;
  elsif jr_wastebasket.force_flag then
  delete SDD_ENTUIE fktab
   where fktab.ATTRIBUTE_REF in (select parent_tab.IRID
                                                      from i$SDD_ATT parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
  ;
  update SDD_EVT fktab
     set 
         fktab.ATTRIBUTE_REF = NULL
   where fktab.ATTRIBUTE_REF in (select parent_tab.IRID
                                                    from i$SDD_ATT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state!='I')
  ;
  delete SDD_EVT fktab
   where fktab.ATTRIBUTE_REF in (select parent_tab.IRID
                                                    from i$SDD_ATT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
     and fktab.ivid in (select o.ivid
                          from I$SDD_OBJECT_VERSIONS o
                         where o.state='I');
  delete SDD_ENTUIE fktab
   where fktab.RELATIONSHIP_END_REF in (select parent_tab.IRID
                                                      from i$SDD_RELEND parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
  ;
  -- bug fix 2078916 - FORCE DELETE IF USER EXTENDED ASSOCIATION EXISTS TO ANY ATTRIBUTES
  delete SDD_UES fktab
  where fktab.USE_OF_REF in (select parent_tab.IRID
                             from i$SDD_ATT parent_tab
                             where parent_tab.parent_ivid=:old.ivid)
  ;
  
  end if;--force delete/purge
 if jr_context.workarea is not null then
  delete SDD_DFLATT
   where ivid in
   (select fktab.ivid
      from i$SDD_DFLATT 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.ATTRIBUTE_REF in (select parent_tab.IRID
                                                    from i$SDD_ATT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_DFLATT
   where ivid in
   (select fktab.ivid
      from i$SDD_DFLATT fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.ATTRIBUTE_REF in (select parent_tab.IRID
                                                    from i$SDD_ATT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_DSTATT
   where ivid in
   (select fktab.ivid
      from i$SDD_DSTATT 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.ATTRIBUTE_REF in (select parent_tab.IRID
                                                    from i$SDD_ATT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_DSTATT
   where ivid in
   (select fktab.ivid
      from i$SDD_DSTATT fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.ATTRIBUTE_REF in (select parent_tab.IRID
                                                    from i$SDD_ATT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  delete SDD_FUNATT
   where ivid in
   (select fktab.ivid
      from i$SDD_FUNATT fktab
          ,i$sdd_wa_context ctxt
     where ctxt.object_ivid = fktab.parent_ivid
       and ctxt.workarea_irid = jr_context.workarea
       and ctxt.wastebasket   = jr_context.wastebasket
     and fktab.ATTRIBUTE_REF in (select parent_tab.IRID
                                                    from i$SDD_ATT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 else
  delete SDD_FUNATT
   where ivid in
   (select fktab.ivid
      from i$SDD_FUNATT fktab
          ,i$sdd_object_versions ov
     where ov.ivid = fktab.parent_ivid
       and ov.wastebasket   = jr_context.wastebasket
     and fktab.ATTRIBUTE_REF in (select parent_tab.IRID
                                                    from i$SDD_ATT parent_tab
                                                   where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_COL
     set SOURCE_ATTRIBUTE_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.SOURCE_ATTRIBUTE_REF in (select parent_tab.IRID
                                                      from i$SDD_ATT parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_COL
     set SOURCE_ATTRIBUTE_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.SOURCE_ATTRIBUTE_REF in (select parent_tab.IRID
                                                      from i$SDD_ATT parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_OCO
     set RELATIONSHIP_END_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.RELATIONSHIP_END_REF in (select parent_tab.IRID
                                                      from i$SDD_RELEND parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_OCO
     set RELATIONSHIP_END_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.RELATIONSHIP_END_REF in (select parent_tab.IRID
                                                      from i$SDD_RELEND parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 end if;
 if jr_context.workarea is not null then
  update SDD_OCO
     set UNIQUE_IDENTIFIER_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_IDENTIFIER_REF in (select parent_tab.IRID
                                                      from i$SDD_UID parent_tab
                                                     where parent_tab.parent_ivid=:old.ivid)
   );
 else
  update SDD_OCO
     set UNIQUE_IDENTIFIER_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_IDENTIFIER_REF in (select parent_tab.IRID
                                                      from i$SDD_UID 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_ENT_d;
/
create or replace trigger SDD_ENTBUN_br
  before insert or update or delete on i$SDD_ENTBUN
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.ENTITY_REF is not null)
       )
    or (updating and (
        (:new.ENTITY_REF != :old.ENTITY_REF
        or (:new.ENTITY_REF is not null and :old.ENTITY_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_ENT owning_tab
        where  owning_tab.IRID=:new.ENTITY_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_ENTBUN_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_ENTBUN');
  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_ENTBUN_br;
/
create or replace trigger SDD_ENTBUN_inv
after insert or update of
  BUSINESS_UNIT_REF
on i$SDD_ENTBUN
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 := 384781276417980053736488019426822201;
  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_ENTBUN_inv;
/
create or replace trigger SDD_ENTBUN_val
after insert or update of
  BUSINESS_UNIT_REF
on i$SDD_ENTBUN
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 := 384781276417980053736488019426822201;
  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_ENTBUN(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_ENTBUN) violated');
    end if;
    if not FK_ENTBUN_TO_BUN(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ENTBUN_TO_BUN) violated - parent key not found');
    end if;
    delete i$sdd_invalid_objects io
    where  io.object_ivid = inv_rec.object_ivid
    and    io.table_irid  = this_table_irid;
  end loop;
end SDD_ENTBUN_val;
/
create or replace trigger SDD_ENTBUN_d
  instead of delete on SDD_ENTBUN 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_ENTBUN 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_ENTBUN
   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_ENTBUN_d;
/
create or replace trigger SDD_ENTUIE_br
  before insert or update or delete on i$SDD_ENTUIE
  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.UNIQUE_IDENTIFIER_REF is not null)
       )
    or (updating and (
        (:new.UNIQUE_IDENTIFIER_REF != :old.UNIQUE_IDENTIFIER_REF
        or (:new.UNIQUE_IDENTIFIER_REF is not null and :old.UNIQUE_IDENTIFIER_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_UID owning_tab
        where  owning_tab.IRID=:new.UNIQUE_IDENTIFIER_REF
        and    jr_vn.context(owning_tab.parent_ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_ENTUIE_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_ENTUIE');
  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_ENTUIE_br;
/
create or replace trigger SDD_ENTUIE_inv
after insert or update of
  ATTRIBUTE_REF
 ,RELATIONSHIP_END_REF
on i$SDD_ENTUIE
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 := 384781276418239783893045849913575481;
  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_ENTUIE_inv;
/
create or replace trigger SDD_ENTUIE_val
after insert or update of
  ATTRIBUTE_REF
 ,RELATIONSHIP_END_REF
on i$SDD_ENTUIE
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 := 384781276418239783893045849913575481;
  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_ENTUIE(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_ENTUIE) violated');
    end if;
    if not FK_ENTUIE_TO_ATT(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ENTUIE_TO_ATT) violated - parent key not found');
    end if;
    if not FK_ENTUIE_TO_RELEND(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ENTUIE_TO_RELEND) 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_ENTUIE_val;
/
create or replace trigger SDD_ENTUIE_d
  instead of delete on SDD_ENTUIE 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_ENTUIE 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_ENTUIE
   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_ENTUIE_d;
/
create or replace trigger SDD_EOU_br
  before insert or update or delete on i$SDD_EOU
  for each row 
begin
  if jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO) then
    if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
                 and (:new.VIEW_OBJECT_REF is not null)
       )
    or (updating and (
        (:new.VIEW_OBJECT_REF != :old.VIEW_OBJECT_REF
        or (:new.VIEW_OBJECT_REF is not null and :old.VIEW_OBJECT_REF is null))
        ))
    or (updating and jr_context.is_enabled(jr_context.POPULATE_PARENT_INFO_EXPLICTLY))
    then
      begin
        select irid, ivid
        into   :new.pac_ref, :new.parent_ivid
        from   i$SDD_CLA owning_tab
        where  owning_tab.IRID=:new.VIEW_OBJECT_REF
        and    jr_vn.context(owning_tab.ivid) > 0;
      exception
        when no_data_found then
          raise_application_error(-20291, 'integrity constraint (SDD_EOU_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_EOU');
  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_EOU_br;
/
create or replace trigger SDD_EOU_inv
after insert or update of
  ENTITY_OBJECT_REF
on i$SDD_EOU
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 := 384781276418518403515535158981183545;
  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_EOU_inv;
/
create or replace trigger SDD_EOU_val
after insert or update of
  ENTITY_OBJECT_REF
on i$SDD_EOU
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 := 384781276418518403515535158981183545;
  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_EOU(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_EOU) violated');
    end if;
    if not FK_EOU_TO_EOC(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_EOU_TO_EOC) 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_EOU_val;
/
create or replace trigger SDD_EOU_d
  instead of delete on SDD_EOU 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_EOU 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_CAT fktab
  where 
        fktab.ENTITY_OBJECT_USAGE_REF = :old.IRID
    ;
  delete SDD_AEU fktab
   where 
         fktab.ENTITY_OBJECT_USAGE_REF = :old.IRID
    ;
 if not delete_ok then 
  RAISE jr_wastebasket.delete_error; 
 end if; 
  delete i$SDD_EOU
   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_EOU_d;
/
create or replace trigger SDD_ERU_inv
after insert or update of
  CIELEMENT_REF
 ,UML_RULE_REF
on i$SDD_ERU
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 := 384781276418702575808367075144517689;
  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_ERU_inv;
/
create or replace trigger SDD_ERU_val
after insert or update of
  CIELEMENT_REF
 ,UML_RULE_REF
on i$SDD_ERU
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 := 384781276418702575808367075144517689;
  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_ELRUL(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (PK_SDD_ELRUL) violated');
    end if;
    if not UK_ERU(inv_rec.object_irid, inv_rec.object_ivid) then
      raise_application_error(-20001, 'unique constraint (UK_ERU) violated');
    end if;
    if not FK_ERU_TO_URU(inv_rec.object_ivid, inv_rec.type_irid, action) then
      raise_application_error(-20291, 'integrity constraint (FK_ERU_TO_URU) 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_ERU_val;
/
create or replace trigger SDD_ERU_d
  instead of delete on SDD_ERU 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_ERU 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_ERU
   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_ERU_d;
/
create or replace trigger SDD_EVH_br
  before insert or update or delete on i$SDD_EVH
  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
