create sequence ords_id_seq start with 10000;

create or replace trigger oauth_approvals_trg before
  insert or update on oauth_approvals for each row
begin
  if inserting then
    if :new.id is null then 
      -- :new.id := ords_id_seq.nextval;  -- supports only 11g and later releases
      -- 10g support for assignment of sequenceName.nextval
      select ords_id_seq.nextval into :new.id from dual;   
    end if;
    -- Populated creation audit
    if :new.created_on is null then
      if :new.updated_on is null then
        :new.created_on := sysdate;
      else
        :new.created_on := :new.updated_on;
      end if;
    end if;
    if :new.created_by is null then
      if :new.updated_by is null then
        :new.created_by := sys_context('USERENV','SESSION_USER');
      else
        :new.created_by := :new.updated_by;
      end if;
    end if;
    -- Populated update audit
    if :new.updated_on is null then
      :new.updated_on := :new.created_on;
    end if;
    if :new.updated_by is null then
      :new.updated_by := :new.created_by;
    end if;
  else 
    case
      -- Updating via PL/SQL API
      when :new.updated_on is null or :new.updated_by is null or 
           :new.created_on is null or :new.created_by is null then
        case
          -- Creation being patched - e.g. import
          when :new.updated_on is null and :new.updated_by is null and 
               :new.created_on is not null and :new.created_by is not null then
            :new.updated_on := :new.created_on;
            :new.updated_by := :new.created_by;
          -- Audit being patched
          when :new.created_on is not null or :new.created_by is not null then
            if :new.updated_on is null then
              :new.updated_on := :old.updated_on;
            end if;
            if :new.updated_by is null then
              :new.updated_by := :old.updated_by;
            end if;
          -- Not patching audit - evolve update audit
          else
            null;
        end case;
        -- Evolve update audit and bring old values forward
        if :new.updated_on is null then
          :new.updated_on := sysdate;
        end if;
        if :new.updated_by is null then
          :new.updated_by := sys_context('USERENV','SESSION_USER');
        end if;
        if :new.created_on is null then
          :new.created_on := :old.created_on;
        end if;
        if :new.created_by is null then
          :new.created_by := :old.created_by;
        end if;
      -- Updating via SQL
      else
        case
          -- Creation audit not changed so evolve update audit
          when :new.created_on = :old.created_on and
               :new.created_by = :old.created_by then
            if :new.updated_on = :old.updated_on then
              :new.updated_on := sysdate;
            end if;
            if :new.updated_by = :old.updated_by then
              :new.updated_by := sys_context('USERENV','SESSION_USER');
            end if;
          -- Patching audit so accept what is given
          else
            null;
        end case;
    end case;
  end if;
end;
/
create or replace trigger oauth_approval_privs_trg before
  insert or update on oauth_approval_privs for each row
begin
  if inserting then
    if :new.id is null then 
      -- :new.id := ords_id_seq.nextval;  -- supports only 11g and later releases
      -- 10g support for assignment of sequenceName.nextval
      select ords_id_seq.nextval into :new.id from dual;   
    end if;
    -- Populated creation audit
    if :new.created_on is null then
      if :new.updated_on is null then
        :new.created_on := sysdate;
      else
        :new.created_on := :new.updated_on;
      end if;
    end if;
    if :new.created_by is null then
      if :new.updated_by is null then
        :new.created_by := sys_context('USERENV','SESSION_USER');
      else
        :new.created_by := :new.updated_by;
      end if;
    end if;
    -- Populated update audit
    if :new.updated_on is null then
      :new.updated_on := :new.created_on;
    end if;
    if :new.updated_by is null then
      :new.updated_by := :new.created_by;
    end if;
  else 
    case
      -- Updating via PL/SQL API
      when :new.updated_on is null or :new.updated_by is null or 
           :new.created_on is null or :new.created_by is null then
        case
          -- Creation being patched - e.g. import
          when :new.updated_on is null and :new.updated_by is null and 
               :new.created_on is not null and :new.created_by is not null then
            :new.updated_on := :new.created_on;
            :new.updated_by := :new.created_by;
          -- Audit being patched
          when :new.created_on is not null or :new.created_by is not null then
            if :new.updated_on is null then
              :new.updated_on := :old.updated_on;
            end if;
            if :new.updated_by is null then
              :new.updated_by := :old.updated_by;
            end if;
          -- Not patching audit - evolve update audit
          else
            null;
        end case;
        -- Evolve update audit and bring old values forward
        if :new.updated_on is null then
          :new.updated_on := sysdate;
        end if;
        if :new.updated_by is null then
          :new.updated_by := sys_context('USERENV','SESSION_USER');
        end if;
        if :new.created_on is null then
          :new.created_on := :old.created_on;
        end if;
        if :new.created_by is null then
          :new.created_by := :old.created_by;
        end if;
      -- Updating via SQL
      else
        case
          -- Creation audit not changed so evolve update audit
          when :new.created_on = :old.created_on and
               :new.created_by = :old.created_by then
            if :new.updated_on = :old.updated_on then
              :new.updated_on := sysdate;
            end if;
            if :new.updated_by = :old.updated_by then
              :new.updated_by := sys_context('USERENV','SESSION_USER');
            end if;
          -- Patching audit so accept what is given
          else
            null;
        end case;
    end case;
  end if;
end;
/
create or replace trigger oauth_clients_trg before
  insert or update on oauth_clients for each row
begin
  if inserting then
    if :new.id is null then 
      -- :new.id := ords_id_seq.nextval;  -- supports only 11g and later releases
      -- 10g support for assignment of sequenceName.nextval
      select ords_id_seq.nextval into :new.id from dual;   
    end if;
    -- Populated creation audit
    if :new.created_on is null then
      if :new.updated_on is null then
        :new.created_on := sysdate;
      else
        :new.created_on := :new.updated_on;
      end if;
    end if;
    if :new.created_by is null then
      if :new.updated_by is null then
        :new.created_by := sys_context('USERENV','SESSION_USER');
      else
        :new.created_by := :new.updated_by;
      end if;
    end if;
    -- Populated update audit
    if :new.updated_on is null then
      :new.updated_on := :new.created_on;
    end if;
    if :new.updated_by is null then
      :new.updated_by := :new.created_by;
    end if;
  else 
    case
      -- Updating via PL/SQL API
      when :new.updated_on is null or :new.updated_by is null or 
           :new.created_on is null or :new.created_by is null then
        case
          -- Creation being patched - e.g. import
          when :new.updated_on is null and :new.updated_by is null and 
               :new.created_on is not null and :new.created_by is not null then
            :new.updated_on := :new.created_on;
            :new.updated_by := :new.created_by;
          -- Audit being patched
          when :new.created_on is not null or :new.created_by is not null then
            if :new.updated_on is null then
              :new.updated_on := :old.updated_on;
            end if;
            if :new.updated_by is null then
              :new.updated_by := :old.updated_by;
            end if;
          -- Not patching audit - evolve update audit
          else
            null;
        end case;
        -- Evolve update audit and bring old values forward
        if :new.updated_on is null then
          :new.updated_on := sysdate;
        end if;
        if :new.updated_by is null then
          :new.updated_by := sys_context('USERENV','SESSION_USER');
        end if;
        if :new.created_on is null then
          :new.created_on := :old.created_on;
        end if;
        if :new.created_by is null then
          :new.created_by := :old.created_by;
        end if;
      -- Updating via SQL
      else
        case
          -- Creation audit not changed so evolve update audit
          when :new.created_on = :old.created_on and
               :new.created_by = :old.created_by then
            if :new.updated_on = :old.updated_on then
              :new.updated_on := sysdate;
            end if;
            if :new.updated_by = :old.updated_by then
              :new.updated_by := sys_context('USERENV','SESSION_USER');
            end if;
          -- Patching audit so accept what is given
          else
            null;
        end case;
    end case;
  end if;
end;
/
create or replace trigger oauth_client_privileges_trg before
  insert or update on oauth_client_privileges for each row
