~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/storage_engine.h

  • Committer: lbieber
  • Date: 2010-10-05 22:23:12 UTC
  • mfrom: (1813.1.4 build)
  • Revision ID: lbieber@orisndriz08-20101005222312-weuq0ardk3gcryau
Merge Travis - 621861 - convert structs to classes
Merge Billy - 621331 - Replace use of stringstream with boost::lexical_cast
Merge Travis - 621861 = To change C structs to C++ classes in Drizzle
Merge Andrew - fix bug 653300 - Syntax error on inport of a SQL file produced by drizzledump

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
21
21
#define DRIZZLED_PLUGIN_STORAGE_ENGINE_H
22
22
 
23
23
 
24
 
#include <drizzled/cached_directory.h>
25
24
#include <drizzled/definitions.h>
26
 
#include <drizzled/error_t.h>
 
25
#include <drizzled/plugin.h>
27
26
#include <drizzled/handler_structs.h>
28
 
#include <drizzled/identifier.h>
29
 
#include <drizzled/message.h>
30
 
#include <drizzled/message/cache.h>
31
 
#include <drizzled/plugin.h>
32
 
#include <drizzled/plugin/monitored_in_transaction.h>
33
 
#include <drizzled/plugin/plugin.h>
34
 
#include <drizzled/sql_string.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/identifier.h"
 
32
#include "drizzled/cached_directory.h"
 
33
#include "drizzled/plugin/monitored_in_transaction.h"
35
34
 
36
35
#include <bitset>
37
36
#include <string>
38
37
#include <vector>
39
38
#include <set>
40
39
 
41
 
