~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table_identifier.h

  • Committer: Monty Taylor
  • Date: 2009-04-14 19:16:51 UTC
  • mto: (997.2.5 mordred)
  • mto: This revision was merged to the branch mainline in revision 994.
  • Revision ID: mordred@inaugust.com-20090414191651-ltbww6hpqks8k7qk
Clarified instructions in README.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 
 *
4
 
 *  Copyright (C) 2009 Sun Microsystems
5
 
 *
6
 
 *  This program is free software; you can redistribute it and/or modify
7
 
 *  it under the terms of the GNU General Public License as published by
8
 
 *  the Free Software Foundation; either version 2 of the License, or
9
 
 *  (at your option) any later version.
10
 
 *
11
 
 *  This program is distributed in the hope that it will be useful,
12
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
 *  GNU General Public License for more details.
15
 
 *
16
 
 *  You should have received a copy of the GNU General Public License
17
 
 *  along with this program; if not, write to the Free Software
18
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
 
 */
20
 
 
21
 
/* 
22
 
  This is a "work in progress". The concept needs to be replicated throughout
23
 
  the code, but we will start with baby steps for the moment. To not incur
24
 
  cost until we are complete, for the moment it will do no allocation.
25
 
 
26
 
  This is mainly here so that it can be used in the SE interface for
27
 
  the time being.
28
 
 
29
 
  This will replace Table_ident.
30
 
  */
31
 
 
32
 
#ifndef DRIZZLED_TABLE_IDENTIFIER_H
33
 
#define DRIZZLED_TABLE_IDENTIFIER_H
34
 
 
35
 
#include <drizzled/enum.h>
36
 
#include "drizzled/definitions.h"
37
 
#include "drizzled/message/table.pb.h"
38
 
 
39
 
#include "drizzled/schema_identifier.h"
40
 
 
41
 
#include <string.h>
42
 
 
43
 
#include <assert.h>
44
 
 
45
 
#include <ostream>
46
 
#include <set>
47
 
#include <algorithm>
48
 
#include <functional>
49
 
 
50
 
namespace drizzled {
51
 
 
52
 
class Table;
53
 
 
54
 
uint32_t filename_to_tablename(const char *from, char *to, uint32_t to_length);
55
 
size_t build_table_filename(std::string &buff, const char *db, const char *table_name, bool is_tmp);
56
 
 
57
 
class TableIdentifier : public SchemaIdentifier
58
 
{
59
 
public:
60
 
  typedef message::Table::TableType Type;
61
 
private:
62
 
 
63
 
  Type type;
64
 
  std::string path;
65
 
  std::string table_name;
66
 
  std::string lower_table_name;
67
 
  std::string sql_path;
68
 
 
69
 
  void init();
70
 
 
71
 
public:
72
 
  TableIdentifier(const Table &table);
73
 
                   
74
 
  TableIdentifier( const SchemaIdentifier &schema,
75
 
                   const std::string &table_name_arg,
76
 
                   Type tmp_arg= message::Table::STANDARD) :
77
 
    SchemaIdentifier(schema),
78
 
    type(tmp_arg),
79
 
    table_name(table_name_arg)
80
 
  { 
81
 
    init();
82
 
  }
83
 
 
84
 
  TableIdentifier( const std::string &db_arg,
85
 
                   const std::string &table_name_arg,
86
 
                   Type tmp_arg= message::Table::STANDARD) :
87
 
    SchemaIdentifier(db_arg),
88
 
    type(tmp_arg),
89
 
    table_name(table_name_arg)
90
 
  { 
91
 
    init();
92
 
  }
93
 
 
94
 
  TableIdentifier( const std::string &schema_name_arg,
95
 
                   const std::string &table_name_arg,
96
 
                   const std::string &path_arg ) :
97
 
    SchemaIdentifier(schema_name_arg),
98
 
    type(message::Table::TEMPORARY),
99
 
    path(path_arg),
100
 
    table_name(table_name_arg)
101
 
  { 
102
 
    init();
103
 
  }
104
 
 
105
 
  using SchemaIdentifier::compare;
106
 
  bool compare(std::string schema_arg, std::string table_arg);
107
 
 
108
 
  bool isTmp() const
109
 
  {
110
 
    if (type == message::Table::TEMPORARY || type == message::Table::INTERNAL)
111
 
      return true;
112
 
    return false;
113
 
  }
114
 
 
115
 
  Type getType() const
116
 
  {
117
 
    return type;
118
 
  }
119
 
 
120
 
  const std::string &getSQLPath();
121
 
 
122
 
  const std::string &getPath();
123
 
 
124
 
  void setPath(const std::string &new_path)
125
 
  {
126
 
    path= new_path;
127
 
  }
128
 
 
129
 
  const std::string &getTableName() const
130
 
  {
131
 
    return table_name;
132
 
  }
133
 
 
134
 
  void copyToTableMessage(message::Table &message);
135
 
 
136
 
  bool operator<(TableIdentifier &right)
137
 
  {
138
 
    int first= getLower().compare(right.getLower());
139
 
 
140
 
    if (first < 0)
141
 
    {
142
 
      return true;
143
 
    }
144
 
    else if (first > 0)
145
 
    {
146
 
      return false;
147
 
    }
148
 
    else
149
 
    {
150
 
      int val= lower_table_name.compare(right.lower_table_name);
151
 
 
152
 
      if (val < 0)
153
 
      {
154
 
        return true;
155
 
      }
156
 
      else if (val > 0)
157
 
      {
158
 
        return false;
159
 
      }
160
 
      else
161
 
      {
162
 
        if (type < right.type)
163
 
        {
164
 
          return true;
165
 
        }
166
 
      }
167
 
    }
168
 
 
169
 
    return false;
170
 
  }
171
 
 
172
 
  friend std::ostream& operator<<(std::ostream& output, const TableIdentifier &identifier)
173
 
  {
174
 
    const char *type_str;
175
 
 
176
 
    output << "TableIdentifier:(";
177
 
    output <<  identifier.getSchemaName();
178
 
    output << ", ";
179
 
    output << identifier.getTableName();
180
 
    output << ", ";
181
 
 
182
 
    switch (identifier.type) {
183
 
    case message::Table::STANDARD:
184
 
      type_str= "standard";
185
 
      break;
186
 
    case message::Table::INTERNAL:
187
 
      type_str= "internal";
188
 
      break;
189
 
    case message::Table::TEMPORARY:
190
 
      type_str= "temporary";
191
 
      break;
192
 
    case message::Table::FUNCTION:
193
 
      type_str= "function";
194
 
      break;
195
 
    }
196
 
 
197
 
    output << type_str;
198
 
    output << ", ";
199
 
    output << identifier.path;
200
 
    output << ")";
201
 
 
202
 
    return output;  // for multiple << operators.
203
 
  }
204
 
 
205
 
  friend bool operator==(TableIdentifier &left, TableIdentifier &right)
206
 
  {
207
 
    if (left.type == right.type)
208
 
    {
209
 
      if (static_cast<SchemaIdentifier &>(left) == static_cast<SchemaIdentifier &>(right))
210
 
      {
211
 
        if (left.lower_table_name == right.lower_table_name)
212
 
        {
213
 
          return true;
214
 
        }
215
 
      }
216
 
    }
217
 
 
218
 
    return false;
219
 
  }
220
 
 
221
 
};
222
 
 
223
 
typedef std::vector <TableIdentifier> TableIdentifierList;
224
 
typedef std::list <TableIdentifier> TableIdentifiers;
225
 
 
226
 
} /* namespace drizzled */
227
 
 
228
 
#endif /* DRIZZLED_TABLE_IDENTIFIER_H */