Rem
Rem $Header: emcore/source/oracle/sysman/emdrep/sql/core/12.2.0.0/events/events_types_upgrade.sql rbali_oneoff_updated/1 2025/03/14 06:41:13 rbali Exp $
Rem
Rem events_types_upgrade.sql
Rem
Rem Copyright (c) 2014, 2025, Oracle and/or its affiliates. 
Rem All rights reserved.

Rem BEGIN EMRU_FILE_METADATA
Rem EMRU_SOURCE_FILE:emcore/source/oracle/sysman/emdrep/sql/core/12.2.0.0/events/events_types_upgrade.sql
Rem EMRU_UNIX_DELIVERABLES:
Rem emcore/source/oracle/sysman/emdrep/sql/core/12.2.0.0/events/events_types_upgrade.sql

Rem EMRU_FILE_POSTINSTALL:<!!! enter the view based location of the executable file. If there is NONE leave as-is !!!>
Rem EMRU_GENERIC_FLAG:NONE
Rem END EMRU_FILE_METADATA

Rem
Rem    NAME
Rem      events_types_upgrade.sql
Rem
Rem    DESCRIPTION
Rem      PL/SQL type upgrade for Events
Rem
Rem    NOTES
Rem      None
Rem
Rem    MODIFIED   (MM/DD/YY)
Rem    gbafna      01/07/25 - make synonyms noneditionable
Rem    jricoir     11/10/15 - Fix bug#22164510: replaced braces by brackets in comment
Rem    sreddy      09/29/15 - fix for 21909571
Rem    rrmohana    09/11/15 - fix for 21609914
Rem    dselim      08/11/15 - Add default English description support to bug fix
Rem    dselim      05/06/15 - Bug 20983450 - Need to store event class and
Rem                           attribute default english labels in repository
Rem    rnadidar    02/11/15 - cut over to EBR
Rem    edcaball    10/16/14 - Added grouping attributes (grouping criteria)
Rem    kalchand    11/17/14 - ALTER TYPE Statement Not Supported in EBRIFICATION Schema
Rem    rrmohana    09/19/14 - Adding context_attr_ref_view under em_event_class_obj
Rem    jricoir     08/14/14 - Added created_during_blackout to
Rem                           em_inc_basic_details_rec
Rem    zeding      07/23/14 - retry during alter type of em_ev_ca_obj error 
Rem    sreddy      06/06/14 - blackout changes to em_event_obj/em_issue_obj
Rem    jbacon      06/05/14 - Add debugger statements for compilation errors
Rem    zeding      03/27/14 - PL/SQL type enhancement to the em_event_obj used 
Rem                           for event grouping and corrective action for all events.
Rem    zeding      03/27/14 - Created
Rem

DECLARE
l_sql VARCHAR2(4000);
l_created_type_names SYSMAN.MGMT_SHORT_STRING_ARRAY := SYSMAN.MGMT_SHORT_STRING_ARRAY();
TYPE l_dependency IS TABLE OF VARCHAR2(30);
l_type_dependency l_dependency := l_dependency();
MODULE_NAME CONSTANT VARCHAR2(20) := 'EM_EVENT_UPGRADE' ;
SCHEMA_SYSMAN_TYPES CONSTANT VARCHAR2(12) := 'SYSMAN_TYPES';

