Sybase eWay API

com.stc.connector.sybaseadapter.base
Class DbConnectorImpl

java.lang.Object
  extended by com.stc.connector.sybaseadapter.base.DbConnectorImpl
All Implemented Interfaces:
com.stc.connector.db.DbConnector
Direct Known Subclasses:
SybaseConnector

public class DbConnectorImpl
extends java.lang.Object
implements com.stc.connector.db.DbConnector

Connector class implementation for database e*Way.

Version:
$Revision: 1.7 $
Author:
$Author: pveerava $

Field Summary
protected  com.stc.connector.db.AgentFactory agentFactory
          An AgentFactory object to create other StatementAgent instance.
protected  boolean bInit
          A flag to indicate if initilization has taken place.
protected  com.stc.connector.db.Session session
          A Session object to hold connection information.
 
Constructor Summary
DbConnectorImpl()
          Default constructor.
 
Method Summary
 void close()
          Requests the DbConnector to close a connection and release all the necessary resources.
 void commit()
          Commits a transaction for the connection.
 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()
          Gets the AutoCommit mode of the connection.
 java.lang.String getCatalog()
          Gets the catalog name of the connection.
 java.sql.Connection getConnection()
          Get the database Connection object of this ETD.
 com.stc.connector.appconn.db.StatementAgent getInstance(java.lang.Class clsAgent)
          Gets an instance of the named StaementAgent.
 com.stc.connector.appconn.db.StatementAgent getInstance(java.lang.Class clsAgent, int iScroll, int iConcur)
          Gets an instance of the named StaementAgent with the specified resultset and concurrency types.
 int getTransactionIsolation()
          Gets the transaction isolation level for the connection.
 void init(javax.sql.DataSource ds, java.util.Properties props)
          Initialize DbConnector
 boolean isConnected()
          Returns the connection status.
 boolean isOpen()
          Checks if the DbConnector has a open connection.
static void main(java.lang.String[] args)
          Main test program.
 void open(javax.sql.DataSource ds, java.util.Properties props)
          Requests the DbConnector object to open a connection and allocate necessary resources.
 void release()
          Releases all the DbConnector resources.
 void requestReset()
          Receives a request to reset the data content of the DB ETD.
 void rollback()
          Rollbacks a transaction for the connection.
 void setAutoCommit(boolean bAuto)
          Sets the AutoCommit mode of the connection.
 void setCatalog(java.lang.String sCatalog)
          Sets the catalog name of the connection.
 void setConcurrencyToReadOnly()
          Set concurrency type of the session to read only.
 void setConcurrencyToUpdatable()
          Set concurrency type of the session to updatable.
protected  void setConcurrencyType(int concurrencyType)
          Set the concurrency type of the connection.
protected  void setResultSetType(int resultSetType)
          Set the resultset type of the connection.
 void setRSReadOnly()
          Force it to read only so that we can satisfy Clover tests.
 void setScrollTypeToForwardOnly()
          Set result set type of the session to be forward only.
 void setScrollTypeToScrollInsensitive()
          Set result set type of the session to be insensitive.
 void setScrollTypeToScrollSensitive()
          Set result set type of the session to be sensitive.
 void setTransactionIsolation(int iLevel)
          Sets the transaction isolation level for the connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

session

protected com.stc.connector.db.Session session
A Session object to hold connection information.


agentFactory

protected com.stc.connector.db.AgentFactory agentFactory
An AgentFactory object to create other StatementAgent instance.


bInit

protected boolean bInit
A flag to indicate if initilization has taken place.

Constructor Detail

DbConnectorImpl

public DbConnectorImpl()
Default constructor.

Method Detail

init

public void init(javax.sql.DataSource ds,
                 java.util.Properties props)
          throws java.sql.SQLException
Initialize DbConnector

Specified by:
init in interface com.stc.connector.db.DbConnector
Parameters:
ds - a DataSource object used to establish connection.
props - a property object which consists of connecton information.
Throws:
java.sql.SQLException - owing to session creation.

