rem ----------------------------------------------------------------+
prompt Trigger: i$sdd_object_versions_ctxt
rem      Notes: to maintain the I$WA_CONTEXT table on ins/upd/del of
rem             I$SDD_OBJECT_VERSIONS
rem
rem WGS 8th Sept 1999, part of performance fix (Bug 986706)
rem ----------------------------------------------------------------+
CREATE OR REPLACE TRIGGER I$SDD_OBJECT_VERSIONS_CTXT
AFTER INSERT OR UPDATE ON I$SDD_OBJECT_VERSIONS
FOR EACH ROW
begin
 if jr_context.is_enabled(jr_context.OBJECT_VERSIONS) then
  if inserting
   and jr_context.workarea is not null then
    -- Version resolving context table
    insert into I$SDD_WA_CONTEXT
     (workarea_irid, object_ivid, wastebasket)
    values (
      jr_context.workarea
     ,:new.ivid
     ,'N');
  end if;
  if updating
   and :new.wastebasket!=:old.wastebasket then
    --Query all workarea irids to allow use of index in I$SDD_WA_CONTEXT
    update I$SDD_WA_CONTEXT ctxt
     set ctxt.wastebasket=:new.wastebasket
   where ctxt.object_ivid=:new.ivid
     and ctxt.workarea_irid in (select irid from I$SDD_WORKAREAS);
  end if;
  --Deletes cascaded from I$SDD_OBJECT_VERSIONS by FK
 end if;
end;
/

/*
rem --------------------------------------------------------------------------+
prompt Trigger: sdd_objver_table_irid_check
rem      Notes: to check that table_irid is to be found in the
rem             rm_sql_tables view
rem
rem CW 2-Jun-99 Fix bug 772837, remove use of dbms_output
rem CW 29-Sep-1999 Fix bug 968298 replace sql by foreign key
rem                Note, this is only ok while the meta data is not versioned !
rem --------------------------------------------------------------------------+
create or replace trigger sdd_objver_table_irid_check
  before insert or update of table_irid on i$sdd_object_versions
  for each row
  declare
    tabname varchar2(120);
  begin
    if :new.table_irid is not null
    then
       select tab.table_name
       into   tabname
       from   rm_sql_tables tab
       where  tab.irid = :new.table_irid;
    end if;

    exception
      when no_data_found then
        raise_application_error(-20101, 'No table in rm_sql_tables with identifier: ''' || :new.table_irid ||'''');
  end;
/

*/