begin
  if inserting then
    if :new.id is null then 
      -- :new.id := ords_id_seq.nextval;  -- supports only 11g and later releases
      -- 10g support for assignment of sequenceName.nextval
      select ords_id_seq.nextval into :new.id from dual;   
    end if;
    -- Populated creation audit
    if :new.created_on is null then
      if :new.updated_on is null then
        :new.created_on := sysdate;
      else
        :new.created_on := :new.updated_on;
      end if;
    end if;
    if :new.created_by is null then
      if :new.updated_by is null then
        :new.created_by := sys_context('USERENV','SESSION_USER');
      else
        :new.created_by := :new.updated_by;
      end if;
    end if;
    -- Populated update audit
    if :new.updated_on is null then
      :new.updated_on := :new.created_on;
    end if;
    if :new.updated_by is null then
      :new.updated_by := :new.created_by;
    end if;
  else 
    case
      -- Updating via PL/SQL API
      when :new.updated_on is null or :new.updated_by is null or 
           :new.created_on is null or :new.created_by is null then
        case
          -- Creation being patched - e.g. import
          when :new.updated_on is null and :new.updated_by is null and 
               :new.created_on is not null and :new.created_by is not null then
            :new.updated_on := :new.created_on;
            :new.updated_by := :new.created_by;
          -- Audit being patched
          when :new.created_on is not null or :new.created_by is not null then
            if :new.updated_on is null then
              :new.updated_on := :old.updated_on;
            end if;
            if :new.updated_by is null then
              :new.updated_by := :old.updated_by;
            end if;
          -- Not patching audit - evolve update audit
          else
            null;
        end case;
        -- Evolve update audit and bring old values forward
        if :new.updated_on is null then
          :new.updated_on := sysdate;
        end if;
        if :new.updated_by is null then
          :new.updated_by := sys_context('USERENV','SESSION_USER');
        end if;
        if :new.created_on is null then
          :new.created_on := :old.created_on;
        end if;
        if :new.created_by is null then
          :new.created_by := :old.created_by;
        end if;
      -- Updating via SQL
      else
        case
          -- Creation audit not changed so evolve update audit
          when :new.created_on = :old.created_on and
               :new.created_by = :old.created_by then
            if :new.updated_on = :old.updated_on then
              :new.updated_on := sysdate;
            end if;
            if :new.updated_by = :old.updated_by then
              :new.updated_by := sys_context('USERENV','SESSION_USER');
            end if;
          -- Patching audit so accept what is given
          else
            null;
        end case;
    end case;
  end if;
end;
/
create or replace trigger oauth_pending_approvals_trg before
  insert or update on oauth_pending_approvals for each row
begin
  if inserting then
    if :new.id is null then 
      -- :new.id := ords_id_seq.nextval;  -- supports only 11g and later releases
      -- 10g support for assignment of sequenceName.nextval
      select ords_id_seq.nextval into :new.id from dual;   
    end if;
    -- Populated creation audit
    if :new.created_on is null then
      if :new.updated_on is null then
        :new.created_on := sysdate;
      else
        :new.created_on := :new.updated_on;
      end if;
    end if;
    if :new.created_by is null then
      if :new.updated_by is null then
        :new.created_by := sys_context('USERENV','SESSION_USER');
      else
        :new.created_by := :new.updated_by;
      end if;
    end if;
    -- Populated update audit
    if :new.updated_on is null then
      :new.updated_on := :new.created_on;
    end if;
    if :new.updated_by is null then
      :new.updated_by := :new.created_by;
    end if;
  else 
    case
      -- Updating via PL/SQL API
      when :new.updated_on is null or :new.updated_by is null or 
           :new.created_on is null or :new.created_by is null then
        case
          -- Creation being patched - e.g. import
          when :new.updated_on is null and :new.updated_by is null and 
               :new.created_on is not null and :new.created_by is not null then
            :new.updated_on := :new.created_on;
            :new.updated_by := :new.created_by;
          -- Audit being patched
          when :new.created_on is not null or :new.created_by is not null then
            if :new.updated_on is null then
              :new.updated_on := :old.updated_on;
            end if;
            if :new.updated_by is null then
              :new.updated_by := :old.updated_by;
            end if;
          -- Not patching audit - evolve update audit
          else
            null;
        end case;
        -- Evolve update audit and bring old values forward
        if :new.updated_on is null then
          :new.updated_on := sysdate;
        end if;
        if :new.updated_by is null then
          :new.updated_by := sys_context('USERENV','SESSION_USER');
        end if;
        if :new.created_on is null then
          :new.created_on := :old.created_on;
        end if;
        if :new.created_by is null then
          :new.created_by := :old.created_by;
        end if;
      -- Updating via SQL
      else
        case
          -- Creation audit not changed so evolve update audit
          when :new.created_on = :old.created_on and
               :new.created_by = :old.created_by then
            if :new.updated_on = :old.updated_on then
              :new.updated_on := sysdate;
            end if;
            if :new.updated_by = :old.updated_by then
              :new.updated_by := sys_context('USERENV','SESSION_USER');
            end if;
          -- Patching audit so accept what is given
          else
            null;
        end case;
    end case;
  end if;
end;
/
create or replace trigger oauth_sessions_trg before
  insert or update on oauth_sessions for each row
begin
  if inserting then
    if :new.id is null then 
      -- :new.id := ords_id_seq.nextval;  -- supports only 11g and later releases
      -- 10g support for assignment of sequenceName.nextval
      select ords_id_seq.nextval into :new.id from dual;   
    end if;
    -- Populated creation audit
    if :new.created_on is null then
      if :new.updated_on is null then
        :new.created_on := sysdate;
      else
        :new.created_on := :new.updated_on;
      end if;
    end if;
    if :new.created_by is null then
      if :new.updated_by is null then
        :new.created_by := sys_context('USERENV','SESSION_USER');
      else
        :new.created_by := :new.updated_by;
      end if;
    end if;
    -- Populated update audit
    if :new.updated_on is null then
      :new.updated_on := :new.created_on;
    end if;
    if :new.updated_by is null then
      :new.updated_by := :new.created_by;
    end if;
  else 
    case
      -- Updating via PL/SQL API
      when :new.updated_on is null or :new.updated_by is null or 
           :new.created_on is null or :new.created_by is null then
        case
          -- Creation being patched - e.g. import
          when :new.updated_on is null and :new.updated_by is null and 
               :new.created_on is not null and :new.created_by is not null then
            :new.updated_on := :new.created_on;
            :new.updated_by := :new.created_by;
          -- Audit being patched
          when :new.created_on is not null or :new.created_by is not null then
            if :new.updated_on is null then
              :new.updated_on := :old.updated_on;
            end if;
            if :new.updated_by is null then
              :new.updated_by := :old.updated_by;
            end if;
          -- Not patching audit - evolve update audit
          else
            null;
        end case;
        -- Evolve update audit and bring old values forward
        if :new.updated_on is null then
          :new.updated_on := sysdate;
        end if;
        if :new.updated_by is null then
          :new.updated_by := sys_context('USERENV','SESSION_USER');
        end if;
        if :new.created_on is null then
          :new.created_on := :old.created_on;
        end if;
        if :new.created_by is null then
          :new.created_by := :old.created_by;
        end if;
      -- Updating via SQL
      else
        case
          -- Creation audit not changed so evolve update audit
          when :new.created_on = :old.created_on and
               :new.created_by = :old.created_by then
            if :new.updated_on = :old.updated_on then
              :new.updated_on := sysdate;
            end if;
            if :new.updated_by = :old.updated_by then
              :new.updated_by := sys_context('USERENV','SESSION_USER');
            end if;
          -- Patching audit so accept what is given
          else
            null;
        end case;
    end case;
  end if;
end;
/
create or replace trigger ords_handlers_trg before
  insert or update on ords_handlers for each row
