17
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>
20
#include "drizzled/server_includes.h"
21
#include "drizzled/plugin/query_cache.h"
23
22
#include "drizzled/plugin/registry.h"
24
#include "drizzled/gettext.h"
26
28
using namespace std;
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(),
33
vector<plugin::QueryCache *> all_query_cache;
43
35
/* Namespaces are here to prevent global symbol clashes with these classes */
46
namespace query_cache {
48
37
class TryFetchAndSendIterate
49
: public unary_function<QueryCache *, bool>
38
: public unary_function<plugin::QueryCache *, bool>
52
41
bool is_transactional;
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) { }
58
47
inline result_type operator()(argument_type handler)
60
if (handler->try_fetch_and_send(session, is_transactional))
49
if (handler->tryFetchAndSend(session, is_transactional))
62
51
errmsg_printf(ERRMSG_LVL_ERROR,
63
52
_("qcache plugin '%s' try_fetch_and_send() failed"),
72
: public unary_function<QueryCache *, bool>
61
: public unary_function<plugin::QueryCache *, bool>
75
64
bool is_transactional;
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) { }
81
70
inline result_type operator()(argument_type handler)
94
83
class InvalidateTableIterate
95
: public unary_function<QueryCache *, bool>
84
: public unary_function<plugin::QueryCache *, bool>
98
87
bool is_transactional;
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) { }
104
93
inline result_type operator()(argument_type handler)
107
if (handler->invalidate_table(session, is_transactional))
96
if (handler->invalidateTable(session, is_transactional))
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());
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) { }
132
121
inline result_type operator()(argument_type handler)
134
if (handler->invalidate_db(session, dbname, is_transactional))
123
if (handler->invalidateDb(session, dbname, is_transactional))
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());
145
134
class FlushIterate
146
: public unary_function<QueryCache *, bool>
135
: public unary_function<plugin::QueryCache *, bool>
148
137
Session *session;
150
139
FlushIterate(Session *session_arg) :
151
unary_function<QueryCache *, bool>(), session(session_arg) { }
140
unary_function<plugin::QueryCache *, bool>(), session(session_arg) { }
153
142
inline result_type operator()(argument_type handler)
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)
154
bool plugin::QueryCache::addPlugin(plugin::QueryCache *handler)
156
all_query_cache.push_back(handler);
160
void plugin::QueryCache::removePlugin(plugin::QueryCache *handler)
162
all_query_cache.erase(find(all_query_cache.begin(), all_query_cache.end(),
167
bool plugin::QueryCache::tryFetchAndSendDo(Session *session,
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();
191
bool set(Session *session, bool transactional)
181
bool plugin::QueryCache::setDo(Session *session, bool transactional)
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();
204
bool invalidate_table(Session *session, bool transactional)
194
bool plugin::QueryCache::invalidateTableDo(Session *session,
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();
217
bool invalidate_db(Session *session, const char *dbname,
208
bool plugin::QueryCache::invalidateDbDo(Session *session, const char *dbname,
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();
231
bool flush(Session *session)
222
bool plugin::QueryCache::flushDo(Session *session)
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