Rem
Rem $Header: emcore/source/oracle/sysman/emdrep/sql/core/12.1.0.4/emInternalSDK/events/events_types.sql rbali_oneoff_updated/1 2025/03/14 06:41:13 rbali Exp $
Rem
Rem events_types.sql
Rem
Rem Copyright (c) 2013, 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.1.0.4/emInternalSDK/events/events_types.sql
Rem EMRU_UNIX_DELIVERABLES:
Rem emcore/source/oracle/sysman/emdrep/sql/core/12.1.0.4/emInternalSDK/events/events_types.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.sql - <one-line expansion of the name>
Rem
Rem    DESCRIPTION
Rem      <short description of component this file declares/defines>
Rem
Rem    NOTES
Rem      <other useful comments, qualifications, etc.>
Rem
Rem    MODIFIED   (MM/DD/YY)
Rem    gbafna      01/07/25 - make synonyms noneditionable
Rem    rnadidar    02/11/15 - cut over to EBR
Rem    orazoma     08/08/13 - Bug 17243136: Modified name/owner sizes for
Rem                           gc_event_source_info
Rem    orazoma     08/08/13 - Created
Rem
Rem    BEGIN SQL_FILE_METADATA 
Rem    SQL_SOURCE_FILE: emcore/source/oracle/sysman/emdrep/sql/core/12.1.0.4/emInternalSDK/events/events_types.sql 
Rem    SQL_SHIPPED_FILE: 
Rem    SQL_PHASE: 
Rem    SQL_STARTUP_MODE: NORMAL 
Rem    SQL_IGNORABLE_ERRORS: NONE 
Rem    SQL_CALLING_FILE: 
Rem    END SQL_FILE_METADATA


DECLARE
  MODULE_NAME  CONSTANT VARCHAR2(20) := 'EM_EVENT_UTIL';
  NEW_SIZE     CONSTANT NUMBER := 256;
  l_length     NUMBER := 0;
  TYPE l_dependency IS TABLE OF VARCHAR2(30);
  l_type_dependency l_dependency := l_dependency();
BEGIN
    EXECUTE IMMEDIATE 'DROP SYNONYM GC_EVENT_SOURCE_INFO';
    EXECUTE IMMEDIATE q'[select DISTINCT(NAME) FROM DBA_DEPENDENCIES 
      start with REFERENCED_NAME='GC_EVENT_SOURCE_INFO' 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
        BEGIN
         EXECUTE IMMEDIATE 'DROP SYNONYM ' || l_type_dependency(i);       
         EXCEPTION
          WHEN OTHERS THEN
          IF (SQLCODE = -1434) THEN
            CONTINUE;
          ELSE
            SYSMAN.MGMT_EMDEP_LOGGER.log_message(1, 'EBR_UPGRADE', 'Failed to Drop Synonym ' || l_type_dependency(i), 'Error : ' || SQLERRM);
            RAISE;
          END IF;
        END;
      END LOOP;
  END IF;

  BEGIN
  SELECT LENGTH INTO l_length
    FROM ALL_TYPE_ATTRS
   WHERE OWNER = 'SYSMAN_TYPES'
     AND TYPE_NAME = 'GC_EVENT_SOURCE_INFO'
     AND ATTR_NAME = 'NAME';

  IF (l_length < NEW_SIZE) THEN
     execute immediate 'ALTER SESSION SET CURRENT_SCHEMA=SYSMAN_TYPES';

     EXECUTE IMMEDIATE 'ALTER TYPE GC_EVENT_SOURCE_INFO MODIFY ATTRIBUTE NAME VARCHAR2(256) CASCADE';
     execute immediate 'create or replace noneditionable synonym SYSMAN.GC_EVENT_SOURCE_INFO for GC_EVENT_SOURCE_INFO';
     execute immediate 'ALTER SESSION SET CURRENT_SCHEMA=SYSMAN';
  END IF;

  SELECT LENGTH INTO l_length
    FROM ALL_TYPE_ATTRS
   WHERE OWNER = 'SYSMAN_TYPES'
     AND TYPE_NAME = 'GC_EVENT_SOURCE_INFO'
     AND ATTR_NAME = 'OWNER';

  IF (l_length < NEW_SIZE) THEN
     execute immediate 'ALTER SESSION SET CURRENT_SCHEMA=SYSMAN_TYPES';
     EXECUTE IMMEDIATE 'ALTER TYPE GC_EVENT_SOURCE_INFO MODIFY ATTRIBUTE OWNER VARCHAR2(256) CASCADE';
     execute immediate 'create or replace noneditionable synonym SYSMAN.GC_EVENT_SOURCE_INFO for GC_EVENT_SOURCE_INFO';
     execute immediate 'ALTER SESSION SET CURRENT_SCHEMA=SYSMAN';
  END IF;
EXCEPTION
  WHEN OTHERS THEN
    execute immediate 'ALTER SESSION SET CURRENT_SCHEMA=SYSMAN';
    MGMT_EMDEP_LOGGER.log_message(P_LOG_LEVEL => MGMT_EMDEP_LOGGER.G_LOG_LEVEL_SEVERE,
                                  P_COMPONENT_NAME => MODULE_NAME,
                                  P_MESSAGE_ID => SQLCODE,
                                  P_MESSAGE => SQLERRM);
END;

     EXECUTE IMMEDIATE 'CREATE OR REPLACE NONEDITIONABLE SYNONYM GC_EVENT_SOURCE_INFO FOR SYSMAN_TYPES.GC_EVENT_SOURCE_INFO';
  
    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;

END;
/




