~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/storage_engine.h

  • Committer: Padraig O'Sullivan
  • Date: 2009-07-08 04:26:02 UTC
  • mto: (1089.3.4 merge)
  • mto: This revision was merged to the branch mainline in revision 1092.
  • Revision ID: osullivan.padraig@gmail.com-20090708042602-x4hmf9ny8dcpvb22
Replaced an instance where a uint8_t type was being used to hold a
collection of flags. Converted it to a std::bitset<2> instead.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
 
24
24
#include <drizzled/definitions.h>
25
 
#include <drizzled/plugin.h>
 
25
#include <drizzled/sql_plugin.h>
26
26
#include <drizzled/handler_structs.h>
27
 
#include <drizzled/message/schema.pb.h>
28
 
#include <drizzled/message/table.pb.h>
29
 
#include "drizzled/plugin/plugin.h"
30
 
#include "drizzled/sql_string.h"
31
 
#include "drizzled/schema_identifier.h"
32
 
#include "drizzled/table_identifier.h"
33
 
#include "drizzled/cached_directory.h"
34
 
#include "drizzled/plugin/monitored_in_transaction.h"
35
 
 
36
 
#include "drizzled/hash.h"
37
27
 
38
28
#include <bitset>
39
29
#include <string>
40
30
#include <vector>
41
 
#include <set>
42
 
 
43
 
namespace drizzled
44
 
