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

#include <DBObject.h>

+ Collaboration diagram for DBObject:

Public Member Functions

 DBObject (const std::string &name, const DBObjectType &objectAndPermissionType)
 
 DBObject (const int32_t id, const DBObjectType &objectAndPermissionType)
 
 DBObject (DBObjectKey key, AccessPrivileges privs, int32_t owner)
 
 DBObject (const DBObject &object)
 
 DBObject (const std::string &name, DBObjectType type, DBObjectKey key, AccessPrivileges privs, int32_t owner)
 
 ~DBObject ()
 
void setObjectType (const DBObjectType &objectType)
 
void setName (std::string name)
 
std::string getName () const
 
DBObjectType getType () const
 
DBObjectKey getObjectKey () const
 
void setObjectKey (const DBObjectKey &objectKey)
 
const AccessPrivilegesgetPrivileges () const
 
void setPrivileges (const AccessPrivileges &privs)
 
void resetPrivileges ()
 
void copyPrivileges (const DBObject &object)
 
void updatePrivileges (const DBObject &object)
 
void grantPrivileges (const DBObject &object)
 
void revokePrivileges (const DBObject &object)
 
void setPermissionType (const DBObjectType &permissionType)
 
int32_t getOwner () const
 
void setOwner (int32_t userId)
 
std::vector< std::string > toString () const
 
void loadKey ()
 
void loadKey (const Catalog_Namespace::Catalog &catalog)
 
bool valid () const
 

Private Attributes

std::string objectName_
 
DBObjectType objectType_
 
DBObjectKey objectKey_
 
AccessPrivileges objectPrivs_
 
int32_t ownerId_
 

Detailed Description

Definition at line 194 of file DBObject.h.

Constructor & Destructor Documentation

DBObject::DBObject ( const std::string &  name,
const DBObjectType objectAndPermissionType 
)

Definition at line 126 of file DBObject.cpp.

References objectKey_, objectType_, ownerId_, and DBObjectKey::permissionType.

127  : objectName_(name) {
128  objectType_ = objectAndPermissionType;
129  objectKey_.permissionType = objectAndPermissionType;
130  ownerId_ = 0;
131 }
int32_t ownerId_
Definition: DBObject.h:250
DBObjectKey objectKey_
Definition: DBObject.h:248
std::string objectName_
Definition: DBObject.h:246
int32_t permissionType
Definition: DBObject.h:53
string name
Definition: setup.in.py:72
DBObjectType objectType_
Definition: DBObject.h:247
DBObject::DBObject ( const int32_t  id,
const DBObjectType objectAndPermissionType 
)

Definition at line 133 of file DBObject.cpp.

References DBObjectKey::objectId, objectKey_, objectType_, ownerId_, and DBObjectKey::permissionType.

134  : objectName_("") {
135  objectType_ = objectAndPermissionType;
136  objectKey_.permissionType = objectAndPermissionType;
137  objectKey_.objectId = id;
138  ownerId_ = 0;
139 }
int32_t objectId
Definition: DBObject.h:55
int32_t ownerId_
Definition: DBObject.h:250
DBObjectKey objectKey_
Definition: DBObject.h:248
std::string objectName_
Definition: DBObject.h:246
int32_t permissionType
Definition: DBObject.h:53
DBObjectType objectType_
Definition: DBObject.h:247
DBObject::DBObject ( DBObjectKey  key,
AccessPrivileges  privs,
int32_t  owner 
)
inline

Definition at line 198 of file DBObject.h.

199  : objectName_("")
201  , objectKey_(key)
202  , objectPrivs_(privs)
203  , ownerId_(owner){};
int32_t ownerId_
Definition: DBObject.h:250
AccessPrivileges objectPrivs_
Definition: DBObject.h:249
DBObjectKey objectKey_
Definition: DBObject.h:248
std::string objectName_
Definition: DBObject.h:246
DBObjectType objectType_
Definition: DBObject.h:247
DBObject::DBObject ( const DBObject object)

Definition at line 141 of file DBObject.cpp.

References copyPrivileges(), objectKey_, objectType_, and setObjectKey().

