~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/memcached_query_cache/query_cache_service.h

  • 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:
 
1
/* 
 
2
 * Copyright (c) 2010, Djellel Eddine Difallah
 
3
 * All rights reserved.
 
4
 *
 
5
 * Redistribution and use in source and binary forms, with or without
 
6
 * modification, are permitted provided that the following conditions are met:
 
7
 *
 
8
 *   * Redistributions of source code must retain the above copyright notice,
 
9
 *     this list of conditions and the following disclaimer.
 
10
 *   * Redistributions in binary form must reproduce the above copyright notice,
 
11
 *     this list of conditions and the following disclaimer in the documentation
 
12
 *     and/or other materials provided with the distribution.
 
13
 *   * Neither the name of Djellel Eddine Difallah nor the names of its contributors
 
14
 *     may be used to endorse or promote products derived from this software
 
15
 *     without specific prior written permission.
 
16
 *
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 
18
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
19
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
20
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 
21
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 
22
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 
23
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 
24
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 
25
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 
26
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 
27
 * THE POSSIBILITY OF SUCH DAMAGE.
 
28
 */
 
29
#ifndef PLUGIN_MEMCACHED_QUERY_CACHE_QUERY_CACHE_SERVICE_H
 
30
#define PLUGIN_MEMCACHED_QUERY_CACHE_QUERY_CACHE_SERVICE_H
 
31
 
 
32
#include "drizzled/message/resultset.pb.h"
 
33
#include <drizzled/sql_list.h>
 
34
#include <map>
 
35
#include <vector>
 
36
 
 
37
namespace drizzled
 
38
{
 
39
class TableList;
 
40
class Item;
 
41
 
 
42
namespace message
 
43
{
 
44
class Resultset;
 
45
}
 
46
 
 
47
class QueryCacheService
 
48
{
 
49
public:
 
50
 
 
51
  typedef std::map<std::string, drizzled::message::Resultset> CacheEntries;
 
52
  typedef std::pair<const std::string, drizzled::message::Resultset> CacheEntry;
 
53
  typedef std::map<std::string, std::vector<std::string>> CachedTablesEntries;
 
54
  typedef std::pair<const std::string, std::vector<std::string>> CachedTablesEntry;
 
55
 
 
56
  static const size_t DEFAULT_RECORD_SIZE= 100;
 
57
  static CacheEntries cache;
 
58
  static CachedTablesEntries cachedTables;
 
59
 
 
60
  /**
 
61
   * Singleton method
 
62
   * Returns the singleton instance of QueryCacheService
 
63
   */
 
64
  static inline QueryCacheService &singleton()
 
65
  {
 
66
    static QueryCacheService query_cache_service;
 
67
    return query_cache_service;
 
68
  };
 
69
 
 
70
  /**
 
71
   * Method which returns the active Resultset message
 
72
   * for the supplied Session.  If one is not found, a new Resultset
 
73
   * message is allocated, initialized, and returned.
 
74
   *
 
75
   * @param The session processing the Select
 
76
   */
 
77
  drizzled::message::Resultset *setCurrentResultsetMessage(drizzled::Session *in_session);
 
78
 
 
79
  /**
 
80
   * Helper method which initializes the header message for
 
81
   * a Resultset.
 
82
   *
 
83
   * @param[inout] Resultset message container to modify
 
84
   * @param[in] Pointer to the Session doing the processing
 
85
   * @param[in] Pointer to the Table being inserted into
 
86
   */
 
87
  void setResultsetHeader(drizzled::message::Resultset &resultset,
 
88
                       drizzled::Session *in_session,
 
89
                       drizzled::TableList *in_table);
 
90
  /**
 
91
   * Creates a new SelectRecord GPB message and pushes it to
 
92
   * currrent Resultset.
 
93
   *
 
94
   * @param Pointer to the Session which has inserted a record
 
95
   * @param Pointer to the List<Items> to add
 
96
   */
 
97
  bool addRecord(drizzled::Session *in_session, drizzled::List<drizzled::Item> &list);
 
98
 
 
99
  /* cache fetching */
 
100
  static bool isCached(std::string query);
 
101
  
 
102
}; 
 
103
} /* namespace drizzled */
 
104
#endif /* PLUGIN_MEMCACHED_QUERY_CACHE_QUERY_CACHE_SERVICE_H */