OmniSciDB  d2f719934e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CreateForeignServerCommand Class Reference

#include <DdlCommandExecutor.h>

+ Inheritance diagram for CreateForeignServerCommand:
+ Collaboration diagram for CreateForeignServerCommand:

Public Member Functions

 CreateForeignServerCommand (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 57 of file DdlCommandExecutor.h.

Constructor & Destructor Documentation

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

Definition at line 592 of file DdlCommandExecutor.cpp.

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

595  : DdlCommand(ddl_data, session_ptr) {
596  auto& ddl_payload = extractPayload(ddl_data_);
597  CHECK(ddl_payload.HasMember("serverName"));
598  CHECK(ddl_payload["serverName"].IsString());
599  CHECK(ddl_payload.HasMember("dataWrapper"));
600  CHECK(ddl_payload["dataWrapper"].IsString());
601  if (ddl_payload.HasMember("options")) {
602  CHECK(ddl_payload["options"].IsObject());
603  }
604  CHECK(ddl_payload.HasMember("ifNotExists"));
605  CHECK(ddl_payload["ifNotExists"].IsBool());
606 }
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:211

+ Here is the call graph for this function:

Member Function Documentation

ExecutionResult CreateForeignServerCommand::execute ( )
overridevirtual

Executes the DDL command corresponding to provided JSON payload.

Parameters
_returnresult of DDL command execution (if applicable)

Implements DdlCommand.

Definition at line 608 of file DdlCommandExecutor.cpp.

References AccessPrivileges::CREATE_SERVER, Catalog_Namespace::SysCatalog::createDBObject(), DdlCommand::ddl_data_, anonymous_namespace{DdlCommandExecutor.cpp}::extractPayload(), Catalog_Namespace::SysCatalog::instance(), DdlCommand::isDefaultServer(), run_benchmark_import::result, ServerDBObjectType, DdlCommand::session_ptr_, and to_upper().

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

608  {
610 
611  auto& ddl_payload = extractPayload(ddl_data_);
612  std::string server_name = ddl_payload["serverName"].GetString();
613  if (isDefaultServer(server_name)) {
614  throw std::runtime_error{"Server names cannot start with \"omnisci\"."};
615  }
616  bool if_not_exists = ddl_payload["ifNotExists"].GetBool();
617  if (session_ptr_->getCatalog().getForeignServer(server_name)) {
618  if (if_not_exists) {
619  return result;
620  } else {
621  throw std::runtime_error{"A foreign server with name \"" + server_name +
622  "\" already exists."};
623  }
624  }
625  // check access privileges
626  if (!session_ptr_->checkDBAccessPrivileges(DBObjectType::ServerDBObjectType,
628  throw std::runtime_error("Server " + std::string(server_name) +
629  " will not be created. User has no create privileges.");
630  }
631 
632  auto& current_user = session_ptr_->get_currentUser();
633  auto foreign_server = std::make_unique<foreign_storage::ForeignServer>();
634  foreign_server->data_wrapper_type = to_upper(ddl_payload["dataWrapper"].GetString());
635  foreign_server->name = server_name;
636  foreign_server->user_id = current_user.userId;
637  if (ddl_payload.HasMember("options")) {
638  foreign_server->populateOptionsMap(ddl_payload["options"]);
639  }
640  foreign_server->validate();
641 
642  auto& catalog = session_ptr_->getCatalog();
643  catalog.createForeignServer(std::move(foreign_server),
644  ddl_payload["ifNotExists"].GetBool());
646  current_user, server_name, ServerDBObjectType, catalog);
647 
648  return result;
649 }
void createDBObject(const UserMetadata &user, const std::string &objectName, DBObjectType type, const Catalog_Namespace::Catalog &catalog, int32_t objectId=-1)
const DdlCommandData & ddl_data_
static SysCatalog & instance()
Definition: SysCatalog.h:326
const rapidjson::Value & extractPayload(const DdlCommandData &ddl_data)
static const AccessPrivileges CREATE_SERVER
Definition: DBObject.h:190
std::string to_upper(const std::string &str)
bool isDefaultServer(const std::string &server_name)
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: