~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/storage_engine.h

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:26:39 UTC
  • mfrom: (2157.2.2 give-in-to-pkg-config)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172639-nhy7i72sfhoq13ms
Merged in pkg-config fixes.

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
 
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
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>
24
25
#include <drizzled/definitions.h>
25
 
#include <drizzled/plugin.h>
 
26
#include <drizzled/error_t.h>
26
27
#include <drizzled/handler_structs.h>
 
28
#include <drizzled/identifier.h>
27
29
#include <drizzled/message.h>
28
30
#include <drizzled/message/cache.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"
 
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>
34
35
 
35
36
#include <bitset>
36
37
#include <string>
37
38
#include <vector>
38
39
#include <set>
39
40
 
 
41
#include <drizzled/visibility.h>
 
42
 
40
43
namespace drizzled
41
44
{
42
45
 
46
49
typedef struct st_hash HASH;
47
50
 
48
51
class TableShare;
49
 
typedef drizzle_lex_string LEX_STRING;
50
52
typedef bool (stat_print_fn)(Session *session, const char *type, uint32_t type_len,
51
53
                             const char *file, uint32_t file_len,
52
54
                             const char *status, uint32_t status_len);
122
124
typedef std::set<std::string> TableNameList;
123
125
 
124
126
extern const std::string UNKNOWN_STRING;
125
 
extern const std::string DEFAULT_DEFINITION_FILE_EXT;
 
127
extern DRIZZLED_API const std::string DEFAULT_DEFINITION_FILE_EXT;
 
128
 
126
129
 
127
130
/*
128
131
  StorageEngine is a singleton structure - one instance per storage engine -
133
136
 
134
137
  static StorageEngine { ... } xxx_engine;
135
138
*/
136
 
class StorageEngine : public Plugin,
137
 
                      public MonitoredInTransaction
 
139
class DRIZZLED_API StorageEngine :
 
140
  public Plugin,
 
141
  public MonitoredInTransaction
138
142
{
 
143
  friend class SEAPITester;
139
144
public:
140
145
  typedef uint64_t Table_flags;
141
146
 
142
147
private:
 
148
  static EngineVector &getSchemaEngines();
143
149
  const std::bitset<HTON_BIT_SIZE> flags; /* global Cursor flags */
144
150
 
145
 
  static EngineVector &getSchemaEngines();
146
151
 
147
152
  virtual void setTransactionReadWrite(Session& session);
148
153
 
199
204
  pthread_mutex_t proto_cache_mutex;
200
205
 
201
206
public:
202
 
 
203
207
  StorageEngine(const std::string name_arg,
204
208
                const std::bitset<HTON_BIT_SIZE> &flags_arg= HTON_NO_FLAGS);
205
209
 
206
210
  virtual ~StorageEngine();
207
211
 
 
212
protected:
208
213
  virtual int doGetTableDefinition(Session &session,
209
 
                                   const drizzled::TableIdentifier &identifier,
 
214
                                   const drizzled::identifier::Table &identifier,
210
215
                                   message::Table &table_message)
211
216
  {
212
217
    (void)session;
217
222
  }
218
223
 
219
224
  /* Old style cursor errors */
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);
 
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
 
224
228
public:
225
 
  virtual void print_error(int error, myf errflag, Table& table);
 
229
  virtual void print_error(int error, myf errflag, const Table& table) const;
226
230
 
227
231
  bool is_user_selectable() const
228
232
  {
252
256
  {
253
257
    return 0;
254
258
  }
 
259
 
255
260
  virtual Cursor *create(Table &)= 0;
256
261
  /* args: path */
257
262
  virtual bool flush_logs() { return false; }
276
281
protected:
277
282
  virtual int doCreateTable(Session &session,
278
283
                            Table &table_arg,
279
 
                            const drizzled::TableIdentifier &identifier,
 
284
                            const drizzled::identifier::Table &identifier,
280
285
                            message::Table &message)= 0;
281
286
 
282
287
  virtual int doRenameTable(Session &session,
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
                            const drizzled::identifier::Table &from, const drizzled::identifier::Table &to)= 0;
 
289
 
 
290
  virtual int doDropTable(Session &session,
 
291
                          const drizzled::identifier::Table &identifier)= 0;
288
292
 
289
293
  virtual void doGetTableIdentifiers(CachedDirectory &directory,
290
 
                                     const drizzled::SchemaIdentifier &schema_identifier,
291
 
                                     TableIdentifiers &set_of_identifiers)= 0;
292
 
 
293
 
  virtual int doDropTable(Session &session,
294
 
                          const drizzled::TableIdentifier &identifier)= 0;
 
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);
295
321
 
296
322
  /* Class Methods for operating on plugin */
297
323
  static bool addPlugin(plugin::StorageEngine *engine);
298
324
  static void removePlugin(plugin::StorageEngine *engine);
299
325
 
300
326
  static int getTableDefinition(Session& session,
301
 
                                const drizzled::TableIdentifier &identifier,
302
 
                                message::TablePtr &table_proto,
 
327
                                const drizzled::identifier::Table &identifier,
 
328
                                message::table::shared_ptr &table_proto,
303
329
                                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);
304
334
  static bool doesTableExist(Session &session,
305
 
                             const drizzled::TableIdentifier &identifier,
 
335
                             const drizzled::identifier::Table &identifier,
306
336
                             bool include_temporary_tables= true);
307
337
 
308
 
  virtual bool doDoesTableExist(Session& session, const drizzled::TableIdentifier &identifier);
309
 
 
310
338
  static plugin::StorageEngine *findByName(const std::string &find_str);
311
339
  static plugin::StorageEngine *findByName(Session& session, const std::string &find_str);
312
340
 
313
341
  static void closeConnection(Session* session);
314
342
  static void dropDatabase(char* path);
315
343
  static bool flushLogs(plugin::StorageEngine *db_type);
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);
 
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
 
