Sun Adapter for VSAM

com.stc.connector.vsamadapter.base
Class SessionImpl

java.lang.Object
  extended by com.stc.connector.vsamadapter.base.SessionImpl
All Implemented Interfaces:
com.stc.connector.db.Session
Direct Known Subclasses:
VSAMSession

public class SessionImpl
extends java.lang.Object
implements com.stc.connector.db.Session

Session hosts a Connection interface.

Version:
$Revision: 1.8 $
Author:
$Author: pveerava $

Field Summary
protected  boolean bSupportsBatch
          Indicator for the driver support of batch processing.
protected  java.sql.Connection conn
          A Connection instance to the database.
protected  javax.sql.DataSource dataSource
          A DataSource instance used for creating database connection.
protected  int dbms
          Database type.
protected  java.sql.DatabaseMetaData dmd
          A database metadata instance for discovering database information.
protected  boolean isConnected
           
protected  java.lang.String password
          Password for database login.
protected  java.util.Vector sessionEventListeners
          A vector of Session event listners.
protected  java.sql.SQLException sqlException
          A SQLException instance used to hold the last exception.
protected  java.lang.String userName
          User name for database login.
 
Fields inherited from interface com.stc.connector.db.Session
DBMS_TYPE_UNKNOWN
 
Constructor Summary
SessionImpl(javax.sql.DataSource dataSource, java.lang.String userName, java.lang.String password)
          SessionImpl constructor.
 
Method Summary
 java.sql.Connection addSessionEventListener(com.stc.connector.db.SessionEventListener listener)
          Adds sessoin event listener.
 void checkConnection(java.sql.SQLException sqlException)
          Connection status check if there is a SQL exception.
 void close()
          Closes the session.
 void commit()
          Commits a transaction for the connection.
 void connect()
          Connects to a database.
 java.lang.Object connInvoke(java.lang.String methodName, java.lang.Class[] argsCls, java.lang.Object[] args)
          Invokes a method of the database Connection object of this ETD.
 boolean getAutoCommit()
          Returns the session auto commit property.
 java.lang.String getCatalog()
          Returns the session catalog property.
 int getConcurrencyType()
          Get concurrency type.
 java.sql.Connection getConnection()
          Get the database Connection object of this ETD.
 int getDBMS()
          Retrieves the DBMS type.
 java.sql.DatabaseMetaData getMetaData()
          Returns the session database meta data.
 boolean getNewTypeFlag()
          Check if it is a new ResultSet type.
 int getResultSetType()
          Get result set type.
 boolean getSupportsBatch()
          checks to see if the driver supports batch operations.
 int getTransactionIsolation()
          Returns the session transaction isolation level.
 java.util.Map getTypeMap()
          Returns the session type map for user-defined type.
protected  void inValidateConnection(java.sql.SQLException sqle)
          Sets the flag inside JDBC Connector for invalid connection when an exception occurs.
 boolean isClosed()
          Returns the session open status.
 boolean isConnected()
          Returns the connection status.
 boolean isReadOnly()
          Returns the session read only status.
 void open()
          Opens the session.
 void releaseResources()
          Releases connection resources.
 boolean removeSessionEventListener(com.stc.connector.db.SessionEventListener listener)
          Removes sessoin event listener.
 void requestReset()
          Request that a reset be done on the data content of the DB ETD.
 void rollback()
          Rollbacks a transaction for the connection.
 void setAutoCommit(boolean bAuto)
          Sets the session auto commit property.
 void setCatalog(java.lang.String sCatalog)
          Sets the session catalog property.
 void setConcurrencyType(int concurrencyType)
          Set the concurrency type of the connection.
 void setDBMS(int dbmsType)
          Sets the DBMS type.
 void setNewTypeFlag(boolean bNew)
          Set whether this is a new ResultSet type.
 void setReadOnly(boolean bRead)
          Sets the session read only property.
 void setResultSetType(int resultSetType)
          Set the resultset type of the connection.
 void setTransactionIsolation(int iLevel)
          Sets the session transaction isolation level.
 void setTypeMap(java.util.Map map)
          Sets the session type map for user-defined type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dataSource

