Sun Adapter for DB2 Universal Database

com.stc.connector.db2adapter.base
Class StatementAgentImpl

java.lang.Object
  extended by com.stc.connector.db2adapter.base.StatementAgentImpl
All Implemented Interfaces:
com.stc.connector.appconn.db.StatementAgent, com.stc.connector.db.SessionEventListener
Direct Known Subclasses:
PreparedStatementAgentImpl, TableResultSetImpl

public abstract class StatementAgentImpl
extends java.lang.Object
implements com.stc.connector.appconn.db.StatementAgent, com.stc.connector.db.SessionEventListener

Agent hosts a managed Statement object

Version:
$Revision: 1.6 $
Author:
$Author: afung $

Field Summary
protected  int concurrencyType
          Current concurrency type.
protected  com.stc.connector.db.StatementEventListener listener
          A StatementEventListener instance.
protected static java.util.HashMap resultSetConcurMap
          Map resultet concurrency to string.
protected  int resultsetDirection
          Current resultset direction.
protected static java.util.HashMap resultSetDirMap
          Map resultset direction to string.
protected  int resultsetType
          Current resultset type.
protected static java.util.HashMap resultSetTypeMap
          Map resultset type to string.
protected  com.stc.connector.db.Session session
          A Session instance that holds the connection information.
protected  java.sql.SQLException sqlException
          A SQLException instance used for holding error information.
protected  java.sql.Statement statement
          A Statement instance used for SQL operations.
protected  java.lang.String statementClassName
          StatementAgent instance class name.
 
Constructor Summary
protected StatementAgentImpl()
          Default StatementAgentImpl constructor
protected StatementAgentImpl(com.stc.connector.db.Session session)
          StatementAgentImpl constructor
protected StatementAgentImpl(com.stc.connector.db.Session session, int resultsetType, int concurrencyType)
          StatementAgentImpl constructor
 
Method Summary
 void cancel()
          Cancels statement results.
 void clearBatch()
          Clears the batch of operations.
 void clearWarnings()
          Clear all SQLWarning objects.
 int[] executeBatch()
          Executes a batch of SQL statements.
 int getFetchDirection()
          Returns result set fetch direction.
 int getFetchSize()
          Returns result set prefetch record count.
 int getMaxFieldSize()
          Gets the maximum data size for a column.
 int getMaxRows()
          Gets the maximum number of fetch records in a result set.
 boolean getMoreResults()
          Checks if there are more result set.
 int getQueryTimeout()
          Returns query timeout duration.
 com.stc.connector.appconn.db.ResultSetAgent getResultSet()
          Returns the result set of last executed statement.
 int getResultSetConcurrency()
          Returns result set concurrency mode.
 int getResultSetType()
          Returns result set scroll type.
 int getUpdateCount()
          Returns the records count of the last executed statement.
 java.sql.SQLWarning getWarnings()
          Gets the first SQLWarning that has been reported for this object.
 boolean isClosed()
          Returns the session open status.
 java.lang.String queryName()
          Retrieves the name of the listener.
static java.lang.String resultSetConcurToString(int concur)
          Gets the symbol string corresponding to the ResultSet Concurrency enumeration.
static java.lang.String resultSetDirToString(int dir)
          Gets the symbol string corresponding to the ResultSet Direction enumeration.
static java.lang.String resultSetTypeToString(int type)
          Gets the symbol string corresponding to the ResultSet Type enumeration.
 void sessionClose(com.stc.connector.db.SessionEvent evt)
          Processes a sessionClose event.
 void sessionOpen(com.stc.connector.db.SessionEvent evt)
          Processes a sessionOpen event.
 void sessionReset(com.stc.connector.db.SessionEvent evt)
          Processes a sessionReset event.
 void setCursorName(java.lang.String sName)
          Sets result set cursor name.
 void setEscapeProcessing(boolean bEscape)
          Sets escape syntax processing mode.
 void setFetchDirection(int fetchDirection)
          Sets result set fetch direction.
 void setFetchSize(int nSize)
          Sets result set prefetch record count.
 void setMaxFieldSize(int nSize)
          Sets maximum data size for a column.
 void setMaxRows(int nRow)
          Sets maximum number of fetch records.
 void setQueryTimeout(int nInterval)
          Sets query timeout duration.
 java.lang.Object stmtInvoke(java.lang.String methodName, java.lang.Class[] argumentClasses, java.lang.Object[] arguments)
          Invokes a method of the database Statement object of this ETD.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

