~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/query_cache.cc

  • Committer: Andrew Hutchings
  • Date: 2010-09-08 19:03:09 UTC
  • mfrom: (1750 staging)
  • mto: (1750.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1751.
  • Revision ID: andrew@linuxjedi.co.uk-20100908190309-mya1nu7xvo1fpvk8
Merge trunk into branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
4
 *  Copyright (C) 2008 Sun Microsystems
 
5
 *  Copyright (C) 2010 Djellel Eddine Difallah
5
6
 *
6
7
 *  This program is free software; you can redistribute it and/or modify
7
8
 *  it under the terms of the GNU General Public License as published by
32
33
 
33
34
namespace drizzled
34
35
{
35
 
 
36
 
vector<plugin::QueryCache *> all_query_cache;
 
36
typedef vector<plugin::QueryCache *> QueryCaches;
 
37
QueryCaches all_query_cache;
37
38
 
38
39
/* Namespaces are here to prevent global symbol clashes with these classes */
39
40
 
40
 
class TryFetchAndSendIterate
41
 
 : public unary_function<plugin::QueryCache *, bool>
42
 
{
43
 
  Session *session;
44
 
  bool is_transactional;
45
 
public:
46
 
  TryFetchAndSendIterate(Session *session_arg, bool is_transactional_arg) :
47
 
    unary_function<plugin::QueryCache *, bool>(),
48
 
    session(session_arg), is_transactional(is_transactional_arg) { }
49
 
 
50
 
  inline result_type operator()(argument_type handler)
51
 
  {
52
 
    if (handler->tryFetchAndSend(session, is_transactional))
53
 
    {
54
 
      errmsg_printf(ERRMSG_LVL_ERROR,
55
 
                    _("qcache plugin '%s' try_fetch_and_send() failed"),
56
 
                    handler->getName().c_str());
57
 
      return true;
58
 
    }
59
 
    return false;
60
 
  }
61
 
};
62
 
 
63
 
class SetIterate
64
 
 : public unary_function<plugin::QueryCache *, bool>
65
 
{
66
 
  Session *session;
67
 
  bool is_transactional;
68
 
public:
69
 
  SetIterate(Session *session_arg, bool is_transactional_arg) :
70
 
    unary_function<plugin::QueryCache *, bool>(),
71
 
    session(session_arg), is_transactional(is_transactional_arg) { }
72
 
 
73
 
  inline result_type operator()(argument_type handler)
74
 
  {
75
 
 
76
 
    if (handler->set(session, is_transactional))
77
 
    {
78
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("qcache plugin '%s' set() failed"),
79
 
                    handler->getName().c_str());
80
 
      return true;
81
 
    }
82
 
    return false;
83
 
  }
84
 
};
85
 
 
86
 
class InvalidateTableIterate
87
 
 : public unary_function<plugin::QueryCache *, bool>
88
 
{
89
 
  Session *session;
90
 
  bool is_transactional;
91
 
public:
92
 
  InvalidateTableIterate(Session *session_arg, bool is_transactional_arg) :
93
 
    unary_function<plugin::QueryCache *, bool>(),
94
 
    session(session_arg), is_transactional(is_transactional_arg) { }
95
 
 
96
 
  inline result_type operator()(argument_type handler)
97
 
  {
98
 
 
99
 
    if (handler->invalidateTable(session, is_transactional))
100
 
    {
101
 
      errmsg_printf(ERRMSG_LVL_ERROR,
102
 
                    _("qcache plugin '%s' invalidateTable() failed"),
103
 
                    handler->getName().c_str());
104
 
      return true;
105
 
    }
106
 
    return false;
107
 
  }
108
 
};
109
 
 
110
 
 
111
 
class InvalidateDbIterate
112
 
 : public unary_function<plugin::QueryCache *, bool>
113
 
{
114
 
  Session *session;
115
 
  const char *dbname;
116
 
  bool is_transactional;
117
 
public:
118
 
  InvalidateDbIterate(Session *session_arg, const char *dbname_arg,
119
 
                      bool is_transactional_arg) :
120
 
    unary_function<plugin::QueryCache *, bool>(),
121
 
    session(session_arg), dbname(dbname_arg),
122
 
    is_transactional(is_transactional_arg) { }
123
 
 
124
 
  inline result_type operator()(argument_type handler)
125
 
  {
126
 
    if (handler->invalidateDb(session, dbname, is_transactional))
127
 
    {
128
 
      errmsg_printf(ERRMSG_LVL_ERROR,
129
 
                    _("qcache plugin '%s' invalidateDb() failed"),
130
 
                    handler->getName().c_str());
131
 
      return true;
132
 
    }
133
 
    return false;
134
 
  }
135
 
};
136
 
 
137
 
class FlushIterate
138
 
 : public unary_function<plugin::QueryCache *, bool>
139
 
{
140
 
  Session *session;
141
 
public:
142
 
  FlushIterate(Session *session_arg) :
 
41
class IsCachedIterate
 
42
 : public unary_function<plugin::QueryCache *, bool>
 
43
{
 
44
  Session *session;
 
45
public:
 
46
  IsCachedIterate(Session* session_arg) :
 
47
    unary_function<plugin::QueryCache *, bool>(),
 
48
    session(session_arg) { }
 
49
 
 
50
  inline result_type operator()(argument_type handler)
 
51
  {
 
52
    return handler->doIsCached(session);
 
53
  }
 
54
};
 
55
 
 
56
bool plugin::QueryCache::isCached(Session *session)
 
57
{
 
58
  /* Use find_if instead of foreach so that we can collect return codes */
 
59
  QueryCaches::iterator iter=
 
60
    find_if(all_query_cache.begin(), all_query_cache.end(),
 
61
            IsCachedIterate(session));
 
62
  /* If iter is == end() here, that means that all of the plugins returned
 
63
   * false, which in this case means they all succeeded. Since we want to 
 
64
   * return false on success, we return the value of the two being != 
 
65
   */
 
66
  return iter != all_query_cache.end();
 
67
}
 
68
 
 
69
 
 
70
class SendCachedResultsetIterate
 
71
 : public unary_function<plugin::QueryCache *, bool>
 
72
{
 
73
  Session *session;
 
74
public:
 
75
  SendCachedResultsetIterate(Session *session_arg) :
 
76
    unary_function<plugin::QueryCache *, bool>(),
 
77
    session(session_arg) { }
 
78
 
 
79
  inline result_type operator()(argument_type handler)
 
80
  {
 
81
    return handler->doSendCachedResultset(session);
 
82
  }
 
83
};
 
84
bool plugin::QueryCache::sendCachedResultset(Session *session)
 
85
{
 
86
  /* Use find_if instead of foreach so that we can collect return codes */
 
87
  QueryCaches::iterator iter=
 
88
    find_if(all_query_cache.begin(), all_query_cache.end(),
 
89
            SendCachedResultsetIterate(session));
 
90
  /* If iter is == end() here, that means that all of the plugins returned
 
91
   * false, which in this case means they all succeeded. Since we want to 
 
92
   * return false on success, we return the value of the two being != 
 
93
   */
 
94
  return iter != all_query_cache.end();
 
95
}
 
96
 
 
97
class PrepareResultsetIterate
 
98
 : public unary_function<plugin::QueryCache *, bool>
 
99
{
 
100
  Session *session;
 
101
public:
 
102
  PrepareResultsetIterate(Session *session_arg) :
143
103
    unary_function<plugin::QueryCache *, bool>(), session(session_arg) { }
144
104
 
145
105
  inline result_type operator()(argument_type handler)
146
106
  {
147
 
    if (handler->flush(session))
148
 
    {
149
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("qcache plugin '%s' flush() failed"),
150
 
                    handler->getName().c_str());
151
 
      return true;
152
 
    }
153
 
    return false;
154
 
  }
155
 
};
 
107
    return handler->doPrepareResultset(session);
 
108
  }
 