--
-- PURPOSE
--   Recompiles invalid dependent objects before retrying
--
PROCEDURE recompile_dependendents(p_type_name IN VARCHAR2)
IS
l_compile_obj varchar2(19);
l_compile_subobj varchar2(19);
l_compile_cmd    varchar2(256);
BEGIN
  -- Look at all of the invalid objects and log them using a debug-level logger command
  FOR invalid_obj_rec IN (SELECT * 
                            FROM all_objects 
                           WHERE status <> 'VALID'
                            AND object_name IN (SELECT name 
                                                  FROM all_dependencies 
                                                  WHERE referenced_name = p_type_name)
                            AND owner = SCHEMA_SYSMAN_TYPES)
  LOOP 
    SYSMAN.MGMT_EMDEP_LOGGER.log_message(p_log_level => SYSMAN.MGMT_EMDEP_LOGGER.G_LOG_LEVEL_DEBUG,
                                         p_component_name => MODULE_NAME,
                                         p_message_id => SQLCODE,
                                         p_message => 'Invalid objects: '  ||
                                         invalid_obj_rec.owner || ' ' ||
                                         invalid_obj_rec.object_name || ' ' ||
                                         invalid_obj_rec.object_type || ' ' ||
                                         invalid_obj_rec.status || ' ' ||
                                         to_char(invalid_obj_rec.last_ddl_time,'yyyymmdd hh24:mi:ss') );

    -- try to recompile
    IF invalid_obj_rec.object_type in ('PACKAGE', 'PACKAGE BODY', 'PROCEDURE', 'FUNCTION','TRIGGER') 
    THEN
      l_compile_obj := case invalid_obj_rec.object_type when 'PACKAGE BODY' then  'PACKAGE' else invalid_obj_rec.object_type end;
      l_compile_subobj := case invalid_obj_rec.object_type when 'PACKAGE BODY' then 'BODY' else null end;
      l_compile_cmd := 'ALTER ' || l_compile_obj || ' ' || invalid_obj_rec.owner || '.' || invalid_obj_rec.object_name || ' COMPILE ' || l_compile_subobj;
      BEGIN
        EXECUTE IMMEDIATE l_compile_cmd;
        SYSMAN.MGMT_EMDEP_LOGGER.log_message(p_log_level => SYSMAN.MGMT_EMDEP_LOGGER.G_LOG_LEVEL_DEBUG,
                                          p_component_name => MODULE_NAME,
                                          p_message_id => SQLCODE,
                                          p_message => 'RECOMPILED OBJECT : '  || l_compile_cmd);
      EXCEPTION 
        -- If there are problems recompiling the dependent objects, log a severe error and stop trying
        WHEN OTHERS THEN 
          SYSMAN.MGMT_EMDEP_LOGGER.log_message(p_log_level => SYSMAN.MGMT_EMDEP_LOGGER.G_LOG_LEVEL_SEVERE,
                                               p_component_name => MODULE_NAME,
                                               p_message_id => SQLCODE,
                                               p_message => 'ERROR: COULD NOT EXECUTE : '  || l_compile_cmd);
        RAISE;
      END;
    END IF;
  END LOOP;
END recompile_dependendents;

-- Utility for determining if max time allowed has elapsed
FUNCTION max_time_elapsed(p_type_name IN VARCHAR2,
                          p_failure1_count IN NUMBER,
                          p_failure2_count IN NUMBER, 
                          p_failure3_count IN NUMBER,
                          p_start_time IN NUMBER,
                          p_max_time_in_seconds IN NUMBER)
RETURN BOOLEAN
IS
l_elapsed_time NUMBER;
BEGIN
  l_elapsed_time := (dbms_utility.get_time -  p_start_time)/100;  

  IF l_elapsed_time >= p_max_time_in_seconds
  THEN
    -- Log an error for the failed operation
    SYSMAN.MGMT_EMDEP_LOGGER.log_message
      (p_log_level => SYSMAN.MGMT_EMDEP_LOGGER.G_LOG_LEVEL_SEVERE, 
       p_component_name => MODULE_NAME, 
       p_message_id => SQLCODE, 
       p_message => 'Failed to recover from intermittent errors while altering type: ' || 
                    p_type_name ||
                    ' [ORA-04020 count: ' || p_failure1_count ||
                    ' ][ORA-22324 count: ' || p_failure2_count || ']' ||
                    ' ][ORA-22933 count: ' || p_failure3_count || ']' ||
                    ' elapsed_time: ' || round(l_elapsed_time, 2));

    RETURN TRUE;
  END IF;

  RETURN FALSE;
END max_time_elapsed;

--
-- PURPOSE
-- internal function for events type upgrade retry
-- when error is encountered
--
PROCEDURE schema_upgrade_with_retry(p_alter_type_ddl IN VARCHAR2,
                                    p_type_name IN VARCHAR2)
