~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/identifier/table.h

  • Committer: Brian Aker
  • Date: 2010-10-28 17:12:01 UTC
  • mfrom: (1887.1.3 merge)
  • Revision ID: brian@tangent.org-20101028171201-baj6l1bnntn1s4ad
Merge in POTFILES changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
4
 *  Copyright (C) 2010 Brian Aker
5
 
 *  Copyright (C) 2009 Sun Microsystems, Inc.
 
5
 *  Copyright (C) 2009 Sun Microsystems
6
6
 *
7
7
 *  This program is free software; you can redistribute it and/or modify
8
8
 *  it under the terms of the GNU General Public License as published by
37
37
#include "drizzled/definitions.h"
38
38
#include "drizzled/message/table.pb.h"
39
39
 
 
40
#include "drizzled/identifier.h"
 
41
 
40
42
#include <string.h>
41
43
 
42
44
#include <assert.h>
48
50
 
49
51
#include <boost/functional/hash.hpp>
50
52
 
51
 
#include "drizzled/visibility.h"
52
 
 
53
53
namespace drizzled {
 
54
 
54
55
class Table;
55
56
 
56
 
namespace identifier {
57
 
 
58
 
class DRIZZLED_API Table : public Schema
 
57
class TableIdentifier : public SchemaIdentifier
59
58
{
60
59
public:
61
60
  typedef message::Table::TableType Type;
62
 
  typedef std::vector <Table> vector;
63
 
  typedef const Table& const_reference;
64
 
  typedef Table& reference;
65
61
 
66
62
  class Key
67
63
  {
118
114
 
119
115
  Type type;
120
116
  std::string path;
121
 
  std::string key_path;
122
117
  std::string table_name;
 
118
  std::string sql_path;
123
119
  Key key;
124
120
  size_t hash_value;
125
121
 
131
127
  }
132
128
 
133
129
public:
134
 
 
135
 
  Table(const drizzled::Table &table);
 
130
  TableIdentifier(const Table &table);
136
131
                   
137
 
  Table(const identifier::Schema &schema,
138
 
        const std::string &table_name_arg,
139
 
        Type tmp_arg= message::Table::STANDARD) :
140
 
    Schema(schema),
141
 
    type(tmp_arg),
142
 
    table_name(table_name_arg)
143
 
  { 
144
 
    init();
145
 
  }
146
 
 
147
 
  Table( const std::string &db_arg,
148
 
                   const std::string &table_name_arg,
149
 
                   Type tmp_arg= message::Table::STANDARD) :
150
 
    Schema(db_arg),
151
 
    type(tmp_arg),
152
 
    table_name(table_name_arg)
153
 
  { 
154
 
    init();
155
 
  }
156
 
 
157
 
  Table( const std::string &schema_name_arg,
 
132
  TableIdentifier( const SchemaIdentifier &schema,
 
133
                   const std::string &table_name_arg,
 
134
                   Type tmp_arg= message::Table::STANDARD) :
 
135
    SchemaIdentifier(schema),
 
136
    type(tmp_arg),
 
137
    table_name(table_name_arg)
 
138
  { 
 
139
    init();
 
140
  }
 
141
 
 
142
  TableIdentifier( const std::string &db_arg,
 
143
                   const std::string &table_name_arg,
 
144
                   Type tmp_arg= message::Table::STANDARD) :
 
145
    SchemaIdentifier(db_arg),
 
146
    type(tmp_arg),
 
147
    table_name(table_name_arg)
 
148
  { 
 
149
    init();
 
150
  }
 
151
 
 
152
  TableIdentifier( const std::string &schema_name_arg,
158
153
                   const std::string &table_name_arg,
159
154
                   const std::string &path_arg ) :
160
 
    Schema(schema_name_arg),
 
155
    SchemaIdentifier(schema_name_arg),
161
156
    type(message::Table::TEMPORARY),
162
157
    path(path_arg),
163
158
    table_name(table_name_arg)
165
160
    init();
166
161
  }
167
162
 
168
 
  using Schema::compare;
 
163
  using SchemaIdentifier::compare;
169
164
 
170
165
  bool isTmp() const
171
166
  {
172
167
    if (type == message::Table::TEMPORARY || type == message::Table::INTERNAL)
173
168
      return true;
174
 
 
175
169
    return false;
176
170
  }
177
171
 
201
195
    return type;
202
196
  }
203
197
 
204
 
  virtual void getSQLPath(std::string &sql_path) const;
 
198
  const std::string &getSQLPath();
205
199
 
206
 
  virtual const std::string &getPath() const;
207
 
  const std::string &getKeyPath() const;
 
200
  const std::string &getPath() const;
208
201
 
209
202
  void setPath(const std::string &new_path)
210
203
  {
218
211
 
219
212
  void copyToTableMessage(message::Table &message) const;
220
213
 
221
 
  friend bool operator<(Table::const_reference left, Table::const_reference right)
 
214
  friend bool operator<(const TableIdentifier &left, const TableIdentifier &right)
222
215
  {
223
216
    if (left.getKey() < right.getKey())
224
217
    {
228
221
    return false;
229
222
  }
230
223
 
231
 
  friend bool operator==(Table::const_reference left, Table::const_reference right)
 
224
  friend std::ostream& operator<<(std::ostream& output, const TableIdentifier &identifier)
 
225
  {
 
226
    const char *type_str;
 
227
 
 
228
    output << "TableIdentifier:(";
 
229
    output <<  identifier.getSchemaName();
 
230
    output << ", ";
 
231
    output << identifier.getTableName();
 
232
    output << ", ";
 
233
 
 
234
    switch (identifier.type) {
 
235
    case message::Table::STANDARD:
 
236
      type_str= "standard";
 
237
      break;
 
238
    case message::Table::INTERNAL:
 
239
      type_str= "internal";
 
240
      break;
 
241
    case message::Table::TEMPORARY:
 
242
      type_str= "temporary";
 
243
      break;
 
244
    case message::Table::FUNCTION:
 
245
      type_str= "function";
 
246
      break;
 
247
    }
 
248
 
 
249
    output << type_str;
 
250
    output << ", ";
 
251
    output << identifier.path;
 
252
    output << ", ";
 
253
    output << identifier.getHashValue();
 
254
    output << ")";
 
255
 
 
256
    return output;  // for multiple << operators.
 
257
  }
 
258
 
 
259
  friend bool operator==(TableIdentifier &left, TableIdentifier &right)
232
260
  {
233
261
    if (left.getHashValue() == right.getHashValue())
234
262
    {
245
273
  static size_t build_tmptable_filename(std::vector<char> &buffer);
246
274
 
247
275
public:
248
 
  bool isValid() const;
249
276
 
250
277
  size_t getHashValue() const
251
278
  {
258
285
  }
259
286
};
260
287
 
261
 
std::ostream& operator<<(std::ostream& output, Table::const_reference identifier);
262
 
std::size_t hash_value(Table const& b);
263
 
std::size_t hash_value(Table::Key const& b);
264
 
 
265
 
} /* namespace identifier */
 
288
std::size_t hash_value(TableIdentifier const& b);
 
289
std::size_t hash_value(TableIdentifier::Key const& b);
 
290
 
 
291
typedef std::vector <TableIdentifier> TableIdentifiers;
 
292
 
266
293
} /* namespace drizzled */
267
294
 
268
295
#endif /* DRIZZLED_IDENTIFIER_TABLE_H */