~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/schema_engine.cc

modifying folder structure

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
class AddSchemaNames : 
38
38
  public std::unary_function<StorageEngine *, void>
39
39
{
40
 
  SchemaIdentifier::vector &schemas;
 
40
  identifier::Schema::vector &schemas;
41
41
 
42
42
public:
43
43
 
44
 
  AddSchemaNames(SchemaIdentifier::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, SchemaIdentifier::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(),
59
59
           AddSchemaNames(schemas));
60
60
 
61
 
  plugin::Authorization::pruneSchemaNames(session.getSecurityContext(), schemas);
 
61
  plugin::Authorization::pruneSchemaNames(session.user(), schemas);
62
62
}
63
63
 
64
64
class StorageEngineGetSchemaDefinition: public std::unary_function<StorageEngine *, bool>
65
65
{
66
 
  const SchemaIdentifier &identifier;
 
66
  const identifier::Schema &identifier;
67
67
  message::schema::shared_ptr &schema_proto;
68
68
 
69
69
public:
70
 
  StorageEngineGetSchemaDefinition(const SchemaIdentifier &identifier_arg,
 
70
  StorageEngineGetSchemaDefinition(const identifier::Schema &identifier_arg,
71
71
                                   message::schema::shared_ptr &schema_proto_arg) :
72
72
    identifier(identifier_arg),
73
73
    schema_proto(schema_proto_arg) 
83
83
/*
84
84
  Return value is "if parsed"
85
85
*/
86
 
bool StorageEngine::getSchemaDefinition(const drizzled::TableIdentifier &identifier, message::schema::shared_ptr &proto)
 
86
bool StorageEngine::getSchemaDefinition(const drizzled::identifier::Table &identifier, message::schema::shared_ptr &proto)
87
87
{
88
88
  return StorageEngine::getSchemaDefinition(identifier, proto);
89
89
}
90
90
 
91
 
bool StorageEngine::getSchemaDefinition(const SchemaIdentifier &identifier, message::schema::shared_ptr &proto)
 
91
bool StorageEngine::getSchemaDefinition(const identifier::Schema &identifier, message::schema::shared_ptr &proto)
92
92
{
93
93
  EngineVector::iterator iter=
94
94
    std::find_if(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
102
102
  return false;
103
103
}
104
104
 
105
 
bool StorageEngine::doesSchemaExist(const SchemaIdentifier &identifier)
 
105
bool StorageEngine::doesSchemaExist(const identifier::Schema &identifier)
106
106
{
107
107
  message::schema::shared_ptr proto;
108
108
 
110
110
}
111
111
 
112
112
 
113
 
const CHARSET_INFO *StorageEngine::getSchemaCollation(const SchemaIdentifier &identifier)
 
113
const CHARSET_INFO *StorageEngine::getSchemaCollation(const identifier::Schema &identifier)
114
114
{
115
115
  message::schema::shared_ptr schmema_proto;
116
116
  bool found;
178
178
  public std::unary_function<StorageEngine *, void>
179
179
{
180
180
  uint64_t &success_count;
181
 
  const SchemaIdentifier &identifier;
 
181
  const identifier::Schema &identifier;
182
182
 
183
183
public:
184
184
 
185
 
  DropSchema(const SchemaIdentifier &arg, uint64_t &count_arg) :
 
185
  DropSchema(const identifier::Schema &arg, uint64_t &count_arg) :
186
186
    success_count(count_arg),
187
187
    identifier(arg)
188
188
  {
202
202
  }
203
203
};
204
204
 
205
 
bool StorageEngine::dropSchema(const SchemaIdentifier &identifier)
206
 
{
207
 
  uint64_t counter= 0;
208
 
  // Add hook here for engines to register schema.
209
 
  std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
210
 
                DropSchema(identifier, counter));
211
 
 
212
 
  return counter ? true : false;
 
205
static bool drop_all_tables_in_schema(Session& session,
 
206
                                      identifier::Schema::const_reference identifier,
 
207
                                      identifier::Table::vector &dropped_tables,
 
208
                                      uint64_t &deleted)
 
209
{
 
210
  TransactionServices &transaction_services= TransactionServices::singleton();
 
211
 
 
212
  plugin::StorageEngine::getIdentifiers(session, identifier, dropped_tables);
 
213
 
 
214
  for (identifier::Table::vector::iterator it= dropped_tables.begin();
 
215
       it != dropped_tables.end();
 
216
       it++)
 
217
  {
 
218
    boost::mutex::scoped_lock scopedLock(table::Cache::singleton().mutex());
 
219
    table::Cache::singleton().removeTable(&session, *it,
 
220
                                          RTFC_WAIT_OTHER_THREAD_FLAG |
 
221
                                          RTFC_CHECK_KILLED_FLAG);
 
222
    if (not plugin::StorageEngine::dropTable(session, *it))
 
223
    {
 
224
      my_error(ER_TABLE_DROP, *it);
 
225
      return false;
 
226
    }
 
227
    transaction_services.dropTable(&session, *it, true);
 
228
    deleted++;
 
229
  }
 
230
 
 
231
  return true;
 
232
}
 
233
 
 
234
bool StorageEngine::dropSchema(Session::reference session, identifier::Schema::const_reference identifier)
 
235
{
 
236
  uint64_t deleted= 0;
 
237
  bool error= false;
 
238
  identifier::Table::vector dropped_tables;
 
239
  message::Schema schema_proto;
 
240
 
 
241
  do
 
242
  {
 
243
    // Remove all temp tables first, this prevents loss of table from
 
244
    // shadowing (ie temp over standard table)
 
245
    {
 
246
      // Lets delete the temporary tables first outside of locks.  
 
247
      identifier::Table::vector set_of_identifiers;
 
248
      session.doGetTableIdentifiers(identifier, set_of_identifiers);
 
249
 
 
250
      for (identifier::Table::vector::iterator iter= set_of_identifiers.begin(); iter != set_of_identifiers.end(); iter++)
 
251
      {
 
252
        if (session.drop_temporary_table(*iter))
 
253
        {
 
254
          my_error(ER_TABLE_DROP, *iter);
 
255
          error= true;
 
256
          break;
 
257
        }
 
258
      }
 
259
    }
 
260
 
 
261
    /* After deleting database, remove all cache entries related to schema */
 
262
    table::Cache::singleton().removeSchema(identifier);
 
263
 
 
264
    if (not drop_all_tables_in_schema(session, identifier, dropped_tables, deleted))
 
265
    {
 
266
      error= true;
 
267
      my_error(ER_DROP_SCHEMA, identifier);
 
268
      break;
 
269
    }
 
270
 
 
271
    uint64_t counter= 0;
 
272
    // Add hook here for engines to register schema.
 
273
    std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(),
 
274
                  DropSchema(identifier, counter));
 
275
 
 
276
    if (not counter)
 
277
    {
 
278
      my_error(ER_DROP_SCHEMA, identifier);
 
279
      error= true;
 
280
 
 
281
      break;
 
282
    }
 
283
    else
 
284
    {
 
285
      /* We've already verified that the schema does exist, so safe to log it */
 
286
      TransactionServices &transaction_services= TransactionServices::singleton();
 
287
      transaction_services.dropSchema(&session, identifier);
 
288
    }
 
289
  } while (0);
 
290
 
 
291
  if (deleted > 0)
 
292
  {
 
293
    session.clear_error();
 
294
    session.server_status|= SERVER_STATUS_DB_DROPPED;
 
295
    session.my_ok((uint32_t) deleted);
 
296
    session.server_status&= ~SERVER_STATUS_DB_DROPPED;
 
297
  }
 
298
 
 
299
 
 
300
  return error;
213
301
}
214
302
 
215
303
class AlterSchema :