protected javax.sql.DataSource dataSource
A DataSource instance used for creating database connection.


conn

protected java.sql.Connection conn
A Connection instance to the database.


dmd

protected java.sql.DatabaseMetaData dmd
A database metadata instance for discovering database information.


sqlException

protected java.sql.SQLException sqlException
A SQLException instance used to hold the last exception.


userName

protected java.lang.String userName
User name for database login.


password

protected java.lang.String password
Password for database login.


dbms

protected int dbms
Database type.


sessionEventListeners

protected java.util.Vector sessionEventListeners
A vector of Session event listners.


bSupportsBatch

protected boolean bSupportsBatch
Indicator for the driver support of batch processing.


isConnected

protected boolean isConnected
Constructor Detail

SessionImpl

public SessionImpl(javax.sql.DataSource dataSource,
                   java.lang.String userName,
                   java.lang.String password)
SessionImpl constructor.

Parameters:
dataSource - a DataSource instance used to create a connection.
userName - user name for login.
password - password for login.
Method Detail

connect

public void connect()
             throws java.sql.SQLException
Connects to a database.

Specified by:
connect in interface com.stc.connector.db.Session
Throws:
java.sql.SQLException - when SQL problems occur.

open

public void open()
          throws java.sql.SQLException
Opens the session.

Specified by:
open in interface com.stc.connector.db.Session
Throws:
java.sql.SQLException - when SQL problems occur.

releaseResources

public void releaseResources()
                      throws java.sql.SQLException
Releases connection resources.

Specified by:
releaseResources in interface com.stc.connector.db.Session
Throws:
java.sql.SQLException - when SQL problems occur.

close

public void close()
           throws java.sql.SQLException
Closes the session.

Specified by:
close in interface com.stc.connector.db.Session
Throws:
java.sql.SQLException - when SQL problems occur.

isClosed

public boolean isClosed()
                 throws java.sql.SQLException
Returns the session open status.

Specified by:
isClosed in interface com.stc.connector.db.Session
Returns:
true if close() method has been called or connection has never established; false otherwise.
Throws:
java.sql.SQLException - when SQL problems occur.

getAutoCommit

public boolean getAutoCommit()
                      throws java.sql.SQLException
Returns the session auto commit property.

Specified by:
getAutoCommit in interface com.stc.connector.db.Session
Returns:
true if AutoCommit is set to true; false otherwise.
Throws:
java.sql.SQLException - when SQL problems occur.

setAutoCommit

public void setAutoCommit(boolean bAuto)
                   throws java.sql.SQLException
Sets the session auto commit property.

Specified by:
setAutoCommit in interface com.stc.connector.db.Session
Parameters:
bAuto - true if auto commit is desired;false otherwise.
Throws:
java.sql.SQLException - when SQL problems occur.

getCatalog

public java.lang.String getCatalog()
                            throws java.sql.SQLException
Returns the session catalog property.

Specified by:
getCatalog in interface com.stc.connector.db.Session
Returns:
the name of the catalog of this connection.
Throws:
java.sql.SQLException - when SQL problems occur.

setCatalog

public void setCatalog(java.lang.String sCatalog)
                throws java.sql.SQLException
Sets the session catalog property.

Specified by:
setCatalog in interface com.stc.connector.db.Session
Parameters:
sCatalog - the desired name of the catalog.
Throws:
java.sql.SQLException - when SQL problems occur.

isReadOnly

public boolean isReadOnly()
                   throws java.sql.SQLException
Returns the session read only status.

Specified by:
isReadOnly in interface com.stc.connector.db.Session
Returns:
true if the database supports read-only; false otherwise.
Throws:
java.sql.SQLException - when SQL problems occur.

