~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/storage_engine.h

  • Committer: Stewart Smith
  • Date: 2010-07-27 00:49:32 UTC
  • mto: (1720.1.1 drizzle)
  • mto: This revision was merged to the branch mainline in revision 1721.
  • Revision ID: stewart@flamingspork.com-20100727004932-basq3vx9szmmbswm
fix storing and manipulating foreign keys in the proto around ALTER TABLE, CREATE TABLE and ALTER TABLE ADD/DROP FOREIGN KEY. We also (mostly) emulate the naming of innodb foreign keys in the upper layer.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include <drizzled/message/table.pb.h>
29
29
#include "drizzled/plugin/plugin.h"
30
30
#include "drizzled/sql_string.h"
31
 
#include "drizzled/schema_identifier.h"
32
 
#include "drizzled/table_identifier.h"
 
31
#include "drizzled/identifier.h"
33
32
#include "drizzled/cached_directory.h"
34
33
#include "drizzled/plugin/monitored_in_transaction.h"
35
34
 
36
 
#include "drizzled/hash.h"
 
35
#include <drizzled/unordered_map.h>
37
36
 
38
37
#include <bitset>
39
38
#include <string>
61
60
  HTON_BIT_NOT_USER_SELECTABLE,
62
61
  HTON_BIT_TEMPORARY_NOT_SUPPORTED,   // Having temporary tables not supported
63
62
  HTON_BIT_TEMPORARY_ONLY,
64
 
  HTON_BIT_FILE_BASED, // use for check_lowercase_names
65
63
  HTON_BIT_DOES_TRANSACTIONS,
66
64
  HTON_BIT_STATS_RECORDS_IS_EXACT,
67
65
  HTON_BIT_NULL_IN_KEY,
68
66
  HTON_BIT_CAN_INDEX_BLOBS,
69
 
  HTON_BIT_PRIMARY_KEY_REQUIRED_FOR_POSITION,
70
67
  HTON_BIT_PRIMARY_KEY_IN_READ_INDEX,
71
68
  HTON_BIT_PARTIAL_COLUMN_READ,
72
69
  HTON_BIT_TABLE_SCAN_ON_INDEX,
93
90
static const std::bitset<HTON_BIT_SIZE> HTON_NOT_USER_SELECTABLE(1 << HTON_BIT_NOT_USER_SELECTABLE);
94
91
static const std::bitset<HTON_BIT_SIZE> HTON_TEMPORARY_NOT_SUPPORTED(1 << HTON_BIT_TEMPORARY_NOT_SUPPORTED);
95
92
static const std::bitset<HTON_BIT_SIZE> HTON_TEMPORARY_ONLY(1 << HTON_BIT_TEMPORARY_ONLY);
96
 
static const std::bitset<HTON_BIT_SIZE> HTON_FILE_BASED(1 << HTON_BIT_FILE_BASED);
97
93
static const std::bitset<HTON_BIT_SIZE> HTON_HAS_DOES_TRANSACTIONS(1 << HTON_BIT_DOES_TRANSACTIONS);
98
94
static const std::bitset<HTON_BIT_SIZE> HTON_STATS_RECORDS_IS_EXACT(1 << HTON_BIT_STATS_RECORDS_IS_EXACT);
99
95
static const std::bitset<HTON_BIT_SIZE> HTON_NULL_IN_KEY(1 << HTON_BIT_NULL_IN_KEY);
100
96
static const std::bitset<HTON_BIT_SIZE> HTON_CAN_INDEX_BLOBS(1 << HTON_BIT_CAN_INDEX_BLOBS);
101
 