#include <drizzled/visibility.h>
42
 
 
43
40
namespace drizzled
44
41
{
45
42
 
49
46
typedef struct st_hash HASH;
50
47
 
51
48
class TableShare;
 
49
typedef drizzle_lex_string LEX_STRING;
52
50
typedef bool (stat_print_fn)(Session *session, const char *type, uint32_t type_len,
53
51
                             const char *file, uint32_t file_len,
54
52
                             const char *status, uint32_t status_len);
124
122
typedef std::set<std::string> TableNameList;
125
123
 
126
124
extern const std::string UNKNOWN_STRING;
127
 
extern DRIZZLED_API const std::string DEFAULT_DEFINITION_FILE_EXT;
128
 
 
 
125
extern const std::string DEFAULT_DEFINITION_FILE_EXT;
129
126
 
130
127
/*
131
128
  StorageEngine is a singleton structure - one instance per storage engine -
136
133
 
137
134
  static StorageEngine { ... } xxx_engine;
138
135
*/
139
 
class DRIZZLED_API StorageEngine :
140
 
  public Plugin,
141
 
  public MonitoredInTransaction
 
136
class StorageEngine : public Plugin,
 
137
                      public MonitoredInTransaction
142
138
{
143
 
  friend class SEAPITester;
144
139
public:
145
140
  typedef uint64_t Table_flags;
146
141
 
147
142
private:
 
143
  const std::bitset<HTON_BIT_SIZE> flags; /* global Cursor flags */
 
144
 
148
145
  static EngineVector &getSchemaEngines();
149
 
  const std::bitset<HTON_BIT_SIZE> flags; /* global Cursor flags */
150
 
 
151
146
 
152
147
  virtual void setTransactionReadWrite(Session& session);
153
148
 
204
199
  pthread_mutex_t proto_cache_mutex;
205
200
 
206
201
public:
 
202
 
207
203
  StorageEngine(const std::string name_arg,
208
204
                const std::bitset<HTON_BIT_SIZE> &flags_arg= HTON_NO_FLAGS);
209
205
 
210
206
  virtual ~StorageEngine();
211
207
 
212
 
protected:
213
208
  virtual int doGetTableDefinition(Session &session,
214
 
                                   const drizzled::identifier::Table &identifier,
 
209
                                   const drizzled::TableIdentifier &identifier,
215
210
                                   message::Table &table_message)
216
211
  {
217
212
    (void)session;
222
217
  }
223
218
 
224
219
  /* Old style cursor errors */
225
 
  void print_keydup_error(uint32_t key_nr, const char *msg, const Table &table) const;
226
 
  virtual bool get_error_message(int error, String *buf) const;
227
 
 
 
220
protected:
 
221
  void print_keydup_error(uint32_t key_nr, const char *msg, Table &table);
 
222
  void print_error(int error, myf errflag, Table *table= NULL);
 
223
  virtual bool get_error_message(int error, String *buf);
228
224
public:
229
 
  virtual void print_error(int error, myf errflag, const Table& table) const;
 
225
  virtual void print_error(int error, myf errflag, Table& table);
230
226
 
231
227
  bool is_user_selectable() const
232
228
  {
256
252
  {
257
253
    return 0;
258
254
  }
259
 
 
260
 
  virtual Cursor *create(Table &)= 0;
 
255
  virtual Cursor *create(TableShare &)= 0;
261
256
  /* args: path */
262
257
  virtual bool flush_logs() { return false; }
263
258
  virtual bool show_status(Session *, stat_print_fn *, enum ha_stat_type)
281
276
protected:
282
277
  virtual int doCreateTable(Session &session,
283
278
                            Table &table_arg,
284
 
                            const drizzled::identifier::Table &identifier,
 
279
                            const drizzled::TableIdentifier &identifier,
285
280
                            message::Table &message)= 0;
286
281
 
287
282
  virtual int doRenameTable(Session &session,
288
 
                            const drizzled::identifier::Table &from, const drizzled::identifier::Table &to)= 0;
 
283
                            const drizzled::TableIdentifier &from, const drizzled::TableIdentifier &to)= 0;
 
284
 
 
285
public:
 
286
 
 
287
  int renameTable(Session &session, const drizzled::TableIdentifier &from, const drizzled::TableIdentifier &to);
 
288
 
 
289
  virtual void doGetTableIdentifiers(CachedDirectory &directory,
 
290
                                     const drizzled::SchemaIdentifier &schema_identifier,
 
291
                                     TableIdentifiers &set_of_identifiers)= 0;
289
292
 
290
293
  virtual int doDropTable(Session &session,
291
 
                          const drizzled::identifier::Table &identifier)= 0;
292
 
 
293
 
  virtual void doGetTableIdentifiers(CachedDirectory &directory,
294
 
                                     const drizzled::identifier::Schema &schema_identifier,
295
 
                                     identifier::Table::vector &set_of_identifiers)= 0;
296
 
 
297
 
  virtual bool doDoesTableExist(Session& session, const drizzled::identifier::Table &identifier);
298
 
 
299
 
  virtual bool doCanCreateTable(const drizzled::identifier::Table &identifier)
300
 
  { (void)identifier;  return true; }
301
 
 
302
 
public:
303
 
 
304
 
  friend class AddSchemaNames;
305
 
  friend class AddTableIdentifier;
306
 
  friend class AlterSchema;
307
 
  friend class CanCreateTable;
308
 
  friend class CreateSchema;
309
 
  friend class DropSchema;
310
 
  friend class DropTable;
311
 
  friend class DropTables;
312
 
  friend class FindEngineByName;
313
 
  friend class Ha_delete_table_error_handler;
314
 
  friend class StorageEngineCloseConnection;
315
 
  friend class StorageEngineDoesTableExist;
316
 
  friend class StorageEngineGetSchemaDefinition;
317
 
  friend class StorageEngineGetTableDefinition;
318
 
  friend class DropTableByIdentifier;
319
 
 
320
 
  int renameTable(Session &session, const drizzled::identifier::Table &from, const drizzled::identifier::Table &to);
 
294
                          const drizzled::TableIdentifier &identifier)= 0;
321
295
 
322
296
  /* Class Methods for operating on plugin */
323
297
  static bool addPlugin(plugin::StorageEngine *engine);
324
298
  static void removePlugin(plugin::StorageEngine *engine);
325
299
 
326
300
  static int getTableDefinition(Session& session,
327
 
                                const drizzled::identifier::Table &identifier,
328
 
                                message::table::shared_ptr &table_proto,
 
301
                                const drizzled::TableIdentifier &identifier,
 
302
                                message::Table &table_proto,
329
303
                                bool include_temporary_tables= true);
330
 
  static message::table::shared_ptr getTableMessage(Session& session,
331
 
                                                    const drizzled::identifier::Table &identifier,
332
 
                                                    drizzled::error_t &error,
333
 
                                                    bool include_temporary_tables= true);
334
304
  static bool doesTableExist(Session &session,
335
 
                             const drizzled::identifier::Table &identifier,
 
305
                             const drizzled::TableIdentifier &identifier,
336
306
                             bool include_temporary_tables= true);
337
307
 
 
308
  virtual bool doDoesTableExist(Session& session, const drizzled::TableIdentifier &identifier);
 
309
 
338
310
  static plugin::StorageEngine *findByName(const std::string &find_str);
339
311
  static plugin::StorageEngine *findByName(Session& session, const std::string &find_str);
340
312
 
341
313
  static void closeConnection(Session* session);
342
314
  static void dropDatabase(char* path);
343
315
  static bool flushLogs(plugin::StorageEngine *db_type);
344
 
 
345
 
  static bool dropTable(Session& session,
346
 
                        const drizzled::identifier::Table &identifier);
347
 
  static bool dropTable(Session& session,
348
 
                        const drizzled::identifier::Table &identifier,
349
 
                        drizzled::error_t &error);
350
 
 
351
 
  static bool dropTable(Session& session,
352
 
                        StorageEngine &engine,
353
 
                        identifier::Table::const_reference identifier,
354
 
                        drizzled::error_t &error);
355
 
 
 
316
  static int dropTable(Session& session,
 
317
                       const drizzled::TableIdentifier &identifier);
 
318
  static int dropTable(Session& session,
 
319
                       StorageEngine &engine,
 
320
                       const drizzled::TableIdentifier &identifier);
356
321
  static void getIdentifiers(Session &session,
357
 
                             const identifier::Schema &schema_identifier,
358
 
                             identifier::Table::vector &set_of_identifiers);
 
322
                             const SchemaIdentifier &schema_identifier,
 
323
                             TableIdentifiers &set_of_identifiers);
