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