142  : objectName_(object.objectName_), ownerId_(object.ownerId_) {
143  objectType_ = object.objectType_;
144  setObjectKey(object.objectKey_);
145  copyPrivileges(object);
146 }
void copyPrivileges(const DBObject &object)
Definition: DBObject.cpp:148
void setObjectKey(const DBObjectKey &objectKey)
Definition: DBObject.h:225
int32_t ownerId_
Definition: DBObject.h:250
DBObjectKey objectKey_
Definition: DBObject.h:248
std::string objectName_
Definition: DBObject.h:246
DBObjectType objectType_
Definition: DBObject.h:247

+ Here is the call graph for this function:

DBObject::DBObject ( const std::string &  name,
DBObjectType  type,
DBObjectKey  key,
AccessPrivileges  privs,
int32_t  owner 
)
inline

Definition at line 205 of file DBObject.h.

210  : objectName_(name)
211  , objectType_(type)
212  , objectKey_(key)
213  , objectPrivs_(privs)
214  , ownerId_(owner){};
int32_t ownerId_
Definition: DBObject.h:250
AccessPrivileges objectPrivs_
Definition: DBObject.h:249
DBObjectKey objectKey_
Definition: DBObject.h:248
std::string objectName_
Definition: DBObject.h:246
string name
Definition: setup.in.py:72
DBObjectType objectType_
Definition: DBObject.h:247
DBObject::~DBObject ( )
inline

Definition at line 215 of file DBObject.h.

215 {}

Member Function Documentation

void DBObject::copyPrivileges ( const DBObject object)

Definition at line 148 of file DBObject.cpp.

References objectPrivs_.

Referenced by DBObject().

148  {
149  objectPrivs_ = object.objectPrivs_;
150 }
AccessPrivileges objectPrivs_
Definition: DBObject.h:249

+ Here is the caller graph for this function:

std::string DBObject::getName ( ) const
inline

Definition at line 219 of file DBObject.h.

References objectName_.

Referenced by loadKey(), and serialize_db_object().

219 { return objectName_; }
std::string objectName_
Definition: DBObject.h:246

+ Here is the caller graph for this function:

DBObjectKey DBObject::getObjectKey ( ) const
inline

load key not called?

Definition at line 221 of file DBObject.h.

References CHECK, DBObjectKey::dbId, and objectKey_.

Referenced by Grantee::checkPrivileges(), DBHandler::get_db_object_privs(), DBHandler::has_object_privilege(), Grantee::hasAnyPrivileges(), Catalog_Namespace::SysCatalog::revokeDBObjectPrivilegesFromAll_unsafe(), and serialize_db_object().

221  {
222  CHECK(-1 != objectKey_.dbId);
223  return objectKey_;
224  }
DBObjectKey objectKey_
Definition: DBObject.h:248
int32_t dbId
Definition: DBObject.h:54
#define CHECK(condition)
Definition: Logger.h:222

+ Here is the caller graph for this function:

int32_t DBObject::getOwner ( ) const
inline

Definition at line 234 of file DBObject.h.

References ownerId_.

234 { return ownerId_; }
int32_t ownerId_
Definition: DBObject.h:250
const AccessPrivileges& DBObject::getPrivileges ( ) const
inline

Definition at line 226 of file DBObject.h.

References objectPrivs_.

Referenced by Parser::ShowPrivilegesStmt::execute(), DBHandler::get_dashboard_impl(), hasAnyPrivs(), hasEnoughPrivs(), and serialize_db_object().

226 { return objectPrivs_; }
AccessPrivileges objectPrivs_
Definition: DBObject.h:249

+ Here is the caller graph for this function:

DBObjectType DBObject::getType ( ) const
inline

Definition at line 220 of file DBObject.h.

References objectType_.

Referenced by serialize_db_object().

220 { return objectType_; }
DBObjectType objectType_
Definition: DBObject.h:247

+ Here is the caller graph for this function:

void DBObject::grantPrivileges ( const DBObject object)
inline

Definition at line 231 of file DBObject.h.

References updatePrivileges().

