AdventNet Web NMS 4 API Specification

com.adventnet.management.transaction
Class ConnectionPool

java.lang.Object
  |
  +--com.adventnet.management.transaction.ConnectionPool

public class ConnectionPool
extends java.lang.Object

ConnectionPool class acts as the gateway for making use of the resources that are pooled. It is a JDBC resource management layer, acts as a driver that performs the resource management functions before passing requests to the database drivers by non-intrusively caches and recycles database resources such as connections, prepared statements and statements.

All database operations in Web NMS are performed via the central resource pool using an instance of this class. Connection Pooling is supported in both transaction and non-transaction mode.

Using this class, you can carry out the following functions :

Prerequisites for using ConnectionPool Getting the handle of ConnectionPool

The first step to access the resources in the pool is to get the ConnectionPool handle. The getInstance() method in ConnectionPool can be used for this purpose. This returns an instance of the already initialized ConnectionPool class, in the same JVM as that of the Web NMS Server. User applications within the same JVM are advised to make use of the ConnectionPool instance created by Web NMS.

Code Snippet :

//getting the handle of ConnectionPool in the sameJVM as of WebNMS
ConnectionPool cp = ConnectionPool.getInstance();

Accessing Connections

Whenever a Connection is requested, the Connection Pool verifies if the request is made by a thread which is in transaction or not.

Code Snippet :

ConnectionPool cp = ConnectionPool.getInstance();
Connection con = cp.getConnection();

Accessing Prepared Statements

Whenever a prepared statement is requested, the Connection Pool verifies if the request is made by a thread which is in transaction or not.

Code Snippet :

// To get a reference of ConnectionPool
ConnectionPool cp = ConnectionPool.getInstance();
//To get a PreparedStatement and execute it.
PreparedStatementWrapper psw = null;
// Get unique ID of the prepared statement
int id = cp.getPreparedStatementID ("select * from ManagedObject where NAME = ?")
try
{
    psw = cp.fetchPreparedStatement(id) ;  // PreparedStatementWrapper reference
    PreparedStatement ps = psw.getPreparedStatement();
    ps.setString(1,"hostname");
}
catch (Exception e)
{
    // handle Exception
}
finally
{
    // To return the prepared statement - IMPORTANT
   cp.returnPreparedStatement(psw);
}

Accessing Statements

A statement requested from a thread involved in transaction, returns the statement from the same connection used in the transaction. A statement requested from a non-transaction mode returns the statement which in not involved in a transaction.

Code Snippet :

// To get the handle of ConnectionPool
ConnectionPool cp = ConnectionPool.getInstance();
// To execute the input SQL query string in an already created Statement
cp.executeQueryStmt(sqlString);
// For database operations like insert, update, delete
cp.executeUpdateStmt(sqlString);


Field Summary
 java.lang.String driverName
          Database Driver name, for eg., sun.jdbc.odbc.JdbcOdbcDriver
 java.lang.String password
          Login password of the database.
 LogUser transUser
          Log User for logging messages to transaction logs.
 java.lang.String url
          Database URL of the form jdbc:subprotocol:DataSourceName.
 java.lang.String userName
          Login user name of the database.
 
Constructor Summary
ConnectionPool()
          Constructs a ConnectionPool with default URL, user name, password and driver name.
ConnectionPool(java.lang.String urlstr, java.lang.String usrname, java.lang.String pwd, java.lang.String drivername)
          Constructs a ConnectionPool with given URL, user name, password and driver name.
ConnectionPool(java.lang.String urlstr, java.lang.String usrname, java.lang.String pwd, java.lang.String drivername, boolean enable, int num_trans, int num_nontrans, java.lang.String conAuth)
          Creates an instance of ConnectionPool.
 