statementClassName

protected java.lang.String statementClassName
StatementAgent instance class name.


session

protected com.stc.connector.db.Session session
A Session instance that holds the connection information.


statement

protected java.sql.Statement statement
A Statement instance used for SQL operations.


sqlException

protected java.sql.SQLException sqlException
A SQLException instance used for holding error information.


listener

protected com.stc.connector.db.StatementEventListener listener
A StatementEventListener instance.


resultsetType

protected int resultsetType
Current resultset type.


concurrencyType

protected int concurrencyType
Current concurrency type.


resultsetDirection

protected int resultsetDirection
Current resultset direction.


resultSetTypeMap

protected static java.util.HashMap resultSetTypeMap
Map resultset type to string.


resultSetDirMap

protected static java.util.HashMap resultSetDirMap
Map resultset direction to string.


resultSetConcurMap

protected static java.util.HashMap resultSetConcurMap
Map resultet concurrency to string.

Constructor Detail

StatementAgentImpl

protected StatementAgentImpl()
Default StatementAgentImpl constructor


StatementAgentImpl

protected StatementAgentImpl(com.stc.connector.db.Session session)
StatementAgentImpl constructor

Parameters:
session - a Session instance for allocating necessary resources for this StatementAgentImpl.

StatementAgentImpl

protected StatementAgentImpl(com.stc.connector.db.Session session,
                             int resultsetType,
                             int concurrencyType)
StatementAgentImpl constructor

Parameters:
session - a Session instance for allocating necessary resources for this StatementAgentImpl.
resultsetType - resultset type; TYPE_FORWARD_ONLY, TYPE_SCROLL_INSENSITIVE, TYPE_SCROLL_SENSITIVE
concurrencyType - concurrency type; CONCUR_READ_ONLY, CONCUR_UPDATABLE
Method Detail

resultSetTypeToString

public static java.lang.String resultSetTypeToString(int type)
Gets the symbol string corresponding to the ResultSet Type enumeration.

Parameters:
type - result set type.
Returns:
enumeration symbol string.

resultSetDirToString

public static java.lang.String resultSetDirToString(int dir)
Gets the symbol string corresponding to the ResultSet Direction enumeration.

Parameters:
dir - result set direction.
Returns:
enumeration symbol string.

resultSetConcurToString

public static java.lang.String resultSetConcurToString(int concur)
Gets the symbol string corresponding to the ResultSet Concurrency enumeration.

Parameters:
concur - concurrency type.
Returns:
enumeration symbol string.

isClosed

public boolean isClosed()
Returns the session open status.

Specified by:
isClosed in interface com.stc.connector.appconn.db.StatementAgent
Returns:
true if close() method has been called or connection has never established; false otherwise.

queryName

public java.lang.String queryName()
Retrieves the name of the listener.

Specified by:
queryName in interface com.stc.connector.appconn.db.StatementAgent
Specified by:
queryName in interface com.stc.connector.db.SessionEventListener
Returns:
the listener's class name.

sessionOpen

public void sessionOpen(com.stc.connector.db.SessionEvent evt)
Processes a sessionOpen event. It will create a Statement object to process SQL operations.

Specified by:
sessionOpen in interface com.stc.connector.db.SessionEventListener
Parameters:
evt - a Session event which signals the connection is open.

sessionClose

public void sessionClose(com.stc.connector.db.SessionEvent evt)
Processes a sessionClose event. It will release the Statement object and session event listener.

Specified by:
sessionClose in interface com.stc.connector.db.SessionEventListener
Parameters:
evt - a Session event which signals the connection is close.

sessionReset

public void sessionReset(com.stc.connector.db.SessionEvent evt)
Processes a sessionReset event. It will release the session event listener and clear all the batch operations and warnings.

Specified by:
sessionReset in interface com.stc.connector.db.SessionEventListener
Parameters:
evt - a Session event which signals the connection is reset.

