Drizzled Public API Documentation

function.cc
1 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3  *
4  * Copyright (C) 2010 Sun Microsystems, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <config.h>
22 #include <boost/foreach.hpp>
23 #include <plugin/function_engine/function.h>
24 #include <plugin/function_engine/cursor.h>
25 #include <string>
26 
27 using namespace std;
28 using namespace drizzled;
29 
30 Function::Function(const std::string &name_arg) :
31  drizzled::plugin::StorageEngine(name_arg,
32  HTON_ALTER_NOT_SUPPORTED |
33  HTON_HAS_SCHEMA_DICTIONARY |
34  HTON_SKIP_STORE_LOCK |
35  HTON_TEMPORARY_NOT_SUPPORTED),
36  information_message(new message::Schema),
37  data_dictionary_message(new message::Schema)
38 
39 {
40  information_message->set_name(INFORMATION_SCHEMA_IDENTIFIER.getSchemaName());
41  information_message->set_collation("utf8_general_ci");
42  message::set_is_replicated(*information_message, false);
43 
44  data_dictionary_message->set_name(DATA_DICTIONARY_IDENTIFIER.getSchemaName());
45  data_dictionary_message->set_collation("utf8_general_ci");
46  message::set_is_replicated(*data_dictionary_message, false);
47 }
48 
49 
50 Cursor *Function::create(Table &table)
51 {
52  return new FunctionCursor(*this, table);
53 }
54 
55 int Function::doGetTableDefinition(Session &,
56  const identifier::Table &identifier,
57  message::Table &table_proto)
58 {
59  drizzled::plugin::TableFunction *function= getFunction(identifier.getPath());
60 
61  if (not function)
62  {
63  return ENOENT;
64  }
65 
66  function->define(table_proto);
67 
68  return EEXIST;
69 }
70 
71 void Function::doGetSchemaIdentifiers(identifier::schema::vector& schemas)
72 {
73  schemas.push_back(INFORMATION_SCHEMA_IDENTIFIER);
74  schemas.push_back(DATA_DICTIONARY_IDENTIFIER);
75 }
76 
77 drizzled::message::schema::shared_ptr Function::doGetSchemaDefinition(const identifier::Schema &schema_identifier)
78 {
79  drizzled::message::schema::shared_ptr schema_message;
80 
81  if (schema_identifier == INFORMATION_SCHEMA_IDENTIFIER)
82  {
83  schema_message= information_message;
84  }
85  else if (schema_identifier == DATA_DICTIONARY_IDENTIFIER)
86  {
87  schema_message= data_dictionary_message;
88  }
89  else
90  {
91  return drizzled::message::schema::shared_ptr();
92  }
93 
94  return schema_message;
95 }
96 
97 bool Function::doCanCreateTable(const drizzled::identifier::Table &table_identifier)
98 {
99  if (static_cast<const identifier::Schema&>(table_identifier) == INFORMATION_SCHEMA_IDENTIFIER)
100  {
101  return false;
102  }
103 
104  else if (static_cast<const identifier::Schema&>(table_identifier) == DATA_DICTIONARY_IDENTIFIER)
105  {
106  return false;
107  }
108 
109  return true;
110 }
111 
112 bool Function::doDoesTableExist(Session&, const identifier::Table &identifier)
113 {
114  return getFunction(identifier.getPath());
115 }
116 
117 
118 void Function::doGetTableIdentifiers(drizzled::CachedDirectory&,
119  const drizzled::identifier::Schema &schema_identifier,
120  drizzled::identifier::table::vector &set_of_identifiers)
121 {
122  set<std::string> set_of_names;
123  drizzled::plugin::TableFunction::getNames(schema_identifier.getSchemaName(), set_of_names);
124 
125  BOOST_FOREACH(const std::string& iter, set_of_names)
126  {
127  set_of_identifiers.push_back(identifier::Table(schema_identifier, iter, drizzled::message::Table::FUNCTION));
128  }
129 }
130 
131 static int init(drizzled::module::Context &context)
132 {
133  context.add(new Function("FunctionEngine"));
134 
135  return 0;
136 }
137 
138 DRIZZLE_DECLARE_PLUGIN
139 {
140  DRIZZLE_VERSION_ID,
141  "function_engine",
142  "1.0",
143  "Brian Aker",
144  N_("Function engine"),
145  PLUGIN_LICENSE_GPL,
146  init,
147  NULL,
148  NULL
149 }
150 DRIZZLE_DECLARE_PLUGIN_END;