Creating an opaque type from an existing Java class

About this task

To create an opaque type from an existing Java™ class:

Procedure

  1. Ensure that the class meets the requirements for conversion to an opaque type.

    For the requirements, see Requirements for the Java class.

  2. 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.

  3. 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.

  4. 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.

  5. Instantiate an UDTManager object and an UDTMetaData object:
    UDTManager udtmgr = new UDTManager(connection);
    UDTMetaData mdata = new UDTMetaData();
  6. 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");
  7. 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.

  8. Create the opaque type:
    udtmgr.createUDT(mdata, "Circle2.jar", "Circle2", 0);

Results

For additional information about creating an opaque type from existing code, see Creating an opaque type from existing code.

For a complete code example of using the preceding steps to create an opaque type, see Create an opaque type from an existing Java class with UDTManager.