Listing 2: DbKit Wrapper Facade connection pooling example.
(a)
Ret = SQLSetEnvAttr( NULL, SQL_ATTR_CONNECTION_POOLING,
(SQLPOINTER)SQL_CP_ONE_PER_DRIVER, SQL_IS_INTEGER );
(b)
// class level declaration for illustration...
map<string, ConnectionPool *> _pools;
// See Occi::ConfigurePool...
if (_pools[ConnectionString] == NULL) {
try {
ConnectionPool *pool = _env->createConnectionPool(
UserName, Password, ConnectionString, 1, iMaxConnections, 1);
if (pool != NULL) {
_pools[ConnectionString] = pool;
}
else {
// handle error ...
}
}
catch (SQLException &excp) {
// handle error ...
}
try {
_pools[ConnectionString]->setTimeOut(600);
// If inactive for 10 minutes, free connections ...
}
catch (SQLException &excp) {
// handle error
}
}