| Oracle8i JDBC Developer's Guide and Reference Release 2 (8.1.6) A81354-01 |
|
A convenient way to create custom object classes, as well as other kinds of custom Java classes, is to use the Oracle JPublisher utility. It generates a full definition for a custom Java class, which you can instantiate to hold the data from an Oracle object. JPublisher-generated classes include methods to convert data from SQL to Java and from Java to SQL, as well as getter and setter methods for the object attributes.
This section offers a brief overview. For more information, see the Oracle8i JPublisher User's Guide.
You can direct JPublisher to create custom object classes that implement either the SQLData interface or the CustomDatum interface, according to how you set the JPublisher type mappings.
If you use the CustomDatum interface, JPublisher will also create a custom reference class to map to object references for the Oracle object type. If you use the SQLData interface, JPublisher will not produce a custom reference class; you would use standard java.sql.Ref instances instead.
If you want additional functionality, you can subclass the custom object class and add features as desired. When you run JPublisher, there is a command-line option for specifying both a generated class name and the name of the subclass you will implement. For the SQL-Java mapping to work properly, JPublisher must know the subclass name, which is incorporated into some of the functionality of the generated class.
JPublisher offers various choices for how to map user-defined types and their attribute types between SQL and Java. The rest of this section lists categories of SQL types and the mapping options available for each category.
For general information about SQL-Java type mappings, see "Datatype Mappings".
For more information about JPublisher features or options, see the Oracle8i JPublisher User's Guide.
JPublisher categorizes SQL types into the following groups, with corresponding JPublisher options as noted:
Use the JPublisher -usertypes option to specify the type-mapping implementation for UDTs--either a standard SQLData implementation or an Oracle-specific CustomDatum implementation.
NUMBER
Use the JPublisher -numbertypes option to specify type-mapping for numeric types.
BLOB and CLOB
Use the JPublisher -lobtypes option to specify type-mapping for LOB types.
CHAR, VARCHAR2, LONG, and RAW
Use the JPublisher -builtintypes option to specify type-mapping for built-in types.
JPublisher defines the following type-mapping modes, two of which apply to numeric types only:
jdbc)--Uses standard default mappings between SQL types and Java native types. For a custom object class, uses a SQLData implementation.
oracle)--Uses corresponding oracle.sql types to map to SQL types. For a custom object, reference, or collection class, uses a CustomDatum implementation.
objectjdbc)--This is an extension of JDBC mapping. Where relevant, object-JDBC mapping uses numeric object types from the standard java.lang package (such as java.lang.Integer, Float, and Double), instead of primitive Java types (such as int, float, and double). The java.lang types are nullable, while the primitive types are not.
BigDecimal mapping (for numeric types only) (setting bigdecimal)--Uses java.math.BigDecimal to map to all numeric attributes; appropriate if you are dealing with large numbers but do not want to map to the oracle.sql.NUMBER class.
Use the JPublisher -usertypes option to determine how JPublisher will implement the custom Java class that corresponds to a SQL object type:
-usertypes=oracle (the default setting) instructs JPublisher to create a CustomDatum implementation for the custom object class.
This will also result in JPublisher producing a CustomDatum implementation for the corresponding custom reference class.
-usertypes=jdbc instructs JPublisher to create a SQLData implementation for the custom object class. No custom reference class can be created--you must use java.sql.Ref or oracle.sql.REF for the reference type.
The next section discusses type mapping options that you can use for object attributes.
If you do not specify mappings for the attribute types of the SQL object type, JPublisher uses the following defaults:
If you want alternate mappings, use the -numbertypes, -lobtypes, and -builtintypes options as necessary, depending on the attribute types you have and the mappings you desire.
If an attribute type is itself a SQL object type, it will be mapped according to the -usertypes setting.
Table 8-1 summarizes JPublisher categories for SQL types, the mapping settings relevant for each category, and the default settings.
|
Note:
The JPublisher |