1223.4.1
by Brian Aker
Table Identifier patch. |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
1660.1.1
by Brian Aker
Merge in move identifier work. |
4 |
* Copyright (C) 2010 Brian Aker
|
1999.6.1
by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file |
5 |
* Copyright (C) 2009 Sun Microsystems, Inc.
|
1223.4.1
by Brian Aker
Table Identifier patch. |
6 |
*
|
7 |
* This program is free software; you can redistribute it and/or modify
|
|
8 |
* it under the terms of the GNU General Public License as published by
|
|
9 |
* the Free Software Foundation; either version 2 of the License, or
|
|
10 |
* (at your option) any later version.
|
|
11 |
*
|
|
12 |
* This program is distributed in the hope that it will be useful,
|
|
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 |
* GNU General Public License for more details.
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License
|
|
18 |
* along with this program; if not, write to the Free Software
|
|
19 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
20 |
*/
|
|
21 |
||
22 |
/*
|
|
23 |
This is a "work in progress". The concept needs to be replicated throughout
|
|
24 |
the code, but we will start with baby steps for the moment. To not incur
|
|
25 |
cost until we are complete, for the moment it will do no allocation.
|
|
26 |
||
27 |
This is mainly here so that it can be used in the SE interface for
|
|
28 |
the time being.
|
|
29 |
||
30 |
This will replace Table_ident.
|
|
31 |
*/
|
|
32 |
||
2200
by Brian Aker
Testing pragma once for build farm. |
33 |
#pragma once
|
1223.4.1
by Brian Aker
Table Identifier patch. |
34 |
|
1223.4.5
by Brian Aker
Added << and == operators to TableIdentifier |
35 |
#include <drizzled/enum.h> |
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
36 |
#include <drizzled/definitions.h> |
37 |
#include <drizzled/message/table.pb.h> |
|
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
38 |
|
1223.4.1
by Brian Aker
Table Identifier patch. |
39 |
#include <string.h> |
40 |
||
1341
by Brian Aker
See if these are now cleaned up. |
41 |
#include <assert.h> |
42 |
||
1223.4.5
by Brian Aker
Added << and == operators to TableIdentifier |
43 |
#include <ostream> |
1309.1.11
by Brian Aker
Small helper bit for dealing with lists of table_identifiers. |
44 |
#include <set> |
1358.1.5
by Brian Aker
Cleans up use of static buffer in TableIdentifier. |
45 |
#include <algorithm> |
46 |
#include <functional> |
|
1223.4.1
by Brian Aker
Table Identifier patch. |
47 |
|
1608.2.1
by Brian Aker
Modified to table identifier to fix temporary table creation loss of file. |
48 |
#include <boost/functional/hash.hpp> |
49 |
||
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
50 |
#include <drizzled/visibility.h> |
2462.1.2
by Brian Aker
Remove common_fwd.h from visibility.h |
51 |
#include <drizzled/common_fwd.h> |
2241.4.14
by Stewart Smith
remove some includes from my_sys.h and instead only include where needed. This helps reduce the number of files that have to be rebuilt when you change some of the more widely included header files (such as the drizzled::identifier ones) |
52 |
#include <drizzled/identifier/schema.h> |
2119.4.1
by Monty Taylor
Turns on -fvisibility=hidden by default. Symbols intended to be used by |
53 |
|
1223.4.1
by Brian Aker
Table Identifier patch. |
54 |
namespace drizzled { |
2087.4.2
by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers. |
55 |
namespace identifier { |
56 |
||
2126.2.1
by Brian Aker
Merge in changes for catalogs usage of constants for identifier. |
57 |
class DRIZZLED_API Table : public Schema |
1223.4.1
by Brian Aker
Table Identifier patch. |
58 |
{
|
1395.1.9
by Brian Aker
Small cleanup around how we do types internally. |
59 |
public: |
60 |
typedef message::Table::TableType Type; |
|
1878.5.3
by Brian Aker
Update Key to work a bit faster. |
61 |
|
62 |
class Key |
|
63 |
{
|
|
64 |
std::vector<char> key_buffer; |
|
65 |
size_t hash_value; |
|
66 |
||
67 |
public: |
|
68 |
||
69 |
Key() : |
|
70 |
hash_value(0) |
|
71 |
{
|
|
72 |
}
|
|
73 |
||
74 |
const char *vector() const |
|
75 |
{
|
|
76 |
return &key_buffer[0]; |
|
77 |
}
|
|
78 |
||
79 |
std::vector<char> &vectorPtr() |
|
80 |
{
|
|
81 |
return key_buffer; |
|
82 |
}
|
|
83 |
||
84 |
void set(size_t resize_arg, const std::string &a, const std::string &b); |
|
85 |
||
86 |
friend bool operator==(const Key &left, const Key &right) |
|
87 |
{
|
|
88 |
if (left.hash_value == right.hash_value and left.key_buffer.size() == right.key_buffer.size()) |
|
89 |
{
|
|
90 |
if (memcmp(&left.key_buffer[0], &right.key_buffer[0], left.key_buffer.size()) == 0) |
|
91 |
return true; |
|
92 |
}
|
|
93 |
||
94 |
return false; |
|
95 |
}
|
|
96 |
||
97 |
friend bool operator<(const Key &left, const Key &right) |
|
98 |
{
|
|
99 |
return left.key_buffer < right.key_buffer; |
|
100 |
}
|
|
101 |
||
102 |
size_t size() const |
|
103 |
{
|
|
104 |
return key_buffer.size(); |
|
105 |
}
|
|
106 |
||
107 |
size_t getHashValue() const |
|
108 |
{
|
|
109 |
return hash_value; |
|
110 |
}
|
|
111 |
};
|
|
112 |
||
1395.1.9
by Brian Aker
Small cleanup around how we do types internally. |
113 |
private: |
114 |
||
115 |
Type type; |
|
1358.1.5
by Brian Aker
Cleans up use of static buffer in TableIdentifier. |
116 |
std::string path; |
2139.3.2
by Brian Aker
Fix innodb to just directly use the identifier (this way we only need to |
117 |
std::string key_path; |
1341
by Brian Aker
See if these are now cleaned up. |
118 |
std::string table_name; |
1618
by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have |
119 |
Key key; |
1608.2.1
by Brian Aker
Modified to table identifier to fix temporary table creation loss of file. |
120 |
size_t hash_value; |
1223.4.1
by Brian Aker
Table Identifier patch. |
121 |
|
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
122 |
void init(); |
1395.1.6
by Brian Aker
Modified TableIdentifier output for errors. |
123 |
|
1618
by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have |
124 |
size_t getKeySize() const |
125 |
{
|
|
126 |
return getSchemaName().size() + getTableName().size() + 2; |
|
127 |
}
|
|
128 |
||
1223.4.1
by Brian Aker
Table Identifier patch. |
129 |
public: |
2087.4.2
by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers. |
130 |
|
131 |
Table(const drizzled::Table &table); |
|
1417
by Brian Aker
Interface for Stewart. |
132 |
|
2087.4.2
by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers. |
133 |
Table(const identifier::Schema &schema, |
134 |
const std::string &table_name_arg, |
|
135 |
Type tmp_arg= message::Table::STANDARD) : |
|
2087.4.1
by Brian Aker
Merge in schema identifier. |
136 |
Schema(schema), |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
137 |
type(tmp_arg), |
138 |
table_name(table_name_arg) |
|
139 |
{
|
|
140 |
init(); |
|
141 |
}
|
|
142 |
||
2087.4.2
by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers. |
143 |
Table( const std::string &db_arg, |
1358.1.5
by Brian Aker
Cleans up use of static buffer in TableIdentifier. |
144 |
const std::string &table_name_arg, |
1395.1.9
by Brian Aker
Small cleanup around how we do types internally. |
145 |
Type tmp_arg= message::Table::STANDARD) : |
2087.4.1
by Brian Aker
Merge in schema identifier. |
146 |
Schema(db_arg), |
1223.4.1
by Brian Aker
Table Identifier patch. |
147 |
type(tmp_arg), |
1395.1.14
by Brian Aker
Fix for Innodb dfe files. |
148 |
table_name(table_name_arg) |
1320.1.5
by Brian Aker
Second pass through remove proto write outside of SE. |
149 |
{
|
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
150 |
init(); |
1320.1.5
by Brian Aker
Second pass through remove proto write outside of SE. |
151 |
}
|
1223.4.1
by Brian Aker
Table Identifier patch. |
152 |
|
2087.4.2
by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers. |
153 |
Table( const std::string &schema_name_arg, |
1395.1.14
by Brian Aker
Fix for Innodb dfe files. |
154 |
const std::string &table_name_arg, |
155 |
const std::string &path_arg ) : |
|
2087.4.1
by Brian Aker
Merge in schema identifier. |
156 |
Schema(schema_name_arg), |
1395.1.7
by Brian Aker
Removed the internal table type in favor of the protobuf one. |
157 |
type(message::Table::TEMPORARY), |
1389
by Brian Aker
Large reord in ALTER TABLE for RENAME. |
158 |
path(path_arg), |
159 |
table_name(table_name_arg) |
|
160 |
{
|
|
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
161 |
init(); |
1358.1.2
by Brian Aker
Long pass through the system to use more of TableIdentifiers. |
162 |
}
|
163 |
||
2087.4.1
by Brian Aker
Merge in schema identifier. |
164 |
using Schema::compare; |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
165 |
|
1223.4.5
by Brian Aker
Added << and == operators to TableIdentifier |
166 |
bool isTmp() const |
1223.4.1
by Brian Aker
Table Identifier patch. |
167 |
{
|
1395.1.7
by Brian Aker
Removed the internal table type in favor of the protobuf one. |
168 |
if (type == message::Table::TEMPORARY || type == message::Table::INTERNAL) |
169 |
return true; |
|
2134.1.7
by Brian Aker
Collapse strings used for table. |
170 |
|
1395.1.7
by Brian Aker
Removed the internal table type in favor of the protobuf one. |
171 |
return false; |
1223.4.1
by Brian Aker
Table Identifier patch. |
172 |
}
|
173 |
||
1802.12.1
by Brian Aker
This solves bug lp:654905 |
174 |
static bool isView(message::Table::TableType arg) // Not a SQL view, but a view for I_S |
175 |
{
|
|
176 |
switch (arg) |
|
177 |
{
|
|
178 |
default: |
|
179 |
case message::Table::STANDARD: |
|
180 |
case message::Table::TEMPORARY: |
|
181 |
case message::Table::INTERNAL: |
|
182 |
break; |
|
183 |
case message::Table::FUNCTION: |
|
184 |
return true; |
|
185 |
}
|
|
186 |
||
187 |
return false; |
|
188 |
}
|
|
189 |
||
1643.3.11
by Brian Aker
Encapsulate a bit of logic. |
190 |
bool isView() const // Not a SQL view, but a view for I_S |
191 |
{
|
|
1802.12.1
by Brian Aker
This solves bug lp:654905 |
192 |
return isView(type); |
1643.3.11
by Brian Aker
Encapsulate a bit of logic. |
193 |
}
|
194 |
||
1395.1.9
by Brian Aker
Small cleanup around how we do types internally. |
195 |
Type getType() const |
196 |
{
|
|
197 |
return type; |
|
198 |
}
|
|
199 |
||
2246.4.2
by Olaf van der Spek
Refactor Identifier::getSQLPath() |
200 |
virtual std::string getSQLPath() const; |
1320.1.5
by Brian Aker
Second pass through remove proto write outside of SE. |
201 |
|
1992.4.1
by Brian Aker
Update code for testing identifiers/table/schema name correctness. |
202 |
virtual const std::string &getPath() const; |
2139.3.2
by Brian Aker
Fix innodb to just directly use the identifier (this way we only need to |
203 |
const std::string &getKeyPath() const; |
1358.1.9
by Brian Aker
Update for std::string |
204 |
|
1395.1.14
by Brian Aker
Fix for Innodb dfe files. |
205 |
void setPath(const std::string &new_path) |
206 |
{
|
|
207 |
path= new_path; |
|
208 |
}
|
|
209 |
||
1411.3.3
by Monty Taylor
Made getTableName() return a const reference instead of a temporary const |
210 |
const std::string &getTableName() const |
1358.1.9
by Brian Aker
Update for std::string |
211 |
{
|
212 |
return table_name; |
|
1223.4.5
by Brian Aker
Added << and == operators to TableIdentifier |
213 |
}
|
214 |
||
1618.1.1
by Brian Aker
Modify TableIdentifier to be const |
215 |
void copyToTableMessage(message::Table &message) const; |
1395.1.1
by Brian Aker
Fixes for alter table to make sure that the proto on disk is valid. |
216 |
|
2246.4.10
by Olaf van der Spek
Remove const_reference and reference from identifier::Table |
217 |
friend bool operator<(const Table& left, const Table& right) |
1429.1.3
by Brian Aker
Merge in work for fetching a list of table identifiers. |
218 |
{
|
1669.2.1
by Brian Aker
Modify how we make comparisons for tables. |
219 |
if (left.getKey() < right.getKey()) |
1429.1.3
by Brian Aker
Merge in work for fetching a list of table identifiers. |
220 |
{
|
221 |
return true; |
|
222 |
}
|
|
223 |
||
224 |
return false; |
|
225 |
}
|
|
226 |
||
2246.4.10
by Olaf van der Spek
Remove const_reference and reference from identifier::Table |
227 |
friend bool operator==(const Table& left, const Table& right) |
1223.4.5
by Brian Aker
Added << and == operators to TableIdentifier |
228 |
{
|
1843.8.2
by Brian Aker
Slight optimization on comparison. |
229 |
if (left.getHashValue() == right.getHashValue()) |
230 |
{
|
|
231 |
if (left.getKey() == right.getKey()) |
|
232 |
return true; |
|
233 |
}
|
|
1223.4.1
by Brian Aker
Table Identifier patch. |
234 |
|
1223.4.5
by Brian Aker
Added << and == operators to TableIdentifier |
235 |
return false; |
236 |
}
|
|
237 |
||
1601
by Brian Aker
Move functions to class methods. |
238 |
static uint32_t filename_to_tablename(const char *from, char *to, uint32_t to_length); |
2318.9.9
by Olaf van der Spek
Refactor build_table_filename |
239 |
static std::string build_table_filename(const std::string &db, const std::string &table_name, bool is_tmp); |
2318.9.5
by Olaf van der Spek
Refactor build_table_filename |
240 |
static std::string build_tmptable_filename(); |
1618
by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have |
241 |
|
1864.3.17
by Brian Aker
Simply the create of an identifier key. |
242 |
public: |
1992.4.1
by Brian Aker
Update code for testing identifiers/table/schema name correctness. |
243 |
bool isValid() const; |
1601
by Brian Aker
Move functions to class methods. |
244 |
|
1608.2.1
by Brian Aker
Modified to table identifier to fix temporary table creation loss of file. |
245 |
size_t getHashValue() const |
246 |
{
|
|
247 |
return hash_value; |
|
248 |
}
|
|
1618
by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have |
249 |
|
250 |
const Key &getKey() const |
|
251 |
{
|
|
252 |
return key; |
|
253 |
}
|
|
1223.4.1
by Brian Aker
Table Identifier patch. |
254 |
};
|
255 |
||
2246.4.10
by Olaf van der Spek
Remove const_reference and reference from identifier::Table |
256 |
std::ostream& operator<<(std::ostream& output, const Table& identifier); |
2087.4.2
by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers. |
257 |
std::size_t hash_value(Table const& b); |
258 |
std::size_t hash_value(Table::Key const& b); |
|
1608.2.1
by Brian Aker
Modified to table identifier to fix temporary table creation loss of file. |
259 |
|
2087.4.2
by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers. |
260 |
} /* namespace identifier */ |
1223.4.1
by Brian Aker
Table Identifier patch. |
261 |
} /* namespace drizzled */ |