begin
  if inserting then
    if :new.id is null then 
      -- :new.id := ords_id_seq.nextval;  -- supports only 11g and later releases
      -- 10g support for assignment of sequenceName.nextval
      select ords_id_seq.nextval into :new.id from dual;   
    end if;
    -- Populated creation audit
    if :new.created_on is null then
      if :new.updated_on is null then
        :new.created_on := sysdate;
      else
        :new.created_on := :new.updated_on;
      end if;
    end if;
    if :new.created_by is null then
      if :new.updated_by is null then
        :new.created_by := sys_context('USERENV','SESSION_USER');
      else
        :new.created_by := :new.updated_by;
      end if;
    end if;
    -- Populated update audit
    if :new.updated_on is null then
      :new.updated_on := :new.created_on;
    end if;
    if :new.updated_by is null then
      :new.updated_by := :new.created_by;
    end if;
  else 
    case
      -- Updating via PL/SQL API
      when :new.updated_on is null or :new.updated_by is null or 
           :new.created_on is null or :new.created_by is null then
        case
          -- Creation being patched - e.g. import
          when :new.updated_on is null and :new.updated_by is null and 
               :new.created_on is not null and :new.created_by is not null then
            :new.updated_on := :new.created_on;
            :new.updated_by := :new.created_by;
          -- Audit being patched
          when :new.created_on is not null or :new.created_by is not null then
            if :new.updated_on is null then
              :new.updated_on := :old.updated_on;
            end if;
            if :new.updated_by is null then
              :new.updated_by := :old.updated_by;
            end if;
          -- Not patching audit - evolve update audit
          else
            null;
        end case;
        -- Evolve update audit and bring old values forward
        if :new.updated_on is null then
          :new.updated_on := sysdate;
        end if;
        if :new.updated_by is null then
          :new.updated_by := sys_context('USERENV','SESSION_USER');
        end if;
        if :new.created_on is null then
          :new.created_on := :old.created_on;
        end if;
        if :new.created_by is null then
          :new.created_by := :old.created_by;
        end if;
      -- Updating via SQL
      else
        case
          -- Creation audit not changed so evolve update audit
          when :new.created_on = :old.created_on and
               :new.created_by = :old.created_by then
            if :new.updated_on = :old.updated_on then
              :new.updated_on := sysdate;
            end if;
            if :new.updated_by = :old.updated_by then
              :new.updated_by := sys_context('USERENV','SESSION_USER');
            end if;
          -- Patching audit so accept what is given
          else
            null;
        end case;
    end case;
  end if;
end;
/
create or replace trigger ords_modules_trg before
  insert or update on ords_modules for each row
declare
    l_operation_timestamp timestamp_unconstrained := sysdate;
begin
  if inserting then
    if :new.id is null then 
      -- :new.id := ords_id_seq.nextval;  -- supports only 11g and later releases
      -- 10g support for assignment of sequenceName.nextval
      select ords_id_seq.nextval into :new.id from dual;   
    end if;
    -- Populated creation audit
    if :new.created_on is null then
      if :new.updated_on is null then
        :new.created_on := sysdate;
      else
        :new.created_on := :new.updated_on;
      end if;
    end if;
    if :new.created_by is null then
      if :new.updated_by is null then
        :new.created_by := sys_context('USERENV','SESSION_USER');
      else
        :new.created_by := :new.updated_by;
      end if;
    end if;
    -- Populated update audit
    if :new.updated_on is null then
      :new.updated_on := :new.created_on;
    end if;
    if :new.updated_by is null then
      :new.updated_by := :new.created_by;
    end if;
  else 
    case
      -- Updating via PL/SQL API
      when :new.updated_on is null or :new.updated_by is null or 
           :new.created_on is null or :new.created_by is null then
        case
          -- Creation being patched - e.g. import
          when :new.updated_on is null and :new.updated_by is null and 
               :new.created_on is not null and :new.created_by is not null then
            :new.updated_on := :new.created_on;
            :new.updated_by := :new.created_by;
          -- Audit being patched
          when :new.created_on is not null or :new.created_by is not null then
            if :new.updated_on is null then
              :new.updated_on := :old.updated_on;
            end if;
            if :new.updated_by is null then
              :new.updated_by := :old.updated_by;
            end if;
          -- Not patching audit - evolve update audit
          else
            null;
        end case;
        -- Evolve update audit and bring old values forward
        if :new.updated_on is null then
          :new.updated_on := sysdate;
        end if;
        if :new.updated_by is null then
          :new.updated_by := sys_context('USERENV','SESSION_USER');
        end if;
        if :new.created_on is null then
          :new.created_on := :old.created_on;
        end if;
        if :new.created_by is null then
          :new.created_by := :old.created_by;
        end if;
      -- Updating via SQL
      else
        case
          -- Creation audit not changed so evolve update audit
          when :new.created_on = :old.created_on and
               :new.created_by = :old.created_by then
            if :new.updated_on = :old.updated_on then
              :new.updated_on := sysdate;
            end if;
            if :new.updated_by = :old.updated_by then
              :new.updated_by := sys_context('USERENV','SESSION_USER');
            end if;
          -- Patching audit so accept what is given
          else
            null;
        end case;
    end case;
  end if;
end;
/
create or replace trigger ords_parameters_trg before
  insert or update on ords_parameters for each row
begin
  if inserting then
    if :new.id is null then 
      -- :new.id := ords_id_seq.nextval;  -- supports only 11g and later releases
      -- 10g support for assignment of sequenceName.nextval
      select ords_id_seq.nextval into :new.id from dual;   
    end if;
    -- Populated creation audit
    if :new.created_on is null then
      if :new.updated_on is null then
        :new.created_on := sysdate;
      else
        :new.created_on := :new.updated_on;
      end if;
    end if;
    if :new.created_by is null then
      if :new.updated_by is null then
        :new.created_by := sys_context('USERENV','SESSION_USER');
      else
        :new.created_by := :new.updated_by;
      end if;
    end if;
    -- Populated update audit
    if :new.updated_on is null then
      :new.updated_on := :new.created_on;
    end if;
    if :new.updated_by is null then
      :new.updated_by := :new.created_by;
    end if;
  else 
    case
      -- Updating via PL/SQL API
      when :new.updated_on is null or :new.updated_by is null or 
           :new.created_on is null or :new.created_by is null then
        case
          -- Creation being patched - e.g. import
          when :new.updated_on is null and :new.updated_by is null and 
               :new.created_on is not null and :new.created_by is not null then
            :new.updated_on := :new.created_on;
            :new.updated_by := :new.created_by;
          -- Audit being patched
          when :new.created_on is not null or :new.created_by is not null then
            if :new.updated_on is null then
              :new.updated_on := :old.updated_on;
            end if;
            if :new.updated_by is null then
              :new.updated_by := :old.updated_by;
            end if;
          -- Not patching audit - evolve update audit
          else
            null;
        end case;
        -- Evolve update audit and bring old values forward
        if :new.updated_on is null then
          :new.updated_on := sysdate;
        end if;
        if :new.updated_by is null then
          :new.updated_by := sys_context('USERENV','SESSION_USER');
        end if;
        if :new.created_on is null then
          :new.created_on := :old.created_on;
        end if;
        if :new.created_by is null then
          :new.created_by := :old.created_by;
        end if;
      -- Updating via SQL
      else
        case
          -- Creation audit not changed so evolve update audit
          when :new.created_on = :old.created_on and
               :new.created_by = :old.created_by then
            if :new.updated_on = :old.updated_on then
              :new.updated_on := sysdate;
            end if;
            if :new.updated_by = :old.updated_by then
              :new.updated_by := sys_context('USERENV','SESSION_USER');
            end if;
          -- Patching audit so accept what is given
          else
            null;
        end case;
    end case;
  end if;
end;
/
create or replace trigger ords_schemas_trg before
  insert or update on ords_schemas for each row
begin
  if inserting then
    if :new.id is null then 
      -- :new.id := ords_id_seq.nextval;  -- supports only 11g and later releases
      -- 10g support for assignment of sequenceName.nextval
      select ords_id_seq.nextval into :new.id from dual;   
    end if;
    -- Populated creation audit
    if :new.created_on is null then
      if :new.updated_on is null then
        :new.created_on := sysdate;
      else
        :new.created_on := :new.updated_on;
      end if;
    end if;
    if :new.created_by is null then
      if :new.updated_by is null then
        :new.created_by := sys_context('USERENV','SESSION_USER');
      else
        :new.created_by := :new.updated_by;
      end if;
    end if;
    -- Populated update audit
    if :new.updated_on is null then
      :new.updated_on := :new.created_on;
    end if;
    if :new.updated_by is null then
      :new.updated_by := :new.created_by;
    end if;
  else 
    case
      -- Updating via PL/SQL API
      when :new.updated_on is null or :new.updated_by is null or 
           :new.created_on is null or :new.created_by is null then
        case
          -- Creation being patched - e.g. import
          when :new.updated_on is null and :new.updated_by is null and 
               :new.created_on is not null and :new.created_by is not null then
            :new.updated_on := :new.created_on;
            :new.updated_by := :new.created_by;
          -- Audit being patched
          when :new.created_on is not null or :new.created_by is not null then
            if :new.updated_on is null then
              :new.updated_on := :old.updated_on;
            end if;
            if :new.updated_by is null then
              :new.updated_by := :old.updated_by;
            end if;
          -- Not patching audit - evolve update audit
          else
            null;
        end case;
        -- Evolve update audit and bring old values forward
        if :new.updated_on is null then
          :new.updated_on := sysdate;
        end if;
        if :new.updated_by is null then
          :new.updated_by := sys_context('USERENV','SESSION_USER');
        end if;
        if :new.created_on is null then
          :new.created_on := :old.created_on;
        end if;
        if :new.created_by is null then
          :new.created_by := :old.created_by;
        end if;
      -- Updating via SQL
      else
        case
          -- Creation audit not changed so evolve update audit
          when :new.created_on = :old.created_on and
               :new.created_by = :old.created_by then
            if :new.updated_on = :old.updated_on then
              :new.updated_on := sysdate;
            end if;
            if :new.updated_by = :old.updated_by then
              :new.updated_by := sys_context('USERENV','SESSION_USER');
            end if;
          -- Patching audit so accept what is given
          else
            null;
        end case;
    end case;
  end if;
