~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/identifier/table.h

  • Committer: Brian Aker
  • Date: 2010-10-19 08:17:10 UTC
  • mto: (1864.2.1 merge)
  • mto: This revision was merged to the branch mainline in revision 1864.
  • Revision ID: brian@tangent.org-20101019081710-hw13j03145h13pdg
Merge in a bit more strictness around table type.

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
{
59
59
public:
60
60
  typedef message::Table::TableType Type;
61
 
  typedef std::vector <TableIdentifier> vector;
62
 
  typedef const TableIdentifier& const_reference;
63
 
  typedef TableIdentifier& reference;
64
 
 
65
 
  class Key
66
 
  {
67
 
    std::vector<char> key_buffer;
68
 
    size_t hash_value;
69
 
 
70
 
  public:
71
 
 
72
 
    Key() :
73
 
      hash_value(0)
74
 
    {
75
 
    }
76
 
 
77
 
    const char *vector() const
78
 
    {
79
 
      return &key_buffer[0];
80
 
    }
81
 
 
82
 
    std::vector<char> &vectorPtr()
83
 
    {
84
 
      return key_buffer;
85
 
    }
86
 
 
87
 
    void set(size_t resize_arg, const std::string &a, const std::string &b);
88
 
 
89
 
    friend bool operator==(const Key &left, const Key &right)
90
 
    {
91
 
      if (left.hash_value == right.hash_value and left.key_buffer.size() == right.key_buffer.size())
92
 
      {
93
 
        if (memcmp(&left.key_buffer[0], &right.key_buffer[0], left.key_buffer.size()) == 0)
94
 
          return true;
95
 
      }
96
 
 
97
 
      return false;
98
 
    }
99
 
 
100
 
    friend bool operator<(const Key &left, const Key &right)
101
 
    {
102
 
      return left.key_buffer < right.key_buffer;
103
 
    }
104
 
 
105
 
    size_t size() const
106
 
    {
107
 
      return key_buffer.size();
108
 
    }
109
 
 
110
 
    size_t getHashValue() const
111
 
    {
112
 
      return hash_value;
113
 
    }
114
 
  };
115
 
 
 
61
  typedef std::vector<char> Key;
116
62
private:
117
63
 
118
64
  Type type;
119
65
  std::string path;
120
66
  std::string table_name;
 
67
  std::string sql_path;
121
68
  Key key;
122
69
  size_t hash_value;
123
70
 
197
144
    return type;
198
145
  }
199
146
 
200
 
  virtual void getSQLPath(std::string &sql_path) const;
 
147
  const std::string &getSQLPath();
201
148
 
202
 
  virtual const std::string &getPath() const;
 
149
  const std::string &getPath() const;
203
150
 
204
151
  void setPath(const std::string &new_path)
205
152
  {
213
160
 
214
161
  void copyToTableMessage(message::Table &message) const;
215
162
 
216
 
  friend bool operator<(TableIdentifier::const_reference left, TableIdentifier::const_reference right)
 
163
  friend bool operator<(const TableIdentifier &left, const TableIdentifier &right)
217
164
  {
218
165
    if (left.getKey() < right.getKey())
219
166
    {
223
170
    return false;
224
171
  }
225
172
 
226
 
  friend std::ostream& operator<<(std::ostream& output, TableIdentifier::const_reference identifier)
 
173
  friend std::ostream& operator<<(std::ostream& output, const TableIdentifier &identifier)
227
174
  {
228
175
    const char *type_str;
229
176
 
258
205
    return output;  // for multiple << operators.
259
206
  }
260
207
 
261
 
  friend bool operator==(TableIdentifier::const_reference left, TableIdentifier::const_reference right)
 
208
  friend bool operator==(TableIdentifier &left, TableIdentifier &right)
262
209
  {
263
210
    if (left.getHashValue() == right.getHashValue())
264
211
    {
270
217
  }
271
218
 
272
219
  static uint32_t filename_to_tablename(const char *from, char *to, uint32_t to_length);
273
 
  static size_t build_table_filename(std::string &path, const std::string &db, const std::string &table_name, bool is_tmp);
 
220
  static size_t build_table_filename(std::string &buff, const char *db, const char *table_name, bool is_tmp);
274
221
  static size_t build_tmptable_filename(std::string &buffer);
275
222
  static size_t build_tmptable_filename(std::vector<char> &buffer);
276
223
 
277
 
public:
278
 
  bool isValid() const;
 
224
  /*
 
225
    Create a table cache key
 
226
 
 
227
    SYNOPSIS
 
228
    createKey()
 
229
    key                 Create key here (must be of size MAX_DBKEY_LENGTH)
 
230
    table_list          Table definition
 
231
 
 
232
    IMPLEMENTATION
 
233
    The table cache_key is created from:
 
234
    db_name + \0
 
235
    table_name + \0
 
236
 
 
237
    if the table is a tmp table, we add the following to make each tmp table
 
238
    unique on the slave:
 
239
 
 
240
    4 bytes for master thread id
 
241
    4 bytes pseudo thread id
 
242
 
 
243
    RETURN
 
244
    Length of key
 
245
  */
 
246
  static uint32_t createKey(char *key, const char *db_arg, const char *table_name_arg)
 
247
  {
 
248
    uint32_t key_length;
 
249
    char *key_pos= key;
 
250
 
 
251
    key_pos= strcpy(key_pos, db_arg) + strlen(db_arg);
 
252
    key_pos= strcpy(key_pos+1, table_name_arg) +
 
253
      strlen(table_name_arg);
 
254
    key_length= (uint32_t)(key_pos-key)+1;
 
255
 
 
256
    return key_length;
 
257
  }
 
258
 
 
259
  static uint32_t createKey(char *key, const TableIdentifier &identifier)
 
260
  {
 
261
    uint32_t key_length;
 
262
    char *key_pos= key;
 
263
 
 
264
    key_pos= strcpy(key_pos, identifier.getSchemaName().c_str()) + identifier.getSchemaName().length();
 
265
    key_pos= strcpy(key_pos + 1, identifier.getTableName().c_str()) + identifier.getTableName().length();
 
266
    key_length= (uint32_t)(key_pos-key)+1;
 
267
 
 
268
    return key_length;
 
269
  }
279
270
 
280
271
  size_t getHashValue() const
281
272
  {
289
280
};
290
281
 
291
282
std::size_t hash_value(TableIdentifier const& b);
292
 
std::size_t hash_value(TableIdentifier::Key const& b);
 
283
 
 
284
typedef std::vector <TableIdentifier> TableIdentifiers;
293
285
 
294
286
} /* namespace drizzled */
295
287