~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/identifier/table.h

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:26:39 UTC
  • mfrom: (2157.2.2 give-in-to-pkg-config)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172639-nhy7i72sfhoq13ms
Merged in pkg-config fixes.

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
 
5
 *  Copyright (C) 2009 Sun Microsystems, Inc.
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
 
 
42
40
#include <string.h>
43
41
 
44
42
#include <assert.h>
50
48
 
51
49
#include <boost/functional/hash.hpp>
52
50
 
 
51
#include "drizzled/visibility.h"
 
52
 
53
53
namespace drizzled {
54
 
 
55
54
class Table;
56
55
 
57
 
class TableIdentifier : public SchemaIdentifier
 
56
namespace identifier {
 
57
 
 
58
class DRIZZLED_API Table : public Schema
58
59
{
59
60
public:
60
61
  typedef message::Table::TableType Type;
 
62
  typedef std::vector <Table> vector;
 
63
  typedef const Table& const_reference;
 
64
  typedef Table& reference;
61
65
 
62
66
  class Key
63
67
  {
114
118
 
115
119
  Type type;
116
120
  std::string path;
 
121
  std::string key_path;
117
122
  std::string table_name;
118
 
  std::string sql_path;
119
123
  Key key;
120
124
  size_t hash_value;
121
125
 
127
131
  }
128
132
 
129
133
public:
130
 
  TableIdentifier(const Table &table);
 
134
 
 
135
  Table(const drizzled::Table &table);
131
136
                   
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,
 
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,
153
158
                   const std::string &table_name_arg,
154
159
                   const std::string &path_arg ) :
155
 
    SchemaIdentifier(schema_name_arg),
 
160
    Schema(schema_name_arg),
156
161
    type(message::Table::TEMPORARY),
157
162
    path(path_arg),
158
163
    table_name(table_name_arg)
160
165
    init();
161
166
  }
162
167
 
163
 
  using SchemaIdentifier::compare;
 
168
  using Schema::compare;
164
169
 
165
170
  bool isTmp() const
166
171
  {
167
172
    if (type == message::Table::TEMPORARY || type == message::Table::INTERNAL)
168
173
      return true;
 
174
 
169
175
    return false;
170
176
  }
171
177
 
195
201
    return type;
196
202
  }
197
203
 
198
 
  const std::string &getSQLPath();
 
204
  virtual void getSQLPath(std::string &sql_path) const;
199
205
 
200
 
  const std::string &getPath() const;
 
206
  virtual const std::string &getPath() const;
 
207
  const std::string &getKeyPath() const;
201
208
 
202
209
  void setPath(const std::string &new_path)
203
210
  {
211
218
 
212
219
  void copyToTableMessage(message::Table &message) const;
213
220
 
214
 
  friend bool operator<(const TableIdentifier &left, const TableIdentifier &right)
 
221
  friend bool operator<(Table::const_reference left, Table::const_reference right)
215
222
  {
216
223
    if (left.getKey() < right.getKey())
217
224
    {
221
228
    return false;
222
229
  }
223
230
 
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)
 
231
  friend bool operator==(Table::const_reference left, Table::const_reference right)
260
232
  {
261
233
    if (left.getHashValue() == right.getHashValue())
262
234
    {
273
245
  static size_t build_tmptable_filename(std::vector<char> &buffer);
274
246
 
275
247
public:
 
248
  bool isValid() const;
276
249
 
277
250
  size_t getHashValue() const
278
251
  {
285
258
  }
286
259
};
287
260
 
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
 
 
 
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 */
293
266
} /* namespace drizzled */
294
267
 
295
268
#endif /* DRIZZLED_IDENTIFIER_TABLE_H */