end;
/
create or replace trigger ords_objects_trg before
  insert or update on ords_objects for each row
begin
  if inserting then
    if :new.id is null then 
      -- :new.id := ords_id_seq.nextval;  -- supports only 11g and later releases
      -- 10g support for assignment of sequenceName.nextval
      select ords_id_seq.nextval into :new.id from dual;   
    end if;
    -- Populated creation audit
    if :new.created_on is null then
      if :new.updated_on is null then
        :new.created_on := sysdate;
      else
        :new.created_on := :new.updated_on;
      end if;
    end if;
    if :new.created_by is null then
      if :new.updated_by is null then
        :new.created_by := sys_context('USERENV','SESSION_USER');
      else
        :new.created_by := :new.updated_by;
      end if;
    end if;
    -- Populated update audit
    if :new.updated_on is null then
      :new.updated_on := :new.created_on;
    end if;
    if :new.updated_by is null then
      :new.updated_by := :new.created_by;
    end if;
  else 
    case
      -- Updating via PL/SQL API
      when :new.updated_on is null or :new.updated_by is null or 
           :new.created_on is null or :new.created_by is null then
        case
          -- Creation being patched - e.g. import
          when :new.updated_on is null and :new.updated_by is null and 
               :new.created_on is not null and :new.created_by is not null then
            :new.updated_on := :new.created_on;
            :new.updated_by := :new.created_by;
          -- Audit being patched
          when :new.created_on is not null or :new.created_by is not null then
            if :new.updated_on is null then
              :new.updated_on := :old.updated_on;
            end if;
            if :new.updated_by is null then
              :new.updated_by := :old.updated_by;
            end if;
          -- Not patching audit - evolve update audit
          else
            null;
        end case;
        -- Evolve update audit and bring old values forward
        if :new.updated_on is null then
          :new.updated_on := sysdate;
        end if;
        if :new.updated_by is null then
          :new.updated_by := sys_context('USERENV','SESSION_USER');
        end if;
        if :new.created_on is null then
          :new.created_on := :old.created_on;
        end if;
        if :new.created_by is null then
          :new.created_by := :old.created_by;
        end if;
      -- Updating via SQL
      else
        case
          -- Creation audit not changed so evolve update audit
          when :new.created_on = :old.created_on and
               :new.created_by = :old.created_by then
            if :new.updated_on = :old.updated_on then
              :new.updated_on := sysdate;
            end if;
            if :new.updated_by = :old.updated_by then
              :new.updated_by := sys_context('USERENV','SESSION_USER');
            end if;
          -- Patching audit so accept what is given
          else
            null;
        end case;
    end case;
  end if;
end;
/
create or replace trigger ords_templates_trg before
  insert or update on ords_templates for each row
begin
  if inserting then
    if :new.id is null then 
      -- :new.id := ords_id_seq.nextval;  -- supports only 11g and later releases
      -- 10g support for assignment of sequenceName.nextval
      select ords_id_seq.nextval into :new.id from dual;   
    end if;
    -- Populated creation audit
    if :new.created_on is null then
      if :new.updated_on is null then
        :new.created_on := sysdate;
      else
        :new.created_on := :new.updated_on;
      end if;
    end if;
    if :new.created_by is null then
      if :new.updated_by is null then
        :new.created_by := sys_context('USERENV','SESSION_USER');
      else
        :new.created_by := :new.updated_by;
      end if;
    end if;
    -- Populated update audit
    if :new.updated_on is null then
      :new.updated_on := :new.created_on;
    end if;
    if :new.updated_by is null then
      :new.updated_by := :new.created_by;
    end if;
  else 
    case
      -- Updating via PL/SQL API
      when :new.updated_on is null or :new.updated_by is null or 
           :new.created_on is null or :new.created_by is null then
        case
          -- Creation being patched - e.g. import
          when :new.updated_on is null and :new.updated_by is null and 
               :new.created_on is not null and :new.created_by is not null then
            :new.updated_on := :new.created_on;
            :new.updated_by := :new.created_by;
          -- Audit being patched
          when :new.created_on is not null or :new.created_by is not null then
            if :new.updated_on is null then
              :new.updated_on := :old.updated_on;
            end if;
            if :new.updated_by is null then
              :new.updated_by := :old.updated_by;
            end if;
          -- Not patching audit - evolve update audit
          else
            null;
        end case;
        -- Evolve update audit and bring old values forward
        if :new.updated_on is null then
          :new.updated_on := sysdate;
        end if;
        if :new.updated_by is null then
          :new.updated_by := sys_context('USERENV','SESSION_USER');
        end if;
        if :new.created_on is null then
          :new.created_on := :old.created_on;
        end if;
        if :new.created_by is null then
          :new.created_by := :old.created_by;
        end if;
      -- Updating via SQL
      else
        case
          -- Creation audit not changed so evolve update audit
          when :new.created_on = :old.created_on and
               :new.created_by = :old.created_by then
            if :new.updated_on = :old.updated_on then
              :new.updated_on := sysdate;
            end if;
            if :new.updated_by = :old.updated_by then
              :new.updated_by := sys_context('USERENV','SESSION_USER');
            end if;
          -- Patching audit so accept what is given
          else
            null;
        end case;
    end case;
  end if;
end;
/

create or replace trigger ords_url_mappings_trg before
  insert or update on ords_url_mappings for each row
begin
  if inserting then
    if :new.id is null then 
      -- :new.id := ords_id_seq.nextval;  -- supports only 11g and later releases
      -- 10g support for assignment of sequenceName.nextval
      select ords_id_seq.nextval into :new.id from dual;   
    end if;
    -- Populated creation audit
    if :new.created_on is null then
      if :new.updated_on is null then
        :new.created_on := sysdate;
      else
        :new.created_on := :new.updated_on;
      end if;
    end if;
    if :new.created_by is null then
      if :new.updated_by is null then
        :new.created_by := sys_context('USERENV','SESSION_USER');
      else
        :new.created_by := :new.updated_by;
      end if;
    end if;
    -- Populated update audit
    if :new.updated_on is null then
      :new.updated_on := :new.created_on;
    end if;
    if :new.updated_by is null then
      :new.updated_by := :new.created_by;
    end if;
  else 
    case
      -- Updating via PL/SQL API
      when :new.updated_on is null or :new.updated_by is null or 
           :new.created_on is null or :new.created_by is null then
        case
          -- Creation being patched - e.g. import
          when :new.updated_on is null and :new.updated_by is null and 
               :new.created_on is not null and :new.created_by is not null then
            :new.updated_on := :new.created_on;
            :new.updated_by := :new.created_by;
          -- Audit being patched
          when :new.created_on is not null or :new.created_by is not null then
            if :new.updated_on is null then
              :new.updated_on := :old.updated_on;
            end if;
            if :new.updated_by is null then
              :new.updated_by := :old.updated_by;
            end if;
          -- Not patching audit - evolve update audit
          else
            null;
        end case;
        -- Evolve update audit and bring old values forward
        if :new.updated_on is null then
          :new.updated_on := sysdate;
        end if;
        if :new.updated_by is null then
          :new.updated_by := sys_context('USERENV','SESSION_USER');
        end if;
        if :new.created_on is null then
          :new.created_on := :old.created_on;
        end if;
        if :new.created_by is null then
          :new.created_by := :old.created_by;
        end if;
      -- Updating via SQL
      else
        case
          -- Creation audit not changed so evolve update audit
          when :new.created_on = :old.created_on and
               :new.created_by = :old.created_by then
            if :new.updated_on = :old.updated_on then
              :new.updated_on := sysdate;
            end if;
            if :new.updated_by = :old.updated_by then
              :new.updated_by := sys_context('USERENV','SESSION_USER');
            end if;
          -- Patching audit so accept what is given
          else
            null;
        end case;
    end case;
  end if;
