20
21
#include "config.h"
21
22
#include "drizzled/plugin/query_cache.h"
22
#include "drizzled/plugin/registry.h"
23
#include "drizzled/errmsg_print.h"
24
25
#include "drizzled/gettext.h"
35
vector<plugin::QueryCache *> all_query_cache;
34
typedef std::vector<plugin::QueryCache *> QueryCaches;
35
QueryCaches all_query_cache;
37
37
/* Namespaces are here to prevent global symbol clashes with these classes */
39
class TryFetchAndSendIterate
40
: public unary_function<plugin::QueryCache *, bool>
43
bool is_transactional;
45
TryFetchAndSendIterate(Session *session_arg, bool is_transactional_arg) :
46
unary_function<plugin::QueryCache *, bool>(),
47
session(session_arg), is_transactional(is_transactional_arg) { }
49
inline result_type operator()(argument_type handler)
51
if (handler->tryFetchAndSend(session, is_transactional))
53
errmsg_printf(ERRMSG_LVL_ERROR,
54
_("qcache plugin '%s' try_fetch_and_send() failed"),
55
handler->getName().c_str());
63
: public unary_function<plugin::QueryCache *, bool>
66
bool is_transactional;
68
SetIterate(Session *session_arg, bool is_transactional_arg) :
69
unary_function<plugin::QueryCache *, bool>(),
70
session(session_arg), is_transactional(is_transactional_arg) { }
72
inline result_type operator()(argument_type handler)
75
if (handler->set(session, is_transactional))
77
errmsg_printf(ERRMSG_LVL_ERROR, _("qcache plugin '%s' set() failed"),
78
handler->getName().c_str());
85
class InvalidateTableIterate
86
: public unary_function<plugin::QueryCache *, bool>
89
bool is_transactional;
91
InvalidateTableIterate(Session *session_arg, bool is_transactional_arg) :
92
unary_function<plugin::QueryCache *, bool>(),
93
session(session_arg), is_transactional(is_transactional_arg) { }
95
inline result_type operator()(argument_type handler)
98
if (handler->invalidateTable(session, is_transactional))
100
errmsg_printf(ERRMSG_LVL_ERROR,
101
_("qcache plugin '%s' invalidateTable() failed"),
102
handler->getName().c_str());
110
class InvalidateDbIterate
111
: public unary_function<plugin::QueryCache *, bool>
115
bool is_transactional;
117
InvalidateDbIterate(Session *session_arg, const char *dbname_arg,
118
bool is_transactional_arg) :
119
unary_function<plugin::QueryCache *, bool>(),
120
session(session_arg), dbname(dbname_arg),
121
is_transactional(is_transactional_arg) { }
123
inline result_type operator()(argument_type handler)
125
if (handler->invalidateDb(session, dbname, is_transactional))
127
errmsg_printf(ERRMSG_LVL_ERROR,
128
_("qcache plugin '%s' invalidateDb() failed"),
129
handler->getName().c_str());
137
: public unary_function<plugin::QueryCache *, bool>
141
FlushIterate(Session *session_arg) :
142
unary_function<plugin::QueryCache *, bool>(), session(session_arg) { }
144
inline result_type operator()(argument_type handler)
146
if (handler->flush(session))
148
errmsg_printf(ERRMSG_LVL_ERROR, _("qcache plugin '%s' flush() failed"),
149
handler->getName().c_str());
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();
156
178
bool plugin::QueryCache::addPlugin(plugin::QueryCache *handler)
162
184
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,
172
/* Use find_if instead of foreach so that we can collect return codes */
173
vector<plugin::QueryCache *>::iterator iter=
174
find_if(all_query_cache.begin(), all_query_cache.end(),
175
TryFetchAndSendIterate(session, transactional));
176
/* If iter is == end() here, that means that all of the plugins returned
177
* false, which in this case means they all succeeded. Since we want to
178
* return false on success, we return the value of the two being !=
180
return iter != all_query_cache.end();
183
bool plugin::QueryCache::setDo(Session *session, bool transactional)
185
/* Use find_if instead of foreach so that we can collect return codes */
186
vector<plugin::QueryCache *>::iterator iter=
187
find_if(all_query_cache.begin(), all_query_cache.end(),
188
SetIterate(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 plugin::QueryCache::invalidateTableDo(Session *session,
199
/* 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=
215
find_if(all_query_cache.begin(), all_query_cache.end(),
216
InvalidateDbIterate(session, dbname, transactional));
217
/* If iter is == end() here, that means that all of the plugins returned
218
* false, which in this case means they all succeeded. Since we want to
219
* return false on success, we return the value of the two being !=
221
return iter != all_query_cache.end();
224
bool plugin::QueryCache::flushDo(Session *session)
226
/* Use find_if instead of foreach so that we can collect return codes */
227
vector<plugin::QueryCache *>::iterator iter=
228
find_if(all_query_cache.begin(), all_query_cache.end(),
229
FlushIterate(session));
230
/* If iter is == end() here, that means that all of the plugins returned
231
* false, which in this case means they all succeeded. Since we want to
232
* return false on success, we return the value of the two being !=
234
return iter != all_query_cache.end();
186
all_query_cache.erase(std::find(all_query_cache.begin(), all_query_cache.end(),
237
190
} /* namespace drizzled */