Drizzled Public API Documentation

table_messages.cc
00001 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2011 Brian Aker
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 #include <config.h>
00022 
00023 #include <drizzled/util/string.h>
00024 #include <drizzled/session/table_messages.h>
00025 #include <drizzled/identifier.h>
00026 #include <drizzled/message/table.h>
00027 #include <drizzled/util/find_ptr.h>
00028 #include <string>
00029 
00030 namespace drizzled {
00031 namespace session {
00032 
00033 bool TableMessages::storeTableMessage(const identifier::Table &identifier, const message::Table &table_message)
00034 {
00035   table_message_cache.insert(make_pair(identifier.getPath(), table_message));
00036   return true;
00037 }
00038 
00039 bool TableMessages::removeTableMessage(const identifier::Table &identifier)
00040 {
00041   Cache::iterator iter= table_message_cache.find(identifier.getPath());
00042   if (iter == table_message_cache.end())
00043     return false;
00044   table_message_cache.erase(iter);
00045   return true;
00046 }
00047 
00048 bool TableMessages::getTableMessage(const identifier::Table &identifier, message::Table &table_message)
00049 {
00050   Cache::mapped_type* ptr= find_ptr(table_message_cache, identifier.getPath());
00051   if (!ptr)
00052     return false;
00053   table_message.CopyFrom(*ptr);
00054   return true;
00055 }
00056 
00057 bool TableMessages::doesTableMessageExist(const identifier::Table &identifier)
00058 {
00059   return find_ptr(table_message_cache, identifier.getPath());
00060 }
00061 
00062 bool TableMessages::renameTableMessage(const identifier::Table &from, const identifier::Table &to)
00063 {
00064   table_message_cache[to.getPath()]= table_message_cache[from.getPath()];
00065   Cache::mapped_type* ptr= find_ptr(table_message_cache, to.getPath());
00066   if (!ptr)
00067     return false;
00068   ptr->set_schema(to.getSchemaName());
00069   ptr->set_name(to.getTableName());
00070   return true;
00071 }
00072 
00073 } /* namespace session */
00074 } /* namespace drizzled */