23#include <drizzled/plugin/catalog.h>
24#include <drizzled/catalog/cache.h>
25#include <drizzled/catalog/local.h>
26#include <drizzled/error.h>
36 catalog::Engine::vector _catalogs;
45 catalog::Engine::vector &catalogs()
53 message::catalog::shared_ptr message= message::catalog::make_shared(identifier);
54 return create(identifier, message);
57bool Catalog::create(
const identifier::Catalog& identifier, message::catalog::shared_ptr &message)
63 if (not lock.locked())
65 my_error(ER_CATALOG_NO_LOCK, MYF(0), identifier.getName().c_str());
69 size_t create_count= 0;
70 for (catalog::Engine::vector::const_reference ref : Engines::singleton().catalogs())
72 if (ref->create(identifier, message))
75 assert(create_count < 2);
79 my_error(ER_CATALOG_CANNOT_CREATE, MYF(0), identifier.getName().c_str());
86bool Catalog::drop(
const identifier::Catalog& identifier)
88 if (identifier == drizzled::catalog::local_identifier())
90 my_error(drizzled::ER_CATALOG_NO_DROP_LOCAL, MYF(0));
94 catalog::lock::Erase lock(identifier);
95 if (not lock.locked())
97 my_error(ER_CATALOG_NO_LOCK, MYF(0), identifier.getName().c_str());
102 size_t drop_count= 0;
103 for (catalog::Engine::vector::const_reference ref : Engines::singleton().catalogs())
105 if (ref->drop(identifier))
110 assert(drop_count < 2);
114 my_error(ER_CATALOG_DOES_NOT_EXIST, MYF(0), identifier.getName().c_str());
121bool Catalog::lock(
const identifier::Catalog& identifier)
123 drizzled::error_t error;
126 if (not catalog::Cache::lock(identifier, error))
128 my_error(error, identifier);
137bool Catalog::unlock(
const identifier::Catalog& identifier)
139 drizzled::error_t error;
140 if (not catalog::Cache::unlock(identifier, error))
142 my_error(error, identifier);
148bool plugin::Catalog::addPlugin(plugin::Catalog &arg)
150 Engines::singleton().catalogs().push_back(arg.engine());
155bool plugin::Catalog::exist(
const identifier::Catalog& identifier)
157 if (catalog::Cache::exist(identifier))
162 for (catalog::Engine::vector::const_reference ref : Engines::singleton().catalogs())
164 if (ref->exist(identifier))
173void plugin::Catalog::getIdentifiers(identifier::catalog::vector &identifiers)
175 for (catalog::Engine::vector::const_reference ref : Engines::singleton().catalogs())
177 ref->getIdentifiers(identifiers);
181void plugin::Catalog::getMessages(message::catalog::vector &messages)
183 for (catalog::Engine::vector::const_reference ref : Engines::singleton().catalogs())
185 ref->getMessages(messages);
189message::catalog::shared_ptr plugin::Catalog::getMessage(
const identifier::Catalog& identifier)
191 drizzled::error_t error;
192 catalog::Instance::shared_ptr instance= catalog::Cache::find(identifier, error);
193 message::catalog::shared_ptr message;
195 if (instance and instance->message())
197 return instance->message();
200 for (catalog::Engine::vector::const_reference ref : Engines::singleton().catalogs())
202 if ((message= ref->getMessage(identifier)))
211catalog::Instance::shared_ptr plugin::Catalog::getInstance(
const identifier::Catalog& identifier)
213 drizzled::error_t error;
214 catalog::Instance::shared_ptr instance= catalog::Cache::find(identifier, error);
221 for (catalog::Engine::vector::const_reference ref : Engines::singleton().catalogs())
223 message::catalog::shared_ptr message;
224 if ((message= ref->getMessage(identifier)))
226 instance= catalog::Instance::make_shared(message);
229 catalog::Cache::insert(identifier, instance, error);
235 return catalog::Instance::shared_ptr();
239void plugin::Catalog::removePlugin(plugin::Catalog &)
TODO: Rename this file - func.h is stupid.