~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/identifier/table.h

  • Committer: Brian Aker
  • Date: 2011-02-14 05:47:07 UTC
  • mto: This revision was merged to the branch mainline in revision 2167.
  • Revision ID: brian@tangent.org-20110214054707-61nsqgg1g4w1zhx1
Merge in all changes for current_session, etc.

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;
61
 
  typedef std::vector <TableIdentifier> vector;
62
 
  typedef const TableIdentifier& const_reference;
63
 
  typedef TableIdentifier& reference;
 
62
  typedef std::vector <Table> vector;
 
63
  typedef const Table& const_reference;
 
64
  typedef Table& reference;
64
65
 
65
66
  class Key
66
67
  {
117
118
 
118
119
  Type type;
119
120
  std::string path;
 
121
  std::string key_path;
120
122
  std::string table_name;
121
123
  Key key;
122
124
  size_t hash_value;
129
131
  }
130
132
 
131
133
public:
132
 
  TableIdentifier(const Table &table);
 
134
 
 
135
  Table(const drizzled::Table &table);
133
136
                   
134
 
  TableIdentifier( const SchemaIdentifier &schema,
135
 
                   const std::string &table_name_arg,
136
 
                   Type tmp_arg= message::Table::STANDARD) :
137
 
    SchemaIdentifier(schema),
138
 
    type(tmp_arg),
139
 
    table_name(table_name_arg)
140
 
  { 
141
 
    init();
142
 
  }
143
 
 
144
 
  TableIdentifier( const std::string &db_arg,
145
 
                   const std::string &table_name_arg,
146
 
                   Type tmp_arg= message::Table::STANDARD) :
147
 
    SchemaIdentifier(db_arg),
148
 
    type(tmp_arg),
149
 
    table_name(table_name_arg)
150
 
  { 
151
 
    init();
152
 
  }
153
 
 
154
 
  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,
155
158
                   const std::string &table_name_arg,
156
159
                   const std::string &path_arg ) :
157
 
    SchemaIdentifier(schema_name_arg),
 
160
    Schema(schema_name_arg),
158
161
    type(message::Table::TEMPORARY),
159
162
    path(path_arg),
160
163
    table_name(table_name_arg)
162
165
    init();
163
166
  }
164
167
 
165
 
  using SchemaIdentifier::compare;
 
168
  using Schema::compare;
166
169
 
167
170
  bool isTmp() const
168
171
  {
169
172
    if (type == message::Table::TEMPORARY || type == message::Table::INTERNAL)
170
173
      return true;
 
174
 
171
175
    return false;
172
176
  }
173
177
 
200
204
  virtual void getSQLPath(std::string &sql_path) const;
201
205
 
202
206
  virtual const std::string &getPath() const;
 
207
  const std::string &getKeyPath() const;
203
208
 
204
209
  void setPath(const std::string &new_path)
205
210
  {
213
218
 
214
219
  void copyToTableMessage(message::Table &message) const;
215
220
 
216
 
  friend bool operator<(TableIdentifier::const_reference left, TableIdentifier::const_reference right)
 
221
  friend bool operator<(Table::const_reference left, Table::const_reference right)
217
222
  {
218
223
    if (left.getKey() < right.getKey())
219
224
    {
223
228
    return false;
224
229
  }
225
230
 
226
 
  friend std::ostream& operator<<(std::ostream& output, TableIdentifier::const_reference identifier)
227
 
  {
228
 
    const char *type_str;
229
 
 
230
 
    output << "TableIdentifier:(";
231
 
    output <<  identifier.getSchemaName();
232
 
    output << ", ";
233
 
    output << identifier.getTableName();
234
 
    output << ", ";
235
 
 
236
 
    switch (identifier.type) {
237
 
    case message::Table::STANDARD:
238
 
      type_str= "standard";
239
 
      break;
240
 
    case message::Table::INTERNAL:
241
 
      type_str= "internal";
242
 
      break;
243
 
    case message::Table::TEMPORARY:
244
 
      type_str= "temporary";
245
 
      break;
246
 
    case message::Table::FUNCTION:
247
 
      type_str= "function";
248
 
      break;
249
 
    }
250
 
 
251
 
    output << type_str;
252
 
    output << ", ";
253
 
    output << identifier.path;
254
 
    output << ", ";
255
 
    output << identifier.getHashValue();
256
 
    output << ")";
257
 
 
258
 
    return output;  // for multiple << operators.
259
 
  }
260
 
 
261
 
  friend bool operator==(TableIdentifier::const_reference left, TableIdentifier::const_reference right)
 
231
  friend bool operator==(Table::const_reference left, Table::const_reference right)
262
232
  {
263
233
    if (left.getHashValue() == right.getHashValue())
264
234
    {
288
258
  }
289
259
};
290
260
 
291
 
std::size_t hash_value(TableIdentifier const& b);
292
 
std::size_t hash_value(TableIdentifier::Key const& b);
 
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);
293
264
 
 
265
} /* namespace identifier */
294
266
} /* namespace drizzled */
295
267
 
296
268
#endif /* DRIZZLED_IDENTIFIER_TABLE_H */