end;
/

create or replace trigger sec_authenticators_trg before
  insert or update on sec_authenticators for each row
begin
  if inserting then
    if :new.id is null then 
      -- :new.id := ords_id_seq.nextval;  -- supports only 11g and later releases
      -- 10g support for assignment of sequenceName.nextval
      select ords_id_seq.nextval into :new.id from dual;   
    end if;
    -- Populated creation audit
    if :new.created_on is null then
      if :new.updated_on is null then
        :new.created_on := sysdate;
      else
        :new.created_on := :new.updated_on;
      end if;
    end if;
    if :new.created_by is null then
      if :new.updated_by is null then
        :new.created_by := sys_context('USERENV','SESSION_USER');
      else
        :new.created_by := :new.updated_by;
      end if;
    end if;
    -- Populated update audit
    if :new.updated_on is null then
      :new.updated_on := :new.created_on;
    end if;
    if :new.updated_by is null then
      :new.updated_by := :new.created_by;
    end if;
  else 
    case
      -- Updating via PL/SQL API
      when :new.updated_on is null or :new.updated_by is null or 
           :new.created_on is null or :new.created_by is null then
        case
          -- Creation being patched - e.g. import
          when :new.updated_on is null and :new.updated_by is null and 
               :new.created_on is not null and :new.created_by is not null then
            :new.updated_on := :new.created_on;
            :new.updated_by := :new.created_by;
          -- Audit being patched
          when :new.created_on is not null or :new.created_by is not null then
            if :new.updated_on is null then
              :new.updated_on := :old.updated_on;
            end if;
            if :new.updated_by is null then
              :new.updated_by := :old.updated_by;
            end if;
          -- Not patching audit - evolve update audit
          else
            null;
        end case;
        -- Evolve update audit and bring old values forward
        if :new.updated_on is null then
          :new.updated_on := sysdate;
        end if;
        if :new.updated_by is null then
          :new.updated_by := sys_context('USERENV','SESSION_USER');
        end if;
        if :new.created_on is null then
          :new.created_on := :old.created_on;
        end if;
        if :new.created_by is null then
          :new.created_by := :old.created_by;
        end if;
      -- Updating via SQL
      else
        case
          -- Creation audit not changed so evolve update audit
          when :new.created_on = :old.created_on and
               :new.created_by = :old.created_by then
            if :new.updated_on = :old.updated_on then
              :new.updated_on := sysdate;
            end if;
            if :new.updated_by = :old.updated_by then
              :new.updated_by := sys_context('USERENV','SESSION_USER');
            end if;
          -- Patching audit so accept what is given
          else
            null;
        end case;
    end case;
  end if;
end;
/
create or replace trigger sec_roles_trg before
  insert or update on sec_roles for each row
begin
  if inserting then
    if :new.id is null then 
      -- :new.id := ords_id_seq.nextval;  -- supports only 11g and later releases
      -- 10g support for assignment of sequenceName.nextval
      select ords_id_seq.nextval into :new.id from dual;   
    end if;
    -- Populated creation audit
    if :new.created_on is null then
      if :new.updated_on is null then
        :new.created_on := sysdate;
      else
        :new.created_on := :new.updated_on;
      end if;
    end if;
    if :new.created_by is null then
      if :new.updated_by is null then
        :new.created_by := sys_context('USERENV','SESSION_USER');
      else
        :new.created_by := :new.updated_by;
      end if;
    end if;
    -- Populated update audit
    if :new.updated_on is null then
      :new.updated_on := :new.created_on;
    end if;
    if :new.updated_by is null then
      :new.updated_by := :new.created_by;
    end if;
  else 
    case
      -- Updating via PL/SQL API
      when :new.updated_on is null or :new.updated_by is null or 
           :new.created_on is null or :new.created_by is null then
        case
          -- Creation being patched - e.g. import
          when :new.updated_on is null and :new.updated_by is null and 
               :new.created_on is not null and :new.created_by is not null then
            :new.updated_on := :new.created_on;
            :new.updated_by := :new.created_by;
          -- Audit being patched
          when :new.created_on is not null or :new.created_by is not null then
            if :new.updated_on is null then
              :new.updated_on := :old.updated_on;
            end if;
            if :new.updated_by is null then
              :new.updated_by := :old.updated_by;
            end if;
          -- Not patching audit - evolve update audit
          else
            null;
        end case;
        -- Evolve update audit and bring old values forward
        if :new.updated_on is null then
          :new.updated_on := sysdate;
        end if;
        if :new.updated_by is null then
          :new.updated_by := sys_context('USERENV','SESSION_USER');
        end if;
        if :new.created_on is null then
          :new.created_on := :old.created_on;
        end if;
        if :new.created_by is null then
          :new.created_by := :old.created_by;
        end if;
      -- Updating via SQL
      else
        case
          -- Creation audit not changed so evolve update audit
          when :new.created_on = :old.created_on and
               :new.created_by = :old.created_by then
            if :new.updated_on = :old.updated_on then
              :new.updated_on := sysdate;
            end if;
            if :new.updated_by = :old.updated_by then
              :new.updated_by := sys_context('USERENV','SESSION_USER');
            end if;
          -- Patching audit so accept what is given
          else
            null;
        end case;
    end case;
  end if;
end;
/
create or replace trigger sec_privileges_trg before
  insert or update on sec_privileges for each row
begin
  if inserting then
    if :new.id is null then 
      -- :new.id := ords_id_seq.nextval;  -- supports only 11g and later releases
      -- 10g support for assignment of sequenceName.nextval
      select ords_id_seq.nextval into :new.id from dual;   
    end if;
    -- Populated creation audit
    if :new.created_on is null then
      if :new.updated_on is null then
        :new.created_on := sysdate;
      else
        :new.created_on := :new.updated_on;
      end if;
    end if;
    if :new.created_by is null then
      if :new.updated_by is null then
        :new.created_by := sys_context('USERENV','SESSION_USER');
      else
        :new.created_by := :new.updated_by;
      end if;
    end if;
    -- Populated update audit
    if :new.updated_on is null then
      :new.updated_on := :new.created_on;
    end if;
    if :new.updated_by is null then
      :new.updated_by := :new.created_by;
    end if;
  else 
    case
      -- Updating via PL/SQL API
      when :new.updated_on is null or :new.updated_by is null or 
           :new.created_on is null or :new.created_by is null then
        case
          -- Creation being patched - e.g. import
          when :new.updated_on is null and :new.updated_by is null and 
               :new.created_on is not null and :new.created_by is not null then
            :new.updated_on := :new.created_on;
            :new.updated_by := :new.created_by;
          -- Audit being patched
          when :new.created_on is not null or :new.created_by is not null then
            if :new.updated_on is null then
              :new.updated_on := :old.updated_on;
            end if;
            if :new.updated_by is null then
              :new.updated_by := :old.updated_by;
            end if;
          -- Not patching audit - evolve update audit
          else
            null;
        end case;
        -- Evolve update audit and bring old values forward
        if :new.updated_on is null then
          :new.updated_on := sysdate;
        end if;
        if :new.updated_by is null then
          :new.updated_by := sys_context('USERENV','SESSION_USER');
        end if;
        if :new.created_on is null then
          :new.created_on := :old.created_on;
        end if;
        if :new.created_by is null then
          :new.created_by := :old.created_by;
        end if;
      -- Updating via SQL
      else
        case
          -- Creation audit not changed so evolve update audit
          when :new.created_on = :old.created_on and
               :new.created_by = :old.created_by then
            if :new.updated_on = :old.updated_on then
              :new.updated_on := sysdate;
            end if;
            if :new.updated_by = :old.updated_by then
              :new.updated_by := sys_context('USERENV','SESSION_USER');
            end if;
          -- Patching audit so accept what is given
          else
            null;
        end case;
    end case;
  end if;
end;
/
create or replace trigger sec_role_mappings_trg before
  insert or update on sec_role_mappings for each row
