~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table/instance/base.h

  • Committer: Monty Taylor
  • Date: 2011-01-26 19:15:55 UTC
  • mto: This revision was merged to the branch mainline in revision 2126.
  • Revision ID: mordred@inaugust.com-20110126191555-nq5nnzyscvngsip2
Turns on -fvisibility=hidden by default. Symbols intended to be used by
plugins need to be marked with DRIZZLED_API.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
  instance of table share per one table in the database.
24
24
*/
25
25
 
26
 
#pragma once
 
26
#ifndef DRIZZLED_TABLE_INSTANCE_BASE_H
 
27
#define DRIZZLED_TABLE_INSTANCE_BASE_H
27
28
 
28
29
#include <string>
29
30
 
31
32
#include <boost/thread/condition_variable.hpp>
32
33
#include <boost/dynamic_bitset.hpp>
33
34
#include <boost/shared_ptr.hpp>
34
 
#include <boost/scoped_ptr.hpp>
35
 
 
36
 
#include <drizzled/memory/root.h>
37
 
#include <drizzled/message.h>
38
 
#include <drizzled/util/string.h>
39
 
#include <drizzled/lex_string.h>
40
 
#include <drizzled/key_map.h>
 
35
 
 
36
#include "drizzled/typelib.h"
 
37
#include "drizzled/memory/root.h"
 
38
#include "drizzled/message/table.pb.h"
 
39
#include "drizzled/util/string.h"
 
40
 
 
41
#include "drizzled/lex_string.h"
 
42
#include "drizzled/key_map.h"
 
43
 
 
44
#include "drizzled/table/cache.h"
 
45
 
41
46
#include <drizzled/field.h>
42
47
 
43
 
namespace drizzled {
44
 
 
 
48
 
 
49
namespace drizzled
 
50
{
 
51
 
 
52
extern uint64_t refresh_version;
 
53
 
 
54
const static std::string STANDARD_STRING("STANDARD");
 
55
const static std::string TEMPORARY_STRING("TEMPORARY");
 
56
const static std::string INTERNAL_STRING("INTERNAL");
 
57
const static std::string FUNCTION_STRING("FUNCTION");
45
58
const static std::string NO_PROTOBUFFER_AVAILABLE("NO PROTOBUFFER AVAILABLE");
46
59
 
 
60
namespace plugin
 
61
{
 
62
class EventObserverList;
 
63
class StorageEngine;
 
64
}
 
65
 
 
66
namespace table {
 
67
class Singular;
 
68
}
 
69
 
 
70
class Field_blob;
 
71
 
47
72
class TableShare
48
73
{
49
74
  typedef std::vector<std::string> StringVector;
81
106
 
82
107
  /* The following is copied to each Table on OPEN */
83
108
  typedef std::vector<Field *> Fields;
84
 
 
85
109
private:
86
110
  Fields _fields;
87
111
 
117
141
    _fields.push_back(arg);
118
142
  }
119
143
 
 
144
 
120
145
  Field **found_next_number_field;
121
 
 
122
146
private:
123
147
  Field *timestamp_field;               /* Used only during open */
124
 
 
125
148
public:
126
149
 
127
150
  Field *getTimestampField() const               /* Used only during open */
137
160
 
138
161
private:
139
162
  KeyInfo  *key_info;                   /* data of keys in database */
140
 
 
141
163
public:
142
164
  KeyInfo &getKeyInfo(uint32_t arg) const
143
165
  {
145
167
  }
146
168
  std::vector<uint>     blob_field;                     /* Index to blobs in Field arrray*/
147
169
 
148
 
private:
149
170
  /* hash of field names (contains pointers to elements of field array) */
 
171
private:
150
172
  typedef boost::unordered_map < std::string, Field **, util::insensitive_hash, util::insensitive_equal_to> FieldMap;
151
173
  typedef std::pair< std::string, Field ** > FieldMapPair;
152
174
  FieldMap name_hash; /* hash of field names */
153
 
 
154
175
public:
155
176
  size_t getNamedFieldSize() const
156
177
  {
164
185
    if (iter == name_hash.end())
165
186
        return 0;
166
187
 
167
 
    return iter->second;
 
188
    return (*iter).second;
168
189
  }
169
190
 
170
191
private:
263
284
  LEX_STRING table_name;                /* Table name (for open) */
264
285
  LEX_STRING path;      /* Path to table (from datadir) */
265
286
  LEX_STRING normalized_path;           /* unpack_filename(path) */
266
 
 
267
287
public:
268
288
 
269
289
  const char *getNormalizedPath() const
299
319
    normalized_path.str= str_arg;
300
320
    normalized_path.length= size_arg;
301
321
  }
302
 
 
303
322
public:
304
323
 
305
324
  const char *getTableName() const
337
356
 
338
357
private:
339
358
  uint64_t   version;
340
 
 
341
359
public:
342
360
  uint64_t getVersion() const
343
361
  {
344
362
    return version;
345
363
  }
346
364
 
347
 
