| Oracle8i SQLJ Developer's Guide and Reference Release 2 (8.1.6) A81360-01 |
|
Weakly typed objects, references, and collections are supported by SQLJ. Their use is not generally recommended, and there are some specific restrictions, but in some circumstances they can be useful. For example, you might have generic code that can use "any STRUCT" or "any REF" (although if this uses dynamic SQL it would require coding in JDBC, instead of SQLJ).
In using Oracle objects, references, or collections in a SQLJ application, you have the option of using generic and weakly typed java.sql or oracle.sql instances instead of the strongly typed custom object, reference, and collection classes that implement the CustomDatum interface or the strongly typed custom object classes that implement the SQLData interface. (Note that if you use SQLData implementations for your custom object classes, you will have no choice but to use weakly typed custom reference instances.)
The following weak types can be used for iterator columns or host expressions in Oracle SQLJ:
java.sql.Struct or oracle.sql.STRUCT for objects
java.sql.Ref or oracle.sql.REF for object references
java.sql.Array or oracle.sql.ARRAY for collections
In host expressions, they are supported as follows:
Using these weak types is not generally recommended, however, as you would lose all the advantages of the strongly typed paradigm that SQLJ offers.
Each attribute in a STRUCT object or each element in an ARRAY object is stored in an oracle.sql.Datum object, with the underlying data being in the form of the appropriate oracle.sql.* type (such as oracle.sql.NUMBER or oracle.sql.CHAR). Attributes in a STRUCT object are nameless.
Because of the generic nature of the STRUCT and ARRAY classes, SQLJ cannot perform type checking where objects or collections are written to or read from instances of these classes.
It is generally recommended that you use custom Java classes for objects, references, and collections, preferably classes generated by JPublisher.
A weakly typed object (Struct or STRUCT instance), reference (Ref or REF instance), or collection (Array or ARRAY instance) cannot be used in host expressions in the following circumstances:
IN parameter if null
OUT or INOUT parameter in a stored procedure or function call
OUT parameter in a stored function result expression
They cannot be used in these ways because there is no way to know the underlying SQL type name (such as Person), which is required by the Oracle JDBC driver to materialize an instance of a user-defined type in Java.