~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-08 17:32:00 UTC
  • mto: This revision was merged to the branch mainline in revision 1833.
  • Revision ID: mordred@inaugust.com-20101008173200-iq22jo2nic48noa3
Updated pandora-build files to version 0.157

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::Schema &schema_proto;
68
69
 
69
70
public:
70
71
  StorageEngineGetSchemaDefinition(const SchemaIdentifier &identifier_arg,
71
 
                                   message::schema::shared_ptr &schema_proto_arg) :
 
72
                                   message::Schema &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::Schema &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::Schema &proto)
92
93
{
 
94
  proto.Clear();
 
95
 
93
96
  EngineVector::iterator iter=
94
 
    std::find_if(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
95
 
                 StorageEngineGetSchemaDefinition(identifier, proto));
 
97
    find_if(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
 
98
            StorageEngineGetSchemaDefinition(identifier, proto));
96
99
 
97
100
  if (iter != StorageEngine::getSchemaEngines().end())
98
101
  {
104
107
 
105
108
bool StorageEngine::doesSchemaExist(const SchemaIdentifier &identifier)
106
109
{
107
 
  message::schema::shared_ptr proto;
 
110
  message::Schema proto;
108
111
 
109
112
  return StorageEngine::getSchemaDefinition(identifier, proto);
110
113
}
112
115
 
113
116
const CHARSET_INFO *StorageEngine::getSchemaCollation(const SchemaIdentifier &identifier)
114
117
{
115
 
  message::schema::shared_ptr schmema_proto;
 
118
  message::Schema schmema_proto;
116
119
  bool found;
117
120
 
118
121
  found= StorageEngine::getSchemaDefinition(identifier, schmema_proto);
119
122
 
120
 
  if (found && schmema_proto->has_collation())
 
123
  if (found && schmema_proto.has_collation())
121
124
  {
122
 
    const std::string buffer= schmema_proto->collation();
 
125
    const string buffer= schmema_proto.collation();
123
126
    const CHARSET_INFO* cs= get_charset_by_name(buffer.c_str());
124
127
 
125
128
    if (not cs)
126
129
    {
127
 
      std::string path;
128
 
      identifier.getSQLPath(path);
129
 
 
130
130
      errmsg_printf(ERRMSG_LVL_ERROR,
131
 
                    _("Error while loading database options: '%s':"), path.c_str());
 
131
                    _("Error while loading database options: '%s':"), const_cast<SchemaIdentifier &>(identifier).getSQLPath().c_str());
132
132
      errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_UNKNOWN_COLLATION), buffer.c_str());
133
133
 
134
134
      return default_charset_info;
141
141
}
142
142
 
143
143
class CreateSchema : 
144
 
  public std::unary_function<StorageEngine *, void>
 
144
  public unary_function<StorageEngine *, void>
145
145
{
146
146
  const drizzled::message::Schema &schema_message;
147
147
 
155
155
  result_type operator() (argument_type engine)
156
156
  {
157
157
    // @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
 
    }
 
158
    (void)engine->doCreateSchema(schema_message);
165
159
  }
166
160
};
167
161
 
168
162
bool StorageEngine::createSchema(const drizzled::message::Schema &schema_message)
169
163
{
170
164
  // Add hook here for engines to register schema.
171
 
  std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
172
 
                CreateSchema(schema_message));
 
165
  for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
 
166
           CreateSchema(schema_message));
173
167
 
174
168
  return true;
175
169
}
176
170
 
177
171
class DropSchema : 
178
 
  public std::unary_function<StorageEngine *, void>
 
172
  public unary_function<StorageEngine *, void>
179
173
{
180
174
  uint64_t &success_count;
181
175
  const SchemaIdentifier &identifier;
194
188
    bool success= engine->doDropSchema(identifier);
195
189
 
196
190
    if (success)
197
 
    {
198
191
      success_count++;
199
 
      TransactionServices &transaction_services= TransactionServices::singleton();
200
 
      transaction_services.allocateNewTransactionId();
201
 
    }
202
192
  }
203
193
};
204
194
 
206
196
{
207
197
  uint64_t counter= 0;
208
198
  // Add hook here for engines to register schema.
209
 
  std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
210
 
                DropSchema(identifier, counter));
 
199
  for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
 
200
           DropSchema(identifier, counter));
211
201
 
212
202
  return counter ? true : false;
213
203
}
214
204
 
215
205
class AlterSchema : 
216
 
  public std::unary_function<StorageEngine *, void>
 
206
  public unary_function<StorageEngine *, void>
217
207
{
218
208
  uint64_t &success_count;
219
209
  const drizzled::message::Schema &schema_message;
233
223
 
234
224
 
235
225
    if (success)
236
 
    {
237
226
      success_count++;
238
 
      TransactionServices &transaction_services= TransactionServices::singleton();
239
 
      transaction_services.allocateNewTransactionId();
240
 
    }
241
227
  }
242
228
};
243
229
 
245
231
{
246
232
  uint64_t success_count= 0;
247
233
 
248
 
  std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
249
 
                AlterSchema(schema_message, success_count));
 
234
  for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
 
235
           AlterSchema(schema_message, success_count));
250
236
 
251
237
  return success_count ? true : false;
252
238
}