00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022 #include <drizzled/plugin/query_cache.h>
00023 #include <drizzled/errmsg_print.h>
00024
00025 #include <drizzled/gettext.h>
00026
00027 #include <algorithm>
00028 #include <vector>
00029
00030 namespace drizzled {
00031
00032 typedef std::vector<plugin::QueryCache *> QueryCaches;
00033 QueryCaches all_query_cache;
00034
00035
00036
00037 class IsCachedIterate
00038 : public std::unary_function<plugin::QueryCache *, bool>
00039 {
00040 Session *session;
00041 public:
00042 IsCachedIterate(Session* session_arg) :
00043 std::unary_function<plugin::QueryCache *, bool>(),
00044 session(session_arg) { }
00045
00046 inline result_type operator()(argument_type handler)
00047 {
00048 return handler->doIsCached(session);
00049 }
00050 };
00051
00052 bool plugin::QueryCache::isCached(Session *session)
00053 {
00054
00055 QueryCaches::iterator iter=
00056 std::find_if(all_query_cache.begin(), all_query_cache.end(),
00057 IsCachedIterate(session));
00058
00059
00060
00061
00062 return iter != all_query_cache.end();
00063 }
00064
00065
00066 class SendCachedResultsetIterate
00067 : public std::unary_function<plugin::QueryCache *, bool>
00068 {
00069 Session *session;
00070 public:
00071 SendCachedResultsetIterate(Session *session_arg) :
00072 std::unary_function<plugin::QueryCache *, bool>(),
00073 session(session_arg) { }
00074
00075 inline result_type operator()(argument_type handler)
00076 {
00077 return handler->doSendCachedResultset(session);
00078 }
00079 };
00080 bool plugin::QueryCache::sendCachedResultset(Session *session)
00081 {
00082
00083 QueryCaches::iterator iter=
00084 std::find_if(all_query_cache.begin(), all_query_cache.end(),
00085 SendCachedResultsetIterate(session));
00086
00087
00088
00089
00090 return iter != all_query_cache.end();
00091 }
00092
00093 class PrepareResultsetIterate : public std::unary_function<plugin::QueryCache *, bool>
00094 {
00095 Session *session;
00096 public:
00097 PrepareResultsetIterate(Session *session_arg) :
00098 std::unary_function<plugin::QueryCache *, bool>(),
00099 session(session_arg) { }
00100
00101 inline result_type operator()(argument_type handler)
00102 {
00103 return handler->doPrepareResultset(session);
00104 }
00105 };
00106 bool plugin::QueryCache::prepareResultset(Session *session)
00107 {
00108
00109 QueryCaches::iterator iter=
00110 std::find_if(all_query_cache.begin(), all_query_cache.end(),
00111 PrepareResultsetIterate(session));
00112
00113
00114
00115
00116 return iter != all_query_cache.end();
00117 }
00118
00119 class SetResultsetIterate : public std::unary_function<plugin::QueryCache *, bool>
00120 {
00121 Session *session;
00122 public:
00123 SetResultsetIterate(Session *session_arg) :
00124 std::unary_function<plugin::QueryCache *, bool>(),
00125 session(session_arg) { }
00126
00127 inline result_type operator()(argument_type handler)
00128 {
00129 return handler->doSetResultset(session);
00130 }
00131 };
00132
00133 bool plugin::QueryCache::setResultset(Session *session)
00134 {
00135
00136 QueryCaches::iterator iter=
00137 std::find_if(all_query_cache.begin(), all_query_cache.end(),
00138 SetResultsetIterate(session));
00139
00140
00141
00142
00143 return iter != all_query_cache.end();
00144 }
00145
00146 class InsertRecordIterate
00147 : public std::unary_function<plugin::QueryCache *, bool>
00148 {
00149 Session *session;
00150 List<Item> &item;
00151 public:
00152 InsertRecordIterate(Session *session_arg, List<Item> &item_arg) :
00153 std::unary_function<plugin::QueryCache *, bool>(),
00154 session(session_arg), item(item_arg) { }
00155
00156 inline result_type operator()(argument_type handler)
00157 {
00158 return handler->doInsertRecord(session, item);
00159 }
00160 };
00161 bool plugin::QueryCache::insertRecord(Session *session, List<Item> &items)
00162 {
00163
00164 QueryCaches::iterator iter=
00165 std::find_if(all_query_cache.begin(), all_query_cache.end(),
00166 InsertRecordIterate(session, items));
00167
00168
00169
00170
00171 return iter != all_query_cache.end();
00172 }
00173
00174
00175
00176 bool plugin::QueryCache::addPlugin(plugin::QueryCache *handler)
00177 {
00178 all_query_cache.push_back(handler);
00179 return false;
00180 }
00181
00182 void plugin::QueryCache::removePlugin(plugin::QueryCache *handler)
00183 {
00184 all_query_cache.erase(std::find(all_query_cache.begin(), all_query_cache.end(),
00185 handler));
00186 }
00187
00188 }