321
356
  static void getIdentifiers(Session &session,
322
 
                             const SchemaIdentifier &schema_identifier,
323
 
                             TableIdentifiers &set_of_identifiers);
 
357
                             const identifier::Schema &schema_identifier,
 
358
                             identifier::Table::vector &set_of_identifiers);
324
359
 
325
360
  // Check to see if any SE objects to creation.
326
 
  static bool canCreateTable(const drizzled::TableIdentifier &identifier);
327
 
  virtual bool doCanCreateTable(const drizzled::TableIdentifier &identifier)
328
 
  { (void)identifier;  return true; }
 
361
  static bool canCreateTable(const drizzled::identifier::Table &identifier);
329
362
 
330
363
  // @note All schema methods defined here
331
 
  static void getIdentifiers(Session &session, SchemaIdentifiers &schemas);
332
 
  static bool getSchemaDefinition(const drizzled::TableIdentifier &identifier, message::SchemaPtr &proto);
333
 
  static bool getSchemaDefinition(const drizzled::SchemaIdentifier &identifier, message::SchemaPtr &proto);
334
 
  static bool doesSchemaExist(const drizzled::SchemaIdentifier &identifier);
335
 
  static const CHARSET_INFO *getSchemaCollation(const drizzled::SchemaIdentifier &identifier);
 
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);
336
369
  static bool createSchema(const drizzled::message::Schema &schema_message);
337
 
  static bool dropSchema(const drizzled::SchemaIdentifier &identifier);
 
370
  static bool dropSchema(drizzled::Session& session, identifier::Schema::const_reference identifier);
338
371
  static bool alterSchema(const drizzled::message::Schema &schema_message);
339
372
 
340
373
  // @note make private/protected
341
 
  virtual void doGetSchemaIdentifiers(SchemaIdentifiers&)
 
374
protected:
 
375
  virtual void doGetSchemaIdentifiers(identifier::Schema::vector&)
342
376
  { }
343
377
 
344
 
  virtual bool doGetSchemaDefinition(const drizzled::SchemaIdentifier&, drizzled::message::SchemaPtr&)
 
378
  virtual bool doGetSchemaDefinition(const drizzled::identifier::Schema&, drizzled::message::schema::shared_ptr&)
345
379
  { 
346
380
    return false; 
347
381
  }
352
386
  virtual bool doAlterSchema(const drizzled::message::Schema&)
353
387
  { return false; }
354
388
 
355
 
  virtual bool doDropSchema(const drizzled::SchemaIdentifier&)
 
389
  virtual bool doDropSchema(const drizzled::identifier::Schema&)
356
390
  { return false; }
357
391
 
 
392
public:
358
393
  static inline const std::string &resolveName(const StorageEngine *engine)
359
394
  {
360
395
    return engine == NULL ? UNKNOWN_STRING : engine->getName();
361
396
  }
362
397
 
363
 
  static int createTable(Session& session,
364
 
                         const drizzled::TableIdentifier &identifier,
365
 
                         message::Table& table_proto);
 
398
  static bool createTable(Session &session,
 
399
                          const identifier::Table &identifier,
 
400
                          message::Table& table_message);
366
401
 
367
402
  static void removeLostTemporaryTables(Session &session, const char *directory);
368
403
 
387
422
  virtual uint32_t max_supported_key_part_length(void) const { return 255; }
388
423
 
389
424
  /* TODO-> Make private */
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);
 
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);
393
429
  static bool readTableFile(const std::string &path, message::Table &table_message);
394
430
 
395
431
public:
427
463
  }
428
464
};
429
465
 
 
466
std::ostream& operator<<(std::ostream& output, const StorageEngine &engine);
 
467
 
430
468
} /* namespace plugin */
431
469
} /* namespace drizzled */
432
470