begin
  if inserting then
    if :new.id is null then 
      -- :new.id := ords_id_seq.nextval;  -- supports only 11g and later releases
      -- 10g support for assignment of sequenceName.nextval
      select ords_id_seq.nextval into :new.id from dual;   
    end if;
    -- Populated creation audit
    if :new.created_on is null then
      if :new.updated_on is null then
        :new.created_on := sysdate;
      else
        :new.created_on := :new.updated_on;
      end if;
    end if;
    if :new.created_by is null then
      if :new.updated_by is null then
        :new.created_by := sys_context('USERENV','SESSION_USER');
      else
        :new.created_by := :new.updated_by;
      end if;
    end if;
    -- Populated update audit
    if :new.updated_on is null then
      :new.updated_on := :new.created_on;
    end if;
    if :new.updated_by is null then
      :new.updated_by := :new.created_by;
    end if;
  else 
    case
      -- Updating via PL/SQL API
      when :new.updated_on is null or :new.updated_by is null or 
           :new.created_on is null or :new.created_by is null then
        case
          -- Creation being patched - e.g. import
          when :new.updated_on is null and :new.updated_by is null and 
               :new.created_on is not null and :new.created_by is not null then
            :new.updated_on := :new.created_on;
            :new.updated_by := :new.created_by;
          -- Audit being patched
          when :new.created_on is not null or :new.created_by is not null then
            if :new.updated_on is null then
              :new.updated_on := :old.updated_on;
            end if;
            if :new.updated_by is null then
              :new.updated_by := :old.updated_by;
            end if;
          -- Not patching audit - evolve update audit
          else
            null;
        end case;
        -- Evolve update audit and bring old values forward
        if :new.updated_on is null then
          :new.updated_on := sysdate;
        end if;
        if :new.updated_by is null then
          :new.updated_by := sys_context('USERENV','SESSION_USER');
        end if;
        if :new.created_on is null then
          :new.created_on := :old.created_on;
        end if;
        if :new.created_by is null then
          :new.created_by := :old.created_by;
        end if;
      -- Updating via SQL
      else
        case
          -- Creation audit not changed so evolve update audit
          when :new.created_on = :old.created_on and
               :new.created_by = :old.created_by then
            if :new.updated_on = :old.updated_on then
              :new.updated_on := sysdate;
            end if;
            if :new.updated_by = :old.updated_by then
              :new.updated_by := sys_context('USERENV','SESSION_USER');
            end if;
          -- Patching audit so accept what is given
          else
            null;
        end case;
    end case;
  end if;
end;
/
create or replace trigger sec_privilege_auths_trg before
  insert or update on sec_privilege_auths for each row
begin
  if inserting then
    if :new.id is null then 
      -- :new.id := ords_id_seq.nextval;  -- supports only 11g and later releases
      -- 10g support for assignment of sequenceName.nextval
      select ords_id_seq.nextval into :new.id from dual;   
    end if;
    -- Populated creation audit
    if :new.created_on is null then
      if :new.updated_on is null then
        :new.created_on := sysdate;
      else
        :new.created_on := :new.updated_on;
      end if;
    end if;
    if :new.created_by is null then
      if :new.updated_by is null then
        :new.created_by := sys_context('USERENV','SESSION_USER');
      else
        :new.created_by := :new.updated_by;
      end if;
    end if;
    -- Populated update audit
    if :new.updated_on is null then
      :new.updated_on := :new.created_on;
    end if;
    if :new.updated_by is null then
      :new.updated_by := :new.created_by;
    end if;
  else 
    case
      -- Updating via PL/SQL API
      when :new.updated_on is null or :new.updated_by is null or 
           :new.created_on is null or :new.created_by is null then
        case
          -- Creation being patched - e.g. import
          when :new.updated_on is null and :new.updated_by is null and 
               :new.created_on is not null and :new.created_by is not null then
            :new.updated_on := :new.created_on;
            :new.updated_by := :new.created_by;
          -- Audit being patched
          when :new.created_on is not null or :new.created_by is not null then
            if :new.updated_on is null then
              :new.updated_on := :old.updated_on;
            end if;
            if :new.updated_by is null then
              :new.updated_by := :old.updated_by;
            end if;
          -- Not patching audit - evolve update audit
          else
            null;
        end case;
        -- Evolve update audit and bring old values forward
        if :new.updated_on is null then
          :new.updated_on := sysdate;
        end if;
        if :new.updated_by is null then
          :new.updated_by := sys_context('USERENV','SESSION_USER');
        end if;
        if :new.created_on is null then
          :new.created_on := :old.created_on;
        end if;
        if :new.created_by is null then
          :new.created_by := :old.created_by;
        end if;
      -- Updating via SQL
      else
        case
          -- Creation audit not changed so evolve update audit
          when :new.created_on = :old.created_on and
               :new.created_by = :old.created_by then
            if :new.updated_on = :old.updated_on then
              :new.updated_on := sysdate;
            end if;
            if :new.updated_by = :old.updated_by then
              :new.updated_by := sys_context('USERENV','SESSION_USER');
            end if;
          -- Patching audit so accept what is given
          else
            null;
        end case;
    end case;
  end if;
end;
/
create or replace trigger sec_privilege_roles_trg before
  insert or update on sec_privilege_roles for each row
begin
  if inserting then
    if :new.id is null then 
      -- :new.id := ords_id_seq.nextval;  -- supports only 11g and later releases
      -- 10g support for assignment of sequenceName.nextval
      select ords_id_seq.nextval into :new.id from dual;   
    end if;
    -- Populated creation audit
    if :new.created_on is null then
      if :new.updated_on is null then
        :new.created_on := sysdate;
      else
        :new.created_on := :new.updated_on;
      end if;
    end if;
    if :new.created_by is null then
      if :new.updated_by is null then
        :new.created_by := sys_context('USERENV','SESSION_USER');
      else
        :new.created_by := :new.updated_by;
      end if;
    end if;
    -- Populated update audit
    if :new.updated_on is null then
      :new.updated_on := :new.created_on;
    end if;
    if :new.updated_by is null then
      :new.updated_by := :new.created_by;
    end if;
  else 
    case
      -- Updating via PL/SQL API
      when :new.updated_on is null or :new.updated_by is null or 
           :new.created_on is null or :new.created_by is null then
        case
          -- Creation being patched - e.g. import
          when :new.updated_on is null and :new.updated_by is null and 
               :new.created_on is not null and :new.created_by is not null then
            :new.updated_on := :new.created_on;
            :new.updated_by := :new.created_by;
          -- Audit being patched
          when :new.created_on is not null or :new.created_by is not null then
            if :new.updated_on is null then
              :new.updated_on := :old.updated_on;
            end if;
            if :new.updated_by is null then
              :new.updated_by := :old.updated_by;
            end if;
          -- Not patching audit - evolve update audit
          else
            null;
        end case;
        -- Evolve update audit and bring old values forward
        if :new.updated_on is null then
          :new.updated_on := sysdate;
        end if;
        if :new.updated_by is null then
          :new.updated_by := sys_context('USERENV','SESSION_USER');
        end if;
        if :new.created_on is null then
          :new.created_on := :old.created_on;
        end if;
        if :new.created_by is null then
          :new.created_by := :old.created_by;
        end if;
      -- Updating via SQL
      else
        case
          -- Creation audit not changed so evolve update audit
          when :new.created_on = :old.created_on and
               :new.created_by = :old.created_by then
            if :new.updated_on = :old.updated_on then
              :new.updated_on := sysdate;
            end if;
            if :new.updated_by = :old.updated_by then
              :new.updated_by := sys_context('USERENV','SESSION_USER');
            end if;
          -- Patching audit so accept what is given
          else
            null;
        end case;
    end case;
  end if;
end;
/
create or replace trigger sec_privilege_modules_trg before
  insert or update on sec_privilege_modules for each row
