1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems, Inc.
5
* Copyright (C) 2010 Djellel Eddine Difallah
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.
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.
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
22
#include "drizzled/plugin/query_cache.h"
23
#include "drizzled/errmsg_print.h"
25
#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 */