setReadOnly

public void setReadOnly(boolean bRead)
                 throws java.sql.SQLException
Sets the session read only property. This is just a hint to the database, which does not necessarily prevents write operations.

Specified by:
setReadOnly in interface com.stc.connector.db.Session
Parameters:
bRead - true if read-only operations are desired; false otherwise.
Throws:
java.sql.SQLException - when SQL problems occur.

getTypeMap

public java.util.Map getTypeMap()
                         throws java.sql.SQLException
Returns the session type map for user-defined type.

Specified by:
getTypeMap in interface com.stc.connector.db.Session
Returns:
type map for user-defined type.
Throws:
java.sql.SQLException - when SQL problems occur.

setTypeMap

public void setTypeMap(java.util.Map map)
                throws java.sql.SQLException
Sets the session type map for user-defined type.

Specified by:
setTypeMap in interface com.stc.connector.db.Session
Parameters:
map - the Map object that contains the mapping from SQL type names for user-defined types to Java classes.
Throws:
java.sql.SQLException - when SQL problems occur.

getMetaData

public java.sql.DatabaseMetaData getMetaData()
                                      throws java.sql.SQLException
Returns the session database meta data.

Specified by:
getMetaData in interface com.stc.connector.db.Session
Returns:
a database metadata object.
Throws:
java.sql.SQLException - when SQL problems occur.

getTransactionIsolation

public int getTransactionIsolation()
                            throws java.sql.SQLException
Returns the session transaction isolation level.

Specified by:
getTransactionIsolation in interface com.stc.connector.db.Session
Returns:
the transaction isolation level: TRANSACTION_NONE, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_READ_COMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE.
Throws:
java.sql.SQLException - when SQL problems occur.

setTransactionIsolation

public void setTransactionIsolation(int iLevel)
                             throws java.sql.SQLException
Sets the session transaction isolation level.

Specified by:
setTransactionIsolation in interface com.stc.connector.db.Session
Parameters:
iLevel - a transaction isolation value: TRANSACTION_NONE, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_READ_COMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE.
Throws:
java.sql.SQLException - when SQL problems occur.

commit

public void commit()
            throws java.sql.SQLException
Commits a transaction for the connection. All data changes will be permanent.

Specified by:
commit in interface com.stc.connector.db.Session
Throws:
java.sql.SQLException - if there is any problem in commiting a transaction.

rollback

public void rollback()
              throws java.sql.SQLException
Rollbacks a transaction for the connection. All data changes will be cleared.

Specified by:
rollback in interface com.stc.connector.db.Session
Throws:
java.sql.SQLException - if there is any problem in rolling back a transaction.

addSessionEventListener

public java.sql.Connection addSessionEventListener(com.stc.connector.db.SessionEventListener listener)
Adds sessoin event listener.

Specified by:
addSessionEventListener in interface com.stc.connector.db.Session
Parameters:
listener - a StatmentAgent that wants to be notified when a Session event occurs.
Returns:
a database Connection instance.

removeSessionEventListener

public boolean removeSessionEventListener(com.stc.connector.db.SessionEventListener listener)
Removes sessoin event listener.

Specified by:
removeSessionEventListener in interface com.stc.connector.db.Session
Parameters:
listener - a StatmentAgent that no longer will be notified when a Session event occurs.
Returns:
true if the removal is successful; false otherwise.

checkConnection

public void checkConnection(java.sql.SQLException sqlException)
                     throws java.sql.SQLException
Connection status check if there is a SQL exception.

Specified by:
checkConnection in interface com.stc.connector.db.Session
Parameters:
sqlException - a SQLException instance.
Throws:
java.sql.SQLException - when SQL problems occur.

setDBMS

public void setDBMS(int dbmsType)
             throws java.sql.SQLException
Sets the DBMS type.

