26 #include <boost/algorithm/string.hpp>
27 #include <boost/foreach.hpp>
28 #include <boost/scoped_ptr.hpp>
43 map<string, HostDataSourceFactory::Factory> HostDataSourceFactory::map_;
47 const string& dbaccess) {
53 DatabaseConnection::ParameterMap::iterator it = parameters.find(
"type");
54 if (it == parameters.end()) {
56 "contain the 'type' keyword");
59 string db_type = it->second;
60 auto index = map_.find(db_type);
63 if (index == map_.end()) {
65 db_type <<
"' is not currently supported");
69 sources.push_back(boost::shared_ptr<BaseHostDataSource>(index->second(parameters)));
72 if (!sources.back()) {
75 " factory returned NULL");
81 const string& db_type) {
82 for (
auto it = sources.begin(); it != sources.end(); ++it) {
83 if ((*it)->getType() != db_type) {
95 HostDataSourceFactory::registerFactory(
const string& db_type,
98 if (map_.count(db_type)) {
101 map_.insert(pair<string, Factory>(db_type, factory));
115 HostDataSourceFactory::deregisterFactory(
const string& db_type,
bool no_log) {
116 auto index = map_.find(db_type);
117 if (index != map_.end()) {
121 HOSTS_BACKEND_DEREGISTER)
131 HostDataSourceFactory::registeredFactory(
const std::string& db_type) {
132 auto index = map_.find(db_type);
133 return (index != map_.end());
137 HostDataSourceFactory::printRegistered() {
138 std::stringstream txt;
140 for (
auto x : map_) {
141 txt << x.first <<
" ";
159 struct MySqlHostDataSourceInit {
161 MySqlHostDataSourceInit() {
162 HostDataSourceFactory::registerFactory(
"mysql", factory,
true);
166 ~MySqlHostDataSourceInit() {
167 HostDataSourceFactory::deregisterFactory(
"mysql",
true);
180 MySqlHostDataSourceInit mysql_init_;
184 struct PgSqlHostDataSourceInit {
186 PgSqlHostDataSourceInit() {
187 HostDataSourceFactory::registerFactory(
"postgresql", factory,
true);
191 ~PgSqlHostDataSourceInit() {
192 HostDataSourceFactory::deregisterFactory(
"postgresql",
true);
205 PgSqlHostDataSourceInit pgsql_init_;
209 struct CqlHostDataSourceInit {
211 CqlHostDataSourceInit() {
212 HostDataSourceFactory::registerFactory(
"cql", factory,
true);
216 ~CqlHostDataSourceInit() {
217 HostDataSourceFactory::deregisterFactory(
"cql",
true);
230 CqlHostDataSourceInit cql_init_;