Drizzled Public API Documentation

query_rewrite.cc

00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2010 Padraig O'Sullivan
00005  *
00006  *  Authors:
00007  *
00008  *    Padraig O'Sullivan <posullivan@akibainc.com>
00009  *
00010  *  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; version 2 of the License.
00013  *
00014  *  This program is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *  GNU General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU General Public License
00020  *  along with this program; if not, write to the Free Software
00021  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022  */
00023 
00024 #include <config.h>
00025 #include <drizzled/plugin/query_rewrite.h>
00026 #include <drizzled/gettext.h>
00027 
00028 #include <algorithm>
00029 #include <vector>
00030 
00031 namespace drizzled
00032 {
00033 
00034 namespace plugin
00035 {
00036 
00037 std::vector<plugin::QueryRewriter *> all_rewriters;
00038 
00039 
00040 bool QueryRewriter::addPlugin(QueryRewriter *in_rewriter)
00041 {
00042   if (in_rewriter != NULL)
00043   {
00044     all_rewriters.push_back(in_rewriter);
00045   }
00046   return false;
00047 }
00048 
00049 
00050 void QueryRewriter::removePlugin(QueryRewriter *in_rewriter)
00051 {
00052   if (in_rewriter != NULL)
00053   {
00054     all_rewriters.erase(std::find(all_rewriters.begin(),
00055                                   all_rewriters.end(),
00056                                   in_rewriter));
00057   }
00058 }
00059 
00060 
00061 /*
00062  * This is the QueryRewriter::rewrite entry point.
00063  * This gets called from within the Drizzle kernel.
00064  */
00065 void QueryRewriter::rewriteQuery(const std::string &schema, std::string &to_rewrite)
00066 {
00067   for (std::vector<plugin::QueryRewriter *>::iterator iter= all_rewriters.begin();
00068        iter != all_rewriters.end();
00069        ++iter)
00070   {
00071     (*iter)->rewrite(schema, to_rewrite);
00072   }
00073 }
00074 
00075 } /* namespace plugin */
00076 
00077 } /* namespace drizzled */