~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/query_cache.cc

  • Committer: Stewart Smith
  • Date: 2010-11-07 04:22:31 UTC
  • mto: (1911.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1912.
  • Revision ID: stewart@flamingspork.com-20101107042231-ola4sl7j0qvg58tz
fix ARCHIVE storage engine calling exit (lintian warning). Was because we were linking in libinternal into libazio, which links into archive plugin. Just link libinternal into the command line utilities.

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, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
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
 
32
34
namespace drizzled
33
35
{
34
 
typedef std::vector<plugin::QueryCache *> QueryCaches;
 
36
typedef vector<plugin::QueryCache *> QueryCaches;
35
37
QueryCaches all_query_cache;
36
38
 
37
39
/* Namespaces are here to prevent global symbol clashes with these classes */
38
40
 
39
41
class IsCachedIterate
40
 
 : public std::unary_function<plugin::QueryCache *, bool>
 
42
 : public unary_function<plugin::QueryCache *, bool>
41
43
{
42
44
  Session *session;
43
45
public:
44
46
  IsCachedIterate(Session* session_arg) :
45
 
    std::unary_function<plugin::QueryCache *, bool>(),
 
47
    unary_function<plugin::QueryCache *, bool>(),
46
48
    session(session_arg) { }
47
49
 
48
50
  inline result_type operator()(argument_type handler)
55
57
{
56
58
  /* Use find_if instead of foreach so that we can collect return codes */
57
59
  QueryCaches::iterator iter=
58
 
    std::find_if(all_query_cache.begin(), all_query_cache.end(),
 
60
    find_if(all_query_cache.begin(), all_query_cache.end(),
59
61
            IsCachedIterate(session));
60
62
  /* If iter is == end() here, that means that all of the plugins returned
61
63
   * false, which in this case means they all succeeded. Since we want to 
66
68
 
67
69
 
68
70
class SendCachedResultsetIterate
69
 
 : public std::unary_function<plugin::QueryCache *, bool>
 
71
 : public unary_function<plugin::QueryCache *, bool>
70
72
{
71
73
  Session *session;
72
74
public:
73
75
  SendCachedResultsetIterate(Session *session_arg) :
74
 
    std::unary_function<plugin::QueryCache *, bool>(),
 
76
    unary_function<plugin::QueryCache *, bool>(),
75
77
    session(session_arg) { }
76
78
 
77
79
  inline result_type operator()(argument_type handler)
83
85
{
84
86
  /* Use find_if instead of foreach so that we can collect return codes */
85
87
  QueryCaches::iterator iter=
86
 
    std::find_if(all_query_cache.begin(), all_query_cache.end(),
87
 
                 SendCachedResultsetIterate(session));
 
88
    find_if(all_query_cache.begin(), all_query_cache.end(),
 
89
            SendCachedResultsetIterate(session));
88
90
  /* If iter is == end() here, that means that all of the plugins returned
89
91
   * false, which in this case means they all succeeded. Since we want to 
90
92
   * return false on success, we return the value of the two being != 
92
94
  return iter != all_query_cache.end();
93
95
}
94
96
 
95
 
class PrepareResultsetIterate : public std::unary_function<plugin::QueryCache *, bool>
 
97
class PrepareResultsetIterate
 
98
 : public unary_function<plugin::QueryCache *, bool>
96
99
{
97
100
  Session *session;
98
101
public:
99
102
  PrepareResultsetIterate(Session *session_arg) :
100
 
    std::unary_function<plugin::QueryCache *, bool>(),
101
 
    session(session_arg) { }
 
103
    unary_function<plugin::QueryCache *, bool>(), session(session_arg) { }
102
104
 
103
105
  inline result_type operator()(argument_type handler)
104
106
  {
109
111
{
110
112
  /* Use find_if instead of foreach so that we can collect return codes */
111
113
  QueryCaches::iterator iter=
112
 
    std::find_if(all_query_cache.begin(), all_query_cache.end(),
113
 
                 PrepareResultsetIterate(session));
 
114
    find_if(all_query_cache.begin(), all_query_cache.end(),
 
115
            PrepareResultsetIterate(session));
114
116
  /* If iter is == end() here, that means that all of the plugins returned
115
117
   * false, which in this case means they all succeeded. Since we want to 
116
118
   * return false on success, we return the value of the two being != 
118
120
  return iter != all_query_cache.end();
119
121
}
120
122
 
121
 
class SetResultsetIterate : public std::unary_function<plugin::QueryCache *, bool>
 
123
class SetResultsetIterate
 
124
 : public unary_function<plugin::QueryCache *, bool>
122
125
{
123
126
  Session *session;
124
127
public:
125
128
  SetResultsetIterate(Session *session_arg) :
126
 
    std::unary_function<plugin::QueryCache *, bool>(),
 
129
    unary_function<plugin::QueryCache *, bool>(),
127
130
    session(session_arg) { }
128
131
 
129
132
  inline result_type operator()(argument_type handler)
136
139
{
137
140
  /* Use find_if instead of foreach so that we can collect return codes */
138
141
  QueryCaches::iterator iter=
139
 
    std::find_if(all_query_cache.begin(), all_query_cache.end(),
140
 
                 SetResultsetIterate(session));
 
142
    find_if(all_query_cache.begin(), all_query_cache.end(),
 
143
            SetResultsetIterate(session));
141
144
  /* If iter is == end() here, that means that all of the plugins returned
142
145
   * false, which in this case means they all succeeded. Since we want to 
143
146
   * return false on success, we return the value of the two being != 
146
149
}
147
150
 
148
151
class InsertRecordIterate
149
 
 : public std::unary_function<plugin::QueryCache *, bool>
 
152
 : public unary_function<plugin::QueryCache *, bool>
150
153
{
151
154
  Session *session;
152
155
  List<Item> &item;
153
156
public:
154
157
  InsertRecordIterate(Session *session_arg, List<Item> &item_arg) :
155
 
    std::unary_function<plugin::QueryCache *, bool>(),
 
158
    unary_function<plugin::QueryCache *, bool>(),
156
159
    session(session_arg), item(item_arg) { }
157
160
 
158
161
  inline result_type operator()(argument_type handler)
164
167
{
165
168
  /* Use find_if instead of foreach so that we can collect return codes */
166
169
  QueryCaches::iterator iter=
167
 
    std::find_if(all_query_cache.begin(), all_query_cache.end(),
168
 
                 InsertRecordIterate(session, items));
 
170
    find_if(all_query_cache.begin(), all_query_cache.end(),
 
171
            InsertRecordIterate(session, items));
169
172
  /* If iter is == end() here, that means that all of the plugins returned
170
173
   * false, which in this case means they all succeeded. Since we want to 
171
174
   * return false on success, we return the value of the two being != 
183
186
 
184
187
void plugin::QueryCache::removePlugin(plugin::QueryCache *handler)
185
188
{
186
 
  all_query_cache.erase(std::find(all_query_cache.begin(), all_query_cache.end(),
187
 
                                  handler));
 
189
  all_query_cache.erase(find(all_query_cache.begin(), all_query_cache.end(),
 
190
                        handler));
188
191
}
189
192
 
190
193
} /* namespace drizzled */