18
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#include "drizzled/server_includes.h"
22
21
#include "drizzled/plugin/query_cache.h"
23
#include "drizzled/errmsg_print.h"
22
#include "drizzled/plugin/registry.h"
25
24
#include "drizzled/gettext.h"
34
typedef std::vector<plugin::QueryCache *> QueryCaches;
35
QueryCaches all_query_cache;
33
vector<plugin::QueryCache *> all_query_cache;
37
35
/* 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();
37
class TryFetchAndSendIterate
38
: public unary_function<plugin::QueryCache *, bool>
41
bool is_transactional;
43
TryFetchAndSendIterate(Session *session_arg, bool is_transactional_arg) :
44
unary_function<plugin::QueryCache *, bool>(),
45
session(session_arg), is_transactional(is_transactional_arg) { }
47
inline result_type operator()(argument_type handler)
49
if (handler->tryFetchAndSend(session, is_transactional))
51
errmsg_printf(ERRMSG_LVL_ERROR,
52
_("qcache plugin '%s' try_fetch_and_send() failed"),
53
handler->getName().c_str());
61
: public unary_function<plugin::QueryCache *, bool>
64
bool is_transactional;
66
SetIterate(Session *session_arg, bool is_transactional_arg) :
67
unary_function<plugin::QueryCache *, bool>(),
68
session(session_arg), is_transactional(is_transactional_arg) { }
70
inline result_type operator()(argument_type handler)
73
if (handler->set(session, is_transactional))
75
errmsg_printf(ERRMSG_LVL_ERROR, _("qcache plugin '%s' set() failed"),
76
handler->getName().c_str());
83
class InvalidateTableIterate
84
: public unary_function<plugin::QueryCache *, bool>
87
bool is_transactional;
89
InvalidateTableIterate(Session *session_arg, bool is_transactional_arg) :
90
unary_function<plugin::QueryCache *, bool>(),
91
session(session_arg), is_transactional(is_transactional_arg) { }
93
inline result_type operator()(argument_type handler)
96
if (handler->invalidateTable(session, is_transactional))
98
errmsg_printf(ERRMSG_LVL_ERROR,
99
_("qcache plugin '%s' invalidateTable() failed"),
100
handler->getName().c_str());
108
class InvalidateDbIterate
109
: public unary_function<plugin::QueryCache *, bool>
113
bool is_transactional;
115
InvalidateDbIterate(Session *session_arg, const char *dbname_arg,
116
bool is_transactional_arg) :
117
unary_function<plugin::QueryCache *, bool>(),
118
session(session_arg), dbname(dbname_arg),
119
is_transactional(is_transactional_arg) { }
121
inline result_type operator()(argument_type handler)
123
if (handler->invalidateDb(session, dbname, is_transactional))
125
errmsg_printf(ERRMSG_LVL_ERROR,
126
_("qcache plugin '%s' invalidateDb() failed"),
127
handler->getName().c_str());
135
: public unary_function<plugin::QueryCache *, bool>
139
FlushIterate(Session *session_arg) :
140
unary_function<plugin::QueryCache *, bool>(), session(session_arg) { }
142
inline result_type operator()(argument_type handler)
144
if (handler->flush(session))
146
errmsg_printf(ERRMSG_LVL_ERROR, _("qcache plugin '%s' flush() failed"),
147
handler->getName().c_str());
178
154
bool plugin::QueryCache::addPlugin(plugin::QueryCache *handler)
184
160
void plugin::QueryCache::removePlugin(plugin::QueryCache *handler)
186
all_query_cache.erase(std::find(all_query_cache.begin(), all_query_cache.end(),
162
all_query_cache.erase(find(all_query_cache.begin(), all_query_cache.end(),
167
bool plugin::QueryCache::tryFetchAndSendDo(Session *session,
170
/* Use find_if instead of foreach so that we can collect return codes */
171
vector<plugin::QueryCache *>::iterator iter=
172
find_if(all_query_cache.begin(), all_query_cache.end(),
173
TryFetchAndSendIterate(session, transactional));
174
/* If iter is == end() here, that means that all of the plugins returned
175
* false, which in this case means they all succeeded. Since we want to
176
* return false on success, we return the value of the two being !=
178
return iter != all_query_cache.end();
181
bool plugin::QueryCache::setDo(Session *session, bool transactional)
183
/* Use find_if instead of foreach so that we can collect return codes */
184
vector<plugin::QueryCache *>::iterator iter=
185
find_if(all_query_cache.begin(), all_query_cache.end(),
186
SetIterate(session, transactional));
187
/* If iter is == end() here, that means that all of the plugins returned
188
* false, which in this case means they all succeeded. Since we want to
189
* return false on success, we return the value of the two being !=
191
return iter != all_query_cache.end();
194
bool plugin::QueryCache::invalidateTableDo(Session *session,
197
/* Use find_if instead of foreach so that we can collect return codes */
198
vector<plugin::QueryCache *>::iterator iter=
199
find_if(all_query_cache.begin(), all_query_cache.end(),
200
InvalidateTableIterate(session, transactional));
201
/* If iter is == end() here, that means that all of the plugins returned
202
* false, which in this case means they all succeeded. Since we want to
203
* return false on success, we return the value of the two being !=
205
return iter != all_query_cache.end();
208
bool plugin::QueryCache::invalidateDbDo(Session *session, const char *dbname,
211
/* Use find_if instead of foreach so that we can collect return codes */
212
vector<plugin::QueryCache *>::iterator iter=
213
find_if(all_query_cache.begin(), all_query_cache.end(),
214
InvalidateDbIterate(session, dbname, 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 plugin::QueryCache::flushDo(Session *session)
224
/* Use find_if instead of foreach so that we can collect return codes */
225
vector<plugin::QueryCache *>::iterator iter=
226
find_if(all_query_cache.begin(), all_query_cache.end(),
227
FlushIterate(session));
228
/* If iter is == end() here, that means that all of the plugins returned
229
* false, which in this case means they all succeeded. Since we want to
230
* return false on success, we return the value of the two being !=
232
return iter != all_query_cache.end();
190
235
} /* namespace drizzled */