Go to the documentation of this file.
28 #if !defined(MYSQLPP_CPOOL_H)
29 #define MYSQLPP_CPOOL_H
40 #if !defined(DOXYGEN_IGNORE)
42 class MYSQLPP_EXPORT Connection;
68 class MYSQLPP_EXPORT ConnectionPool
78 virtual ~ConnectionPool() { assert(empty()); }
81 bool empty()
const {
return pool_.empty(); }
106 virtual Connection* exchange(
const Connection* pc);
120 virtual Connection* grab();
137 virtual void release(
const Connection* pc);
150 void remove(
const Connection* pc);
162 virtual Connection* safe_grab();
165 void shrink() { clear(
false); }
176 void clear(
bool all =
true);
188 virtual Connection* create() = 0;
197 virtual void destroy(Connection*) = 0;
207 virtual unsigned int max_idle_time() = 0;
210 size_t size()
const {
return pool_.size(); }
214 struct ConnectionInfo {
219 ConnectionInfo(Connection* c) :
231 bool operator<(
const ConnectionInfo& rhs)
const
233 const ConnectionInfo& lhs = *
this;
234 return lhs.in_use == rhs.in_use ?
235 lhs.last_used < rhs.last_used :
239 typedef std::list<ConnectionInfo> PoolT;
240 typedef PoolT::iterator PoolIt;
243 Connection* find_mru();
244 void remove(
const PoolIt& it);
245 void remove_old_connections();
249 BeecryptMutex mutex_;
254 #endif // !defined(MYSQLPP_CPOOL_H)
virtual void destroy(Connection *)=0
Destroy a connection.
MUTually EXclusive lock class.
Manages the connection to the database server.
Definition: connection.h:81
virtual Connection * exchange(const Connection *pc)
Return a defective connection to the pool and get a new one back.
Definition: cpool.cpp:117
Declares the ConnectionPool class.
Functor to test whether a given ConnectionInfo object is "too old".
Definition: cpool.cpp:69
virtual unsigned int max_idle_time()=0
Returns the maximum number of seconds a connection is able to remain idle before it is dropped.
Wrapper around BeecryptMutex to add scope-bound locking and unlocking.
Definition: beemutex.h:119
virtual Connection * safe_grab()
Grab a free connection from the pool, testing that it's connected before returning it.
Definition: cpool.cpp:234
virtual void release(const Connection *pc)
Return a connection to the pool.
Definition: cpool.cpp:168
Declares the Connection class.
virtual Connection * create()=0
Create a new connection.
virtual Connection * grab()
Grab a free connection from the pool.
Definition: cpool.cpp:150
void clear(bool all=true)
Drains the pool, freeing all allocated memory.
Definition: cpool.cpp:96
void remove(const Connection *pc)
Removes the given connection from the pool.
Definition: cpool.cpp:194