~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/slot/query_cache.cc

Merged in plugin-slot-reorg patches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include <drizzled/server_includes.h>
21
 
#include <drizzled/qcache.h>
22
 
#include <drizzled/gettext.h>
 
20
#include "drizzled/server_includes.h"
 
21
#include "drizzled/slot/query_cache.h"
 
22
#include "drizzled/plugin/query_cache.h"
23
23
#include "drizzled/plugin/registry.h"
 
24
 
 
25
#include "drizzled/gettext.h"
 
26
 
24
27
#include <vector>
25
28
 
 
29
using namespace drizzled;
26
30
using namespace std;
27
31
 
28
 
static vector<QueryCache *> all_query_cache;
29
 
 
30
 
void add_query_cache(QueryCache *handler)
31
 
{
32
 
  all_query_cache.push_back(handler);
33
 
}
34
 
 
35
 
void remove_query_cache(QueryCache *handler)
36
 
{
37
 
  all_query_cache.erase(find(all_query_cache.begin(), all_query_cache.end(),
38
 
                        handler));
39
 
}
40
 
 
41
 
 
 
32
namespace plugin
 
33
{
 
34
  class QueryCache;
 
35
}
 
36
 
 
37
namespace drizzled
 
38
{
 
39
namespace slot
 
40
{
 
41
namespace query_cache_priv
 
42
{
42
43
 
43
44
/* Namespaces are here to prevent global symbol clashes with these classes */
44
45
 
45
 
namespace drizzled {
46
 
namespace query_cache {
47
 
 
48
46
class TryFetchAndSendIterate
49
 
 : public unary_function<QueryCache *, bool>
 
47
 : public unary_function<plugin::QueryCache *, bool>
50
48
{
51
49
  Session *session;
52
50
  bool is_transactional;
53
51
public:
54
52
  TryFetchAndSendIterate(Session *session_arg, bool is_transactional_arg) :
55
 
    unary_function<QueryCache *, bool>(),
 
53
    unary_function<plugin::QueryCache *, bool>(),
56
54
    session(session_arg), is_transactional(is_transactional_arg) { }
57
55
 
58
56
  inline result_type operator()(argument_type handler)
69
67
};
70
68
 
71
69
class SetIterate
72
 
 : public unary_function<QueryCache *, bool>
 
70
 : public unary_function<plugin::QueryCache *, bool>
73
71
{
74
72
  Session *session;
75
73
  bool is_transactional;
76
74
public:
77
75
  SetIterate(Session *session_arg, bool is_transactional_arg) :
78
 
    unary_function<QueryCache *, bool>(),
 
76
    unary_function<plugin::QueryCache *, bool>(),
79
77
    session(session_arg), is_transactional(is_transactional_arg) { }
80
78
 
81
79
  inline result_type operator()(argument_type handler)
92
90
};
93
91
 
94
92
class InvalidateTableIterate
95
 
 : public unary_function<QueryCache *, bool>
 
93
 : public unary_function<plugin::QueryCache *, bool>
96
94
{
97
95
  Session *session;
98
96
  bool is_transactional;
99
97
public:
100
98
  InvalidateTableIterate(Session *session_arg, bool is_transactional_arg) :
101
 
    unary_function<QueryCache *, bool>(),
 
99
    unary_function<plugin::QueryCache *, bool>(),
102
100
    session(session_arg), is_transactional(is_transactional_arg) { }
103
101
 
104
102
  inline result_type operator()(argument_type handler)
117
115
 
118
116
 
119
117
class InvalidateDbIterate
120
 
 : public unary_function<QueryCache *, bool>
 
118
 : public unary_function<plugin::QueryCache *, bool>
121
119
{
122
120
  Session *session;
123
121
  const char *dbname;
125
123
public:
126
124
  InvalidateDbIterate(Session *session_arg, const char *dbname_arg,
127
125
                      bool is_transactional_arg) :
128
 
    unary_function<QueryCache *, bool>(),
 
126
    unary_function<plugin::QueryCache *, bool>(),
129
127
    session(session_arg), dbname(dbname_arg),
130
128
    is_transactional(is_transactional_arg) { }
131
129
 
143
141
};
144
142
 
145
143
class FlushIterate
146
 
 : public unary_function<QueryCache *, bool>
 
144
 : public unary_function<plugin::QueryCache *, bool>
147
145
{
148
146
  Session *session;
149
147
public:
150
148
  FlushIterate(Session *session_arg) :
151
 
    unary_function<QueryCache *, bool>(), session(session_arg) { }
 
149
    unary_function<plugin::QueryCache *, bool>(), session(session_arg) { }
152
150
 
153
151
  inline result_type operator()(argument_type handler)
154
152
  {
162
160
  }
163
161
};
164
162
 
 
163
} /* namespace query_cache_priv */
 
164
} /* namespace slot */
 
165
} /* namespace drizzled */
 
166
 
 
167
void slot::QueryCache::add(plugin::QueryCache *handler)
 
168
{
 
169
  all_query_cache.push_back(handler);
 
170
}
 
171
 
 
172
void slot::QueryCache::remove(plugin::QueryCache *handler)
 
173
{
 
174
  all_query_cache.erase(find(all_query_cache.begin(), all_query_cache.end(),
 
175
                        handler));
 
176
}
 
177
 
 
178
 
165
179
/*
166
180
  Following functions:
167
181
 
175
189
  rest of the Drizzle server code.
176
190
*/
177
191
 
178
 
bool try_fetch_and_send(Session *session, bool transactional)
179
 
{
180
 
  /* Use find_if instead of foreach so that we can collect return codes */
181
 
  vector<QueryCache *>::iterator iter=
182
 
    find_if(all_query_cache.begin(), all_query_cache.end(),
183
 
            TryFetchAndSendIterate(session, transactional));
184
 
  /* If iter is == end() here, that means that all of the plugins returned
185
 
   * false, which in this case means they all succeeded. Since we want to 
186
 
   * return false on success, we return the value of the two being != 
187
 
   */
188
 
  return iter != all_query_cache.end();
189
 
}
190
 
 
191
 
bool set(Session *session, bool transactional)
192
 
{
193
 
  /* Use find_if instead of foreach so that we can collect return codes */
194
 
  vector<QueryCache *>::iterator iter=
195
 
    find_if(all_query_cache.begin(), all_query_cache.end(),
196
 
            SetIterate(session, transactional));
197
 
  /* If iter is == end() here, that means that all of the plugins returned
198
 
   * false, which in this case means they all succeeded. Since we want to 
199
 
   * return false on success, we return the value of the two being != 
200
 
   */
201
 
  return iter != all_query_cache.end();
202
 
}
203
 
 
204
 
bool invalidate_table(Session *session, bool transactional)
205
 
{
206
 
  /* Use find_if instead of foreach so that we can collect return codes */
207
 
  vector<QueryCache *>::iterator iter=
208
 
    find_if(all_query_cache.begin(), all_query_cache.end(),
209
 
            InvalidateTableIterate(session, transactional));
210
 
  /* If iter is == end() here, that means that all of the plugins returned
211
 
   * false, which in this case means they all succeeded. Since we want to 
212
 
   * return false on success, we return the value of the two being != 
213
 
   */
214
 
  return iter != all_query_cache.end();
215
 
}
216
 
 
217
 
bool invalidate_db(Session *session, const char *dbname,
218
 
                                         bool transactional)
219
 
{
220
 
  /* Use find_if instead of foreach so that we can collect return codes */
221
 
  vector<QueryCache *>::iterator iter=
222
 
    find_if(all_query_cache.begin(), all_query_cache.end(),
223
 
            InvalidateDbIterate(session, dbname, transactional));
224
 
  /* If iter is == end() here, that means that all of the plugins returned
225
 
   * false, which in this case means they all succeeded. Since we want to 
226
 
   * return false on success, we return the value of the two being != 
227
 
   */
228
 
  return iter != all_query_cache.end();
229
 
}
230
 
 
231
 
bool flush(Session *session)
232
 
{
233
 
  /* Use find_if instead of foreach so that we can collect return codes */
234
 
  vector<QueryCache *>::iterator iter=
235
 
    find_if(all_query_cache.begin(), all_query_cache.end(),
236
 
            FlushIterate(session));
237
 
  /* If iter is == end() here, that means that all of the plugins returned
238
 
   * false, which in this case means they all succeeded. Since we want to 
239
 
   * return false on success, we return the value of the two being != 
240
 
   */
241
 
  return iter != all_query_cache.end();
242
 
}
243
 
 
244
 
} /* namespace query_cache */
245
 
} /* namespace drizzled */
 
192
bool slot::QueryCache::try_fetch_and_send(Session *session, bool transactional)
 
193
{
 
194
  /* Use find_if instead of foreach so that we can collect return codes */
 
195
  vector<plugin::QueryCache *>::iterator iter=
 
196
    find_if(all_query_cache.begin(), all_query_cache.end(),
 
197
            slot::query_cache_priv::TryFetchAndSendIterate(session,
 
198
                                                           transactional));
 
199
  /* If iter is == end() here, that means that all of the plugins returned
 
200
   * false, which in this case means they all succeeded. Since we want to 
 
201
   * return false on success, we return the value of the two being != 
 
202
   */
 
203
  return iter != all_query_cache.end();
 
204
}
 
205
 
 
206
bool slot::QueryCache::set(Session *session, bool transactional)
 
207
{
 
208
  /* Use find_if instead of foreach so that we can collect return codes */
 
209
  vector<plugin::QueryCache *>::iterator iter=
 
210
    find_if(all_query_cache.begin(), all_query_cache.end(),
 
211
            slot::query_cache_priv::SetIterate(session, transactional));
 
212
  /* If iter is == end() here, that means that all of the plugins returned
 
213
   * false, which in this case means they all succeeded. Since we want to 
 
214
   * return false on success, we return the value of the two being != 
 
215
   */
 
216
  return iter != all_query_cache.end();
 
217
}
 
218
 
 
219
bool slot::QueryCache::invalidate_table(Session *session, bool transactional)
 
220
{
 
221
  /* Use find_if instead of foreach so that we can collect return codes */
 
222
  vector<plugin::QueryCache *>::iterator iter=
 
223
    find_if(all_query_cache.begin(), all_query_cache.end(),
 
224
            slot::query_cache_priv::InvalidateTableIterate(session,
 
225
                                                           transactional));
 
226
  /* If iter is == end() here, that means that all of the plugins returned
 
227
   * false, which in this case means they all succeeded. Since we want to 
 
228
   * return false on success, we return the value of the two being != 
 
229
   */
 
230
  return iter != all_query_cache.end();
 
231
}
 
232
 
 
233
bool slot::QueryCache::invalidate_db(Session *session, const char *dbname,
 
234
                                     bool transactional)
 
235
{
 
236
  /* Use find_if instead of foreach so that we can collect return codes */
 
237
  vector<plugin::QueryCache *>::iterator iter=
 
238
    find_if(all_query_cache.begin(), all_query_cache.end(),
 
239
            slot::query_cache_priv::InvalidateDbIterate(session,
 
240
                                                        dbname,
 
241
                                                        transactional));
 
242
  /* If iter is == end() here, that means that all of the plugins returned
 
243
   * false, which in this case means they all succeeded. Since we want to 
 
244
   * return false on success, we return the value of the two being != 
 
245
   */
 
246
  return iter != all_query_cache.end();
 
247
}
 
248
 
 
249
bool slot::QueryCache::flush(Session *session)
 
250
{
 
251
  /* Use find_if instead of foreach so that we can collect return codes */
 
252
  vector<plugin::QueryCache *>::iterator iter=
 
253
    find_if(all_query_cache.begin(), all_query_cache.end(),
 
254
            slot::query_cache_priv::FlushIterate(session));
 
255
  /* If iter is == end() here, that means that all of the plugins returned
 
256
   * false, which in this case means they all succeeded. Since we want to 
 
257
   * return false on success, we return the value of the two being != 
 
258
   */
 
259
  return iter != all_query_cache.end();
 
260
}
246
261