open

public void open(javax.sql.DataSource ds,
                 java.util.Properties props)
          throws java.sql.SQLException
Requests the DbConnector object to open a connection and allocate necessary resources.

Specified by:
open in interface com.stc.connector.db.DbConnector
Parameters:
ds - a DataSource object used to establish connection.
props - a property object which consists of connecton information.
Throws:
java.sql.SQLException - owing to opening a connection.

isOpen

public boolean isOpen()
               throws java.sql.SQLException
Checks if the DbConnector has a open connection.

Specified by:
isOpen in interface com.stc.connector.db.DbConnector
Returns:
true if the connection is still oper; false otherwise.
Throws:
java.sql.SQLException - if errors are encountered during connection checking.

isConnected

public boolean isConnected()
Returns the connection status.

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

close

public void close()
           throws java.sql.SQLException
Requests the DbConnector to close a connection and release all the necessary resources.

Specified by:
close in interface com.stc.connector.db.DbConnector
Throws:
java.sql.SQLException - when encountering any error in closing a connection.

release

public void release()
Releases all the DbConnector resources.

Specified by:
release in interface com.stc.connector.db.DbConnector

getInstance

public com.stc.connector.appconn.db.StatementAgent getInstance(java.lang.Class clsAgent)
                                                        throws java.sql.SQLException
Gets an instance of the named StaementAgent. Only one instance of this class will be created. The same instance will be retrieved if it has been created.

Specified by:
getInstance in interface com.stc.connector.db.DbConnector
Parameters:
clsAgent - the class of the StatementAgent.
Returns:
the named StatementAgent instance.
Throws:
java.sql.SQLException - if it encounters errors in instantiating the named class.

getInstance

public com.stc.connector.appconn.db.StatementAgent getInstance(java.lang.Class clsAgent,
                                                               int iScroll,
                                                               int iConcur)
                                                        throws java.sql.SQLException
Gets an instance of the named StaementAgent with the specified resultset and concurrency types. Only one instance of this class will be created. The same instance will be retrieved if it has been created.

Specified by:
getInstance in interface com.stc.connector.db.DbConnector
Parameters:
clsAgent - the class of the StatementAgent.
iScroll - resultset type; TYPE_FORWARD_ONLY, TYPE_SCROLL_INSENSITIVE, TYPE_SCROLL_SENSITIVE
iConcur - concurrency type; CONCUR_READ_ONLY, CONCUR_UPDATABLE
Returns:
the named StatementAgent instance.
Throws:
java.sql.SQLException - if it encounters errors in instantiating the named class.

getAutoCommit

public boolean getAutoCommit()
                      throws java.sql.SQLException
Gets the AutoCommit mode of the connection.

Specified by:
getAutoCommit in interface com.stc.connector.db.DbConnector
Returns:
true if the Autocommit mode is true; false otherwise.
Throws:
java.sql.SQLException - if there is any error in getting the AutoCommit mode from the database.

setAutoCommit

public void setAutoCommit(boolean bAuto)
                   throws java.sql.SQLException
Sets the AutoCommit mode of the connection.

Specified by:
setAutoCommit in interface com.stc.connector.db.DbConnector
Parameters:
bAuto - a true value will set the connection to be in AutoCommit mode; false otherwise.
Throws:
java.sql.SQLException - if there is any problem in setting the AutoCommit mode.

getCatalog

public java.lang.String getCatalog()
                            throws java.sql.SQLException
Gets the catalog name of the connection.

Specified by:
getCatalog in interface com.stc.connector.db.DbConnector
Returns:
the catalog name.
Throws:
java.sql.SQLException - if there is any problem in getting the catalog name.

setCatalog

public void setCatalog(java.lang.String sCatalog)
                throws java.sql.SQLException
Sets the catalog name of the connection.

Specified by:
setCatalog in interface com.stc.connector.db.DbConnector
Parameters:
sCatalog - the desired catalog name.
Throws:
java.sql.SQLException - if there is any problem in setting the catalog name.

