2018-08-07 17:57:44 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Interpreters/Context.h>
|
|
|
|
#include <Poco/Logger.h>
|
|
|
|
#include <Poco/Net/HTTPRequestHandler.h>
|
|
|
|
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
2018-08-09 12:57:34 +00:00
|
|
|
#include <Poco/Data/SessionPool.h>
|
2018-08-07 17:57:44 +00:00
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2018-08-10 14:46:12 +00:00
|
|
|
/** Main handler for requests to ODBC driver
|
|
|
|
* requires connection_string and columns in request params
|
|
|
|
* and also query in request body
|
|
|
|
* response in RowBinary format
|
|
|
|
*/
|
2018-08-08 16:15:29 +00:00
|
|
|
class ODBCHandler : public Poco::Net::HTTPRequestHandler
|
2018-08-07 17:57:44 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-08-09 12:57:34 +00:00
|
|
|
using PoolPtr = std::shared_ptr<Poco::Data::SessionPool>;
|
|
|
|
using PoolMap = std::unordered_map<std::string, PoolPtr>;
|
|
|
|
|
|
|
|
ODBCHandler(std::shared_ptr<PoolMap> pool_map_,
|
2018-08-07 17:57:44 +00:00
|
|
|
size_t keep_alive_timeout_,
|
2020-05-13 18:30:26 +00:00
|
|
|
Context & context_,
|
2020-04-28 00:56:44 +00:00
|
|
|
const String & mode_)
|
2018-08-08 16:15:29 +00:00
|
|
|
: log(&Poco::Logger::get("ODBCHandler"))
|
2018-08-09 12:57:34 +00:00
|
|
|
, pool_map(pool_map_)
|
2018-08-07 17:57:44 +00:00
|
|
|
, keep_alive_timeout(keep_alive_timeout_)
|
|
|
|
, context(context_)
|
2020-04-28 00:56:44 +00:00
|
|
|
, mode(mode_)
|
2018-08-07 17:57:44 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void handleRequest(Poco::Net::HTTPServerRequest & request, Poco::Net::HTTPServerResponse & response) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Poco::Logger * log;
|
2018-08-09 12:57:34 +00:00
|
|
|
|
|
|
|
std::shared_ptr<PoolMap> pool_map;
|
2018-08-07 17:57:44 +00:00
|
|
|
size_t keep_alive_timeout;
|
2020-04-17 14:40:39 +00:00
|
|
|
Context & context;
|
2020-04-28 00:56:44 +00:00
|
|
|
String mode;
|
2018-08-09 12:57:34 +00:00
|
|
|
|
|
|
|
static inline std::mutex mutex;
|
|
|
|
|
|
|
|
PoolPtr getPool(const std::string & connection_str);
|
2020-04-28 00:56:44 +00:00
|
|
|
void processError(Poco::Net::HTTPServerResponse & response, const std::string & message);
|
2018-08-07 17:57:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|