1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Brian Aker
4
5
* Copyright (C) 2009 Sun Microsystems
6
7
* This program is free software; you can redistribute it and/or modify
29
30
This will replace Table_ident.
32
#ifndef DRIZZLED_TABLE_IDENTIFIER_H
33
#define DRIZZLED_TABLE_IDENTIFIER_H
33
#ifndef DRIZZLED_IDENTIFIER_TABLE_H
34
#define DRIZZLED_IDENTIFIER_TABLE_H
35
36
#include <drizzled/enum.h>
36
37
#include "drizzled/definitions.h"
37
38
#include "drizzled/message/table.pb.h"
39
#include "drizzled/schema_identifier.h"
40
#include "drizzled/identifier.h"
41
42
#include <string.h>
47
48
#include <algorithm>
48
49
#include <functional>
51
#include <boost/functional/hash.hpp>
50
53
namespace drizzled {
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);
57
57
class TableIdentifier : public SchemaIdentifier
60
60
typedef message::Table::TableType Type;
61
typedef std::vector<char> Key;
65
66
std::string table_name;
66
std::string lower_table_name;
67
67
std::string sql_path;
73
size_t getKeySize() const
75
return getSchemaName().size() + getTableName().size() + 2;
72
79
TableIdentifier(const Table &table);
131
144
return table_name;
134
void copyToTableMessage(message::Table &message);
147
void copyToTableMessage(message::Table &message) const;
136
bool operator<(TableIdentifier &right)
149
friend bool operator<(const TableIdentifier &left, const TableIdentifier &right)
138
int first= getLower().compare(right.getLower());
151
if (left.getKey() < right.getKey())
150
int val= lower_table_name.compare(right.lower_table_name);
162
if (type < right.type)
205
194
friend bool operator==(TableIdentifier &left, TableIdentifier &right)
207
if (left.type == right.type)
209
if (static_cast<SchemaIdentifier &>(left) == static_cast<SchemaIdentifier &>(right))
211
if (left.lower_table_name == right.lower_table_name)
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
223
typedef std::vector <TableIdentifier> TableIdentifierList;
224
typedef std::list <TableIdentifier> TableIdentifiers;
265
std::size_t hash_value(TableIdentifier const& b);
267
typedef std::vector <TableIdentifier> TableIdentifiers;
226
269
} /* namespace drizzled */
228
#endif /* DRIZZLED_TABLE_IDENTIFIER_H */
271
#endif /* DRIZZLED_IDENTIFIER_TABLE_H */