Enterprise Information Portal APIs

com.ibm.gcs.db.util
Class Transaction

java.lang.Object
  |
  +--com.ibm.gcs.db.util.Transaction
Direct Known Subclasses:
PreparedTransaction

public class Transaction
extends java.lang.Object

A Transaction represents a set of SQL statements to be executed as a unit. These sets of SQL statements may be commited or rolled back through a Transaction object. All SQL statements must be executed and results returned through methods in the Transaction object.

A Transaction object may be constructed by specifying the level of transaction isolation. If no level is specified, the Transaction defaults to TRANSACTION_READ_UNCOMMITTED. When a SQL statement is executed, the Transaction object obtains a java.sql.Connection from the ConnectionManager to execute the statement. It holds onto and uses this connection to execute all subsequent SQL statements and releases it (for use by other threads) only after the Transaction is committed or aborted.

Note: If a transaction is never committed or aborted, the application will go into deadlock.


Field Summary
static boolean debug
          If true, prints all SQL statements to System.out.
 
Constructor Summary
Transaction()
          Default Constructor.
Transaction(int isolationLevel)
          Constructor.
 
Method Summary
 void abort()
          Aborts a transaction in progress.
 void commit()
          Commits all changes in the transaction and releases the connection.
 java.util.Hashtable executeQuery(java.lang.String sql)
          Executes a select sql statement which returns at most 1 row as a result.
 java.util.Enumeration executeQuery(java.lang.String sql, int max)
          Executes a select sql statement which returns the values from a single column for each row which satisfy the query.
 java.util.Enumeration executeQueryT(java.lang.String sql, int max)
          Executes a select sql statement which returns the values for each row which satisfy the query as hashtables which map as (column-name,value) pairs.
 int executeUpdate(java.lang.String sql)
          Executes an update, insert, or delete sql statement.
 java.io.InputStream getBinaryStream(java.lang.String sql)
          Executes a select sql statement which returns at most 1 value of type BLOB as a result.
 java.sql.Connection getConnection()
          Returns a pointer to the connection object in use by this transaction.
 int getMaxSqlBytes()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debug

public static boolean debug
If true, prints all SQL statements to System.out.
Constructor Detail

Transaction

public Transaction()
Default Constructor. Sets transaction isolation level to TRANSACTION_READ_UNCOMMITTED.

Transaction

public Transaction(int isolationLevel)
Constructor.
Parameters:
isolationLevel - The transaction isolation level as defined in java.sql.Connection
See Also:
Connection
Method Detail

executeUpdate

public int executeUpdate(java.lang.String sql)
                  throws TransactionException
Executes an update, insert, or delete sql statement. Returns the update count.
Parameters:
sql - The SQL String to execute.
Returns:
int The number of rows updated.
Throws:
TransactionException - database error occured during SQL update.

executeQuery

public java.util.Hashtable executeQuery(java.lang.String sql)
                                 throws TransactionException
Executes a select sql statement which returns at most 1 row as a result. Returns the data as a hashtable with key->value pairs mapping to column-name->value pairs. If the database column has no name, the key is represented as the empty string (eg. for functions like count(*)).
Parameters:
sql - The SQL statement to execute.
Returns:
Hashtable The data returned by the query. Null if no results returned.
Throws:
TransactionException - SQL error occured during query execution. Transaction aborted.

executeQuery

public java.util.Enumeration executeQuery(java.lang.String sql,
                                          int max)
                                   throws TransactionException
Executes a select sql statement which returns the values from a single column for each row which satisfy the query. Returns the data as an enumeration of java objects.
Parameters:
sql - The SQL statement to execute.
max - The maximum number of rows to select for. 0 means no maximum.
Returns:
Enumeration-The data returned by the query.
Throws:
TransactionException - SQL error occured during query execution. Transaction aborted.

executeQueryT

public java.util.Enumeration executeQueryT(java.lang.String sql,
                                           int max)
                                    throws TransactionException
Executes a select sql statement which returns the values for each row which satisfy the query as hashtables which map as (column-name,value) pairs. Returns the data as an enumeration of java objects.
Parameters:
sql - The SQL statement to execute.
int - max The maximum number of rows to select for. 0 means no maximum.
Returns:
Enumeration-The data returned by the query.
Throws:
TransactionException - SQL error occured during query execution. Transaction aborted.

getBinaryStream

public java.io.InputStream getBinaryStream(java.lang.String sql)
                                    throws TransactionException
Executes a select sql statement which returns at most 1 value of type BLOB as a result. Returns the column as a BinaryInputStream.
Parameters:
sql - The SQL statement to execute.
Returns:
InputStream-The BLOB returned as an input stream.
Throws:
TransactionException - SQL error occured during query execution. Transaction aborted.

abort

public void abort()
Aborts a transaction in progress. Rolls back all changes, returns the connection to the connection manager, and loses reference to the connection. If the changes could not be rolled back, notifies the ConnectionManager that the connection may be in error. If no transaction is in progress, throws an exception.
Throws:
ImplementationException - no changes to abort.

commit

public void commit()
            throws TransactionException
Commits all changes in the transaction and releases the connection. If the changes could not be committed, aborts the transaction and throws a TransactionException.
Throws:
TransactionException - Changes could not be committed.
ImplementationException - No transaction in progress.

getConnection

public java.sql.Connection getConnection()
Returns a pointer to the connection object in use by this transaction.
Returns:
java.sql.Connection-A pointer to the connection in use by this transaction. (Could be null.)

getMaxSqlBytes

public int getMaxSqlBytes()
Returns:
int The maximum number of bytes allowed per SQL insert or update statement.

EIP Web Crawler APIs

(c) Copyright International Business Machines Corporation 1996, 2002. IBM Corp. All rights reserved.