Drizzled Public API Documentation

function.cc
00001 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2010 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 #include <config.h>
00022 
00023 #include <plugin/function_engine/function.h>
00024 #include <plugin/function_engine/cursor.h>
00025 
00026 #include <string>
00027 
00028 using namespace std;
00029 using namespace drizzled;
00030 
00031 Function::Function(const std::string &name_arg) :
00032   drizzled::plugin::StorageEngine(name_arg,
00033                                   HTON_ALTER_NOT_SUPPORTED |
00034                                   HTON_HAS_SCHEMA_DICTIONARY |
00035                                   HTON_SKIP_STORE_LOCK |
00036                                   HTON_TEMPORARY_NOT_SUPPORTED),
00037   information_message(new(message::Schema)),
00038   data_dictionary_message(new(message::Schema))
00039 
00040 {
00041   information_message->set_name(INFORMATION_SCHEMA_IDENTIFIER.getSchemaName());
00042   information_message->set_collation("utf8_general_ci");
00043   message::set_is_replicated(*information_message, false);
00044 
00045   data_dictionary_message->set_name(DATA_DICTIONARY_IDENTIFIER.getSchemaName());
00046   data_dictionary_message->set_collation("utf8_general_ci");
00047   message::set_is_replicated(*data_dictionary_message, false);
00048 }
00049 
00050 
00051 Cursor *Function::create(Table &table)
00052 {
00053   return new FunctionCursor(*this, table);
00054 }
00055 
00056 int Function::doGetTableDefinition(Session &,
00057                                    const identifier::Table &identifier,
00058                                    message::Table &table_proto)
00059 {
00060   drizzled::plugin::TableFunction *function= getFunction(identifier.getPath());
00061 
00062   if (not function)
00063   {
00064     return ENOENT;
00065   }
00066 
00067   function->define(table_proto);
00068 
00069   return EEXIST;
00070 }
00071 
00072 void Function::doGetSchemaIdentifiers(identifier::Schema::vector& schemas)
00073 {
00074   schemas.push_back(INFORMATION_SCHEMA_IDENTIFIER);
00075   schemas.push_back(DATA_DICTIONARY_IDENTIFIER);
00076 }
00077 
00078 drizzled::message::schema::shared_ptr Function::doGetSchemaDefinition(const identifier::Schema &schema_identifier)
00079 {
00080   drizzled::message::schema::shared_ptr schema_message;
00081 
00082   if (schema_identifier == INFORMATION_SCHEMA_IDENTIFIER)
00083   {
00084     schema_message= information_message;
00085   }
00086   else if (schema_identifier == DATA_DICTIONARY_IDENTIFIER)
00087   {
00088     schema_message= data_dictionary_message;
00089   }
00090   else
00091   {
00092     return drizzled::message::schema::shared_ptr();
00093   }
00094 
00095   return schema_message;
00096 }
00097 
00098 bool Function::doCanCreateTable(const drizzled::identifier::Table &table_identifier)
00099 {
00100   if (static_cast<const identifier::Schema&>(table_identifier) == INFORMATION_SCHEMA_IDENTIFIER)
00101   {
00102     return false;
00103   }
00104 
00105   else if (static_cast<const identifier::Schema&>(table_identifier) == DATA_DICTIONARY_IDENTIFIER)
00106   {
00107     return false;
00108   }
00109 
00110   return true;
00111 }
00112 
00113 bool Function::doDoesTableExist(Session&, const identifier::Table &identifier)
00114 {
00115   drizzled::plugin::TableFunction *function= getFunction(identifier.getPath());
00116 
00117   if (function)
00118     return true;
00119 
00120   return false;
00121 }
00122 
00123 
00124 void Function::doGetTableIdentifiers(drizzled::CachedDirectory&,
00125                                      const drizzled::identifier::Schema &schema_identifier,
00126                                      drizzled::identifier::Table::vector &set_of_identifiers)
00127 {
00128   set<std::string> set_of_names;
00129   drizzled::plugin::TableFunction::getNames(schema_identifier.getSchemaName(), set_of_names);
00130 
00131   for (set<std::string>::iterator iter= set_of_names.begin(); iter != set_of_names.end(); iter++)
00132   {
00133     set_of_identifiers.push_back(identifier::Table(schema_identifier, *iter, drizzled::message::Table::FUNCTION));
00134   }
00135 }
00136 
00137 static int init(drizzled::module::Context &context)
00138 {
00139   context.add(new Function("FunctionEngine"));
00140 
00141   return 0;
00142 }
00143 
00144 DRIZZLE_DECLARE_PLUGIN
00145 {
00146   DRIZZLE_VERSION_ID,
00147   "FunctionEngine",
00148   "1.0",
00149   "Brian Aker",
00150   "Function Engine provides the infrastructure for Table Functions,etc.",
00151   PLUGIN_LICENSE_GPL,
00152   init,     /* Plugin Init */
00153   NULL,               /* depends */
00154   NULL                /* config options   */
00155 }
00156 DRIZZLE_DECLARE_PLUGIN_END;