Specified by:
setDBMS in interface com.stc.connector.db.Session
Parameters:
dbmsType - the database vendor type.
Throws:
java.sql.SQLException - if there is any SQL problem.

getDBMS

public int getDBMS()
Retrieves the DBMS type.

Specified by:
getDBMS in interface com.stc.connector.db.Session
Returns:
the DBMS type of the current session.
See Also:
Session.DBMS_TYPE_UNKNOWN, #DBMS_TYPE_ORACLE, #DBMS_TYPE_SYBASE, #DBMS_TYPE_MSSQL, #DBMS_TYPE_DB2, #DBMS_TYPE_SEQUELINK, #DBMS_TYPE_ATTUNITY

getSupportsBatch

public boolean getSupportsBatch()
checks to see if the driver supports batch operations.

Specified by:
getSupportsBatch in interface com.stc.connector.db.Session
Returns:
true if the driver supports batch operations;false otherwise.

requestReset

public void requestReset()
Request that a reset be done on the data content of the DB ETD.

Specified by:
requestReset in interface com.stc.connector.db.Session

connInvoke

public java.lang.Object connInvoke(java.lang.String methodName,
                                   java.lang.Class[] argsCls,
                                   java.lang.Object[] args)
                            throws java.lang.Exception
Invokes a method of the database Connection object of this ETD.

Specified by:
connInvoke in interface com.stc.connector.db.Session
Parameters:
methodName - the name of the method
argsCls - 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.
args - 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.

getConnection

public java.sql.Connection getConnection()
Get the database Connection object of this ETD.

Specified by:
getConnection in interface com.stc.connector.db.Session
Returns:
database Connection object of this ETD.

setResultSetType

public void setResultSetType(int resultSetType)
Set the resultset type of the connection. It will be reseted if as soon as a DB object is created.

Specified by:
setResultSetType in interface com.stc.connector.db.Session
Parameters:
resultSetType - resultset can have the following types: TYPE_FORWARD_ONLY, TYPE_SCROLL_INSENSITIVE, TYPE_SCROLL_SENSITIVE.

getResultSetType

public int getResultSetType()
Get result set type.

Specified by:
getResultSetType in interface com.stc.connector.db.Session
Returns:
result set type of this session at this moment.

setConcurrencyType

public void setConcurrencyType(int concurrencyType)
Set the concurrency type of the connection. It will be reseted if as soon as a DB object is created.

Specified by:
setConcurrencyType in interface com.stc.connector.db.Session
Parameters:
concurrencyType - concurrency can have the following types: CONCUR_READ_ONLY, CONCUR_UPDATABLE

getConcurrencyType

public int getConcurrencyType()
Get concurrency type.

Specified by:
getConcurrencyType in interface com.stc.connector.db.Session
Returns:
concurrency type of this session at this moment

setNewTypeFlag

public void setNewTypeFlag(boolean bNew)
Set whether this is a new ResultSet type.

Specified by:
setNewTypeFlag in interface com.stc.connector.db.Session
Parameters:
bNew - a boolean value to indicate if the ResultSet type is modified.

getNewTypeFlag

public boolean getNewTypeFlag()
Check if it is a new ResultSet type.

Specified by:
getNewTypeFlag in interface com.stc.connector.db.Session
Returns:
boolean value to indicate if the ResultSet type has been modified.

isConnected

public boolean isConnected()
Returns the connection status.

Specified by:
isConnected in interface com.stc.connector.db.Session
Returns:
true if connection is broken or not established; false otherwise.

inValidateConnection

protected void inValidateConnection(java.sql.SQLException sqle)
Sets the flag inside JDBC Connector for invalid connection when an exception occurs. The flag inside ConnectionHolder is checked by ManagedConnectionFactory to determine if the connection is invalid and removed from the connectionPool by the application server. (see com.stc.gjc.spi.CPManagedConnectionFactory method getInvalidConnections for implementation details.


Sun Adapter for VSAM