Method Summary
 int addPSToPool(java.lang.String sqlStat)
          Adds the PreparedStatement corresponding the input SQL string to the connection pool and returns an integer ID, which uniquely references the prepared statement.
 void commitAllNonTransactionConnections()
          Commits all the non transaction connections.
 void createConnection(int num_trans, int num_nontrans)
          Creates transaction and non-transaction connections as specified by the input parameters.
 void disconnect()
          Disconnects all connections in the connection pool.
 void disconnectAll()
          Disconnects all connections in the ConnectionPool.
 void execute(java.lang.String sqlString)
          Executes the input SQL string.
 int[] executeBatch(java.sql.PreparedStatement batchedPs)
          Executes a Prepared Statement which is batched with various set of values
 java.sql.ResultSet executeQuery(java.sql.PreparedStatement prstmt)
          Executes the SQL query of the PreparedStatement object passed and returns the result set generated by the query.
 java.sql.ResultSet executeQueryStmt(java.lang.String sqlstr)
          Executes the input SQL query string in an already created Statement contained in ConnectionPool and returns a ResultSet.
 void executeTheStatement(java.lang.Object stm)
          Executes the SQL query as specified by the input.
 int executeUpdate(java.sql.PreparedStatement prstmt)
          Executes the SQL INSERT, UPDATE or DELETE statement in the PreparedStatement object passed and returns the update count(number of records that gets effected into the database).
 int executeUpdateStmt(java.lang.String sqlstr)
          Executes the input SQL query string in an already created Statement contained in ConnectionPool.
 PreparedStatementWrapper fetchPreparedStatement(int id)
          Fetches the preparedStatement from the pool corresponding to the given unique ID.
 void freeConnectionForTransaction()
          Frees the connection associated with a transaction over the current thread.
 java.sql.Connection getConnection()
          Gets a Connection from the ConnectionPool.
 java.sql.Connection getConnectionForTransaction()
          Gets the connection already dedicated to a transaction in the current thread.
 java.sql.Connection getConnectionForTransaction(java.lang.Thread threadObj)
          Gets the connection already dedicated to a transaction over the specified thread.
 java.lang.Integer getConnectionId(java.sql.Connection con)
           
 java.lang.Integer getIdForThread(java.lang.Thread obj)
           
static ConnectionPool getInstance()
          Gets a reference to a ConnectionPool object.
 java.sql.DatabaseMetaData getMetaData()
          Gets comprehensive information about the database as a whole.
 java.sql.DatabaseMetaData getMetaData(java.sql.Connection con)
          Gets comprehensive information about the database as a whole.
 int getNestingLevel()
          Gets the number of nested transactions in the current thread.
 int getNumOfNonTransactionConnections()
          Gets number of connections that are reserved for transactions.
 int getNumOfTransactionConnections()
          Gets number of connections reserved for non-transactional operations.
 java.sql.PreparedStatement getPreparedStatement(java.lang.String sqlstr)
          Gets the PreparedStatement associated with the input SQL string.
 java.sql.PreparedStatement getPreparedStatement(java.lang.String sqlstr, boolean isFromPool)
          Gets the PreparedStatement associated with the input SQL string.
 int getPreparedStatementID(java.lang.String sqlstr)
          Adds the PreparedStatement corresponding the input SQL string to the pool and returns the unique identifier.
 Scheduler getScheduler()
          Gets the scheduler filed in the connection pool.
 TransactionAPI getTransactionAPI()
          Gets a reference to TransactionAPI.
 int getTransactionTimeOut()
          Returns the transaction timeout value as an integer.
 void handleConnectionFail(java.sql.Connection conn, java.sql.SQLException sqle)
          This is used to handle the connection failure.
 boolean isInTimedOutThreads()
          Checks if there is a timed out transaction in the current thread.
 boolean isInTransaction()
          Checks if there is a transaction in progress in the current thread.
 boolean isNestedTransaction()
          Checks if the current thread already has a transaction in progress.
 boolean isTransactionEnabled()
          Returns if transaction is supported.
 boolean lockConnectionForTransaction(int timeout)
          Gets a dedicated connection for the transaction and locks it.
 java.sql.PreparedStatement prepareStatement(java.lang.String sqlStat)
          Returns a PreparedStatement corresponding to the input SQL string.
 java.sql.Statement query(java.lang.String sqlstring, boolean flag)
          Executes the SQL string, returns the java.sql.Statement in which the SQL string was executed.
 void refreshConnectionPool()
           
 void resetNestingLevel(java.lang.Thread threadObj)
          Sets the transaction nesting level in the input thread to zero.
 void returnPreparedStatement(PreparedStatementWrapper ps)
          Returns the PreparedStatement for use by other database operations.
 void setConAuthInterfaceClassName(java.lang.String conAuth)
          Sets the class name which has implemented ConnectionAuthenticationInterface.
 void setConnectionBreakHandler(ConnectionBreakHandler connectionBreakHandler)
          Registers the specified connection break handler to the Connectionpool.
 void setMaxTime(long time)
          Sets the timeout period for all PreparedStatements.
 void setNumberInCache(int num)
          Sets the number of PreparedStatements to be stored in cache for ready access.
 void setPSCacheSize(int size)
          Sets the size of cache, i.e., the number of PreparedStatements which will be stored in cache for ready access.
 void setScheduler(Scheduler sch)
          Sets the scheduler field in the connection pool.
 void setStmtCacheSize(int size)
          Sets the number of Statements that will be kept in cache.
 void setTransactionMode(boolean mode)
          Sets if transaction is enabled or not.
 void setTransactionTimeOut(int timeOutValue)
          Sets the transaction time out value with the given parameter.
 void startConnectionMaintainer(java.lang.String queryStr)
          Instantiates a ConnectionMaintainer object to ensure that a connection in the connection pool does not get timed out (because of non-use) by the database.
 void updateNestingLevel(boolean increment)
          Either increases or decreases the number of nested transactions in the current thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

