0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-16 04:47:18 +08:00

Reordered template arguments

This commit is contained in:
Frank Park 2017-04-02 11:06:12 -04:00
parent 71a234c4ba
commit 9f26495ced
2 changed files with 15 additions and 18 deletions

View File

@ -104,11 +104,11 @@ namespace sqlpp
} }
template <typename Connection_config, template <typename Connection_config,
typename Connection = typename std::enable_if<std::is_class<Connection_config::connection>::value, Connection_config::connection>::type, typename Reconnect_policy = reconnect_policy::auto_reconnect,
typename Reconnect_policy = reconnect_policy::auto_reconnect> typename Connection = typename std::enable_if<std::is_class<Connection_config::connection>::value, Connection_config::connection>::type>
class connection_pool class connection_pool
{ {
friend pool_connection<Connection, Connection_config, Reconnect_policy>; friend pool_connection<Connection_config, Reconnect_policy, Connection>;
private: private:
std::mutex connection_pool_mutex; std::mutex connection_pool_mutex;
@ -145,9 +145,8 @@ namespace sqlpp
} }
public: public:
connection_pool(const std::shared_ptr<Connection_config>& config, size_t pool_size, connection_pool(const std::shared_ptr<Connection_config>& config, size_t pool_size)
Reconnect_policy reconnect_policy = sqlpp::reconnect_policy::auto_reconnect()) : config(config), maximum_pool_size(pool_size), reconnect_policy(Reconnect_policy()) {}
: config(config), maximum_pool_size(pool_size), reconnect_policy(reconnect_policy) {}
~connection_pool() = default; ~connection_pool() = default;
connection_pool(const connection_pool&) = delete; connection_pool(const connection_pool&) = delete;
connection_pool(connection_pool&& other) connection_pool(connection_pool&& other)
@ -156,19 +155,19 @@ namespace sqlpp
connection_pool& operator=(const connection_pool&) = delete; connection_pool& operator=(const connection_pool&) = delete;
connection_pool& operator=(connection_pool&&) = delete; connection_pool& operator=(connection_pool&&) = delete;
pool_connection<Connection, Connection_config, Reconnect_policy> get_connection() pool_connection<Connection_config, Reconnect_policy, Connection> get_connection()
{ {
std::lock_guard<std::mutex> lock(connection_pool_mutex); std::lock_guard<std::mutex> lock(connection_pool_mutex);
if (!free_connections.empty()) if (!free_connections.empty())
{ {
auto connection = std::move(free_connections.top()); auto connection = std::move(free_connections.top());
free_connections.pop(); free_connections.pop();
return pool_connection<Connection, Connection_config, Reconnect_policy>(connection, this); return pool_connection<Connection_config, Reconnect_policy, Connection>(connection, this);
} }
try try
{ {
return pool_connection<Connection, Connection_config, Reconnect_policy>(std::move(std::make_unique<Connection>(config)), this); return pool_connection<Connection_config, Reconnect_policy, Connection>(std::move(std::make_unique<Connection>(config)), this);
} }
catch (const sqlpp::exception& e) catch (const sqlpp::exception& e)
{ {
@ -180,15 +179,13 @@ namespace sqlpp
}; };
template<typename Connection_config, template<typename Connection_config,
typename Connection = typename std::enable_if<std::is_class<Connection_config::connection>::value, Connection_config::connection>::type, typename Reconnect_policy = reconnect_policy::auto_reconnect,
typename Reconnect_policy = reconnect_policy::auto_reconnect> typename Connection = typename std::enable_if<std::is_class<Connection_config::connection>::value,Connection_config::connection>::type>
connection_pool<Connection_config, Connection, Reconnect_policy> make_connection_pool( connection_pool<Connection_config, Reconnect_policy, Connection> make_connection_pool(
const std::shared_ptr<Connection_config>& config, const std::shared_ptr<Connection_config>& config,
size_t max_pool_size, size_t max_pool_size)
Reconnect_policy reconnect_policy = reconnect_policy::auto_reconnect()
)
{ {
return connection_pool<Connection_config, Connection, Reconnect_policy>(config, max_pool_size, reconnect_policy); return connection_pool<Connection_config, Reconnect_policy, Connection>(config, max_pool_size);
} }
} }

View File

@ -31,8 +31,8 @@
namespace sqlpp namespace sqlpp
{ {
template <typename Connection, typename Connection_config, typename Reconnect_policy, template <typename Connection_config, typename Reconnect_policy, typename Connection,
typename Connection_pool = connection_pool<Connection_config, Connection, Reconnect_policy>> typename Connection_pool = connection_pool<Connection_config, Reconnect_policy, Connection>>
struct pool_connection struct pool_connection
{ {
private: private: