informix
Informix JDBC Driver Programmer's Guide
Manipulating Informix Data Types

Manipulating Informix Opaque Types

Informix has extended the JDBC 2.0 definition of the java.sql.SQLInput and java.sql.SQLOutput methods to fully support Informix fixed binary and variable binary opaque types. This extension includes the following interfaces:

IfmxUdtSQLInput Interface

The com.informix.jdbc.IfmxUdtSQLInput interface extends java.sql.SQLInput with several added methods. To use these methods, you must cast the SQLInput references to IfmxUdtSQLInput. Here are the signatures and descriptions of each added method:

This method returns the total length of the entire data stream.

This method reads the next attribute in the stream as a Java string. This method is similar to the SQLInput.readString() method except that a fixed length of data is read in. Since the opaque type is unknown to the driver, you must supply a maximum length for the driver to read in the next attribute properly.

This method reads the next attribute in the stream as Java byte array. This method is similar to the SQLInput.readBytes() method except that a fixed length of data is read in. Since the opaque type is unknown to the driver, you must supply a maximum length for the driver to read in the next attribute properly.

IfmxUdtSQLOutput Interface

The com.informix.jdbc.IfmxUdtSQLOutput interface extends java.sql.SQLOutput with several added methods. To use these methods, you must cast the SQLOutput references to IfmxUdtSQLOutput. Here are the signatures and descriptions of each added method:

This method writes the next attribute to the stream as a Java String. This method is similar to the SQLOutput.writeString() method except that a fixed length of data is written to the stream. If the string passed in is shorter than the specified length, the driver pads the string with zeros. Since the opaque type is unknown to the driver, you must supply a length for the driver to write the next attribute properly.

This method writes the next attribute to the stream as a Java byte array. This method is similar to the SQLOutput.writeBytes() method except that a fixed length of data is written to the stream. If the array passed in is shorter than the specified length, the driver pads the array with zeros. Since the opaque type is unknown to the driver, you must supply a length for the driver to write the next attribute properly.

Mapping Opaque Types

Informix opaque types map to Java objects, which must implement the java.sql.SQLData interface. These Java objects describe all the data members that make up the opaque type. These Java objects are strongly typed; that is, each read or write method in the readSQL or WriteSQL method of the Java object must match the corresponding data member in the opaque type definition. Informix JDBC Driver cannot perform any type conversion because the type structure is unknown to it.

Furthermore, the driver also requires that all opaque data be transported as Informix DataBlade API data types, as defined in incl/public/mitypes.h (this file is included in all Informix Dynamic Server with Universal Data Option installations). All opaque data is stored in the database server table in a C struct, which is made up of various DataBlade API types, as defined in the opaque type. For more information, see the DataBlade API Programmer's Manual.

The following table lists the mapping of DataBlade API types to their corresponding Java types.

DataBlade API Type Java Type
MI_LO_HANDLE BLOB or CLOB
gl_wchar_t String
mi_boolean boolean
mi_char String
mi_char1 String
mi_date Date
mi_datetime TimeStamp
mi_decimal BigDecimal
mi_double_precision double
mi_int1 byte
mi_int8 long
mi_integer int
mi_interval Not supported
mi_money BigDecimal
mi_numeric BigDecimal
mi_real float
mi_smallint short
mi_string String
mi_unsigned_char1 String
mi_unsigned_int8 long
mi_unsigned_integer int
mi_unsigned_smallint short
mi_wchar String

The C struct may contain padding bytes. The driver automatically skips these padding bytes to make sure the next data member is properly aligned. Therefore, your Java objects do not have to take care of alignment themselves.

In addition, you must provide a custom type map as described in Mapping Data Types to map this Java object to the corresponding SQL type name.

Caching Type Information

When an SQLData object inserts data into an opaque type column and getSQLTypeName() returns the name of the opaque type, Informix JDBC Driver uses the type information to verify that the data provided matches the data the database server expects. The driver asks the database server for the type information each time.

However, you can set an environment variable in the database URL, ENABLE_CACHE_TYPE=1, so the driver caches the type information the first time it is retrieved. In this case, Informix JDBC Driver asks the cache for the type information before requesting the data from the database server.

Inserting Data Examples

You can insert an opaque type as either its original type or its cast type. Here is an example of how to insert opaque data using the original type:

If a casting function is defined and you would like to insert data as the casting type instead of the original type, you must call the setXXX() method that corresponds to the casting type. For example, if you have defined a function casting CHAR or LVARCHAR to a charattrUDT column, you can use the setString() method to insert data, as follows:

The charattrUDT class must implement the SQLData interface, as in the following example:

In your JDBC application, a custom type map must map the type name charattr_udt to the charattrUDT class, as in the following example:

Retrieving Data Example

To retrieve Informix opaque types, you must use ResultSet.getObject(). Informix JDBC Driver converts the data to a Java object according to the custom type map you provide. Using the previous example of the charattrUDT type, you can fetch the opaque data, as in the following example:

Using Smart Large Objects Examples

A smart large object can be a data member within an opaque type, although you are most likely to create a large object on the database server, outside of the opaque type context, using the Informix BLOB and CLOB extension classes.

A large object is stored as a MI_LO_HANDLE object within the opaque type. The MI_LO_HANDLE object is created using the methods provided in com.informix.jdbc.IfxSmartBlob, and the large object handle obtained from these methods becomes the data member within the opaque type. Both BLOB and CLOB objects use the same MI_LO_HANDLE, as follows:

In a JDBC application, you create the MI_LO_HANDLE object using the methods provided by the IfxSmartBlob class:

See Manipulating Informix BLOB and CLOB Data Types for details.

Unsupported Methods

The following methods are not supported for opaque types:


Informix JDBC Driver Programmer's Guide, Version 2.0
Copyright © 1999, Informix Software, Inc. All rights reserved