url

public java.lang.String url
Database URL of the form jdbc:subprotocol:DataSourceName.

userName

public java.lang.String userName
Login user name of the database.

password

public java.lang.String password
Login password of the database.

driverName

public java.lang.String driverName
Database Driver name, for eg., sun.jdbc.odbc.JdbcOdbcDriver

transUser

public LogUser transUser
Log User for logging messages to transaction logs.
Constructor Detail

ConnectionPool

public ConnectionPool()
Constructs a ConnectionPool with default URL, user name, password and driver name.

ConnectionPool

public ConnectionPool(java.lang.String urlstr,
                      java.lang.String usrname,
                      java.lang.String pwd,
                      java.lang.String drivername)
Constructs a ConnectionPool with given URL, user name, password and driver name. This does not create the connections. They have to be created explicitly by calling the createConnection method.
Parameters:
urlstr - URL name
usrname - user name
pwd - password
drivername - driver name

ConnectionPool

public ConnectionPool(java.lang.String urlstr,
                      java.lang.String usrname,
                      java.lang.String pwd,
                      java.lang.String drivername,
                      boolean enable,
                      int num_trans,
                      int num_nontrans,
                      java.lang.String conAuth)
Creates an instance of ConnectionPool. This constructor takes the number of transaction and non-transaction connections as parameters and hence creates the connections itself. This constructor is for internal purposes.
Parameters:
urlstr - URL name
usrname - user name
pwd - password
drivername - driver name
enable - indicates whether transaction is enabled or not
num_trans - number of transaction connections
num_nontrans - number of non-transaction connections
conAuth - full classname for ConnectionAuthenticationInterface class (can be null).ConnectionAuthentication is not necessary.
Method Detail

getTransactionAPI

public TransactionAPI getTransactionAPI()
Gets a reference to TransactionAPI.
Returns:
a reference to TransactionAPI.

getInstance

public static ConnectionPool getInstance()
Gets a reference to a ConnectionPool object.

Note: This method does not instantiate a new instance of ConnectionPool if it had not been instantiated before. Applications have to explicitly initialize ConnectionPool either by creating an instance of RelationalAPI (recommended) or by using one of the constructors of this class.

Returns:
instance of ConnectionPool, null if not initialized.

getConnection

