9.6 Managing Java in the DatabaseThis section explores in more detail issues related to the way Java elements are stored in the database, and how you can manage those elements. 9.6.1 The Java Namespace in OracleOracle 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. 9.6.2 Examining Loaded Java ElementsOnce 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 .
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:
Copyright (c) 2000 O'Reilly & Associates. All rights reserved. |
|