SQL/MX Programming Manual for Java

Sample Programs
HP NonStop SQL/MX Programming Manual for Java523726-003
C-22
StreamTimeout.sqlj—Stream Timeout Setting
StreamTimeout.sqlj—Stream Timeout Setting
In this SQLJ program, an iterator with the holdability property accesses a regular
database table as a continuous data stream. The iterator remains open when the
transaction is committed and when a new transaction is started after each row is
fetched or after the stream times out. The stream access mode first does a regular
scan of the table. Then, if all available rows have been retrieved, the stream access
mode causes the fetch operation to block (wait) until more rows are available instead
of returning the end-of-data condition.
The stream timeout setting controls the time that the fetch operation waits for a row to
be available. The CONTROL QUERY DEFAULT statement sets the stream timeout
value to five seconds, which causes the stream to wait five seconds before timing out.
After the stream times out, the program commits the transaction, which releases locks
on the table, and starts a new transaction.
The program code handles the stream timeout exception within a nested try-catch
block. After the stream times out, the endFetch() method of the iterator returns true
to signal that no row was returned. Because more rows might appear in the stream
later and because the iterator is coded to be holdable across transactions, the program
resumes fetching rows during the next transaction.
For information about publish/subscribe functionality, see the SQL/MX Queuing and
Publish/Subscribe Services manual.
This SQLJ program uses tables in the shipping database. To install this database, see
the SQL/MX Quick Start.
SQLJ Source File
Example C-6. StreamTimeout.sqlj—Stream Timeout Setting (page 1 of 2)
import java.sql.*;
#sql iterator StreamTimeoutIter with (holdability=true)
(int, int, int);
public class StreamTimeout
{
public static void main(String[] args)
{
int destination = 0;
int origin = 0;
int seqnbr = 0;
StreamTimeoutIter arrivals = null;