Java Backup

A good backup is always a DBA's best friend, especially when the database has a large number of Java Classes, Java Resources, Java Grants and Policies. No special tool is provided by Oracle to handle the Java objects backup, you'll need to use standard utilities.

A Java Classes Backup is made by a full database export without rows.

Example of a full database export:

% exp userid=system full=y ROWS=N file=full_export_norows.dmp 

To restore Java Classes from previously taken backup:

% imp userid=system INGORE=Y full=y

Java Privileges Backup is simply a Java grants and policies extraction from the database. Here is the script to extract the Java information (Oracle Metalink, DocID: 183825):

spool setjvmprivs.sql 
set echo off 
set feedback off 
set heading off 
set linesize 80 
set pagesize 1000 
column stmt format a70 word_wrapped 
select 'exec '||stmt 
from (select seq, 'dbms_java.grant_permission('''||grantee||''','''|| 
             ''');' stmt 
      from dba_java_policy 
      where grantee not in ('JAVADEBUGPRIV', 'JAVASYSPRIV', 'JAVAUSERPRIV', 
                         'JAVA_ADMIN', 'JAVA_DEPLOY', 'SYS', 'PUBLIC') and 
      union all 
      select seq,'dbms_java.grant_policy_permission('''||a.grantee||''','''|| 
   ||''','''||permition||''','''||action||''');' stmt 
      from sys.user$ u, 
           (select seq, grantee, 
                   to_number(substr(name,1,instr(name,':')-1)) userid, 
                   substr(name,instr(name,':')+1,instr(name,'#') - 
                          instr(name,':')-1) permition, 
                   substr(name,instr(name,'#')+1 ) action 
            from dba_java_policy 
            where grantee not in ('JAVADEBUGPRIV', 'JAVASYSPRIV', 
                                  'JAVAUSERPRIV', 'JAVA_ADMIN', 'JAVA_DEPLOY', 
                                  'SYS', 'PUBLIC') and 
                  type_name = 
                      '') a 
      where u.user#=userid) order by seq; 
column stmt clear 
set pagesize 24 
set heading on 
spool off 

Output from that script should produce Java recreation commands like:

exec dbms_java.grant_permission('SCOTT','','temp\output.txt','read,write);


Recent surveys showed interesting answers to the question of 'why use Java'.

Some said because Java developers are easier to find than other developers, others are of the opinion that the development time is reduced due to Java code's simplicity and accessibility. Most of them believe that Java's performance will be comparable to other natively compiled languages in the future.

Once loaded, the Java option will need attention from a DBA.

When it is no longer needed, it should be removed, rather than just sizing down the Java pool.

» See All Articles by Columnist Marin Komadina