1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Brian Aker
5
* Copyright (C) 2009 Sun Microsystems
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.
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.
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
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.
27
This is mainly here so that it can be used in the SE interface for
30
This will replace Table_ident.
33
#ifndef DRIZZLED_IDENTIFIER_TABLE_H
34
#define DRIZZLED_IDENTIFIER_TABLE_H
36
#include <drizzled/enum.h>
37
#include "drizzled/definitions.h"
38
#include "drizzled/message/table.pb.h"
40
#include "drizzled/identifier.h"
51
#include <boost/functional/hash.hpp>
57
class TableIdentifier : public SchemaIdentifier
60
typedef message::Table::TableType Type;
61
typedef std::vector<char> Key;
66
std::string table_name;
73
size_t getKeySize() const
75
return getSchemaName().size() + getTableName().size() + 2;
79
TableIdentifier(const Table &table);
81
TableIdentifier( const SchemaIdentifier &schema,
82
const std::string &table_name_arg,
83
Type tmp_arg= message::Table::STANDARD) :
84
SchemaIdentifier(schema),
86
table_name(table_name_arg)
91
TableIdentifier( const std::string &db_arg,
92
const std::string &table_name_arg,
93
Type tmp_arg= message::Table::STANDARD) :
94
SchemaIdentifier(db_arg),
96
table_name(table_name_arg)
101
TableIdentifier( const std::string &schema_name_arg,
102
const std::string &table_name_arg,
103
const std::string &path_arg ) :
104
SchemaIdentifier(schema_name_arg),
105
type(message::Table::TEMPORARY),
107
table_name(table_name_arg)
112
using SchemaIdentifier::compare;
116
if (type == message::Table::TEMPORARY || type == message::Table::INTERNAL)
121
bool isView() const // Not a SQL view, but a view for I_S
123
if (type == message::Table::FUNCTION)
133
const std::string &getSQLPath();
135
const std::string &getPath() const;
137
void setPath(const std::string &new_path)
142
const std::string &getTableName() const
147
void copyToTableMessage(message::Table &message) const;
149
friend bool operator<(const TableIdentifier &left, const TableIdentifier &right)
151
if (left.getKey() < right.getKey())
159
friend std::ostream& operator<<(std::ostream& output, const TableIdentifier &identifier)
161
const char *type_str;
163
output << "TableIdentifier:(";
164
output << identifier.getSchemaName();
166
output << identifier.getTableName();
169
switch (identifier.type) {
170
case message::Table::STANDARD:
171
type_str= "standard";
173
case message::Table::INTERNAL:
174
type_str= "internal";
176
case message::Table::TEMPORARY:
177
type_str= "temporary";
179
case message::Table::FUNCTION:
180
type_str= "function";
186
output << identifier.path;
188
output << identifier.getHashValue();
191
return output; // for multiple << operators.
194
friend bool operator==(TableIdentifier &left, TableIdentifier &right)
196
if (left.getKey() == right.getKey())
202
static uint32_t filename_to_tablename(const char *from, char *to, uint32_t to_length);
203
static size_t build_table_filename(std::string &buff, const char *db, const char *table_name, bool is_tmp);
204
static size_t build_tmptable_filename(std::string &buffer);
205
static size_t build_tmptable_filename(std::vector<char> &buffer);
208
Create a table cache key
212
key Create key here (must be of size MAX_DBKEY_LENGTH)
213
table_list Table definition
216
The table cache_key is created from:
220
if the table is a tmp table, we add the following to make each tmp table
223
4 bytes for master thread id
224
4 bytes pseudo thread id
229
static uint32_t createKey(char *key, const char *db_arg, const char *table_name_arg)
234
key_pos= strcpy(key_pos, db_arg) + strlen(db_arg);
235
key_pos= strcpy(key_pos+1, table_name_arg) +
236
strlen(table_name_arg);
237
key_length= (uint32_t)(key_pos-key)+1;
242
static uint32_t createKey(char *key, const TableIdentifier &identifier)
247
key_pos= strcpy(key_pos, identifier.getSchemaName().c_str()) + identifier.getSchemaName().length();
248
key_pos= strcpy(key_pos + 1, identifier.getTableName().c_str()) + identifier.getTableName().length();
249
key_length= (uint32_t)(key_pos-key)+1;
254
size_t getHashValue() const
259
const Key &getKey() const
265
std::size_t hash_value(TableIdentifier const& b);
267
typedef std::vector <TableIdentifier> TableIdentifiers;
269
} /* namespace drizzled */
271
#endif /* DRIZZLED_IDENTIFIER_TABLE_H */