getResultSetType

public int getResultSetType()
                     throws java.sql.SQLException
Returns result set scroll type.

Specified by:
getResultSetType in interface com.stc.connector.appconn.db.StatementAgent
Returns:
the result set type. It can be either TYPE_FORWARD_ONLY, TYPE_SCROLL_INSENSITIVE and TYPE_SCROLL_SENSITIVE.
Throws:
java.sql.SQLException - when SQL problems occur.

getResultSetConcurrency

public int getResultSetConcurrency()
                            throws java.sql.SQLException
Returns result set concurrency mode.

Specified by:
getResultSetConcurrency in interface com.stc.connector.appconn.db.StatementAgent
Returns:
the result set concurrency mode. It can be either CONCUR_READ_ONLY or CONCUR_UPDATABLE.
Throws:
java.sql.SQLException - when SQL problems occur.

setEscapeProcessing

public void setEscapeProcessing(boolean bEscape)
                         throws java.sql.SQLException
Sets escape syntax processing mode. When enable, the driver will scan for any escape syntax and do escape substitution before sending the escapted SQL statement to the database.

Specified by:
setEscapeProcessing in interface com.stc.connector.appconn.db.StatementAgent
Parameters:
bEscape - true to enable escape scanning; false otherwise.
Throws:
java.sql.SQLException - when SQL problems occur.

setCursorName

public void setCursorName(java.lang.String sName)
                   throws java.sql.SQLException
Sets result set cursor name.

Specified by:
setCursorName in interface com.stc.connector.appconn.db.StatementAgent
Parameters:
sName - a cursor name.
Throws:
java.sql.SQLException - when SQL problems occur.

getQueryTimeout

public int getQueryTimeout()
                    throws java.sql.SQLException
Returns query timeout duration.

Specified by:
getQueryTimeout in interface com.stc.connector.appconn.db.StatementAgent
Returns:
the query timout limit in second.
Throws:
java.sql.SQLException - when SQL problems occur.

setQueryTimeout

public void setQueryTimeout(int nInterval)
                     throws java.sql.SQLException
Sets query timeout duration.

Specified by:
setQueryTimeout in interface com.stc.connector.appconn.db.StatementAgent
Parameters:
nInterval - the query timeout limit in second.
Throws:
java.sql.SQLException - when SQL problems occur.

getFetchDirection

public int getFetchDirection()
                      throws java.sql.SQLException
Returns result set fetch direction.

Specified by:
getFetchDirection in interface com.stc.connector.appconn.db.StatementAgent
Returns:
the fetch direction.
Throws:
java.sql.SQLException - when SQL problems occur.

setFetchDirection

public void setFetchDirection(int fetchDirection)
                       throws java.sql.SQLException
Sets result set fetch direction.

Specified by:
setFetchDirection in interface com.stc.connector.appconn.db.StatementAgent
Parameters:
fetchDirection - the fetch direction hint: FETCH_FORWARD, FETCH_REVERSE or FETCH_UNKNOWN.
Throws:
java.sql.SQLException - when SQL problems occur.

getFetchSize

public int getFetchSize()
                 throws java.sql.SQLException
Returns result set prefetch record count.

Specified by:
getFetchSize in interface com.stc.connector.appconn.db.StatementAgent
Returns:
number of rows to be fetched at a time
Throws:
java.sql.SQLException - when SQL problems occur.

setFetchSize

public void setFetchSize(int nSize)
                  throws java.sql.SQLException
Sets result set prefetch record count.

Specified by:
setFetchSize in interface com.stc.connector.appconn.db.StatementAgent
Parameters:
nSize - number of rows to be fetched at a time
Throws:
java.sql.SQLException - when SQL problems occur.

getMaxRows

public int getMaxRows()
               throws java.sql.SQLException
Gets the maximum number of fetch records in a result set.

Specified by:
getMaxRows in interface com.stc.connector.appconn.db.StatementAgent
Returns:
the maximum number of fetch records.
Throws:
java.sql.SQLException - when SQL problems occur.

setMaxRows

public void setMaxRows(int nRow)
                throws java.sql.SQLException
Sets maximum number of fetch records.