begin
  if inserting then
    if :new.id is null then 
      select ords_id_seq.nextval into :new.id from dual;   
    end if;
    -- Populated creation audit
    if :new.created_on is null then
      if :new.updated_on is null then
        :new.created_on := sysdate;
      else
        :new.created_on := :new.updated_on;
      end if;
    end if;
    if :new.created_by is null then
      if :new.updated_by is null then
        :new.created_by := sys_context('USERENV','SESSION_USER');
      else
        :new.created_by := :new.updated_by;
      end if;
    end if;
    -- Populated update audit
    if :new.updated_on is null then
      :new.updated_on := :new.created_on;
    end if;
    if :new.updated_by is null then
      :new.updated_by := :new.created_by;
    end if;
  else 
    case
      -- Updating via PL/SQL API
      when :new.updated_on is null or :new.updated_by is null or 
           :new.created_on is null or :new.created_by is null then
        case
          -- Creation being patched - e.g. import
          when :new.updated_on is null and :new.updated_by is null and 
               :new.created_on is not null and :new.created_by is not null then
            :new.updated_on := :new.created_on;
            :new.updated_by := :new.created_by;
          -- Audit being patched
          when :new.created_on is not null or :new.created_by is not null then
            if :new.updated_on is null then
              :new.updated_on := :old.updated_on;
            end if;
            if :new.updated_by is null then
              :new.updated_by := :old.updated_by;
            end if;
          -- Not patching audit - evolve update audit
          else
            null;
        end case;
        -- Evolve update audit and bring old values forward
        if :new.updated_on is null then
          :new.updated_on := sysdate;
        end if;
        if :new.updated_by is null then
          :new.updated_by := sys_context('USERENV','SESSION_USER');
        end if;
        if :new.created_on is null then
          :new.created_on := :old.created_on;
        end if;
        if :new.created_by is null then
          :new.created_by := :old.created_by;
        end if;
      -- Updating via SQL
      else
        case
          -- Creation audit not changed so evolve update audit
          when :new.created_on = :old.created_on and
               :new.created_by = :old.created_by then
            if :new.updated_on = :old.updated_on then
              :new.updated_on := sysdate;
            end if;
            if :new.updated_by = :old.updated_by then
              :new.updated_by := sys_context('USERENV','SESSION_USER');
            end if;
          -- Patching audit so accept what is given
          else
            null;
        end case;
    end case;
  end if;
end;
/
create or replace trigger sec_sessions_trg before
  insert or update on sec_sessions for each row
begin
  if inserting then
    if :new.id is null then 
      -- :new.id := ords_id_seq.nextval;  -- supports only 11g and later releases
      -- 10g support for assignment of sequenceName.nextval
      select ords_id_seq.nextval into :new.id from dual;   
    end if;
    -- Populated creation audit
    if :new.created_on is null then
      if :new.updated_on is null then
        :new.created_on := sysdate;
      else
        :new.created_on := :new.updated_on;
      end if;
    end if;
    if :new.created_by is null then
      if :new.updated_by is null then
        :new.created_by := sys_context('USERENV','SESSION_USER');
      else
        :new.created_by := :new.updated_by;
      end if;
    end if;
    -- Populated update audit
    if :new.updated_on is null then
      :new.updated_on := :new.created_on;
    end if;
    if :new.updated_by is null then
      :new.updated_by := :new.created_by;
    end if;
  else 
    case
      -- Updating via PL/SQL API
      when :new.updated_on is null or :new.updated_by is null or 
           :new.created_on is null or :new.created_by is null then
        case
          -- Creation being patched - e.g. import
          when :new.updated_on is null and :new.updated_by is null and 
               :new.created_on is not null and :new.created_by is not null then
            :new.updated_on := :new.created_on;
            :new.updated_by := :new.created_by;
          -- Audit being patched
          when :new.created_on is not null or :new.created_by is not null then
            if :new.updated_on is null then
              :new.updated_on := :old.updated_on;
            end if;
            if :new.updated_by is null then
              :new.updated_by := :old.updated_by;
            end if;
          -- Not patching audit - evolve update audit
          else
            null;
        end case;
        -- Evolve update audit and bring old values forward
        if :new.updated_on is null then
          :new.updated_on := sysdate;
        end if;
        if :new.updated_by is null then
          :new.updated_by := sys_context('USERENV','SESSION_USER');
        end if;
        if :new.created_on is null then
          :new.created_on := :old.created_on;
        end if;
        if :new.created_by is null then
          :new.created_by := :old.created_by;
        end if;
      -- Updating via SQL
      else
        case
          -- Creation audit not changed so evolve update audit
          when :new.created_on = :old.created_on and
               :new.created_by = :old.created_by then
            if :new.updated_on = :old.updated_on then
              :new.updated_on := sysdate;
            end if;
            if :new.updated_by = :old.updated_by then
              :new.updated_by := sys_context('USERENV','SESSION_USER');
            end if;
          -- Patching audit so accept what is given
          else
            null;
        end case;
    end case;
  end if;
end;
/
create or replace trigger sec_keys_trg before
  insert or update on sec_keys for each row
begin
  if inserting then
    if :new.id is null then 
      -- :new.id := ords_id_seq.nextval;  -- supports only 11g and later releases
      -- 10g support for assignment of sequenceName.nextval
      select ords_id_seq.nextval into :new.id from dual;   
    end if;
    -- Populated creation audit
    if :new.created_on is null then
      if :new.updated_on is null then
        :new.created_on := sysdate;
      else
        :new.created_on := :new.updated_on;
      end if;
    end if;
    if :new.created_by is null then
      if :new.updated_by is null then
        :new.created_by := sys_context('USERENV','SESSION_USER');
      else
        :new.created_by := :new.updated_by;
      end if;
    end if;
    -- Populated update audit
    if :new.updated_on is null then
      :new.updated_on := :new.created_on;
    end if;
    if :new.updated_by is null then
      :new.updated_by := :new.created_by;
    end if;
  else 
    case
      -- Updating via PL/SQL API
      when :new.updated_on is null or :new.updated_by is null or 
           :new.created_on is null or :new.created_by is null then
        case
          -- Creation being patched - e.g. import
          when :new.updated_on is null and :new.updated_by is null and 
               :new.created_on is not null and :new.created_by is not null then
            :new.updated_on := :new.created_on;
            :new.updated_by := :new.created_by;
          -- Audit being patched
          when :new.created_on is not null or :new.created_by is not null then
            if :new.updated_on is null then
              :new.updated_on := :old.updated_on;
            end if;
            if :new.updated_by is null then
              :new.updated_by := :old.updated_by;
            end if;
          -- Not patching audit - evolve update audit
          else
            null;
        end case;
        -- Evolve update audit and bring old values forward
        if :new.updated_on is null then
          :new.updated_on := sysdate;
        end if;
        if :new.updated_by is null then
          :new.updated_by := sys_context('USERENV','SESSION_USER');
        end if;
        if :new.created_on is null then
          :new.created_on := :old.created_on;
        end if;
        if :new.created_by is null then
          :new.created_by := :old.created_by;
        end if;
      -- Updating via SQL
      else
        case
          -- Creation audit not changed so evolve update audit
          when :new.created_on = :old.created_on and
               :new.created_by = :old.created_by then
            if :new.updated_on = :old.updated_on then
              :new.updated_on := sysdate;
            end if;
            if :new.updated_by = :old.updated_by then
              :new.updated_by := sys_context('USERENV','SESSION_USER');
            end if;
          -- Patching audit so accept what is given
          else
            null;
        end case;
    end case;
  end if;
end;
/
create or replace trigger ords_workspace_schemas_trg before
  insert or update on ords_workspace_schemas for each row
begin
  if inserting then
    if :new.id is null then 
      -- :new.id := ords_id_seq.nextval;  -- supports only 11g and later releases
      -- 10g support for assignment of sequenceName.nextval
      select ords_id_seq.nextval into :new.id from dual;   
    end if;
    -- Populated creation audit
    if :new.created_on is null then
      if :new.updated_on is null then
        :new.created_on := sysdate;
      else
        :new.created_on := :new.updated_on;
      end if;
    end if;
    if :new.created_by is null then
      if :new.updated_by is null then
        :new.created_by := sys_context('USERENV','SESSION_USER');
      else
        :new.created_by := :new.updated_by;
      end if;
    end if;
    -- Populated update audit
    if :new.updated_on is null then
      :new.updated_on := :new.created_on;
    end if;
    if :new.updated_by is null then
      :new.updated_by := :new.created_by;
    end if;
  else 
    case
      -- Updating via PL/SQL API
      when :new.updated_on is null or :new.updated_by is null or 
           :new.created_on is null or :new.created_by is null then
        case
          -- Creation being patched - e.g. import
          when :new.updated_on is null and :new.updated_by is null and 
               :new.created_on is not null and :new.created_by is not null then
            :new.updated_on := :new.created_on;
            :new.updated_by := :new.created_by;
          -- Audit being patched
          when :new.created_on is not null or :new.created_by is not null then
            if :new.updated_on is null then
              :new.updated_on := :old.updated_on;
            end if;
            if :new.updated_by is null then
              :new.updated_by := :old.updated_by;
            end if;
          -- Not patching audit - evolve update audit
          else
            null;
        end case;
        -- Evolve update audit and bring old values forward
        if :new.updated_on is null then
          :new.updated_on := sysdate;
        end if;
        if :new.updated_by is null then
          :new.updated_by := sys_context('USERENV','SESSION_USER');
        end if;
        if :new.created_on is null then
          :new.created_on := :old.created_on;
        end if;
        if :new.created_by is null then
          :new.created_by := :old.created_by;
        end if;
      -- Updating via SQL
      else
        case
          -- Creation audit not changed so evolve update audit
          when :new.created_on = :old.created_on and
               :new.created_by = :old.created_by then
            if :new.updated_on = :old.updated_on then
              :new.updated_on := sysdate;
            end if;
            if :new.updated_by = :old.updated_by then
              :new.updated_by := sys_context('USERENV','SESSION_USER');
            end if;
          -- Patching audit so accept what is given
          else
            null;
        end case;
    end case;
  end if;
