On the client, your JDBC application can use ResultSet methods to access smart-large-object data, such as:
On the client side, the JDBC driver references the LO handle through an IfxLocator object. Your JDBC application obtains an instance of the IfxLocator class to contain the smart-large-object locator handle, as shown in Figure 4. Your application creates a smart large object independently and then inserts the smart large object into different columns, even in multiple tables. Using multiple threads, an application can write or read data from various portions of the smart large object in parallel, which is very efficient.
In IDS, support for Informix smart large object data types is available only with 9.x and later versions of the database server.
The Informix smart large object implementation is based on the following classes:
For detailed documentation on the onspaces utility that creates sbspaces, see the IBM Informix: Dynamic Server Administrator's Guide. For an example of creating an sbspace, see Example of Setting sbspace Characteristics.
This allows you to set storage characteristics for the smart large object. The driver passes the IfxLobDescriptor object to the database server when the IfxSmartBlob.IfxLoCreate() method creates the large object.
For most smart large objects, the sbspace name is the only storage characteristic that you need to specify. The database server can calculate values for all other storage characteristics. You can set particular storage characteristics to override these calculated values. However, most applications do not need to set storage characteristics at this level of detail. For more information, see Working with Storage Characteristics.
This is the pointer to the smart large object on the client.
This lets you perform various common operations on the smart large object.
IfxLoCreate() takes the IfxLocator and IfxLobDescriptor objects as parameters to identify the smart large object in the database server.
The IfxLobDescriptor class stores the internal storage characteristics for a smart large object. Before you can create a smart large object on the database server, you must create an IfxLobDescriptor object, as follows:
IfxLobDescriptor loDesc = new IfxLobDescriptor(conn);
The conn parameter is a java.sql.Connection object. The IfxLobDescriptor() constructor sets all the default values for the object.
For more information about the internal storage characteristics, see Working with Storage Characteristics.
The IfxLocator object (usually known as the locator pointer or large object locator) identifies the location of the smart large object, as shown in Figure 4; the locator pointer is the communication link between the database server and the client for a particular large object. Before it creates a large object or opens a large object for reading or writing, an application must create an IfxLocator object:
IfxLocator loPtr = new IfxLocator();
IfxLocator loPtr = new IfxLocator(Connection conn);
Use the second of these constructors to display localized error messages if an exception is thrown. For more information, see Support for Localized Error Messages.
To create a smart large object and obtain access to the methods for performing operations on the object, call the IfxSmartBlob constructor, passing a reference to the JDBC connection:
IfxSmartBlob smb = new IfxSmartBlob(myConn)
Once you have written all the methods that perform operations you need in the smart large object, you can then use the IfxSmartBlob.IfxLoCreate() method to create the large object in the database server and open it for access within your application. The method signature is as follows:
public int IfxLoCreate(IfxLobDescriptor loDesc, int flag, IfxLocator loPtr) throws SQLException public int IfxLoCreate(IfxLobDescriptor loDesc, int flag, IfxBblob blob)throws SQLException public int IfxLoCreate(IfxLobDescriptor loDesc, int flag, IfxCblob clob throws SQLException
The return value is the locator handle, which you can use in subsequent read, write, seek, and close methods (you can pass it as the locator file descriptor (lofd) parameter to the methods that operate on open smart large objects; these methods are described beginning with Positioning Within a Smart Large Object).
The flag parameter is an integer value that specifies the access mode in which the new smart large object is opened in the server. The access mode determines which read and write operations are valid on the open smart large object. If you do not specify a value, the object is opened in read-only mode.
Use the access mode flag values in the following table with the IfxLoCreate() and IfxLoOpen() methods to open or create smart large objects with specific access modes.
Access Mode | Purpose | Flag Value in IfxSmartBlob |
---|---|---|
Read only | Allows read operations only | LO_RDONLY |
Write only | Allows write operations only | LO_WRONLY |
Write/Append | Appends data you write to the end of the smart large object By itself, it is equivalent to write-only mode followed by a seek to the end of the smart large object. Read operations fail. When you open a smart large object in write/append mode only, the smart large object is opened in write-only mode. Seek operations move the seek position, but read operations to the smart large object fail, and the seek position remains unchanged from its position just before the write. Write operations occur at the seek position, and then the seek position is moved. | LO_APPEND |
Read/Write | Allows read and write operations | LO_RDWR |
The following example shows how to use a LO_RDWR flag value:
IfxSmartBlob smb = new IfxSmartBlob(myConn); int loFd = smb.IfxLoCreate(loDesc, smb.LO_RDWR, loPtr);
The loDesc and loPtr objects are previously created IfxLobDescriptor and IfxLocator objects, respectively.
The database server uses the following system defaults when it opens a smart large object.
For more information on locking, see Working with Locks.
The following table provides the full set of open-mode flags:
By itself, it is equivalent to write-only mode followed by a seek to the end of the smart large object. Read operations fail.
When you open a smart large object in write/append mode only, the smart large object is opened in write-only mode. Seek operations move the seek position, but read operations to the smart large object fail, and the seek position remains unchanged from its position just before the write. Write operations occur at the seek position, and then the seek position is moved.
Allows you to read uncommitted data pages for the smart large object
You cannot write to a smart large object after you set the mode to LO_DIRTY_READ. When you set this flag, you reset the current transaction isolation mode to Dirty Read for the smart large object.
Do not base updates on data that you obtain from a smart large object in Dirty Read mode.
Indicates that I/O is random and that the database server should not read ahead. Default open mode.
Indicates that reads are sequential in either forward or reverse direction.
You specify the range of bytes through the IfxSmartBlob.IfxLoLock() method when you place the lock.
After creating a smart large object, you must insert it into a BLOB or CLOB column to save it in the database. To do this, you must convert the IfxLocator object to an IfxBblob or IfxCblob object, depending upon the column type.
IfxBblob blb = new IfxBblob(loPtr);
The loPtr parameter is an IfxLocator object obtained from one of the previous sets of steps.
Follow these steps to use the Informix extensions to select a smart large object from a database column.
Standard JDBC ResultSet methods such as ResultSet.getBinaryStream(), getAsciiStream(), getString(), getBytes(), getBlob(), and getClob() can fetch BLOB or CLOB data from a table. The Informix extension classes can then access the data.
Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]