Drizzled Public API Documentation

query_cache.cc
1 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3  *
4  * Copyright (C) 2008 Sun Microsystems, Inc.
5  * Copyright (C) 2010 Djellel Eddine Difallah
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; version 2 of the License.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <config.h>
22 #include <drizzled/plugin/query_cache.h>
23 #include <drizzled/errmsg_print.h>
24 
25 #include <drizzled/gettext.h>
26 
27 #include <algorithm>
28 #include <vector>
29 
30 namespace drizzled {
31 
32 typedef std::vector<plugin::QueryCache *> QueryCaches;
33 QueryCaches all_query_cache;
34 
35 /* Namespaces are here to prevent global symbol clashes with these classes */
36 
38  : public std::unary_function<plugin::QueryCache *, bool>
39 {
40  Session *session;
41 public:
42  IsCachedIterate(Session* session_arg) :
43  std::unary_function<plugin::QueryCache *, bool>(),
44  session(session_arg) { }
45 
46  inline result_type operator()(argument_type handler)
47  {
48  return handler->doIsCached(session);
49  }
50 };
51 
52 bool plugin::QueryCache::isCached(Session *session)
53 {
54  /* Use find_if instead of foreach so that we can collect return codes */
55  QueryCaches::iterator iter=
56  std::find_if(all_query_cache.begin(), all_query_cache.end(),
57  IsCachedIterate(session));
58  /* If iter is == end() here, that means that all of the plugins returned
59  * false, which in this case means they all succeeded. Since we want to
60  * return false on success, we return the value of the two being !=
61  */
62  return iter != all_query_cache.end();
63 }
64 
65 
67  : public std::unary_function<plugin::QueryCache *, bool>
68 {
69  Session *session;
70 public:
71  SendCachedResultsetIterate(Session *session_arg) :
72  std::unary_function<plugin::QueryCache *, bool>(),
73  session(session_arg) { }
74 
75  inline result_type operator()(argument_type handler)
76  {
77  return handler->doSendCachedResultset(session);
78  }
79 };
80 bool plugin::QueryCache::sendCachedResultset(Session *session)
81 {
82  /* Use find_if instead of foreach so that we can collect return codes */
83  QueryCaches::iterator iter=
84  std::find_if(all_query_cache.begin(), all_query_cache.end(),
86  /* If iter is == end() here, that means that all of the plugins returned
87  * false, which in this case means they all succeeded. Since we want to
88  * return false on success, we return the value of the two being !=
89  */
90  return iter != all_query_cache.end();
91 }
92 
93 class PrepareResultsetIterate : public std::unary_function<plugin::QueryCache *, bool>
94 {
95  Session *session;
96 public:
97  PrepareResultsetIterate(Session *session_arg) :
98  std::unary_function<plugin::QueryCache *, bool>(),
99  session(session_arg) { }
100 
101  inline result_type operator()(argument_type handler)
102  {
103  return handler->doPrepareResultset(session);
104  }
105 };
106 bool plugin::QueryCache::prepareResultset(Session *session)
107 {
108  /* Use find_if instead of foreach so that we can collect return codes */
109  QueryCaches::iterator iter=
110  std::find_if(all_query_cache.begin(), all_query_cache.end(),
111  PrepareResultsetIterate(session));
112  /* If iter is == end() here, that means that all of the plugins returned
113  * false, which in this case means they all succeeded. Since we want to
114  * return false on success, we return the value of the two being !=
115  */
116  return iter != all_query_cache.end();
117 }
118 
119 class SetResultsetIterate : public std::unary_function<plugin::QueryCache *, bool>
120 {
121  Session *session;
122 public:
123  SetResultsetIterate(Session *session_arg) :
124  std::unary_function<plugin::QueryCache *, bool>(),
125  session(session_arg) { }
126 
127  inline result_type operator()(argument_type handler)
128  {
129  return handler->doSetResultset(session);
130  }
131 };
132 
133 bool plugin::QueryCache::setResultset(Session *session)
134 {
135  /* Use find_if instead of foreach so that we can collect return codes */
136  QueryCaches::iterator iter=
137  std::find_if(all_query_cache.begin(), all_query_cache.end(),
138  SetResultsetIterate(session));
139  /* If iter is == end() here, that means that all of the plugins returned
140  * false, which in this case means they all succeeded. Since we want to
141  * return false on success, we return the value of the two being !=
142  */
143  return iter != all_query_cache.end();
144 }
145 
147  : public std::unary_function<plugin::QueryCache *, bool>
148 {
149  Session *session;
150  List<Item> &item;
151 public:
152  InsertRecordIterate(Session *session_arg, List<Item> &item_arg) :
153  std::unary_function<plugin::QueryCache *, bool>(),
154  session(session_arg), item(item_arg) { }
155 
156  inline result_type operator()(argument_type handler)
157  {
158  return handler->doInsertRecord(session, item);
159  }
160 };
161 bool plugin::QueryCache::insertRecord(Session *session, List<Item> &items)
162 {
163  /* Use find_if instead of foreach so that we can collect return codes */
164  QueryCaches::iterator iter=
165  std::find_if(all_query_cache.begin(), all_query_cache.end(),
166  InsertRecordIterate(session, items));
167  /* If iter is == end() here, that means that all of the plugins returned
168  * false, which in this case means they all succeeded. Since we want to
169  * return false on success, we return the value of the two being !=
170  */
171  return iter != all_query_cache.end();
172 }
173 
174 
175 
176 bool plugin::QueryCache::addPlugin(plugin::QueryCache *handler)
177 {
178  all_query_cache.push_back(handler);
179  return false;
180 }
181 
182 void plugin::QueryCache::removePlugin(plugin::QueryCache *handler)
183 {
184  all_query_cache.erase(std::find(all_query_cache.begin(), all_query_cache.end(),
185  handler));
186 }
187 
188 } /* namespace drizzled */
TODO: Rename this file - func.h is stupid.