499.2.14
by Mark Atwood
fixes as per MontyT's comments, prep for internationalization |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
499.2.10
by Mark Atwood
add editor format hints, and other useful metadata comments |
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
499.2.14
by Mark Atwood
fixes as per MontyT's comments, prep for internationalization |
3 |
*
|
1999.6.1
by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file |
4 |
* Copyright (C) 2008 Sun Microsystems, Inc.
|
1643.6.5
by Djellel E. Difallah
retrieve data from the local cache |
5 |
* Copyright (C) 2010 Djellel Eddine Difallah
|
499.2.10
by Mark Atwood
add editor format hints, and other useful metadata comments |
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 |
||
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
21 |
#include <config.h> |
22 |
#include <drizzled/plugin/query_cache.h> |
|
23 |
#include <drizzled/errmsg_print.h> |
|
1130.1.1
by Monty Taylor
Merged in plugin-slot-reorg patches. |
24 |
|
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
25 |
#include <drizzled/gettext.h> |
1130.1.1
by Monty Taylor
Merged in plugin-slot-reorg patches. |
26 |
|
1530.2.5
by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant |
27 |
#include <algorithm> |
968.2.37
by Monty Taylor
Converted qcache plugin. |
28 |
#include <vector> |
29 |
||
2252.1.22
by Olaf van der Spek
Common fwd |
30 |
namespace drizzled { |
1241.9.26
by Monty Taylor
Removed forward declares from server_includes.h |
31 |
|
1966.2.9
by Brian Aker
Remove the use of "using std" from the plugin interface .cc files. |
32 |
typedef std::vector<plugin::QueryCache *> QueryCaches; |
1643.6.18
by Djellel E. Difallah
typedef of vector<plugin::QueryCache *> into QueryCaches |
33 |
QueryCaches all_query_cache; |
968.2.37
by Monty Taylor
Converted qcache plugin. |
34 |
|
35 |
/* Namespaces are here to prevent global symbol clashes with these classes */
|
|
36 |
||
1643.6.3
by Djellel E. Difallah
Refactoring of the QC Plugin's interface methods, adding mutual exclusion mechanism between sessions to cache a query, Store Meta inoformation of all the tables and select fields of the query |
37 |
class IsCachedIterate |
1966.2.9
by Brian Aker
Remove the use of "using std" from the plugin interface .cc files. |
38 |
: public std::unary_function<plugin::QueryCache *, bool> |
1643.6.3
by Djellel E. Difallah
Refactoring of the QC Plugin's interface methods, adding mutual exclusion mechanism between sessions to cache a query, Store Meta inoformation of all the tables and select fields of the query |
39 |
{
|
40 |
Session *session; |
|
41 |
public: |
|
42 |
IsCachedIterate(Session* session_arg) : |
|
1966.2.9
by Brian Aker
Remove the use of "using std" from the plugin interface .cc files. |
43 |
std::unary_function<plugin::QueryCache *, bool>(), |
1643.6.3
by Djellel E. Difallah
Refactoring of the QC Plugin's interface methods, adding mutual exclusion mechanism between sessions to cache a query, Store Meta inoformation of all the tables and select fields of the query |
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 */
|
|
1643.6.18
by Djellel E. Difallah
typedef of vector<plugin::QueryCache *> into QueryCaches |
55 |
QueryCaches::iterator iter= |
1966.2.9
by Brian Aker
Remove the use of "using std" from the plugin interface .cc files. |
56 |
std::find_if(all_query_cache.begin(), all_query_cache.end(), |
1643.6.3
by Djellel E. Difallah
Refactoring of the QC Plugin's interface methods, adding mutual exclusion mechanism between sessions to cache a query, Store Meta inoformation of all the tables and select fields of the query |
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 |
||
66 |
class SendCachedResultsetIterate |
|
1966.2.9
by Brian Aker
Remove the use of "using std" from the plugin interface .cc files. |
67 |
: public std::unary_function<plugin::QueryCache *, bool> |
1643.6.3
by Djellel E. Difallah
Refactoring of the QC Plugin's interface methods, adding mutual exclusion mechanism between sessions to cache a query, Store Meta inoformation of all the tables and select fields of the query |
68 |
{
|
69 |
Session *session; |
|
70 |
public: |
|
71 |
SendCachedResultsetIterate(Session *session_arg) : |
|
1966.2.9
by Brian Aker
Remove the use of "using std" from the plugin interface .cc files. |
72 |
std::unary_function<plugin::QueryCache *, bool>(), |
1643.6.3
by Djellel E. Difallah
Refactoring of the QC Plugin's interface methods, adding mutual exclusion mechanism between sessions to cache a query, Store Meta inoformation of all the tables and select fields of the query |
73 |
session(session_arg) { } |
74 |
||
75 |
inline result_type operator()(argument_type handler) |
|
76 |
{
|
|
1643.6.5
by Djellel E. Difallah
retrieve data from the local cache |
77 |
return handler->doSendCachedResultset(session); |
1643.6.3
by Djellel E. Difallah
Refactoring of the QC Plugin's interface methods, adding mutual exclusion mechanism between sessions to cache a query, Store Meta inoformation of all the tables and select fields of the query |
78 |
}
|
79 |
};
|
|
80 |
bool plugin::QueryCache::sendCachedResultset(Session *session) |
|
81 |
{
|
|
82 |
/* Use find_if instead of foreach so that we can collect return codes */
|
|
1643.6.18
by Djellel E. Difallah
typedef of vector<plugin::QueryCache *> into QueryCaches |
83 |
QueryCaches::iterator iter= |
1966.2.9
by Brian Aker
Remove the use of "using std" from the plugin interface .cc files. |
84 |
std::find_if(all_query_cache.begin(), all_query_cache.end(), |
85 |
SendCachedResultsetIterate(session)); |
|
1643.6.3
by Djellel E. Difallah
Refactoring of the QC Plugin's interface methods, adding mutual exclusion mechanism between sessions to cache a query, Store Meta inoformation of all the tables and select fields of the query |
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 |
}
|
|
1643.6.1
by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin |
92 |
|
1966.2.9
by Brian Aker
Remove the use of "using std" from the plugin interface .cc files. |
93 |
class PrepareResultsetIterate : public std::unary_function<plugin::QueryCache *, bool> |
1643.6.1
by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin |
94 |
{
|
95 |
Session *session; |
|
96 |
public: |
|
97 |
PrepareResultsetIterate(Session *session_arg) : |
|
1966.2.9
by Brian Aker
Remove the use of "using std" from the plugin interface .cc files. |
98 |
std::unary_function<plugin::QueryCache *, bool>(), |
99 |
session(session_arg) { } |
|
772.1.1
by Toru Maesaka
Defined the first version of the Query Cache interface. |
100 |
|
968.2.37
by Monty Taylor
Converted qcache plugin. |
101 |
inline result_type operator()(argument_type handler) |
772.1.1
by Toru Maesaka
Defined the first version of the Query Cache interface. |
102 |
{
|
1643.6.3
by Djellel E. Difallah
Refactoring of the QC Plugin's interface methods, adding mutual exclusion mechanism between sessions to cache a query, Store Meta inoformation of all the tables and select fields of the query |
103 |
return handler->doPrepareResultset(session); |
1643.6.1
by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin |
104 |
}
|
105 |
};
|
|
1643.6.3
by Djellel E. Difallah
Refactoring of the QC Plugin's interface methods, adding mutual exclusion mechanism between sessions to cache a query, Store Meta inoformation of all the tables and select fields of the query |
106 |
bool plugin::QueryCache::prepareResultset(Session *session) |
107 |
{
|
|
108 |
/* Use find_if instead of foreach so that we can collect return codes */
|
|
1643.6.18
by Djellel E. Difallah
typedef of vector<plugin::QueryCache *> into QueryCaches |
109 |
QueryCaches::iterator iter= |
1966.2.9
by Brian Aker
Remove the use of "using std" from the plugin interface .cc files. |
110 |
std::find_if(all_query_cache.begin(), all_query_cache.end(), |
111 |
PrepareResultsetIterate(session)); |
|
1643.6.3
by Djellel E. Difallah
Refactoring of the QC Plugin's interface methods, adding mutual exclusion mechanism between sessions to cache a query, Store Meta inoformation of all the tables and select fields of the query |
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 |
}
|
|
1643.6.1
by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin |
118 |
|
1966.2.9
by Brian Aker
Remove the use of "using std" from the plugin interface .cc files. |
119 |
class SetResultsetIterate : public std::unary_function<plugin::QueryCache *, bool> |
1643.6.1
by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin |
120 |
{
|
121 |
Session *session; |
|
122 |
public: |
|
123 |
SetResultsetIterate(Session *session_arg) : |
|
1966.2.9
by Brian Aker
Remove the use of "using std" from the plugin interface .cc files. |
124 |
std::unary_function<plugin::QueryCache *, bool>(), |
1643.6.1
by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin |
125 |
session(session_arg) { } |
126 |
||
127 |
inline result_type operator()(argument_type handler) |
|
128 |
{
|
|
1643.6.3
by Djellel E. Difallah
Refactoring of the QC Plugin's interface methods, adding mutual exclusion mechanism between sessions to cache a query, Store Meta inoformation of all the tables and select fields of the query |
129 |
return handler->doSetResultset(session); |
1643.6.1
by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin |
130 |
}
|
131 |
};
|
|
132 |
||
1643.6.3
by Djellel E. Difallah
Refactoring of the QC Plugin's interface methods, adding mutual exclusion mechanism between sessions to cache a query, Store Meta inoformation of all the tables and select fields of the query |
133 |
bool plugin::QueryCache::setResultset(Session *session) |
134 |
{
|
|
135 |
/* Use find_if instead of foreach so that we can collect return codes */
|
|
1643.6.18
by Djellel E. Difallah
typedef of vector<plugin::QueryCache *> into QueryCaches |
136 |
QueryCaches::iterator iter= |
1966.2.9
by Brian Aker
Remove the use of "using std" from the plugin interface .cc files. |
137 |
std::find_if(all_query_cache.begin(), all_query_cache.end(), |
138 |
SetResultsetIterate(session)); |
|
1643.6.3
by Djellel E. Difallah
Refactoring of the QC Plugin's interface methods, adding mutual exclusion mechanism between sessions to cache a query, Store Meta inoformation of all the tables and select fields of the query |
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 |
||
1643.6.1
by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin |
146 |
class InsertRecordIterate |
1966.2.9
by Brian Aker
Remove the use of "using std" from the plugin interface .cc files. |
147 |
: public std::unary_function<plugin::QueryCache *, bool> |
1643.6.1
by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin |
148 |
{
|
149 |
Session *session; |
|
150 |
List<Item> &item; |
|
151 |
public: |
|
152 |
InsertRecordIterate(Session *session_arg, List<Item> &item_arg) : |
|
1966.2.9
by Brian Aker
Remove the use of "using std" from the plugin interface .cc files. |
153 |
std::unary_function<plugin::QueryCache *, bool>(), |
1643.6.1
by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin |
154 |
session(session_arg), item(item_arg) { } |
155 |
||
156 |
inline result_type operator()(argument_type handler) |
|
157 |
{
|
|
1643.6.3
by Djellel E. Difallah
Refactoring of the QC Plugin's interface methods, adding mutual exclusion mechanism between sessions to cache a query, Store Meta inoformation of all the tables and select fields of the query |
158 |
return handler->doInsertRecord(session, item); |
1643.6.1
by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin |
159 |
}
|
160 |
};
|
|
1643.6.3
by Djellel E. Difallah
Refactoring of the QC Plugin's interface methods, adding mutual exclusion mechanism between sessions to cache a query, Store Meta inoformation of all the tables and select fields of the query |
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 */
|
|
1643.6.18
by Djellel E. Difallah
typedef of vector<plugin::QueryCache *> into QueryCaches |
164 |
QueryCaches::iterator iter= |
1966.2.9
by Brian Aker
Remove the use of "using std" from the plugin interface .cc files. |
165 |
std::find_if(all_query_cache.begin(), all_query_cache.end(), |
166 |
InsertRecordIterate(session, items)); |
|
1643.6.3
by Djellel E. Difallah
Refactoring of the QC Plugin's interface methods, adding mutual exclusion mechanism between sessions to cache a query, Store Meta inoformation of all the tables and select fields of the query |
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 |
}
|
|
1643.6.1
by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin |
173 |
|
174 |
||
968.2.37
by Monty Taylor
Converted qcache plugin. |
175 |
|
1130.1.19
by Monty Taylor
Added error reporting to plugin registration. |
176 |
bool plugin::QueryCache::addPlugin(plugin::QueryCache *handler) |
1130.1.1
by Monty Taylor
Merged in plugin-slot-reorg patches. |
177 |
{
|
178 |
all_query_cache.push_back(handler); |
|
1130.1.19
by Monty Taylor
Added error reporting to plugin registration. |
179 |
return false; |
1130.1.1
by Monty Taylor
Merged in plugin-slot-reorg patches. |
180 |
}
|
181 |
||
1130.1.18
by Monty Taylor
Changed ::add() and ::remove() to ::addPlugin() and ::removePlugin() so that |
182 |
void plugin::QueryCache::removePlugin(plugin::QueryCache *handler) |
1130.1.1
by Monty Taylor
Merged in plugin-slot-reorg patches. |
183 |
{
|
1966.2.9
by Brian Aker
Remove the use of "using std" from the plugin interface .cc files. |
184 |
all_query_cache.erase(std::find(all_query_cache.begin(), all_query_cache.end(), |
185 |
handler)); |
|
1130.1.1
by Monty Taylor
Merged in plugin-slot-reorg patches. |
186 |
}
|
187 |
||
1130.3.10
by Monty Taylor
Cleaned up service namespacing. |
188 |
} /* namespace drizzled */ |