diff options
-rw-r--r-- | libdbpp/connectionPool.cpp | 11 | ||||
-rw-r--r-- | libdbpp/connectionPool.h | 23 |
2 files changed, 25 insertions, 9 deletions
diff --git a/libdbpp/connectionPool.cpp b/libdbpp/connectionPool.cpp index 739f48e..0eda241 100644 --- a/libdbpp/connectionPool.cpp +++ b/libdbpp/connectionPool.cpp @@ -5,8 +5,13 @@ template class AdHoc::ResourcePool<DB::Connection>; template class AdHoc::ResourceHandle<DB::Connection>; namespace DB { + BasicConnectionPool::BasicConnectionPool(unsigned int m, unsigned int k) : + ResourcePool<Connection>(m, k) + { + } + ConnectionPool::ConnectionPool(unsigned int m, unsigned int k, const std::string & t, const std::string & cs) : - ResourcePool<Connection>(m, k), + BasicConnectionPool(m, k), factory(ConnectionFactory::get(t)), connectionString(cs) { @@ -19,13 +24,13 @@ namespace DB { } void - ConnectionPool::returnTestResource(Connection const * c) const + BasicConnectionPool::returnTestResource(Connection const * c) const { c->finish(); } void - ConnectionPool::testResource(Connection const * c) const + BasicConnectionPool::testResource(Connection const * c) const { c->ping(); } diff --git a/libdbpp/connectionPool.h b/libdbpp/connectionPool.h index 3b1eed8..a3312ce 100644 --- a/libdbpp/connectionPool.h +++ b/libdbpp/connectionPool.h @@ -8,7 +8,21 @@ namespace DB { /// Specialisation of AdHoc::ResourcePool for database connections. - class DLL_PUBLIC ConnectionPool : public AdHoc::ResourcePool<Connection> { + class DLL_PUBLIC BasicConnectionPool : public AdHoc::ResourcePool<Connection> { + public: + /// Create a new connection pool. + /// @param max Maximum number of concurrent database connections. + /// @param keep Number of connections to keep open after use. + BasicConnectionPool(unsigned int max, unsigned int keep); + + protected: + /// Ping a connection. + void returnTestResource(Connection const *) const override; + /// Ping a connection. + void testResource(Connection const *) const override; + }; + + class DLL_PUBLIC ConnectionPool : public BasicConnectionPool { public: /// Create a new connection pool. /// @param max Maximum number of concurrent database connections. @@ -20,16 +34,13 @@ namespace DB { protected: /// Create a new connection. ConnectionPtr createResource() const override; - /// Ping a connection. - void returnTestResource(Connection const *) const override; - /// Ping a connection. - void testResource(Connection const *) const override; private: const ConnectionFactoryCPtr factory; const std::string connectionString; }; - typedef std::shared_ptr<ConnectionPool> ConnectionPoolPtr; + + typedef std::shared_ptr<BasicConnectionPool> ConnectionPoolPtr; } #endif |