18
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
#include "drizzled/plugin/query_cache.h"
23
#include "drizzled/errmsg_print.h"
25
#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"
34
typedef std::vector<plugin::QueryCache *> QueryCaches;
35
QueryCaches 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 */
40
: public std::unary_function<plugin::QueryCache *, bool>
44
IsCachedIterate(Session* session_arg) :
45
std::unary_function<plugin::QueryCache *, bool>(),
46
session(session_arg) { }
48
inline result_type operator()(argument_type handler)
50
return handler->doIsCached(session);
54
bool plugin::QueryCache::isCached(Session *session)
56
/* Use find_if instead of foreach so that we can collect return codes */
57
QueryCaches::iterator iter=
58
std::find_if(all_query_cache.begin(), all_query_cache.end(),
59
IsCachedIterate(session));
60
/* If iter is == end() here, that means that all of the plugins returned
61
* false, which in this case means they all succeeded. Since we want to
62
* return false on success, we return the value of the two being !=
64
return iter != all_query_cache.end();
68
class SendCachedResultsetIterate
69
: public std::unary_function<plugin::QueryCache *, bool>
73
SendCachedResultsetIterate(Session *session_arg) :
74
std::unary_function<plugin::QueryCache *, bool>(),
75
session(session_arg) { }
77
inline result_type operator()(argument_type handler)
79
return handler->doSendCachedResultset(session);
82
bool plugin::QueryCache::sendCachedResultset(Session *session)
84
/* Use find_if instead of foreach so that we can collect return codes */
85
QueryCaches::iterator iter=
86
std::find_if(all_query_cache.begin(), all_query_cache.end(),
87
SendCachedResultsetIterate(session));
88
/* If iter is == end() here, that means that all of the plugins returned
89
* false, which in this case means they all succeeded. Since we want to
90
* return false on success, we return the value of the two being !=
92
return iter != all_query_cache.end();
95
class PrepareResultsetIterate : public std::unary_function<plugin::QueryCache *, bool>
99
PrepareResultsetIterate(Session *session_arg) :
100
std::unary_function<plugin::QueryCache *, bool>(),
101
session(session_arg) { }
103
inline result_type operator()(argument_type handler)
105
return handler->doPrepareResultset(session);
108
bool plugin::QueryCache::prepareResultset(Session *session)
110
/* Use find_if instead of foreach so that we can collect return codes */
111
QueryCaches::iterator iter=
112
std::find_if(all_query_cache.begin(), all_query_cache.end(),
113
PrepareResultsetIterate(session));
114
/* If iter is == end() here, that means that all of the plugins returned
115
* false, which in this case means they all succeeded. Since we want to
116
* return false on success, we return the value of the two being !=
118
return iter != all_query_cache.end();
121
class SetResultsetIterate : public std::unary_function<plugin::QueryCache *, bool>
125
SetResultsetIterate(Session *session_arg) :
126
std::unary_function<plugin::QueryCache *, bool>(),
127
session(session_arg) { }
129
inline result_type operator()(argument_type handler)
131
return handler->doSetResultset(session);
135
bool plugin::QueryCache::setResultset(Session *session)
137
/* Use find_if instead of foreach so that we can collect return codes */
138
QueryCaches::iterator iter=
139
std::find_if(all_query_cache.begin(), all_query_cache.end(),
140
SetResultsetIterate(session));
141
/* If iter is == end() here, that means that all of the plugins returned
142
* false, which in this case means they all succeeded. Since we want to
143
* return false on success, we return the value of the two being !=
145
return iter != all_query_cache.end();
148
class InsertRecordIterate
149
: public std::unary_function<plugin::QueryCache *, bool>
154
InsertRecordIterate(Session *session_arg, List<Item> &item_arg) :
155
std::unary_function<plugin::QueryCache *, bool>(),
156
session(session_arg), item(item_arg) { }
158
inline result_type operator()(argument_type handler)
160
return handler->doInsertRecord(session, item);
163
bool plugin::QueryCache::insertRecord(Session *session, List<Item> &items)
165
/* Use find_if instead of foreach so that we can collect return codes */
166
QueryCaches::iterator iter=
167
std::find_if(all_query_cache.begin(), all_query_cache.end(),
168
InsertRecordIterate(session, items));
169
/* If iter is == end() here, that means that all of the plugins returned
170
* false, which in this case means they all succeeded. Since we want to
171
* return false on success, we return the value of the two being !=
173
return iter != all_query_cache.end();
178
bool plugin::QueryCache::addPlugin(plugin::QueryCache *handler)
180
all_query_cache.push_back(handler);
184
void plugin::QueryCache::removePlugin(plugin::QueryCache *handler)
186
all_query_cache.erase(std::find(all_query_cache.begin(), all_query_cache.end(),
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());
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)
180
/* Use find_if instead of foreach so that we can collect return codes */
181
vector<QueryCache *>::iterator iter=
182
find_if(all_query_cache.begin(), all_query_cache.end(),
183
TryFetchAndSendIterate(session, transactional));
184
/* If iter is == end() here, that means that all of the plugins returned
185
* false, which in this case means they all succeeded. Since we want to
186
* return false on success, we return the value of the two being !=
188
return iter != all_query_cache.end();
191
bool set(Session *session, bool transactional)
193
/* Use find_if instead of foreach so that we can collect return codes */
194
vector<QueryCache *>::iterator iter=
195
find_if(all_query_cache.begin(), all_query_cache.end(),
196
SetIterate(session, transactional));
197
/* If iter is == end() here, that means that all of the plugins returned
198
* false, which in this case means they all succeeded. Since we want to
199
* return false on success, we return the value of the two being !=
201
return iter != all_query_cache.end();
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,
220
/* Use find_if instead of foreach so that we can collect return codes */
221
vector<QueryCache *>::iterator iter=
222
find_if(all_query_cache.begin(), all_query_cache.end(),
223
InvalidateDbIterate(session, dbname, transactional));
224
/* If iter is == end() here, that means that all of the plugins returned
225
* false, which in this case means they all succeeded. Since we want to
226
* return false on success, we return the value of the two being !=
228
return iter != all_query_cache.end();
231
bool flush(Session *session)
233
/* Use find_if instead of foreach so that we can collect return codes */
234
vector<QueryCache *>::iterator iter=
235
find_if(all_query_cache.begin(), all_query_cache.end(),
236
FlushIterate(session));
237
/* If iter is == end() here, that means that all of the plugins returned
238
* false, which in this case means they all succeeded. Since we want to
239
* return false on success, we return the value of the two being !=
241
return iter != all_query_cache.end();
244
} /* namespace query_cache */
190
245
} /* namespace drizzled */