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>
20
#include <drizzled/server_includes.h>
21
#include <drizzled/qcache.h>
25
22
#include <drizzled/gettext.h>
34
typedef std::vector<plugin::QueryCache *> QueryCaches;
35
QueryCaches all_query_cache;
37
/* 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(),
190
} /* namespace drizzled */
24
int qcache_initializer(st_plugin_int *plugin)
29
if (p == NULL) return 1;
30
memset(p, 0, sizeof(qcache_t));
32
plugin->data= (void *)p;
34
if (plugin->plugin->init)
36
if (plugin->plugin->init((void *)p))
38
/* TRANSLATORS: The leading word "qcache" is the name
39
of the plugin api, and so should not be translated. */
40
sql_print_error(_("qcache plugin '%s' init() failed"),
52
int qcache_finalizer(st_plugin_int *plugin)
54
qcache_t *p= (qcache_t *) plugin->data;
56
if (plugin->plugin->deinit)
58
if (plugin->plugin->deinit((void *)p))
60
/* TRANSLATORS: The leading word "qcache" is the name
61
of the plugin api, and so should not be translated. */
62
sql_print_error(_("qcache plugin '%s' deinit() failed"),
72
/* The plugin_foreach() iterator requires that we
73
convert all the parameters of a plugin api entry point
74
into just one single void ptr, plus the session.
75
So we will take all the additional paramters of qcache_do1,
76
and marshall them into a struct of this type, and
77
then just pass in a pointer to it.
79
typedef struct qcache_do1_parms_st
85
/* This gets called by plugin_foreach once for each loaded qcache plugin */
86
static bool qcache_do1_iterate (Session *session, plugin_ref plugin, void *p)
88
qcache_t *l= plugin_data(plugin, qcache_t *);
89
qcache_do1_parms_t *parms= (qcache_do1_parms_t *) p;
91
/* call this loaded qcache plugin's qcache_func1 function pointer */
92
if (l && l->qcache_func1)
94
if (l->qcache_func1(session, parms->parm1, parms->parm2))
96
/* TRANSLATORS: The leading word "qcache" is the name
97
of the plugin api, and so should not be translated. */
98
sql_print_error(_("qcache plugin '%s' do1() failed"),
99
(char *)plugin_name(plugin));
106
/* This is the qcache_do1 entry point.
107
This gets called by the rest of the Drizzle server code */
108
bool qcache_do1 (Session *session, void *parm1, void *parm2)
110
qcache_do1_parms_t parms;
113
/* marshall the parameters so they will fit into the foreach */
117
/* call qcache_do1_iterate
118
once for each loaded qcache plugin */
119
foreach_rv= plugin_foreach(session,
121
DRIZZLE_QCACHE_PLUGIN,
126
/* The plugin_foreach() iterator requires that we
127
convert all the parameters of a plugin api entry point
128
into just one single void ptr, plus the session.
129
So we will take all the additional paramters of qcache_do2,
130
and marshall them into a struct of this type, and
131
then just pass in a pointer to it.
133
typedef struct qcache_do2_parms_st
137
} qcache_do2_parms_t;
139
/* This gets called by plugin_foreach once for each loaded qcache plugin */
140
static bool qcache_do2_iterate (Session *session, plugin_ref plugin, void *p)
142
qcache_t *l= plugin_data(plugin, qcache_t *);
143
qcache_do2_parms_t *parms= (qcache_do2_parms_t *) p;
145
/* call this loaded qcache plugin's qcache_func1 function pointer */
146
if (l && l->qcache_func1)
148
if (l->qcache_func2(session, parms->parm3, parms->parm4))
150
/* TRANSLATORS: The leading word "qcache" is the name
151
of the plugin api, and so should not be translated. */
152
sql_print_error(_("qcache plugin '%s' qcache_func2() failed"),
153
(char *)plugin_name(plugin));
161
/* This is the qcache_do2 entry point.
162
This gets called by the rest of the Drizzle server code */
163
bool qcache_do2 (Session *session, void *parm3, void *parm4)
165
qcache_do2_parms_t parms;
168
/* marshall the parameters so they will fit into the foreach */
172
/* call qcache_do2_iterate
173
once for each loaded qcache plugin */
174
foreach_rv= plugin_foreach(session,
176
DRIZZLE_QCACHE_PLUGIN,