1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
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; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#include <drizzled/server_includes.h>
21
#include <drizzled/qcache.h>
22
#include <drizzled/gettext.h>
23
#include "drizzled/plugin_registry.h"
28
static vector<QueryCache *> all_query_cache;
30
void add_query_cache(QueryCache *handler)
32
all_query_cache.push_back(handler);
35
void remove_query_cache(QueryCache *handler)
37
all_query_cache.erase(find(all_query_cache.begin(), all_query_cache.end(),
43
/* Namespaces are here to prevent global symbol clashes with these classes */
46
namespace query_cache {
48
class TryFetchAndSendIterate
49
: public unary_function<QueryCache *, bool>
52
bool is_transactional;
54
TryFetchAndSendIterate(Session *session_arg, bool is_transactional_arg) :
55
unary_function<QueryCache *, bool>(),
56
session(session_arg), is_transactional(is_transactional_arg) { }
58
inline result_type operator()(argument_type handler)
60
if (handler->try_fetch_and_send(session, is_transactional))
62
errmsg_printf(ERRMSG_LVL_ERROR,
63
_("qcache plugin '%s' try_fetch_and_send() failed"),
64
handler->getName().c_str());
72
: public unary_function<QueryCache *, bool>
75
bool is_transactional;
77
SetIterate(Session *session_arg, bool is_transactional_arg) :
78
unary_function<QueryCache *, bool>(),
79
session(session_arg), is_transactional(is_transactional_arg) { }
81
inline result_type operator()(argument_type handler)
84
if (handler->set(session, is_transactional))
86
errmsg_printf(ERRMSG_LVL_ERROR, _("qcache plugin '%s' set() failed"),
87
handler->getName().c_str());
94
class InvalidateTableIterate
95
: public unary_function<QueryCache *, bool>
98
bool is_transactional;
100
InvalidateTableIterate(Session *session_arg, bool is_transactional_arg) :
101
unary_function<QueryCache *, bool>(),
102
session(session_arg), is_transactional(is_transactional_arg) { }
104
inline result_type operator()(argument_type handler)
107
if (handler->invalidate_table(session, is_transactional))
109
errmsg_printf(ERRMSG_LVL_ERROR,
110
_("qcache plugin '%s' invalidate_table() failed"),
111
handler->getName().c_str());
119
class InvalidateDbIterate
120
: public unary_function<QueryCache *, bool>
124
bool is_transactional;
126
InvalidateDbIterate(Session *session_arg, const char *dbname_arg,
127
bool is_transactional_arg) :
128
unary_function<QueryCache *, bool>(),
129
session(session_arg), dbname(dbname_arg),
130
is_transactional(is_transactional_arg) { }
132
inline result_type operator()(argument_type handler)
134
if (handler->invalidate_db(session, dbname, is_transactional))
136
errmsg_printf(ERRMSG_LVL_ERROR,
137
_("qcache plugin '%s' invalidate_db() failed"),
138
handler->getName().c_str());
146
: public unary_function<QueryCache *, bool>
150
FlushIterate(Session *session_arg) :
151
unary_function<QueryCache *, bool>(), session(session_arg) { }
153
inline result_type operator()(argument_type handler)
155
if (handler->flush(session))
157
errmsg_printf(ERRMSG_LVL_ERROR, _("qcache plugin '%s' flush() failed"),
158
handler->getName().c_str());
165
} /* namespace query_cache */
166
} /* namespace drizzled */
168
using namespace drizzled::query_cache;
173
drizzle_qcache_try_fetch_and_send();
174
drizzle_qcache_set();
175
drizzle_qcache_invalidate_table();
176
drizzle_qcache_invalidate_db();
177
drizzle_qcache_flush();
179
are the entry points to the query cache plugin that is called by the
180
rest of the Drizzle server code.
183
bool drizzle_qcache_try_fetch_and_send(Session *session, bool transactional)
185
/* Use find_if instead of foreach so that we can collect return codes */
186
vector<QueryCache *>::iterator iter=
187
find_if(all_query_cache.begin(), all_query_cache.end(),
188
TryFetchAndSendIterate(session, transactional));
189
/* If iter is == end() here, that means that all of the plugins returned
190
* false, which in this case means they all succeeded. Since we want to
191
* return false on success, we return the value of the two being !=
193
return iter != all_query_cache.end();
196
bool drizzle_qcache_set(Session *session, bool transactional)
198
/* Use find_if instead of foreach so that we can collect return codes */
199
vector<QueryCache *>::iterator iter=
200
find_if(all_query_cache.begin(), all_query_cache.end(),
201
SetIterate(session, transactional));
202
/* If iter is == end() here, that means that all of the plugins returned
203
* false, which in this case means they all succeeded. Since we want to
204
* return false on success, we return the value of the two being !=
206
return iter != all_query_cache.end();
209
bool drizzle_qcache_invalidate_table(Session *session, bool transactional)
211
/* Use find_if instead of foreach so that we can collect return codes */
212
vector<QueryCache *>::iterator iter=
213
find_if(all_query_cache.begin(), all_query_cache.end(),
214
InvalidateTableIterate(session, transactional));
215
/* If iter is == end() here, that means that all of the plugins returned
216
* false, which in this case means they all succeeded. Since we want to
217
* return false on success, we return the value of the two being !=
219
return iter != all_query_cache.end();
222
bool drizzle_qcache_invalidate_db(Session *session, const char *dbname,
225
/* Use find_if instead of foreach so that we can collect return codes */
226
vector<QueryCache *>::iterator iter=
227
find_if(all_query_cache.begin(), all_query_cache.end(),
228
InvalidateDbIterate(session, dbname, transactional));
229
/* If iter is == end() here, that means that all of the plugins returned
230
* false, which in this case means they all succeeded. Since we want to
231
* return false on success, we return the value of the two being !=
233
return iter != all_query_cache.end();
236
bool drizzle_qcache_flush(Session *session)
238
/* Use find_if instead of foreach so that we can collect return codes */
239
vector<QueryCache *>::iterator iter=
240
find_if(all_query_cache.begin(), all_query_cache.end(),
241
FlushIterate(session));
242
/* If iter is == end() here, that means that all of the plugins returned
243
* false, which in this case means they all succeeded. Since we want to
244
* return false on success, we return the value of the two being !=
246
return iter != all_query_cache.end();