IS
l_max_elapsed_time NUMBER := 900;
l_start_time NUMBER :=0;
l_elapsed_time NUMBER;
l_failure1_count NUMBER := 0;
l_failure2_count NUMBER := 0;
l_failure3_count NUMBER := 0;
deadlock_detected EXCEPTION;
compilation_error EXCEPTION;
table_error EXCEPTION;
PRAGMA EXCEPTION_INIT(deadlock_detected, -4020);
PRAGMA EXCEPTION_INIT(compilation_error,-22324);
PRAGMA EXCEPTION_INIT(table_error,-22933);
BEGIN
  l_start_time :=  DBMS_UTILITY.GET_TIME;
  LOOP
    BEGIN
      EXECUTE IMMEDIATE p_alter_type_ddl;

      -- Log a warning message if an exception occurred in the past to indicate completion of operation
      IF l_failure1_count + l_failure2_count + l_failure3_count > 0
      THEN
        l_elapsed_time := (dbms_utility.get_time -  l_start_time)/100;  

        SYSMAN.MGMT_EMDEP_LOGGER.log_message
            (p_log_level => SYSMAN.MGMT_EMDEP_LOGGER.G_LOG_LEVEL_WARNING, 
             p_component_name => MODULE_NAME, 
             p_message_id => SQLCODE, 
             p_message => 'Recovered from intermittent errors while altering type: ' || p_type_name ||
                          ' [ORA-04020 count: ' || l_failure1_count ||
                          ' ][ORA-22324 count: ' || l_failure2_count || ']' ||
                          ' ][ORA-22933 count: ' || l_failure3_count || ']' ||
                          ' elapsed_time: ' || round(l_elapsed_time, 2));
      END IF;

      -- If the code reaches here, type changes have been completed, so exit the loop.
      EXIT;

    EXCEPTION 
      --
      -- Rarely ORA-04020 is raised when executing the 'alter type' statements.
      -- pid#7144356 has tracked this issue.
      --
      WHEN deadlock_detected THEN

        -- Log a warning message for the first exception raised
        IF l_failure1_count = 0
        THEN
          SYSMAN.MGMT_EMDEP_LOGGER.log_message
              (p_log_level => SYSMAN.MGMT_EMDEP_LOGGER.G_LOG_LEVEL_WARNING, 
               p_component_name => MODULE_NAME, 
               p_message_id => SQLCODE, 
               p_message => 'Encountered ORA-04020 exception, while altering type: ' || p_type_name || '. Will try to recover by retrying the operation periodically for a short period of time.') ;
        END IF;

        l_failure1_count := l_failure1_count + 1;
  
        IF max_time_elapsed(p_type_name, l_failure1_count, l_failure2_count, l_failure3_count,
                            l_start_time, l_max_elapsed_time)
        THEN
          RAISE;
        END IF;

      -- has not been compiled properly.  Try to recompile those dependent objects before retrying the original TYPE alteration.
      WHEN compilation_error THEN

        -- Log a warning message for the first exception raised
        IF l_failure2_count = 0
        THEN
          SYSMAN.MGMT_EMDEP_LOGGER.log_message
              (p_log_level => SYSMAN.MGMT_EMDEP_LOGGER.G_LOG_LEVEL_WARNING,
               p_component_name => MODULE_NAME,
               p_message_id => SQLCODE,
               p_message => SQLERRM ||' Encountered ORA-22324 exception, while altering type: ' || p_type_name || '. Will try to recover by retrying the operation periodically for a short period of time.') ;
        END IF;

        l_failure2_count := l_failure2_count + 1;

        recompile_dependendents(p_type_name);

        IF max_time_elapsed(p_type_name, l_failure1_count, l_failure2_count, l_failure3_count,
                            l_start_time, l_max_elapsed_time)
        THEN
          RAISE;
        END IF;

      -- has not been compiled properly.  Try to recompile those dependent objects before retrying the original TYPE alteration.
      WHEN table_error THEN

        -- Log a warning message for the first exception raised
        IF l_failure3_count = 0
        THEN
          SYSMAN.MGMT_EMDEP_LOGGER.log_message
              (p_log_level => SYSMAN.MGMT_EMDEP_LOGGER.G_LOG_LEVEL_WARNING,
               p_component_name => MODULE_NAME,
               p_message_id => SQLCODE,
               p_message => SQLERRM ||' Encountered ORA-22933 exception, while altering type: ' || p_type_name || '. Will try to recover by retrying the operation periodically for a short period of time.') ;
        END IF;

        l_failure3_count := l_failure3_count + 1;

        recompile_dependendents(p_type_name);

        IF max_time_elapsed(p_type_name, l_failure1_count, l_failure2_count, l_failure3_count,
                            l_start_time, l_max_elapsed_time)
        THEN
          RAISE;
        END IF;

      -- NOTE: Ensure that other exceptions are raised, per recommendation from schema review team.
      -- PLSQL engine intermittently fails to raise other exceptions without the explict the block below.
      WHEN OTHERS THEN
        RAISE;
    END;
  END LOOP;