public java.sql.Connection getConnection()
Gets a Connection from the ConnectionPool. If there is a transaction underway in the current thread, this method returns the connection dedicated to the transaction. Otherwise,it returns any non-transactional connection.
Returns:
a Connection instance.

disconnectAll

public void disconnectAll()
Disconnects all connections in the ConnectionPool.

addPSToPool

public int addPSToPool(java.lang.String sqlStat)
Adds the PreparedStatement corresponding the input SQL string to the connection pool and returns an integer ID, which uniquely references the prepared statement.
Parameters:
sqlStat - the SQL String for which the PreparedStatement is to be formed.
Returns:
an integer ID for the PreparedStatement, -1 if the input SQL string is null.

setNumberInCache

public void setNumberInCache(int num)
Sets the number of PreparedStatements to be stored in cache for ready access. By default, this is 200.
Parameters:
num - number of PreparedStatements in cache.

lockConnectionForTransaction

public boolean lockConnectionForTransaction(int timeout)
Gets a dedicated connection for the transaction and locks it.
Parameters:
timeout - transaction timeout value.
Returns:
true if successful, false otherwise.

getConnectionForTransaction

public java.sql.Connection getConnectionForTransaction()
                                                throws UserTransactionException
Gets the connection already dedicated to a transaction in the current thread.
Returns:
a reference to dedicated connection, null if there is no transaction in the current thread.
Throws:
UserTransactionException - if the current transaction is timed out.

getConnectionForTransaction

public java.sql.Connection getConnectionForTransaction(java.lang.Thread threadObj)
                                                throws UserTransactionException
Gets the connection already dedicated to a transaction over the specified thread.
Parameters:
threadObj - the thread over which transaction will be performed.
Returns:
a reference to dedicated connection, null if there is no transaction in the given thread.
Throws:
UserTransactionException - if the transaction is timed out.

freeConnectionForTransaction

public void freeConnectionForTransaction()
Frees the connection associated with a transaction over the current thread.

setMaxTime

public void setMaxTime(long time)
Sets the timeout period for all PreparedStatements. By default, this is 10 seconds.
Parameters:
time - timeout period in milliseconds.

setPSCacheSize

public void setPSCacheSize(int size)
Sets the size of cache, i.e., the number of PreparedStatements which will be stored in cache for ready access.
Parameters:
size - number of PreparedStatements

setStmtCacheSize

public void setStmtCacheSize(int size)
Sets the number of Statements that will be kept in cache. This method is for internal use only.
Parameters:
size - number of Statements

prepareStatement

public java.sql.PreparedStatement prepareStatement(java.lang.String sqlStat)
                                            throws NmsStorageException,
                                                   UserTransactionException
Returns a PreparedStatement corresponding to the input SQL string. Note that these PreparedStatements are generated on the fly and will not be stored. If there is a transaction in progress in the current thread, the PreparedStatement will be prepared over the connection dedicated to the transaction.
Parameters:
sqlStat - SQL string for the PreparedStatement.
Returns:
PreparedStatement
Throws:
NmsStorageException - if any SQL error occurs while doing database operations.
UserTransactionException - if the current transaction is timed out.

isInTransaction

public boolean isInTransaction()
Checks if there is a transaction in progress in the current thread.
Returns:
true if there is a transaction in progress in the current thread.

isInTimedOutThreads

public boolean isInTimedOutThreads()
Checks if there is a timed out transaction in the current thread.
Returns:
true if the current thread has a transaction which has timed out.

executeUpdateStmt

public int executeUpdateStmt(java.lang.String sqlstr)
                      throws NmsStorageException,
                             UserTransactionException
Executes the input SQL query string in an already created Statement contained in ConnectionPool. This method can be used when it is not desirable to create PreparedStatements.
Parameters:
sqlstr - SQL query string.
Returns:
integer returned by executeUpdate method on Statement.
Throws:
NmsStorageException - if any SQL error occurs while doing database operations.
UserTransactionException - if the current transaction is timed out.

executeQueryStmt

public java.sql.ResultSet executeQueryStmt(java.lang.String sqlstr)
                                    throws NmsStorageException,
                                           UserTransactionException
