~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/schema_engine.cc

  • Committer: tdavies
  • Date: 2010-10-31 07:38:13 UTC
  • mto: (1897.2.4 merge)
  • mto: This revision was merged to the branch mainline in revision 1899.
  • Revision ID: tdavies@molly-20101031073813-mmu12nqc0bwezxny
struct order_st changed and renamed to c++ class named:Order

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2010 Brian Aker
 
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; version 2 of the License.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
 
19
 
 
20
#include "config.h"
 
21
 
 
22
#include "drizzled/session.h"
 
23
 
 
24
#include "drizzled/global_charset_info.h"
 
25
#include "drizzled/charset.h"
 
26
 
 
27
#include "drizzled/plugin/storage_engine.h"
 
28
#include "drizzled/plugin/authorization.h"
 
29
 
 
30
using namespace std;
 
31
 
 
32
namespace drizzled
 
33
{
 
34
 
 
35
namespace plugin
 
36
{
 
37
 
 
38
class AddSchemaNames : 
 
39
  public unary_function<StorageEngine *, void>
 
40
{
 
41
  SchemaIdentifiers &schemas;
 
42
 
 
43
public:
 
44
 
 
45
  AddSchemaNames(SchemaIdentifiers &of_names) :
 
46
    schemas(of_names)
 
47
  {
 
48
  }
 
49
 
 
50
  result_type operator() (argument_type engine)
 
51
  {
 
52
    engine->doGetSchemaIdentifiers(schemas);
 
53
  }
 
54
};
 
55
 
 
56
void StorageEngine::getIdentifiers(Session &session, SchemaIdentifiers &schemas)
 
57
{
 
58
  // Add hook here for engines to register schema.
 
59
  for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
 
60
           AddSchemaNames(schemas));
 
61
 
 
62
  plugin::Authorization::pruneSchemaNames(session.getSecurityContext(), schemas);
 
63
}
 
64
 
 
65
class StorageEngineGetSchemaDefinition: public unary_function<StorageEngine *, bool>
 
66
{
 
67
  const SchemaIdentifier &identifier;
 
68
  message::SchemaPtr &schema_proto;
 
69
 
 
70
public:
 
71
  StorageEngineGetSchemaDefinition(const SchemaIdentifier &identifier_arg,
 
72
                                   message::SchemaPtr &schema_proto_arg) :
 
73
    identifier(identifier_arg),
 
74
    schema_proto(schema_proto_arg) 
 
75
  {
 
76
  }
 
77
 
 
78
  result_type operator() (argument_type engine)
 
79
  {
 
80
    return engine->doGetSchemaDefinition(identifier, schema_proto);
 
81
  }
 
82
};
 
83
 
 
84
/*
 
85
  Return value is "if parsed"
 
86
*/
 
87
bool StorageEngine::getSchemaDefinition(const drizzled::TableIdentifier &identifier, message::SchemaPtr &proto)
 
88
{
 
89
  return StorageEngine::getSchemaDefinition(identifier, proto);
 
90
}
 
91
 
 
92
bool StorageEngine::getSchemaDefinition(const SchemaIdentifier &identifier, message::SchemaPtr &proto)
 
93
{
 
94
  EngineVector::iterator iter=
 
95
    find_if(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
 
96
            StorageEngineGetSchemaDefinition(identifier, proto));
 
97
 
 
98
  if (iter != StorageEngine::getSchemaEngines().end())
 
99
  {
 
100
    return true;
 
101
  }
 
102
 
 
103
  return false;
 
104
}
 
105
 
 
106
bool StorageEngine::doesSchemaExist(const SchemaIdentifier &identifier)
 
107
{
 
108
  message::SchemaPtr proto;
 
109
 
 
110
  return StorageEngine::getSchemaDefinition(identifier, proto);
 
111
}
 
112
 
 
113
 
 
114
const CHARSET_INFO *StorageEngine::getSchemaCollation(const SchemaIdentifier &identifier)
 
115
{
 
116
  message::SchemaPtr schmema_proto;
 
117
  bool found;
 
118
 
 
119
  found= StorageEngine::getSchemaDefinition(identifier, schmema_proto);
 
120
 
 
121
  if (found && schmema_proto->has_collation())
 
122
  {
 
123
    const string buffer= schmema_proto->collation();
 
124
    const CHARSET_INFO* cs= get_charset_by_name(buffer.c_str());
 
125
 
 
126
    if (not cs)
 
127
    {
 
128
      errmsg_printf(ERRMSG_LVL_ERROR,
 
129
                    _("Error while loading database options: '%s':"), const_cast<SchemaIdentifier &>(identifier).getSQLPath().c_str());
 
130
      errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_UNKNOWN_COLLATION), buffer.c_str());
 
131
 
 
132
      return default_charset_info;
 
133
    }
 
134
 
 
135
    return cs;
 
136
  }
 
