~drizzle-trunk/drizzle/development

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/* Copyright (C) 2005 MySQL AB

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; version 2 of the License.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */


#ifndef PLUGIN_INFORMATION_ENGINE_INFORMATION_ENGINE_H
#define PLUGIN_INFORMATION_ENGINE_INFORMATION_ENGINE_H

#include <drizzled/server_includes.h>
#include <mysys/thr_lock.h>
#include <drizzled/plugin/info_schema_table.h>

static const char *information_exts[] = {
  NULL
};


class InformationEngine : public drizzled::plugin::StorageEngine
{
public:
  InformationEngine(const std::string &name_arg)
    : drizzled::plugin::StorageEngine(name_arg,
                                      HTON_ALTER_NOT_SUPPORTED |
                                      HTON_HIDDEN |
                                      HTON_NOT_USER_SELECTABLE |
                                      HTON_TEMPORARY_NOT_SUPPORTED)
  {
    pthread_mutex_init(&mutex, NULL);
  }

  ~InformationEngine()
  {
    pthread_mutex_destroy(&mutex);
  }

  class Share 
  {
  private:
    uint32_t count;
    drizzled::plugin::InfoSchemaTable *table;
    THR_LOCK lock;


  public:

    Share(const std::string &in_name) :
      count(1)
    {
      thr_lock_init(&lock);
      table= drizzled::plugin::InfoSchemaTable::getTable(in_name.c_str());
    }

    ~Share() 
    {
      thr_lock_delete(&lock);
    }

    /**
     * Increment the counter which tracks how many instances of this share are
     * currently open.
     * @return the new counter value
   */
    uint32_t incUseCount(void) 
    { 
      return ++count; 
    }

    /**
     * Decrement the count which tracks how many instances of this share are
     * currently open.
     * @return the new counter value
   */
    uint32_t decUseCount(void) 
    { 
      return --count; 
    }

    /**
     * @ return the value of the use counter for this share
   */
    uint32_t getUseCount() const
    {
      return count;
    }

    /**
     * @return the table name associated with this share.
   */
    const std::string &getName() const
    {
      return table->getTableName();
    }

    /**
     * @return the I_S table associated with this share.
   */
    drizzled::plugin::InfoSchemaTable *getInfoSchemaTable()
    {
      return table;
    }
  };

private:
  typedef std::map<const std::string, Share> OpenTables;
  typedef std::pair<const std::string, Share> Record;

  OpenTables open_tables;
  pthread_mutex_t mutex; // Mutext used in getShare() calls

public:

  // Follow Two Methods are for "share"
  Share *getShare(const std::string &name_arg);
  void freeShare(Share *share);


  int doCreateTable(Session *,
                    const char *,
                    Table&,
                    HA_CREATE_INFO&,
                    drizzled::message::Table&)
  {
    return EPERM;
  }

  int doDropTable(Session&, const std::string) 
  { 
    return EPERM; 
  }

  virtual Cursor *create(TableShare &table, MEM_ROOT *mem_root);

  const char **bas_ext() const 
  {
    return information_exts;
  }

  void doGetTableNames(CachedDirectory&, 
                       std::string &db, 
                       std::set<std::string> &set_of_names);

  int doGetTableDefinition(Session &session,
                           const char *path,
                           const char *db,
                           const char *table_name,
                           const bool is_tmp,
                           drizzled::message::Table *table_proto);

};

#endif /* PLUGIN_INFORMATION_ENGINE_INFORMATION_ENGINE_H */