Wt: Wt::Dbo::FixedSqlConnectionPool Class Reference

Wt 4.10.4

Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
Wt::Dbo::FixedSqlConnectionPool Class Reference
Database Objects (Wt::Dbo)

A connection pool of fixed size. More...

`#include <Wt/Dbo/FixedSqlConnectionPool.h>`

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

## Public Member Functions
| FixedSqlConnectionPool (std::unique_ptr< SqlConnection > connection, int size)
| Creates a fixed connection pool.
void | setTimeout (std::chrono::steady_clock::duration timeout)
| Set a timeout to get a connection.
std::chrono::steady_clock::duration | timeout () const
| Get the timeout to get a connection.
virtual std::unique_ptr< SqlConnection > | getConnection () override
| Uses a connection from the pool.
virtual void | returnConnection (std::unique_ptr< SqlConnection >) override
| Returns a connection to the pool.
virtual void | prepareForDropTables () const override
| 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.

## 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 | ( | std::unique_ptr< SqlConnection > | connection,
|  | int | size )

Creates a fixed connection pool.

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

## Member Function Documentation

## ◆ getConnection()

virtual std::unique_ptr< SqlConnection > Wt::Dbo::FixedSqlConnectionPool::getConnection | ( |  | ) |
| overridevirtual

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()

virtual 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()

virtual void Wt::Dbo::FixedSqlConnectionPool::returnConnection | ( | std::unique_ptr< SqlConnection > |  | ) |
| overridevirtual

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 | ( | std::chrono::steady_clock::duration | timeout | ) |

Set a timeout to get a connection.

When the connection pool has no available connection, it will wait the given duration.

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

By default, there is no timeout.

## ◆ timeout()

std::chrono::steady_clock::duration Wt::Dbo::FixedSqlConnectionPool::timeout | ( |  | ) | const

Get the timeout to get a connection.

See also
  setTimeout()