1415
by Brian Aker
Mass overhaul to use schema_identifier. |
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; version 2 of the License.
|
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* GNU General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
17 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
18 |
*/
|
|
19 |
||
20 |
#include "config.h" |
|
21 |
||
22 |
#include "drizzled/session.h" |
|
23 |
||
24 |
#include "drizzled/global_charset_info.h" |
|
25 |
#include "drizzled/charset.h" |
|
1979.1.1
by Joseph Daly
move trx id assignment outside of schema engine and in plugin/schema_engine/schema.cc |
26 |
#include "drizzled/transaction_services.h" |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
27 |
|
28 |
#include "drizzled/plugin/storage_engine.h" |
|
29 |
#include "drizzled/plugin/authorization.h" |
|
30 |
||
31 |
namespace drizzled |
|
32 |
{
|
|
33 |
||
34 |
namespace plugin |
|
35 |
{
|
|
36 |
||
37 |
class AddSchemaNames : |
|
1966.2.9
by Brian Aker
Remove the use of "using std" from the plugin interface .cc files. |
38 |
public std::unary_function<StorageEngine *, void> |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
39 |
{
|
1966.2.3
by Brian Aker
Fix another style issue. |
40 |
SchemaIdentifier::vector &schemas; |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
41 |
|
42 |
public: |
|
43 |
||
1966.2.3
by Brian Aker
Fix another style issue. |
44 |
AddSchemaNames(SchemaIdentifier::vector &of_names) : |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
45 |
schemas(of_names) |
46 |
{
|
|
47 |
}
|
|
48 |
||
49 |
result_type operator() (argument_type engine) |
|
50 |
{
|
|
51 |
engine->doGetSchemaIdentifiers(schemas); |
|
52 |
}
|
|
53 |
};
|
|
54 |
||
1966.2.3
by Brian Aker
Fix another style issue. |
55 |
void StorageEngine::getIdentifiers(Session &session, SchemaIdentifier::vector &schemas) |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
56 |
{
|
57 |
// Add hook here for engines to register schema.
|
|
1966.2.14
by Brian Aker
Merge in some additional std namespace finds. |
58 |
std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(), |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
59 |
AddSchemaNames(schemas)); |
60 |
||
61 |
plugin::Authorization::pruneSchemaNames(session.getSecurityContext(), schemas); |
|
62 |
}
|
|
63 |
||
1966.2.9
by Brian Aker
Remove the use of "using std" from the plugin interface .cc files. |
64 |
class StorageEngineGetSchemaDefinition: public std::unary_function<StorageEngine *, bool> |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
65 |
{
|
1642
by Brian Aker
This adds const to SchemaIdentifier. |
66 |
const SchemaIdentifier &identifier; |
1966.2.1
by Brian Aker
Clean up style for shared_ptr for messages around table/schema. |
67 |
message::schema::shared_ptr &schema_proto; |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
68 |
|
69 |
public: |
|
1642
by Brian Aker
This adds const to SchemaIdentifier. |
70 |
StorageEngineGetSchemaDefinition(const SchemaIdentifier &identifier_arg, |
1966.2.1
by Brian Aker
Clean up style for shared_ptr for messages around table/schema. |
71 |
message::schema::shared_ptr &schema_proto_arg) : |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
72 |
identifier(identifier_arg), |
73 |
schema_proto(schema_proto_arg) |
|
74 |
{
|
|
75 |
}
|
|
76 |
||
77 |
result_type operator() (argument_type engine) |
|
78 |
{
|
|
79 |
return engine->doGetSchemaDefinition(identifier, schema_proto); |
|
80 |
}
|
|
81 |
};
|
|
82 |
||
83 |
/*
|
|
84 |
Return value is "if parsed"
|
|
85 |
*/
|
|
1966.2.1
by Brian Aker
Clean up style for shared_ptr for messages around table/schema. |
86 |
bool StorageEngine::getSchemaDefinition(const drizzled::TableIdentifier &identifier, message::schema::shared_ptr &proto) |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
87 |
{
|
88 |
return StorageEngine::getSchemaDefinition(identifier, proto); |
|
89 |
}
|
|
90 |
||
1966.2.1
by Brian Aker
Clean up style for shared_ptr for messages around table/schema. |
91 |
bool StorageEngine::getSchemaDefinition(const SchemaIdentifier &identifier, message::schema::shared_ptr &proto) |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
92 |
{
|
93 |
EngineVector::iterator iter= |
|
1966.2.14
by Brian Aker
Merge in some additional std namespace finds. |
94 |
std::find_if(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(), |
95 |
StorageEngineGetSchemaDefinition(identifier, proto)); |
|
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
96 |
|
97 |
if (iter != StorageEngine::getSchemaEngines().end()) |
|
98 |
{
|
|
99 |
return true; |
|
100 |
}
|
|
101 |
||
102 |
return false; |
|
103 |
}
|
|
104 |
||
1642
by Brian Aker
This adds const to SchemaIdentifier. |
105 |
bool StorageEngine::doesSchemaExist(const SchemaIdentifier &identifier) |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
106 |
{
|
1966.2.1
by Brian Aker
Clean up style for shared_ptr for messages around table/schema. |
107 |
message::schema::shared_ptr proto; |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
108 |
|
109 |
return StorageEngine::getSchemaDefinition(identifier, proto); |
|
110 |
}
|
|
111 |
||
112 |
||
1642
by Brian Aker
This adds const to SchemaIdentifier. |
113 |
const CHARSET_INFO *StorageEngine::getSchemaCollation(const SchemaIdentifier &identifier) |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
114 |
{
|
1966.2.1
by Brian Aker
Clean up style for shared_ptr for messages around table/schema. |
115 |
message::schema::shared_ptr schmema_proto; |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
116 |
bool found; |
117 |
||
118 |
found= StorageEngine::getSchemaDefinition(identifier, schmema_proto); |
|
119 |
||
1812.3.8
by Brian Aker
This switches our schema system over to using a shared ptr. Lets see how |
120 |
if (found && schmema_proto->has_collation()) |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
121 |
{
|
1966.2.9
by Brian Aker
Remove the use of "using std" from the plugin interface .cc files. |
122 |
const std::string buffer= schmema_proto->collation(); |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
123 |
const CHARSET_INFO* cs= get_charset_by_name(buffer.c_str()); |
124 |
||
125 |
if (not cs) |
|
126 |
{
|
|
1954.2.1
by Brian Aker
getSQLPath() modified to take a string so that we can const the table |
127 |
std::string path; |
128 |
identifier.getSQLPath(path); |
|
129 |
||
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
130 |
errmsg_printf(ERRMSG_LVL_ERROR, |
1954.2.1
by Brian Aker
getSQLPath() modified to take a string so that we can const the table |
131 |
_("Error while loading database options: '%s':"), path.c_str()); |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
132 |
errmsg_printf(ERRMSG_LVL_ERROR, ER(ER_UNKNOWN_COLLATION), buffer.c_str()); |
133 |
||
134 |
return default_charset_info; |
|
135 |
}
|
|
136 |
||
137 |
return cs; |
|
138 |
}
|
|
139 |
||
140 |
return default_charset_info; |
|
141 |
}
|
|
142 |
||
143 |
class CreateSchema : |
|
1966.2.9
by Brian Aker
Remove the use of "using std" from the plugin interface .cc files. |
144 |
public std::unary_function<StorageEngine *, void> |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
145 |
{
|
146 |
const drizzled::message::Schema &schema_message; |
|
147 |
||
148 |
public: |
|
149 |
||
1856.2.8
by Joseph Daly
working alter, drop, create schema |
150 |
CreateSchema(const drizzled::message::Schema &arg) : |
151 |
schema_message(arg) |
|
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
152 |
{
|
153 |
}
|
|
154 |
||
155 |
result_type operator() (argument_type engine) |
|
156 |
{
|
|
157 |
// @todo eomeday check that at least one engine said "true"
|
|
1979.1.1
by Joseph Daly
move trx id assignment outside of schema engine and in plugin/schema_engine/schema.cc |
158 |
bool success= engine->doCreateSchema(schema_message); |
159 |
||
160 |
if (success) |
|
161 |
{
|
|
162 |
TransactionServices &transaction_services= TransactionServices::singleton(); |
|
163 |
transaction_services.allocateNewTransactionId(); |
|
164 |
}
|
|
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
165 |
}
|
166 |
};
|
|
167 |
||
1856.2.8
by Joseph Daly
working alter, drop, create schema |
168 |
bool StorageEngine::createSchema(const drizzled::message::Schema &schema_message) |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
169 |
{
|
170 |
// Add hook here for engines to register schema.
|
|
1966.2.14
by Brian Aker
Merge in some additional std namespace finds. |
171 |
std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(), |
172 |
CreateSchema(schema_message)); |
|
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
173 |
|
174 |
return true; |
|
175 |
}
|
|
176 |
||
177 |
class DropSchema : |
|
1966.2.9
by Brian Aker
Remove the use of "using std" from the plugin interface .cc files. |
178 |
public std::unary_function<StorageEngine *, void> |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
179 |
{
|
180 |
uint64_t &success_count; |
|
1642
by Brian Aker
This adds const to SchemaIdentifier. |
181 |
const SchemaIdentifier &identifier; |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
182 |
|
183 |
public: |
|
184 |
||
1642
by Brian Aker
This adds const to SchemaIdentifier. |
185 |
DropSchema(const SchemaIdentifier &arg, uint64_t &count_arg) : |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
186 |
success_count(count_arg), |
187 |
identifier(arg) |
|
188 |
{
|
|
189 |
}
|
|
190 |
||
191 |
result_type operator() (argument_type engine) |
|
192 |
{
|
|
193 |
// @todo someday check that at least one engine said "true"
|
|
194 |
bool success= engine->doDropSchema(identifier); |
|
195 |
||
196 |
if (success) |
|
1979.1.1
by Joseph Daly
move trx id assignment outside of schema engine and in plugin/schema_engine/schema.cc |
197 |
{
|
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
198 |
success_count++; |
1979.1.1
by Joseph Daly
move trx id assignment outside of schema engine and in plugin/schema_engine/schema.cc |
199 |
TransactionServices &transaction_services= TransactionServices::singleton(); |
200 |
transaction_services.allocateNewTransactionId(); |
|
201 |
}
|
|
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
202 |
}
|
203 |
};
|
|
204 |
||
1642
by Brian Aker
This adds const to SchemaIdentifier. |
205 |
bool StorageEngine::dropSchema(const SchemaIdentifier &identifier) |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
206 |
{
|
207 |
uint64_t counter= 0; |
|
208 |
// Add hook here for engines to register schema.
|
|
1966.2.14
by Brian Aker
Merge in some additional std namespace finds. |
209 |
std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(), |
210 |
DropSchema(identifier, counter)); |
|
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
211 |
|
212 |
return counter ? true : false; |
|
213 |
}
|
|
214 |
||
215 |
class AlterSchema : |
|
1966.2.9
by Brian Aker
Remove the use of "using std" from the plugin interface .cc files. |
216 |
public std::unary_function<StorageEngine *, void> |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
217 |
{
|
218 |
uint64_t &success_count; |
|
219 |
const drizzled::message::Schema &schema_message; |
|
220 |
||
221 |
public: |
|
222 |
||
223 |
AlterSchema(const drizzled::message::Schema &arg, uint64_t &count_arg) : |
|
224 |
success_count(count_arg), |
|
225 |
schema_message(arg) |
|
226 |
{
|
|
227 |
}
|
|
228 |
||
229 |
result_type operator() (argument_type engine) |
|
230 |
{
|
|
231 |
// @todo eomeday check that at least one engine said "true"
|
|
232 |
bool success= engine->doAlterSchema(schema_message); |
|
233 |
||
1802.12.1
by Brian Aker
This solves bug lp:654905 |
234 |
|
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
235 |
if (success) |
1979.1.1
by Joseph Daly
move trx id assignment outside of schema engine and in plugin/schema_engine/schema.cc |
236 |
{
|
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
237 |
success_count++; |
1979.1.1
by Joseph Daly
move trx id assignment outside of schema engine and in plugin/schema_engine/schema.cc |
238 |
TransactionServices &transaction_services= TransactionServices::singleton(); |
239 |
transaction_services.allocateNewTransactionId(); |
|
240 |
}
|
|
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
241 |
}
|
242 |
};
|
|
243 |
||
244 |
bool StorageEngine::alterSchema(const drizzled::message::Schema &schema_message) |
|
245 |
{
|
|
246 |
uint64_t success_count= 0; |
|
247 |
||
1966.2.14
by Brian Aker
Merge in some additional std namespace finds. |
248 |
std::for_each(StorageEngine::getSchemaEngines().begin(), StorageEngine::getSchemaEngines().end(), |
249 |
AlterSchema(schema_message, success_count)); |
|
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
250 |
|
251 |
return success_count ? true : false; |
|
252 |
}
|
|
253 |
||
254 |
} /* namespace plugin */ |
|
255 |
} /* namespace drizzled */ |