~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/schema_engine.cc

  • Committer: Monty Taylor
  • Date: 2010-10-13 17:53:36 UTC
  • mto: This revision was merged to the branch mainline in revision 1845.
  • Revision ID: mordred@inaugust.com-20101013175336-amzhjftgztblvua5
Updated pandora-build files to version 0.161

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
#include "drizzled/global_charset_info.h"
25
25
#include "drizzled/charset.h"
26
 
#include "drizzled/transaction_services.h"
27
26
 
28
27
#include "drizzled/plugin/storage_engine.h"
29
28
#include "drizzled/plugin/authorization.h"
30
29
 
 
30
using namespace std;
 
31
 
31
32
namespace drizzled
32
33
{
33
34
 
35
36
{
36
37
 
37
38
class AddSchemaNames : 
38
 
  public std::unary_function<StorageEngine *, void>
 
39
  public unary_function<StorageEngine *, void>
39
40
{
40
 
  SchemaIdentifier::vector &schemas;
 
41
  SchemaIdentifiers &schemas;
41
42
 
42
43
public:
43
44
 
44
 
  AddSchemaNames(SchemaIdentifier::vector &of_names) :
 
45
  AddSchemaNames(SchemaIdentifiers &of_names) :
45
46
    schemas(of_names)
46
47
  {
47
48
  }
52
53
  }
53
54
};
54
55
 
55
 
void StorageEngine::getIdentifiers(Session &session, SchemaIdentifier::vector &schemas)
 
56
void StorageEngine::getIdentifiers(Session &session, SchemaIdentifiers &schemas)
56
57
{
57
58
  // Add hook here for engines to register schema.
58
 
  std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
 
59
  for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
59
60
           AddSchemaNames(schemas));
60
61
 
61
62
  plugin::Authorization::pruneSchemaNames(session.getSecurityContext(), schemas);
62
63
}
63
64
 
64
 
class StorageEngineGetSchemaDefinition: public std::unary_function<StorageEngine *, bool>
 
65
class StorageEngineGetSchemaDefinition: public unary_function<StorageEngine *, bool>
65
66
{
66
67
  const SchemaIdentifier &identifier;
67
 
  message::schema::shared_ptr &schema_proto;
 
68
  message::SchemaPtr &schema_proto;
68
69
 
69
70
public:
70
71
  StorageEngineGetSchemaDefinition(const SchemaIdentifier &identifier_arg,
71
 
                                   message::schema::shared_ptr &schema_proto_arg) :
 
72
                                   message::SchemaPtr &schema_proto_arg) :
72
73
    identifier(identifier_arg),
73
74
    schema_proto(schema_proto_arg) 