Executes the input SQL query string in an already created Statement contained in ConnectionPool and returns a ResultSet. This method can be used when it is not desirable to create PreparedStatements.
Parameters:
sqlstr - SQL query string.
Returns:
ResultSet.
Throws:
NmsStorageException - if any SQL error occurs while doing database operations.
UserTransactionException - if the current transaction is timed out.

fetchPreparedStatement

public PreparedStatementWrapper fetchPreparedStatement(int id)
                                                throws TransactionException
Fetches the preparedStatement from the pool corresponding to the given unique ID. If there is a transaction in progress in the current thread, the PreparedStatement is fetched from the dedicated connection (if the transaction has timed out, a TransactionException is thrown). Otherwise, the PreparedStatement will be fetched from a non-transaction connection.
Parameters:
id - unique identifier for the PreparedStatement.
Returns:
PreparedStatementWrapper containing the PreparedStatement.
Throws:
TransactionException - if the current transaction is timed out.

setConAuthInterfaceClassName

public void setConAuthInterfaceClassName(java.lang.String conAuth)
Sets the class name which has implemented ConnectionAuthenticationInterface.
Parameters:
conAuth - instance of ConnectionAuthenticationInterface.

isTransactionEnabled

public boolean isTransactionEnabled()
Returns if transaction is supported.
Returns:
true if transaction is supported.

setTransactionMode

public void setTransactionMode(boolean mode)
Sets if transaction is enabled or not.
Parameters:
mode - true if transaction is enabled, false otherwise.

getNumOfNonTransactionConnections

public int getNumOfNonTransactionConnections()
Gets number of connections that are reserved for transactions.
Returns:
number of transaction connections.

getNumOfTransactionConnections

public int getNumOfTransactionConnections()
Gets number of connections reserved for non-transactional operations.
Returns:
number of non-transactional connections.

createConnection

public void createConnection(int num_trans,
                             int num_nontrans)
                      throws NmsStorageException
Creates transaction and non-transaction connections as specified by the input parameters. Transaction connections are reserved for transactions only. Similarly, non-transaction connections are reserved for non-transactions only, i.e., transactions will not be performed over these connections. This ensures that all connections are not taken up by transactions and some are available for non-transactions as well.
Parameters:
num_trans - number of connections reserved for transactions.
num_nontrans - number of connections reserved for non-transactions.
Throws:
NmsStorageException - in case of any problem while creating a connection.

startConnectionMaintainer

public void startConnectionMaintainer(java.lang.String queryStr)
Instantiates a ConnectionMaintainer object to ensure that a connection in the connection pool does not get timed out (because of non-use) by the database.
Parameters:
queryStr - SQL string to be used by the maintainer.

setScheduler

public void setScheduler(Scheduler sch)
Sets the scheduler field in the connection pool.
Parameters:
sch - Scheduler object.
See Also:
getScheduler()

getScheduler

public Scheduler getScheduler()
Gets the scheduler filed in the connection pool.
Returns:
Scheduler field.
See Also:
setScheduler(com.adventnet.management.scheduler.Scheduler)

isNestedTransaction

public boolean isNestedTransaction()
Checks if the current thread already has a transaction in progress.
Returns:
true if there is a transaction in the current thread.

getNestingLevel

public int getNestingLevel()
Gets the number of nested transactions in the current thread.
Returns:
the number of nested transactions, -1 if there is no transaction in the current thread.

resetNestingLevel

public void resetNestingLevel(java.lang.Thread threadObj)
Sets the transaction nesting level in the input thread to zero.
Parameters:
threadObj - input thread

updateNestingLevel

public void updateNestingLevel(boolean increment)
Either increases or decreases the number of nested transactions in the current thread. Increments if the input parameter is true, else decrements.
Parameters:
increment - true if the nesting level should be incremented, false otherwise.

getMetaData

public java.sql.DatabaseMetaData getMetaData()
                                      throws java.sql.SQLException,
                                             UserTransactionException
