OmniSciDB  dfae7c3b14
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
 
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)
 

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() [1/4]

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

Definition at line 115 of file DBObject.cpp.

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

116  : objectName_(name) {
117  objectType_ = objectAndPermissionType;
118  objectKey_.permissionType = objectAndPermissionType;
119  ownerId_ = 0;
120 }
int32_t ownerId_
Definition: DBObject.h:235
name
Definition: setup.py:35
DBObjectKey objectKey_
Definition: DBObject.h:233
std::string objectName_
Definition: DBObject.h:231
int32_t permissionType
Definition: DBObject.h:55
DBObjectType objectType_
Definition: DBObject.h:232

◆ DBObject() [2/4]

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

Definition at line 122 of file DBObject.cpp.

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

123  : objectName_("") {
124  objectType_ = objectAndPermissionType;
125  objectKey_.permissionType = objectAndPermissionType;
126  objectKey_.objectId = id;
127  ownerId_ = 0;
128 }
int32_t objectId
Definition: DBObject.h:57
int32_t ownerId_
Definition: DBObject.h:235
DBObjectKey objectKey_
Definition: DBObject.h:233
std::string objectName_
Definition: DBObject.h:231
int32_t permissionType
Definition: DBObject.h:55
DBObjectType objectType_
Definition: DBObject.h:232

◆ DBObject() [3/4]

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:235
AccessPrivileges objectPrivs_
Definition: DBObject.h:234
DBObjectKey objectKey_
Definition: DBObject.h:233
std::string objectName_
Definition: DBObject.h:231
DBObjectType objectType_
Definition: DBObject.h:232

◆ DBObject() [4/4]

DBObject::DBObject ( const DBObject object)

Definition at line 130 of file DBObject.cpp.

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

131  : objectName_(object.objectName_), ownerId_(object.ownerId_) {
132  objectType_ = object.objectType_;
133  setObjectKey(object.objectKey_);
134  copyPrivileges(object);
135 }
void copyPrivileges(const DBObject &object)
Definition: DBObject.cpp:137
void setObjectKey(const DBObjectKey &objectKey)
Definition: DBObject.h:215
int32_t ownerId_
Definition: DBObject.h:235
DBObjectKey objectKey_
Definition: DBObject.h:233
std::string objectName_
Definition: DBObject.h:231
DBObjectType objectType_
Definition: DBObject.h:232
+ Here is the call graph for this function:

◆ ~DBObject()

DBObject::~DBObject ( )
inline

Definition at line 205 of file DBObject.h.

205 {}

Member Function Documentation

◆ copyPrivileges()

void DBObject::copyPrivileges ( const DBObject object)

Definition at line 137 of file DBObject.cpp.

References objectPrivs_.

Referenced by DBObject().

137  {
138  objectPrivs_ = object.objectPrivs_;
139 }
AccessPrivileges objectPrivs_
Definition: DBObject.h:234
+ Here is the caller graph for this function:

◆ getName()

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

Definition at line 209 of file DBObject.h.

Referenced by loadKey(), and serialize_db_object().

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

◆ getObjectKey()

DBObjectKey DBObject::getObjectKey ( ) const
inline

load key not called?

Definition at line 211 of file DBObject.h.

References CHECK.

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

211  {
212  CHECK(-1 != objectKey_.dbId);
213  return objectKey_;
214  }
DBObjectKey objectKey_
Definition: DBObject.h:233
int32_t dbId
Definition: DBObject.h:56
#define CHECK(condition)
Definition: Logger.h:197
+ Here is the caller graph for this function:

◆ getOwner()

int32_t DBObject::getOwner ( ) const
inline

Definition at line 224 of file DBObject.h.

224 { return ownerId_; }
int32_t ownerId_
Definition: DBObject.h:235

◆ getPrivileges()

const AccessPrivileges& DBObject::getPrivileges ( ) const
inline

Definition at line 216 of file DBObject.h.

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

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

◆ getType()

DBObjectType DBObject::getType ( ) const
inline

Definition at line 210 of file DBObject.h.

Referenced by serialize_db_object().

210 { return objectType_; }
DBObjectType objectType_
Definition: DBObject.h:232
+ Here is the caller graph for this function:

◆ grantPrivileges()

void DBObject::grantPrivileges ( const DBObject object)
inline

Definition at line 221 of file DBObject.h.

221 { updatePrivileges(object); }
void updatePrivileges(const DBObject &object)
Definition: DBObject.cpp:141

