OmniSciDB  04ee39c94c
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 ()
 
void setObjectType (const DBObjectType &objectType)
 
void setName (std::string name)
 
std::string getName () 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)
 

Private Attributes

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

Detailed Description

Definition at line 180 of file DBObject.h.

Constructor & Destructor Documentation

◆ DBObject() [1/4]

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

Definition at line 102 of file DBObject.cpp.

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

103  : objectName_(name) {
104  objectType_ = objectAndPermissionType;
105  objectKey_.permissionType = objectAndPermissionType;
106  ownerId_ = 0;
107 }
int32_t ownerId_
Definition: DBObject.h:220
DBObjectKey objectKey_
Definition: DBObject.h:218
std::string objectName_
Definition: DBObject.h:216
int32_t permissionType
Definition: DBObject.h:54
DBObjectType objectType_
Definition: DBObject.h:217

◆ DBObject() [2/4]

DBObject::DBObject ( const int32_t  id,
const DBObjectType objectAndPermissionType 
)

Definition at line 109 of file DBObject.cpp.

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

110  : objectName_("") {
111  objectType_ = objectAndPermissionType;
112  objectKey_.permissionType = objectAndPermissionType;
113  objectKey_.objectId = id;
114  ownerId_ = 0;
115 }
int32_t objectId
Definition: DBObject.h:56
int32_t ownerId_
Definition: DBObject.h:220
DBObjectKey objectKey_
Definition: DBObject.h:218
std::string objectName_
Definition: DBObject.h:216
int32_t permissionType
Definition: DBObject.h:54
DBObjectType objectType_
Definition: DBObject.h:217

◆ DBObject() [3/4]

DBObject::DBObject ( DBObjectKey  key,
AccessPrivileges  privs,
int32_t  owner 
)
inline

Definition at line 184 of file DBObject.h.

185  : objectName_("")
187  , objectKey_(key)
188  , objectPrivs_(privs)
189  , ownerId_(owner){};
int32_t ownerId_
Definition: DBObject.h:220
AccessPrivileges objectPrivs_
Definition: DBObject.h:219
DBObjectKey objectKey_
Definition: DBObject.h:218
std::string objectName_
Definition: DBObject.h:216
DBObjectType objectType_
Definition: DBObject.h:217

◆ DBObject() [4/4]

DBObject::DBObject ( const DBObject object)

Definition at line 117 of file DBObject.cpp.

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

118  : objectName_(object.objectName_), ownerId_(object.ownerId_) {
119  objectType_ = object.objectType_;
120  setObjectKey(object.objectKey_);
121  copyPrivileges(object);
122 }
void copyPrivileges(const DBObject &object)
Definition: DBObject.cpp:124
void setObjectKey(const DBObjectKey &objectKey)
Definition: DBObject.h:200
int32_t ownerId_
Definition: DBObject.h:220
DBObjectKey objectKey_
Definition: DBObject.h:218
std::string objectName_
Definition: DBObject.h:216
DBObjectType objectType_
Definition: DBObject.h:217
+ Here is the call graph for this function:

◆ ~DBObject()

DBObject::~DBObject ( )
inline

Definition at line 191 of file DBObject.h.

191 {}

Member Function Documentation

◆ copyPrivileges()

void DBObject::copyPrivileges ( const DBObject object)

Definition at line 124 of file DBObject.cpp.

References objectPrivs_.

Referenced by DBObject().

124  {
125  objectPrivs_ = object.objectPrivs_;
126 }
AccessPrivileges objectPrivs_
Definition: DBObject.h:219
+ Here is the caller graph for this function:

◆ getName()

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

Definition at line 195 of file DBObject.h.

Referenced by loadKey(), and serialize_db_object().

195 { return objectName_; }
std::string objectName_
Definition: DBObject.h:216
+ Here is the caller graph for this function:

◆ getObjectKey()

DBObjectKey DBObject::getObjectKey ( ) const
inline

load key not called?

Definition at line 196 of file DBObject.h.

References CHECK.

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

196  {
197  CHECK(-1 != objectKey_.dbId);
198  return objectKey_;
199  }
DBObjectKey objectKey_
Definition: DBObject.h:218
int32_t dbId
Definition: DBObject.h:55
#define CHECK(condition)
Definition: Logger.h:187
+ Here is the caller graph for this function:

◆ getOwner()

int32_t DBObject::getOwner ( ) const
inline

Definition at line 209 of file DBObject.h.

209 { return ownerId_; }
int32_t ownerId_
Definition: DBObject.h:220

◆ getPrivileges()

const AccessPrivileges& DBObject::getPrivileges ( ) const
inline

Definition at line 201 of file DBObject.h.

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

201 { return objectPrivs_; }
AccessPrivileges objectPrivs_
Definition: DBObject.h:219
+ Here is the caller graph for this function:

◆ grantPrivileges()

void DBObject::grantPrivileges ( const DBObject object)
inline

Definition at line 206 of file DBObject.h.

206 { updatePrivileges(object); }
void updatePrivileges(const DBObject &object)
Definition: DBObject.cpp:128

◆ loadKey() [1/2]

void DBObject::loadKey ( )

Definition at line 165 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(), MapDHandler::check_table_load_privileges(), Executor::execute(), Parser::TruncateTableStmt::execute(), Parser::CopyTableStmt::execute(), MapDHandler::get_db_object_privs(), Catalog_Namespace::SysCatalog::getDatabaseListForUser(), MapDHandler::has_object_privilege(), MapDHandler::hasTableAccessPrivileges(), loadKey(), Catalog_Namespace::SysCatalog::revokeDBObjectPrivilegesFromAll_unsafe(), Catalog_Namespace::SysCatalog::switchDatabase(), TEST(), TEST_F(), testViewPermissions(), and MapDHandler::user_can_access_table().

165  {
167  if (!getName().empty()) {
169  if (!Catalog_Namespace::SysCatalog::instance().getMetadataForDB(getName(), db)) {
170  throw std::runtime_error("Failure generating DB object key. Database " + getName() +
171  " does not exist.");
172  }
173  objectKey_.dbId = db.dbId;
174  ownerId_ = db.dbOwner;
175  } else {
176  objectKey_.dbId = 0; // very special case only used for initialisation of a role
177  }
178 }
int32_t ownerId_
Definition: DBObject.h:220
DBObjectKey objectKey_
Definition: DBObject.h:218
static SysCatalog & instance()
Definition: SysCatalog.h:240
std::string getName() const
Definition: DBObject.h:195
int32_t dbId
Definition: DBObject.h:55
#define CHECK(condition)
Definition: Logger.h:187
DBObjectType objectType_
Definition: DBObject.h:217
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadKey() [2/2]

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

Definition at line 180 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::getMetadataForDashboard(), Catalog_Namespace::Catalog::getMetadataForTable(), getName(), loadKey(), DBObjectKey::objectId, objectKey_, objectName_, objectType_, ownerId_, TableDBObjectType, to_string(), and ViewDBObjectType.

180  {
181  switch (objectType_) {
182  case DatabaseDBObjectType: {
183  loadKey();
184  break;
185  }
186  case ViewDBObjectType:
187  case TableDBObjectType: {
188  objectKey_.dbId = catalog.getCurrentDB().dbId;
189 
190  if (!getName().empty()) {
191  auto table =
192  catalog.getMetadataForTable(getName(), false /* do not populate fragments */);
193  if (!table) {
194  throw std::runtime_error("Failure generating DB object key. Table/View " +
195  getName() + " does not exist.");
196  }
197  objectKey_.objectId = table->tableId;
198  ownerId_ = table->userId;
199  } else {
200  ownerId_ = catalog.getCurrentDB().dbOwner;
201  }
202 
203  break;
204  }
205  case DashboardDBObjectType: {
206  objectKey_.dbId = catalog.getCurrentDB().dbId;
207 
208  if (objectKey_.objectId > 0) {
209  auto dashboard = catalog.getMetadataForDashboard(objectKey_.objectId);
210  if (!dashboard) {
211  throw std::runtime_error(
212  "Failure generating DB object key. Dashboard with ID " +
213  std::to_string(objectKey_.objectId) + " does not exist.");
214  }
215  objectName_ = dashboard->dashboardName;
216  ownerId_ = dashboard->userId;
217  } else {
218  ownerId_ = catalog.getCurrentDB().dbOwner;
219  }
220 
221  break;
222  }
223  default:
224  CHECK(false);
225  }
226 }
const TableDescriptor * getMetadataForTable(const std::string &tableName, const bool populateFragmenter=true) const
Returns a pointer to a const TableDescriptor struct matching the provided tableName.
int32_t objectId
Definition: DBObject.h:56
int32_t ownerId_
Definition: DBObject.h:220
std::string to_string(char const *&&v)
DBObjectKey objectKey_
Definition: DBObject.h:218
std::string getName() const
Definition: DBObject.h:195
std::string objectName_
Definition: DBObject.h:216
const DBMetadata & getCurrentDB() const
Definition: Catalog.h:176
void loadKey()
Definition: DBObject.cpp:165
int32_t dbId
Definition: DBObject.h:55
#define CHECK(condition)
Definition: Logger.h:187
const DashboardDescriptor * getMetadataForDashboard(const std::string &userId, const std::string &dashName) const
DBObjectType objectType_
Definition: DBObject.h:217
+ Here is the call graph for this function:

◆ resetPrivileges()

void DBObject::resetPrivileges ( )
inline

