~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/identifier/table.h

  • Committer: Olaf van der Spek
  • Date: 2011-04-20 09:27:49 UTC
  • mto: This revision was merged to the branch mainline in revision 2285.
  • Revision ID: olafvdspek@gmail.com-20110420092749-hw1q9rfj1pumc2no
Session Cache

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
30
30
  This will replace Table_ident.
31
31
  */
32
32
 
33
 
#ifndef DRIZZLED_IDENTIFIER_TABLE_H
34
 
#define DRIZZLED_IDENTIFIER_TABLE_H
 
33
#pragma once
35
34
 
36
35
#include <drizzled/enum.h>
37
 
#include "drizzled/definitions.h"
38
 
#include "drizzled/message/table.pb.h"
39
 
 
40
 
#include "drizzled/identifier.h"
 
36
#include <drizzled/definitions.h>
 
37
#include <drizzled/message/table.pb.h>
41
38
 
42
39
#include <string.h>
43
40
 
50
47
 
51
48
#include <boost/functional/hash.hpp>
52
49
 
 
50
#include <drizzled/visibility.h>
 
51
#include <drizzled/identifier/schema.h>
 
52
 
53
53
namespace drizzled {
54
 
 
55
 
class Table;
56
 
 
57
 
class TableIdentifier : public SchemaIdentifier
 
54
namespace identifier {
 
55
 
 
56
class DRIZZLED_API Table : public Schema
58
57
{
59
58
public:
60
59
  typedef message::Table::TableType Type;
61
 
  typedef std::vector <TableIdentifier> vector;
62
 
  typedef const TableIdentifier& const_reference;
63
 
  typedef TableIdentifier& reference;
64
60
 
65
61
  class Key
66
62
  {
117
113
 
118
114
  Type type;
119
115
  std::string path;
 
116
  std::string key_path;
120
117
  std::string table_name;
121
118
  Key key;
122
119
  size_t hash_value;
129
126
  }
130
127
 
131
128
public:
132
 
  TableIdentifier(const Table &table);
 
129
 
 
130
  Table(const drizzled::Table &table);
133
131
                   
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,
 
132
  Table(const identifier::Schema &schema,
 
133
        const std::string &table_name_arg,
 
134
        Type tmp_arg= message::Table::STANDARD) :
 
135
    Schema(schema),
 
136
    type(tmp_arg),
 
137
    table_name(table_name_arg)
 
138
  { 
 
139
    init();
 
140
  }
 
141
 
 
142
  Table( const std::string &db_arg,
 
143
                   const std::string &table_name_arg,
 
144
                   Type tmp_arg= message::Table::STANDARD) :
 
145
    Schema(db_arg),
 
146
    type(tmp_arg),
 
147
    table_name(table_name_arg)
 
148
  { 
 
149
    init();
 
150
  }
 
151
 
 
152
  Table( const std::string &schema_name_arg,
155
153
                   const std::string &table_name_arg,
156
154
                   const std::string &path_arg ) :
157
 
    SchemaIdentifier(schema_name_arg),
 
155
    Schema(schema_name_arg),
158
156
    type(message::Table::TEMPORARY),
159
157
    path(path_arg),
160
158
    table_name(table_name_arg)
162
160
    init();
163
161
  }
164
162
 
165
 
  using SchemaIdentifier::compare;
 
163
  using Schema::compare;
166
164
 
167
165
  bool isTmp() const
168
166
  {
169
167
    if (type == message::Table::TEMPORARY || type == message::Table::INTERNAL)
170
168
      return true;
 
169
 
171
170
    return false;
172
171
  }
173
172
 
197
196
    return type;
198
197
  }
199
198
 
200
 
  virtual void getSQLPath(std::string &sql_path) const;
 
199
  virtual std::string getSQLPath() const;
201
200
 
202
201
  virtual const std::string &getPath() const;
 
202
  const std::string &getKeyPath() const;
203
203
 
204
204
  void setPath(const std::string &new_path)
205
205
  {
213
213
 
214
214
  void copyToTableMessage(message::Table &message) const;
215
215
 
216
 
  friend bool operator<(TableIdentifier::const_reference left, TableIdentifier::const_reference right)
 
216
  friend bool operator<(const Table& left, const Table& right)
217
217
  {
218
218
    if (left.getKey() < right.getKey())
219
219
    {
223
223
    return false;
224
224
  }
225
225
 
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)
 
226
  friend bool operator==(const Table& left, const Table& right)
262
227
  {
263
228
    if (left.getHashValue() == right.getHashValue())
264
229
    {
288
253
  }
289
254
};
290
255
 
291
 
std::size_t hash_value(TableIdentifier const& b);
292
 
std::size_t hash_value(TableIdentifier::Key const& b);
 
256
std::ostream& operator<<(std::ostream& output, const Table& identifier);
 
257
std::size_t hash_value(Table const& b);
 
258
std::size_t hash_value(Table::Key const& b);
293
259
 
 
260
} /* namespace identifier */
294
261
} /* namespace drizzled */
295
 
 
296
 
#endif /* DRIZZLED_IDENTIFIER_TABLE_H */