~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/table_cache_dictionary/table_definition_cache.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-03-18 12:12:31 UTC
  • Revision ID: james.westby@ubuntu.com-20100318121231-k6g1xe6cshbwa0f8
Tags: upstream-2010.03.1347
ImportĀ upstreamĀ versionĀ 2010.03.1347

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) 2010 Brian Aker
 
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
#include "config.h"
 
22
 
 
23
#include "plugin/table_cache_dictionary/dictionary.h"
 
24
#include "drizzled/pthread_globals.h"
 
25
 
 
26
using namespace drizzled;
 
27
using namespace std;
 
28
 
 
29
table_cache_dictionary::TableDefinitionCache::TableDefinitionCache() :
 
30
  plugin::TableFunction("DATA_DICTIONARY", "TABLE_DEFINITION_CACHE")
 
31
{
 
32
  add_field("TABLE_SCHEMA");
 
33
  add_field("TABLE_NAME");
 
34
  add_field("VERSION", plugin::TableFunction::NUMBER);
 
35
  add_field("TABLE_COUNT", plugin::TableFunction::NUMBER);
 
36
  add_field("IS_NAME_LOCKED", plugin::TableFunction::BOOLEAN);
 
37
}
 
38
 
 
39
table_cache_dictionary::TableDefinitionCache::Generator::Generator(drizzled::Field **arg) :
 
40
  drizzled::plugin::TableFunction::Generator(arg),
 
41
  is_primed(false)
 
42
{
 
43
  pthread_mutex_lock(&LOCK_open); /* Optionally lock for remove tables from open_cahe if not in use */
 
44
}
 
45
 
 
46
table_cache_dictionary::TableDefinitionCache::Generator::~Generator()
 
47
{
 
48
  pthread_mutex_unlock(&LOCK_open); /* Optionally lock for remove tables from open_cahe if not in use */
 
49
}
 
50
 
 
51
bool table_cache_dictionary::TableDefinitionCache::Generator::nextCore()
 
52
{
 
53
  if (is_primed)
 
54
  {
 
55
    table_share_iterator++;
 
56
  }
 
57
  else
 
58
  {
 
59
    is_primed= true;
 
60
    table_share_iterator= TableShare::getCache().begin();
 
61
  }
 
62
 
 
63
  if (table_share_iterator == TableShare::getCache().end())
 
64
    return false;
 
65
 
 
66
  share= (*table_share_iterator).second;
 
67
 
 
68
  return true;
 
69
}
 
70
 
 
71
bool table_cache_dictionary::TableDefinitionCache::Generator::next()
 
72
{
 
73
  while (not nextCore())
 
74
  {
 
75
    if (table_share_iterator != TableShare::getCache().end())
 
76
      continue;
 
77
 
 
78
    return false;
 
79
  }
 
80
 
 
81
  return true;
 
82
}
 
83
 
 
84
bool table_cache_dictionary::TableDefinitionCache::Generator::populate()
 
85
{
 
86
  if (not next())
 
87
    return false;
 
88
  
 
89
  fill();
 
90
 
 
91
  return true;
 
92
}
 
93
 
 
94
void table_cache_dictionary::TableDefinitionCache::Generator::fill()
 
95
{
 
96
  /**
 
97
    For test cases use:
 
98
    --replace_column 3 # 4 # 5 #
 
99
  */
 
100
 
 
101
  /* TABLE_SCHEMA 1 */
 
102
  string arg;
 
103
  push(share->getSchemaName(arg));
 
104
 
 
105
  /* TABLE_NAME  2 */
 
106
  push(share->getTableName(arg));
 
107
 
 
108
  /* VERSION 3 */
 
109
  push(static_cast<int64_t>(share->getVersion()));
 
110
 
 
111
  /* TABLE_COUNT 4 */
 
112
  push(static_cast<uint64_t>(share->getTableCount()));
 
113
 
 
114
  /* IS_NAME_LOCKED */
 
115
  push(share->isNameLock());
 
116
}