23 #include <drizzled/plugin/catalog.h>
24 #include <drizzled/catalog/cache.h>
25 #include <drizzled/catalog/local.h>
26 #include <drizzled/error.h>
28 #include <boost/foreach.hpp>
38 catalog::Engine::vector _catalogs;
47 catalog::Engine::vector &catalogs()
55 message::catalog::shared_ptr message= message::catalog::make_shared(identifier);
56 return create(identifier, message);
59 bool Catalog::create(
const identifier::Catalog& identifier, message::catalog::shared_ptr &message)
65 if (not lock.locked())
67 my_error(ER_CATALOG_NO_LOCK, MYF(0), identifier.getName().c_str());
71 size_t create_count= 0;
72 BOOST_FOREACH(catalog::Engine::vector::const_reference ref, Engines::singleton().catalogs())
74 if (ref->create(identifier, message))
77 assert(create_count < 2);
81 my_error(ER_CATALOG_CANNOT_CREATE, MYF(0), identifier.getName().c_str());
88 bool Catalog::drop(
const identifier::Catalog& identifier)
90 if (identifier == drizzled::catalog::local_identifier())
92 my_error(drizzled::ER_CATALOG_NO_DROP_LOCAL, MYF(0));
96 catalog::lock::Erase lock(identifier);
97 if (not lock.locked())
99 my_error(ER_CATALOG_NO_LOCK, MYF(0), identifier.getName().c_str());
104 size_t drop_count= 0;
105 BOOST_FOREACH(catalog::Engine::vector::const_reference ref, Engines::singleton().catalogs())
107 if (ref->drop(identifier))
112 assert(drop_count < 2);
116 my_error(ER_CATALOG_DOES_NOT_EXIST, MYF(0), identifier.getName().c_str());
123 bool Catalog::lock(
const identifier::Catalog& identifier)
125 drizzled::error_t error;
128 if (not catalog::Cache::lock(identifier, error))
130 my_error(error, identifier);
139 bool Catalog::unlock(
const identifier::Catalog& identifier)
141 drizzled::error_t error;
142 if (not catalog::Cache::unlock(identifier, error))
144 my_error(error, identifier);
150 bool plugin::Catalog::addPlugin(plugin::Catalog *arg)
152 Engines::singleton().catalogs().push_back(arg->engine());
157 bool plugin::Catalog::exist(
const identifier::Catalog& identifier)
159 if (catalog::Cache::exist(identifier))
164 BOOST_FOREACH(catalog::Engine::vector::const_reference ref, Engines::singleton().catalogs())
166 if (ref->exist(identifier))
175 void plugin::Catalog::getIdentifiers(identifier::catalog::vector &identifiers)
177 BOOST_FOREACH(catalog::Engine::vector::const_reference ref, Engines::singleton().catalogs())
179 ref->getIdentifiers(identifiers);
183 void plugin::Catalog::getMessages(message::catalog::vector &messages)
185 BOOST_FOREACH(catalog::Engine::vector::const_reference ref, Engines::singleton().catalogs())
187 ref->getMessages(messages);
191 message::catalog::shared_ptr plugin::Catalog::getMessage(
const identifier::Catalog& identifier)
193 drizzled::error_t error;
194 catalog::Instance::shared_ptr instance= catalog::Cache::find(identifier, error);
195 message::catalog::shared_ptr message;
197 if (instance and instance->message())
199 return instance->message();
202 BOOST_FOREACH(catalog::Engine::vector::const_reference ref, Engines::singleton().catalogs())
204 if ((message= ref->getMessage(identifier)))
213 catalog::Instance::shared_ptr plugin::Catalog::getInstance(
const identifier::Catalog& identifier)
215 drizzled::error_t error;
216 catalog::Instance::shared_ptr instance= catalog::Cache::find(identifier, error);
223 BOOST_FOREACH(catalog::Engine::vector::const_reference ref, Engines::singleton().catalogs())
225 message::catalog::shared_ptr message;
226 if (message= ref->getMessage(identifier))
228 instance= catalog::Instance::make_shared(message);
231 catalog::Cache::insert(identifier, instance, error);
237 return catalog::Instance::shared_ptr();
241 void plugin::Catalog::removePlugin(plugin::Catalog *)