END schema_upgrade_with_retry ;

PROCEDURE drop_synonym(p_synonym IN VARCHAR2)
IS
BEGIN
  EXECUTE IMMEDIATE 'DROP SYNONYM ' || p_synonym;
EXCEPTION WHEN OTHERS THEN 
  IF (SQLCODE = -1434) 
  THEN
    NULL;
  ELSE
    SYSMAN.MGMT_EMDEP_LOGGER.log_message(1, 'EBR_UPGRADE', 'Failed to Drop Synonym ' || p_synonym, 'Error : ' || SQLERRM);
    RAISE;
  END IF;
END drop_synonym;

BEGIN
  EXECUTE IMMEDIATE 'ALTER SESSION SET CURRENT_SCHEMA=&EM_REPOS_USER';

  -- Include ca_requested_date , ca_reference_id , reference_source_type as 12.2 project 
  -- CA for all events

  -- TYPE DEPENDENCY SYNONYMS DROP and RE-CREATE

  drop_synonym('EM_EV_CA_OBJ');
  EXECUTE IMMEDIATE q'[select DISTINCT(NAME) FROM DBA_DEPENDENCIES 
    start with REFERENCED_NAME='EM_EV_CA_OBJ' and TYPE='TYPE' CONNECT BY NOCYCLE PRIOR NAME = REFERENCED_NAME 
      and TYPE = 'TYPE']' BULK COLLECT INTO l_type_dependency;

  IF l_type_dependency.COUNT > 0 THEN
    FOR i IN l_type_dependency.first .. l_type_dependency.last LOOP
      drop_synonym(l_type_dependency(i));
    END LOOP;
  END IF;
 

  l_sql := 'ALTER TYPE SYSMAN_TYPES.em_ev_ca_obj 
              ADD ATTRIBUTE (ca_reference_id RAW(16), 
                             ca_update_date DATE,
                             reference_source_type NUMBER(2)) CASCADE NOT INCLUDING TABLE DATA'; 
  schema_upgrade_with_retry(p_alter_type_ddl => l_sql, p_type_name => 'EM_EV_CA_OBJ');

  EXECUTE IMMEDIATE 'CREATE OR REPLACE NONEDITIONABLE SYNONYM EM_EV_CA_OBJ FOR SYSMAN_TYPES.EM_EV_CA_OBJ';

  FOR i IN l_type_dependency.first .. l_type_dependency.last LOOP
    EXECUTE IMMEDIATE 'CREATE OR REPLACE NONEDITIONABLE SYNONYM ' || l_type_dependency(i) || ' FOR SYSMAN_TYPES.' || l_type_dependency(i);
  END LOOP;

  EXECUTE IMMEDIATE 'ALTER SESSION SET CURRENT_SCHEMA=SYSMAN_TYPES';
  
  l_sql := 'CREATE OR REPLACE TYPE em_ev_ca_array AS VARRAY(200) OF SYSMAN_TYPES.EM_EV_CA_OBJ';
  EXECUTE IMMEDIATE l_sql;
  EXECUTE IMMEDIATE 'GRANT EXECUTE ON SYSMAN_TYPES.EM_EV_CA_ARRAY TO SYSMAN WITH GRANT OPTION';
  EXECUTE IMMEDIATE 'ALTER SESSION SET CURRENT_SCHEMA=SYSMAN';

  -- TYPE DEPENDENCY SYNONYMS DROP and RE-CREATE

  drop_synonym('EM_EVENT_OBJ');
  EXECUTE IMMEDIATE q'[select DISTINCT(NAME) FROM DBA_DEPENDENCIES 
    start with REFERENCED_NAME='EM_EVENT_OBJ' and TYPE='TYPE' CONNECT BY NOCYCLE PRIOR NAME = REFERENCED_NAME
      and TYPE = 'TYPE']' BULK COLLECT INTO l_type_dependency;

  IF l_type_dependency.COUNT > 0 THEN
    FOR i IN l_type_dependency.first .. l_type_dependency.last LOOP
      drop_synonym(l_type_dependency(i));
    END LOOP;
  END IF;

   -- 1) Add an additional grouping ID field to the event_obj
   -- This field is applicable to event that matches an event rule for grouping.
   -- grouping ID is constructed using the hash code of the string concatenation of rule id and the respective specified grouping action value, e.g. event_name, category value
   -- 2) Add CA array info to the event
   -- 3) CREATED_DURING_BLACKOUT: 
   -- 1 => event created during blackout; 0 => otherwise
   -- It will be set to 1 for events that are published during blackout
  l_sql := 'ALTER TYPE SYSMAN_TYPES.em_event_obj ADD ATTRIBUTE (grouping_signature_id RAW(16), 
                                                   ca_job_info_array SYSMAN_TYPES.EM_EV_CA_ARRAY,
                                                    CREATED_DURING_BLACKOUT NUMBER(1)
                                                  ) CASCADE NOT INCLUDING TABLE DATA';
  schema_upgrade_with_retry(p_alter_type_ddl => l_sql, p_type_name => 'EM_EVENT_OBJ');

  EXECUTE IMMEDIATE 'CREATE OR REPLACE NONEDITIONABLE SYNONYM EM_EVENT_OBJ FOR SYSMAN_TYPES.EM_EVENT_OBJ';

  FOR i IN l_type_dependency.first .. l_type_dependency.last LOOP
    EXECUTE IMMEDIATE 'CREATE OR REPLACE NONEDITIONABLE SYNONYM ' || l_type_dependency(i) || ' FOR SYSMAN_TYPES.' || l_type_dependency(i);
  END LOOP;

  drop_synonym('EM_ISSUE_OBJ');
  EXECUTE IMMEDIATE q'[select DISTINCT(NAME) FROM DBA_DEPENDENCIES 
    start with REFERENCED_NAME='EM_ISSUE_OBJ' and TYPE='TYPE' CONNECT BY NOCYCLE PRIOR NAME = REFERENCED_NAME 
      and TYPE = 'TYPE']' BULK COLLECT INTO l_type_dependency;

  IF l_type_dependency.COUNT > 0 THEN
    FOR i IN l_type_dependency.first .. l_type_dependency.last LOOP
      drop_synonym(l_type_dependency(i));
    END LOOP;
  END IF;

  -- Add LAST_PROCESSED_SEVERITY to EM_ISSUE_OBJ: 
  -- It tracks the last severity that was processed through rule engine for given issue.
  l_sql := 'ALTER TYPE SYSMAN_TYPES.EM_ISSUE_OBJ ADD ATTRIBUTE (
              LAST_PROCESSED_SEVERITY NUMBER(2)
            ) CASCADE NOT INCLUDING TABLE DATA';
  schema_upgrade_with_retry(p_alter_type_ddl => l_sql, p_type_name => 'EM_ISSUE_OBJ');

  EXECUTE IMMEDIATE 'CREATE OR REPLACE NONEDITIONABLE SYNONYM EM_ISSUE_OBJ FOR SYSMAN_TYPES.EM_ISSUE_OBJ';

  FOR i IN l_type_dependency.first .. l_type_dependency.last LOOP
    EXECUTE IMMEDIATE 'CREATE OR REPLACE NONEDITIONABLE SYNONYM ' || l_type_dependency(i) || ' FOR SYSMAN_TYPES.' || l_type_dependency(i);
  END LOOP;

  drop_synonym('EM_INCIDENT_OBJ');
  EXECUTE IMMEDIATE q'[select DISTINCT(NAME) FROM DBA_DEPENDENCIES 
    start with REFERENCED_NAME='EM_INCIDENT_OBJ' and TYPE='TYPE' CONNECT BY NOCYCLE PRIOR NAME = REFERENCED_NAME 
      and TYPE = 'TYPE']' BULK COLLECT INTO l_type_dependency;

  IF l_type_dependency.COUNT > 0 THEN
    FOR i IN l_type_dependency.first .. l_type_dependency.last LOOP
      drop_synonym(l_type_dependency(i));
    END LOOP;
  END IF;

   -- Add grouping criteria and its values to the incident_obj
   -- This fields are applicable to an incident which is created by event grouping rule.
   -- grouping ID is constructed using the hash code of the string concatenation of rule id and the respective specified grouping action value, e.g. event_name, category value
   -- Grouping attributes contains the grouping criteria and its values by which the events are grouped. They are used in incident details page.
   -- Grouping attributes e.g. 
   -- GROUPING_ATTRS_NAME_ARRAY  [event_name, target_name]
   -- GROUPING_ATTRS_VALUE_ARRAY [theEventName, my.host.com]
  l_sql := 'ALTER TYPE SYSMAN_TYPES.EM_INCIDENT_OBJ 
              ADD ATTRIBUTE (GROUPING_SIGNATURE_ID RAW(16),
                             GROUPING_ATTRIBUTES GC_EVENT_PAIR_ARRAY) CASCADE NOT INCLUDING TABLE DATA';
  schema_upgrade_with_retry(p_alter_type_ddl => l_sql, p_type_name => 'EM_INCIDENT_OBJ');

   -- Add CREATED_DURING_BLACKOUT to EM_INC_BASIC_DETAILS_REC: 
   -- 1 => event created during blackout; 0 => otherwise
   -- It will be set to 1 for events that are published during blackout
   -- l_sql := 'ALTER TYPE EM_INC_BASIC_DETAILS_REC ADD ATTRIBUTE (
   --           CREATED_DURING_BLACKOUT NUMBER(1)
   --         ) CASCADE';

  EXECUTE IMMEDIATE 'CREATE OR REPLACE NONEDITIONABLE SYNONYM EM_INCIDENT_OBJ FOR SYSMAN_TYPES.EM_INCIDENT_OBJ';

  FOR i IN l_type_dependency.first .. l_type_dependency.last LOOP
    EXECUTE IMMEDIATE 'CREATE OR REPLACE NONEDITIONABLE SYNONYM ' || l_type_dependency(i) || ' FOR SYSMAN_TYPES.' || l_type_dependency(i);
  END LOOP;

  EXECUTE IMMEDIATE 'DROP TYPE EM_INC_BASIC_DETAILS_REC FORCE';

  l_sql := q'[CREATE OR REPLACE TYPE "SYSMAN"."EM_INC_BASIC_DETAILS_REC" IS OBJECT (
  incident_id       RAW(16),
  severity          NUMBER(2),
  target_guid       RAW(16),
  target_name       VARCHAR2(256),
  target_type       VARCHAR2(64),
  category          NUMBER(12),
  creation_date     DATE,
  last_upd_date     DATE,
  summary_msg       VARCHAR2(4000),
  summary_nlsid     VARCHAR2(64),
  summary_nlsparams VARCHAR2(4000),
  summary_resbundle VARCHAR2(512),
  incident_tz       VARCHAR2(64),
  event_seq_id      RAW(16),
  incident_num      NUMBER(16),
  CREATED_DURING_BLACKOUT NUMBER(1)
  )]';
  
  schema_upgrade_with_retry(p_alter_type_ddl => l_sql, p_type_name => 'EM_INC_BASIC_DETAILS_REC');