359
324
 
360
325
  // Check to see if any SE objects to creation.
361
 
  static bool canCreateTable(const drizzled::identifier::Table &identifier);
 
326
  static bool canCreateTable(const drizzled::TableIdentifier &identifier);
 
327
  virtual bool doCanCreateTable(const drizzled::TableIdentifier &identifier)
 
328
  { (void)identifier;  return true; }
362
329
 
363
330
  // @note All schema methods defined here
364
 
  static void getIdentifiers(Session &session, identifier::Schema::vector &schemas);
365
 
  static bool getSchemaDefinition(const drizzled::identifier::Table &identifier, message::schema::shared_ptr &proto);
366
 
  static bool getSchemaDefinition(const drizzled::identifier::Schema &identifier, message::schema::shared_ptr &proto);
367
 
  static bool doesSchemaExist(const drizzled::identifier::Schema &identifier);
368
 
  static const CHARSET_INFO *getSchemaCollation(const drizzled::identifier::Schema &identifier);
 
331
  static void getIdentifiers(Session &session, SchemaIdentifiers &schemas);
 
332
  static bool getSchemaDefinition(const drizzled::TableIdentifier &identifier, message::Schema &proto);
 
333
  static bool getSchemaDefinition(const drizzled::SchemaIdentifier &identifier, message::Schema &proto);
 
334
  static bool doesSchemaExist(const drizzled::SchemaIdentifier &identifier);
 
335
  static const CHARSET_INFO *getSchemaCollation(const drizzled::SchemaIdentifier &identifier);
369
336
  static bool createSchema(const drizzled::message::Schema &schema_message);
370
 
  static bool dropSchema(drizzled::Session& session, identifier::Schema::const_reference identifier);
 
337
  static bool dropSchema(const drizzled::SchemaIdentifier &identifier);
371
338
  static bool alterSchema(const drizzled::message::Schema &schema_message);
372
339
 
373
340
  // @note make private/protected
374
 
protected:
375
 
  virtual void doGetSchemaIdentifiers(identifier::Schema::vector&)
 
341
  virtual void doGetSchemaIdentifiers(SchemaIdentifiers&)
376
342
  { }
377
343
 
378
 
  virtual bool doGetSchemaDefinition(const drizzled::identifier::Schema&, drizzled::message::schema::shared_ptr&)
 
344
  virtual bool doGetSchemaDefinition(const drizzled::SchemaIdentifier&, drizzled::message::Schema&)
379
345
  { 
380
346
    return false; 
381
347
  }
386
352
  virtual bool doAlterSchema(const drizzled::message::Schema&)
387
353
  { return false; }
388
354
 
389
 
  virtual bool doDropSchema(const drizzled::identifier::Schema&)
 
355
  virtual bool doDropSchema(const drizzled::SchemaIdentifier&)
390
356
  { return false; }
391
357
 
392
 
public:
393
358
  static inline const std::string &resolveName(const StorageEngine *engine)
394
359
  {
395
360
    return engine == NULL ? UNKNOWN_STRING : engine->getName();
396
361
  }
397
362
 
398
 
  static bool createTable(Session &session,
399
 
                          const identifier::Table &identifier,
400
 
                          message::Table& table_message);
 
363
  static int createTable(Session& session,
 
364
                         const drizzled::TableIdentifier &identifier,
 
365
                         message::Table& table_proto);
401
366
 
402
367
  static void removeLostTemporaryTables(Session &session, const char *directory);
403
368
 
404
 
  Cursor *getCursor(Table &share);
 
369
  Cursor *getCursor(TableShare &share);
405
370
 
406
371
  uint32_t max_record_length() const
407
372
  { return std::min((unsigned int)HA_MAX_REC_LENGTH, max_supported_record_length()); }
422
387
  virtual uint32_t max_supported_key_part_length(void) const { return 255; }
423
388
 
424
389
  /* TODO-> Make private */
425
 
protected:
426
 
  static int deleteDefinitionFromPath(const drizzled::identifier::Table &identifier);
427
 
  static int renameDefinitionFromPath(const drizzled::identifier::Table &dest, const drizzled::identifier::Table &src);
428
 
  static int writeDefinitionFromPath(const drizzled::identifier::Table &identifier, message::Table &proto);
 
390
  static int deleteDefinitionFromPath(const drizzled::TableIdentifier &identifier);
 
391
  static int renameDefinitionFromPath(const drizzled::TableIdentifier &dest, const drizzled::TableIdentifier &src);
 
392
  static int writeDefinitionFromPath(const drizzled::TableIdentifier &identifier, message::Table &proto);
429
393
  static bool readTableFile(const std::string &path, message::Table &table_message);
430
394
 
431
395
public:
463
427
  }
464
428
};
465
429
 
466
 
std::ostream& operator<<(std::ostream& output, const StorageEngine &engine);
467
 
 
468
430
} /* namespace plugin */
469
431
} /* namespace drizzled */
470
432