231 { updatePrivileges(object); }
void updatePrivileges(const DBObject &object)
Definition: DBObject.cpp:152

+ Here is the call graph for this function:

void DBObject::loadKey ( )

Definition at line 190 of file DBObject.cpp.

References CHECK, DatabaseDBObjectType, DBObjectKey::dbId, Catalog_Namespace::DBMetadata::dbId, Catalog_Namespace::DBMetadata::dbOwner, getName(), Catalog_Namespace::SysCatalog::instance(), objectKey_, objectType_, and ownerId_.

Referenced by Parser::check_alter_table_privilege(), DBHandler::check_table_load_privileges(), DBHandler::connect(), ShowCreateServerCommand::execute(), ShowCreateTableCommand::execute(), ShowUserDetailsCommand::execute(), Parser::TruncateTableStmt::execute(), Parser::CopyTableStmt::execute(), Catalog_Namespace::Catalog::filterTableByTypeAndUser(), DBHandler::get_db_object_privs(), Catalog_Namespace::SysCatalog::getDatabaseListForUser(), Catalog_Namespace::Catalog::getForeignServersForUser(), DBHandler::has_object_privilege(), DBHandler::hasTableAccessPrivileges(), DBHandler::internal_connect(), loadKey(), Catalog_Namespace::SysCatalog::revokeDBObjectPrivilegesFromAll_unsafe(), Catalog_Namespace::SysCatalog::switchDatabase(), DBHandler::user_can_access_table(), and Parser::anonymous_namespace{ParserNode.cpp}::user_can_access_table().

190  {
192  if (!getName().empty()) {
194  if (!Catalog_Namespace::SysCatalog::instance().getMetadataForDB(getName(), db)) {
195  throw std::runtime_error("Failure generating DB object key. Database " + getName() +
196  " does not exist.");
197  }
198  objectKey_.dbId = db.dbId;
199  ownerId_ = db.dbOwner;
200  } else {
201  objectKey_.dbId = 0; // very special case only used for initialisation of a role
202  }
203 }
int32_t ownerId_
Definition: DBObject.h:250
DBObjectKey objectKey_
Definition: DBObject.h:248
static SysCatalog & instance()
Definition: SysCatalog.h:341
std::string getName() const
Definition: DBObject.h:219
int32_t dbId
Definition: DBObject.h:54
#define CHECK(condition)
Definition: Logger.h:222
DBObjectType objectType_
Definition: DBObject.h:247

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void DBObject::loadKey ( const Catalog_Namespace::Catalog catalog)

Definition at line 205 of file DBObject.cpp.

References CHECK, DashboardDBObjectType, DatabaseDBObjectType, DBObjectKey::dbId, Catalog_Namespace::DBMetadata::dbId, Catalog_Namespace::DBMetadata::dbOwner, Catalog_Namespace::Catalog::getCurrentDB(), Catalog_Namespace::Catalog::getForeignServer(), Catalog_Namespace::Catalog::getMetadataForDashboard(), Catalog_Namespace::Catalog::getMetadataForTable(), getName(), loadKey(), DBObjectKey::objectId, objectKey_, objectName_, objectType_, ownerId_, ServerDBObjectType, TableDBObjectType, to_string(), and ViewDBObjectType.

205  {
206  switch (objectType_) {
207  case DatabaseDBObjectType: {
208  loadKey();
209  break;
210  }
211  case ServerDBObjectType: {
212  objectKey_.dbId = catalog.getCurrentDB().dbId;
213 
214  if (!getName().empty()) {
215  auto server = catalog.getForeignServer(getName());
216  if (!server) {
217  throw std::runtime_error("Failure generating DB object key. Server " +
218  getName() + " does not exist.");
219  }
220  objectKey_.objectId = server->id;
221  ownerId_ = server->user_id;
222  } else {
223  ownerId_ = catalog.getCurrentDB().dbOwner;
224  }
225 
226  break;
227  }
228  case ViewDBObjectType:
229  case TableDBObjectType: {
230  objectKey_.dbId = catalog.getCurrentDB().dbId;
231 
232  if (!getName().empty()) {
233  auto table =
234  catalog.getMetadataForTable(getName(), false /* do not populate fragments */);
235  if (!table) {
236  throw std::runtime_error("Failure generating DB object key. Table/View " +
237  getName() + " does not exist.");
238  }
239  objectKey_.objectId = table->tableId;
240  ownerId_ = table->userId;
241  } else {
242  ownerId_ = catalog.getCurrentDB().dbOwner;
243  }
244 
245  break;
246  }
247  case DashboardDBObjectType: {
248  objectKey_.dbId = catalog.getCurrentDB().dbId;
249 
250  if (objectKey_.objectId > 0) {
251  auto dashboard = catalog.getMetadataForDashboard(objectKey_.objectId);
252  if (!dashboard) {
253  throw std::runtime_error(
254  "Failure generating DB object key. Dashboard with ID " +
255  std::to_string(objectKey_.objectId) + " does not exist.");
256  }
257  objectName_ = dashboard->dashboardName;
258  ownerId_ = dashboard->userId;
259  } else {
260  ownerId_ = catalog.getCurrentDB().dbOwner;
261  }
262 
263  break;
264  }
265  default:
266  CHECK(false);
267  }
268 }
const foreign_storage::ForeignServer * getForeignServer(const std::string &server_name) const
Definition: Catalog.cpp:3097
int32_t objectId
Definition: DBObject.h:55
int32_t ownerId_
Definition: DBObject.h:250
std::string to_string(char const *&&v)
DBObjectKey objectKey_
Definition: DBObject.h:248
const DBMetadata & getCurrentDB() const
Definition: Catalog.h:242
const DashboardDescriptor * getMetadataForDashboard(const std::string &userId, const std::string &dashName) const
std::string getName() const
Definition: DBObject.h:219
std::string objectName_
Definition: DBObject.h:246
void loadKey()
Definition: DBObject.cpp:190
int32_t dbId
Definition: DBObject.h:54
#define CHECK(condition)
Definition: Logger.h:222
const TableDescriptor * getMetadataForTable(const std::string &tableName, const bool populateFragmenter=true) const
Returns a pointer to a const TableDescriptor struct matching the provided tableName.
DBObjectType objectType_
Definition: DBObject.h:247

+ Here is the call graph for this function:

void DBObject::resetPrivileges ( )
inline

Definition at line 228 of file DBObject.h.

References objectPrivs_, and AccessPrivileges::reset().

228 { objectPrivs_.reset(); }
AccessPrivileges objectPrivs_
Definition: DBObject.h:249

+ Here is the call graph for this function:

void DBObject::revokePrivileges ( const DBObject object)

Definition at line 156 of file DBObject.cpp.

References objectPrivs_, and AccessPrivileges::privileges.

156  {
157  objectPrivs_.privileges &= ~(object.objectPrivs_.privileges);
158 }
AccessPrivileges objectPrivs_
Definition: DBObject.h:249
int64_t privileges
Definition: DBObject.h:133
void DBObject::setName ( std::string  name)
inline

Definition at line 218 of file DBObject.h.

References setup::name, and objectName_.

Referenced by Catalog_Namespace::SysCatalog::migrateDBAccessPrivileges().

218 { objectName_ = name; }
std::string objectName_
Definition: DBObject.h:246
string name
Definition: setup.in.py:72

+ Here is the caller graph for this function:

void DBObject::setObjectKey ( const DBObjectKey objectKey)
inline

Definition at line 225 of file DBObject.h.

References objectKey_.

Referenced by Catalog_Namespace::SysCatalog::createRole_unsafe(), DBObject(), Catalog_Namespace::Catalog::recordOwnershipOfObjectsInObjectPermissions(), and Catalog_Namespace::SysCatalog::renameDBObject().

225 { objectKey_ = objectKey; }
DBObjectKey objectKey_
Definition: DBObject.h:248

+ Here is the caller graph for this function:

void DBObject::setObjectType ( const DBObjectType objectType)

Definition at line 163 of file DBObject.cpp.

References objectType_.

Referenced by Catalog_Namespace::SysCatalog::migrateDBAccessPrivileges().