end;
/

--ALTER TYPE em_event_class_obj DROP CONSTRUCTOR FUNCTION em_event_class_obj
--  (p_event_class             IN VARCHAR2,
--   p_version                 IN NUMBER,
--   p_plugin_id               IN VARCHAR2,
--   p_nlsid                   IN VARCHAR2,
--   p_desc_nlsid              IN VARCHAR2 DEFAULT NULL,
--   p_target_aware            IN NUMBER DEFAULT 1,
--   p_source_object_type      IN VARCHAR2,
--   p_resource_bundle         IN VARCHAR2,
--   p_table_name              IN VARCHAR2,
--   p_ref_attr_source         IN VARCHAR2 DEFAULT NULL,
--   p_clear_event_source      IN VARCHAR2 DEFAULT NULL,
--   p_attr_list               IN em_event_attr_array,
--   p_valid_severity_levels   IN mgmt_integer_array,
--   p_xml_content             IN CLOB  DEFAULT NULL
--  )
-- RETURN SELF AS RESULT CASCADE;

rem PURPOSE
rem New optional column added for storing database view name provided by event type integrator to allow event system to retrieve the event context attribute details.

--ALTER TYPE em_event_class_obj ADD ATTRIBUTE (context_attr_ref_view VARCHAR2(30)) CASCADE;

