~drizzle-trunk/drizzle/development

1307.1.1 by Padraig O'Sullivan
Added query rewrite interface and plugin point.
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2010 Padraig O'Sullivan
5
 *
6
 *  Authors:
7
 *
8
 *    Padraig O'Sullivan <posullivan@akibainc.com>
9
 *
10
 *  This program is free software; you can redistribute it and/or modify
11
 *  it under the terms of the GNU General Public License as published by
12
 *  the Free Software Foundation; version 2 of the License.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program; if not, write to the Free Software
21
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22
 */
23
2234 by Brian Aker
Mass removal of ifdef/endif in favor of pragma once.
24
#pragma once
1307.1.1 by Padraig O'Sullivan
Added query rewrite interface and plugin point.
25
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
26
#include <drizzled/atomics.h>
27
#include <drizzled/plugin/plugin.h>
1307.1.1 by Padraig O'Sullivan
Added query rewrite interface and plugin point.
28
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
29
#include <drizzled/visibility.h>
2119.4.1 by Monty Taylor
Turns on -fvisibility=hidden by default. Symbols intended to be used by
30
1307.1.1 by Padraig O'Sullivan
Added query rewrite interface and plugin point.
31
/**
32
 * @file Defines the API for a QueryRewriter.  
33
 */
34
35
namespace drizzled
36
{
37
38
namespace plugin
39
{
40
41
/**
42
 * Class which rewrites queries
43
 */
2119.4.1 by Monty Taylor
Turns on -fvisibility=hidden by default. Symbols intended to be used by
44
class DRIZZLED_API QueryRewriter : public Plugin
1307.1.1 by Padraig O'Sullivan
Added query rewrite interface and plugin point.
45
{
46
public:
47
  explicit QueryRewriter(std::string name_arg)
48
    : 
49
      Plugin(name_arg, "QueryRewriter")
50
  {}
51
52
  /**
53
   * Rewrite a query in the form of a std::string
54
   *
1307.1.6 by Padraig O'Sullivan
Updated the query rewriting API based on a suggestion from Jay to pass the schema the Session is currently in after seeing the result of rewriting plugin Padraig developed.
55
   * @param[in] schema the schema the current session is in
1307.1.1 by Padraig O'Sullivan
Added query rewrite interface and plugin point.
56
   * @param[out] to_rewrite string representing the query to rewrite
57
   */
1971.4.2 by Padraig O'Sullivan
Some re-factoring based on feedback from Monty on IRC.
58
  virtual void rewrite(const std::string &schema, std::string &to_rewrite)= 0; 
1307.1.1 by Padraig O'Sullivan
Added query rewrite interface and plugin point.
59
60
  static bool addPlugin(QueryRewriter *in_rewriter);
61
  static void removePlugin(QueryRewriter *in_rewriter);
62
63
  /**
64
   * Take a query to be rewritten and go through all the rewriters that are registered as plugins
65
   * and let the enabled ones rewrite they query.
66
   * TODO: does it make sense to have multiple rewriters?
67
   *
1307.1.6 by Padraig O'Sullivan
Updated the query rewriting API based on a suggestion from Jay to pass the schema the Session is currently in after seeing the result of rewriting plugin Padraig developed.
68
   * @param[in] schema the schema the current session is
1971.4.2 by Padraig O'Sullivan
Some re-factoring based on feedback from Monty on IRC.
69
   * @param[out] to_rewrite the query to rewrite
1307.1.1 by Padraig O'Sullivan
Added query rewrite interface and plugin point.
70
   */
1971.4.2 by Padraig O'Sullivan
Some re-factoring based on feedback from Monty on IRC.
71
  static void rewriteQuery(const std::string &schema, std::string &to_rewrite);
1307.1.1 by Padraig O'Sullivan
Added query rewrite interface and plugin point.
72
};
73
74
} /* namespace plugin */
75
} /* namespace drizzled */
76