  void refreshVersion();
 
365
  void refreshVersion()
 
366
  {
 
367
   version= refresh_version;
 
368
  }
348
369
 
349
370
  void resetVersion()
350
371
  {
351
372
    version= 0;
352
373
  }
353
374
 
354
 
private:
355
375
  uint32_t   timestamp_offset;          /* Set to offset+1 of record */
356
 
 
357
 
  uint32_t reclength;                   /* Recordlength */
358
 
  uint32_t stored_rec_length;         /* Stored record length*/
359
 
 
 
376
private:
 
377
  uint32_t   reclength;                 /* Recordlength */
360
378
public:
361
 
  uint32_t sizeStoredRecord() const
362
 
  {
363
 
    return stored_rec_length;
364
 
  }
 
379
  uint32_t   stored_rec_length;         /* Stored record length*/
365
380
 
366
381
  uint32_t getRecordLength() const
367
382
  {
385
400
  /* Max rows is a hint to HEAP during a create tmp table */
386
401
  uint64_t max_rows;
387
402
 
388
 
  boost::scoped_ptr<message::Table> _table_message;
389
 
 
 
403
  message::Table *table_proto;
390
404
public:
 
405
 
391
406
  /*
392
 
    @note Without a _table_message, we assume we are building a STANDARD table.
 
407
    @note Without a table_proto, we assume we are building a STANDARD table.
393
408
    This will be modified once we use Identifiers in the Share itself.
394
409
  */
395
410
  message::Table::TableType getTableType() const
396
411
  {
397
 
    return getTableMessage() ? getTableMessage()->type() : message::Table::STANDARD;
 
412
    return table_proto ? table_proto->type() : message::Table::STANDARD;
398
413
  }
399
414
 
400
415
  const std::string &getTableTypeAsString() const
401
416
  {
402
 
    if (getTableMessage())
403
 
      return message::type(getTableMessage()->type());
404
 
 
405
 
    return NO_PROTOBUFFER_AVAILABLE;
 
417
    if (table_proto)
 
418
    {
 
419
      switch (table_proto->type())
 
420
      {
 
421
      default:
 
422
      case message::Table::STANDARD:
 
423
        return STANDARD_STRING;
 
424
      case message::Table::TEMPORARY:
 
425
        return TEMPORARY_STRING;
 
426
      case message::Table::INTERNAL:
 
427
        return INTERNAL_STRING;
 
428
      case message::Table::FUNCTION:
 
429
        return FUNCTION_STRING;
 
430
      }
 
431
    }
 
432
    else
 
433
    {
 
434
      return NO_PROTOBUFFER_AVAILABLE;
 
435
    }
406
436
  }
407
437
 
408
438
  /* This is only used in one location currently */
409
 
  inline message::Table *getTableMessage() const
410
 
  {
411
 
    return _table_message.get();
412
 
  }
413
 
 
414
 
  void setTableMessage(const message::Table &arg)
415
 
  {
416
 
    assert(not getTableMessage());
417
 
    _table_message.reset(new message::Table(arg));
 
439
  inline message::Table *getTableProto() const
 
440
  {
 
441
    return table_proto;
418
442
  }
419
443
 
420
444
  const message::Table::Field &field(int32_t field_position) const
421
445
  {
422
 
    assert(getTableMessage());
423
 
    return getTableMessage()->field(field_position);
 
446
    assert(table_proto);
 
447
    return table_proto->field(field_position);
 
448
  }
 
449
 
 
450
  inline void setTableProto(message::Table *arg)
 
451
  {
 
452
    assert(table_proto == NULL);
 
453
    table_proto= arg;
424
454
  }
425
455
 
426
456
  inline bool hasComment() const
427
457
  {
428
 
    return getTableMessage() ?  getTableMessage()->options().has_comment() : false; 
 
458
    return (table_proto) ?  table_proto->options().has_comment() : false; 
429
459
  }
430
460
 
431
461
  inline const char *getComment()
432
462
  {
433
 
    return (getTableMessage() && getTableMessage()->has_options()) ?  getTableMessage()->options().comment().c_str() : NULL; 
 
463
    return (table_proto && table_proto->has_options()) ?  table_proto->options().comment().c_str() : NULL; 
434
464
  }
435
465
 
436
466
  inline uint32_t getCommentLength() const
437
467
  {
438
 
    return (getTableMessage()) ? getTableMessage()->options().comment().length() : 0; 
 
468
    return (table_proto) ? table_proto->options().comment().length() : 0; 
439
469
  }
440
470
 
441
471
  inline uint64_t getMaxRows() const
524
554
  uint32_t blob_fields;                 /* number of blob fields */
525
555
private:
526
556
  bool has_variable_width;                  /* number of varchar fields */
527
 
 
528
557
public:
529
558
  bool hasVariableWidth() const
530
559
  {
567
596
  uint32_t next_number_keypart;             /* autoinc keypart number in a key */
568
597
  uint32_t error, open_errno, errarg;       /* error from open_table_def() */
569
598
 
570
 
private:
571
599
  uint8_t blob_ptr_size;                        /* 4 or 8 */
572
 
 
573
 
public:
574
 
  uint8_t sizeBlobPtr() const
575
 
  {
576
 
    return blob_ptr_size;
577
 
  }
578
 
 
579
600
  bool db_low_byte_first;               /* Portable row format */
580
601
 
581
602
  /*
589
610
    event_observers is a class containing all the event plugins that have 
590
611
    registered an interest in this table.
591
612
  */
592
 
  virtual plugin::EventObserverList *getTableObservers() 
 
613
  private:
 
614
  plugin::EventObserverList *event_observers;
 
615
  public:
 
616
  plugin::EventObserverList *getTableObservers() 
593
617
  { 
594
 
    return NULL;
 
618
    return event_observers;
595
619
  }
596
620
  
597
 
  virtual void setTableObservers(plugin::EventObserverList *) 
598
 
  { }
 
621
  void setTableObservers(plugin::EventObserverList *observers) 
 
622
  { 
 
623
    event_observers= observers;
 
624
  }
599
625
  
600
626
  /*
601
627
    Set share's identifier information.
627
653
private:
628
654
  void init(const char *new_table_name,
629
655
            const char *new_path);
 
656
public:
630
657
 
631
 
protected:
632
658
  void open_table_error(int pass_error, int db_errno, int pass_errarg);
633
659
 
634
 
public:
635
 
 
636
660
  static TableShare::shared_ptr getShareCreate(Session *session, 
637
661
                                               const identifier::Table &identifier,
638
662
                                               int &error);
700
724
                              Table &outparam,
701
725
                              bool &error_reported);
702
726
public:
703
 
  bool parse_table_proto(Session& session, const message::Table &table);
 
727
  int parse_table_proto(Session& session, message::Table &table);
704
728
 
705
 
  virtual bool is_replicated() const
706
 
  {
707
 
    return false;
708
 
  }
 
729
private:
 
730
  int inner_parse_table_proto(Session& session, message::Table &table);
709
731
};
710
732
 
711
733
} /* namespace drizzled */
712
734
 
 
735
#endif /* DRIZZLED_TABLE_INSTANCE_BASE_H */