2021-03-06 18:21:40 +00:00
|
|
|
#include "SharedLibraryHandlerFactory.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2021-03-22 15:58:20 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int LOGICAL_ERROR;
|
|
|
|
}
|
|
|
|
|
2021-03-06 18:21:40 +00:00
|
|
|
SharedLibraryHandlerPtr SharedLibraryHandlerFactory::get(const std::string & dictionary_id)
|
|
|
|
{
|
|
|
|
std::lock_guard lock(mutex);
|
|
|
|
auto library_handler = library_handlers.find(dictionary_id);
|
|
|
|
|
|
|
|
if (library_handler != library_handlers.end())
|
|
|
|
return library_handler->second;
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-24 08:41:42 +00:00
|
|
|
void SharedLibraryHandlerFactory::create(
|
2021-03-24 09:23:29 +00:00
|
|
|
const std::string & dictionary_id,
|
|
|
|
const std::string & library_path,
|
|
|
|
const std::vector<std::string> & library_settings,
|
|
|
|
const Block & sample_block,
|
2021-03-24 19:32:31 +00:00
|
|
|
const std::vector<std::string> & attributes_names)
|
2021-03-06 18:21:40 +00:00
|
|
|
{
|
|
|
|
std::lock_guard lock(mutex);
|
2021-03-24 19:32:31 +00:00
|
|
|
library_handlers[dictionary_id] = std::make_shared<SharedLibraryHandler>(library_path, library_settings, sample_block, attributes_names);
|
2021-03-06 18:21:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-22 15:58:20 +00:00
|
|
|
void SharedLibraryHandlerFactory::clone(const std::string & from_dictionary_id, const std::string & to_dictionary_id)
|
2021-03-06 18:21:40 +00:00
|
|
|
{
|
|
|
|
std::lock_guard lock(mutex);
|
|
|
|
auto from_library_handler = library_handlers.find(from_dictionary_id);
|
|
|
|
|
2021-03-07 15:23:20 +00:00
|
|
|
/// This is not supposed to happen as libClone is called from copy constructor of LibraryDictionarySource
|
2021-03-06 18:21:40 +00:00
|
|
|
/// object, and shared library handler of from_dictionary is removed only in its destructor.
|
|
|
|
/// And if for from_dictionary there was no shared library handler, it would have received and exception in
|
2021-03-07 15:23:20 +00:00
|
|
|
/// its constructor, so no libClone would be made from it.
|
2021-03-06 18:21:40 +00:00
|
|
|
if (from_library_handler == library_handlers.end())
|
2021-03-22 15:58:20 +00:00
|
|
|
throw Exception(ErrorCodes::LOGICAL_ERROR, "No shared library handler found");
|
|
|
|
|
|
|
|
/// libClone method will be called in copy constructor
|
|
|
|
library_handlers[to_dictionary_id] = std::make_shared<SharedLibraryHandler>(*from_library_handler->second);
|
2021-03-06 18:21:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-22 15:58:20 +00:00
|
|
|
void SharedLibraryHandlerFactory::remove(const std::string & dictionary_id)
|
2021-03-06 18:21:40 +00:00
|
|
|
{
|
|
|
|
std::lock_guard lock(mutex);
|
2021-03-22 15:58:20 +00:00
|
|
|
/// libDelete is called in destructor.
|
|
|
|
library_handlers.erase(dictionary_id);
|
2021-03-06 18:21:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SharedLibraryHandlerFactory & SharedLibraryHandlerFactory::instance()
|
|
|
|
{
|
|
|
|
static SharedLibraryHandlerFactory ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|