Drizzled Public API Documentation

schema.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 #include <config.h>
00022 
00023 #include <drizzled/generator.h>
00024 #include <drizzled/session.h>
00025 
00026 using namespace std;
00027 
00028 namespace drizzled
00029 {
00030 namespace generator
00031 {
00032 
00033 Schema::Schema(Session &arg) :
00034   session(arg)
00035   {
00036     plugin::StorageEngine::getIdentifiers(session, schema_names);
00037 #if defined(DEBUG)
00038     random_shuffle(schema_names.begin(), schema_names.end());
00039 #endif
00040     schema_iterator= schema_names.begin();
00041   }
00042 
00043 Schema::operator const drizzled::message::schema::shared_ptr()
00044 {
00045   while (schema_iterator != schema_names.end())
00046   {
00047     identifier::Schema schema_identifier(*schema_iterator);
00048 
00049     if (not plugin::Authorization::isAuthorized(*session.user(), schema_identifier, false))
00050     {
00051       schema_iterator++;
00052       continue;
00053     }
00054 
00055     schema= plugin::StorageEngine::getSchemaDefinition(schema_identifier);
00056     schema_iterator++;
00057 
00058     if (schema)
00059       return schema;
00060   }
00061 
00062   return message::schema::shared_ptr();
00063 }
00064 
00065 Schema::operator const drizzled::identifier::Schema*()
00066 {
00067   while (schema_iterator != schema_names.end())
00068   {
00069     const drizzled::identifier::Schema *_ptr= &(*schema_iterator);
00070     schema_iterator++;
00071 
00072     if (not plugin::Authorization::isAuthorized(*session.user(), *_ptr, false))
00073       continue;
00074 
00075     return _ptr;
00076   }
00077 
00078   return NULL;
00079 }
00080 
00081 } /* namespace generator */
00082 } /* namespace drizzled */