summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2018-04-11 23:04:20 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2018-04-12 18:27:12 +0100
commitb2923581fc44ce9d54e6552e729f80375c3801b3 (patch)
tree18d5d28a8ca43306f8f9d153e4c6a4fa05d6e40b
parentC++17 (diff)
downloadlibdbpp-b2923581fc44ce9d54e6552e729f80375c3801b3.tar.bz2
libdbpp-b2923581fc44ce9d54e6552e729f80375c3801b3.tar.xz
libdbpp-b2923581fc44ce9d54e6552e729f80375c3801b3.zip
Split ConnectionPool into two
Allows implementing a non-factory based version whilst keeping a standard base
-rw-r--r--libdbpp/connectionPool.cpp11
-rw-r--r--libdbpp/connectionPool.h23
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