drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
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
30namespace drizzled {
31
32typedef std::vector<plugin::QueryCache *> QueryCaches;
33QueryCaches all_query_cache;
34
35/* Namespaces are here to prevent global symbol clashes with these classes */
36
37class IsCachedIterate
38{
39 Session *session;
40public:
41 IsCachedIterate(Session* session_arg) :
42 session(session_arg) { }
43
44 inline bool operator()(plugin::QueryCache *handler)
45 {
46 return handler->doIsCached(session);
47 }
48};
49
50bool plugin::QueryCache::isCached(Session *session)
51{
52 /* Use find_if instead of foreach so that we can collect return codes */
53 QueryCaches::iterator iter=
54 std::find_if(all_query_cache.begin(), all_query_cache.end(),
55 IsCachedIterate(session));
56 /* If iter is == end() here, that means that all of the plugins returned
57 * false, which in this case means they all succeeded. Since we want to
58 * return false on success, we return the value of the two being !=
59 */
60 return iter != all_query_cache.end();
61}
62
63
64class SendCachedResultsetIterate
65{
66 Session *session;
67public:
68 SendCachedResultsetIterate(Session *session_arg) :
69 session(session_arg) { }
70
71 inline bool operator()(plugin::QueryCache *handler)
72 {
73 return handler->doSendCachedResultset(session);
74 }
75};
76bool plugin::QueryCache::sendCachedResultset(Session *session)
77{
78 /* Use find_if instead of foreach so that we can collect return codes */
79 QueryCaches::iterator iter=
80 std::find_if(all_query_cache.begin(), all_query_cache.end(),
82 /* If iter is == end() here, that means that all of the plugins returned
83 * false, which in this case means they all succeeded. Since we want to
84 * return false on success, we return the value of the two being !=
85 */
86 return iter != all_query_cache.end();
87}
88
89class PrepareResultsetIterate
90{
91 Session *session;
92public:
93 PrepareResultsetIterate(Session *session_arg) :
94 session(session_arg) { }
95
96 inline bool operator()(plugin::QueryCache *handler)
97 {
98 return handler->doPrepareResultset(session);
99 }
100};
101bool plugin::QueryCache::prepareResultset(Session *session)
102{
103 /* Use find_if instead of foreach so that we can collect return codes */
104 QueryCaches::iterator iter=
105 std::find_if(all_query_cache.begin(), all_query_cache.end(),
106 PrepareResultsetIterate(session));
107 /* If iter is == end() here, that means that all of the plugins returned
108 * false, which in this case means they all succeeded. Since we want to
109 * return false on success, we return the value of the two being !=
110 */
111 return iter != all_query_cache.end();
112}
113
114class SetResultsetIterate
115{
116 Session *session;
117public:
118 SetResultsetIterate(Session *session_arg) :
119 session(session_arg) { }
120
121 inline bool operator()(plugin::QueryCache *handler)
122 {
123 return handler->doSetResultset(session);
124 }
125};
126
127bool plugin::QueryCache::setResultset(Session *session)
128{
129 /* Use find_if instead of foreach so that we can collect return codes */
130 QueryCaches::iterator iter=
131 std::find_if(all_query_cache.begin(), all_query_cache.end(),
132 SetResultsetIterate(session));
133 /* If iter is == end() here, that means that all of the plugins returned
134 * false, which in this case means they all succeeded. Since we want to
135 * return false on success, we return the value of the two being !=
136 */
137 return iter != all_query_cache.end();
138}
139
140class InsertRecordIterate
141{
142 Session *session;
143 List<Item> &item;
144public:
145 InsertRecordIterate(Session *session_arg, List<Item> &item_arg) :
146 session(session_arg), item(item_arg) { }
147
148 inline bool operator()(plugin::QueryCache *handler)
149 {
150 return handler->doInsertRecord(session, item);
151 }
152};
153bool plugin::QueryCache::insertRecord(Session *session, List<Item> &items)
154{
155 /* Use find_if instead of foreach so that we can collect return codes */
156 QueryCaches::iterator iter=
157 std::find_if(all_query_cache.begin(), all_query_cache.end(),
158 InsertRecordIterate(session, items));
159 /* If iter is == end() here, that means that all of the plugins returned
160 * false, which in this case means they all succeeded. Since we want to
161 * return false on success, we return the value of the two being !=
162 */
163 return iter != all_query_cache.end();
164}
165
166
167
168bool plugin::QueryCache::addPlugin(plugin::QueryCache &handler)
169{
170 all_query_cache.push_back(&handler);
171 return false;
172}
173
174void plugin::QueryCache::removePlugin(plugin::QueryCache &handler)
175{
176 all_query_cache.erase(std::find(all_query_cache.begin(), all_query_cache.end(),
177 &handler));
178}
179
180} /* namespace drizzled */
TODO: Rename this file - func.h is stupid.