~drizzle-trunk/drizzle/development

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
 *
1010 by Brian Aker
Replacing Sun employee copyright headers (aka... anything done by a Sun
4
 *  Copyright (C) 2008 Sun Microsystems
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
1241.9.36 by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h.
21
#include "config.h"
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
22
#include "drizzled/plugin/query_cache.h"
1530.2.5 by Monty Taylor
Renamed classes that were in drizzled::plugin but which were not meant
23
#include "drizzled/errmsg_print.h"
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
24
25
#include "drizzled/gettext.h"
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
1241.9.26 by Monty Taylor
Removed forward declares from server_includes.h
30
class Session;
31
1130.3.10 by Monty Taylor
Cleaned up service namespacing.
32
namespace drizzled
33
{
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
34
typedef std::vector<plugin::QueryCache *> QueryCaches;
1643.6.18 by Djellel E. Difallah
typedef of vector<plugin::QueryCache *> into QueryCaches
35
QueryCaches all_query_cache;
968.2.37 by Monty Taylor
Converted qcache plugin.
36
37
/* Namespaces are here to prevent global symbol clashes with these classes */
38
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
class IsCachedIterate
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
40
 : 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
41
{
42
  Session *session;
43
public:
44
  IsCachedIterate(Session* session_arg) :
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
45
    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
46
    session(session_arg) { }
47
48
  inline result_type operator()(argument_type handler)
49
  {
50
    return handler->doIsCached(session);
51
  }
52
};
53
54
bool plugin::QueryCache::isCached(Session *session)
55
{
56
  /* 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
57
  QueryCaches::iterator iter=
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
58
    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
59
            IsCachedIterate(session));
60
  /* If iter is == end() here, that means that all of the plugins returned
61
   * false, which in this case means they all succeeded. Since we want to 
62
   * return false on success, we return the value of the two being != 
63
   */
64
  return iter != all_query_cache.end();
65
}
66
67
68
class SendCachedResultsetIterate
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
69
 : 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
70
{
71
  Session *session;
72
public:
73
  SendCachedResultsetIterate(Session *session_arg) :
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
74
    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
75
    session(session_arg) { }
76
77
  inline result_type operator()(argument_type handler)
78
  {
1643.6.5 by Djellel E. Difallah
retrieve data from the local cache
79
    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
80
  }
81
};
82
bool plugin::QueryCache::sendCachedResultset(Session *session)
83
{
84
  /* 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
85
  QueryCaches::iterator iter=
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
86
    std::find_if(all_query_cache.begin(), all_query_cache.end(),
87
                 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
88
  /* If iter is == end() here, that means that all of the plugins returned
89
   * false, which in this case means they all succeeded. Since we want to 
90
   * return false on success, we return the value of the two being != 
91
   */
92
  return iter != all_query_cache.end();
93
}
1643.6.1 by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin
94
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
95
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
96
{
97
  Session *session;
98
public:
99
  PrepareResultsetIterate(Session *session_arg) :
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
100
    std::unary_function<plugin::QueryCache *, bool>(),
101
    session(session_arg) { }
772.1.1 by Toru Maesaka
Defined the first version of the Query Cache interface.
102
968.2.37 by Monty Taylor
Converted qcache plugin.
103
  inline result_type operator()(argument_type handler)
772.1.1 by Toru Maesaka
Defined the first version of the Query Cache interface.
104
  {
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
105
    return handler->doPrepareResultset(session);
1643.6.1 by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin
106
  }
107
};
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
108
bool plugin::QueryCache::prepareResultset(Session *session)
109
{
110
  /* 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
111
  QueryCaches::iterator iter=
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
112
    std::find_if(all_query_cache.begin(), all_query_cache.end(),
113
                 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
114
  /* If iter is == end() here, that means that all of the plugins returned
115
   * false, which in this case means they all succeeded. Since we want to 
116
   * return false on success, we return the value of the two being != 
117
   */
118
  return iter != all_query_cache.end();
119
}
1643.6.1 by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin
120
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
121
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
122
{
123
  Session *session;
124
public:
125
  SetResultsetIterate(Session *session_arg) :
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
126
    std::unary_function<plugin::QueryCache *, bool>(),
1643.6.1 by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin
127
    session(session_arg) { }
128
129
  inline result_type operator()(argument_type handler)
130
  {
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
131
    return handler->doSetResultset(session);
1643.6.1 by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin
132
  }
133
};
134
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
135
bool plugin::QueryCache::setResultset(Session *session)
136
{
137
  /* 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
138
  QueryCaches::iterator iter=
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
139
    std::find_if(all_query_cache.begin(), all_query_cache.end(),
140
                 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
141
  /* If iter is == end() here, that means that all of the plugins returned
142
   * false, which in this case means they all succeeded. Since we want to 
143
   * return false on success, we return the value of the two being != 
144
   */
145
  return iter != all_query_cache.end();
146
}
147
1643.6.1 by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin
148
class InsertRecordIterate
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
149
 : 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
150
{
151
  Session *session;
152
  List<Item> &item;
153
public:
154
  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.
155
    std::unary_function<plugin::QueryCache *, bool>(),
1643.6.1 by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin
156
    session(session_arg), item(item_arg) { }
157
158
  inline result_type operator()(argument_type handler)
159
  {
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
160
    return handler->doInsertRecord(session, item);
1643.6.1 by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin
161
  }
162
};
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
163
bool plugin::QueryCache::insertRecord(Session *session, List<Item> &items)
164
{
165
  /* 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
166
  QueryCaches::iterator iter=
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
167
    std::find_if(all_query_cache.begin(), all_query_cache.end(),
168
                 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
169
  /* If iter is == end() here, that means that all of the plugins returned
170
   * false, which in this case means they all succeeded. Since we want to 
171
   * return false on success, we return the value of the two being != 
172
   */
173
  return iter != all_query_cache.end();
174
}
1643.6.1 by Djellel E. Difallah
Added hook points and the interface for the Query Cache plugin
175
176
968.2.37 by Monty Taylor
Converted qcache plugin.
177
1130.1.19 by Monty Taylor
Added error reporting to plugin registration.
178
bool plugin::QueryCache::addPlugin(plugin::QueryCache *handler)
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
179
{
180
  all_query_cache.push_back(handler);
1130.1.19 by Monty Taylor
Added error reporting to plugin registration.
181
  return false;
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
182
}
183
1130.1.18 by Monty Taylor
Changed ::add() and ::remove() to ::addPlugin() and ::removePlugin() so that
184
void plugin::QueryCache::removePlugin(plugin::QueryCache *handler)
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
185
{
1966.2.9 by Brian Aker
Remove the use of "using std" from the plugin interface .cc files.
186
  all_query_cache.erase(std::find(all_query_cache.begin(), all_query_cache.end(),
187
                                  handler));
1130.1.1 by Monty Taylor
Merged in plugin-slot-reorg patches.
188
}
189
1130.3.10 by Monty Taylor
Cleaned up service namespacing.
190
} /* namespace drizzled */