109
};
 
110
bool plugin::QueryCache::prepareResultset(Session *session)
 
111
{
 
112
  /* Use find_if instead of foreach so that we can collect return codes */
 
113
  QueryCaches::iterator iter=
 
114
    find_if(all_query_cache.begin(), all_query_cache.end(),
 
115
            PrepareResultsetIterate(session));
 
116
  /* If iter is == end() here, that means that all of the plugins returned
 
117
   * false, which in this case means they all succeeded. Since we want to 
 
118
   * return false on success, we return the value of the two being != 
 
119
   */
 
120
  return iter != all_query_cache.end();
 
121
}
 
122
 
 
123
class SetResultsetIterate
 
124
 : public unary_function<plugin::QueryCache *, bool>
 
125
{
 
126
  Session *session;
 
127
public:
 
128
  SetResultsetIterate(Session *session_arg) :
 
129
    unary_function<plugin::QueryCache *, bool>(),
 
130
    session(session_arg) { }
 
131
 
 
132
  inline result_type operator()(argument_type handler)
 
133
  {
 
134
    return handler->doSetResultset(session);
 
135
  }
 
136
};
 
137
 
 
138
bool plugin::QueryCache::setResultset(Session *session)
 
139
{
 
140
  /* Use find_if instead of foreach so that we can collect return codes */
 
141
  QueryCaches::iterator iter=
 
142
    find_if(all_query_cache.begin(), all_query_cache.end(),
 
143
            SetResultsetIterate(session));
 
144
  /* If iter is == end() here, that means that all of the plugins returned
 
145
   * false, which in this case means they all succeeded. Since we want to 
 
146
   * return false on success, we return the value of the two being != 
 
147
   */
 
148
  return iter != all_query_cache.end();
 
149
}
 
