Creating UDT-to-Java mappings

The routine manager needs a mapping between SQL data values and Java objects to be able to pass parameters to and retrieve return results from a UDR. The SQL-to-Java data type mapping is performed according to the Informix® JDBC Driver specification.

About this task

For built-in SQL data types, the routine manager can use mappings to existing Informix® JDBC Driver data types.

For any UDTs that your UDR uses, you must create mappings. You can use the following UDTs in UDRs written in Java code.
User-defined data type SQL statement
Distinct data type CREATE DISTINCT TYPE
Opaque data type CREATE OPAQUE TYPE
Restriction: You cannot use row or collection data types in UDRs written in Java code.

To create the mapping between a user-defined SQL data type and a Java object:

Procedure

  1. Create a user-defined class that implements the SQLData interface.
    For more information, see the Informix® JDBC Driver 2.0 specification.
  2. Bind this user-defined class to the user-defined SQL data type by using the setUDTExtName built-in procedure.
    Because the SQL statements that create UDTs do not currently provide a clause for specifying the external name of a UDT, you must define this mapping. Use the following built-in procedures with the EXECUTE PROCEDURE statement to define the mapping:
    • sqlj.setUDTExtName()

      This procedure defines the mapping between a UDT and a Java data type.

    • sqlj.unsetUDTExtName()

      This procedure removes the SQL-to-Java mapping and removes any cached copy of the Java class from database server shared memory.

      For example:
      -- Creating or removing UDT-to-Java Mappings
      EXECUTE PROCEDURE sqlj.setUDTExtName('udt_name', 
            'class_name.udtname');
      EXECUTE PROCEDURE sqlj.unsetUDTExtName('udt_name');

Results

The online examples in $INFORMIXDIR/extend/krakatoa/examples.tar include a sample implementation of a UDT written in Java code, Circle.java.