Gets comprehensive information about the database as a whole. This method internally calls getMetaData method on the Connection object.
Returns:
a reference to DatabaseMetaData object
Throws:
java.sql.SQLException - if any SQL error occurs while doing database operations
UserTransactionException - if the current transaction is timed out.

getMetaData

public java.sql.DatabaseMetaData getMetaData(java.sql.Connection con)
                                      throws java.sql.SQLException
Gets comprehensive information about the database as a whole. This method internally calls getMetaData method on the Connection object, passed as a parameter.
Parameters:
con - a Connection object
Returns:
a reference to DatabaseMetaData object
Throws:
java.sql.SQLException - if any SQL error occurs while doing database operations.

disconnect

public void disconnect()
                throws java.sql.SQLException
Disconnects all connections in the connection pool. In fact, this method calls disconnectAll.
Throws:
java.sql.SQLException - if any SQL error occurs while doing database operations.

query

public java.sql.Statement query(java.lang.String sqlstring,
                                boolean flag)
                         throws NmsStorageException,
                                UserTransactionException
Executes the SQL string, returns the java.sql.Statement in which the SQL string was executed. To get the ResultSet from the returned Statement object, use the method java.sql.Statement.getResultSet(). After completing operations in ResultSet, please ensure that you close both the ResultSet and Statement objects. Note Please set the variable "flag" to true always
Parameters:
sqlstring - the SQL query to be executed
flag - this parameter has no effect
Returns:
an SQL statement
Throws:
NmsStorageException - if any SQL error occurs while doing database operations.
UserTransactionException - if the current transaction is timed out.

executeQuery

public java.sql.ResultSet executeQuery(java.sql.PreparedStatement prstmt)
                                throws NmsStorageException,
                                       UserTransactionException
Executes the SQL query of the PreparedStatement object passed and returns the result set generated by the query. Do not forget to close the ResultSet once used.
Parameters:
prstmt - a PreparedStatement object
Returns:
a ResultSet that contains the data produced by the query
Throws:
NmsStorageException - if any SQL error occurs while doing database operations.
UserTransactionException - if the current transaction is timed out or rolled back.

executeUpdate

public int executeUpdate(java.sql.PreparedStatement prstmt)
                  throws NmsStorageException,
                         UserTransactionException
Executes the SQL INSERT, UPDATE or DELETE statement in the PreparedStatement object passed and returns the update count(number of records that gets effected into the database).
Parameters:
prstmt - a PreparedStatement object
Returns:
a int, either the row count for INSERT, UPDATE or DELETE statements; or 0 for SQL statements that return nothing
Throws:
NmsStorageException - if any SQL error occurs while doing database operations
UserTransactionException - if the current transaction is timed out or rolled back.

returnPreparedStatement

public void returnPreparedStatement(PreparedStatementWrapper ps)
Returns the PreparedStatement for use by other database operations.
Parameters:
ps - PreparedStatementWrapper which contains the PreparedStatement.

getPreparedStatement

public java.sql.PreparedStatement getPreparedStatement(java.lang.String sqlstr,
                                                       boolean isFromPool)
                                                throws NmsStorageException,
                                                       UserTransactionException
Gets the PreparedStatement associated with the input SQL string.
Parameters:
sqlstr - SQL string associated with the PreparedStatement.
isFromPool - specifies if the PreparedStatement should be obtained from the pool.
Returns:
PreparedStatement associated with the input SQL string.
Throws:
NmsStorageException - if any SQL error occurs while doing database operations.
UserTransactionException - if the current transaction is timed out.

getPreparedStatementID

public int getPreparedStatementID(java.lang.String sqlstr)
Adds the PreparedStatement corresponding the input SQL string to the pool and returns the unique identifier. This method internally calls the addPSToPool(sqlstr) method.
Parameters:
sqlstr - SQL string value.
Returns:
unique identifier for the PreparedStatement.

getPreparedStatement

public java.sql.PreparedStatement getPreparedStatement(java.lang.String sqlstr)
                                                throws NmsStorageException,
                                                       UserTransactionException