--ALTER TYPE em_event_class_obj ADD CONSTRUCTOR FUNCTION em_event_class_obj
--  (p_event_class             IN VARCHAR2,
--   p_version                 IN NUMBER,
--   p_plugin_id               IN VARCHAR2,
--   p_nlsid                   IN VARCHAR2,
--   p_desc_nlsid              IN VARCHAR2 DEFAULT NULL,
--   p_target_aware            IN NUMBER DEFAULT 1,
--   p_source_object_type      IN VARCHAR2,
--   p_resource_bundle         IN VARCHAR2,
--   p_table_name              IN VARCHAR2,
--   p_ref_attr_source         IN VARCHAR2 DEFAULT NULL,
--   p_clear_event_source      IN VARCHAR2 DEFAULT NULL,
--   p_context_attr_ref_view   IN VARCHAR2 DEFAULT NULL,
--   p_attr_list               IN em_event_attr_array,
--   p_valid_severity_levels   IN mgmt_integer_array,
--   p_xml_content             IN CLOB  DEFAULT NULL
--  )
-- RETURN SELF AS RESULT CASCADE;

Rem EBRFICATION does not support ALTER TYPE statements

CREATE OR REPLACE TYPE em_event_attr_obj FORCE AS OBJECT
(name                  VARCHAR2(30),
 nlsid                 VARCHAR2(64),
 data_type             VARCHAR2(10),
 attr_type             VARCHAR2(10),
 desc_nlsid            VARCHAR2(64),
 description           VARCHAR2(512),
 label                 VARCHAR2(256),
 is_translated         NUMBER(1),
 is_referenced         NUMBER(1),
 signature_order       NUMBER(3),
 rules_order           NUMBER(3),
 apply_rules_on_change NUMBER(1),
 notif_order           NUMBER(3),
 CONSTRUCTOR FUNCTION em_event_attr_obj
 (p_name                  VARCHAR2,
  p_nlsid                 VARCHAR2 DEFAULT NULL,
  p_data_type             VARCHAR2 DEFAULT 'STRING',
  p_attr_type             VARCHAR2 DEFAULT 'CLASS',
  p_desc_nlsid            VARCHAR2 DEFAULT NULL,
  p_description           VARCHAR2 DEFAULT NULL,
  p_label                 VARCHAR2 DEFAULT NULL,
  p_is_translated         NUMBER DEFAULT 0,
  p_is_referenced         NUMBER DEFAULT 0,
  p_signature_order       NUMBER DEFAULT 0,
  p_rules_order           NUMBER DEFAULT 0,
  p_apply_rules_on_change NUMBER DEFAULT 0,
  p_notif_order           NUMBER DEFAULT 0
 )
 RETURN SELF AS RESULT
)
/

