OmniSciDB  ba1bac9284
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DropForeignTableCommand Class Reference

#include <DdlCommandExecutor.h>

+ Inheritance diagram for DropForeignTableCommand:
+ Collaboration diagram for DropForeignTableCommand:

Public Member Functions

 DropForeignTableCommand (const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
 
ExecutionResult execute () override
 
- Public Member Functions inherited from DdlCommand
 DdlCommand (const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
 

Additional Inherited Members

- Protected Member Functions inherited from DdlCommand
bool isDefaultServer (const std::string &server_name)
 
- Protected Attributes inherited from DdlCommand
const DdlCommandDataddl_data_
 
std::shared_ptr
< Catalog_Namespace::SessionInfo
const
session_ptr_
 

Detailed Description

Definition at line 106 of file DdlCommandExecutor.h.

Constructor & Destructor Documentation

DropForeignTableCommand::DropForeignTableCommand ( const DdlCommandData ddl_data,
std::shared_ptr< Catalog_Namespace::SessionInfo const session_ptr 
)

Definition at line 988 of file DdlCommandExecutor.cpp.

References CHECK, DdlCommand::ddl_data_, and anonymous_namespace{DdlCommandExecutor.cpp}::extractPayload().

991  : DdlCommand(ddl_data, session_ptr) {
992  auto& ddl_payload = extractPayload(ddl_data_);
993  CHECK(ddl_payload.HasMember("tableName"));
994  CHECK(ddl_payload["tableName"].IsString());
995  CHECK(ddl_payload.HasMember("ifExists"));
996  CHECK(ddl_payload["ifExists"].IsBool());
997 }
const DdlCommandData & ddl_data_
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
DdlCommand(const DdlCommandData &ddl_data, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
#define CHECK(condition)
Definition: Logger.h:206

+ Here is the call graph for this function:

Member Function Documentation

ExecutionResult DropForeignTableCommand::execute ( )
overridevirtual

Executes the DDL command corresponding to provided JSON payload.

Parameters
_returnresult of DDL command execution (if applicable)

Implements DdlCommand.

Definition at line 999 of file DdlCommandExecutor.cpp.

References CHECK, DdlCommand::ddl_data_, AccessPrivileges::DROP_TABLE, anonymous_namespace{DdlCommandExecutor.cpp}::extractPayload(), ddl_utils::FOREIGN_TABLE, lockmgr::TableLockMgrImpl< TableDataLockMgr >::getWriteLockForTable(), DdlCommand::session_ptr_, TableDBObjectType, and ddl_utils::validate_table_type().

Referenced by omnisci.cursor.Cursor::executemany().

999  {
1000  auto& catalog = session_ptr_->getCatalog();
1001  auto& ddl_payload = extractPayload(ddl_data_);
1002 
1003  const std::string& table_name = ddl_payload["tableName"].GetString();
1004  const TableDescriptor* td{nullptr};
1005  std::unique_ptr<lockmgr::TableSchemaLockContainer<lockmgr::WriteLock>> td_with_lock;
1006 
1007  try {
1008  td_with_lock =
1009  std::make_unique<lockmgr::TableSchemaLockContainer<lockmgr::WriteLock>>(
1011  catalog, table_name, false));
1012  CHECK(td_with_lock);
1013  td = (*td_with_lock)();
1014  } catch (const std::runtime_error& e) {
1015  // TODO(Misiu): This should not just swallow any exception, it should only catch
1016  // exceptions that stem from the table not existing.
1017  if (ddl_payload["ifExists"].GetBool()) {
1018  return ExecutionResult();
1019  } else {
1020  throw e;
1021  }
1022  }
1023 
1024  CHECK(td);
1025 
1026  if (!session_ptr_->checkDBAccessPrivileges(
1028  throw std::runtime_error(
1029  "Foreign table \"" + table_name +
1030  "\" will not be dropped. User has no DROP TABLE privileges.");
1031  }
1032 
1034  auto table_data_write_lock =
1036  catalog.dropTable(td);
1037 
1038  return ExecutionResult();
1039 }
static WriteLock getWriteLockForTable(const Catalog_Namespace::Catalog &cat, const std::string &table_name)
Definition: LockMgrImpl.h:155
const DdlCommandData & ddl_data_
static const AccessPrivileges DROP_TABLE
Definition: DBObject.h:161
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
void validate_table_type(const TableDescriptor *td, const TableType expected_table_type, const std::string &command)
Definition: DdlUtils.cpp:554
#define CHECK(condition)
Definition: Logger.h:206
std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr_

+ Here is the call graph for this function:

+ Here is the caller graph for this function:


The documentation for this class was generated from the following files: