~jaypipes/drizzle/xa-transaction-log

« back to all changes in this revision

Viewing changes to drizzled/plugin/storage_engine.cc

  • Committer: Jay Pipes
  • Date: 2010-03-05 18:24:28 UTC
  • mfrom: (1273.1.51 staging)
  • Revision ID: jpipes@serialcoder-20100305182428-9m16fszbs3mvdhe0
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
#include "drizzled/xid.h"
48
48
#include "drizzled/sql_table.h"
49
49
#include "drizzled/global_charset_info.h"
 
50
#include "drizzled/plugin/authorization.h"
50
51
#include "drizzled/charset.h"
51
52
#include "drizzled/internal/my_sys.h"
52
53
#include "drizzled/db.h"
309
310
  const char *db;
310
311
  const char *table_name;
311
312
  const bool is_tmp;
312
 
  message::Table *table_proto;
 
313
  message::Table *table_message;
313
314
  int *err;
314
315
 
315
316
public:
318
319
                                  const char *db_arg,
319
320
                                  const char *table_name_arg,
320
321
                                  const bool is_tmp_arg,
321
 
                                  message::Table *table_proto_arg,
 
322
                                  message::Table *table_message_arg,
322
323
                                  int *err_arg) :
323
324
    session(session_arg), 
324
325
    path(path_arg), 
325
326
    db(db_arg),
326
327
    table_name(table_name_arg),
327
328
    is_tmp(is_tmp_arg),
328
 
    table_proto(table_proto_arg), 
 
329
    table_message(table_message_arg), 
329
330
    err(err_arg) {}
330
331
 
331
332
  result_type operator() (argument_type engine)
335
336
                                          db,
336
337
                                          table_name,
337
338
                                          is_tmp,
338
 
                                          table_proto);
 
339
                                          table_message);
339
340
 
340
341
    if (ret != ENOENT)
341
342
      *err= ret;
361
362
*/
362
363
int StorageEngine::getTableDefinition(Session& session,
363
364
                                      TableIdentifier &identifier,
364
 
                                      message::Table *table_proto,
 
365
                                      message::Table *table_message,
365
366
                                      bool include_temporary_tables)
366
367
{
367
368
  return getTableDefinition(session,
368
369
                            identifier.getPath(), identifier.getDBName(), identifier.getTableName(), identifier.isTmp(),
369
 
                            table_proto, include_temporary_tables);
 
370
                            table_message, include_temporary_tables);
370
371
}
371
372
 
372
373
int StorageEngine::getTableDefinition(Session& session,
374
375
                                              const char *schema_name,
375
376
                                              const char *table_name,
376
377
                                              const bool,
377
 
                                              message::Table *table_proto,
 
378
                                              message::Table *table_message,
378
379
                                              bool include_temporary_tables)
379
380
{
380
381
  int err= ENOENT;
381
382
 
382
383
  if (include_temporary_tables)
383
384
  {
384
 
    if (session.doGetTableDefinition(path, schema_name, table_name, false, table_proto) == EEXIST)
 
385
    if (session.doGetTableDefinition(path, schema_name, table_name, false, table_message) == EEXIST)
385
386
      return EEXIST;
386
387
  }
387
388
 
388
389
  EngineVector::iterator iter=
389
390
    find_if(vector_of_engines.begin(), vector_of_engines.end(),
390
 
            StorageEngineGetTableDefinition(session, path, NULL, NULL, true, table_proto, &err));
 
391
            StorageEngineGetTableDefinition(session, path, NULL, NULL, true, table_message, &err));
391
392
 
392
393
  if (iter == vector_of_engines.end())
393
394
  {
514
515
   @todo refactor to remove goto
515
516
*/
516
517
int StorageEngine::createTable(Session& session,
517
 
                                       TableIdentifier &identifier,
518
 
                                       bool update_create_info,
519
 
                                       message::Table& table_proto, bool proto_used)
 
518
                               TableIdentifier &identifier,
 
519
                               bool update_create_info,
 
520
                               message::Table& table_message)
