OmniSciDB  a5dc49c757
 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:291

+ 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::dbName, Catalog_Namespace::DBMetadata::dbOwner, getName(), Catalog_Namespace::SysCatalog::instance(), objectKey_, objectName_, objectType_, and ownerId_.

Referenced by Parser::check_alter_table_privilege(), anonymous_namespace{Calcite.cpp}::check_db_access(), 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  objectName_ = db.dbName;
201  } else {
202  objectKey_.dbId = 0; // very special case only used for initialisation of a role
203  }
204 }
int32_t ownerId_
Definition: DBObject.h:250
DBObjectKey objectKey_
Definition: DBObject.h:248
static SysCatalog & instance()
Definition: SysCatalog.h:343
std::string getName() const
Definition: DBObject.h:219
std::string objectName_
Definition: DBObject.h:246
int32_t dbId
Definition: DBObject.h:54
#define CHECK(condition)
Definition: Logger.h:291
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 206 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.

206  {
207  switch (objectType_) {
208  case DatabaseDBObjectType: {
209  loadKey();
210  break;
211  }
212  case ServerDBObjectType: {
213  objectKey_.dbId = catalog.getCurrentDB().dbId;
214 
215  if (!getName().empty()) {
216  auto server = catalog.getForeignServer(getName());
217  if (!server) {
218  throw std::runtime_error("Failure generating DB object key. Server " +
219  getName() + " does not exist.");
220  }
221  objectKey_.objectId = server->id;
222  ownerId_ = server->user_id;
223  } else {
224  ownerId_ = catalog.getCurrentDB().dbOwner;
225  }
226 
227  break;
228  }
229  case ViewDBObjectType:
230  case TableDBObjectType: {
231  objectKey_.dbId = catalog.getCurrentDB().dbId;
232 
233  if (!getName().empty()) {
234  auto table =
235  catalog.getMetadataForTable(getName(), false /* do not populate fragments */);
236  if (!table) {
237  throw std::runtime_error("Failure generating DB object key. Table/View " +
238  getName() + " does not exist.");
239  }
240  objectKey_.objectId = table->tableId;
241  ownerId_ = table->userId;
242  } else {
243  ownerId_ = catalog.getCurrentDB().dbOwner;
244  }
245 
246  break;
247  }
248  case DashboardDBObjectType: {
249  objectKey_.dbId = catalog.getCurrentDB().dbId;
250 
251  if (objectKey_.objectId > 0) {
252  auto dashboard = catalog.getMetadataForDashboard(objectKey_.objectId);
253  if (!dashboard) {
254  throw std::runtime_error(
255  "Failure generating DB object key. Dashboard with ID " +
256  std::to_string(objectKey_.objectId) + " does not exist.");
257  }
258  objectName_ = dashboard->dashboardName;
259  ownerId_ = dashboard->userId;
260  } else {
261  ownerId_ = catalog.getCurrentDB().dbOwner;
262  }
263 
264  break;
265  }
266  default:
267  CHECK(false);
268  }
269 }
const foreign_storage::ForeignServer * getForeignServer(const std::string &server_name) const
Definition: Catalog.cpp:3344
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:265
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:291
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:291
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: