MINI MINI MANI MO

Path : /opt/oracle/product/18c/dbhomeXE/javavm/install/
File Upload :
Current File : //opt/oracle/product/18c/dbhomeXE/javavm/install/jvmrm.sql

Rem    BEGIN SQL_FILE_METADATA
Rem    SQL_SOURCE_FILE: javavm/install/jvmrm.sql
Rem    SQL_SHIPPED_FILE: javavm/install/jvmrm.sql
Rem    SQL_PHASE: JVMRM
Rem    SQL_STARTUP_MODE: NORMAL
Rem    SQL_IGNORABLE_ERRORS: NONE
Rem    END SQL_FILE_METADATA



-- Remove some portion of the Java related data dictionary objects

-- This script must be run as a subscript of a script which sets the
-- variable jvmrmaction.
-- Possible values are
--  FULL_REMOVAL:        remove all java related objects
--  GRADE_REMOVAL:       remove java related objects as appropriate during
--                       upgrade or downgrade when running in the 
--                       up/downgrade from release
--  NONE (or null):      do nothing, except in the case where :jvmdownto
--                       is set in which case forms involving
--                       initjvmaux.compare_releases may be executed
--                       jvmrmaction will be null in these cases

-- This script can not function properly in SVRMGR.  The following 
-- lines are intended to abort the script if it is being run with
-- SVRMGR, but will be interpreted simply as remarks by SQLPLUS.
rem -
set stoponerror on
rem -
jvmrm.sql must be run with SQLPLUS, not SVRMGRL

-- This script may only be called as a subscript.  
-- Otherwise, jvmudaction will be undefined and the following will 
-- abort the script.
whenever sqlerror exit;

/*
/*
##  If the following sequence results in
##   SP2-0552: Bind variable "JVMUDACTION" not declared.
##  followed by
##   ORA-01476: divisor is equal to zero
##  thereby causing SQLPLUS to exit, it is because this script is 
##  not being run as a subscript, as required.
*/
variable scratch varchar2(30)
execute :scratch := :jvmudaction; :scratch := 'not null';
declare z number := 0; begin if :scratch is null then z := 1/z;end if;end;
/

whenever sqlerror continue;

select initjvmaux.registrystatus,:jvmudaction,:jvmrmaction from dual;

begin
  if :jvmrmaction = 'FULL_REMOVAL' then
    dbms_registry.removing('JAVAVM');
    initjvmaux.startaction('UNLOAD');
  end if;
  if :jvmudaction = 'DOWNGRADE' and
     initjvmaux.registrystatus = 'LOADED' and 
     initjvmaux.startstep('SET_REGISTRY_GRADING') then
    dbms_registry.downgrading('JAVAVM');
    initjvmaux.endstep;
  end if;
end;
/

begin if :jvmrmaction = 'FULL_REMOVAL' then

if initjvmaux.startstep('RMJVM_REMOVE_ROLES') then
--
initjvmaux.drp('drop role javauserpriv');
initjvmaux.drp('drop role javaidpriv');
initjvmaux.drp('drop role javasyspriv');
initjvmaux.drp('drop role javadebugpriv');
initjvmaux.drp('drop role ejbclient');

--
initjvmaux.drp('drop view javasnm');
initjvmaux.drp('drop public synonym javasnm');

initjvmaux.endstep; end if;
end if;end;
/

begin if :jvmrmaction = 'FULL_REMOVAL' or :jvmrmaction = 'GRADE_REMOVAL' then

if initjvmaux.startstep('RMJVM_REMOVE_GET_ERROR') then

--
initjvmaux.drp('drop package get_error$');
initjvmaux.drp('drop public synonym get_error$');

-- The following four can go away in 12.2 when upgrade from 10.2 is no longer
initjvmaux.drp('drop trigger AURORA$SERVER$SHUTDOWN');
initjvmaux.drp('drop trigger AURORA$SERVER$STARTUP');
initjvmaux.drp('drop table aurora$startup$classes$');
initjvmaux.drp('drop table aurora$shutdown$classes$');


-- initsql
initjvmaux.drp('drop package sqljutl');


