Rem
Rem $Header: javavm/install/bug37273789_apply.sql /st_javavm_19.0.0.0.0ojvmru/5 2025/04/02 06:57:23 etucker Exp $
Rem
Rem bug37273789_apply.sql  
Rem
Rem Copyright (c) 2025, Oracle and/or its affiliates.
Rem
Rem    NAME
Rem      bug37273789_apply.sql - install 37273789
Rem
Rem    DESCRIPTION
Rem      Removes javax.mail.jar ( mail.jar) and activation.jar and
Rem      replaces with jakarta.mail.jar and jakarata.activation.jar.
Rem
Rem    NOTES
Rem      Required for CISA signoff.  
Rem
Rem    BEGIN SQL_FILE_METADATA
Rem    SQL_SOURCE_FILE: javavm/install/bug37273789_apply.sql
Rem    SQL_SHIPPED_FILE: javavm/install/bug37273789_apply.sql
Rem    SQL_PHASE: PATCH_POSTAPPLY
Rem    SQL_STARTUP_MODE: NORMAL
Rem    SQL_IGNORABLE_ERRORS: NONE
Rem    END SQL_FILE_METADATA
Rem
Rem    MODIFIED   (MM/DD/YY)
Rem    etucker     04/01/25 - CI #37772121 of etucker_bug-37733669 from
Rem                           main
Rem    etucker     03/07/25 - add check to JAVAVM existance
Rem    etucker     02/11/25 - 19c version
Rem
Rem set echo on
Rem set serveroutput on
@@?/rdbms/admin/sqlsessstart.sql

--
-- This will remove mail and activation classes and synonyms from SYS
--
declare 
  stat    varchar2(30);
begin
  begin
    select status into stat from dba_registry where comp_id = 'JAVAVM';
  exception when no_data_found then
    stat := 'NOT FOUND';
  end;

  if stat != 'REMOVED' and stat != 'NOT FOUND'  then

   execute immediate '
    declare 
      junk varchar2(30);
    begin
      junk := dbms_java.get_jdk_version;
    end;';

    declare
      name varchar2(128);
      cursor c is
      select  o.name from obj$ o, javasnm$ where (short(+) = o.name and nvl(longdbcs,o.name) like 'javax/mail/%')   and o.type#=29 and o.owner#=0;
    begin
      open c;
      loop
        fetch c into name;
        exit when c%NOTFOUND;
        begin
          execute immediate 'drop java class ' || 
            sys.dbms_assert.enquote_name(name, false);
          execute immediate 'drop public synonym ' ||
            sys.dbms_assert.enquote_name(name, false);
        exception when others then 
          if sqlcode not in (-942, -1432, -4043) then
            raise;
          end if;
        end; 
      end loop;
      close c;
    end;

    declare
      name varchar2(128);
      cursor c is
      select  o.name from obj$ o, javasnm$ where (short(+) = o.name and nvl(longdbcs,o.name) like 'com/sun/mail/%')   and o.type#=29 and o.owner#=0;
    begin
      open c;
      loop
        fetch c into name;
        exit when c%NOTFOUND;
        begin
          execute immediate 'drop java class ' || 
            sys.dbms_assert.enquote_name(name, false);
          execute immediate 'drop public synonym ' ||
            sys.dbms_assert.enquote_name(name, false);
        exception when others then 
          if sqlcode not in (-942, -1432, -4043) then
            raise;
          end if;
        end; 
      end loop;
      close c;
    end;

    begin
-- mail.jar
      execute immediate 'drop java resource ' ||
        sys.dbms_assert.enquote_name(
        'META-INF/javamail.default.providers', false);
      execute immediate 'drop java resource ' ||
        sys.dbms_assert.enquote_name(
        'META-INF/javamail.default.address.map', false);
      execute immediate 'drop java resource ' ||
        sys.dbms_assert.enquote_name('META-INF/javamail.charset.map', false);
      execute immediate 'drop java resource ' ||
        sys.dbms_assert.enquote_name('META-INF/mailcap', false);
-- activation.jar
      execute immediate 'drop java resource ' ||
        sys.dbms_assert.enquote_name('META-INF/mailcap.default', false);
      execute immediate 'drop java resource ' ||
        sys.dbms_assert.enquote_name('META-INF/mimetypes.default', false);
    exception when others then
      if sqlcode not in (-942, -1432, -4043) then
        raise;
      end if;
    end;

    execute immediate 'begin
      dbms_java.loadjava(''-v -force -noverify -resolve -install -synonym -grant PUBLIC jlib/jakarta.mail.jar jlib/jakarta.activation.jar'');
    end;';
  end if;
end;
/

@?/rdbms/admin/sqlsessend.sql

