Session SessionPool::get(SessionPool::SessionDataPtr &session_data_ptr) { Poco::Mutex::ScopedLock lock(_mutex); if (_shutdown) throw InvalidAccessException("Session pool has been shut down."); purgeDeadSessions(); if (_idleSessions.empty()) { Session newSession(SessionFactory::instance().create(_connector, _connectionString)); applySettings(newSession.impl()); PooledSessionHolderPtr pHolder(new PooledSessionHolder(*this, newSession.impl())); session_data_ptr.assign(new SessionData); session_data_ptr->session = pHolder; _idleSessions.push_front(session_data_ptr); ++_nSessions; } PooledSessionHolderPtr pHolder(_idleSessions.front()->session); PooledSessionImplPtr pPSI(new PooledSessionImpl(pHolder)); _activeSessions.push_front(std::move(_idleSessions.front())); _idleSessions.pop_front(); if (session_data_ptr.isNull()) { session_data_ptr.assign(_activeSessions.front()); } return Session(pPSI); }
Session SessionPool::get() { Poco::Mutex::ScopedLock lock(_mutex); if (_shutdown) throw InvalidAccessException("Session pool has been shut down."); purgeDeadSessions(); if (_idleSessions.empty()) { if (_nSessions < _maxSessions) { Session newSession(SessionFactory::instance().create(_connector, _connectionString)); applySettings(newSession.impl()); customizeSession(newSession); PooledSessionHolderPtr pHolder(new PooledSessionHolder(*this, newSession.impl())); _idleSessions.push_front(pHolder); ++_nSessions; } else throw SessionPoolExhaustedException(_connector); } PooledSessionHolderPtr pHolder(_idleSessions.front()); PooledSessionImplPtr pPSI(new PooledSessionImpl(pHolder)); _activeSessions.push_front(pHolder); _idleSessions.pop_front(); return Session(pPSI); }
Session SessionPool::get() { Poco::FastMutex::ScopedLock lock(_mutex); purgeDeadSessions(); if (_idleSessions.empty()) { if (_nSessions < _maxSessions) { Session newSession(SessionFactory::instance().create(_sessionKey, _connectionString)); PooledSessionHolderPtr pHolder(new PooledSessionHolder(*this, newSession.impl())); _idleSessions.push_front(pHolder); ++_nSessions; } else throw SessionPoolExhaustedException(_sessionKey, _connectionString); } PooledSessionHolderPtr pHolder(_idleSessions.front()); PooledSessionImplPtr pPSI(new PooledSessionImpl(pHolder)); _activeSessions.push_front(pHolder); _idleSessions.pop_front(); return Session(pPSI); }