Wt  3.7.1
Public Member Functions | Protected Member Functions | List of all members
Wt::Dbo::FixedSqlConnectionPool Class Reference

A connection pool of fixed size. More...

#include <Wt/Dbo/FixedSqlConnectionPool>

Inheritance diagram for Wt::Dbo::FixedSqlConnectionPool:
Inheritance graph
[legend]

Public Member Functions

 FixedSqlConnectionPool (SqlConnection *connection, int size)
 Creates a fixed connection pool. More...
 
void setTimeout (int millis)
 Set a timeout to get a connection. More...
 
int timeout () const
 Get the timeout to get a connection. More...
 
virtual SqlConnectiongetConnection ()
 Uses a connection from the pool. More...
 
virtual void returnConnection (SqlConnection *)
 Returns a connection to the pool. More...
 
virtual void prepareForDropTables () const
 Prepares all connections in the pool for dropping the tables.
 
- Public Member Functions inherited from Wt::Dbo::SqlConnectionPool
virtual ~SqlConnectionPool ()
 Destructor.
 

Protected Member Functions

virtual void handleTimeout ()
 Handle a timeout that occured while getting a connection. More...
 

Detailed Description

A connection pool of fixed size.

This provides a connection pool of fixed size: its size is determined at startup time, and the pool will not grow as more connections are needed.

This is adequate when the number of threads (which need different connections to work with) is also bounded, like when using a fixed size thread pool. This is for example the case when used in conjunction with Wt. Note that you do not need as many connections as sessions, since Session will only use a connection while processing a transaction.

Constructor & Destructor Documentation

◆ FixedSqlConnectionPool()

Wt::Dbo::FixedSqlConnectionPool::FixedSqlConnectionPool ( SqlConnection connection,
int  size 
)

Creates a fixed connection pool.

The pool is initialized with the provided connection, which is cloned (size - 1) times.

The pool thus takes ownership of the given connection.

Member Function Documentation

◆ getConnection()

SqlConnection * Wt::Dbo::FixedSqlConnectionPool::getConnection ( )
virtual

Uses a connection from the pool.

This returns a connection from the pool that can be used. If the pool has no more connection available, the pool may decide to grow or block until a connection is returned.

This method is called by a Session when a new transaction is started.

Implements Wt::Dbo::SqlConnectionPool.

◆ handleTimeout()

void Wt::Dbo::FixedSqlConnectionPool::handleTimeout ( )
protectedvirtual

Handle a timeout that occured while getting a connection.

The default implementation throws an Exception.

If the function returns cleanly, it is assumed that something has been done to fix the situation (e.g. connections have been added to the pool): the timeout is reset and another attempt is made to obtain a connection.

◆ returnConnection()

void Wt::Dbo::FixedSqlConnectionPool::returnConnection ( SqlConnection )
virtual

Returns a connection to the pool.

This returns a connection to the pool. This method is called by a Session after a transaction has been finished.

Implements Wt::Dbo::SqlConnectionPool.

◆ setTimeout()

void Wt::Dbo::FixedSqlConnectionPool::setTimeout ( int  millis)

Set a timeout to get a connection.

When the connection pool has no available connection, it will wait the given amount of milliseconds.

On timeout, handleTimeout() is called, which throws an exception by default.

By default, there is no timeout.

◆ timeout()

int Wt::Dbo::FixedSqlConnectionPool::timeout ( ) const

Get the timeout to get a connection.

See also
setTimeout()

Generated on Tue Dec 15 2020 for the C++ Web Toolkit (Wt) by doxygen 1.8.13