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
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Class Poco::Data::SessionPool</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<meta name="author" content="Applied Informatics Software Engineering GmbH and Contributors"/>
<meta name="publisher" content="Applied Informatics Software Engineering GmbH and Contributors"/>
<meta name="copyright" content="Copyright (c) 2009, Applied Informatics Software Engineering GmbH and Contributors"/>
<meta name="language" content="en"/>
<meta name="date" content="2009-11-24"/>
<meta name="generator" content="PocoDoc"/>
<link rel="stylesheet" href="css/styles.css" type="text/css"/>
</head>
<body bgcolor="#ffffff" leftmargin="0" topmargin="0">
<div class="header">
<h1 class="namespace"><a href="Poco.Data.html" class="namespace">Poco::Data</a></h1>
<h1 class="symbol">class SessionPool</h1>
</div>
<div class="body">
<p>
<b>Library:</b> Data<br />
<b>Package:</b> SessionPooling<br />
<b>Header:</b> Poco/Data/SessionPool.h</p>
<h2>Description</h2>
<div class="description">
<p>This class implements session pooling for POCO <a href="Poco.Data.html" title="namespace Poco::Data">Data</a>. </p>
<p>Creating a connection to a database is often a time consuming operation. Therefore it makes sense to reuse a session object once it is no longer needed. </p>
<p>A <a href="Poco.Data.SessionPool.html" title="class Poco::Data::SessionPool">SessionPool</a> manages a collection of <a href="Poco.Data.SessionImpl.html" title="class Poco::Data::SessionImpl">SessionImpl</a> objects (decorated with a <a href="Poco.Data.PooledSessionImpl.html" title="class Poco::Data::PooledSessionImpl">PooledSessionImpl</a>). </p>
<p>When a <a href="Poco.Data.SessionImpl.html" title="class Poco::Data::SessionImpl">SessionImpl</a> object is requested, the <a href="Poco.Data.SessionPool.html" title="class Poco::Data::SessionPool">SessionPool</a> first looks in its set of already initialized <a href="Poco.Data.SessionImpl.html" title="class Poco::Data::SessionImpl">SessionImpl</a> for an available object. If one is found, it is returned to the client and marked as "in-use". If no <a href="Poco.Data.SessionImpl.html" title="class Poco::Data::SessionImpl">SessionImpl</a> is available, the <a href="Poco.Data.SessionPool.html" title="class Poco::Data::SessionPool">SessionPool</a> attempts to create a new one for the client. To avoid excessive creation of <a href="Poco.Data.SessionImpl.html" title="class Poco::Data::SessionImpl">SessionImpl</a> objects, a limit can be set on the maximum number of objects. Sessions found not to be connected to the database are purged from the pool whenever one of the following events occurs: </p>
<p></p>
<ul>
<li>JanitorTimer event </li>
<li><a href="Poco.Data.SessionPool.html#2988" title="Poco::Data::SessionPool::get()">get</a>() request </li>
<li><a href="Poco.Data.SessionPool.html#3003" title="Poco::Data::SessionPool::putBack()">putBack</a>() request </li>
</ul>
<p>Not connected idle sessions can not exist. </p>
<p>Usage example: </p>
<p></p>
<pre>SessionPool pool("ODBC", "...");
...
Session sess(pool.get());
...
</pre>
</div>
<h2>Member Summary</h2>
<p><b>Member Functions: </b><a href="Poco.Data.SessionPool.html#2993" title="Poco::Data::SessionPool::allocated()">allocated</a>, <a href="Poco.Data.SessionPool.html#2994" title="Poco::Data::SessionPool::available()">available</a>, <a href="Poco.Data.SessionPool.html#2989" title="Poco::Data::SessionPool::capacity()">capacity</a>, <a href="Poco.Data.SessionPool.html#2995" title="Poco::Data::SessionPool::customizeSession()">customizeSession</a>, <a href="Poco.Data.SessionPool.html#2992" title="Poco::Data::SessionPool::dead()">dead</a>, <a href="Poco.Data.SessionPool.html#3001" title="Poco::Data::SessionPool::deadImpl()">deadImpl</a>, <a href="Poco.Data.SessionPool.html#2988" title="Poco::Data::SessionPool::get()">get</a>, <a href="Poco.Data.SessionPool.html#2991" title="Poco::Data::SessionPool::idle()">idle</a>, <a href="Poco.Data.SessionPool.html#3005" title="Poco::Data::SessionPool::onJanitorTimer()">onJanitorTimer</a>, <a href="Poco.Data.SessionPool.html#3000" title="Poco::Data::SessionPool::purgeDeadSessions()">purgeDeadSessions</a>, <a href="Poco.Data.SessionPool.html#3003" title="Poco::Data::SessionPool::putBack()">putBack</a>, <a href="Poco.Data.SessionPool.html#2990" title="Poco::Data::SessionPool::used()">used</a></p>
<h2>Types</h2>
<h3><a name="2997">PooledSessionHolderPtr</a> <img src="images/protected.gif" alt="protected" title="protected" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">typedef <a href="Poco.AutoPtr.html" title="class Poco::AutoPtr">Poco::AutoPtr</a> < <a href="Poco.Data.PooledSessionHolder.html" title="class Poco::Data::PooledSessionHolder">PooledSessionHolder</a> > <a href="Poco.Data.SessionPool.html#2997" title="Poco::Data::SessionPool::PooledSessionHolderPtr">PooledSessionHolderPtr</a>;</p>
<div class="description">
<p></p>
</div>
<h3><a name="2998">PooledSessionImplPtr</a> <img src="images/protected.gif" alt="protected" title="protected" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">typedef <a href="Poco.AutoPtr.html" title="class Poco::AutoPtr">Poco::AutoPtr</a> < <a href="Poco.Data.PooledSessionImpl.html" title="class Poco::Data::PooledSessionImpl">PooledSessionImpl</a> > <a href="Poco.Data.SessionPool.html#2998" title="Poco::Data::SessionPool::PooledSessionImplPtr">PooledSessionImplPtr</a>;</p>
<div class="description">
<p></p>
</div>
<h3><a name="2999">SessionList</a> <img src="images/protected.gif" alt="protected" title="protected" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">typedef std::list < <a href="Poco.Data.SessionPool.html#2997" title="Poco::Data::SessionPool::PooledSessionHolderPtr">PooledSessionHolderPtr</a> > <a href="Poco.Data.SessionPool.html#2999" title="Poco::Data::SessionPool::SessionList">SessionList</a>;</p>
<div class="description">
<p></p>
</div>
<h2>Constructors</h2>
<h3><a name="2981">SessionPool</a></h3>
<p class="decl"><a href="Poco.Data.SessionPool.html" title="class Poco::Data::SessionPool">SessionPool</a>(<br /> const std::string & sessionKey,<br /> const std::string & connectionString,<br /> int minSessions = 1,<br /> int maxSessions = 32,<br /> int idleTime = 60<br />);</p>
<div class="description">
<p>Creates the <a href="Poco.Data.SessionPool.html" title="class Poco::Data::SessionPool">SessionPool</a> for sessions with the given sessionKey and connectionString. </p>
<p>The pool allows for at most maxSessions sessions to be created. If a session has been idle for more than idleTime seconds, and more than minSessions sessions are in the pool, the session is automatically destroyed. </p>
<p>If idleTime is 0, automatic cleanup of unused sessions is disabled. </p>
</div>
<h2>Destructor</h2>
<h3><a name="2987">~SessionPool</a> <img src="images/virtual.gif" alt="virtual" title="virtual" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">virtual ~<a href="Poco.Data.SessionPool.html" title="class Poco::Data::SessionPool">SessionPool</a>();</p>
<div class="description">
<p>Destroys the <a href="Poco.Data.SessionPool.html" title="class Poco::Data::SessionPool">SessionPool</a>. </p>
</div>
<h2>Member Functions</h2>
<h3><a name="2993">allocated</a></h3>
<p class="decl">int allocated() const;</p>
<div class="description">
<p>Returns the number of allocated sessions. </p>
</div>
<h3><a name="2994">available</a></h3>
<p class="decl">int available() const;</p>
<div class="description">
<p>Returns the number of available (idle + remaining capacity) sessions. </p>
</div>
<h3><a name="2989">capacity</a></h3>
<p class="decl">int capacity() const;</p>
<div class="description">
<p>Returns the maximum number of sessions the <a href="Poco.Data.SessionPool.html" title="class Poco::Data::SessionPool">SessionPool</a> will manage. </p>
</div>
<h3><a name="2992">dead</a></h3>
<p class="decl">int dead();</p>
<div class="description">
<p>Returns the number of not connected active sessions. </p>
</div>
<h3><a name="2988">get</a></h3>
<p class="decl"><a href="Poco.Data.Session.html" title="class Poco::Data::Session">Session</a> get();</p>
<div class="description">
<p>Returns a <a href="Poco.Data.Session.html" title="class Poco::Data::Session">Session</a>. </p>
<p>If there are unused sessions available, one of the unused sessions is recycled. Otherwise, a new session is created. </p>
<p>If the maximum number of sessions for this pool has already been created, a <a href="Poco.Data.SessionPoolExhaustedException.html" title="class Poco::Data::SessionPoolExhaustedException">SessionPoolExhaustedException</a> is thrown. </p>
</div>
<h3><a name="2991">idle</a></h3>
<p class="decl">int idle() const;</p>
<div class="description">
<p>Returns the number of idle sessions. </p>
</div>
<h3><a name="2990">used</a></h3>
<p class="decl">int used() const;</p>
<div class="description">
<p>Returns the number of sessions currently in use. </p>
</div>
<h3><a name="2995">customizeSession</a> <img src="images/protected.gif" alt="protected" title="protected" style="vertical-align:baseline;" border="0" /> <img src="images/virtual.gif" alt="virtual" title="virtual" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">virtual void customizeSession(<br /> <a href="Poco.Data.Session.html" title="class Poco::Data::Session">Session</a> & session<br />);</p>
<div class="description">
<p>Can be overridden by subclass to perform custom initialization of a newly created database session. </p>
<p>The default implementation does nothing. </p>
</div>
<h3><a name="3001">deadImpl</a> <img src="images/protected.gif" alt="protected" title="protected" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">int deadImpl(<br /> <a href="Poco.Data.SessionPool.html#2999" title="Poco::Data::SessionPool::SessionList">SessionList</a> & rSessions<br />);</p>
<div class="description">
<p></p>
</div>
<h3><a name="3005">onJanitorTimer</a> <img src="images/protected.gif" alt="protected" title="protected" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">void onJanitorTimer(<br /> <a href="Poco.Timer.html" title="class Poco::Timer">Poco::Timer</a> & param39<br />);</p>
<div class="description">
<p></p>
</div>
<h3><a name="3000">purgeDeadSessions</a> <img src="images/protected.gif" alt="protected" title="protected" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">void purgeDeadSessions();</p>
<div class="description">
<p></p>
</div>
<h3><a name="3003">putBack</a> <img src="images/protected.gif" alt="protected" title="protected" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">void putBack(<br /> <a href="Poco.Data.SessionPool.html#2997" title="Poco::Data::SessionPool::PooledSessionHolderPtr">PooledSessionHolderPtr</a> pHolder<br />);</p>
<div class="description">
<p></p>
</div>
<p class="footer">POCO C++ Libraries 1.3.6-all<br />
Copyright © 2009, <a href="http://pocoproject.org/" target="_blank">Applied Informatics Software Engineering GmbH and Contributors</a></p>
</div>
</body>
</html>
|