17
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#include "drizzled/plugin/query_cache.h"
22
#include "drizzled/plugin/registry.h"
24
#include "drizzled/gettext.h"
20
#include <drizzled/server_includes.h>
21
#include <drizzled/qcache.h>
22
#include <drizzled/gettext.h>
23
#include "drizzled/plugin_registry.h"
30
26
using namespace std;
35
vector<plugin::QueryCache *> all_query_cache;
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(),
37
43
/* Namespaces are here to prevent global symbol clashes with these classes */
46
namespace query_cache {
39
48
class TryFetchAndSendIterate
40
: public unary_function<plugin::QueryCache *, bool>
49
: public unary_function<QueryCache *, bool>
43
52
bool is_transactional;
45
54
TryFetchAndSendIterate(Session *session_arg, bool is_transactional_arg) :
46
unary_function<plugin::QueryCache *, bool>(),
55
unary_function<QueryCache *, bool>(),
47
56
session(session_arg), is_transactional(is_transactional_arg) { }
49
58
inline result_type operator()(argument_type handler)
51
if (handler->tryFetchAndSend(session, is_transactional))
60
if (handler->try_fetch_and_send(session, is_transactional))
53
62
errmsg_printf(ERRMSG_LVL_ERROR,
54
63
_("qcache plugin '%s' try_fetch_and_send() failed"),
63
: public unary_function<plugin::QueryCache *, bool>
72
: public unary_function<QueryCache *, bool>
66
75
bool is_transactional;
68
77
SetIterate(Session *session_arg, bool is_transactional_arg) :
69
unary_function<plugin::QueryCache *, bool>(),
78
unary_function<QueryCache *, bool>(),
70
79
session(session_arg), is_transactional(is_transactional_arg) { }
72
81
inline result_type operator()(argument_type handler)
85
94
class InvalidateTableIterate
86
: public unary_function<plugin::QueryCache *, bool>
95
: public unary_function<QueryCache *, bool>
89
98
bool is_transactional;
91
100
InvalidateTableIterate(Session *session_arg, bool is_transactional_arg) :
92
unary_function<plugin::QueryCache *, bool>(),
101
unary_function<QueryCache *, bool>(),
93
102
session(session_arg), is_transactional(is_transactional_arg) { }
95
104
inline result_type operator()(argument_type handler)
98
if (handler->invalidateTable(session, is_transactional))
107
if (handler->invalidate_table(session, is_transactional))
100
109
errmsg_printf(ERRMSG_LVL_ERROR,
101
_("qcache plugin '%s' invalidateTable() failed"),
110
_("qcache plugin '%s' invalidate_table() failed"),
102
111
handler->getName().c_str());
117
126
InvalidateDbIterate(Session *session_arg, const char *dbname_arg,
118
127
bool is_transactional_arg) :
119
unary_function<plugin::QueryCache *, bool>(),
128
unary_function<QueryCache *, bool>(),
120
129
session(session_arg), dbname(dbname_arg),
121
130
is_transactional(is_transactional_arg) { }
123
132
inline result_type operator()(argument_type handler)
125
if (handler->invalidateDb(session, dbname, is_transactional))
134
if (handler->invalidate_db(session, dbname, is_transactional))
127
136
errmsg_printf(ERRMSG_LVL_ERROR,
128
_("qcache plugin '%s' invalidateDb() failed"),
137
_("qcache plugin '%s' invalidate_db() failed"),
129
138
handler->getName().c_str());
136
145
class FlushIterate
137
: public unary_function<plugin::QueryCache *, bool>
146
: public unary_function<QueryCache *, bool>
139
148
Session *session;
141
150
FlushIterate(Session *session_arg) :
142
unary_function<plugin::QueryCache *, bool>(), session(session_arg) { }
151
unary_function<QueryCache *, bool>(), session(session_arg) { }
144
153
inline result_type operator()(argument_type handler)
156
bool plugin::QueryCache::addPlugin(plugin::QueryCache *handler)
158
all_query_cache.push_back(handler);
162
void plugin::QueryCache::removePlugin(plugin::QueryCache *handler)
164
all_query_cache.erase(find(all_query_cache.begin(), all_query_cache.end(),
169
bool plugin::QueryCache::tryFetchAndSendDo(Session *session,
168
try_fetch_and_send();
174
are the entry points to the query cache plugin that is called by the
175
rest of the Drizzle server code.
178
bool try_fetch_and_send(Session *session, bool transactional)
172
180
/* Use find_if instead of foreach so that we can collect return codes */
173
vector<plugin::QueryCache *>::iterator iter=
181
vector<QueryCache *>::iterator iter=
174
182
find_if(all_query_cache.begin(), all_query_cache.end(),
175
183
TryFetchAndSendIterate(session, transactional));
176
184
/* If iter is == end() here, that means that all of the plugins returned
180
188
return iter != all_query_cache.end();
183
bool plugin::QueryCache::setDo(Session *session, bool transactional)
191
bool set(Session *session, bool transactional)
185
193
/* Use find_if instead of foreach so that we can collect return codes */
186
vector<plugin::QueryCache *>::iterator iter=
194
vector<QueryCache *>::iterator iter=
187
195
find_if(all_query_cache.begin(), all_query_cache.end(),
188
196
SetIterate(session, transactional));
189
197
/* If iter is == end() here, that means that all of the plugins returned
193
201
return iter != all_query_cache.end();
196
bool plugin::QueryCache::invalidateTableDo(Session *session,
204
bool invalidate_table(Session *session, bool transactional)
206
/* Use find_if instead of foreach so that we can collect return codes */
207
vector<QueryCache *>::iterator iter=
208
find_if(all_query_cache.begin(), all_query_cache.end(),
209
InvalidateTableIterate(session, transactional));
210
/* If iter is == end() here, that means that all of the plugins returned
211
* false, which in this case means they all succeeded. Since we want to
212
* return false on success, we return the value of the two being !=
214
return iter != all_query_cache.end();
217
bool invalidate_db(Session *session, const char *dbname,
197
218
bool transactional)
199
220
/* Use find_if instead of foreach so that we can collect return codes */
200
vector<plugin::QueryCache *>::iterator iter=
201
find_if(all_query_cache.begin(), all_query_cache.end(),
202
InvalidateTableIterate(session, transactional));
203
/* If iter is == end() here, that means that all of the plugins returned
204
* false, which in this case means they all succeeded. Since we want to
205
* return false on success, we return the value of the two being !=
207
return iter != all_query_cache.end();
210
bool plugin::QueryCache::invalidateDbDo(Session *session, const char *dbname,
213
/* Use find_if instead of foreach so that we can collect return codes */
214
vector<plugin::QueryCache *>::iterator iter=
221
vector<QueryCache *>::iterator iter=
215
222
find_if(all_query_cache.begin(), all_query_cache.end(),
216
223
InvalidateDbIterate(session, dbname, transactional));
217
224
/* If iter is == end() here, that means that all of the plugins returned
221
228
return iter != all_query_cache.end();
224
bool plugin::QueryCache::flushDo(Session *session)
231
bool flush(Session *session)
226
233
/* Use find_if instead of foreach so that we can collect return codes */
227
vector<plugin::QueryCache *>::iterator iter=
234
vector<QueryCache *>::iterator iter=
228
235
find_if(all_query_cache.begin(), all_query_cache.end(),
229
236
FlushIterate(session));
230
237
/* If iter is == end() here, that means that all of the plugins returned