~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

edit

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include <boost/thread/condition_variable.hpp>
33
33
#include <boost/dynamic_bitset.hpp>
34
34
#include <boost/shared_ptr.hpp>
35
 
#include <boost/scoped_ptr.hpp>
36
 
 
37
 
#include <drizzled/memory/root.h>
38
 
#include <drizzled/message.h>
39
 
#include <drizzled/util/string.h>
40
 
 
41
 
#include <drizzled/lex_string.h>
42
 
#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
43
 
44
 
#include <drizzled/table/cache.h>
 
44
#include "drizzled/table/cache.h"
45
45
 
46
46
#include <drizzled/field.h>
47
47
 
49
49
namespace drizzled
50
50
{
51
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");
52
58
const static std::string NO_PROTOBUFFER_AVAILABLE("NO PROTOBUFFER AVAILABLE");
53
59
 
54
60
namespace plugin
100
106
 
101
107
  /* The following is copied to each Table on OPEN */
102
108
  typedef std::vector<Field *> Fields;
103
 
 
104
109
private:
105
110
  Fields _fields;
106
111
 
136
141
    _fields.push_back(arg);
137
142
  }
138
143
 
 
144
 
139
145
  Field **found_next_number_field;
140
 
 
141
146
private:
142
147
  Field *timestamp_field;               /* Used only during open */
143
 
 
144
148
public:
145
149
 
146
150
  Field *getTimestampField() const               /* Used only during open */
156
160
 
157
161
private:
158
162
  KeyInfo  *key_info;                   /* data of keys in database */
159
 
 
160
163
public:
161
164
  KeyInfo &getKeyInfo(uint32_t arg) const
162
165
  {
164
167
  }
165
168
  std::vector<uint>     blob_field;                     /* Index to blobs in Field arrray*/
166
169
 
167
 
private:
168
170
  /* hash of field names (contains pointers to elements of field array) */
 
171
private:
169
172
  typedef boost::unordered_map < std::string, Field **, util::insensitive_hash, util::insensitive_equal_to> FieldMap;
170
173
  typedef std::pair< std::string, Field ** > FieldMapPair;
171
174
  FieldMap name_hash; /* hash of field names */
172
 
 
173
175
public:
174
176
  size_t getNamedFieldSize() const
175
177
  {
282
284
  LEX_STRING table_name;                /* Table name (for open) */
283
285
  LEX_STRING path;      /* Path to table (from datadir) */
284
286
  LEX_STRING normalized_path;           /* unpack_filename(path) */
285
 
 
286
287
public:
287
288
 
288
289
  const char *getNormalizedPath() const
318
319
    normalized_path.str= str_arg;
319
320
    normalized_path.length= size_arg;
320
321
  }
321
 
 
322
322
public:
323
323
 
324
324
  const char *getTableName() const
356
356
 
357
357
private:
358
358
  uint64_t   version;
359
 
 
360
359
public:
361
360
  uint64_t getVersion() const
362
361
  {
363
362
    return version;
364
363
  }
365
364
 
366
 
  void refreshVersion();
 
365
  void refreshVersion()
 
366
  {
 
367
   version= refresh_version;
 
368
  }
367
369
 
368
370
  void resetVersion()
369
371
  {
370
372
    version= 0;
371
373
  }
372
374
 
373
 
private:
374
375
  uint32_t   timestamp_offset;          /* Set to offset+1 of record */
375
 
 
376
 
  uint32_t reclength;                   /* Recordlength */
377
 
  uint32_t stored_rec_length;         /* Stored record length*/
378
 
 
 
376
private:
 
377
  uint32_t   reclength;                 /* Recordlength */
379
378
public:
380
 
  uint32_t sizeStoredRecord() const
381
 
  {
382
 
    return stored_rec_length;
383
 
  }
 
379
  uint32_t   stored_rec_length;         /* Stored record length*/
384
380
 
385
381
  uint32_t getRecordLength() const
386
382
  {
404
400
  /* Max rows is a hint to HEAP during a create tmp table */
405
401
  uint64_t max_rows;
406
402
 
407
 
  boost::scoped_ptr<message::Table> _table_message;
408
 
 
 
403
  message::Table *table_proto;
409
404
public:
 
405
 
410
406
  /*
411
 
    @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.
412
408
    This will be modified once we use Identifiers in the Share itself.
413
409
  */
414
410
  message::Table::TableType getTableType() const
415
411
  {
416
 
    return getTableMessage() ? getTableMessage()->type() : message::Table::STANDARD;
 
412
    return table_proto ? table_proto->type() : message::Table::STANDARD;
417
413
  }
418
414
 
419
415
  const std::string &getTableTypeAsString() const
420
416
  {
421
 
    if (getTableMessage())
422
 
      return message::type(getTableMessage()->type());
423
 
 
424
 
    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
    }
425
436
  }