getTransactionIsolation

public int getTransactionIsolation()
                            throws java.sql.SQLException
Gets the transaction isolation level for the connection.

Specified by:
getTransactionIsolation in interface com.stc.connector.db.DbConnector
Returns:
the transaction isolation level: TRANSACTION_NONE, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_READ_COMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE.
Throws:
java.sql.SQLException - if there is any error in getting the transaction isolation level.

setTransactionIsolation

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

Specified by:
setTransactionIsolation in interface com.stc.connector.db.DbConnector
Parameters:
iLevel - a transaction isolation value: TRANSACTION_NONE, TRANSACTION_READ_UNCOMMITTED, TRANSACTION_READ_COMMITTED, TRANSACTION_REPEATABLE_READ, TRANSACTION_SERIALIZABLE.
Throws:
java.sql.SQLException - if there is any problem in setting the transaction isolation level.

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.DbConnector
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.DbConnector
Throws:
java.sql.SQLException - if there is any problem in rolling back a transaction.

requestReset

public void requestReset()
Receives a request to reset the data content of the DB ETD.

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

connInvoke

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

Specified by:
connInvoke in interface com.stc.connector.db.DbConnector
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.sql.SQLException - whatever exception the invoked method throws.

getConnection

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

Specified by:
getConnection in interface com.stc.connector.db.DbConnector
Returns:
the database Connection object of this ETD.
Throws:
java.sql.SQLException - owing to connection retrieval.

setResultSetType

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

Parameters:
resultSetType - resultset can have the following types: TYPE_FORWARD_ONLY, TYPE_SCROLL_INSENSITIVE, TYPE_SCROLL_SENSITIVE.
Throws:
java.sql.SQLException - if there is any problem in setting the resultset type.

setConcurrencyType

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

Parameters:
concurrencyType - concurrency can have the following types: CONCUR_READ_ONLY, CONCUR_UPDATABLE
Throws:
java.sql.SQLException - if there is any problem in setting the concurrency type.

setScrollTypeToForwardOnly

public void setScrollTypeToForwardOnly()
                                throws java.sql.SQLException
Set result set type of the session to be forward only.

Specified by:
setScrollTypeToForwardOnly in interface com.stc.connector.db.DbConnector
Throws:
java.sql.SQLException - if there is any problem in setting result set type.

setScrollTypeToScrollInsensitive

public void setScrollTypeToScrollInsensitive()
                                      throws java.sql.SQLException
Set result set type of the session to be insensitive.

Specified by:
setScrollTypeToScrollInsensitive in interface com.stc.connector.db.DbConnector
Throws:
java.sql.SQLException - if there is any problem in setting result set type.

setScrollTypeToScrollSensitive

public void setScrollTypeToScrollSensitive()
                                    throws java.sql.SQLException
Set result set type of the session to be sensitive.

Specified by:
setScrollTypeToScrollSensitive in interface com.stc.connector.db.DbConnector
Throws:
java.sql.SQLException - if there is any problem in setting result set type.

setConcurrencyToReadOnly

public void setConcurrencyToReadOnly()
                              throws java.sql.SQLException
Set concurrency type of the session to read only.

Specified by:
setConcurrencyToReadOnly in interface com.stc.connector.db.DbConnector
Throws:
java.sql.SQLException - if there is any problem in setting concurrency type.

setConcurrencyToUpdatable

public void setConcurrencyToUpdatable()
                               throws java.sql.SQLException
Set concurrency type of the session to updatable.

Specified by:
setConcurrencyToUpdatable in interface com.stc.connector.db.DbConnector
Throws:
java.sql.SQLException - if there is any problem in setting concurrency type.

setRSReadOnly

public void setRSReadOnly()
Force it to read only so that we can satisfy Clover tests.


main

public static void main(java.lang.String[] args)
Main test program.

Parameters:
args - command line arguments.

Sybase eWay API