Connection Pools
The number of connections that an RWDBDatabase instance holds open is determined by the size of its connection pool. A connection pool is associated with every RWDBDatabase object; it is essentially a repository that maintains a set number of connections for the life of the RWDBDatabase object. These connections are maintained by the pool and retrieved whenever your application needs one. They are held open by the RWDBDatabase until its implementation is destructed.
To maximize efficiency and performance, the DB Interface Module provides for managing these connections. Applications can control:
*the number of connections that the RWDBDatabase object will manage
*whether or not to automatically allocate a connection when the RWDBDatabase object is constructed.
By default, the pool size is one connection. This is because, when an RWDBDatabase is instantiated, connectivity is automatically confirmed by allocating one RWDBConnection instance. However, the size of the pool may be altered to accommodate the needs of your application through the method RWDBDatabase::defaultConnections(size_t n). If set to n connections, the connection pool will hold at most n connections for the life of the RWDBDatabase object.
NOTE: Setting the pool size does not limit the number of connections an application can create; rather, it limits only the number of idle connections held by the RWDBDatabase object in its connection pool.
Why should you choose to set the number of connections? Performance! Creating a connection from your client application to the remote server is a time-consuming operation. By optimizing the size of the connection pool, there are no hidden performance costs for creating connections again and again. Connections are reused as needed, which may produce considerable performance improvement.
Another option, if you need to control every connection that your application creates, is to postpone the creation of connections until they are actually needed. In other words, you can insure that no connections are allocated when you create your RWDBDatabase instance. You can do this through the static method RWDBDatabase::connect(bool). When invoked with an argument of false, this method disables the creation of the implicit connection for the RWDBDatabase instance at the time this instance is constructed.