137
 
 
138
  return default_charset_info;
 
139
}
 
140
 
 
141
class CreateSchema : 
 
142
  public unary_function<StorageEngine *, void>
 
143
{
 
144
  const drizzled::message::Schema &schema_message;
 
145
 
 
146
public:
 
147
 
 
148
  CreateSchema(const drizzled::message::Schema &arg) :
 
149
    schema_message(arg)
 
150
  {
 
151
  }
 
152
 
 
153
  result_type operator() (argument_type engine)
 
154
  {
 
155
    // @todo eomeday check that at least one engine said "true"
 
156
    (void)engine->doCreateSchema(schema_message);
 
157
  }
 
158
};
 
159
 
 
160
bool StorageEngine::createSchema(const drizzled::message::Schema &schema_message)
 
161
{
 
162
  // Add hook here for engines to register schema.
 
163
  for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
 
164
           CreateSchema(schema_message));
 
165
 
 
166
  return true;
 
167
}
 
168
 
 
169
class DropSchema : 
 
170
  public unary_function<StorageEngine *, void>
 
171
{
 
172
  uint64_t &success_count;
 
173
  const SchemaIdentifier &identifier;
 
174
 
 
175
public:
 
176
 
 
177
  DropSchema(const SchemaIdentifier &arg, uint64_t &count_arg) :
 
178
    success_count(count_arg),
 
179
    identifier(arg)
 
180
  {
 
181
  }
 
182
 
 
183
  result_type operator() (argument_type engine)
 
184
  {
 
185
    // @todo someday check that at least one engine said "true"
 
186
    bool success= engine->doDropSchema(identifier);
 
187
 
 
188
    if (success)
 
189
      success_count++;
 
190
  }
 
191
};
 
192
 
 
193
bool StorageEngine::dropSchema(const SchemaIdentifier &identifier)
 
194
{
 
195
  uint64_t counter= 0;
 
196
  // Add hook here for engines to register schema.
 
197
  for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
 
198
           DropSchema(identifier, counter));
 
199
 
 
200
  return counter ? true : false;
 
201
}
 
202
 
 
203
class AlterSchema : 
 
204
  public unary_function<StorageEngine *, void>
 
205
{
 
206
  uint64_t &success_count;
 
207
  const drizzled::message::Schema &schema_message;
 
208
 
 
209
public:
 
210
 
 
211
  AlterSchema(const drizzled::message::Schema &arg, uint64_t &count_arg) :
 
212
    success_count(count_arg),
 
213
    schema_message(arg)
 
214
  {
 
215
  }
 
216
 
 
217
  result_type operator() (argument_type engine)
 
218
  {
 
219
    // @todo eomeday check that at least one engine said "true"
 
220
    bool success= engine->doAlterSchema(schema_message);
 
221
 
 
222
 
 
223
    if (success)
 
224
      success_count++;
 
225
  }
 
226
};
 
227
 
 
228
bool StorageEngine::alterSchema(const drizzled::message::Schema &schema_message)
 
229
{
 
230
  uint64_t success_count= 0;
 
231
 
 
232
  for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
 
233
           AlterSchema(schema_message, success_count));
 
234
 
 
235
  return success_count ? true : false;
 
236
}
 
237
 
 
238
} /* namespace plugin */
 
239
} /* namespace drizzled */