34
typedef std::vector<plugin::QueryCache *> QueryCaches;
35
QueryCaches all_query_cache;
36
vector<plugin::QueryCache *> all_query_cache;
37
38
/* 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();
40
class TryFetchAndSendIterate
41
: public unary_function<plugin::QueryCache *, bool>
44
bool is_transactional;
46
TryFetchAndSendIterate(Session *session_arg, bool is_transactional_arg) :
47
unary_function<plugin::QueryCache *, bool>(),
48
session(session_arg), is_transactional(is_transactional_arg) { }
50
inline result_type operator()(argument_type handler)
52
if (handler->tryFetchAndSend(session, is_transactional))
54
errmsg_printf(ERRMSG_LVL_ERROR,
55
_("qcache plugin '%s' try_fetch_and_send() failed"),
56
handler->getName().c_str());
64
: public unary_function<plugin::QueryCache *, bool>
67
bool is_transactional;
69
SetIterate(Session *session_arg, bool is_transactional_arg) :
70
unary_function<plugin::QueryCache *, bool>(),
71
session(session_arg), is_transactional(is_transactional_arg) { }
73
inline result_type operator()(argument_type handler)
76
if (handler->set(session, is_transactional))
78
errmsg_printf(ERRMSG_LVL_ERROR, _("qcache plugin '%s' set() failed"),
79
handler->getName().c_str());
86
class InvalidateTableIterate
87
: public unary_function<plugin::QueryCache *, bool>
90
bool is_transactional;
92
InvalidateTableIterate(Session *session_arg, bool is_transactional_arg) :
93
unary_function<plugin::QueryCache *, bool>(),
94
session(session_arg), is_transactional(is_transactional_arg) { }
96
inline result_type operator()(argument_type handler)
99
if (handler->invalidateTable(session, is_transactional))
101
errmsg_printf(ERRMSG_LVL_ERROR,
102
_("qcache plugin '%s' invalidateTable() failed"),
103
handler->getName().c_str());
111
class InvalidateDbIterate
112
: public unary_function<plugin::QueryCache *, bool>
116
bool is_transactional;
118
InvalidateDbIterate(Session *session_arg, const char *dbname_arg,
119
bool is_transactional_arg) :
120
unary_function<plugin::QueryCache *, bool>(),
121
session(session_arg), dbname(dbname_arg),
122
is_transactional(is_transactional_arg) { }
124
inline result_type operator()(argument_type handler)
126
if (handler->invalidateDb(session, dbname, is_transactional))
128
errmsg_printf(ERRMSG_LVL_ERROR,
129
_("qcache plugin '%s' invalidateDb() failed"),
130
handler->getName().c_str());
138
: public unary_function<plugin::QueryCache *, bool>
142
FlushIterate(Session *session_arg) :
143
unary_function<plugin::QueryCache *, bool>(), session(session_arg) { }
145
inline result_type operator()(argument_type handler)
147
if (handler->flush(session))
149
errmsg_printf(ERRMSG_LVL_ERROR, _("qcache plugin '%s' flush() failed"),
150
handler->getName().c_str());
178
157
bool plugin::QueryCache::addPlugin(plugin::QueryCache *handler)
184
163
void plugin::QueryCache::removePlugin(plugin::QueryCache *handler)
186
all_query_cache.erase(std::find(all_query_cache.begin(), all_query_cache.end(),
165
all_query_cache.erase(find(all_query_cache.begin(), all_query_cache.end(),
170
bool plugin::QueryCache::tryFetchAndSendDo(Session *session,
173
/* Use find_if instead of foreach so that we can collect return codes */
174
vector<plugin::QueryCache *>::iterator iter=
175
find_if(all_query_cache.begin(), all_query_cache.end(),
176
TryFetchAndSendIterate(session, transactional));
177
/* If iter is == end() here, that means that all of the plugins returned
178
* false, which in this case means they all succeeded. Since we want to
179
* return false on success, we return the value of the two being !=
181
return iter != all_query_cache.end();
184
bool plugin::QueryCache::setDo(Session *session, bool transactional)
186
/* Use find_if instead of foreach so that we can collect return codes */
187
vector<plugin::QueryCache *>::iterator iter=
188
find_if(all_query_cache.begin(), all_query_cache.end(),
189
SetIterate(session, transactional));
190
/* If iter is == end() here, that means that all of the plugins returned
191
* false, which in this case means they all succeeded. Since we want to
192
* return false on success, we return the value of the two being !=
194
return iter != all_query_cache.end();
197
bool plugin::QueryCache::invalidateTableDo(Session *session,
200
/* Use find_if instead of foreach so that we can collect return codes */
201
vector<plugin::QueryCache *>::iterator iter=
202
find_if(all_query_cache.begin(), all_query_cache.end(),
203
InvalidateTableIterate(session, transactional));
204
/* If iter is == end() here, that means that all of the plugins returned
205
* false, which in this case means they all succeeded. Since we want to
206
* return false on success, we return the value of the two being !=
208
return iter != all_query_cache.end();
211
bool plugin::QueryCache::invalidateDbDo(Session *session, const char *dbname,
214
/* Use find_if instead of foreach so that we can collect return codes */
215
vector<plugin::QueryCache *>::iterator iter=
216
find_if(all_query_cache.begin(), all_query_cache.end(),
217
InvalidateDbIterate(session, dbname, transactional));
218
/* If iter is == end() here, that means that all of the plugins returned
219
* false, which in this case means they all succeeded. Since we want to
220
* return false on success, we return the value of the two being !=
222
return iter != all_query_cache.end();
225
bool plugin::QueryCache::flushDo(Session *session)
227
/* Use find_if instead of foreach so that we can collect return codes */
228
vector<plugin::QueryCache *>::iterator iter=
229
find_if(all_query_cache.begin(), all_query_cache.end(),
230
FlushIterate(session));
231
/* If iter is == end() here, that means that all of the plugins returned
232
* false, which in this case means they all succeeded. Since we want to
233
* return false on success, we return the value of the two being !=
235
return iter != all_query_cache.end();
190
238
} /* namespace drizzled */