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 #include <boost/foreach.hpp>
00023 #include <plugin/function_engine/function.h>
00024 #include <plugin/function_engine/cursor.h>
00025 #include <string>
00026 
00027 using namespace std;
00028 using namespace drizzled;
00029 
00030 Function::Function(const std::string &name_arg) :
00031   drizzled::plugin::StorageEngine(name_arg,
00032                                   HTON_ALTER_NOT_SUPPORTED |
00033                                   HTON_HAS_SCHEMA_DICTIONARY |
00034                                   HTON_SKIP_STORE_LOCK |
00035                                   HTON_TEMPORARY_NOT_SUPPORTED),
00036   information_message(new message::Schema),
00037   data_dictionary_message(new message::Schema)
00038 
00039 {
00040   information_message->set_name(INFORMATION_SCHEMA_IDENTIFIER.getSchemaName());
00041   information_message->set_collation("utf8_general_ci");
00042   message::set_is_replicated(*information_message, false);
00043 
00044   data_dictionary_message->set_name(DATA_DICTIONARY_IDENTIFIER.getSchemaName());
00045   data_dictionary_message->set_collation("utf8_general_ci");
00046   message::set_is_replicated(*data_dictionary_message, false);
00047 }
00048 
00049 
00050 Cursor *Function::create(Table &table)
00051 {
00052   return new FunctionCursor(*this, table);
00053 }
00054 
00055 int Function::doGetTableDefinition(Session &,
00056                                    const identifier::Table &identifier,
00057                                    message::Table &table_proto)
00058 {
00059   drizzled::plugin::TableFunction *function= getFunction(identifier.getPath());
00060 
00061   if (not function)
00062   {
00063     return ENOENT;
00064   }
00065 
00066   function->define(table_proto);
00067 
00068   return EEXIST;
00069 }
00070 
00071 void Function::doGetSchemaIdentifiers(identifier::schema::vector& schemas)
00072 {
00073   schemas.push_back(INFORMATION_SCHEMA_IDENTIFIER);
00074   schemas.push_back(DATA_DICTIONARY_IDENTIFIER);
00075 }
00076 
00077 drizzled::message::schema::shared_ptr Function::doGetSchemaDefinition(const identifier::Schema &schema_identifier)
00078 {
00079   drizzled::message::schema::shared_ptr schema_message;
00080 
00081   if (schema_identifier == INFORMATION_SCHEMA_IDENTIFIER)
00082   {
00083     schema_message= information_message;
00084   }
00085   else if (schema_identifier == DATA_DICTIONARY_IDENTIFIER)
00086   {
00087     schema_message= data_dictionary_message;
00088   }
00089   else
00090   {
00091     return drizzled::message::schema::shared_ptr();
00092   }
00093 
00094   return schema_message;
00095 }
00096 
00097 bool Function::doCanCreateTable(const drizzled::identifier::Table &table_identifier)
00098 {
00099   if (static_cast<const identifier::Schema&>(table_identifier) == INFORMATION_SCHEMA_IDENTIFIER)
00100   {
00101     return false;
00102   }
00103 
00104   else if (static_cast<const identifier::Schema&>(table_identifier) == DATA_DICTIONARY_IDENTIFIER)
00105   {
00106     return false;
00107   }
00108 
00109   return true;
00110 }
00111 
00112 bool Function::doDoesTableExist(Session&, const identifier::Table &identifier)
00113 {
00114   return getFunction(identifier.getPath());
00115 }
00116 
00117 
00118 void Function::doGetTableIdentifiers(drizzled::CachedDirectory&,
00119                                      const drizzled::identifier::Schema &schema_identifier,
00120                                      drizzled::identifier::table::vector &set_of_identifiers)
00121 {
00122   set<std::string> set_of_names;
00123   drizzled::plugin::TableFunction::getNames(schema_identifier.getSchemaName(), set_of_names);
00124 
00125   BOOST_FOREACH(const std::string& iter, set_of_names)
00126   {
00127     set_of_identifiers.push_back(identifier::Table(schema_identifier, iter, drizzled::message::Table::FUNCTION));
00128   }
00129 }
00130 
00131 static int init(drizzled::module::Context &context)
00132 {
00133   context.add(new Function("FunctionEngine"));
00134 
00135   return 0;
00136 }
00137 
00138 DRIZZLE_DECLARE_PLUGIN
00139 {
00140   DRIZZLE_VERSION_ID,
00141   "FunctionEngine",
00142   "1.0",
00143   "Brian Aker",
00144   "Function Engine provides the infrastructure for Table Functions,etc.",
00145   PLUGIN_LICENSE_GPL,
00146   init,     /* Plugin Init */
00147   NULL,               /* depends */
00148   NULL                /* config options   */
00149 }
00150 DRIZZLE_DECLARE_PLUGIN_END;