JTS Java class compilation for 11g and above

Java classes loaded into the Oracle JVM are interpreted when executed up to and including Oracle 10gR2. For Oracle 11g and upwards, these loaded Java classes can be compiled to native code.

I have added the optional compilation of my JTS Java wrappers and the source JTS classes to the JTS installer.

The installation is done using snippets of anonymous PL/SQL as follows.

1. Check correct version

 WHENEVER SQLERROR EXIT FAILURE;
 SET serveroutput ON SIZE unlimited
 DECLARE
    l_version       long;
    l_compatibility long;
    v_version       varchar2(20);
 BEGIN
    dbms_utility.db_version(version => l_version, compatibility => l_compatibility);
    v_version := SUBSTR(l_version,1,2);
    IF ( NOT ( v_version > '10' ) ) THEN
      RAISE_APPLICATION_ERROR(-20000,'Can only compile java classes in Oracle 11g and later.');
    END IF;
 END;
 /
 SHOW errors
 -- For 10g
 Error report:
 ORA-20000: Can ONLY compile java classes IN Oracle 11g AND later.
 ORA-06512: at line 9
 20000. 00000 -  "%s"
 *Cause:    The stored PROCEDURE 'raise_application_error'
            was called which causes this error TO be generated.
 *Action:   Correct the problem AS described IN the error message OR contact
            the application administrator OR DBA FOR more information.

2. Now compile

 WHENEVER SQLERROR EXIT FAILURE;
 SET serveroutput ON SIZE unlimited
 DECLARE
    v_compile       NUMBER;
 BEGIN
    FOR rec IN (SELECT name FROM user_java_classes) loop
    BEGIN
       v_compile := DBMS_JAVA.compile_class(rec.name);
       dbms_output.put_line('Compiling class ' || rec.name || ' resulted in ' || v_compile || ' methods being compiled.');
       EXCEPTION
          WHEN OTHERS THEN
               dbms_output.put_line('Compile of Java class ' || rec.name || ' failed with ' || SQLCODE );
    END;
    END loop;
 END;
 /
 SHOW ERRORS
 -- Results (11g)
 Compiling class com/spatialdbadvisor/dbutils/ora/GeoProcessing resulted IN 21 methods being compiled.
 Compiling class com/vividsolutions/jts/geom/GeometryFactory resulted IN 33 methods being compiled.
 Compiling class com/vividsolutions/jts/geom/PrecisionModel resulted IN 21 methods being compiled.
 Compiling class org/geotools/DATA/oracle/sdo/GeometryConverter resulted IN 23 methods being compiled.
 Compiling class com/vividsolutions/jts/geom/LineString resulted IN 31 methods being compiled.
 ....

The full JTS zip file has been uploaded to my website.