1#pragma once
2
3#include <Interpreters/Context.h>
4#include <Poco/Logger.h>
5#include <Poco/Net/HTTPRequestHandler.h>
6
7#pragma GCC diagnostic push
8#pragma GCC diagnostic ignored "-Wunused-parameter"
9 #include <Poco/Data/SessionPool.h>
10#pragma GCC diagnostic pop
11
12namespace DB
13{
14/** Main handler for requests to ODBC driver
15 * requires connection_string and columns in request params
16 * and also query in request body
17 * response in RowBinary format
18 */
19class ODBCHandler : public Poco::Net::HTTPRequestHandler
20{
21public:
22 using PoolPtr = std::shared_ptr<Poco::Data::SessionPool>;
23 using PoolMap = std::unordered_map<std::string, PoolPtr>;
24
25 ODBCHandler(std::shared_ptr<PoolMap> pool_map_,
26 size_t keep_alive_timeout_,
27 std::shared_ptr<Context> context_)
28 : log(&Poco::Logger::get("ODBCHandler"))
29 , pool_map(pool_map_)
30 , keep_alive_timeout(keep_alive_timeout_)
31 , context(context_)
32 {
33 }
34
35 void handleRequest(Poco::Net::HTTPServerRequest & request, Poco::Net::HTTPServerResponse & response) override;
36
37private:
38 Poco::Logger * log;
39
40 std::shared_ptr<PoolMap> pool_map;
41 size_t keep_alive_timeout;
42 std::shared_ptr<Context> context;
43
44 static inline std::mutex mutex;
45
46 PoolPtr getPool(const std::string & connection_str);
47};
48
49}
50