end;
/
create or replace trigger sec_orig_allowed_mod_trg before
  insert or update on sec_origins_allowed_modules for each row
begin
  if inserting then
    if :new.id is null then 
      -- :new.id := ords_id_seq.nextval;  -- supports only 11g and later releases
      -- 10g support for assignment of sequenceName.nextval
      select ords_id_seq.nextval into :new.id from dual;   
    end if;
    -- Populated creation audit
    if :new.created_on is null then
      if :new.updated_on is null then
        :new.created_on := sysdate;
      else
        :new.created_on := :new.updated_on;
      end if;
    end if;
    if :new.created_by is null then
      if :new.updated_by is null then
        :new.created_by := sys_context('USERENV','SESSION_USER');
      else
        :new.created_by := :new.updated_by;
      end if;
    end if;
    -- Populated update audit
    if :new.updated_on is null then
      :new.updated_on := :new.created_on;
    end if;
    if :new.updated_by is null then
      :new.updated_by := :new.created_by;
    end if;
  else 
    case
      -- Updating via PL/SQL API
      when :new.updated_on is null or :new.updated_by is null or 
           :new.created_on is null or :new.created_by is null then
        case
          -- Creation being patched - e.g. import
          when :new.updated_on is null and :new.updated_by is null and 
               :new.created_on is not null and :new.created_by is not null then
            :new.updated_on := :new.created_on;
            :new.updated_by := :new.created_by;
          -- Audit being patched
          when :new.created_on is not null or :new.created_by is not null then
            if :new.updated_on is null then
              :new.updated_on := :old.updated_on;
            end if;
            if :new.updated_by is null then
              :new.updated_by := :old.updated_by;
            end if;
          -- Not patching audit - evolve update audit
          else
            null;
        end case;
        -- Evolve update audit and bring old values forward
        if :new.updated_on is null then
          :new.updated_on := sysdate;
        end if;
        if :new.updated_by is null then
          :new.updated_by := sys_context('USERENV','SESSION_USER');
        end if;
        if :new.created_on is null then
          :new.created_on := :old.created_on;
        end if;
        if :new.created_by is null then
          :new.created_by := :old.created_by;
        end if;
      -- Updating via SQL
      else
        case
          -- Creation audit not changed so evolve update audit
          when :new.created_on = :old.created_on and
               :new.created_by = :old.created_by then
            if :new.updated_on = :old.updated_on then
              :new.updated_on := sysdate;
            end if;
            if :new.updated_by = :old.updated_by then
              :new.updated_by := sys_context('USERENV','SESSION_USER');
            end if;
          -- Patching audit so accept what is given
          else
            null;
        end case;
    end case;
  end if;
end;
/
create or replace trigger sec_priv_maps_trg before
  insert or update on sec_privilege_mappings for each row
begin
  if inserting then
    if :new.id is null then 
      -- :new.id := ords_id_seq.nextval;  -- supports only 11g and later releases
      -- 10g support for assignment of sequenceName.nextval
      select ords_id_seq.nextval into :new.id from dual;   
    end if;
    -- Populated creation audit
    if :new.created_on is null then
      if :new.updated_on is null then
        :new.created_on := sysdate;
      else
        :new.created_on := :new.updated_on;
      end if;
    end if;
    if :new.created_by is null then
      if :new.updated_by is null then
        :new.created_by := sys_context('USERENV','SESSION_USER');
      else
        :new.created_by := :new.updated_by;
      end if;
    end if;
    -- Populated update audit
    if :new.updated_on is null then
      :new.updated_on := :new.created_on;
    end if;
    if :new.updated_by is null then
      :new.updated_by := :new.created_by;
    end if;
  else 
    case
      -- Updating via PL/SQL API
      when :new.updated_on is null or :new.updated_by is null or 
           :new.created_on is null or :new.created_by is null then
        case
          -- Creation being patched - e.g. import
          when :new.updated_on is null and :new.updated_by is null and 
               :new.created_on is not null and :new.created_by is not null then
            :new.updated_on := :new.created_on;
            :new.updated_by := :new.created_by;
          -- Audit being patched
          when :new.created_on is not null or :new.created_by is not null then
            if :new.updated_on is null then
              :new.updated_on := :old.updated_on;
            end if;
            if :new.updated_by is null then
              :new.updated_by := :old.updated_by;
            end if;
          -- Not patching audit - evolve update audit
          else
            null;
        end case;
        -- Evolve update audit and bring old values forward
        if :new.updated_on is null then
          :new.updated_on := sysdate;
        end if;
        if :new.updated_by is null then
          :new.updated_by := sys_context('USERENV','SESSION_USER');
        end if;
        if :new.created_on is null then
          :new.created_on := :old.created_on;
        end if;
        if :new.created_by is null then
          :new.created_by := :old.created_by;
        end if;
      -- Updating via SQL
      else
        case
          -- Creation audit not changed so evolve update audit
          when :new.created_on = :old.created_on and
               :new.created_by = :old.created_by then
            if :new.updated_on = :old.updated_on then
              :new.updated_on := sysdate;
            end if;
            if :new.updated_by = :old.updated_by then
              :new.updated_by := sys_context('USERENV','SESSION_USER');
            end if;
          -- Patching audit so accept what is given
          else
            null;
        end case;
    end case;
  end if;
end;
/
create or replace trigger oauth_client_roles_trg before
  insert or update on oauth_client_roles for each row
begin
  if inserting then
    if :new.id is null then 
      -- :new.id := ords_id_seq.nextval;  -- supports only 11g and later releases
      -- 10g support for assignment of sequenceName.nextval
      select ords_id_seq.nextval into :new.id from dual;   
    end if;
    -- Populated creation audit
    if :new.created_on is null then
      if :new.updated_on is null then
        :new.created_on := sysdate;
      else
        :new.created_on := :new.updated_on;
      end if;
    end if;
    if :new.created_by is null then
      if :new.updated_by is null then
        :new.created_by := sys_context('USERENV','SESSION_USER');
      else
        :new.created_by := :new.updated_by;
      end if;
    end if;
    -- Populated update audit
    if :new.updated_on is null then
      :new.updated_on := :new.created_on;
    end if;
    if :new.updated_by is null then
      :new.updated_by := :new.created_by;
    end if;
  else 
    case
      -- Updating via PL/SQL API
      when :new.updated_on is null or :new.updated_by is null or 
           :new.created_on is null or :new.created_by is null then
        case
          -- Creation being patched - e.g. import
          when :new.updated_on is null and :new.updated_by is null and 
               :new.created_on is not null and :new.created_by is not null then
            :new.updated_on := :new.created_on;
            :new.updated_by := :new.created_by;
          -- Audit being patched
          when :new.created_on is not null or :new.created_by is not null then
            if :new.updated_on is null then
              :new.updated_on := :old.updated_on;
            end if;
            if :new.updated_by is null then
              :new.updated_by := :old.updated_by;
            end if;
          -- Not patching audit - evolve update audit
          else
            null;
        end case;
        -- Evolve update audit and bring old values forward
        if :new.updated_on is null then
          :new.updated_on := sysdate;
        end if;
        if :new.updated_by is null then
          :new.updated_by := sys_context('USERENV','SESSION_USER');
        end if;
        if :new.created_on is null then
          :new.created_on := :old.created_on;
        end if;
        if :new.created_by is null then
          :new.created_by := :old.created_by;
        end if;
      -- Updating via SQL
      else
        case
          -- Creation audit not changed so evolve update audit
          when :new.created_on = :old.created_on and
               :new.created_by = :old.created_by then
            if :new.updated_on = :old.updated_on then
              :new.updated_on := sysdate;
            end if;
            if :new.updated_by = :old.updated_by then
              :new.updated_by := sys_context('USERENV','SESSION_USER');
            end if;
          -- Patching audit so accept what is given
          else
            null;
        end case;
    end case;
  end if;
end;
/