static const std::bitset<HTON_BIT_SIZE> HTON_PRIMARY_KEY_REQUIRED_FOR_POSITION(1 << HTON_BIT_PRIMARY_KEY_REQUIRED_FOR_POSITION);
102
97
static const std::bitset<HTON_BIT_SIZE> HTON_PRIMARY_KEY_IN_READ_INDEX(1 << HTON_BIT_PRIMARY_KEY_IN_READ_INDEX);
103
98
static const std::bitset<HTON_BIT_SIZE> HTON_PARTIAL_COLUMN_READ(1 << HTON_BIT_PARTIAL_COLUMN_READ);
104
99
static const std::bitset<HTON_BIT_SIZE> HTON_TABLE_SCAN_ON_INDEX(1 << HTON_BIT_TABLE_SCAN_ON_INDEX);
124
119
namespace plugin
125
120
{
126
121
 
127
 
typedef hash_map<std::string, StorageEngine *> EngineMap;
 
122
typedef unordered_map<std::string, StorageEngine *> EngineMap;
128
123
typedef std::vector<StorageEngine *> EngineVector;
129
124
 
130
125
typedef std::set<std::string> TableNameList;
214
209
  virtual ~StorageEngine();
215
210
 
216
211
  virtual int doGetTableDefinition(Session &session,
217
 
                                   TableIdentifier &identifier,
 
212
                                   const drizzled::TableIdentifier &identifier,
218
213
                                   message::Table &table_message)
219
214
  {
220
215
    (void)session;
284
279
protected:
285
280
  virtual int doCreateTable(Session &session,
286
281
                            Table &table_arg,
287
 
                            TableIdentifier &identifier,
 
282
                            const drizzled::TableIdentifier &identifier,
288
283
                            message::Table &message)= 0;
289
284
 
290
285
  virtual int doRenameTable(Session &session,
291
 
                            TableIdentifier &from, TableIdentifier &to)= 0;
 
286
                            const drizzled::TableIdentifier &from, const drizzled::TableIdentifier &to)= 0;
292
287
 
293
288
public:
294
289
 
295
 
  int renameTable(Session &session, TableIdentifier &from, TableIdentifier &to);
 
290
  int renameTable(Session &session, const drizzled::TableIdentifier &from, const drizzled::TableIdentifier &to);
296
291
 
297
292
  // @todo move these to protected
298
293
  virtual void doGetTableNames(CachedDirectory &directory,
299
 
                               drizzled::SchemaIdentifier &schema_identifier,
 
294
                               const drizzled::SchemaIdentifier &schema_identifier,
300
295
                               TableNameList &set_of_names)= 0;
301
296
 
302
297
  virtual void doGetTableIdentifiers(CachedDirectory &directory,
303
 
                                     drizzled::SchemaIdentifier &schema_identifier,
 
298
                                     const drizzled::SchemaIdentifier &schema_identifier,
304
299
                                     TableIdentifiers &set_of_identifiers)= 0;
305
300
 
306
301
  virtual int doDropTable(Session &session,
307
 
                          TableIdentifier &identifier)= 0;
 
302
                          const drizzled::TableIdentifier &identifier)= 0;
308
303
 
309
304
  /* Class Methods for operating on plugin */
310
305
  static bool addPlugin(plugin::StorageEngine *engine);
311
306
  static void removePlugin(plugin::StorageEngine *engine);
312
307
 
313
308
  static int getTableDefinition(Session& session,
314
 
                                TableIdentifier &identifier,
 
309
                                const drizzled::TableIdentifier &identifier,
315
310
                                message::Table &table_proto,
316
311
                                bool include_temporary_tables= true);
317
312
  static bool doesTableExist(Session &session,
318
 
                             TableIdentifier &identifier,
 
313
                             const drizzled::TableIdentifier &identifier,
319
314
                             bool include_temporary_tables= true);
320
315
 
321
 
  virtual bool doDoesTableExist(Session& session, TableIdentifier &identifier);
 
316
  virtual bool doDoesTableExist(Session& session, const drizzled::TableIdentifier &identifier);
322
317
 
323
318
  static plugin::StorageEngine *findByName(const std::string &find_str);
324
319
  static plugin::StorageEngine *findByName(Session& session, const std::string &find_str);
327
322
  static void dropDatabase(char* path);
328
323
  static bool flushLogs(plugin::StorageEngine *db_type);
329
324
  static int dropTable(Session& session,
330
 
                       TableIdentifier &identifier);
 
325
                       const drizzled::TableIdentifier &identifier);
331
326
  static int dropTable(Session& session,
332
327
                       StorageEngine &engine,
333
 
                       TableIdentifier &identifier);
334
 
  static void getTableNames(Session &session, drizzled::SchemaIdentifier& schema_identifier, TableNameList &set_of_names);
335
 
  static void getTableIdentifiers(Session &session, SchemaIdentifier &schema_identifier, TableIdentifiers &set_of_identifiers);
 
328
                       const drizzled::TableIdentifier &identifier);
 
329
  static void getIdentifiers(Session &session,
 
330
                             const SchemaIdentifier &schema_identifier,
 
331
                             TableIdentifiers &set_of_identifiers);
336
332
 
337
333
  // Check to see if any SE objects to creation.
338
 
  static bool canCreateTable(drizzled::TableIdentifier &identifier);
339
 
  virtual bool doCanCreateTable(drizzled::TableIdentifier &identifier)
 
