/** * * DbClientLockFree.h * An Tao * * Copyright 2018, An Tao. All rights reserved. * https://github.com/an-tao/drogon * Use of this source code is governed by a MIT license * that can be found in the License file. * * Drogon * */ #pragma once #include "DbConnection.h" #include #include #include #include #include #include #include #include namespace drogon { namespace orm { class DbClientLockFree : public DbClient, public std::enable_shared_from_this { public: DbClientLockFree(const std::string &connInfo, trantor::EventLoop *loop, ClientType type, size_t connectionNumberPerLoop); virtual ~DbClientLockFree() noexcept; virtual void execSql(const char *sql, size_t sqlLength, size_t paraNum, std::vector &¶meters, std::vector &&length, std::vector &&format, ResultCallback &&rcb, std::function &&exceptCallback) override; virtual std::shared_ptr newTransaction( const std::function &commitCallback = nullptr) override; virtual void newTransactionAsync( const std::function &)> &callback) override; virtual bool hasAvailableConnections() const noexcept override; private: std::string connectionInfo_; trantor::EventLoop *loop_; DbConnectionPtr newConnection(); const size_t connectionsNumber_; std::vector connections_; std::vector connectionHolders_; std::unordered_set transSet_; std::deque> sqlCmdBuffer_; std::queue &)>> transCallbacks_; void makeTrans( const DbConnectionPtr &conn, std::function &)> &&callback); void handleNewTask(const DbConnectionPtr &conn); #if LIBPQ_SUPPORTS_BATCH_MODE size_t connectionPos_{0}; // Used for pg batch mode. #endif }; } // namespace orm } // namespace drogon