2018-08-07 17:57:44 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
#include <Interpreters/Context_fwd.h>
|
2021-02-19 12:51:26 +00:00
|
|
|
#include <Server/HTTP/HTTPRequestHandler.h>
|
|
|
|
|
2018-08-07 17:57:44 +00:00
|
|
|
#include <Poco/Logger.h>
|
|
|
|
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
2021-02-19 12:51:26 +00:00
|
|
|
#include <Poco/Data/SessionPool.h>
|
2018-08-07 17:57:44 +00:00
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
|
2021-04-10 23:33:54 +00:00
|
|
|
#include <mutex>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
|
2018-08-07 17:57:44 +00:00
|
|
|
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
|
|
|
|
*/
|
2021-04-10 23:33:54 +00:00
|
|
|
class ODBCHandler : public HTTPRequestHandler, WithContext
|
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_,
|
2021-04-10 23:33:54 +00:00
|
|
|
ContextPtr context_,
|
2020-04-28 00:56:44 +00:00
|
|
|
const String & mode_)
|
2021-04-10 23:33:54 +00:00
|
|
|
: WithContext(context_)
|
|
|
|
, 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_)
|
2020-04-28 00:56:44 +00:00
|
|
|
, mode(mode_)
|
2018-08-07 17:57:44 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-02-19 12:51:26 +00:00
|
|
|
void handleRequest(HTTPServerRequest & request, HTTPServerResponse & response) override;
|
2018-08-07 17:57:44 +00:00
|
|
|
|
|
|
|
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-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);
|
2021-02-19 12:51:26 +00:00
|
|
|
void processError(HTTPServerResponse & response, const std::string & message);
|
2018-08-07 17:57:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|