DROP TYPE EM_EVENT_CLASS_OBJ FORCE;

CREATE OR REPLACE TYPE EM_EVENT_CLASS_OBJ AS OBJECT
(event_class            VARCHAR2(20),
 version                NUMBER,
 plugin_id              VARCHAR2(64),
 nlsid                  VARCHAR2(64),
 desc_nlsid             VARCHAR2(64),
 description            VARCHAR2(512),
 label                  VARCHAR2(256),
 target_aware           NUMBER,
 source_object_type     VARCHAR2(30),
 resource_bundle        VARCHAR2(512),
 table_name             VARCHAR2(30),
 ref_attr_source        VARCHAR2(512),
 attr_list              em_event_attr_array,
 valid_severity_levels  mgmt_integer_array,
 xml_content            CLOB,
 clear_event_source     VARCHAR2(128),
 context_attr_ref_view VARCHAR2(30),
 CONSTRUCTOR FUNCTION em_event_class_obj
  (p_event_class             IN VARCHAR2,
   p_version                 IN NUMBER,
   p_plugin_id               IN VARCHAR2,
   p_nlsid                   IN VARCHAR2,
   p_desc_nlsid              IN VARCHAR2 DEFAULT NULL,
   p_description             IN VARCHAR2 DEFAULT NULL,
   p_label                   IN VARCHAR2 DEFAULT NULL,
   p_target_aware            IN NUMBER DEFAULT 1,
   p_source_object_type      IN VARCHAR2,
   p_resource_bundle         IN VARCHAR2,
   p_table_name              IN VARCHAR2,
   p_ref_attr_source         IN VARCHAR2 DEFAULT NULL,
   p_clear_event_source      IN VARCHAR2 DEFAULT NULL,
   p_context_attr_ref_view   IN VARCHAR2 DEFAULT NULL,
   p_attr_list               IN em_event_attr_array,
   p_valid_severity_levels   IN mgmt_integer_array,
   p_xml_content             IN CLOB  DEFAULT NULL
  )
  RETURN SELF AS RESULT
);
/



