About this task
To create an opaque type from an existing Java™ class:
Procedure
-
Ensure that the class meets the requirements for conversion
to an opaque type.
-
If you do not want to use the default input and output
routines provided by the server, write support UDRs for input and
output.
For general information about writing support
UDRs, see HCL OneDB™ User-Defined
Routines and Data Types Developer's Guide.
-
Create a default sbspace on the database server to hold
the JAR file that contains the code for the opaque type.
For
information about creating an sbspace, see the HCL
OneDB
Administrator's Guide for
your database server and the HCL® J/Foundation Developer's
Guide.
-
Open a JDBC connection.
Make sure a database
object is associated with the connection object. The driver cannot
create an opaque type without a database object. For details about
creating a connection with a database object, see Connect to the database.
-
Instantiate an UDTManager object and an UDTMetaData object:
UDTManager udtmgr = new UDTManager(connection);
UDTMetaData mdata = new UDTMetaData();
-
Set properties for the opaque type by calling methods in
the UDTMetaData object.
At a minimum, you must
specify the SQL name, UDT length, and JAR file SQL name. For an explanation
of SQL names, see SQL names.
You
can also specify the alignment, implicit and explicit casts, and any
support UDRs:
mdata.setSQLName("circle2");
mdata.setLength(24);
mdata.setAlignment(UDTMetaData.EIGHT_BYTE)
mdata.setJarFileSQLName("circle2_jar");
mdata.setUDR(areamethod, "area");
mdata.setSupportUDR(input, "input", UDTMetaData.INPUT)
mdata.setSupportUDR(output, "output",UDTMetaData.OUTPUT)
mdata.SetImplicitCast(com.informix.lang.IfxTypes.IFX_TYPE_
LVARCHAR, "input");
mdata.SetExplicitCast(com.informix.lang.IfxTypes.IFX_TYPE_
LVARCHAR, "output");
-
If desired, specify a path name where the driver should
place the JAR file in the database server file system:
String pathname = "/work/srv93/examples";
udtmgr.setJarFileTmpPath(pathname);
Make sure the path
exists in the server file system. For more information, see Specify a JAR file temporary path.
-
Create the opaque type:
udtmgr.createUDT(mdata, "Circle2.jar", "Circle2", 0);