Drizzled Public API Documentation

table.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 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 
00022 #include <config.h>
00023 #include <drizzled/message/table.h>
00024 #include <drizzled/charset.h>
00025 #include <drizzled/catalog/local.h>
00026 
00027 namespace drizzled {
00028 namespace message {
00029 namespace table {
00030 
00031 shared_ptr make_shared(const identifier::Table& identifier, const std::string &engine_arg)
00032 {
00033   shared_ptr shared(new message::Table);
00034 
00035   init(*shared, identifier.getTableName(), identifier.getSchemaName(), engine_arg);
00036 
00037   return shared;
00038 }
00039 
00040 shared_ptr make_shared(const std::string &name_arg, const std::string &schema_arg, const std::string &engine_arg)
00041 {
00042   shared_ptr shared(new message::Table);
00043 
00044   init(*shared, name_arg, schema_arg, engine_arg);
00045 
00046   return shared;
00047 }
00048 
00049 void init(drizzled::message::Table &arg, const std::string &name_arg, const std::string &schema_arg, const std::string &engine_arg)
00050 {
00051   arg.set_name(name_arg);
00052   arg.set_schema(schema_arg);
00053   arg.set_creation_timestamp(time(NULL));
00054   arg.set_update_timestamp(time(NULL));
00055   arg.mutable_engine()->set_name(engine_arg);
00056 
00057   /* 36 characters for uuid string +1 for NULL */
00058   uuid_t uu;
00059   char uuid_string[37];
00060   uuid_generate_random(uu);
00061   uuid_unparse(uu, uuid_string);
00062   arg.set_uuid(uuid_string, 36);
00063 
00064   arg.set_version(1);
00065 
00066   if (not arg.has_type())
00067   {
00068     arg.set_type(drizzled::message::Table::STANDARD);
00069   }
00070 
00071   arg.mutable_options()->set_collation_id(default_charset_info->number);
00072   arg.mutable_options()->set_collation(default_charset_info->name);
00073 
00074   arg.set_catalog(drizzled::catalog::local()->name());
00075 }
00076 
00077 void update(drizzled::message::Table &arg)
00078 {
00079   arg.set_version(arg.version() + 1);
00080   arg.set_update_timestamp(time(NULL));
00081 }
00082 
00083 } // namespace table
00084 } // namespace message
00085 } // namespace drizzled