This section explores in more detail issues related to the way Java elements are stored in the database, and how you can manage those elements.
Oracle stores each Java class in the database as a schema object. The name of that object is derived from (but is not the same as) the fully qualified name of the class; this name includes the names of any containing packages. The full name of the class OracleSimpleChecker, for example, is as follows:
oracle.sqlj.checker.OracleSimpleChecker
In the database, however, the full name of the Java schema object would be:
oracle/sqlj/checker/OracleSimpleChecker
Once stored in the Oracle RDBMS, in other words, slashes replace dots.
An object name in Oracle, whether it is the name of a database table or a Java class, cannot be longer than 30 characters. Java does not have the same restriction; you can have much longer names. Oracle will allow you to load a Java class into Oracle with a name of up to 4000 characters. If the Java element name has more than 30 characters, Oracle will automatically generate a valid (less than 31 characters) alias for that element.
But don't worry! You never have to reference that alias. You can, instead, continue to use the real name for your Java element in your code. Oracle will map that long name automatically to its alias (the schema name) when necessary.
Once you have loaded Java source, class, and resource elements into the database, information about those elements is available in several different data dictionary views, as shown in Table 9.4.
View | Description |
---|---|
Contains header information about your objects of JAVA SOURCE, JAVA CLASS, and JAVA RESOURCE types | |
Contains any compilation errors encountered for your objects | |
Contains the source code for your Java source if and only if you used the CREATE JAVA SOURCE command to create the Java schema object |
You can write queries against these views or you can build programs to access the information in a variety of useful ways. For example, here is a query that shows me all of the Java-related objects in my schema:
/ *Filename on companion disk: myjava.pkg */ COLUMN object_name FORMAT A30 SELECT object_name, object_type, status, timestamp FROM user_objects WHERE (object_name NOT LIKE 'SYS_%' AND object_name NOT LIKE 'CREATE$%' AND object_name NOT LIKE 'JAVA$%' AND object_name NOT LIKE 'LOADLOB%') AND object_type LIKE 'JAVA %' ORDER BY object_type, object_name;
The WHERE clause filters out those objects created by Oracle for managing Java objects. Here is some sample output:
SQL> @showjava OBJECT_NAME OBJECT_TYPE STATUS TIMESTAMP --------------------- ------------ ------- ------------------- Hello JAVA CLASS VALID 1999-05-19:16:42:27 JFile2 JAVA CLASS VALID 1999-05-26:17:07:11 JFile3 JAVA CLASS VALID 1999-05-27:12:53:46 plsolutions/java/putLn JAVA SOURCE VALID 1999-05-19:16:30:29
The myjava.pkg file on the companion disk contains a packaged version of this query, allowing you to view your Java objects with this procedure call:
SQL> exec myjava.showobjects
The following lets you see a list of all the Java elements whose names start with OE:
SQL> exec myjava.showobjects ('OE%')
The USER_OBJECTS view's object_name column contains the full names of Java schema objects, unless the name is longer than 30 characters or contains an untranslatable character from the Unicode character set. In this case, the short name is displayed in the object_name column. To convert short names to full names, you can use the LONGNAME function in the utility package DBMS_JAVA, which is explored in the next section.
Here are some things to keep in mind about Java schema elements stored in the database:
When you use the loadjava command to load your Java element into the database, the source of your Java element is not transferred to Oracle. Only the .class, .jar, .zip, .java, etc., files are moved into the database.
If you use the CREATE JAVA DDL command, then the source for your Java element is stored in the database. You will then find an entry in your USER_OBJECTS (as well as DBA_OBJECTS and ALL_OBJECTS) view for that element with type "JAVA SOURCE". You can then use the DBMS_JAVA.EXPORT_SOURCE procedure to extract that source into PL/SQL data structures and display or manipulate the text. See the showjava.sp file, discussed later in this chapter, for an example of such a procedure.
Copyright (c) 2000 O'Reilly & Associates. All rights reserved.