Definition at line 203 of file DBObject.h.

Referenced by TEST_F().

203 { objectPrivs_.reset(); }
AccessPrivileges objectPrivs_
Definition: DBObject.h:219
+ Here is the caller graph for this function:

◆ revokePrivileges()

void DBObject::revokePrivileges ( const DBObject object)

Definition at line 132 of file DBObject.cpp.

References objectPrivs_, and AccessPrivileges::privileges.

132  {
133  objectPrivs_.privileges &= ~(object.objectPrivs_.privileges);
134 }
AccessPrivileges objectPrivs_
Definition: DBObject.h:219
int64_t privileges
Definition: DBObject.h:126

◆ setName()

void DBObject::setName ( std::string  name)
inline

Definition at line 194 of file DBObject.h.

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

194 { objectName_ = name; }
std::string objectName_
Definition: DBObject.h:216
+ Here is the caller graph for this function:

◆ setObjectKey()

void DBObject::setObjectKey ( const DBObjectKey objectKey)
inline

Definition at line 200 of file DBObject.h.

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

200 { objectKey_ = objectKey; }
DBObjectKey objectKey_
Definition: DBObject.h:218
+ Here is the caller graph for this function:

◆ setObjectType()

void DBObject::setObjectType ( const DBObjectType objectType)

Definition at line 139 of file DBObject.cpp.

References objectType_.

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

139  {
140  objectType_ = objectType;
141 }
DBObjectType objectType_
Definition: DBObject.h:217
+ Here is the caller graph for this function:

◆ setOwner()

void DBObject::setOwner ( int32_t  userId)
inline

Definition at line 210 of file DBObject.h.

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

210 { ownerId_ = userId; }
int32_t ownerId_
Definition: DBObject.h:220
+ Here is the caller graph for this function:

◆ setPermissionType()

void DBObject::setPermissionType ( const DBObjectType permissionType)

Definition at line 136 of file DBObject.cpp.

References objectKey_, and DBObjectKey::permissionType.

Referenced by Catalog_Namespace::SysCatalog::grantAllOnDatabase_unsafe(), and TEST_F().

136  {
137  objectKey_.permissionType = permissionType;
138 }
DBObjectKey objectKey_
Definition: DBObject.h:218
int32_t permissionType
Definition: DBObject.h:54
+ Here is the caller graph for this function:

◆ setPrivileges()

◆ toString()

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

Definition at line 143 of file DBObject.cpp.

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

143  {
144  std::vector<std::string> objectKey;
145  switch (objectKey_.permissionType) {
147  objectKey.push_back(std::to_string(objectKey_.permissionType));
148  objectKey.push_back(std::to_string(objectKey_.dbId));
149  objectKey.push_back(std::to_string(-1));
150  break;
151  case TableDBObjectType:
153  case ViewDBObjectType:
154  objectKey.push_back(std::to_string(objectKey_.permissionType));
155  objectKey.push_back(std::to_string(objectKey_.dbId));
156  objectKey.push_back(std::to_string(objectKey_.objectId));
157  break;
158  default: {
159  CHECK(false);
160  }
161  }
162  return objectKey;
163 }
int32_t objectId
Definition: DBObject.h:56
std::string to_string(char const *&&v)
DBObjectKey objectKey_
Definition: DBObject.h:218
int32_t dbId
Definition: DBObject.h:55
#define CHECK(condition)
Definition: Logger.h:187
int32_t permissionType
Definition: DBObject.h:54
+ Here is the call graph for this function:

◆ updatePrivileges()

void DBObject::updatePrivileges ( const DBObject object)

Definition at line 128 of file DBObject.cpp.

References objectPrivs_, and AccessPrivileges::privileges.

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

128  {
129  objectPrivs_.privileges |= object.objectPrivs_.privileges;
130 }
AccessPrivileges objectPrivs_
Definition: DBObject.h:219
int64_t privileges
Definition: DBObject.h:126
+ Here is the caller graph for this function:

Member Data Documentation

◆ objectKey_

DBObjectKey DBObject::objectKey_
private

Definition at line 218 of file DBObject.h.

Referenced by DBObject(), loadKey(), setPermissionType(), and toString().

◆ objectName_

std::string DBObject::objectName_
private

Definition at line 216 of file DBObject.h.

Referenced by loadKey().

◆ objectPrivs_

AccessPrivileges DBObject::objectPrivs_
private

Definition at line 219 of file DBObject.h.

Referenced by copyPrivileges(), revokePrivileges(), and updatePrivileges().

◆ objectType_

DBObjectType DBObject::objectType_
private

Definition at line 217 of file DBObject.h.

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

◆ ownerId_

int32_t DBObject::ownerId_
private

Definition at line 220 of file DBObject.h.

Referenced by DBObject(), and loadKey().


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