|
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:
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:
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:
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.
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.
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.
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:
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:
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.
The following methods are not supported for opaque types: