1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>MySQL++ Reference Manual</title>
<meta http-equiv="Content-type" content="text/html;charset=iso-8859-1">
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="refman.css" rel="stylesheet" type="text/css">
</head>
<body>
<!-- Generated by Doxygen 1.4.7 -->
<div class="tabs">
<ul>
<li><a href="index.html"><span>Main Page</span></a></li>
<li id="current"><a href="annotated.html"><span>Classes</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
</ul></div>
<div class="tabs">
<ul>
<li><a href="annotated.html"><span>Class List</span></a></li>
<li><a href="hierarchy.html"><span>Class Hierarchy</span></a></li>
<li><a href="functions.html"><span>Class Members</span></a></li>
</ul></div>
<div class="nav">
<b>mysqlpp</b>::<a class="el" href="classmysqlpp_1_1ConnectionPool.html">ConnectionPool</a></div>
<h1>mysqlpp::ConnectionPool Class Reference</h1><!-- doxytag: class="mysqlpp::ConnectionPool" -->Manages a pool of connections for programs that need more than one <a class="el" href="classmysqlpp_1_1Connection.html">Connection</a> object at a time, but can't predict how many they need in advance.
<a href="#_details">More...</a>
<p>
<code>#include <<a class="el" href="cpool_8h-source.html">cpool.h</a>></code>
<p>
Collaboration diagram for mysqlpp::ConnectionPool:<p><center><img src="classmysqlpp_1_1ConnectionPool__coll__graph.png" border="0" usemap="#mysqlpp_1_1ConnectionPool__coll__map" alt="Collaboration graph"></center>
<map name="mysqlpp_1_1ConnectionPool__coll__map">
<area href="classmysqlpp_1_1BeecryptMutex.html" shape="rect" coords="5,7,192,31" alt="">
</map>
<center><font size="2">[<a href="graph_legend.html">legend</a>]</font></center><a href="classmysqlpp_1_1ConnectionPool-members.html">List of all members.</a><table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td colspan="2"><br><h2>Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="cc1262db33d586284651825ff076a8d7"></a><!-- doxytag: member="mysqlpp::ConnectionPool::ConnectionPool" ref="cc1262db33d586284651825ff076a8d7" args="()" -->
</td><td class="memItemRight" valign="bottom"><a class="el" href="classmysqlpp_1_1ConnectionPool.html#cc1262db33d586284651825ff076a8d7">ConnectionPool</a> ()</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Create empty pool. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual </td><td class="memItemRight" valign="bottom"><a class="el" href="classmysqlpp_1_1ConnectionPool.html#2cee954229416e24da07f5e208b35b09">~ConnectionPool</a> ()</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Destroy object. <a href="#2cee954229416e24da07f5e208b35b09"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="264ea3fc4311c8bfd18e7d7b6103d124"></a><!-- doxytag: member="mysqlpp::ConnectionPool::empty" ref="264ea3fc4311c8bfd18e7d7b6103d124" args="() const " -->
bool </td><td class="memItemRight" valign="bottom"><a class="el" href="classmysqlpp_1_1ConnectionPool.html#264ea3fc4311c8bfd18e7d7b6103d124">empty</a> () const </td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Returns true if pool is empty. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual <a class="el" href="classmysqlpp_1_1Connection.html">Connection</a> * </td><td class="memItemRight" valign="bottom"><a class="el" href="classmysqlpp_1_1ConnectionPool.html#cbf56ee86ef66b3ebdf02adde5908776">grab</a> ()</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Grab a free connection from the pool. <a href="#cbf56ee86ef66b3ebdf02adde5908776"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual void </td><td class="memItemRight" valign="bottom"><a class="el" href="classmysqlpp_1_1ConnectionPool.html#c51a7a63ce4d8825c3f7b05f4b8bfe68">release</a> (const <a class="el" href="classmysqlpp_1_1Connection.html">Connection</a> *pc)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Return a connection to the pool. <a href="#c51a7a63ce4d8825c3f7b05f4b8bfe68"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="c410ed5cb3032aed048fb3a275629654"></a><!-- doxytag: member="mysqlpp::ConnectionPool::shrink" ref="c410ed5cb3032aed048fb3a275629654" args="()" -->
void </td><td class="memItemRight" valign="bottom"><a class="el" href="classmysqlpp_1_1ConnectionPool.html#c410ed5cb3032aed048fb3a275629654">shrink</a> ()</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Remove all unused connections from the pool. <br></td></tr>
<tr><td colspan="2"><br><h2>Protected Member Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classmysqlpp_1_1ConnectionPool.html#981e1b1715de2daea9f6b10bdcbb5915">clear</a> (bool all=true)</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Drains the pool, freeing all allocated memory. <a href="#981e1b1715de2daea9f6b10bdcbb5915"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual <a class="el" href="classmysqlpp_1_1Connection.html">Connection</a> * </td><td class="memItemRight" valign="bottom"><a class="el" href="classmysqlpp_1_1ConnectionPool.html#f755c7e11b92bbab0e88ab3e9c88f0fd">create</a> ()=0</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Create a new connection. <a href="#f755c7e11b92bbab0e88ab3e9c88f0fd"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual void </td><td class="memItemRight" valign="bottom"><a class="el" href="classmysqlpp_1_1ConnectionPool.html#3dae30e24dd6967e4e427fa69dbc2105">destroy</a> (<a class="el" href="classmysqlpp_1_1Connection.html">Connection</a> *)=0</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Destroy a connection. <a href="#3dae30e24dd6967e4e427fa69dbc2105"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual unsigned int </td><td class="memItemRight" valign="bottom"><a class="el" href="classmysqlpp_1_1ConnectionPool.html#8a5ba414a5b02c48d64501c25b64a656">max_idle_time</a> ()=0</td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Returns the maximum number of seconds a connection is able to remain idle before it is dropped. <a href="#8a5ba414a5b02c48d64501c25b64a656"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="3a42387a44afad4c3d3895ba89ded21d"></a><!-- doxytag: member="mysqlpp::ConnectionPool::size" ref="3a42387a44afad4c3d3895ba89ded21d" args="() const " -->
size_t </td><td class="memItemRight" valign="bottom"><a class="el" href="classmysqlpp_1_1ConnectionPool.html#3a42387a44afad4c3d3895ba89ded21d">size</a> () const </td></tr>
<tr><td class="mdescLeft"> </td><td class="mdescRight">Returns the current size of the internal connection pool. <br></td></tr>
<tr><td colspan="2"><br><h2>Classes</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">struct </td><td class="memItemRight" valign="bottom"><b>ConnectionInfo</b></td></tr>
</table>
<hr><a name="_details"></a><h2>Detailed Description</h2>
Manages a pool of connections for programs that need more than one <a class="el" href="classmysqlpp_1_1Connection.html">Connection</a> object at a time, but can't predict how many they need in advance.
<p>
This class is useful in programs that need to make multiple simultaneous queries on the database; this requires multiple <a class="el" href="classmysqlpp_1_1Connection.html">Connection</a> objects due to a hard limitation of the underlying C API. <a class="el" href="classmysqlpp_1_1Connection.html">Connection</a> pools are most useful in multithreaded programs, but it can be helpful to have one in a single-threaded program as well. Sometimes it's necessary to get more data from the server while in the middle of processing data from an earlier query; this requires multiple connections. Whether you use a pool or manage connections yourself is up to you, but realize that this class takes care of a lot of subtle details for you that aren't obvious.<p>
The pool's policy for connection reuse is to always return the <em>most</em> recently used connection that's not being used right now. This ensures that excess connections don't hang around any longer than they must. If the pool were to return the <em>least</em> recently used connection, it would be likely to result in a large pool of sparsely used connections because we'd keep resetting the last-used time of whichever connection is least recently used at that moment.
<p>
<hr><h2>Constructor & Destructor Documentation</h2>
<a class="anchor" name="2cee954229416e24da07f5e208b35b09"></a><!-- doxytag: member="mysqlpp::ConnectionPool::~ConnectionPool" ref="2cee954229416e24da07f5e208b35b09" args="()" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">virtual mysqlpp::ConnectionPool::~ConnectionPool </td>
<td>(</td>
<td class="paramname"> </td>
<td> ) </td>
<td width="100%"><code> [inline, virtual]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Destroy object.
<p>
If the pool raises an assertion on destruction, it means our subclass isn't calling <a class="el" href="classmysqlpp_1_1ConnectionPool.html#981e1b1715de2daea9f6b10bdcbb5915">clear()</a> in its dtor as it should.
</div>
</div><p>
<hr><h2>Member Function Documentation</h2>
<a class="anchor" name="981e1b1715de2daea9f6b10bdcbb5915"></a><!-- doxytag: member="mysqlpp::ConnectionPool::clear" ref="981e1b1715de2daea9f6b10bdcbb5915" args="(bool all=true)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void mysqlpp::ConnectionPool::clear </td>
<td>(</td>
<td class="paramtype">bool </td>
<td class="paramname"> <em>all</em> = <code>true</code> </td>
<td> ) </td>
<td width="100%"><code> [protected]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Drains the pool, freeing all allocated memory.
<p>
A derived class must call this in its dtor to avoid leaking all <a class="el" href="classmysqlpp_1_1Connection.html">Connection</a> objects still in existence. We can't do it up at this level because this class's dtor can't call our subclass's <a class="el" href="classmysqlpp_1_1ConnectionPool.html#3dae30e24dd6967e4e427fa69dbc2105">destroy()</a> method.<p>
<dl compact><dt><b>Parameters:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"></td><td valign="top"><em>all</em> </td><td>if true, remove all connections, even those in use </td></tr>
</table>
</dl>
</div>
</div><p>
<a class="anchor" name="f755c7e11b92bbab0e88ab3e9c88f0fd"></a><!-- doxytag: member="mysqlpp::ConnectionPool::create" ref="f755c7e11b92bbab0e88ab3e9c88f0fd" args="()=0" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">virtual <a class="el" href="classmysqlpp_1_1Connection.html">Connection</a>* mysqlpp::ConnectionPool::create </td>
<td>(</td>
<td class="paramname"> </td>
<td> ) </td>
<td width="100%"><code> [protected, pure virtual]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Create a new connection.
<p>
Subclasses must override this.<p>
Essentially, this method lets your code tell <a class="el" href="classmysqlpp_1_1ConnectionPool.html">ConnectionPool</a> what server to connect to, what login parameters to use, what connection options to enable, etc. <a class="el" href="classmysqlpp_1_1ConnectionPool.html">ConnectionPool</a> can't know any of this without your help.<p>
<dl compact><dt><b>Return values:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"></td><td valign="top"><em>A</em> </td><td>connected <a class="el" href="classmysqlpp_1_1Connection.html">Connection</a> object </td></tr>
</table>
</dl>
</div>
</div><p>
<a class="anchor" name="3dae30e24dd6967e4e427fa69dbc2105"></a><!-- doxytag: member="mysqlpp::ConnectionPool::destroy" ref="3dae30e24dd6967e4e427fa69dbc2105" args="(Connection *)=0" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">virtual void mysqlpp::ConnectionPool::destroy </td>
<td>(</td>
<td class="paramtype"><a class="el" href="classmysqlpp_1_1Connection.html">Connection</a> * </td>
<td class="paramname"> </td>
<td> ) </td>
<td width="100%"><code> [protected, pure virtual]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Destroy a connection.
<p>
Subclasses must override this.<p>
This is for destroying the objects returned by <a class="el" href="classmysqlpp_1_1ConnectionPool.html#f755c7e11b92bbab0e88ab3e9c88f0fd">create()</a>. Because we can't know what the derived class did to create the connection we can't reliably know how to destroy it.
</div>
</div><p>
<a class="anchor" name="cbf56ee86ef66b3ebdf02adde5908776"></a><!-- doxytag: member="mysqlpp::ConnectionPool::grab" ref="cbf56ee86ef66b3ebdf02adde5908776" args="()" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="classmysqlpp_1_1Connection.html">Connection</a> * mysqlpp::ConnectionPool::grab </td>
<td>(</td>
<td class="paramname"> </td>
<td> ) </td>
<td width="100%"><code> [virtual]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Grab a free connection from the pool.
<p>
This method creates a new connection if an unused one doesn't exist, and destroys any that have remained unused for too long. If there is more than one free connection, we return the most recently used one; this allows older connections to die off over time when the caller's need for connections decreases.<p>
Do not delete the returned pointer. This object manages the lifetime of connection objects it creates.<p>
<dl compact><dt><b>Return values:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"></td><td valign="top"><em>a</em> </td><td>pointer to the connection </td></tr>
</table>
</dl>
</div>
</div><p>
<a class="anchor" name="8a5ba414a5b02c48d64501c25b64a656"></a><!-- doxytag: member="mysqlpp::ConnectionPool::max_idle_time" ref="8a5ba414a5b02c48d64501c25b64a656" args="()=0" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">virtual unsigned int mysqlpp::ConnectionPool::max_idle_time </td>
<td>(</td>
<td class="paramname"> </td>
<td> ) </td>
<td width="100%"><code> [protected, pure virtual]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Returns the maximum number of seconds a connection is able to remain idle before it is dropped.
<p>
Subclasses must override this as it encodes a policy issue, something that MySQL++ can't declare by fiat.<p>
<dl compact><dt><b>Return values:</b></dt><dd>
<table border="0" cellspacing="2" cellpadding="0">
<tr><td valign="top"></td><td valign="top"><em>number</em> </td><td>of seconds before an idle connection is destroyed due to lack of use </td></tr>
</table>
</dl>
</div>
</div><p>
<a class="anchor" name="c51a7a63ce4d8825c3f7b05f4b8bfe68"></a><!-- doxytag: member="mysqlpp::ConnectionPool::release" ref="c51a7a63ce4d8825c3f7b05f4b8bfe68" args="(const Connection *pc)" -->
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void mysqlpp::ConnectionPool::release </td>
<td>(</td>
<td class="paramtype">const <a class="el" href="classmysqlpp_1_1Connection.html">Connection</a> * </td>
<td class="paramname"> <em>pc</em> </td>
<td> ) </td>
<td width="100%"><code> [virtual]</code></td>
</tr>
</table>
</div>
<div class="memdoc">
<p>
Return a connection to the pool.
<p>
Marks the connection as no longer in use.<p>
The pool updates the last-used time of a connection only on release, on the assumption that it was used just prior. There's nothing forcing you to do it this way: your code is free to delay releasing idle connections as long as it likes. You want to avoid this because it will make the pool perform poorly; if it doesn't know approximately how long a connection has really been idle, it can't make good judgements about when to remove it from the pool.
</div>
</div><p>
<hr>The documentation for this class was generated from the following files:<ul>
<li><a class="el" href="cpool_8h-source.html">cpool.h</a><li>cpool.cpp</ul>
<hr size="1"><address style="align: right;"><small>Generated on Wed Feb 4 14:43:01 2009 for MySQL++ by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.7 </small></address>
</body>
</html>
|