Gets the PreparedStatement associated with the input SQL string.
Parameters:
sqlstr - SQL string
Returns:
PreparedStatement
Throws:
NmsStorageException - if any SQL error occurs while doing database operations.
UserTransactionException - if the current transaction is timed out.

executeTheStatement

public void executeTheStatement(java.lang.Object stm)
                         throws NmsStorageException,
                                UserTransactionException
Executes the SQL query as specified by the input. The input parameter must be either a String, or, a java.sql.PreparedStatement. Otherwise, an exception is thrown. Note:This method is used for SQL queries which do not return any values, i.e., DDL and DCL type SQL statements.
Parameters:
stm - either a String or a java.sql.PreparedStatement.
Throws:
NmsStorageException - if any SQL error occurs while doing database operations.
UserTransactionException - if the current transaction is timed out.

commitAllNonTransactionConnections

public void commitAllNonTransactionConnections()
                                        throws NmsStorageException
Commits all the non transaction connections. This is basically used for SOLID database, because after executing each database queries, explicit commit should be called.
Throws:
NmsStorageException - if any SQL error occurs while doing database operations

execute

public void execute(java.lang.String sqlString)
             throws NmsStorageException,
                    UserTransactionException
Executes the input SQL string. This method creates a Statement on a connection in the ConnectionPool and calls the execute method on this Statement.
Parameters:
sqlString - SQL String to be executed
Throws:
NmsStorageException - if any SQL error occurs while doing database operations.
UserTransactionException - if the current transaction is timed out.

executeBatch

public int[] executeBatch(java.sql.PreparedStatement batchedPs)
                   throws NmsStorageException,
                          UserTransactionException
Executes a Prepared Statement which is batched with various set of values
Returns:
An array of update counts containing one element for each command in the batch. The elements of the array are ordered according to the order in which commands were added to the batch
Throws:
NmsStorageException - If a database access error occurs or the driver does not support batch statements or if one of the commands sent to the database fails to execute properly or attempts to return a result set.
UserTransactionException - If an error occurs while handling connection fail.

setTransactionTimeOut

public void setTransactionTimeOut(int timeOutValue)
Sets the transaction time out value with the given parameter. The given parameter should be in milliseconds.
Parameters:
timeOutValue - - integer representing the timeout value.
See Also:
getTransactionTimeOut()

getTransactionTimeOut

public int getTransactionTimeOut()
Returns the transaction timeout value as an integer.
Returns:
integer representing transaction timeout value in milliseconds.
See Also:
setTransactionTimeOut(int)

setConnectionBreakHandler

public void setConnectionBreakHandler(ConnectionBreakHandler connectionBreakHandler)
Registers the specified connection break handler to the Connectionpool. When the connection to the database is closed or broken, the handleConnectionFail() method of the registered ConnectionBrakeHandler will be invoked.

Web NMS by default reads the ConnectionBreakhandler from the nmsInterfaces.conf file in WebNMS_HOME/conf directory from the parameter connectionBreakHandler="Implemetation_Class_of_ ConnectionBreakHandler" and registers this with the ConnectionPool.

Parameters:
connectionBreakHandler - a ConnectionBreakHandler object instance.

handleConnectionFail

public void handleConnectionFail(java.sql.Connection conn,
                                 java.sql.SQLException sqle)
This is used to handle the connection failure. i.e if the DBServer goes down and comes up, the connection reference, created earlier will be invalid. This method will invoke the ConnectionBreakHandler implementation to handle the invalid connection. Here the exception is used to check the connection validity for Oracle and MSSQL databases based on the error code.
Parameters:
con - Connection reference, which is invalid after the DBServer failure/restart
sqle - SQLException raised when we try to execute a query after the DBServer is down/ after the connection is invalid

refreshConnectionPool

public void refreshConnectionPool()

getConnectionId

public java.lang.Integer getConnectionId(java.sql.Connection con)

getIdForThread

public java.lang.Integer getIdForThread(java.lang.Thread obj)

AdventNet Web NMS 4 API Specification