163  {
164  objectType_ = objectType;
165 }
DBObjectType objectType_
Definition: DBObject.h:247

+ Here is the caller graph for this function:

void DBObject::setOwner ( int32_t  userId)
inline

Definition at line 235 of file DBObject.h.

References ownerId_.

Referenced by Catalog_Namespace::Catalog::recordOwnershipOfObjectsInObjectPermissions().

235 { ownerId_ = userId; }
int32_t ownerId_
Definition: DBObject.h:250

+ Here is the caller graph for this function:

void DBObject::setPermissionType ( const DBObjectType permissionType)

Definition at line 160 of file DBObject.cpp.

References objectKey_, and DBObjectKey::permissionType.

Referenced by Catalog_Namespace::SysCatalog::grantAllOnDatabase_unsafe().

160  {
161  objectKey_.permissionType = permissionType;
162 }
DBObjectKey objectKey_
Definition: DBObject.h:248
int32_t permissionType
Definition: DBObject.h:53

+ Here is the caller graph for this function:

std::vector< std::string > DBObject::toString ( ) const

Definition at line 167 of file DBObject.cpp.

References CHECK, DashboardDBObjectType, DatabaseDBObjectType, DBObjectKey::dbId, DBObjectKey::objectId, objectKey_, DBObjectKey::permissionType, ServerDBObjectType, TableDBObjectType, to_string(), and ViewDBObjectType.

167  {
168  std::vector<std::string> objectKey;
169  switch (objectKey_.permissionType) {
171  objectKey.push_back(std::to_string(objectKey_.permissionType));
172  objectKey.push_back(std::to_string(objectKey_.dbId));
173  objectKey.push_back(std::to_string(-1));
174  break;
175  case TableDBObjectType:
177  case ViewDBObjectType:
178  case ServerDBObjectType:
179  objectKey.push_back(std::to_string(objectKey_.permissionType));
180  objectKey.push_back(std::to_string(objectKey_.dbId));
181  objectKey.push_back(std::to_string(objectKey_.objectId));
182  break;
183  default: {
184  CHECK(false);
185  }
186  }
187  return objectKey;
188 }
int32_t objectId
Definition: DBObject.h:55
std::string to_string(char const *&&v)
DBObjectKey objectKey_
Definition: DBObject.h:248
int32_t dbId
Definition: DBObject.h:54
#define CHECK(condition)
Definition: Logger.h:222
int32_t permissionType
Definition: DBObject.h:53

+ Here is the call graph for this function:

void DBObject::updatePrivileges ( const DBObject object)

Definition at line 152 of file DBObject.cpp.

References objectPrivs_, and AccessPrivileges::privileges.

Referenced by grantPrivileges(), and Catalog_Namespace::SysCatalog::migrateDBAccessPrivileges().

152  {
153  objectPrivs_.privileges |= object.objectPrivs_.privileges;
154 }
AccessPrivileges objectPrivs_
Definition: DBObject.h:249
int64_t privileges
Definition: DBObject.h:133

+ Here is the caller graph for this function:

bool DBObject::valid ( ) const
inline

Definition at line 240 of file DBObject.h.

References AbstractDBObjectType, DBObjectKey::dbId, objectKey_, objectType_, and DBObjectKey::permissionType.

240  {
242  objectKey_.dbId != -1);
243  }
DBObjectKey objectKey_
Definition: DBObject.h:248
int32_t dbId
Definition: DBObject.h:54
int32_t permissionType
Definition: DBObject.h:53
DBObjectType objectType_
Definition: DBObject.h:247

Member Data Documentation

DBObjectKey DBObject::objectKey_
private
std::string DBObject::objectName_
private

Definition at line 246 of file DBObject.h.

Referenced by getName(), loadKey(), and setName().

AccessPrivileges DBObject::objectPrivs_
private
DBObjectType DBObject::objectType_
private

Definition at line 247 of file DBObject.h.

Referenced by DBObject(), getType(), loadKey(), setObjectType(), and valid().

int32_t DBObject::ownerId_
private

Definition at line 250 of file DBObject.h.

Referenced by DBObject(), getOwner(), loadKey(), and setOwner().


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