520
521
{
521
522
  int error= 1;
522
523
  Table table;
523
524
  TableShare share(identifier.getDBName(), 0, identifier.getTableName(), identifier.getPath());
524
525
  message::Table tmp_proto;
525
526
 
526
 
  if (proto_used)
527
 
  {
528
 
    if (parse_table_proto(session, table_proto, &share))
529
 
      goto err;
530
 
  }
531
 
  else
532
 
  {
533
 
    if (open_table_def(session, &share))
534
 
      goto err;
535
 
  }
 
527
  if (parse_table_proto(session, table_message, &share))
 
528
    goto err;
536
529
 
537
530
  if (open_table_from_share(&session, &share, "", 0, 0,
538
531
                            &table))
539
532
    goto err;
540
533
 
541
534
  if (update_create_info)
542
 
    table.updateCreateInfo(&table_proto);
 
535
    table.updateCreateInfo(&table_message);
543
536
 
544
537
  /* Check for legal operations against the Engine using the proto (if used) */
545
 
  if (proto_used)
546
 
  {
547
 
    if (table_proto.type() == message::Table::TEMPORARY &&
548
 
        share.storage_engine->check_flag(HTON_BIT_TEMPORARY_NOT_SUPPORTED) == true)
549
 
    {
550
 
      error= HA_ERR_UNSUPPORTED;
551
 
      goto err2;
552
 
    }
553
 
    else if (table_proto.type() != message::Table::TEMPORARY &&
554
 
             share.storage_engine->check_flag(HTON_BIT_TEMPORARY_ONLY) == true)
555
 
    {
556
 
      error= HA_ERR_UNSUPPORTED;
557
 
      goto err2;
558
 
    }
 
538
  if (table_message.type() == message::Table::TEMPORARY &&
 
539
      share.storage_engine->check_flag(HTON_BIT_TEMPORARY_NOT_SUPPORTED) == true)
 
540
  {
 
541
    error= HA_ERR_UNSUPPORTED;
 
542
    goto err2;
 
543
  }
 
544
  else if (table_message.type() != message::Table::TEMPORARY &&
 
545
           share.storage_engine->check_flag(HTON_BIT_TEMPORARY_ONLY) == true)
 
546
  {
 
547
    error= HA_ERR_UNSUPPORTED;
 
548
    goto err2;
559
549
  }
560
550
 
561
551
  {
564
554
 
565
555
    table_name_arg= share.storage_engine->checkLowercaseNames(identifier.getPath(), name_buff);
566
556
 
 
557
    if (not share.storage_engine->check_flag(HTON_BIT_HAS_DATA_DICTIONARY))
 
558
    {
 
559
      int protoerr= StorageEngine::writeDefinitionFromPath(identifier, table_message);
 
560
 
 
561
      if (protoerr)
 
562
      {
 
563
        error= protoerr;
 
564
        goto err2;
 
565
      }
 
566
    }
 
567
 
567
568
    share.storage_engine->setTransactionReadWrite(session);
568
569
 
569
570
    error= share.storage_engine->doCreateTable(&session,
570
571
                                               table_name_arg,
571
572
                                               table,
572
 
                                               table_proto);
 
573
                                               table_message);
573
574
  }
574
575
 
575
576
err2:
 
577
  if (error)
 
578
  {
 
579
    if (not share.storage_engine->check_flag(HTON_BIT_HAS_DATA_DICTIONARY))
 
580
      plugin::StorageEngine::deleteDefinitionFromPath(identifier);
 
581
 
 
582
    my_error(ER_CANT_CREATE_TABLE, MYF(ME_BELL+ME_WAITTANG), identifier.getSQLPath().c_str(), error);
 
583
  }
 
584
 
576
585
  table.closefrm(false);
577
586
 
578
 
  if (error)
579
 
  {
580
 
    char name_buff[FN_REFLEN];
581
 
    sprintf(name_buff,"%s.%s", identifier.getDBName(), identifier.getTableName());
582
 
    my_error(ER_CANT_CREATE_TABLE, MYF(ME_BELL+ME_WAITTANG), name_buff, error);
583
 
  }
584
587
err:
585
588
  share.free_table_share();
586
589
  return(error != 0);
642
645
  // Add hook here for engines to register schema.
643
646
  for_each(vector_of_schema_engines.begin(), vector_of_schema_engines.end(),
644
647
           AddSchemaNames(set_of_names));
 
648
 
 
649
  plugin::Authorization::pruneSchemaNames(current_session->getSecurityContext(),
 
650
                                          set_of_names);
645
651
}
646
652
 
647
653
class StorageEngineGetSchemaDefinition: public unary_function<StorageEngine *, bool>
1230
1236
  return internal::my_rename(src_path.c_str(), dest_path.c_str(), MYF(MY_WME));
1231
1237
}
1232
1238
 
1233
 
int StorageEngine::writeDefinitionFromPath(TableIdentifier &identifier, message::Table &table_proto)
 
1239
int StorageEngine::writeDefinitionFromPath(TableIdentifier &identifier, message::Table &table_message)
1234
1240
{
1235
1241
  string file_name(identifier.getPath());
1236
1242
 
1244
1250
  google::protobuf::io::ZeroCopyOutputStream* output=
1245
1251
    new google::protobuf::io::FileOutputStream(fd);
1246
1252
 
1247
 
  if (table_proto.SerializeToZeroCopyStream(output) == false)
 
1253
  if (table_message.SerializeToZeroCopyStream(output) == false)
1248
1254
  {
1249
1255
    delete output;
1250
1256
    close(fd);
1256
1262
  return 0;
1257
1263
}
1258
1264
 
 
1265
class CanCreateTable: public unary_function<StorageEngine *, bool>
 
1266
{
 
1267
  const TableIdentifier &identifier;
 
1268
 
 
1269
public:
 
1270
  CanCreateTable(const TableIdentifier &identifier_arg) :
 
1271
    identifier(identifier_arg)
 
1272
  { }
 
1273
 
 
1274
  result_type operator() (argument_type engine)
 
1275
  {
 
1276
    return not engine->doCanCreateTable(identifier);
 
1277
  }
 
1278
};
 
1279
 
 
1280
 
 
1281
/**
 
1282
  @note on success table can be created.
 
1283
*/
 
1284
bool StorageEngine::canCreateTable(drizzled::TableIdentifier &identifier)
 
1285
{
 
1286
  EngineVector::iterator iter=
 
1287
    find_if(vector_of_engines.begin(), vector_of_engines.end(),
 
1288
            CanCreateTable(identifier));
 
1289
 
 
1290
  if (iter == vector_of_engines.end())
 
1291
  {
 
1292
    return true;
 
1293
  }
 
1294
 
 
1295
  return false;
 
1296
}
 
1297
 
1259
1298
} /* namespace plugin */
1260
1299
} /* namespace drizzled */