mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-12 18:20:26 +01:00
added SessionPoolExistsException
when duplicate session add is requested by name, it is silently ignored
This commit is contained in:
parent
4e0cc97d6a
commit
dcede96ede
@ -59,6 +59,7 @@ POCO_DECLARE_EXCEPTION(Data_API, LimitException, DataException)
|
||||
POCO_DECLARE_EXCEPTION(Data_API, NotSupportedException, DataException)
|
||||
POCO_DECLARE_EXCEPTION(Data_API, SessionUnavailableException, DataException)
|
||||
POCO_DECLARE_EXCEPTION(Data_API, SessionPoolExhaustedException, DataException)
|
||||
POCO_DECLARE_EXCEPTION(Data_API, SessionPoolExistsException, DataException)
|
||||
POCO_DECLARE_EXCEPTION(Data_API, NoDataException, DataException)
|
||||
POCO_DECLARE_EXCEPTION(Data_API, LengthExceededException, DataException)
|
||||
|
||||
|
@ -62,6 +62,7 @@ public:
|
||||
|
||||
void add(SessionPool* pPool);
|
||||
/// Adds existing session pool to the container.
|
||||
/// Throws SessionPoolExistsException if pool already exists.
|
||||
|
||||
Session add(const std::string& sessionKey,
|
||||
const std::string& connectionString,
|
||||
@ -69,7 +70,8 @@ public:
|
||||
int maxSessions = 32,
|
||||
int idleTime = 60);
|
||||
/// Adds a new session pool to the container and returns a Session from
|
||||
/// newly created pool.
|
||||
/// newly created pool. If pool already exists, request to add is silently
|
||||
/// ignored and session is returned from the existing pool.
|
||||
|
||||
Session get(const std::string& name);
|
||||
/// Returns a Session.
|
||||
|
@ -53,6 +53,7 @@ POCO_IMPLEMENT_EXCEPTION(LimitException, DataException, "Limit error")
|
||||
POCO_IMPLEMENT_EXCEPTION(NotSupportedException, DataException, "Feature or property not supported")
|
||||
POCO_IMPLEMENT_EXCEPTION(SessionUnavailableException, DataException, "Session is unavailable")
|
||||
POCO_IMPLEMENT_EXCEPTION(SessionPoolExhaustedException, DataException, "No more sessions available from the session pool")
|
||||
POCO_IMPLEMENT_EXCEPTION(SessionPoolExistsException, DataException, "Session already exists in the pool")
|
||||
POCO_IMPLEMENT_EXCEPTION(NoDataException, DataException, "No data found")
|
||||
POCO_IMPLEMENT_EXCEPTION(LengthExceededException, DataException, "Data too long")
|
||||
|
||||
|
@ -60,7 +60,7 @@ void SessionPoolContainer::add(SessionPool* pPool)
|
||||
poco_check_ptr (pPool);
|
||||
|
||||
if (_sessionPools.find(pPool->name()) != _sessionPools.end())
|
||||
throw InvalidAccessException("Session pool already exists: " + pPool->name());
|
||||
throw SessionPoolExistsException("Session pool already exists: " + pPool->name());
|
||||
|
||||
pPool->duplicate();
|
||||
_sessionPools.insert(SessionPoolMap::ValueType(pPool->name(), pPool));
|
||||
@ -73,14 +73,15 @@ Session SessionPoolContainer::add(const std::string& sessionKey,
|
||||
int maxSessions,
|
||||
int idleTime)
|
||||
{
|
||||
std::string name = SessionPool::name(sessionKey, connectionString);
|
||||
SessionPoolMap::Iterator it = _sessionPools.find(name);
|
||||
|
||||
// pool already exists, silently return a session from it
|
||||
if (it != _sessionPools.end()) return it->second->get();
|
||||
|
||||
SessionPool* pSP =
|
||||
new SessionPool(sessionKey, connectionString, minSessions, maxSessions, idleTime);
|
||||
|
||||
std::string name = pSP->name();
|
||||
|
||||
if (_sessionPools.find(name) != _sessionPools.end())
|
||||
throw InvalidAccessException("Session pool already exists: " + name);
|
||||
|
||||
std::pair<SessionPoolMap::Iterator, bool> ins =
|
||||
_sessionPools.insert(SessionPoolMap::ValueType(name, pSP));
|
||||
|
||||
|
@ -50,6 +50,7 @@ using Poco::Data::Session;
|
||||
using Poco::Data::SessionPool;
|
||||
using Poco::Data::SessionPoolContainer;
|
||||
using Poco::Data::SessionPoolExhaustedException;
|
||||
using Poco::Data::SessionPoolExistsException;
|
||||
using Poco::Data::SessionUnavailableException;
|
||||
|
||||
|
||||
@ -228,13 +229,14 @@ void SessionPoolTest::testSessionPoolContainer()
|
||||
spc.add(pPool);
|
||||
assert (1 == spc.count());
|
||||
try { spc.add(pPool); fail ("must fail"); }
|
||||
catch (InvalidAccessException&) { }
|
||||
catch (SessionPoolExistsException&) { }
|
||||
spc.remove(pPool->name());
|
||||
assert (0 == spc.count());
|
||||
try { spc.get("test"); fail ("must fail"); }
|
||||
catch (NotFoundException&) { }
|
||||
|
||||
spc.add("test", "cs");
|
||||
spc.add("test", "cs");//duplicate request, must be silently ignored
|
||||
assert (1 == spc.count());
|
||||
spc.remove("test://cs");
|
||||
assert (0 == spc.count());
|
||||
|
Loading…
Reference in New Issue
Block a user