Oracle8i Java Developer's Guide Release 3 (8.1.7) Part Number A83728-01 |
Library | Service | Contents | Index

## Initializing a Java-Enabled Database

If you installed Oracle8i with JServer, the database is Java-enabled. That is, it is ready to run Java stored procedures, JDBC, SQLJ, and CORBA/EJB objects. If you are using your own scripts to create your Oracle instance, you must initialize the JServer explicitly.

You install JServer in one of three ways:

- Oracle8i Typical or Minimal Install--Choose the Typical or Minimal Oracle8i installation, which results in JServer being automatically installed.

- Oracle8i Custom Install--Choose the JServer option within a "Custom" Oracle8i installation.

- Manual Install--Install JServer by invoking the `initjvm.sql` script.

### Manual Install

If you did not install JServer through any of the Oracle8i install options, you can add JServer to an existing database with the `initjvm.sql` script in `ORACLE_HOME/javavm/install`.

The `initjvm.sql` script loads the initial set of Java classes necessary to support Java, initializes the tables for supporting Java and for the CORBA namespace, and publishes top-level entry points through call-specifications. The `initjvm.sql` script loads the support Java classes into the database, which include the following:

- the standard Java runtime

- bytecode verifier and optimizer

- Java and SQLJ compilers

- JDBC runtime

- CORBA ORB and EJB runtime

- some additional support classes, such as `DBMS_JAVA`, which are described in "Package DBMS_JAVA"

The `initjvm.sql` script performs the following actions:

1. Loads the classes to the SYS schema.

2. Creates public synonyms for the loaded classes to be accessible to all users.

3. Alters some of these classes to run with definer's rights to support CORBA callouts.

4. Defines database start up and shut down triggers.

   Note: The initjvm.sql script can take up to an hour to execute.

### Requirements

Initializing a Java-enabled database requires a `SHARED_POOL_SIZE` of 50 MB, a `JAVA_POOL_SIZE` of about 20 MB, an additional 30 MB of system tablespace, and enough rollback segments. If the script fails for some reason, such as a lack of resources, you can adjust resources as necessary and re-execute `initjvm.sql`. Refer to "Java Memory Usage" and the `/javavm/README.txt` file for the most up-to-date information on database initialization file configuration parameters and requirements.

In addition, there are specific requirements for enabling EJB and CORBA communications. The initial settings that the Oracle8i JServer installations furnish should be sufficient to get you started. Consult the specifics of the documentation in the Oracle8i Enterprise JavaBeans Developer's Guide and Reference, the Oracle8i CORBA Developer's Guide and Reference, and the Net8 Administrator's Guide for more details.

### Package DBMS_JAVA

When initializing the JServer, the `initjvm.sql` script creates the PL/SQL package `DBMS_JAVA`. Some entrypoints of `DBMS_JAVA` are for your use; others are only for internal use. The corresponding Java class `DbmsJava` provides methods for accessing RDBMS functionality from Java.

The `DBMS_JAVA` package supplies the following entrypoints:

    FUNCTION longname (shortname VARCHAR2) RETURN VARCHAR2

Return the full name from a Java schema object. Because Java classes and methods can have names exceeding the maximum SQL identifier length, Aurora uses abbreviated names internally for SQL access. This function simply returns the original Java name for any (potentially) truncated name. An example of this function is to print the fully qualified name of classes that are invalid:

    select dbms_java.longname (object_name) from user_objects
       where object_type = 'JAVA CLASS' and status = 'INVALID';

    FUNCTION shortname (longname VARCHAR2) RETURN VARCHAR2

You can specify a full name to the database by using the `shortname()` routine of the `DBMS_JAVA` package, which takes a full name as input and returns the corresponding short name. This is useful when verifying that your classes loaded by querying the `USER_OBJECTS` view.

Refer to "Shortened Class Names" and Oracle8i Java Stored Procedures Developer's Guide for examples of these functions.

    FUNCTION get_compiler_option(what VARCHAR2, optionName VARCHAR2)
    PROCEDURE set_compiler_option(what VARCHAR2, optionName VARCHAR2,

    	value VARCHAR2)
    PROCEDURE reset_compiler_option(what VARCHAR2, optionName VARCHAR2)

These three entry points control the options of the JServer Java and SQLJ compiler Oracle8i delivers. See "Compiling Java Classes" for an example of these options. Additionally, both the Oracle8i Java Stored Procedures Developer's Guide and the Oracle8i SQLJ Developer's Guide and Reference document the options and these entry points.

    PROCEDURE set_output (buffersize NUMBER)

This procedure redirects the output of Java stored procedures and triggers to the `DBMS_OUTPUT` package. See "Redirecting Output on the Server" for an example.

    PROCEDURE loadjava(options varchar2)
    PROCEDURE loadjava(options varchar2, resolver varchar2)
    PROCEDURE dropjava(options varchar2)

These procedures allow you to load and drop classes within the database using a call rather than through the `loadjava` or `dropjava` command-line tools. To execute within your Java application, do the following:

    call dbms_java.loadjava('... options...');
    call dbms_java.dropjava('... options...');

The options are identical to those specified for the `loadjava` and `dropjava` command-line tools. Each option should be separated by a blank. You should not separate the options with a comma. The only exception for this is the `loadjava` -`resolver` option, which contains blanks. For -`resolver`, you should specify all other options first, separate these options by a comma, and then specify the -`resolver` option with its definition. You should not specify the following options, because they relate to the database connection for the `loadjava` command-line tool: `-thin,` `-oci8,` `-user,` `-password`. The output is directed to stderr.

For more information on the available options, see the Oracle8i Java Tools Reference for complete information on `loadjava`.

    PROCEDURE grant_permission( grantee varchar2,

    	permission_type varchar2,

    	permission_name varchar2,

    	permission_action varchar2 )

    PROCEDURE restrict_permission( grantee varchar2,

    	permission_type varchar2,

    	permission_name varchar2,

    	permission_action varchar2)

    PROCEDURE grant_policy_permission( grantee varchar2,

    	permission_schema varchar2,

    	permission_type varchar2,

    	permission_name varchar2)

    PROCEDURE revoke_permission(permission_schema varchar2,

    	permission_type varchar2,

    	permission_name varchar2,

    	permission_action varchar2)

    PROCEDURE disable_permission(key number)

    PROCEDURE enable_permission(key number)

    PROCEDURE delete_permission(key number)

These entry points control the JVM permissions. See "Setting Permissions" for a description and example of these options.

    PROCEDURE start_debugging(host varchar2, port number,

    	timeout number)

    PROCEDURE stop_debugging

    PROCEDURE restart_debugging(timeout number)

These entry points start and stop the debug agent when debugging. See "Debugging Server Applications" for a description and example of these options.

| Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
Library | Service | Contents | Index