Specified by:
setMaxRows in interface com.stc.connector.appconn.db.StatementAgent
Parameters:
nRow - the maximum number of rows in a result set. zero means no limit.
Throws:
java.sql.SQLException - when SQL problems occur.

getMaxFieldSize

public int getMaxFieldSize()
                    throws java.sql.SQLException
Gets the maximum data size for a column.

Specified by:
getMaxFieldSize in interface com.stc.connector.appconn.db.StatementAgent
Returns:
the maximum data size for a column.
Throws:
java.sql.SQLException - when SQL problems occur.

setMaxFieldSize

public void setMaxFieldSize(int nSize)
                     throws java.sql.SQLException
Sets maximum data size for a column.

Specified by:
setMaxFieldSize in interface com.stc.connector.appconn.db.StatementAgent
Parameters:
nSize - the maximum column size limit in bytes; zero means no limit.
Throws:
java.sql.SQLException - when SQL problems occur.

getUpdateCount

public int getUpdateCount()
                   throws java.sql.SQLException
Returns the records count of the last executed statement.

Specified by:
getUpdateCount in interface com.stc.connector.appconn.db.StatementAgent
Returns:
the number of records affected by the update operation.
Throws:
java.sql.SQLException - when SQL problems occur.

getResultSet

public com.stc.connector.appconn.db.ResultSetAgent getResultSet()
                                                         throws java.sql.SQLException
Returns the result set of last executed statement.

Specified by:
getResultSet in interface com.stc.connector.appconn.db.StatementAgent
Returns:
a ResultSetAgent instance which holds the result set.
Throws:
java.sql.SQLException - when SQL problems occur.

getMoreResults

public boolean getMoreResults()
                       throws java.sql.SQLException
Checks if there are more result set.

Specified by:
getMoreResults in interface com.stc.connector.appconn.db.StatementAgent
Returns:
true if the next result is a result set.
Throws:
java.sql.SQLException - when SQL problems occur.

clearBatch

public void clearBatch()
                throws java.sql.SQLException
Clears the batch of operations.

Specified by:
clearBatch in interface com.stc.connector.appconn.db.StatementAgent
Throws:
java.sql.SQLException - when SQL problems occur.

executeBatch

public int[] executeBatch()
                   throws java.sql.SQLException
Executes a batch of SQL statements.

Specified by:
executeBatch in interface com.stc.connector.appconn.db.StatementAgent
Returns:
an array of execution status of each command in the batch.
Throws:
java.sql.SQLException - when SQL problems occur.

cancel

public void cancel()
            throws java.sql.SQLException
Cancels statement results.

Specified by:
cancel in interface com.stc.connector.appconn.db.StatementAgent
Throws:
java.sql.SQLException - when SQL problems occur.

getWarnings

public java.sql.SQLWarning getWarnings()
                                throws java.sql.SQLException
Gets the first SQLWarning that has been reported for this object.

Specified by:
getWarnings in interface com.stc.connector.appconn.db.StatementAgent
Returns:
SQL Warning
Throws:
java.sql.SQLException - when SQL problems occur. when SQL problems occur.

clearWarnings

public void clearWarnings()
                   throws java.sql.SQLException
Clear all SQLWarning objects.

Specified by:
clearWarnings in interface com.stc.connector.appconn.db.StatementAgent
Throws:
java.sql.SQLException - when SQL problems occur.

stmtInvoke

public java.lang.Object stmtInvoke(java.lang.String methodName,
                                   java.lang.Class[] argumentClasses,
                                   java.lang.Object[] arguments)
                            throws java.lang.Exception
Invokes a method of the database Statement object of this ETD.

Specified by:
stmtInvoke in interface com.stc.connector.appconn.db.StatementAgent
Parameters:
methodName - the name of the method
argumentClasses - Class array for types of formal arguments for method, in the declared order. Can be null if there are no formal arguments. However, cannot invoke constructor here.
arguments - Object array of formal arguments for method in the declared order. Can be null if there are no formal arguments. However, cannot invoke constructor here.
Returns:
the Object instance resulting from the method invocation. Can be null if nothing is returned (void return declaration).
Throws:
java.lang.Exception - whatever exception the invoked method throws.

Sun Adapter for DB2 Universal Database