00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __PION_DATABASEMANAGER_HEADER__
00021 #define __PION_DATABASEMANAGER_HEADER__
00022
00023 #include <string>
00024 #include <libxml/tree.h>
00025 #include <pion/PionConfig.hpp>
00026 #include <pion/PionException.hpp>
00027 #include <pion/platform/Database.hpp>
00028 #include <pion/platform/PluginConfig.hpp>
00029
00030
00031 namespace pion {
00032 namespace platform {
00033
00037 class PION_PLATFORM_API DatabaseManager :
00038 public PluginConfig<Database>
00039 {
00040 public:
00041
00043 class DatabaseNotFoundException : public PionException {
00044 public:
00045 DatabaseNotFoundException(const std::string& database_id)
00046 : PionException("No databases found for identifier: ", database_id) {}
00047 };
00048
00049
00051 virtual ~DatabaseManager() {}
00052
00058 explicit DatabaseManager(const VocabularyManager& vocab_mgr);
00059
00066 DatabasePtr getDatabase(const std::string& database_id);
00067
00075 void setDatabaseConfig(const std::string& database_id,
00076 const xmlNodePtr config_ptr);
00077
00086 std::string addDatabase(const xmlNodePtr config_ptr);
00087
00093 void removeDatabase(const std::string& database_id);
00094
00103 static xmlNodePtr createDatabaseConfig(const char *buf, std::size_t len) {
00104 return ConfigManager::createResourceConfig(DATABASE_ELEMENT_NAME, buf, len);
00105 }
00106
00112 void writeDatabaseEnginesXML(std::ostream& out);
00113
00120 xmlDocPtr getDatabaseEngineConfig(const std::string& database_engine, xmlNodePtr& config_detail_ptr);
00121
00123 std::string getPermissionType(void) const { return DATABASES_PERMISSION_TYPE; }
00124
00125
00126 protected:
00127
00139 virtual void addPluginNoLock(const std::string& plugin_id,
00140 const std::string& plugin_name,
00141 const xmlNodePtr config_ptr)
00142 {
00143 try {
00144 Database *new_plugin_ptr = m_plugins.load(plugin_id, plugin_name);
00145 new_plugin_ptr->setId(plugin_id);
00146 new_plugin_ptr->setDatabaseManager(*this);
00147 if (config_ptr != NULL) {
00148 VocabularyPtr vocab_ptr(m_vocab_mgr.getVocabulary());
00149 new_plugin_ptr->setConfig(*vocab_ptr, config_ptr);
00150 }
00151 } catch (PionPlugin::PluginNotFoundException&) {
00152 throw;
00153 } catch (std::exception& e) {
00154 throw PluginException(e.what());
00155 }
00156 }
00157
00158
00159 private:
00160
00162 static const std::string DEFAULT_CONFIG_FILE;
00163
00165 static const std::string DATABASE_ELEMENT_NAME;
00166
00168 static const std::string DATABASES_PERMISSION_TYPE;
00169
00171 static const std::string TEMPLATE_FILE;
00172
00174 static const std::string DBENGINES_ROOT_ELEMENT_NAME;
00175 static const std::string TEMPLATE_ELEMENT_NAME;
00176 static const std::string ENGINE_ELEMENT_NAME;
00177
00179 static const std::string DEFAULT_DATABASE_TYPE;
00180 };
00181
00182
00183 }
00184 }
00185
00186 #endif