74
75
  {
83
84
/*
84
85
  Return value is "if parsed"
85
86
*/
86
 
bool StorageEngine::getSchemaDefinition(const drizzled::TableIdentifier &identifier, message::schema::shared_ptr &proto)
 
87
bool StorageEngine::getSchemaDefinition(const drizzled::TableIdentifier &identifier, message::SchemaPtr &proto)
87
88
{
88
89
  return StorageEngine::getSchemaDefinition(identifier, proto);
89
90
}
90
91
 
91
 
bool StorageEngine::getSchemaDefinition(const SchemaIdentifier &identifier, message::schema::shared_ptr &proto)
 
92
bool StorageEngine::getSchemaDefinition(const SchemaIdentifier &identifier, message::SchemaPtr &proto)
92
93
{
93
94
  EngineVector::iterator iter=
94
 
    std::find_if(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
95
 
                 StorageEngineGetSchemaDefinition(identifier, proto));
 
95
    find_if(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
 
96
            StorageEngineGetSchemaDefinition(identifier, proto));
96
97
 
97
98
  if (iter != StorageEngine::getSchemaEngines().end())
98
99
  {
104
105
 
105
106
bool StorageEngine::doesSchemaExist(const SchemaIdentifier &identifier)
106
107
{
107
 
  message::schema::shared_ptr proto;
 
108
  message::SchemaPtr proto;
108
109
 
109
110
  return StorageEngine::getSchemaDefinition(identifier, proto);
110
111
}
112
113
 
113
114
const CHARSET_INFO *StorageEngine::getSchemaCollation(const SchemaIdentifier &identifier)
114
115
{
115
 
  message::schema::shared_ptr schmema_proto;
 
116
  message::SchemaPtr schmema_proto;
116
117
  bool found;
117
118
 
118
119
  found= StorageEngine::getSchemaDefinition(identifier, schmema_proto);
119
120
 
120
121
  if (found && schmema_proto->has_collation())
121
122
  {
122
 
    const std::string buffer= schmema_proto->collation();
 
123
    const string buffer= schmema_proto->collation();
123
124
    const CHARSET_INFO* cs= get_charset_by_name(buffer.c_str());
124
125
 
125
126
    if (not cs)
126
127
    {
127
 
      std::string path;
128
 
      identifier.getSQLPath(path);
129
 
 
130
128
      errmsg_printf(ERRMSG_LVL_ERROR,
131
 
                    _("Error while loading database options: '%s':"), path.c_str());
 
129
                    _("Error while loading database options: '%s':"), const_cast<SchemaIdentifier &>(identifier).getSQLPath().c_str());
132
130
      errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_UNKNOWN_COLLATION), buffer.c_str());
133
131
 
134
132
      return default_charset_info;
141
139
}
142
140
 
143
141
class CreateSchema : 
144
 
  public std::unary_function<StorageEngine *, void>
 
142
  public unary_function<StorageEngine *, void>
145
143
{
146
144
  const drizzled::message::Schema &schema_message;
147
145
 
155
153
  result_type operator() (argument_type engine)
156
154
  {
157
155
    // @todo eomeday check that at least one engine said "true"
158
 
    bool success= engine->doCreateSchema(schema_message);
159
 
 
160
 
    if (success) 
161
 
    {
162
 
      TransactionServices &transaction_services= TransactionServices::singleton();
163
 
      transaction_services.allocateNewTransactionId();
164
 
    }
 
156
    (void)engine->doCreateSchema(schema_message);
165
157
  }
166
158
};
167
159
 
168
160
bool StorageEngine::createSchema(const drizzled::message::Schema &schema_message)
169
161
{
170
162
  // Add hook here for engines to register schema.
171
 
  std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
172
 
                CreateSchema(schema_message));
 
163
  for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
 
164
           CreateSchema(schema_message));
173
165
 
174
166
  return true;
175
167
}
176
168
 
177
169
class DropSchema : 
178
 
  public std::unary_function<StorageEngine *, void>
 
170
  public unary_function<StorageEngine *, void>
179
171
{
180
172
  uint64_t &success_count;
181
173
  const SchemaIdentifier &identifier;
194
186
    bool success= engine->doDropSchema(identifier);
195
187
 
196
188
    if (success)
197
 
    {
198
189
      success_count++;
199
 
      TransactionServices &transaction_services= TransactionServices::singleton();
200
 
      transaction_services.allocateNewTransactionId();
201
 
    }
202
190
  }
203
191
};
204
192
 
206
194
{
207
195
  uint64_t counter= 0;
208
196
  // Add hook here for engines to register schema.
209
 
  std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
210
 
                DropSchema(identifier, counter));
 
197
  for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
 
198
           DropSchema(identifier, counter));
211
199
 
212
200
  return counter ? true : false;
213
201
}
214
202
 
215
203
class AlterSchema : 
216
 
  public std::unary_function<StorageEngine *, void>
 
204
  public unary_function<StorageEngine *, void>
217
205
{
218
206
  uint64_t &success_count;
219
207
  const drizzled::message::Schema &schema_message;
233
221
 
234
222
 
235
223
    if (success)
236
 
    {
237
224
      success_count++;
238
 
      TransactionServices &transaction_services= TransactionServices::singleton();
239
 
      transaction_services.allocateNewTransactionId();
240
 
    }
241
225
  }
242
226
};
243
227
 
245
229
{
246
230
  uint64_t success_count= 0;
247
231
 
248
 
  std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
249
 
                AlterSchema(schema_message, success_count));
 
232
  for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
 
233
           AlterSchema(schema_message, success_count));
250
234
 
251
235
  return success_count ? true : false;
252
236
}