-- Remove any occurrences of LOADLOBS package
DECLARE 
max_iterations number;
loop_count number;
iterations number;
drop_statement varchar2(50);
my_err number;
cursor C1 is select unique 'DROP PACKAGE ' || u.name || '.LOADLOBS' 
             into drop_statement from obj$ o, user$ u where
             (o.name = 'LOADLOBS' and 
             (o.type# = 9 or o.type# = 11)) and 
             u.user#=o.owner#;
BEGIN
  max_iterations := 10000000;
  select count(*) into iterations from obj$ o, user$ u where
        (o.name = 'LOADLOBS' and (o.type# = 9 or o.type# = 11)) and
        u.user#=o.owner#;
  LOOP
    exit when iterations=0 or iterations >= max_iterations;
    max_iterations := iterations;
    loop_count := 0;
    open C1;
    LOOP -- outer loop for snap shot checking.
      BEGIN
        fetch c1 into drop_statement;
        exit when C1%notfound or loop_count > iterations;
      EXCEPTION
        when others then
          my_err := SQLCODE;
          if my_err = -1555 then 
            exit;
          else
            raise;
          end if;
       END;
     initjvmaux.drp(drop_statement);
     loop_count := loop_count + 1;    
   END LOOP;--inner
close C1;
commit;
end LOOP; --outer
end;--LOADLOBS

initjvmaux.endstep; end if;

end if;end;
/

@@jvmrmcat
@@jvmrmdbj
@@jvmrmsec
@@jvmrmxa
@@jvmrmprefs

VARIABLE jvmexp VARCHAR2(32)
COLUMN :jvmexp NEW_VALUE jvm_exp_file NOPRINT;

begin
if :jvmrmaction = 'DOWNGRADE' and
   initjvmaux.compare_releases(:jvmdownto, '12.2') = 'FIRST IS OLDER' then
  execute immediate 'alter table javajar$ modify (name varchar2(30))';
  execute immediate 'alter table javajarobjects$ modify (jarname varchar2(30), objname varchar2(40))';
  execute immediate 'alter table javanegdeps$ modify (name varchar2(30), uname varchar2(30))';
  -- prior to 12.1: "grant select ...". Starting from 12.2: grant read
  execute immediate 'revoke read on USER_JAVA_POLICY from PUBLIC';
  execute immediate 'revoke read on javasnm from PUBLIC';
  execute immediate 'grant select on USER_JAVA_POLICY to PUBLIC with grant option';
  execute immediate 'grant select on javasnm to public';
  execute immediate 'drop role dbjavascript';
  :jvmexp := 'jvm_exp_pre_122.sql';
--
-- This will remove HTTClient classes and synonyms from SYS
--
  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;
      initjvmaux.drop_sys_class(name);
    end loop;
    close c;
  exception when others then raise;
  end;

  if initjvmaux.compare_releases(:jvmdownto, '11.2') = 'FIRST IS NEWER' then
    execute immediate 'alter table OJVMSYS.ojds$inode$ modify owner varchar2(30)';
    execute immediate 'alter table OJVMSYS.ojds$permissions$ modify schema varchar2(30)';
  end if;
else
  :jvmexp := 'jvmempty.sql';
end if;
end;
/

SELECT :jvmexp FROM DUAL;
@@&jvm_exp_file

begin if :jvmrmaction = 'FULL_REMOVAL' then
initjvmaux.drp('drop package sqljutl2');
initjvmaux.drp('drop package utl_dbws');
initjvmaux.drp('drop package jvmfcb');
initjvmaux.drp('drop package dbms_jvm_exp_perms');
initjvmaux.drp('drop public synonym dbms_jvm_exp_perms');
initjvmaux.drp('drop table javajar$');
initjvmaux.drp('drop table javajarobjects$');
initjvmaux.drp('drop table java$jvm$runtime$parameters');
initjvmaux.drp('drop table java$mc$');
initjvmaux.drp('drop table java$compiler$options');
initjvmaux.drp('drop table java$jvm$rjbc');
initjvmaux.drp('drop package jvmrjbc');
initjvmaux.drp('drop table java$jvm$system$property$defs');
initjvmaux.drp('drop role jmxserver');
initjvmaux.drp('drop role dbjavascript');
end if; end;
/

begin
  if :jvmrmaction = 'FULL_REMOVAL' or
     (:jvmrmaction = 'DOWNGRADE' and
      initjvmaux.compare_releases(:jvmdownto, '12.2') = 'FIRST IS OLDER')
  then
    execute immediate 'drop table javanamestatus$';
    execute immediate 'drop table javasnm_tmp$';
  end if;
end;
/

begin
-- Drop C/UJS status table on downgrade to below 12.2.0.1.
-- For downgrade to 12.2.0.1, where the structure of the table
-- is different from that in higher releases, drop and re-create
-- the table with the older structure and preserve the contents.
-- The table is present only in the root, in case of CDB.
  if :jvmrmaction = 'FULL_REMOVAL' or
     (:jvmrmaction = 'DOWNGRADE' and
      initjvmaux.compare_releases(:jvmdownto, '12.2.0.1') = 'FIRST IS OLDER')
  then
    execute immediate 'drop table java$jox$cujs$status$';
  elsif :jvmrmaction = 'DOWNGRADE' and
        substr(:jvmdownto, 1, 8) = '12.2.0.1'
  then
    execute immediate 'create table javavm_cujs_tmp as select timestamp, conid, action, phase, phase_desc, release from java$jox$cujs$status$';
    execute immediate 'drop table java$jox$cujs$status$';
    execute immediate 'create table java$jox$cujs$status$ as select * from javavm_cujs_tmp';
    execute immediate 'drop table javavm_cujs_tmp';
  end if;
exception
when others then
  if sqlcode not in (-942) then
    raise;
  end if;
end;
/

-- revert the OJVMSYS to old method. If this is run in the pdb before
-- the root then it will not make the change. it will fail with 
-- ORA-65050.

declare
  acct_string varchar2(32);
begin
  if :jvmrmaction = 'DOWNGRADE' and
      initjvmaux.compare_releases(:jvmdownto, '12.2') = 'FIRST IS OLDER'
  then
    select account_status into acct_string from dba_users where username='OJVMSYS';
    if instr(acct_string,'EXPIRED',1,1) = 0 then
       execute immediate 'alter user OJVMSYS identified by xxx';
       execute immediate 'alter user OJVMSYS account lock password expire';
    end if;
  end if;
exception
when others then
if sqlcode not in (-65050) then raise; end if;
end;
/

       



begin if :jvmrmaction = 'FULL_REMOVAL'
then
  initjvmaux.drp('drop role dbhadoop');
else
  if (:jvmrmaction = 'DOWNGRADE' and
      initjvmaux.compare_releases(:jvmdownto, '12.1') = 'FIRST IS OLDER')
  then
    if initjvmaux.startstep('RMJVM_REMOVE_HADOOP') then
      initjvmaux.exec('call javavm_sys.uninstall_dbhadoop()');
      initjvmaux.endstep;
    end if;
  end if;
end if; end;
/

begin if :jvmrmaction = 'FULL_REMOVAL' or
         (:jvmrmaction = 'DOWNGRADE' and
          initjvmaux.compare_releases(:jvmdownto, '12.1') = 'FIRST IS OLDER')
then
initjvmaux.drp('declare trash varchar2(100):=dbms_java.endsession_and_related_state;begin null;end;');
initjvmaux.drp('drop user ojvmsys cascade');
initjvmaux.drp('declare trash varchar2(100):=dbms_java.endsession_and_related_state;begin null;end;');
initjvmaux.drp('drop java resource "lib/security/java.security.alt"');
initjvmaux.drp('drop synonym ojds$node_number$');
initjvmaux.drp('drop synonym ojds$bindings$');
initjvmaux.drp('drop synonym ojds$inode$');
initjvmaux.drp('drop synonym ojds$attributes$');
initjvmaux.drp('drop synonym ojds$refaddr$');
initjvmaux.drp('drop synonym ojds$permissions$');
initjvmaux.drp('drop synonym ojds$shared$obj$seq$');
initjvmaux.drp('drop synonym ojds$shared$obj$');
initjvmaux.drp('drop package ojds_namespace');
initjvmaux.drp('drop public synonym ojds_namespace');
initjvmaux.drp('drop trigger OJDS$ROLE_TRIGGER$');
-- remove entry for drop user cascade
initjvmaux.exec('delete from duc$ where OWNER = ''SYS'' and PACK = ''OJDS_CONTEXT'' and PROC = ''USER_DROPPED''');
initjvmaux.drp('drop package ojds_context');
initjvmaux.drp('drop view java_system_property_settings');
initjvmaux.drp('drop package javavm_sys');
initjvmaux.drp('drop view java$rmjvm$aux4v');
initjvmaux.drp('drop table java$rmjvm$aux4');
initjvmaux.drp('drop package dbms_java_misc');
initjvmaux.drp('drop package jvmrjbcinv');

end if; end;
/

begin if :jvmrmaction = 'FULL_REMOVAL' or
         (:jvmrmaction = 'DOWNGRADE' and
          initjvmaux.compare_releases(:jvmdownto, '11.2') = 'FIRST IS OLDER')
then
initjvmaux.drp('drop table java$method$metadata');
initjvmaux.drp('drop table java$mc$deps');
initjvmaux.drp('drop package dbms_java_definers');
initjvmaux.drp('drop table javanegdeps$');
initjvmaux.drp('drop table java$runtime$exec$user$');
end if; end;
/

/*
  The following statements containing calls to rmjvm may generate errors
  if java has never been installed.  Such errors are harmless and may be
  ignored.  If java has been installed, these statements may take tens
  of minutes to run.
*/

begin if :jvmrmaction = 'FULL_REMOVAL' then
  rmjvm.run(true);
  initjvmaux.endaction;
  dbms_registry.removed('JAVAVM');
end if;end;
/

begin if :jvmrmaction = 'GRADE_REMOVAL' and :jvmudaction = 'DOWNGRADE' then
  if initjvmaux.startstep('RMJVM_RUN') then
    rmjvm.run(false);
  initjvmaux.endstep; end if;
end if;end;
/

OHA YOOOO