~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/storage_engine.h

  • Committer: Marisa Plumb
  • Date: 2010-12-04 02:38:29 UTC
  • mto: This revision was merged to the branch mainline in revision 1984.
  • Revision ID: marisa.plumb@gmail.com-20101204023829-2khzxh30wxi256db
updates to a few sql docs 

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
27
#include <drizzled/message.h>
30
28
#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>
 
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
255
  virtual Cursor *create(Table &)= 0;
261
256
  /* args: path */
262
257
  virtual bool flush_logs() { return false; }
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
 
  static message::table::shared_ptr getTableMessage(Session& session,
327
 
                                                    const drizzled::identifier::Table &identifier,
328
 
                                                    bool include_temporary_tables= true);
 
300
  static int getTableDefinition(Session& session,
 
301
                                const drizzled::TableIdentifier &identifier,
 
302
                                message::table::shared_ptr &table_proto,
 
303
                                bool include_temporary_tables= true);
329
304
  static bool doesTableExist(Session &session,
330
 
                             const drizzled::identifier::Table &identifier,
 
305
                             const drizzled::TableIdentifier &identifier,
331
306
                             bool include_temporary_tables= true);
332
307
 
 
308
  virtual bool doDoesTableExist(Session& session, const drizzled::TableIdentifier &identifier);
 
309
 
333
310
  static plugin::StorageEngine *findByName(const std::string &find_str);
334
311
  static plugin::StorageEngine *findByName(Session& session, const std::string &find_str);
335
312
 
336
313
  static void closeConnection(Session* session);
337
314
  static void dropDatabase(char* path);
338
315
  static bool flushLogs(plugin::StorageEngine *db_type);
339
 
 
340
 
  static bool dropTable(Session& session,
341
 
                        const drizzled::identifier::Table &identifier);
342
 
  static bool dropTable(Session& session,
343
 
                        const drizzled::identifier::Table &identifier,
344
 
                        drizzled::error_t &error);
345
 
 
346
 
  static bool dropTable(Session& session,
347
 
                        StorageEngine &engine,
348
 
                        identifier::Table::const_reference identifier,
349
 
                        drizzled::error_t &error);
350
 
 
 
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);
351
321
  static void getIdentifiers(Session &session,
352
 
                             const identifier::Schema &schema_identifier,
353
 
                             identifier::Table::vector &set_of_identifiers);
 
322
                             const SchemaIdentifier &schema_identifier,
 
323
                             TableIdentifiers &set_of_identifiers);
354
324
 
355
325
  // Check to see if any SE objects to creation.
356
 
  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; }
357
329
 
358
330
  // @note All schema methods defined here
359
 
  static void getIdentifiers(Session &session, identifier::Schema::vector &schemas);
360
 
  static message::schema::shared_ptr getSchemaDefinition(const drizzled::identifier::Table &identifier);
361
 
  static message::schema::shared_ptr getSchemaDefinition(const drizzled::identifier::Schema &identifier);
362
 
  static bool doesSchemaExist(const drizzled::identifier::Schema &identifier);
363
 
  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::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
336
  static bool createSchema(const drizzled::message::Schema &schema_message);
365
 
  static bool dropSchema(Session &session,
366
 
                         identifier::Schema::const_reference identifier,
367
 
                         message::schema::const_reference schema_message);
 
337
  static bool dropSchema(const drizzled::SchemaIdentifier &identifier);
368
338
  static bool alterSchema(const drizzled::message::Schema &schema_message);
369
339
 
370
340
  // @note make private/protected
371
 
protected:
372
 
  virtual void doGetSchemaIdentifiers(identifier::Schema::vector&)
 
341
  virtual void doGetSchemaIdentifiers(SchemaIdentifiers&)
373
342
  { }
374
343
 
375
 
  virtual drizzled::message::schema::shared_ptr doGetSchemaDefinition(const drizzled::identifier::Schema&)
 
344
  virtual bool doGetSchemaDefinition(const drizzled::SchemaIdentifier&, drizzled::message::SchemaPtr&)
376
345
  { 
377
 
    return drizzled::message::schema::shared_ptr(); 
 
346
    return false; 
378
347
  }
379
348
 
380
349
  virtual bool doCreateSchema(const drizzled::message::Schema&)
383
352
  virtual bool doAlterSchema(const drizzled::message::Schema&)
384
353
  { return false; }
385
354
 
386
 
  virtual bool doDropSchema(const drizzled::identifier::Schema&)
 
355
  virtual bool doDropSchema(const drizzled::SchemaIdentifier&)
387
356
  { return false; }
388
357
 
389
 
public:
390
358
  static inline const std::string &resolveName(const StorageEngine *engine)
391
359
  {
392
360
    return engine == NULL ? UNKNOWN_STRING : engine->getName();
393
361
  }
394
362
 
395
 
  static bool createTable(Session &session,
396
 
                          const identifier::Table &identifier,
397
 
                          message::Table& table_message);
 
363
  static int createTable(Session& session,
 
364
                         const drizzled::TableIdentifier &identifier,
 
365
                         message::Table& table_proto);
398
366
 
399
367
  static void removeLostTemporaryTables(Session &session, const char *directory);
400
368
 
401
369
  Cursor *getCursor(Table &share);
402
370
 
403
371
  uint32_t max_record_length() const
404
 
  { return std::min(HA_MAX_REC_LENGTH, max_supported_record_length()); }
 
372
  { return std::min((unsigned int)HA_MAX_REC_LENGTH, max_supported_record_length()); }
405
373
  uint32_t max_keys() const
406
 
  { return std::min(MAX_KEY, max_supported_keys()); }
 
374
  { return std::min((unsigned int)MAX_KEY, max_supported_keys()); }
407
375
  uint32_t max_key_parts() const
408
 
  { return std::min(MAX_REF_PARTS, max_supported_key_parts()); }
 
376
  { return std::min((unsigned int)MAX_REF_PARTS, max_supported_key_parts()); }
409
377
  uint32_t max_key_length() const
410
 
  { return std::min(MAX_KEY_LENGTH, max_supported_key_length()); }
 
378
  { return std::min((unsigned int)MAX_KEY_LENGTH, max_supported_key_length()); }
411
379
  uint32_t max_key_part_length(void) const
412
 
  { return std::min(MAX_KEY_LENGTH, max_supported_key_part_length()); }
 
380
  { return std::min((unsigned int)MAX_KEY_LENGTH, max_supported_key_part_length()); }
413
381
 
414
382
  virtual uint32_t max_supported_record_length(void) const
415
383
  { return HA_MAX_REC_LENGTH; }
419
387
  virtual uint32_t max_supported_key_part_length(void) const { return 255; }
420
388
 
421
389
  /* TODO-> Make private */
422
 
protected:
423
 
  static int deleteDefinitionFromPath(const drizzled::identifier::Table &identifier);
424
 
  static int renameDefinitionFromPath(const drizzled::identifier::Table &dest, const drizzled::identifier::Table &src);
425
 
  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);
426
393
  static bool readTableFile(const std::string &path, message::Table &table_message);
427
394
 
428
395
public:
460
427
  }
461
428
};
462
429
 
463
 
std::ostream& operator<<(std::ostream& output, const StorageEngine &engine);
464
 
 
465
430
} /* namespace plugin */
466
431
} /* namespace drizzled */
467
432