
create or replace trigger SDD_UPR_br
before insert or update or delete on i$SDD_UPR
for each row 
begin
  if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
    and (:new.CIELEMENT_REF is not null and :new.PREFERENCE_FOR is not null)
     )
    or (updating and (
    (:new.CIELEMENT_REF != :old.CIELEMENT_REF
    or (:new.CIELEMENT_REF is not null and :old.CIELEMENT_REF is null))
    )) then
    begin
      jr_reg_ver.populate_parent_info( :new.cielement_ref
                                     , :new.preference_for
                                     , :new.pac_ref
                                     , :new.parent_ivid
                                     );
    end;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_UPR');
  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, 'SDD_UPR');
  end if;  -- deleting
end SDD_UPR_br;
/

create or replace trigger SDD_PRU_br
before insert or update or delete on i$SDD_PRU
for each row 
begin
  if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
    and (:new.CIELEMENT_REF is not null and :new.PREFERENCE_SET_USAGE_FOR is not null)
     )
    or (updating and (
    (:new.CIELEMENT_REF != :old.CIELEMENT_REF
    or (:new.CIELEMENT_REF is not null and :old.CIELEMENT_REF is null))
    )) then
    begin
      jr_reg_ver.populate_parent_info( :new.cielement_ref
                                     , :new.preference_set_usage_for
                                     , :new.pac_ref
                                     , :new.parent_ivid
                                     );
    end;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_PRU');
  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, 'SDD_PRU');
  end if;  -- deleting
end SDD_PRU_br;
/

create or replace trigger SDD_ERU_br
before insert or update or delete on i$SDD_ERU
for each row 
begin
  if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
    and (:new.CIELEMENT_REF is not null and :new.ELEMENT_TYPE_FOR is not null)
     )
    or (updating and (
    (:new.CIELEMENT_REF != :old.CIELEMENT_REF
    or (:new.CIELEMENT_REF is not null and :old.CIELEMENT_REF is null))
    )) then
    begin
      jr_reg_ver.populate_parent_info( :new.cielement_ref
                                     , :new.element_type_for
                                     , :new.pac_ref
                                     , :new.parent_ivid
                                     );
    end;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_ERU');
  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,'SDD_ERU');
  end if;  -- deleting
end SDD_ERU_br;
/

create or replace trigger SDD_TAGVAL_br
before insert or update or delete on i$SDD_TAGVAL
for each row 
begin
  if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
    and (:new.ELEMENT_REF is not null and :new.TAGGED_ELEMENT_TYPE is not null)
     )
    or (updating and (
    (:new.ELEMENT_REF != :old.ELEMENT_REF
    or (:new.ELEMENT_REF is not null and :old.ELEMENT_REF is null))
    )) then
    begin
      jr_reg_ver.populate_parent_info( :new.element_ref
                                     , :new.tagged_element_type
                                     , :new.pac_ref
                                     , :new.parent_ivid
                                     );
    end;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_TAGVAL');
  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,'SDD_TAGVAL');
  end if;  -- deleting
end SDD_TAGVAL_br;
/

create or replace trigger SDD_UES_br
before insert or update or delete on i$SDD_UES
for each row 
begin
  if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
    and (:new.PART_OF_REF is not null and :new.ELEMENT_TYPE_FOR is not null)
     )
    or (updating and (
    (:new.PART_OF_REF != :old.PART_OF_REF
    or (:new.PART_OF_REF is not null and :old.PART_OF_REF is null))
    )) then
    begin
      jr_reg_ver.populate_parent_info( :new.part_of_ref
                                     , :new.element_type_for
                                     , :new.pac_ref
                                     , :new.parent_ivid
                                     );
    end;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_UES');
  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,'SDD_UES');
  end if;  -- deleting
end SDD_UES_br;
/

create or replace trigger RM_TEXT_LINES_br
before insert or update or delete on i$RM_TEXT_LINES
for each row 
begin
  if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
    and (:new.TXT_REF is not null and :new.ELEMENT_TYPE_FOR is not null)
     )
    or (updating and (
    (:new.TXT_REF != :old.TXT_REF
    or (:new.TXT_REF is not null and :old.TXT_REF is null))
    )) then
    begin
      jr_reg_ver.populate_parent_info( :new.txt_ref
                                     , :new.element_type_for
                                     , :new.pac_ref
                                     , :new.parent_ivid
                                     );
    end;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'RM_TEXT_LINES');
  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,'RM_TEXT_LINES');
  end if;  -- deleting
end RM_TEXT_LINES_br;
/

create or replace trigger CK_APPLICATION_LOGIC_br
before insert or update or delete on i$CK_APPLICATION_LOGIC
for each row 
begin
  if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
    and (:new.AL_REPOS_ELEMENT is not null and :new.ELEMENT_TYPE_FOR is not null)
     )
    or (updating and (
    (:new.AL_REPOS_ELEMENT != :old.AL_REPOS_ELEMENT
    or (:new.AL_REPOS_ELEMENT is not null and :old.AL_REPOS_ELEMENT is null))
    )) then
    begin
      jr_reg_ver.populate_parent_info( :new.al_repos_element
                                     , :new.element_type_for
                                     , :new.pac_ref
                                     , :new.parent_ivid
                                     );
    end;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'CK_APPLICATION_LOGIC');
  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,'CK_APPLICATION_LOGIC');
  end if;  -- deleting
end CK_APPLICATION_LOGIC_br;
/

/* ***TODO***
create or replace trigger SDD_DEPENDENCIES_br
before insert or update or delete on i$SDD_DEPENDENCIES
for each row 
begin
  if (inserting and (:new.pac_ref is null or :new.parent_ivid is null)
    and (:new.AL_REPOS_ELEMENT is not null and :new.ELEMENT_TYPE_FOR is not null)
     )
    or (updating and (
    (:new.AL_REPOS_ELEMENT != :old.AL_REPOS_ELEMENT
    or (:new.AL_REPOS_ELEMENT is not null and :old.AL_REPOS_ELEMENT is null))
    )) then
    begin
      jr_reg_ver.populate_parent_info( :new.al_repos_element
                                     , :new.element_type_for
                                     , :new.pac_ref
                                     , :new.parent_ivid
                                     );
    end;
  end if;
  -- Check access rights and check_in state of owning object
  jr_secondary_object.check_access_rights(:new.parent_ivid, 'SDD_DEPENDENCIES');
  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_DEPENDENCIES_br;
/
***END TODO*** */