{
45
31
 
46
32
class TableList;
47
33
class Session;
48
 
class Cursor;
49
 
typedef struct st_hash HASH;
 
34
class XID;
 
35
class handler;
50
36
 
51
37
class TableShare;
52
 
typedef drizzle_lex_string LEX_STRING;
 
38
typedef struct st_mysql_lex_string LEX_STRING;
53
39
typedef bool (stat_print_fn)(Session *session, const char *type, uint32_t type_len,
54
40
                             const char *file, uint32_t file_len,
55
41
                             const char *status, uint32_t status_len);
 
42
enum ha_stat_type { HA_ENGINE_STATUS, HA_ENGINE_LOGS, HA_ENGINE_MUTEX };
56
43
 
57
44
/* Possible flags of a StorageEngine (there can be 32 of them) */
58
45
enum engine_flag_bits {
 
46
  HTON_BIT_CLOSE_CURSORS_AT_COMMIT,
59
47
  HTON_BIT_ALTER_NOT_SUPPORTED,       // Engine does not support alter
 
48
  HTON_BIT_CAN_RECREATE,              // Delete all is used for truncate
60
49
  HTON_BIT_HIDDEN,                    // Engine does not appear in lists
 
50
  HTON_BIT_FLUSH_AFTER_RENAME,
61
51
  HTON_BIT_NOT_USER_SELECTABLE,
62
52
  HTON_BIT_TEMPORARY_NOT_SUPPORTED,   // Having temporary tables not supported
63
53
  HTON_BIT_TEMPORARY_ONLY,
64
 
  HTON_BIT_FILE_BASED, // use for check_lowercase_names
65
 
  HTON_BIT_DOES_TRANSACTIONS,
66
 
  HTON_BIT_STATS_RECORDS_IS_EXACT,
67
 
  HTON_BIT_NULL_IN_KEY,
68
 
  HTON_BIT_CAN_INDEX_BLOBS,
69
 
  HTON_BIT_PRIMARY_KEY_REQUIRED_FOR_POSITION,
70
 
  HTON_BIT_PRIMARY_KEY_IN_READ_INDEX,
71
 
  HTON_BIT_PARTIAL_COLUMN_READ,
72
 
  HTON_BIT_TABLE_SCAN_ON_INDEX,
73
 
  HTON_BIT_FAST_KEY_READ,
74
 
  HTON_BIT_NO_BLOBS,
75
 
  HTON_BIT_HAS_RECORDS,
76
 
  HTON_BIT_NO_AUTO_INCREMENT,
77
 
  HTON_BIT_DUPLICATE_POS,
78
 
  HTON_BIT_AUTO_PART_KEY,
79
 
  HTON_BIT_REQUIRE_PRIMARY_KEY,
80
 
  HTON_BIT_REQUIRES_KEY_COLUMNS_FOR_DELETE,
81
 
  HTON_BIT_PRIMARY_KEY_REQUIRED_FOR_DELETE,
82
 
  HTON_BIT_NO_PREFIX_CHAR_KEYS,
83
 
  HTON_BIT_HAS_CHECKSUM,
84
 
  HTON_BIT_SKIP_STORE_LOCK,
85
 
  HTON_BIT_SCHEMA_DICTIONARY,
86
 
  HTON_BIT_FOREIGN_KEYS,
87
54
  HTON_BIT_SIZE
88
55
};
89
56
 
90
57
static const std::bitset<HTON_BIT_SIZE> HTON_NO_FLAGS(0);
 
58
static const std::bitset<HTON_BIT_SIZE> HTON_CLOSE_CURSORS_AT_COMMIT(1 <<  HTON_BIT_CLOSE_CURSORS_AT_COMMIT);
91
59
static const std::bitset<HTON_BIT_SIZE> HTON_ALTER_NOT_SUPPORTED(1 << HTON_BIT_ALTER_NOT_SUPPORTED);
 
60
static const std::bitset<HTON_BIT_SIZE> HTON_CAN_RECREATE(1 << HTON_BIT_CAN_RECREATE);
92
61
static const std::bitset<HTON_BIT_SIZE> HTON_HIDDEN(1 << HTON_BIT_HIDDEN);
 
62
static const std::bitset<HTON_BIT_SIZE> HTON_FLUSH_AFTER_RENAME(1 << HTON_BIT_FLUSH_AFTER_RENAME);
93
63
static const std::bitset<HTON_BIT_SIZE> HTON_NOT_USER_SELECTABLE(1 << HTON_BIT_NOT_USER_SELECTABLE);
94
64
static const std::bitset<HTON_BIT_SIZE> HTON_TEMPORARY_NOT_SUPPORTED(1 << HTON_BIT_TEMPORARY_NOT_SUPPORTED);
95
65
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
 
static const std::bitset<HTON_BIT_SIZE> HTON_HAS_DOES_TRANSACTIONS(1 << HTON_BIT_DOES_TRANSACTIONS);
98
 
static const std::bitset<HTON_BIT_SIZE> HTON_STATS_RECORDS_IS_EXACT(1 << HTON_BIT_STATS_RECORDS_IS_EXACT);
99
 
static const std::bitset<HTON_BIT_SIZE> HTON_NULL_IN_KEY(1 << HTON_BIT_NULL_IN_KEY);
100
 
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
 
static const std::bitset<HTON_BIT_SIZE> HTON_PRIMARY_KEY_IN_READ_INDEX(1 << HTON_BIT_PRIMARY_KEY_IN_READ_INDEX);
103
 
static const std::bitset<HTON_BIT_SIZE> HTON_PARTIAL_COLUMN_READ(1 << HTON_BIT_PARTIAL_COLUMN_READ);
104
 
static const std::bitset<HTON_BIT_SIZE> HTON_TABLE_SCAN_ON_INDEX(1 << HTON_BIT_TABLE_SCAN_ON_INDEX);
105
 
static const std::bitset<HTON_BIT_SIZE> HTON_FAST_KEY_READ(1 << HTON_BIT_FAST_KEY_READ);
106
 
static const std::bitset<HTON_BIT_SIZE> HTON_NO_BLOBS(1 << HTON_BIT_NO_BLOBS);
107
 
static const std::bitset<HTON_BIT_SIZE> HTON_HAS_RECORDS(1 << HTON_BIT_HAS_RECORDS);
108
 
static const std::bitset<HTON_BIT_SIZE> HTON_NO_AUTO_INCREMENT(1 << HTON_BIT_NO_AUTO_INCREMENT);
109
 
static const std::bitset<HTON_BIT_SIZE> HTON_DUPLICATE_POS(1 << HTON_BIT_DUPLICATE_POS);
110
 
static const std::bitset<HTON_BIT_SIZE> HTON_AUTO_PART_KEY(1 << HTON_BIT_AUTO_PART_KEY);
111
 
static const std::bitset<HTON_BIT_SIZE> HTON_REQUIRE_PRIMARY_KEY(1 << HTON_BIT_REQUIRE_PRIMARY_KEY);
112
 
static const std::bitset<HTON_BIT_SIZE> HTON_REQUIRES_KEY_COLUMNS_FOR_DELETE(1 << HTON_BIT_REQUIRES_KEY_COLUMNS_FOR_DELETE);
113
 
static const std::bitset<HTON_BIT_SIZE> HTON_PRIMARY_KEY_REQUIRED_FOR_DELETE(1 << HTON_BIT_PRIMARY_KEY_REQUIRED_FOR_DELETE);
114
 
static const std::bitset<HTON_BIT_SIZE> HTON_NO_PREFIX_CHAR_KEYS(1 << HTON_BIT_NO_PREFIX_CHAR_KEYS);
115
 
static const std::bitset<HTON_BIT_SIZE> HTON_HAS_CHECKSUM(1 << HTON_BIT_HAS_CHECKSUM);
116
 
static const std::bitset<HTON_BIT_SIZE> HTON_SKIP_STORE_LOCK(1 << HTON_BIT_SKIP_STORE_LOCK);
117
 
static const std::bitset<HTON_BIT_SIZE> HTON_HAS_SCHEMA_DICTIONARY(1 << HTON_BIT_SCHEMA_DICTIONARY);
118
 
static const std::bitset<HTON_BIT_SIZE> HTON_HAS_FOREIGN_KEYS(1 << HTON_BIT_FOREIGN_KEYS);
119
 
 
120
66
 
121
67
class Table;
122
 
class NamedSavepoint;
123
 
 
124
 
namespace plugin
125
 
{
126
 
 
127
 
typedef hash_map<std::string, StorageEngine *> EngineMap;
128
 
typedef std::vector<StorageEngine *> EngineVector;
129
 
 
130
 
typedef std::set<std::string> TableNameList;
131
 
 
132
 
extern const std::string UNKNOWN_STRING;
133
 
extern const std::string DEFAULT_DEFINITION_FILE_EXT;
134
68
 
135
69
/*
136
70
  StorageEngine is a singleton structure - one instance per storage engine -
137
71
  to provide access to storage engine functionality that works on the
138
 
  "global" level (unlike Cursor class that works on a per-table basis)
 
72
  "global" level (unlike handler class that works on a per-table basis)
139
73
 
140
74
  usually StorageEngine instance is defined statically in ha_xxx.cc as
141
75
 
142
76
  static StorageEngine { ... } xxx_engine;
 
77
 
 
78
  savepoint_*, prepare, recover, and *_by_xid pointers can be 0.
143
79
*/
144
 
class StorageEngine : public Plugin,
145
 
                      public MonitoredInTransaction
 
80
class StorageEngine
146
81
{
147
 
public:
148
 
  typedef uint64_t Table_flags;
149
 
 
150
 
private:
151
 
  const std::bitset<HTON_BIT_SIZE> flags; /* global Cursor flags */
152
 
 
153
 
  static EngineVector &getSchemaEngines();
154
 
 
155
 
  virtual void setTransactionReadWrite(Session& session);
156
 
 
157
 
  /*
158
 
   * Indicates to a storage engine the start of a
159
 
   * new SQL statement.
160
 
   */
161
 
  virtual void doStartStatement(Session *session)
162
 
  {
163
 
    (void) session;
164
 
  }
165
 
 
166
 
  /*
167
 
   * Indicates to a storage engine the end of
168
 
   * the current SQL statement in the supplied
169
 
   * Session.
170
 
   */
171
 
  virtual void doEndStatement(Session *session)
172
 
  {
173
 
    (void) session;
174
 
  }
175
 
 
176
 
protected:
177
 
  std::string table_definition_ext;
178
 
 
179
 
public:
180
 
  const std::string& getTableDefinitionFileExtension()
181
 
  {
182
 
    return table_definition_ext;
183
 
  }
184
 
 
185
 
private:
 
82
  /*
 
83
    Name used for storage engine.
 
84
  */
 
85
  const std::string name;
 
86
  const bool two_phase_commit;
 
87
  bool enabled;
 
88
 
 
89
  const std::bitset<HTON_BIT_SIZE> flags; /* global handler flags */
 
90
  /*
 
91
    to store per-savepoint data storage engine is provided with an area
 
92
    of a requested size (0 is ok here).
 
93
    savepoint_offset must be initialized statically to the size of
 
94
    the needed memory to store per-savepoint information.
 
95
    After xxx_init it is changed to be an offset to savepoint storage
 
96
    area and need not be used by storage engine.
 
97
    see binlog_engine and binlog_savepoint_set/rollback for an example.
 
98
  */
 
99
  size_t savepoint_offset;
 
100
  size_t orig_savepoint_offset;
186
101
  std::vector<std::string> aliases;
187
102
 
 
103
  void setTransactionReadWrite(Session* session);
 
104
 
 
105
protected:
 
106
 
 
107
  /**
 
108
   * Implementing classes should override these to provide savepoint
 
109
   * functionality.
 
110
   */
 
111
  virtual int savepoint_set_hook(Session *, void *) { return 0; }
 
112
 
 
113
  virtual int savepoint_rollback_hook(Session *, void *) { return 0; }
 
114
 
 
115
  virtual int savepoint_release_hook(Session *, void *) { return 0; }
 
116
 
188
117
public:
189
 
  const std::vector<std::string>& getAliases() const
 
118
 
 
119
  StorageEngine(const std::string name_arg,
 
120
                const std::bitset<HTON_BIT_SIZE> &flags_arg= HTON_NO_FLAGS,
 
121
                size_t savepoint_offset_arg= 0,
 
122
                bool support_2pc= false);
 
123
 
 
124
  virtual ~StorageEngine();
 
125
 
 
126
  /*
 
127
    each storage engine has it's own memory area (actually a pointer)
 
128
    in the session, for storing per-connection information.
 
129
    It is accessed as
 
130
 
 
131
      session->ha_data[xxx_engine.slot]
 
132
 
 
133
   slot number is initialized by MySQL after xxx_init() is called.
 
134
  */
 
135
  uint32_t slot;
 
136
 
 
137
  inline uint32_t getSlot (void) { return slot; }
 
138
  inline void setSlot (uint32_t value) { slot= value; }
 
139
 
 
140
  const std::vector<std::string>& getAliases()
190
141
  {
191
142
    return aliases;
192
143
  }
196
147
    aliases.push_back(alias);
197
148
  }
198
149
 
199
 
protected:
200
 
 
201
 
  /**
202
 
    @brief
203
 
    Used as a protobuf storage currently by TEMP only engines.
204
 
  */
205
 
  typedef std::map <std::string, message::Table> ProtoCache;
206
 
  ProtoCache proto_cache;
207
 
  pthread_mutex_t proto_cache_mutex;
208
 
 
209
 
public:
210
 
 
211
 
  StorageEngine(const std::string name_arg,
212
 
                const std::bitset<HTON_BIT_SIZE> &flags_arg= HTON_NO_FLAGS);
213
 
 
214
 
  virtual ~StorageEngine();
215
 
 
216
 
  virtual int doGetTableDefinition(Session &session,
217
 
                                   TableIdentifier &identifier,
218
 
                                   message::Table &table_message)
219
 
  {
220
 
    (void)session;
221
 
    (void)identifier;
222
 
    (void)table_message;
223
 
 
224
 
    return ENOENT;
225
 
  }
226
 
 
227
 
  /* Old style cursor errors */
228
 
protected:
229
 
  void print_keydup_error(uint32_t key_nr, const char *msg, Table &table);
230
 
  void print_error(int error, myf errflag, Table *table= NULL);
231
 
  virtual bool get_error_message(int error, String *buf);
232
 
public:
233
 
  virtual void print_error(int error, myf errflag, Table& table);
 
150
  bool has_2pc()
 
151
  {
 
152
    return two_phase_commit;
 
153
  }
 
154
 
 
155
 
 
156
  bool is_enabled() const
 
157
  {
 
158
    return enabled;
 
159
  }
234
160
 
235
161
  bool is_user_selectable() const
236
162
  {
242
168
    return flags.test(flag);
243
169
  }
244
170
 
245
 
  // @todo match check_flag interface
246
 
  virtual uint32_t index_flags(enum  ha_key_alg) const { return 0; }
247
 
  virtual void startStatement(Session *session)
248
 
  {
249
 
    doStartStatement(session);
250
 
  }
251
 
  virtual void endStatement(Session *session)
252
 
  {
253
 
    doEndStatement(session);
254
 
  }
 
171
  void enable() { enabled= true; }
 
172
  void disable() { enabled= false; }
 
173
 
 
174
  std::string getName() const { return name; }
255
175
 
256
176
  /*
257
 
   * Called during Session::cleanup() for all engines
258
 
   */
 
177
    StorageEngine methods:
 
178
 
 
179
    close_connection is only called if
 
180
    session->ha_data[xxx_engine.slot] is non-zero, so even if you don't need
 
181
    this storage area - set it to something, so that MySQL would know
 
182
    this storage engine was accessed in this connection
 
183
  */
259
184
  virtual int close_connection(Session  *)
260
185
  {
261
186
    return 0;
262
187
  }
263
 
  virtual Cursor *create(TableShare &, memory::Root *)= 0;
 
188
  /*
 
189
    'all' is true if it's a real commit, that makes persistent changes
 
190
    'all' is false if it's not in fact a commit but an end of the
 
191
    statement that is part of the transaction.
 
192
    NOTE 'all' is also false in auto-commit mode where 'end of statement'
 
193
    and 'real commit' mean the same event.
 
194
  */
 
195
  virtual int  commit(Session *, bool)
 
196
  {
 
197
    return 0;
 
198
  }
 
199
 
 
200
  virtual int  rollback(Session *, bool)
 
201
  {
 
202
    return 0;
 
203
  }
 
204
 
 
205
  /*
 
206
    The void * points to an uninitialized storage area of requested size
 
207
    (see savepoint_offset description)
 
208
  */
 
209
  int savepoint_set(Session *session, void *sp)
 
210
  {
 
211
    return savepoint_set_hook(session, (unsigned char *)sp+savepoint_offset);
 
212
  }
 
213
 
 
214
  /*
 
215
    The void * points to a storage area, that was earlier passed
 
216
    to the savepoint_set call
 
217
  */
 
218
  int savepoint_rollback(Session *session, void *sp)
 
219
  {
 
220
     return savepoint_rollback_hook(session,
 
221
                                    (unsigned char *)sp+savepoint_offset);
 
222
  }
 
223
 
 
224
  int savepoint_release(Session *session, void *sp)
 
225
  {
 
226
    return savepoint_release_hook(session,
 
227
                                  (unsigned char *)sp+savepoint_offset);
 
228
  }
 
229
 
 
230
  virtual int  prepare(Session *, bool) { return 0; }
 
231
  virtual int  recover(XID *, uint32_t) { return 0; }
 
232
  virtual int  commit_by_xid(XID *) { return 0; }
 
233
  virtual int  rollback_by_xid(XID *) { return 0; }
 
234
  virtual handler *create(TableShare *, MEM_ROOT *)= 0;
264
235
  /* args: path */
 
236
  virtual void drop_database(char*) { }
 
237
  virtual int start_consistent_snapshot(Session *) { return 0; }
265
238
  virtual bool flush_logs() { return false; }
266
239
  virtual bool show_status(Session *, stat_print_fn *, enum ha_stat_type)
267
240
  {
268
241
    return false;
269
242
  }
270
243
 
 
244
  /* args: current_session, tables, cond */
 
245
  virtual int fill_files_table(Session *, TableList *,
 
246
                               Item *) { return 0; }
 
247
  virtual int release_temporary_latches(Session *) { return false; }
 
248
 
 
249
  /* args: current_session, db, name */
 
250
  virtual int table_exists_in_engine(Session*, const char *, const char *);
 
251
 
271
252
  /**
272
253
    If frm_error() is called then we will use this to find out what file
273
254
    extentions exist for the storage engine. This is also used by the default
274
 
    rename_table and delete_table method in Cursor.cc.
 
255
    rename_table and delete_table method in handler.cc.
275
256
 
276
257
    For engines that have two file name extentions (separate meta/index file
277
258
    and data file), the order of elements is relevant. First element of engine
282
263
  virtual const char **bas_ext() const =0;
283
264
 
284
265
protected:
285
 
  virtual int doCreateTable(Session &session,
286
 
                            Table &table_arg,
287
 
                            TableIdentifier &identifier,
288
 
                            message::Table &message)= 0;
289
 
 
290
 
  virtual int doRenameTable(Session &session,
291
 
                            TableIdentifier &from, TableIdentifier &to)= 0;
292
 
 
293
 
public:
294
 
 
295
 
  int renameTable(Session &session, TableIdentifier &from, TableIdentifier &to);
296
 
 
297
 
  // @todo move these to protected
298
 
  virtual void doGetTableNames(CachedDirectory &directory,
299
 
                               drizzled::SchemaIdentifier &schema_identifier,
300
 
                               TableNameList &set_of_names)= 0;
301
 
 
302
 
  virtual void doGetTableIdentifiers(CachedDirectory &directory,
303
 
                                     drizzled::SchemaIdentifier &schema_identifier,
304
 
                                     TableIdentifiers &set_of_identifiers)= 0;
305
 
 
306
 
  virtual int doDropTable(Session &session,
307
 
                          TableIdentifier &identifier)= 0;
308
 
 
309
 
  /* Class Methods for operating on plugin */
310
 
  static bool addPlugin(plugin::StorageEngine *engine);
311
 
  static void removePlugin(plugin::StorageEngine *engine);
312
 
 
313
 
  static int getTableDefinition(Session& session,
314
 
                                TableIdentifier &identifier,
315
 
                                message::Table &table_proto,
316
 
                                bool include_temporary_tables= true);
317
 
  static bool doesTableExist(Session &session,
318
 
                             TableIdentifier &identifier,
319
 
                             bool include_temporary_tables= true);
320
 
 
321
 
  virtual bool doDoesTableExist(Session& session, TableIdentifier &identifier);
322
 
 
323
 
  static plugin::StorageEngine *findByName(const std::string &find_str);
324
 
  static plugin::StorageEngine *findByName(Session& session, const std::string &find_str);
325
 
 
326
 
  static void closeConnection(Session* session);
327
 
  static void dropDatabase(char* path);
328
 
  static bool flushLogs(plugin::StorageEngine *db_type);
329
 
  static int dropTable(Session& session,
330
 
                       TableIdentifier &identifier);
331
 
  static int dropTable(Session& session,
332
 
                       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);
336
 
 
337
 
  // Check to see if any SE objects to creation.
338
 
  static bool canCreateTable(drizzled::TableIdentifier &identifier);
339
 
  virtual bool doCanCreateTable(drizzled::TableIdentifier &identifier)
340
 
  { (void)identifier;  return true; }
341
 
 
342
 
  // @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);
348
 
  static bool createSchema(const drizzled::message::Schema &schema_message);
349
 
  static bool dropSchema(drizzled::SchemaIdentifier &identifier);
350
 
  static bool alterSchema(const drizzled::message::Schema &schema_message);
351
 
 
352
 
  // @note make private/protected
353
 
  virtual void doGetSchemaIdentifiers(SchemaIdentifierList&)
354
 
  { }
355
 
 
356
 
  virtual bool doGetSchemaDefinition(drizzled::SchemaIdentifier&, drizzled::message::Schema&)
357
 
  { 
358
 
    return false; 
359
 
  }
360
 
 
361
 
  virtual bool doCreateSchema(const drizzled::message::Schema&)
362
 
  { return false; }
363
 
 
364
 
  virtual bool doAlterSchema(const drizzled::message::Schema&)
365
 
  { return false; }
366
 
 
367
 
  virtual bool doDropSchema(drizzled::SchemaIdentifier&)
368
 
  { return false; }
369
 
 
370
 
  static inline const std::string &resolveName(const StorageEngine *engine)
371
 
  {
372
 
    return engine == NULL ? UNKNOWN_STRING : engine->getName();
373
 
  }
374
 
 
375
 
  static int createTable(Session& session,
376
 
                         TableIdentifier &identifier,
377
 
                         bool update_create_info,
378
 
                         message::Table& table_proto);
379
 
 
380
 
  static void removeLostTemporaryTables(Session &session, const char *directory);
381
 
 
382
 
  Cursor *getCursor(TableShare &share, memory::Root *alloc);
383
 
 
384
 
  uint32_t max_record_length() const
385
 
  { return std::min((unsigned int)HA_MAX_REC_LENGTH, max_supported_record_length()); }
386
 
  uint32_t max_keys() const
387
 
  { return std::min((unsigned int)MAX_KEY, max_supported_keys()); }
388
 
  uint32_t max_key_parts() const
389
 
  { return std::min((unsigned int)MAX_REF_PARTS, max_supported_key_parts()); }
390
 
  uint32_t max_key_length() const
391
 
  { return std::min((unsigned int)MAX_KEY_LENGTH, max_supported_key_length()); }
392
 
  uint32_t max_key_part_length(void) const
393
 
  { return std::min((unsigned int)MAX_KEY_LENGTH, max_supported_key_part_length()); }
394
 
 
395
 
  virtual uint32_t max_supported_record_length(void) const
396
 
  { return HA_MAX_REC_LENGTH; }
397
 
  virtual uint32_t max_supported_keys(void) const { return 0; }
398
 
  virtual uint32_t max_supported_key_parts(void) const { return MAX_REF_PARTS; }
399
 
  virtual uint32_t max_supported_key_length(void) const { return MAX_KEY_LENGTH; }
400
 
  virtual uint32_t max_supported_key_part_length(void) const { return 255; }
401
 
 
402
 
  /* 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);
406
 
  static bool readTableFile(const std::string &path, message::Table &table_message);
407
 
 
408
 
public:
409
 
  /* 
410
 
   * The below are simple virtual overrides for the plugin::MonitoredInTransaction
411
 
   * interface.
412
 
   */
413
 
  virtual bool participatesInSqlTransaction() const
414
 
  {
415
 
    return false; /* plugin::StorageEngine is non-transactional in terms of SQL */
416
 
  }
417
 
  virtual bool participatesInXaTransaction() const
418
 
  {
419
 
    return false; /* plugin::StorageEngine is non-transactional in terms of XA */
420
 
  }
421
 
  virtual bool alwaysRegisterForXaTransaction() const
422
 
  {
423
 
    return false;
 
266
  virtual int createTableImpl(Session *session, const char *table_name,
 
267
                              Table *table_arg,
 
268
                              HA_CREATE_INFO *create_info)= 0;
 
269
 
 
270
  virtual int renameTableImpl(Session* session, const char *from, const char *to);
 
271
 
 
272
  virtual int deleteTableImpl(Session* session, const std::string table_path);
 
273
 
 
274
public:
 
275
  int createTable(Session *session, const char *table_name, Table *table_arg,
 
276
                  HA_CREATE_INFO *create_info) {
 
277
    setTransactionReadWrite(session);
 
278
 
 
279
    return createTableImpl(session, table_name, table_arg, create_info);
 
280
  }
 
281
 
 
282
  int renameTable(Session *session, const char *from, const char *to) {
 
283
    setTransactionReadWrite(session);
 
284
 
 
285
    return renameTableImpl(session, from, to);
 
286
  }
 
287
 
 
288
  int deleteTable(Session* session, const std::string table_path) {
 
289
    setTransactionReadWrite(session);
 
290
 
 
291
    return deleteTableImpl(session, table_path);
424
292
  }
425
293
};
426
294
 
427
 
} /* namespace plugin */
428
 
} /* namespace drizzled */
 
295
/* lookups */
 
296
StorageEngine *ha_default_storage_engine(Session *session);
 
297
StorageEngine *ha_resolve_by_name(Session *session, const LEX_STRING *name);
 
298
handler *get_new_handler(TableShare *share, MEM_ROOT *alloc,
 
299
                         StorageEngine *db_type);
 
300
const std::string ha_resolve_storage_engine_name(const StorageEngine *db_type);
429
301
 
430
302
#endif /* DRIZZLED_PLUGIN_STORAGE_ENGINE_H */