Rem
Rem $Header: javavm/install/bug37273777_rollback.sql /st_javavm_19.0.0.0.0ojvmru/4 2025/04/02 06:57:23 etucker Exp $
Rem
Rem bug37273777_rollback.sql
Rem
Rem Copyright (c) 2025, Oracle and/or its affiliates.
Rem
Rem    NAME
Rem      bug37273777_rollback.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    BEGIN SQL_FILE_METADATA
Rem    SQL_SOURCE_FILE: javavm/install/bug37273777_rollback.sql
Rem    SQL_SHIPPED_FILE: javavm/install/bug37273777_rollback.sql
Rem    SQL_PHASE: PATCH_POSTROLLBACK
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    etucker     03/07/25 - add test that JAVAVM exists
Rem    etucker     01/31/25 - remove new classes and restore the old.
Rem    etucker     01/31/25 - Created
Rem
Rem set echo on
Rem set serveroutput on
@@?/rdbms/admin/sqlsessstart.sql
--
-- This will remove HTTClient 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 'HTTPClient%') 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;
    exception when others then raise;
    end;

-- load version in lib
    execute immediate 'begin
      dbms_java.loadjava(''-v -noverify -resolve -install -synonym -grant PUBLIC -resolver ((* SYS) (* PUBLIC) (* -)) lib/http_client.jar'');
   end;';
  end if;
end;
/

@?/rdbms/admin/sqlsessend.sql
 
