Wt  4.0.2
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.h>

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

Public Member Functions

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

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

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.

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.

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.

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.

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

Get the timeout to get a connection.

See also
setTimeout()

Generated on Fri Nov 24 2017 for the C++ Web Toolkit (Wt) by doxygen 1.8.11