The Declaration Name and Use Name fields in the JPublisher wizard give you the flexibility of extending generated classes. In the Declaration Name field, enter the name of the class that you want JPublisher to generate from the given database object. In the Use Name field, enter the name of the class that your Java program will use to represent the database object.
When publishing an object type where Use Name is
different from Declaration Name, JPublisher creates a
declaration_name.sqlj file and a use_nameRef.java
file, where use_name represents the object type in your Java program.
JPublisher expects that you have written the class use_name,
which extends declaration_name. If you do not provide this
class, then the use_nameRef.java file will not
compile.
For example, suppose you want JPublisher to generate the class
JAddress from the PL/SQL object type ADDRESS. You
have also written a class, MyAddress, to represent
ADDRESS objects, where MyAddress either extends the
functionality provided by JAddress or has a JAddress
field.
Under this scenario, select ADDRESS in the Database Browser
and right-click Generate Java. In the JPublisher wizard, enter
JAddress in the Declaration Name field and
MyAddress in the Use Name field. JPublisher will
generate the custom Java class JAddress, and map the
ADDRESS object to the MyAddress classnot to the
JAddress class. JPublisher will also produce a reference class for
MyAddress, not JAddress.
This is how JPublisher will alter the code it generates:
MyAddressRef
rather than JAddressRef.
MyAddress class, instead of the
JAddress class, to represent attributes whose database type is
ADDRESS. This situation will occur in classes generated by
JPublisher, or in classes written by the user.
MyAddress class, instead of the
JAddress class to represent VARRAY and nested table elements whose
database type is ADDRESS.
MyAddress factory, instead of the
JAddress factory, when the CustomDatumFactory interface is
used to construct Java objects whose database type is ADDRESS
. This situation will occur both in classes generated by JPublisher, and in
classes written by the user.
The class that you create (for example, MyAddress.java)
must have the following features:
CustomDatum interface. The
simplest way to do this is to inherit the toDatum()
method from the superclass.
CustomDatumFactory interface,
either in the same class or in a different one. For example, you could
have a class Employee that implements CustomDatum
and a class EmployeeFactory that implements
CustomDatumFactory.
Enhancing
JPublisher-Generated Classes
Generating Source Code for Oracle Objects and PL/SQL Packages
Copyright © 1997, 2004, Oracle. All rights reserved.