mirror of
https://github.com/pocoproject/poco.git
synced 2025-03-30 07:26:33 +02:00
SessionPoolContainer: added getPool() and FastMutex locking
This commit is contained in:
parent
6fa5bcf09f
commit
0bd881fd5e
@ -44,6 +44,7 @@
|
||||
#include "Poco/Data/Session.h"
|
||||
#include "Poco/Data/SessionPool.h"
|
||||
#include "Poco/HashMap.h"
|
||||
#include "Poco/Mutex.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@ -74,7 +75,12 @@ public:
|
||||
/// ignored and session is returned from the existing pool.
|
||||
|
||||
Session get(const std::string& name);
|
||||
/// Returns a Session.
|
||||
/// Returns the requested Session.
|
||||
/// Throws NotFoundException if session is not found.
|
||||
|
||||
SessionPool& getPool(const std::string& name);
|
||||
/// Returns a SessionPool reference.
|
||||
/// Throws NotFoundException if session is not found.
|
||||
|
||||
void remove(const std::string& name);
|
||||
/// Removes a SessionPool.
|
||||
@ -91,7 +97,8 @@ private:
|
||||
SessionPoolContainer(const SessionPoolContainer&);
|
||||
SessionPoolContainer& operator = (const SessionPoolContainer&);
|
||||
|
||||
SessionPoolMap _sessionPools;
|
||||
SessionPoolMap _sessionPools;
|
||||
Poco::FastMutex _mutex;
|
||||
};
|
||||
|
||||
|
||||
|
@ -43,6 +43,9 @@
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
using Poco::FastMutex;
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
|
||||
@ -59,6 +62,7 @@ SessionPoolContainer::~SessionPoolContainer()
|
||||
|
||||
void SessionPoolContainer::add(SessionPool* pPool)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
poco_check_ptr (pPool);
|
||||
|
||||
if (_sessionPools.find(pPool->name()) != _sessionPools.end())
|
||||
@ -75,6 +79,7 @@ Session SessionPoolContainer::add(const std::string& sessionKey,
|
||||
int maxSessions,
|
||||
int idleTime)
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
std::string name = SessionPool::name(sessionKey, connectionString);
|
||||
SessionPoolMap::Iterator it = _sessionPools.find(name);
|
||||
|
||||
@ -92,6 +97,12 @@ Session SessionPoolContainer::add(const std::string& sessionKey,
|
||||
|
||||
|
||||
Session SessionPoolContainer::get(const std::string& name)
|
||||
{
|
||||
return getPool(name).get();
|
||||
}
|
||||
|
||||
|
||||
SessionPool& SessionPoolContainer::getPool(const std::string& name)
|
||||
{
|
||||
URI uri(name);
|
||||
std::string path = uri.getPath();
|
||||
@ -99,7 +110,7 @@ Session SessionPoolContainer::get(const std::string& name)
|
||||
std::string n = Session::uri(uri.getScheme(), path.substr(1));
|
||||
SessionPoolMap::Iterator it = _sessionPools.find(n);
|
||||
if (_sessionPools.end() == it) throw NotFoundException(n);
|
||||
return it->second->get();
|
||||
return *it->second;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user