◆ loadKey() [1/2]

void DBObject::loadKey ( )

Definition at line 179 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(), Parser::TruncateTableStmt::execute(), Parser::CopyTableStmt::execute(), Parser::ShowCreateTableStmt::execute(), DBHandler::get_db_object_privs(), Catalog_Namespace::SysCatalog::getDatabaseListForUser(), Catalog_Namespace::Catalog::getForeignServersForUser(), Catalog_Namespace::Catalog::getTableNamesForUser(), DBHandler::has_object_privilege(), DBHandler::hasTableAccessPrivileges(), loadKey(), Catalog_Namespace::SysCatalog::revokeDBObjectPrivilegesFromAll_unsafe(), Catalog_Namespace::SysCatalog::switchDatabase(), and DBHandler::user_can_access_table().

179  {
181  if (!getName().empty()) {
183  if (!Catalog_Namespace::SysCatalog::instance().getMetadataForDB(getName(), db)) {
184  throw std::runtime_error("Failure generating DB object key. Database " + getName() +
185  " does not exist.");
186  }
187  objectKey_.dbId = db.dbId;
188  ownerId_ = db.dbOwner;
189  } else {
190  objectKey_.dbId = 0; // very special case only used for initialisation of a role
191  }
192 }
int32_t ownerId_
Definition: DBObject.h:235
DBObjectKey objectKey_
Definition: DBObject.h:233
static SysCatalog & instance()
Definition: SysCatalog.h:286
std::string getName() const
Definition: DBObject.h:209
int32_t dbId
Definition: DBObject.h:56
#define CHECK(condition)
Definition: Logger.h:197
DBObjectType objectType_
Definition: DBObject.h:232
+ 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 194 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.

194  {
195  switch (objectType_) {
196  case DatabaseDBObjectType: {
197  loadKey();
198  break;
199  }
200  case ServerDBObjectType: {
201  objectKey_.dbId = catalog.getCurrentDB().dbId;
202 
203  if (!getName().empty()) {
204  auto server = catalog.getForeignServer(getName());
205  if (!server) {
206  throw std::runtime_error("Failure generating DB object key. Server " +
207  getName() + " does not exist.");
208  }
209  objectKey_.objectId = server->id;
210  ownerId_ = server->user_id;
211  } else {
212  ownerId_ = catalog.getCurrentDB().dbOwner;
213  }
214 
215  break;
216  }
217  case ViewDBObjectType:
218  case TableDBObjectType: {
219  objectKey_.dbId = catalog.getCurrentDB().dbId;
220 
221  if (!getName().empty()) {
222  auto table =
223  catalog.getMetadataForTable(getName(), false /* do not populate fragments */);
224  if (!table) {
225  throw std::runtime_error("Failure generating DB object key. Table/View " +
226  getName() + " does not exist.");
227  }
228  objectKey_.objectId = table->tableId;
229  ownerId_ = table->userId;
230  } else {
231  ownerId_ = catalog.getCurrentDB().dbOwner;
232  }
233 
234  break;
235  }
236  case DashboardDBObjectType: {
237  objectKey_.dbId = catalog.getCurrentDB().dbId;
238 
239  if (objectKey_.objectId > 0) {
240  auto dashboard = catalog.getMetadataForDashboard(objectKey_.objectId);
241  if (!dashboard) {
242  throw std::runtime_error(
243  "Failure generating DB object key. Dashboard with ID " +
244  std::to_string(objectKey_.objectId) + " does not exist.");
245  }
246  objectName_ = dashboard->dashboardName;
247  ownerId_ = dashboard->userId;
248  } else {
249  ownerId_ = catalog.getCurrentDB().dbOwner;
250  }
251 
252  break;
253  }
254  default:
255  CHECK(false);
256  }
257 }
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:57
int32_t ownerId_
Definition: DBObject.h:235
std::string to_string(char const *&&v)
DBObjectKey objectKey_
Definition: DBObject.h:233
std::string getName() const
Definition: DBObject.h:209
std::string objectName_
Definition: DBObject.h:231
const DBMetadata & getCurrentDB() const
Definition: Catalog.h:208
void loadKey()
Definition: DBObject.cpp:179
int32_t dbId
Definition: DBObject.h:56
const foreign_storage::ForeignServer * getForeignServer(const std::string &server_name) const
Definition: Catalog.cpp:2495
#define CHECK(condition)
Definition: Logger.h:197
const DashboardDescriptor * getMetadataForDashboard(const std::string &userId, const std::string &dashName) const
DBObjectType objectType_
Definition: DBObject.h:232
+ Here is the call graph for this function:

