~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/query_cache.cc

  • Committer: Brian Aker
  • Date: 2011-02-22 06:12:02 UTC
  • mfrom: (2190.1.6 drizzle-build)
  • Revision ID: brian@tangent.org-20110222061202-k03czxykqy4x9hjs
List update, header fixes, multiple symbols, and David deletes some code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems
 
4
 *  Copyright (C) 2008 Sun Microsystems, Inc.
5
5
 *  Copyright (C) 2010 Djellel Eddine Difallah
6
6
 *
7
7
 *  This program is free software; you can redistribute it and/or modify
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include "config.h"
22
 
#include "drizzled/plugin/query_cache.h"
23
 
#include "drizzled/errmsg_print.h"
 
21
#include <config.h>
 
22
#include <drizzled/plugin/query_cache.h>
 
23
#include <drizzled/errmsg_print.h>
24
24
 
25
 
#include "drizzled/gettext.h"
 
25
#include <drizzled/gettext.h>
26
26
 
27
27
#include <algorithm>
28
28
#include <vector>
29
29
 
30
30
class Session;
31
31
 
32
 
using namespace std;
33
 
 
34
32
namespace drizzled
35
33
{
36
 
typedef vector<plugin::QueryCache *> QueryCaches;
 
34
typedef std::vector<plugin::QueryCache *> QueryCaches;
37
35
QueryCaches all_query_cache;
38
36
 
39
37
/* Namespaces are here to prevent global symbol clashes with these classes */
40
38
 
41
39
class IsCachedIterate
42
 
 : public unary_function<plugin::QueryCache *, bool>
 
40
 : public std::unary_function<plugin::QueryCache *, bool>
43
41
{
44
42
  Session *session;
45
43
public:
46
44
  IsCachedIterate(Session* session_arg) :
47
 
    unary_function<plugin::QueryCache *, bool>(),
 
45
    std::unary_function<plugin::QueryCache *, bool>(),
48
46
    session(session_arg) { }
49
47
 
50
48
  inline result_type operator()(argument_type handler)
57
55
{
58
56
  /* Use find_if instead of foreach so that we can collect return codes */
59
57
  QueryCaches::iterator iter=
60
 
    find_if(all_query_cache.begin(), all_query_cache.end(),
 
58
    std::find_if(all_query_cache.begin(), all_query_cache.end(),
61
59
            IsCachedIterate(session));
62
60
  /* If iter is == end() here, that means that all of the plugins returned
63
61
   * false, which in this case means they all succeeded. Since we want to 
68
66
 
69
67
 
70
68
class SendCachedResultsetIterate
71
 
 : public unary_function<plugin::QueryCache *, bool>
 
69
 : public std::unary_function<plugin::QueryCache *, bool>
72
70
{
73
71
  Session *session;
74
72
public:
75
73
  SendCachedResultsetIterate(Session *session_arg) :
76
 
    unary_function<plugin::QueryCache *, bool>(),
 
74
    std::unary_function<plugin::QueryCache *, bool>(),
77
75
    session(session_arg) { }
78
76
 
79
77
  inline result_type operator()(argument_type handler)
85
83
{
86
84
  /* Use find_if instead of foreach so that we can collect return codes */
87
85
  QueryCaches::iterator iter=
88
 
    find_if(all_query_cache.begin(), all_query_cache.end(),
89
 
            SendCachedResultsetIterate(session));
 
86
    std::find_if(all_query_cache.begin(), all_query_cache.end(),
 
87
                 SendCachedResultsetIterate(session));
90
88
  /* If iter is == end() here, that means that all of the plugins returned
91
89
   * false, which in this case means they all succeeded. Since we want to 
92
90
   * return false on success, we return the value of the two being != 
94
92
  return iter != all_query_cache.end();
95
93
}
96
94
 
97
 
class PrepareResultsetIterate
98
 
 : public unary_function<plugin::QueryCache *, bool>
 
95
class PrepareResultsetIterate : public std::unary_function<plugin::QueryCache *, bool>
99
96
{
100
97
  Session *session;
101
98
public:
102
99
  PrepareResultsetIterate(Session *session_arg) :
103
 
    unary_function<plugin::QueryCache *, bool>(), session(session_arg) { }
 
100
    std::unary_function<plugin::QueryCache *, bool>(),
 
101
    session(session_arg) { }
104
102
 
105
103
  inline result_type operator()(argument_type handler)
106
104
  {
111
109
{
112
110
  /* Use find_if instead of foreach so that we can collect return codes */
113
111
  QueryCaches::iterator iter=
114
 
    find_if(all_query_cache.begin(), all_query_cache.end(),
115
 
            PrepareResultsetIterate(session));
 
112
    std::find_if(all_query_cache.begin(), all_query_cache.end(),
 
113
                 PrepareResultsetIterate(session));
116
114
  /* If iter is == end() here, that means that all of the plugins returned
117
115
   * false, which in this case means they all succeeded. Since we want to 
118
116
   * return false on success, we return the value of the two being != 
120
118
  return iter != all_query_cache.end();
121
119
}
122
120
 
123
 
class SetResultsetIterate
124
 
 : public unary_function<plugin::QueryCache *, bool>
 
121
class SetResultsetIterate : public std::unary_function<plugin::QueryCache *, bool>
125
122
{
126
123
  Session *session;
127
124
public:
128
125
  SetResultsetIterate(Session *session_arg) :
129
 
    unary_function<plugin::QueryCache *, bool>(),
 
126
    std::unary_function<plugin::QueryCache *, bool>(),
130
127
    session(session_arg) { }
131
128
 
132
129
  inline result_type operator()(argument_type handler)
139
136
{
140
137
  /* Use find_if instead of foreach so that we can collect return codes */
141
138
  QueryCaches::iterator iter=
142
 
    find_if(all_query_cache.begin(), all_query_cache.end(),
143
 
            SetResultsetIterate(session));
 
139
    std::find_if(all_query_cache.begin(), all_query_cache.end(),
 
140
                 SetResultsetIterate(session));
144
141
  /* If iter is == end() here, that means that all of the plugins returned
145
142
   * false, which in this case means they all succeeded. Since we want to 
146
143
   * return false on success, we return the value of the two being != 
149
146
}
150
147
 
151
148
class InsertRecordIterate
152
 
 : public unary_function<plugin::QueryCache *, bool>
 
149
 : public std::unary_function<plugin::QueryCache *, bool>
153
150
{
154
151
  Session *session;
155
152
  List<Item> &item;
156
153
public:
157
154
  InsertRecordIterate(Session *session_arg, List<Item> &item_arg) :
158
 
    unary_function<plugin::QueryCache *, bool>(),
 
155
    std::unary_function<plugin::QueryCache *, bool>(),
159
156
    session(session_arg), item(item_arg) { }
160
157
 
161
158
  inline result_type operator()(argument_type handler)
167
164
{
168
165
  /* Use find_if instead of foreach so that we can collect return codes */
169
166
  QueryCaches::iterator iter=
170
 
    find_if(all_query_cache.begin(), all_query_cache.end(),
171
 
            InsertRecordIterate(session, items));
 
167
    std::find_if(all_query_cache.begin(), all_query_cache.end(),
 
168
                 InsertRecordIterate(session, items));
172
169
  /* If iter is == end() here, that means that all of the plugins returned
173
170
   * false, which in this case means they all succeeded. Since we want to 
174
171
   * return false on success, we return the value of the two being != 
186
183
 
187
184
void plugin::QueryCache::removePlugin(plugin::QueryCache *handler)
188
185
{
189
 
  all_query_cache.erase(find(all_query_cache.begin(), all_query_cache.end(),
190
 
                        handler));
 
186
  all_query_cache.erase(std::find(all_query_cache.begin(), all_query_cache.end(),
 
187
                                  handler));
191
188
}
192
189
 
193
190
} /* namespace drizzled */