mirror of
https://github.com/pocoproject/poco.git
synced 2025-11-26 00:40:05 +01:00
[SF 2505290] DB connection as URI (MySQL not tested!)
This commit is contained in:
@@ -44,6 +44,7 @@ namespace Data {
|
||||
|
||||
|
||||
PooledSessionImpl::PooledSessionImpl(PooledSessionHolder* pHolder):
|
||||
SessionImpl(pHolder->session()->connectionString()),
|
||||
_pHolder(pHolder, true)
|
||||
{
|
||||
}
|
||||
@@ -113,6 +114,12 @@ void PooledSessionImpl::close()
|
||||
}
|
||||
|
||||
|
||||
const std::string& PooledSessionImpl::connectorName()
|
||||
{
|
||||
return access()->connectorName();
|
||||
}
|
||||
|
||||
|
||||
void PooledSessionImpl::setFeature(const std::string& name, bool state)
|
||||
{
|
||||
access()->setFeature(name, state);
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
|
||||
#include "Poco/Data/Session.h"
|
||||
#include "Poco/Data/SessionFactory.h"
|
||||
#include "Poco/String.h"
|
||||
#include "Poco/URI.h"
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
@@ -58,8 +60,14 @@ Session::Session(const std::string& connector, const std::string& connectionStri
|
||||
}
|
||||
|
||||
|
||||
Session::Session(const Session& other):
|
||||
_ptrImpl(other._ptrImpl),
|
||||
Session::Session(const std::string& connection)
|
||||
{
|
||||
Session newSession(SessionFactory::instance().create(connection));
|
||||
swap(newSession);
|
||||
}
|
||||
|
||||
|
||||
Session::Session(const Session& other): _ptrImpl(other._ptrImpl),
|
||||
_statementCreator(other._ptrImpl)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
|
||||
|
||||
#include "Poco/Data/SessionFactory.h"
|
||||
#include "Poco/URI.h"
|
||||
#include "Poco/String.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
@@ -62,36 +64,41 @@ void SessionFactory::add(Connector* pIn)
|
||||
{
|
||||
Poco::FastMutex::ScopedLock lock(_mutex);
|
||||
SessionInfo info(pIn);
|
||||
std::pair<Connectors::iterator, bool> res = _connectors.insert(std::make_pair(pIn->name(), info));
|
||||
if (!res.second)
|
||||
{
|
||||
res.first->second.cnt++;
|
||||
}
|
||||
std::pair<Connectors::iterator, bool> res =
|
||||
_connectors.insert(std::make_pair(toLower(pIn->name()), info));
|
||||
if (!res.second) res.first->second.cnt++;
|
||||
}
|
||||
|
||||
|
||||
void SessionFactory::remove(const std::string& key)
|
||||
{
|
||||
Poco::FastMutex::ScopedLock lock(_mutex);
|
||||
Connectors::iterator it = _connectors.find(key);
|
||||
Connectors::iterator it = _connectors.find(toLower(key));
|
||||
poco_assert (_connectors.end() != it);
|
||||
|
||||
--(it->second.cnt);
|
||||
if (it->second.cnt == 0)
|
||||
_connectors.erase(it);
|
||||
if (it->second.cnt == 0) _connectors.erase(it);
|
||||
}
|
||||
|
||||
|
||||
Session SessionFactory::create(const std::string& key, const std::string& connectionString)
|
||||
{
|
||||
Poco::FastMutex::ScopedLock lock(_mutex);
|
||||
Connectors::iterator it = _connectors.find(key);
|
||||
Connectors::iterator it = _connectors.find(toLower(key));
|
||||
poco_assert (_connectors.end() != it);
|
||||
|
||||
return Session(it->second.ptrSI->createSession(connectionString));
|
||||
}
|
||||
|
||||
|
||||
Session SessionFactory::create(const std::string& uri)
|
||||
{
|
||||
URI u(uri);
|
||||
poco_assert (!u.getPath().empty());
|
||||
return create(u.getScheme(), u.getPath().substr(1));
|
||||
}
|
||||
|
||||
|
||||
SessionFactory::SessionInfo::SessionInfo(Connector* pSI):
|
||||
cnt(1),
|
||||
ptrSI(pSI)
|
||||
|
||||
@@ -41,7 +41,8 @@ namespace Poco {
|
||||
namespace Data {
|
||||
|
||||
|
||||
SessionImpl::SessionImpl()
|
||||
SessionImpl::SessionImpl(const std::string& connectionString):
|
||||
_connectionString(connectionString)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -44,8 +44,8 @@ namespace Poco {
|
||||
namespace Data {
|
||||
|
||||
|
||||
SessionPool::SessionPool(const std::string& sessionKey, const std::string& connectionString, int minSessions, int maxSessions, int idleTime):
|
||||
_sessionKey(sessionKey),
|
||||
SessionPool::SessionPool(const std::string& connector, const std::string& connectionString, int minSessions, int maxSessions, int idleTime):
|
||||
_connector(connector),
|
||||
_connectionString(connectionString),
|
||||
_minSessions(minSessions),
|
||||
_maxSessions(maxSessions),
|
||||
@@ -76,7 +76,7 @@ Session SessionPool::get()
|
||||
{
|
||||
if (_nSessions < _maxSessions)
|
||||
{
|
||||
Session newSession(SessionFactory::instance().create(_sessionKey, _connectionString));
|
||||
Session newSession(SessionFactory::instance().create(_connector, _connectionString));
|
||||
|
||||
FeatureMap::Iterator fmIt = _featureMap.begin();
|
||||
FeatureMap::Iterator fmEnd = _featureMap.end();
|
||||
@@ -90,7 +90,7 @@ Session SessionPool::get()
|
||||
_idleSessions.push_front(pHolder);
|
||||
++_nSessions;
|
||||
}
|
||||
else throw SessionPoolExhaustedException(_sessionKey, _connectionString);
|
||||
else throw SessionPoolExhaustedException(_connector, _connectionString);
|
||||
}
|
||||
|
||||
PooledSessionHolderPtr pHolder(_idleSessions.front());
|
||||
|
||||
Reference in New Issue
Block a user