~drizzle-trunk/drizzle/development

1273.13.1 by Brian Aker
First pass through data dictionary.
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2009 Sun Microsystems
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 <plugin/data_engine/dictionary.h>
22
#include <plugin/data_engine/cursor.h>
23
24
#include <string>
25
26
using namespace std;
27
using namespace drizzled;
28
29
static const string schema_name("data_dictionary");
30
static const string schema_name_prefix("./data_dictionary/");
31
32
Dictionary::Dictionary(const std::string &name_arg) :
33
  drizzled::plugin::StorageEngine(name_arg,
34
                                  HTON_ALTER_NOT_SUPPORTED |
35
                                  HTON_SKIP_STORE_LOCK |
36
                                  HTON_TEMPORARY_NOT_SUPPORTED)
37
{
1273.13.6 by Brian Aker
Updates for interface/etc.
38
39
  pair<ToolMap::iterator, bool> ret;
40
41
  ret= table_map.insert(make_pair(character_sets.getPath(), &character_sets));
42
  assert(ret.second == true);
43
44
  ret= table_map.insert(make_pair(collation_character_set_applicability.getPath(),
45
                                  &collation_character_set_applicability));
46
  assert(ret.second == true);
47
48
  ret= table_map.insert(make_pair(collations.getPath(),
49
                                  &collations));
50
  assert(ret.second == true);
51
52
  ret= table_map.insert(make_pair(columns.getPath(),
53
                                  &columns));
54
  assert(ret.second == true);
55
56
  ret= table_map.insert(make_pair(key_column_usage.getPath(),
57
                                  &key_column_usage));
58
  assert(ret.second == true);
59
60
  ret= table_map.insert(make_pair(modules.getPath(),
61
                                  &modules));
62
  assert(ret.second == true);
63
64
  ret= table_map.insert(make_pair(plugins.getPath(),
65
                                  &plugins));
66
  assert(ret.second == true);
67
68
  ret= table_map.insert(make_pair(processlist.getPath(),
69
                                  &processlist));
70
  assert(ret.second == true);
71
72
  ret= table_map.insert(make_pair(referential_constraints.getPath(),
73
                                  &referential_constraints));
74
  assert(ret.second == true);
75
1273.13.9 by Brian Aker
Updating test cases + added Drizzle specific schema_names and schema_info.
76
  ret= table_map.insert(make_pair(schemas.getPath(),
77
                                  &schemas));
78
  assert(ret.second == true);
79
80
  ret= table_map.insert(make_pair(schemas_full.getPath(),
81
                                  &schemas_full));
82
  assert(ret.second == true);
83
1273.13.6 by Brian Aker
Updates for interface/etc.
84
  ret= table_map.insert(make_pair(schemata.getPath(),
85
                                  &schemata));
86
  assert(ret.second == true);
87
88
  ret= table_map.insert(make_pair(statistics.getPath(),
89
                                  &statistics));
90
  assert(ret.second == true);
91
92
  ret= table_map.insert(make_pair(global_status.getPath(),
93
                                  &global_status));
94
  assert(ret.second == true);
95
96
#if 0
97
  ret= table_map.insert(make_pair(session_status.getPath(),
98
                                  &session_status));
99
  assert(ret.second == true);
100
#endif
101
102
  ret= table_map.insert(make_pair(tables.getPath(),
103
                                  &tables));
104
  assert(ret.second == true);
105
106
  ret= table_map.insert(make_pair(table_constraints.getPath(),
107
                                  &table_constraints));
108
  assert(ret.second == true);
109
110
  ret= table_map.insert(make_pair(global_variables.getPath(),
111
                                  &global_variables));
112
  assert(ret.second == true);
113
114
#if 0
115
  ret= table_map.insert(make_pair(session_variables.getPath(),
116
                                  &session_variables));
117
  assert(ret.second == true);
118
#endif
1273.13.1 by Brian Aker
First pass through data dictionary.
119
}
120
121
122
Cursor *Dictionary::create(TableShare &table, memory::Root *mem_root)
123
{
124
  return new (mem_root) DictionaryCursor(*this, table);
125
}
126
127
Tool *Dictionary::getTool(const char *path)
128
{
1273.13.6 by Brian Aker
Updates for interface/etc.
129
  ToolMap::iterator iter= table_map.find(path);
130
131
  if (iter == table_map.end())
132
  {
133
    fprintf(stderr, "\n %s\n", path);
134
    assert(path == NULL);
135
  }
136
  return (*iter).second;
137
1273.13.1 by Brian Aker
First pass through data dictionary.
138
}
139
140
141
int Dictionary::doGetTableDefinition(Session &,
142
                                     const char *path,
143
                                     const char *,
144
                                     const char *,
145
                                     const bool,
146
                                     message::Table *table_proto)
147
{
148
  string tab_name(path);
149
150
  if (tab_name.compare(0, schema_name_prefix.length(), schema_name_prefix) != 0)
151
  {
152
    return ENOENT;
153
  }
1273.13.6 by Brian Aker
Updates for interface/etc.
154
155
  ToolMap::iterator iter= table_map.find(path);
156
157
  if (iter == table_map.end())
158
  {
159
    fprintf(stderr, "\n doGetTableDefinition() %s\n", path);
1273.13.1 by Brian Aker
First pass through data dictionary.
160
    return ENOENT;
161
  }
162
1273.13.6 by Brian Aker
Updates for interface/etc.
163
  if (table_proto)
164
  {
165
    Tool *tool= (*iter).second;
166
167
    tool->define(*table_proto);
168
  }
169
1273.13.1 by Brian Aker
First pass through data dictionary.
170
  return EEXIST;
171
}
172
173
174
void Dictionary::doGetTableNames(drizzled::CachedDirectory&, 
175
                                        string &db, 
176
                                        set<string> &set_of_names)
177
{
178
  if (db.compare("data_dictionary"))
179
    return;
180
1273.13.6 by Brian Aker
Updates for interface/etc.
181
  for (ToolMap::iterator it= table_map.begin();
182
       it != table_map.end();
183
       it++)
184
  {
185
    Tool *tool= (*it).second;
186
    set_of_names.insert(tool->getName());
187
  }
1273.13.1 by Brian Aker
First pass through data dictionary.
188
}
189
190
191
static plugin::StorageEngine *dictionary_plugin= NULL;
192
193
static int init(plugin::Registry &registry)
194
{
195
  dictionary_plugin= new(std::nothrow) Dictionary(engine_name);
196
  if (! dictionary_plugin)
197
  {
198
    return 1;
199
  }
200
201
  registry.add(dictionary_plugin);
202
  
203
  return 0;
204
}
205
206
static int finalize(plugin::Registry &registry)
207
{
208
  registry.remove(dictionary_plugin);
209
  delete dictionary_plugin;
210
211
  return 0;
212
}
213
214
DRIZZLE_DECLARE_PLUGIN
215
{
216
  DRIZZLE_VERSION_ID,
217
  "DICTIONARY",
218
  "1.0",
219
  "Brian Aker",
220
  "Dictionary provides the information for data_dictionary.",
221
  PLUGIN_LICENSE_GPL,
222
  init,     /* Plugin Init */
223
  finalize,     /* Plugin Deinit */
224
  NULL,               /* status variables */
225
  NULL,               /* system variables */
226
  NULL                /* config options   */
227
}
228
DRIZZLE_DECLARE_PLUGIN_END;