drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
drizzled/generator/schema.cc
1/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2010 Brian Aker
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <config.h>
22
23#include <drizzled/generator.h>
24#include <drizzled/session.h>
25
26#include <algorithm>
27#include <random>
28
29using namespace std;
30
31namespace drizzled
32{
33namespace generator
34{
35
36Schema::Schema(Session &arg) :
37 session(arg)
38 {
39 plugin::StorageEngine::getIdentifiers(session, schema_names);
40#if defined(DEBUG)
41 std::random_device random_device;
42 std::mt19937 generator(random_device());
43 std::shuffle(schema_names.begin(), schema_names.end(), generator);
44#endif
45 schema_iterator= schema_names.begin();
46 }
47
48Schema::operator const drizzled::message::schema::shared_ptr()
49{
50 while (schema_iterator != schema_names.end())
51 {
52 identifier::Schema schema_identifier(*schema_iterator);
53
54 if (not plugin::Authorization::isAuthorized(*session.user(), schema_identifier, false))
55 {
56 schema_iterator++;
57 continue;
58 }
59
60 schema= plugin::StorageEngine::getSchemaDefinition(schema_identifier);
61 schema_iterator++;
62
63 if (schema)
64 return schema;
65 }
66
67 return message::schema::shared_ptr();
68}
69
70Schema::operator const drizzled::identifier::Schema*()
71{
72 while (schema_iterator != schema_names.end())
73 {
74 const drizzled::identifier::Schema *_ptr= &(*schema_iterator);
75 schema_iterator++;
76
77 if (not plugin::Authorization::isAuthorized(*session.user(), *_ptr, false))
78 continue;
79
80 return _ptr;
81 }
82
83 return NULL;
84}
85
86} /* namespace generator */
87} /* namespace drizzled */
TODO: Rename this file - func.h is stupid.
STL namespace.