OmniSciDB  95562058bd
 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 rapidjson::Value &ddl_payload, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
 
void execute (TQueryResult &_return) override
 
- Public Member Functions inherited from DdlCommand
 DdlCommand (const rapidjson::Value &ddl_payload, 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 rapidjson::Value & ddl_payload_
 
std::shared_ptr
< Catalog_Namespace::SessionInfo
const > 
session_ptr_
 

Detailed Description

Definition at line 51 of file DdlCommandExecutor.h.

Constructor & Destructor Documentation

CreateForeignServerCommand::CreateForeignServerCommand ( const rapidjson::Value &  ddl_payload,
std::shared_ptr< Catalog_Namespace::SessionInfo const >  session_ptr 
)

Definition at line 144 of file DdlCommandExecutor.cpp.

References CHECK.

147  : DdlCommand(ddl_payload, session_ptr) {
148  CHECK(ddl_payload.HasMember("serverName"));
149  CHECK(ddl_payload["serverName"].IsString());
150  CHECK(ddl_payload.HasMember("dataWrapper"));
151  CHECK(ddl_payload["dataWrapper"].IsString());
152  CHECK(ddl_payload.HasMember("options"));
153  CHECK(ddl_payload["options"].IsObject());
154  CHECK(ddl_payload.HasMember("ifNotExists"));
155  CHECK(ddl_payload["ifNotExists"].IsBool());
156 }
DdlCommand(const rapidjson::Value &ddl_payload, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
#define CHECK(condition)
Definition: Logger.h:197

Member Function Documentation

void CreateForeignServerCommand::execute ( TQueryResult &  _return)
overridevirtual

Executes the DDL command corresponding to provided JSON payload.

Parameters
_returnresult of DDL command execution (if applicable)

Implements DdlCommand.

Definition at line 158 of file DdlCommandExecutor.cpp.

References AccessPrivileges::CREATE_SERVER, Catalog_Namespace::SysCatalog::createDBObject(), DdlCommand::ddl_payload_, Catalog_Namespace::SysCatalog::instance(), DdlCommand::isDefaultServer(), ServerDBObjectType, DdlCommand::session_ptr_, and to_upper().

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

158  {
159  std::string server_name = ddl_payload_["serverName"].GetString();
160  if (isDefaultServer(server_name)) {
161  throw std::runtime_error{"Server names cannot start with \"omnisci\"."};
162  }
163  bool if_not_exists = ddl_payload_["ifNotExists"].GetBool();
164  if (session_ptr_->getCatalog().getForeignServer(server_name)) {
165  if (if_not_exists) {
166  return;
167  } else {
168  throw std::runtime_error{"A foreign server with name \"" + server_name +
169  "\" already exists."};
170  }
171  }
172  // check access privileges
173  if (!session_ptr_->checkDBAccessPrivileges(DBObjectType::ServerDBObjectType,
175  throw std::runtime_error("Server " + std::string(server_name) +
176  " will not be created. User has no create privileges.");
177  }
178 
179  auto& current_user = session_ptr_->get_currentUser();
180  auto foreign_server = std::make_unique<foreign_storage::ForeignServer>();
181  foreign_server->data_wrapper_type = to_upper(ddl_payload_["dataWrapper"].GetString());
182  foreign_server->name = server_name;
183  foreign_server->user_id = current_user.userId;
184  foreign_server->populateOptionsMap(ddl_payload_["options"]);
185  foreign_server->validate();
186 
187  auto& catalog = session_ptr_->getCatalog();
188  catalog.createForeignServer(std::move(foreign_server),
189  ddl_payload_["ifNotExists"].GetBool());
191  current_user, server_name, ServerDBObjectType, catalog);
192 }
void createDBObject(const UserMetadata &user, const std::string &objectName, DBObjectType type, const Catalog_Namespace::Catalog &catalog, int32_t objectId=-1)
static SysCatalog & instance()
Definition: SysCatalog.h:286
static const AccessPrivileges CREATE_SERVER
Definition: DBObject.h:189
std::string to_upper(const std::string &str)
bool isDefaultServer(const std::string &server_name)
const rapidjson::Value & ddl_payload_
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: