TTConnectionPool Reference

The TTConnectionPool class is used by multithreaded applications to manage a pool of connections.

Public Members

None

Public Methods

This section summarizes then describes the TTConnectionPool public methods.

Public Methods Summary

Method Description

AddConnectionToPool()

Adds a TTConnection object (possibly an object of a class derived from TTConnection) to the connection pool.

ConnectAll()

Connects all the TTConnection objects to TimesTen simultaneously.

DisconnectAll()

Disconnects all connections in the connection pool from TimesTen.

freeConnection()

Returns a connection to the pool for reassignment to another thread.

getConnection()

Checks out an idle connection from the connection pool for a thread.

getStats()

Queries the TTConnectionPool object for connection pool status information.

AddConnectionToPool()

int AddConnectionToPool(TTConnection* connP)

This method is used to add a TTConnection object (possibly an object of a class derived from TTConnection) to the connection pool. It returns -1 if there is an error. Also see freeConnection().

ConnectAll()

void ConnectAll(const char* connStr)
void ConnectAll(const char* connStr, const char* username, const char* password)

After all the TTConnection objects of an application have been added to the connection pool by AddConnectionToPool(), the ConnectAll() method can be used to connect all of the TTConnection objects to TimesTen simultaneously. The connection string specified in the connStr parameter is used to create the connection. Specify a user and password, either as part of the connect string or as separate parameters. Also see the next method, DisconnectAll().

A TTStatus object is thrown as an exception if an error occurs.

Privilege to connect to a database must be granted to users through the CREATE SESSION privilege, either directly or through the PUBLIC role. See Connection Methods.

DisconnectAll()

void DisconnectAll()

Disconnects all connections in the connection pool from TimesTen. Also see the preceding method, ConnectAll().

Applications must call DisconnectAll() before termination to avoid overhead associated with process failure analysis and recovery. A TTStatus object is thrown as an exception if an error occurs.

freeConnection()

void freeConnection(TTConnection* connP)

Returns a connection to the pool for reassignment to another thread. Applications should not free connections that are in the middle of a transaction. TTConnection::Commit() or Rollback() should be called immediately before the TTConnection object is passed to freeConnection(). Also see AddConnectionToPool().

getConnection()

TTConnection* getConnection(int timeout_millis=0)

Checks out an idle connection from the connection pool for use by a thread. A pointer to an idle TTConnection object is returned. The thread should then perform a transaction, ending with either Commit() or Rollback(), and then should return the connection to the pool using the freeConnection() method.

If no idle connections are in the pool, the thread calling getConnection() blocks until a connection is returned to the pool by a call to freeConnection(). An optional timeout, in milliseconds, can be provided. If this is provided, getConnection() waits for a free connection for no more than timeout_millis milliseconds. If no connection is available in that time then getConnection() returns NULL to the caller.

getStats()

void getStats(int* nGets, int* nFrees, int* nWaits, int* nTimeouts,
              int* maxInUse, int* nForcedCommits)

Queries the TTConnectionPool for status information. The following data are returned:

  • nGets: Number of calls to getConnection()

  • nFrees: Number of calls to freeConnection()

  • nWaits: Number of times a call to getConnection() had to wait before returning a connection

  • nTimeouts: Number of calls to getConnection() that timed out

  • maxInUse: High point for the most number of connections in use simultaneously

  • nForcedCommits: Number of times that freeConnection() had to call Commit() on a connection before checking it into the pool

    If this counter is nonzero, the user application is not calling TTConnection::Commit() or Rollback() before returning a connection to the pool.