~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/schema_engine.cc

  • Committer: Olaf van der Spek
  • Date: 2011-04-05 12:26:58 UTC
  • mto: (2278.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 2272.
  • Revision ID: olafvdspek@gmail.com-20110405122658-xxrvmobwwwwf3oct
Refactor Open_tables_state

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include <config.h>
21
21
 
22
22
#include <drizzled/session.h>
23
 
 
 
23
#include <drizzled/sql_base.h>
24
24
#include <drizzled/global_charset_info.h>
25
25
#include <drizzled/charset.h>
26
26
#include <drizzled/transaction_services.h>
34
34
namespace plugin
35
35
{
36
36
 
37
 
class AddSchemaNames : 
 
37
class AddSchemaNames :
38
38
  public std::unary_function<StorageEngine *, void>
39
39
{
40
 
  identifier::Schema::vector &schemas;
 
40
  identifier::schema::vector &schemas;
41
41
 
42
42
public:
43
43
 
44
 
  AddSchemaNames(identifier::Schema::vector &of_names) :
 
44
  AddSchemaNames(identifier::schema::vector &of_names) :
45
45
    schemas(of_names)
46
46
  {
47
47
  }
52
52
  }
53
53
};
54
54
 
55
 
void StorageEngine::getIdentifiers(Session &session, identifier::Schema::vector &schemas)
 
55
void StorageEngine::getIdentifiers(Session &session, identifier::schema::vector &schemas)
56
56
{
57
57
  // Add hook here for engines to register schema.
58
58
  std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
70
70
  StorageEngineGetSchemaDefinition(const identifier::Schema &identifier_arg,
71
71
                                   message::schema::shared_ptr &schema_proto_arg) :
72
72
    identifier(identifier_arg),
73
 
    schema_proto(schema_proto_arg) 
 
73
    schema_proto(schema_proto_arg)
74
74
  {
75
75
  }
76
76
 
86
86
*/
87
87
message::schema::shared_ptr StorageEngine::getSchemaDefinition(const drizzled::identifier::Table &identifier)
88
88
{
89
 
  return StorageEngine::getSchemaDefinition(identifier);
 
89
  identifier::Schema schema_identifier= identifier;
 
90
  return StorageEngine::getSchemaDefinition(schema_identifier);
90
91
}
91
92
 
92
93
message::schema::shared_ptr StorageEngine::getSchemaDefinition(const identifier::Schema &identifier)
113
114
}
114
115
 
115
116
 
116
 
const CHARSET_INFO *StorageEngine::getSchemaCollation(const identifier::Schema &identifier)
 
117
const charset_info_st *StorageEngine::getSchemaCollation(const identifier::Schema &identifier)
117
118
{
118
 
  message::schema::shared_ptr schmema_proto;
119
 
 
120
 
  schmema_proto= StorageEngine::getSchemaDefinition(identifier);
121
 
 
122
 
  if (schmema_proto && schmema_proto->has_collation())
123
 
  {
124
 
    const std::string buffer= schmema_proto->collation();
125
 
    const CHARSET_INFO* cs= get_charset_by_name(buffer.c_str());
126
 
 
127
 
    if (not cs)
128
 
    {
129
 
      std::string path;
130
 
      identifier.getSQLPath(path);
131
 
 
132
 
      errmsg_printf(error::ERROR,
133
 
                    _("Error while loading database options: '%s':"), path.c_str());
134
 
      errmsg_printf(error::ERROR, ER(ER_UNKNOWN_COLLATION), buffer.c_str());
135
 
 
136
 
      return default_charset_info;
137
 
    }
138
 
 
139
 
    return cs;
140
 
  }
141
 
 
 
119
  message::schema::shared_ptr schmema_proto= StorageEngine::getSchemaDefinition(identifier);
 
120
  if (not schmema_proto || not schmema_proto->has_collation())
 
121
                return default_charset_info;
 
122
  const std::string buffer= schmema_proto->collation();
 
123
  if (const charset_info_st* cs= get_charset_by_name(buffer.c_str()))
 
124
                return cs;
 
125
  errmsg_printf(error::ERROR, _("Error while loading database options: '%s':"), identifier.getSQLPath().c_str());
 
126
  errmsg_printf(error::ERROR, ER(ER_UNKNOWN_COLLATION), buffer.c_str());
142
127
  return default_charset_info;
143
128
}
144
129
 
145
 
class CreateSchema : 
 
130
class CreateSchema :
146
131
  public std::unary_function<StorageEngine *, void>
147
132
{
148
133
  const drizzled::message::Schema &schema_message;
161
146
    // @todo eomeday check that at least one engine said "true"
162
147
    bool success= engine->doCreateSchema(schema_message);
163
148
 
164
 
    if (success) 
 
149
    if (success)
165
150
    {
166
151
      success_count++;
167
152
      TransactionServices &transaction_services= TransactionServices::singleton();
177
162
  std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
178
163
                CreateSchema(schema_message, success_count));
179
164
 
180
 
  if (success_count) 
 
165
  if (success_count)
181
166
  {
182
167
    TransactionServices &transaction_services= TransactionServices::singleton();
183
168
    transaction_services.allocateNewTransactionId();
186
171
  return (bool)success_count;
187
172
}
188
173
 
189
 
class DropSchema : 
 
174
class DropSchema :
190
175
  public std::unary_function<StorageEngine *, void>
191
176
{
192
177
  uint64_t &success_count;
215
200
};
216
201
 
217
202
static bool drop_all_tables_in_schema(Session& session,
218
 
                                      identifier::Schema::const_reference identifier,
219
 
                                      identifier::Table::vector &dropped_tables,
 
203
                                      const identifier::Schema& identifier,
 
204
                                      identifier::table::vector &dropped_tables,
220
205
                                      uint64_t &deleted)
221
206
{
222
207
  TransactionServices &transaction_services= TransactionServices::singleton();
223
208
 
224
209
  plugin::StorageEngine::getIdentifiers(session, identifier, dropped_tables);
225
210
 
226
 
  for (identifier::Table::vector::iterator it= dropped_tables.begin();
 
211
  for (identifier::table::vector::iterator it= dropped_tables.begin();
227
212
       it != dropped_tables.end();
228
213
       it++)
229
214
  {
251
236
  return true;
252
237
}
253
238
 
254
 
bool StorageEngine::dropSchema(Session::reference session,
255
 
                               identifier::Schema::const_reference identifier,
 
239
bool StorageEngine::dropSchema(Session& session,
 
240
                               const identifier::Schema& identifier,
256
241
                               message::schema::const_reference schema_message)
257
242
{
258
243
  uint64_t deleted= 0;
259
244
  bool error= false;
260
 
  identifier::Table::vector dropped_tables;
 
245
  identifier::table::vector dropped_tables;
261
246
 
262
247
  do
263
248
  {
264
249
    // Remove all temp tables first, this prevents loss of table from
265
250
    // shadowing (ie temp over standard table)
266
251
    {
267
 
      // Lets delete the temporary tables first outside of locks.  
268
 
      identifier::Table::vector set_of_identifiers;
269
 
      session.doGetTableIdentifiers(identifier, set_of_identifiers);
 
252
      // Lets delete the temporary tables first outside of locks.
 
253
      identifier::table::vector set_of_identifiers;
 
254
      session.open_tables.doGetTableIdentifiers(identifier, set_of_identifiers);
270
255
 
271
 
      for (identifier::Table::vector::iterator iter= set_of_identifiers.begin(); iter != set_of_identifiers.end(); iter++)
 
256
      for (identifier::table::vector::iterator iter= set_of_identifiers.begin(); iter != set_of_identifiers.end(); iter++)
272
257
      {
273
258
        if (session.drop_temporary_table(*iter))
274
259
        {
321
306
  return error;
322
307
}
323
308
 
324
 
class AlterSchema : 
 
309
class AlterSchema :
325
310
  public std::unary_function<StorageEngine *, void>
326
311
{
327
312
  uint64_t &success_count;