◆ resetPrivileges()

void DBObject::resetPrivileges ( )
inline

Definition at line 218 of file DBObject.h.

218 { objectPrivs_.reset(); }
AccessPrivileges objectPrivs_
Definition: DBObject.h:234

◆ revokePrivileges()

void DBObject::revokePrivileges ( const DBObject object)

Definition at line 145 of file DBObject.cpp.

References objectPrivs_, and AccessPrivileges::privileges.

145  {
146  objectPrivs_.privileges &= ~(object.objectPrivs_.privileges);
147 }
AccessPrivileges objectPrivs_
Definition: DBObject.h:234
int64_t privileges
Definition: DBObject.h:134

◆ setName()

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

Definition at line 208 of file DBObject.h.

References setup::name.

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

208 { objectName_ = name; }
name
Definition: setup.py:35
std::string objectName_
Definition: DBObject.h:231
+ Here is the caller graph for this function:

◆ setObjectKey()

void DBObject::setObjectKey ( const DBObjectKey objectKey)
inline

Definition at line 215 of file DBObject.h.

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

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

◆ setObjectType()

void DBObject::setObjectType ( const DBObjectType objectType)

Definition at line 152 of file DBObject.cpp.

References objectType_.

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

152  {
153  objectType_ = objectType;
154 }
DBObjectType objectType_
Definition: DBObject.h:232
+ Here is the caller graph for this function:

◆ setOwner()

void DBObject::setOwner ( int32_t  userId)
inline

Definition at line 225 of file DBObject.h.

References toString().

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

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

◆ setPermissionType()

void DBObject::setPermissionType ( const DBObjectType permissionType)

Definition at line 149 of file DBObject.cpp.

References objectKey_, and DBObjectKey::permissionType.

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

149  {
150  objectKey_.permissionType = permissionType;
151 }
DBObjectKey objectKey_
Definition: DBObject.h:233
int32_t permissionType
Definition: DBObject.h:55
+ Here is the caller graph for this function:

◆ setPrivileges()

◆ toString()

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

Definition at line 156 of file DBObject.cpp.

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

156  {
157  std::vector<std::string> objectKey;
158  switch (objectKey_.permissionType) {
160  objectKey.push_back(std::to_string(objectKey_.permissionType));
161  objectKey.push_back(std::to_string(objectKey_.dbId));
162  objectKey.push_back(std::to_string(-1));
163  break;
164  case TableDBObjectType:
166  case ViewDBObjectType:
167  case ServerDBObjectType:
168  objectKey.push_back(std::to_string(objectKey_.permissionType));
169  objectKey.push_back(std::to_string(objectKey_.dbId));
170  objectKey.push_back(std::to_string(objectKey_.objectId));
171  break;
172  default: {
173  CHECK(false);
174  }
175  }
176  return objectKey;
177 }
int32_t objectId
Definition: DBObject.h:57
std::string to_string(char const *&&v)
DBObjectKey objectKey_
Definition: DBObject.h:233
int32_t dbId
Definition: DBObject.h:56
#define CHECK(condition)
Definition: Logger.h:197
int32_t permissionType
Definition: DBObject.h:55
+ Here is the call graph for this function:

◆ updatePrivileges()

void DBObject::updatePrivileges ( const DBObject object)

Definition at line 141 of file DBObject.cpp.

References objectPrivs_, and AccessPrivileges::privileges.

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

141  {
142  objectPrivs_.privileges |= object.objectPrivs_.privileges;
143 }
AccessPrivileges objectPrivs_
Definition: DBObject.h:234
int64_t privileges
Definition: DBObject.h:134
+ Here is the caller graph for this function:

Member Data Documentation

◆ objectKey_

DBObjectKey DBObject::objectKey_
private

Definition at line 233 of file DBObject.h.

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

◆ objectName_

std::string DBObject::objectName_
private

Definition at line 231 of file DBObject.h.

Referenced by loadKey().

◆ objectPrivs_

AccessPrivileges DBObject::objectPrivs_
private

Definition at line 234 of file DBObject.h.

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

◆ objectType_

DBObjectType DBObject::objectType_
private

Definition at line 232 of file DBObject.h.

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

◆ ownerId_

int32_t DBObject::ownerId_
private

Definition at line 235 of file DBObject.h.

Referenced by DBObject(), and loadKey().


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