~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/query_cache.cc

  • Committer: Brian Aker
  • Date: 2009-10-02 19:38:12 UTC
  • mfrom: (1152.1.7 merge)
  • Revision ID: brian@gaz-20091002193812-mpd61oecep74t6gd
Merge Monty + Brian for plugins.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include <drizzled/server_includes.h>
21
 
#include <drizzled/qcache.h>
22
 
#include <drizzled/gettext.h>
 
20
#include "drizzled/server_includes.h"
 
21
#include "drizzled/plugin/query_cache.h"
23
22
#include "drizzled/plugin/registry.h"
 
23
 
 
24
#include "drizzled/gettext.h"
 
25
 
24
26
#include <vector>
25
27
 
26
28
using namespace std;
27
29
 
28
 
static vector<QueryCache *> all_query_cache;
29
 
 
30
 
void add_query_cache(QueryCache *handler)
31
 
{
32
 
  all_query_cache.push_back(handler);
33
 
}
34
 
 
35
 
void remove_query_cache(QueryCache *handler)
36
 
{
37
 
  all_query_cache.erase(find(all_query_cache.begin(), all_query_cache.end(),
38
 
                        handler));
39
 
}
40
 
 
41
 
 
 
30
namespace drizzled
 
31
{
 
32
 
 
33
vector<plugin::QueryCache *> all_query_cache;
42
34
 
43
35
/* Namespaces are here to prevent global symbol clashes with these classes */
44
36
 
45
 
namespace drizzled {
46
 
namespace query_cache {
47
 
 
48
37
class TryFetchAndSendIterate
49
 
 : public unary_function<QueryCache *, bool>
 
38
 : public unary_function<plugin::QueryCache *, bool>
50
39
{
51
40
  Session *session;
52
41
  bool is_transactional;
53
42
public:
54
43
  TryFetchAndSendIterate(Session *session_arg, bool is_transactional_arg) :
55
 
    unary_function<QueryCache *, bool>(),
 
44
    unary_function<plugin::QueryCache *, bool>(),
56
45
    session(session_arg), is_transactional(is_transactional_arg) { }
57
46
 
58
47
  inline result_type operator()(argument_type handler)
59
48
  {
60
 
    if (handler->try_fetch_and_send(session, is_transactional))
 
49
    if (handler->tryFetchAndSend(session, is_transactional))
61
50
    {
62
51
      errmsg_printf(ERRMSG_LVL_ERROR,
63
52
                    _("qcache plugin '%s' try_fetch_and_send() failed"),
69
58
};
70
59
 
71
60
class SetIterate
72
 
 : public unary_function<QueryCache *, bool>
 
61
 : public unary_function<plugin::QueryCache *, bool>
73
62
{
74
63
  Session *session;
75
64
  bool is_transactional;
76
65
public:
77
66
  SetIterate(Session *session_arg, bool is_transactional_arg) :
78
 
    unary_function<QueryCache *, bool>(),
 
67
    unary_function<plugin::QueryCache *, bool>(),
79
68
    session(session_arg), is_transactional(is_transactional_arg) { }
80
69
 
81
70
  inline result_type operator()(argument_type handler)
92
81
};
93
82
 
94
83
class InvalidateTableIterate
95
 
 : public unary_function<QueryCache *, bool>
 
84
 : public unary_function<plugin::QueryCache *, bool>
96
85
{
97
86
  Session *session;
98
87
  bool is_transactional;
99
88
public:
100
89
  InvalidateTableIterate(Session *session_arg, bool is_transactional_arg) :
101
 
    unary_function<QueryCache *, bool>(),
 
90
    unary_function<plugin::QueryCache *, bool>(),
102
91
    session(session_arg), is_transactional(is_transactional_arg) { }
103
92
 
104
93
  inline result_type operator()(argument_type handler)
105
94
  {
106
95
 
107
 
    if (handler->invalidate_table(session, is_transactional))
 
96
    if (handler->invalidateTable(session, is_transactional))
108
97
    {
109
98
      errmsg_printf(ERRMSG_LVL_ERROR,
110
 
                    _("qcache plugin '%s' invalidate_table() failed"),
 
99
                    _("qcache plugin '%s' invalidateTable() failed"),
111
100
                    handler->getName().c_str());
112
101
      return true;
113
102
    }
117
106
 
118
107
 
119
108
class InvalidateDbIterate
120
 
 : public unary_function<QueryCache *, bool>
 
109
 : public unary_function<plugin::QueryCache *, bool>
121
110
{
122
111
  Session *session;
123
112
  const char *dbname;
125
114
public:
126
115
  InvalidateDbIterate(Session *session_arg, const char *dbname_arg,
127
116
                      bool is_transactional_arg) :
128
 
    unary_function<QueryCache *, bool>(),
 
117
    unary_function<plugin::QueryCache *, bool>(),
129
118
    session(session_arg), dbname(dbname_arg),
130
119
    is_transactional(is_transactional_arg) { }
131
120
 
132
121
  inline result_type operator()(argument_type handler)
133
122
  {
134
 
    if (handler->invalidate_db(session, dbname, is_transactional))
 
123
    if (handler->invalidateDb(session, dbname, is_transactional))
135
124
    {
136
125
      errmsg_printf(ERRMSG_LVL_ERROR,
137
 
                    _("qcache plugin '%s' invalidate_db() failed"),
 
126
                    _("qcache plugin '%s' invalidateDb() failed"),
138
127
                    handler->getName().c_str());
139
128
      return true;
140
129
    }
143
132
};
144
133
 
145
134
class FlushIterate
146
 
 : public unary_function<QueryCache *, bool>
 
135
 : public unary_function<plugin::QueryCache *, bool>
147
136
{
148
137
  Session *session;
149
138
public:
150
139
  FlushIterate(Session *session_arg) :
151
 
    unary_function<QueryCache *, bool>(), session(session_arg) { }
 
140
    unary_function<plugin::QueryCache *, bool>(), session(session_arg) { }
152
141
 
153
142
  inline result_type operator()(argument_type handler)
154
143
  {
162
151
  }
163
152
};
164
153
 
165
 
/*
166
 
  Following functions:
167
 
 
168
 
    try_fetch_and_send();
169
 
    set();
170
 
    invalidate_table();
171
 
    invalidate_db();
172
 
    flush();
173
 
 
174
 
  are the entry points to the query cache plugin that is called by the
175
 
  rest of the Drizzle server code.
176
 
*/
177
 
 
178
 
bool try_fetch_and_send(Session *session, bool transactional)
 
154
bool plugin::QueryCache::addPlugin(plugin::QueryCache *handler)
 
155
{
 
156
  all_query_cache.push_back(handler);
 
157
  return false;
 
158
}
 
159
 
 
160
void plugin::QueryCache::removePlugin(plugin::QueryCache *handler)
 
161
{
 
162
  all_query_cache.erase(find(all_query_cache.begin(), all_query_cache.end(),
 
163
                        handler));
 
164
}
 
165
 
 
166
 
 
167
bool plugin::QueryCache::tryFetchAndSendDo(Session *session,
 
168
                                           bool transactional)
179
169
{
180
170
  /* Use find_if instead of foreach so that we can collect return codes */
181
 
  vector<QueryCache *>::iterator iter=
 
171
  vector<plugin::QueryCache *>::iterator iter=
182
172
    find_if(all_query_cache.begin(), all_query_cache.end(),
183
173
            TryFetchAndSendIterate(session, transactional));
184
174
  /* If iter is == end() here, that means that all of the plugins returned
188
178
  return iter != all_query_cache.end();
189
179
}
190
180
 
191
 
bool set(Session *session, bool transactional)
 
181
bool plugin::QueryCache::setDo(Session *session, bool transactional)
192
182
{
193
183
  /* Use find_if instead of foreach so that we can collect return codes */
194
 
  vector<QueryCache *>::iterator iter=
 
184
  vector<plugin::QueryCache *>::iterator iter=
195
185
    find_if(all_query_cache.begin(), all_query_cache.end(),
196
186
            SetIterate(session, transactional));
197
187
  /* If iter is == end() here, that means that all of the plugins returned
201
191
  return iter != all_query_cache.end();
202
192
}
203
193
 
204
 
bool invalidate_table(Session *session, bool transactional)
 
194
bool plugin::QueryCache::invalidateTableDo(Session *session,
 
195
                                         bool transactional)
205
196
{
206
197
  /* Use find_if instead of foreach so that we can collect return codes */
207
 
  vector<QueryCache *>::iterator iter=
 
198
  vector<plugin::QueryCache *>::iterator iter=
208
199
    find_if(all_query_cache.begin(), all_query_cache.end(),
209
200
            InvalidateTableIterate(session, transactional));
210
201
  /* If iter is == end() here, that means that all of the plugins returned
214
205
  return iter != all_query_cache.end();
215
206
}
216
207
 
217
 
bool invalidate_db(Session *session, const char *dbname,
218
 
                                         bool transactional)
 
208
bool plugin::QueryCache::invalidateDbDo(Session *session, const char *dbname,
 
209
                                        bool transactional)
219
210
{
220
211
  /* Use find_if instead of foreach so that we can collect return codes */
221
 
  vector<QueryCache *>::iterator iter=
 
212
  vector<plugin::QueryCache *>::iterator iter=
222
213
    find_if(all_query_cache.begin(), all_query_cache.end(),
223
214
            InvalidateDbIterate(session, dbname, transactional));
224
215
  /* If iter is == end() here, that means that all of the plugins returned
228
219
  return iter != all_query_cache.end();
229
220
}
230
221
 
231
 
bool flush(Session *session)
 
222
bool plugin::QueryCache::flushDo(Session *session)
232
223
{
233
224
  /* Use find_if instead of foreach so that we can collect return codes */
234
 
  vector<QueryCache *>::iterator iter=
 
225
  vector<plugin::QueryCache *>::iterator iter=
235
226
    find_if(all_query_cache.begin(), all_query_cache.end(),
236
227
            FlushIterate(session));
237
228
  /* If iter is == end() here, that means that all of the plugins returned
241
232
  return iter != all_query_cache.end();
242
233
}
243
234
 
244
 
} /* namespace query_cache */
245
235
} /* namespace drizzled */
246