Creating an opaque type without an existing Java class

About this task

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

Procedure

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

  2. Open a JDBC connection.

    Make sure the connection object has a database object associated with it. For details, see Connect to the database.

  3. Instantiate a UDTManager object and a UDTMetaData object:
    UDTManager udtmgr = new UDTManager(connection);
    UDTMetaData mdata = new UDTMetaData();
  4. Specify the characteristics of the opaque type by calling methods in the UDTMetaData class:
    mdata.setSQLName("acircle");
    mdata.setLength(24);
    mdata.setFieldCount(3);
    mdata.setFieldName(1, "x");
    mdata.setFieldName(2, "y");
    mdata.setFieldName(3, "radius");
    mdata.setFieldType
       (1,com.informix.lang.IfxTypes.IFX_TYPE_INT);
    mdata.setFieldType
       (2,com.informix.lang.IfxTypes.IFX_TYPE_INT);
    mdata.setFieldType
       (3,com.informix.lang.IfxTypes.IFX_TYPE_INT);
    mdata.setJarFileSQLName("ACircleJar");

    For more information about setting characteristics for opaque types, see Specify characteristics for an opaque type.

  5. Create the Java file, the class file, and the JAR file:
    mdata.keepJavaFile(true);
    String classname = udtmgr.createUDTClass(mdata);
    String jarfilename = udtmgr.createJar(mdata, new String[] 
       {classname + .class"}); 

    For more information, see Creating the JAR and class files.

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

  7. Send the class definition to the database server:
    udtmgr.createUDT(mdata, jarfilename, classname, 0);

    For more information, see Send the class definition to the database server.

Results

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