150
 
 
151
class InsertRecordIterate
 
152
 : public unary_function<plugin::QueryCache *, bool>
 
153
{
 
154
  Session *session;
 
155
  List<Item> &item;
 
156
public:
 
157
  InsertRecordIterate(Session *session_arg, List<Item> &item_arg) :
 
158
    unary_function<plugin::QueryCache *, bool>(),
 
159
    session(session_arg), item(item_arg) { }
 
160
 
 
161
  inline result_type operator()(argument_type handler)
 
162
  {
 
163
    return handler->doInsertRecord(session, item);
 
164
  }
 
165
};
 
166
bool plugin::QueryCache::insertRecord(Session *session, List<Item> &items)
 
167
{
 
168
  /* Use find_if instead of foreach so that we can collect return codes */
 
169
  QueryCaches::iterator iter=
 
170
    find_if(all_query_cache.begin(), all_query_cache.end(),
 
171
            InsertRecordIterate(session, items));
 
172
  /* If iter is == end() here, that means that all of the plugins returned
 
173
   * false, which in this case means they all succeeded. Since we want to 
 
174
   * return false on success, we return the value of the two being != 
 
175
   */
 
176
  return iter != all_query_cache.end();
 
177
}
 
178
 
 
179
 
156
180
 
157
181
bool plugin::QueryCache::addPlugin(plugin::QueryCache *handler)
158
182
{
166
190
                        handler));
167
191
}
168
192
 
169
 
 
170
 
bool plugin::QueryCache::tryFetchAndSendDo(Session *session,
171
 
                                           bool transactional)
172
 
{
173
 
  /* Use find_if instead of foreach so that we can collect return codes */
174
 
  vector<plugin::QueryCache *>::iterator iter=
175
 
    find_if(all_query_cache.begin(), all_query_cache.end(),
176
 
            TryFetchAndSendIterate(session, transactional));
177
 
  /* If iter is == end() here, that means that all of the plugins returned
178
 
   * false, which in this case means they all succeeded. Since we want to 
179
 
   * return false on success, we return the value of the two being != 
180
 
   */
181
 
  return iter != all_query_cache.end();
182
 
}
183
 
 
184
 
bool plugin::QueryCache::setDo(Session *session, bool transactional)
185
 
{
186
 
  /* Use find_if instead of foreach so that we can collect return codes */
187
 
  vector<plugin::QueryCache *>::iterator iter=
188
 
    find_if(all_query_cache.begin(), all_query_cache.end(),
189
 
            SetIterate(session, transactional));
190
 
  /* If iter is == end() here, that means that all of the plugins returned
191
 
   * false, which in this case means they all succeeded. Since we want to 
192
 
   * return false on success, we return the value of the two being != 
193
 
   */
194
 
  return iter != all_query_cache.end();
195
 
}
196
 
 
197
 
bool plugin::QueryCache::invalidateTableDo(Session *session,
198
 
                                         bool transactional)
199
 
{
200
 
  /* Use find_if instead of foreach so that we can collect return codes */
201
 
  vector<plugin::QueryCache *>::iterator iter=
202
 
    find_if(all_query_cache.begin(), all_query_cache.end(),
203
 
            InvalidateTableIterate(session, transactional));
204
 
  /* If iter is == end() here, that means that all of the plugins returned
205
 
   * false, which in this case means they all succeeded. Since we want to 
206
 
   * return false on success, we return the value of the two being != 
207
 
   */
208
 
  return iter != all_query_cache.end();
209
 
}
210
 
 
211
 
bool plugin::QueryCache::invalidateDbDo(Session *session, const char *dbname,
212
 
                                        bool transactional)
213
 
{
214
 
  /* Use find_if instead of foreach so that we can collect return codes */
215
 
  vector<plugin::QueryCache *>::iterator iter=
216
 
    find_if(all_query_cache.begin(), all_query_cache.end(),
217
 
            InvalidateDbIterate(session, dbname, transactional));
218
 
  /* If iter is == end() here, that means that all of the plugins returned
219
 
   * false, which in this case means they all succeeded. Since we want to 
220
 
   * return false on success, we return the value of the two being != 
221
 
   */
222
 
  return iter != all_query_cache.end();
223
 
}
224
 
 
225
 
bool plugin::QueryCache::flushDo(Session *session)
226
 
{
227
 
  /* Use find_if instead of foreach so that we can collect return codes */
228
 
  vector<plugin::QueryCache *>::iterator iter=
229
 
    find_if(all_query_cache.begin(), all_query_cache.end(),
230
 
            FlushIterate(session));
231
 
  /* If iter is == end() here, that means that all of the plugins returned
232
 
   * false, which in this case means they all succeeded. Since we want to 
233
 
   * return false on success, we return the value of the two being != 
234
 
   */
235
 
  return iter != all_query_cache.end();
236
 
}
237
 
 
238
193
} /* namespace drizzled */