426
437
 
427
438
  /* This is only used in one location currently */
428
 
  inline message::Table *getTableMessage() const
429
 
  {
430
 
    return _table_message.get();
431
 
  }
432
 
 
433
 
  void setTableMessage(const message::Table &arg)
434
 
  {
435
 
    assert(not getTableMessage());
436
 
    _table_message.reset(new(std::nothrow) message::Table(arg));
 
439
  inline message::Table *getTableProto() const
 
440
  {
 
441
    return table_proto;
437
442
  }
438
443
 
439
444
  const message::Table::Field &field(int32_t field_position) const
440
445
  {
441
 
    assert(getTableMessage());
442
 
    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;
443
454
  }
444
455
 
445
456
  inline bool hasComment() const
446
457
  {
447
 
    return (getTableMessage()) ?  getTableMessage()->options().has_comment() : false; 
 
458
    return (table_proto) ?  table_proto->options().has_comment() : false; 
448
459
  }
449
460
 
450
461
  inline const char *getComment()
451
462
  {
452
 
    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; 
453
464
  }
454
465
 
455
466
  inline uint32_t getCommentLength() const
456
467
  {
457
 
    return (getTableMessage()) ? getTableMessage()->options().comment().length() : 0; 
 
468
    return (table_proto) ? table_proto->options().comment().length() : 0; 
458
469
  }
459
470
 
460
471
  inline uint64_t getMaxRows() const
543
554
  uint32_t blob_fields;                 /* number of blob fields */
544
555
private:
545
556
  bool has_variable_width;                  /* number of varchar fields */
546
 
 
547
557
public:
548
558
  bool hasVariableWidth() const
549
559
  {
586
596
  uint32_t next_number_keypart;             /* autoinc keypart number in a key */
587
597
  uint32_t error, open_errno, errarg;       /* error from open_table_def() */
588
598
 
589
 
private:
590
599
  uint8_t blob_ptr_size;                        /* 4 or 8 */
591
 
 
592
 
public:
593
 
  uint8_t sizeBlobPtr() const
594
 
  {
595
 
    return blob_ptr_size;
596
 
  }
597
 
 
598
600
  bool db_low_byte_first;               /* Portable row format */
599
601
 
600
602
  /*
608
610
    event_observers is a class containing all the event plugins that have 
609
611
    registered an interest in this table.
610
612
  */
611
 
  virtual plugin::EventObserverList *getTableObservers() 
 
613
  private:
 
614
  plugin::EventObserverList *event_observers;
 
615
  public:
 
616
  plugin::EventObserverList *getTableObservers() 
612
617
  { 
613
 
    return NULL;
 
618
    return event_observers;
614
619
  }
615
620
  
616
 
  virtual void setTableObservers(plugin::EventObserverList *) 
617
 
  { }
 
621
  void setTableObservers(plugin::EventObserverList *observers) 
 
622
  { 
 
623
    event_observers= observers;
 
624
  }
618
625
  
619
626
  /*
620
627
    Set share's identifier information.
646
653
private:
647
654
  void init(const char *new_table_name,
648
655
            const char *new_path);
 
656
public:
649
657
 
650
 
protected:
651
658
  void open_table_error(int pass_error, int db_errno, int pass_errarg);
652
659
 
653
 
public:
654
 
 
655
660
  static TableShare::shared_ptr getShareCreate(Session *session, 
656
661
                                               const identifier::Table &identifier,
657
662
                                               int &error);
719
724
                              Table &outparam,
720
725
                              bool &error_reported);
721
726
public:
722
 
  bool parse_table_proto(Session& session, message::Table &table);
 
727
  int parse_table_proto(Session& session, message::Table &table);
723
728
 
724
 
  virtual bool replicate() const
725
 
  {
726
 
    return false;
727
 
  }
 
729
private:
 
730
  int inner_parse_table_proto(Session& session, message::Table &table);
728
731
};
729
732
 
730
733
} /* namespace drizzled */