334
  static bool canCreateTable(const drizzled::TableIdentifier &identifier);
 
335
  virtual bool doCanCreateTable(const drizzled::TableIdentifier &identifier)
340
336
  { (void)identifier;  return true; }
341
337
 
342
338
  // @note All schema methods defined here
343
 
  static void getSchemaIdentifiers(Session &session, SchemaIdentifierList &schemas);
344
 
  static bool getSchemaDefinition(TableIdentifier &identifier, message::Schema &proto);
345
 
  static bool getSchemaDefinition(drizzled::SchemaIdentifier &identifier, message::Schema &proto);
346
 
  static bool doesSchemaExist(drizzled::SchemaIdentifier &identifier);
347
 
  static const CHARSET_INFO *getSchemaCollation(drizzled::SchemaIdentifier &identifier);
 
339
  static void getIdentifiers(Session &session, SchemaIdentifiers &schemas);
 
340
  static bool getSchemaDefinition(const drizzled::TableIdentifier &identifier, message::Schema &proto);
 
341
  static bool getSchemaDefinition(const drizzled::SchemaIdentifier &identifier, message::Schema &proto);
 
342
  static bool doesSchemaExist(const drizzled::SchemaIdentifier &identifier);
 
343
  static const CHARSET_INFO *getSchemaCollation(const drizzled::SchemaIdentifier &identifier);
348
344
  static bool createSchema(const drizzled::message::Schema &schema_message);
349
 
  static bool dropSchema(drizzled::SchemaIdentifier &identifier);
 
345
  static bool dropSchema(const drizzled::SchemaIdentifier &identifier);
350
346
  static bool alterSchema(const drizzled::message::Schema &schema_message);
351
347
 
352
348
  // @note make private/protected
353
 
  virtual void doGetSchemaIdentifiers(SchemaIdentifierList&)
 
349
  virtual void doGetSchemaIdentifiers(SchemaIdentifiers&)
354
350
  { }
355
351
 
356
 
  virtual bool doGetSchemaDefinition(drizzled::SchemaIdentifier&, drizzled::message::Schema&)
 
352
  virtual bool doGetSchemaDefinition(const drizzled::SchemaIdentifier&, drizzled::message::Schema&)
357
353
  { 
358
354
    return false; 
359
355
  }
364
360
  virtual bool doAlterSchema(const drizzled::message::Schema&)
365
361
  { return false; }
366
362
 
367
 
  virtual bool doDropSchema(drizzled::SchemaIdentifier&)
 
363
  virtual bool doDropSchema(const drizzled::SchemaIdentifier&)
368
364
  { return false; }
369
365
 
370
366
  static inline const std::string &resolveName(const StorageEngine *engine)
373
369
  }
374
370
 
375
371
  static int createTable(Session& session,
376
 
                         TableIdentifier &identifier,
377
 
                         bool update_create_info,
 
372
                         const drizzled::TableIdentifier &identifier,
378
373
                         message::Table& table_proto);
379
374
 
380
375
  static void removeLostTemporaryTables(Session &session, const char *directory);
400
395
  virtual uint32_t max_supported_key_part_length(void) const { return 255; }
401
396
 
402
397
  /* TODO-> Make private */
403
 
  static int deleteDefinitionFromPath(TableIdentifier &identifier);
404
 
  static int renameDefinitionFromPath(TableIdentifier &dest, TableIdentifier &src);
405
 
  static int writeDefinitionFromPath(TableIdentifier &identifier, message::Table &proto);
 
398
  static int deleteDefinitionFromPath(const drizzled::TableIdentifier &identifier);
 
399
  static int renameDefinitionFromPath(const drizzled::TableIdentifier &dest, const drizzled::TableIdentifier &src);
 
400
  static int writeDefinitionFromPath(const drizzled::TableIdentifier &identifier, message::Table &proto);
406
401
  static bool readTableFile(const std::string &path, message::Table &table_message);
407
402
 
408
403
public:
422
417
  {
423
418
    return false;
424
419
  }
 
420
 
 
421
  virtual bool validateCreateTableOption(const std::string &key, const std::string &state)
 
422
  {
 
423
    (void)key;
 
424
    (void)state;
 
425
 
 
426
    return false;
 
427
  }
 
428
 
 
429
  virtual bool validateCreateSchemaOption(const std::string &key, const std::string &state)
 
430
  {
 
431
    (void)key;
 
432
    (void)state;
 
433
 
 
434
    return false;
 
435
  }
425
436
};
426
437
 
427
438
} /* namespace plugin */