8 #include "knowrob/Logger.h"
9 #include "knowrob/storage/StorageManager.h"
10 #include "knowrob/storage/StorageError.h"
11 #include "knowrob/storage/QueryableStorage.h"
17 vocabulary_(vocabulary) {
22 std::shared_ptr<BackendFactory> factory =
findFactory(config);
24 if (!factory)
throw StorageError(
"failed to load a backend.");
27 KB_INFO(
"Using backend `{}` with type `{}`.", backendID, factory->name());
30 auto definedBackend = factory->create(backendID);
31 definedBackend->value()->setVocabulary(
vocabulary());
33 PropertyTree pluginConfig(std::make_shared<boost::property_tree::ptree>(config));
38 success = definedBackend->value()->initializeBackend(pluginConfig);
40 success = definedBackend->value()->initializeBackend(pluginConfig);
44 KB_WARN(
"Backend `{}` failed to loadConfig.", backendID);
49 return definedBackend;
54 KB_WARN(
"Overwriting backend with name '{}'", backendID);
56 auto managedBackend = std::make_shared<NamedBackend>(backendID, language, backend);
57 pluginPool_.emplace(managedBackend->name(), managedBackend);
58 initBackend(managedBackend);
59 return managedBackend;
64 KB_WARN(
"Overwriting backend with name '{}'", definedKG->name());
67 initBackend(definedKG);
70 void StorageManager::initBackend(
const std::shared_ptr<NamedBackend> &definedKG) {
71 definedKG->value()->setStorageLanguage(definedKG->language());
72 definedKG->value()->setVocabulary(
vocabulary());
74 auto queryable = std::dynamic_pointer_cast<QueryableStorage>(definedKG->value());
76 KB_INFO(
"Using queryable backend with id '{}'.", definedKG->name());
77 queryable_[definedKG->name()] =
queryable;
81 KB_INFO(
"Using persistent backend with id '{}'.", definedKG->name());
82 persistent_[definedKG->name()] =
queryable;
std::shared_ptr< PluginFactory< Storage > > findFactory(const boost::property_tree::ptree &config)
std::string getPluginID(const std::shared_ptr< PluginFactory< Storage >> &factory, const boost::property_tree::ptree &config)
std::map< std::string_view, std::shared_ptr< NamedPlugin< Storage > >, std::less<> > pluginPool_
StorageManager(const std::shared_ptr< Vocabulary > &vocabulary)
std::shared_ptr< NamedBackend > loadPlugin(const boost::property_tree::ptree &config) override
const auto & queryable() const
void addPlugin(const std::shared_ptr< NamedBackend > &backend)
auto & vocabulary() const
std::shared_ptr< Storage > StoragePtr