OmniSciDB  ba1bac9284
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 464 of file DdlCommandExecutor.cpp.

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

467  : DdlCommand(ddl_data, session_ptr) {
468  auto& ddl_payload = extractPayload(ddl_data_);
469  CHECK(ddl_payload.HasMember("serverName"));
470  CHECK(ddl_payload["serverName"].IsString());
471  CHECK(ddl_payload.HasMember("dataWrapper"));
472  CHECK(ddl_payload["dataWrapper"].IsString());
473  if (ddl_payload.HasMember("options")) {
474  CHECK(ddl_payload["options"].IsObject());
475  }
476  CHECK(ddl_payload.HasMember("ifNotExists"));
477  CHECK(ddl_payload["ifNotExists"].IsBool());
478 }
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 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 480 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().

480  {
482 
483  auto& ddl_payload = extractPayload(ddl_data_);
484  std::string server_name = ddl_payload["serverName"].GetString();
485  if (isDefaultServer(server_name)) {
486  throw std::runtime_error{"Server names cannot start with \"omnisci\"."};
487  }
488  bool if_not_exists = ddl_payload["ifNotExists"].GetBool();
489  if (session_ptr_->getCatalog().getForeignServer(server_name)) {
490  if (if_not_exists) {
491  return result;
492  } else {
493  throw std::runtime_error{"A foreign server with name \"" + server_name +
494  "\" already exists."};
495  }
496  }
497  // check access privileges
498  if (!session_ptr_->checkDBAccessPrivileges(DBObjectType::ServerDBObjectType,
500  throw std::runtime_error("Server " + std::string(server_name) +
501  " will not be created. User has no create privileges.");
502  }
503 
504  auto& current_user = session_ptr_->get_currentUser();
505  auto foreign_server = std::make_unique<foreign_storage::ForeignServer>();
506  foreign_server->data_wrapper_type = to_upper(ddl_payload["dataWrapper"].GetString());
507  foreign_server->name = server_name;
508  foreign_server->user_id = current_user.userId;
509  if (ddl_payload.HasMember("options")) {
510  foreign_server->populateOptionsMap(ddl_payload["options"]);
511  }
512  foreign_server->validate();
513 
514  auto& catalog = session_ptr_->getCatalog();
515  catalog.createForeignServer(std::move(foreign_server),
516  ddl_payload["ifNotExists"].GetBool());
518  current_user, server_name, ServerDBObjectType, catalog);
519 
520  return result;
521 }
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:292
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: