OmniSciDB  eb3a3d0a03
 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 196 of file DBObject.h.

Constructor & Destructor Documentation

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

Definition at line 117 of file DBObject.cpp.

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

118  : objectName_(name) {
119  objectType_ = objectAndPermissionType;
120  objectKey_.permissionType = objectAndPermissionType;
121  ownerId_ = 0;
122 }
string name
Definition: setup.in.py:72
int32_t ownerId_
Definition: DBObject.h:252
DBObjectKey objectKey_
Definition: DBObject.h:250
std::string objectName_
Definition: DBObject.h:248
int32_t permissionType
Definition: DBObject.h:55
DBObjectType objectType_
Definition: DBObject.h:249
DBObject::DBObject ( const int32_t  id,
const DBObjectType objectAndPermissionType 
)

Definition at line 124 of file DBObject.cpp.

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

125  : objectName_("") {
126  objectType_ = objectAndPermissionType;
127  objectKey_.permissionType = objectAndPermissionType;
128  objectKey_.objectId = id;
129  ownerId_ = 0;
130 }
int32_t objectId
Definition: DBObject.h:57
int32_t ownerId_
Definition: DBObject.h:252
DBObjectKey objectKey_
Definition: DBObject.h:250
std::string objectName_
Definition: DBObject.h:248
int32_t permissionType
Definition: DBObject.h:55
DBObjectType objectType_
Definition: DBObject.h:249
DBObject::DBObject ( DBObjectKey  key,
AccessPrivileges  privs,
int32_t  owner 
)
inline

Definition at line 200 of file DBObject.h.

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

Definition at line 132 of file DBObject.cpp.

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

133  : objectName_(object.objectName_), ownerId_(object.ownerId_) {
134  objectType_ = object.objectType_;
135  setObjectKey(object.objectKey_);
136  copyPrivileges(object);
137 }
void copyPrivileges(const DBObject &object)
Definition: DBObject.cpp:139
void setObjectKey(const DBObjectKey &objectKey)
Definition: DBObject.h:227
int32_t ownerId_
Definition: DBObject.h:252
DBObjectKey objectKey_
Definition: DBObject.h:250
std::string objectName_
Definition: DBObject.h:248
DBObjectType objectType_
Definition: DBObject.h:249

+ 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 207 of file DBObject.h.

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

Definition at line 217 of file DBObject.h.

217 {}

Member Function Documentation

void DBObject::copyPrivileges ( const DBObject object)

Definition at line 139 of file DBObject.cpp.

References objectPrivs_.

Referenced by DBObject().

139  {
140  objectPrivs_ = object.objectPrivs_;
141 }
AccessPrivileges objectPrivs_
Definition: DBObject.h:251

+ Here is the caller graph for this function:

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

Definition at line 221 of file DBObject.h.

References objectName_.

Referenced by loadKey(), and serialize_db_object().

221 { return objectName_; }
std::string objectName_
Definition: DBObject.h:248

+ Here is the caller graph for this function:

DBObjectKey DBObject::getObjectKey ( ) const
inline

load key not called?

Definition at line 223 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().

223  {
224  CHECK(-1 != objectKey_.dbId);
225  return objectKey_;
226  }
DBObjectKey objectKey_
Definition: DBObject.h:250
int32_t dbId
Definition: DBObject.h:56
#define CHECK(condition)
Definition: Logger.h:209

+ Here is the caller graph for this function:

int32_t DBObject::getOwner ( ) const
inline

Definition at line 236 of file DBObject.h.

References ownerId_.

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

Definition at line 228 of file DBObject.h.

References objectPrivs_.

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

228 { return objectPrivs_; }
AccessPrivileges objectPrivs_
Definition: DBObject.h:251

+ Here is the caller graph for this function:

DBObjectType DBObject::getType ( ) const
inline

Definition at line 222 of file DBObject.h.

References objectType_.

Referenced by serialize_db_object().

222 { return objectType_; }
DBObjectType objectType_
Definition: DBObject.h:249

+ Here is the caller graph for this function:

void DBObject::grantPrivileges ( const DBObject object)
inline

Definition at line 233 of file DBObject.h.

References updatePrivileges().

233 { updatePrivileges(object); }
void updatePrivileges(const DBObject &object)
Definition: DBObject.cpp:143

+ Here is the call graph for this function:

void DBObject::loadKey ( )

Definition at line 181 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(), Parser::TruncateTableStmt::execute(), Parser::CopyTableStmt::execute(), Parser::ShowCreateTableStmt::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().

181  {
183  if (!getName().empty()) {
185  if (!Catalog_Namespace::SysCatalog::instance().getMetadataForDB(getName(), db)) {
186  throw std::runtime_error("Failure generating DB object key. Database " + getName() +
187  " does not exist.");
188  }
189  objectKey_.dbId = db.dbId;
190  ownerId_ = db.dbOwner;
191  } else {
192  objectKey_.dbId = 0; // very special case only used for initialisation of a role
193  }
194 }
int32_t ownerId_
Definition: DBObject.h:252
DBObjectKey objectKey_
Definition: DBObject.h:250
static SysCatalog & instance()
Definition: SysCatalog.h:318
std::string getName() const
Definition: DBObject.h:221
int32_t dbId
Definition: DBObject.h:56
#define CHECK(condition)
Definition: Logger.h:209
DBObjectType objectType_
Definition: DBObject.h:249

+ 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 196 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.

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

+ Here is the call graph for this function:

void DBObject::resetPrivileges ( )
inline

Definition at line 230 of file DBObject.h.

References objectPrivs_, and AccessPrivileges::reset().

230 { objectPrivs_.reset(); }
AccessPrivileges objectPrivs_
Definition: DBObject.h:251

+ Here is the call graph for this function:

void DBObject::revokePrivileges ( const DBObject object)

Definition at line 147 of file DBObject.cpp.

References objectPrivs_, and AccessPrivileges::privileges.

147  {
148  objectPrivs_.privileges &= ~(object.objectPrivs_.privileges);
149 }
AccessPrivileges objectPrivs_
Definition: DBObject.h:251
int64_t privileges
Definition: DBObject.h:135
void DBObject::setName ( std::string  name)
inline

Definition at line 220 of file DBObject.h.

References setup::name, and objectName_.

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

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

+ Here is the caller graph for this function:

void DBObject::setObjectKey ( const DBObjectKey objectKey)
inline

Definition at line 227 of file DBObject.h.

References objectKey_.

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

227 { objectKey_ = objectKey; }
DBObjectKey objectKey_
Definition: DBObject.h:250

+ Here is the caller graph for this function:

void DBObject::setObjectType ( const DBObjectType objectType)

Definition at line 154 of file DBObject.cpp.

References objectType_.

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

154  {
155  objectType_ = objectType;
156 }
DBObjectType objectType_
Definition: DBObject.h:249

+ Here is the caller graph for this function:

void DBObject::setOwner ( int32_t  userId)
inline

Definition at line 237 of file DBObject.h.

References ownerId_.

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

237 { ownerId_ = userId; }
int32_t ownerId_
Definition: DBObject.h:252

+ Here is the caller graph for this function:

void DBObject::setPermissionType ( const DBObjectType permissionType)

Definition at line 151 of file DBObject.cpp.

References objectKey_, and DBObjectKey::permissionType.

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

151  {
152  objectKey_.permissionType = permissionType;
153 }
DBObjectKey objectKey_
Definition: DBObject.h:250
int32_t permissionType
Definition: DBObject.h:55

+ Here is the caller graph for this function:

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

Definition at line 158 of file DBObject.cpp.

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

158  {
159  std::vector<std::string> objectKey;
160  switch (objectKey_.permissionType) {
162  objectKey.push_back(std::to_string(objectKey_.permissionType));
163  objectKey.push_back(std::to_string(objectKey_.dbId));
164  objectKey.push_back(std::to_string(-1));
165  break;
166  case TableDBObjectType:
168  case ViewDBObjectType:
169  case ServerDBObjectType:
170  objectKey.push_back(std::to_string(objectKey_.permissionType));
171  objectKey.push_back(std::to_string(objectKey_.dbId));
172  objectKey.push_back(std::to_string(objectKey_.objectId));
173  break;
174  default: {
175  CHECK(false);
176  }
177  }
178  return objectKey;
179 }
int32_t objectId
Definition: DBObject.h:57
std::string to_string(char const *&&v)
DBObjectKey objectKey_
Definition: DBObject.h:250
int32_t dbId
Definition: DBObject.h:56
#define CHECK(condition)
Definition: Logger.h:209
int32_t permissionType
Definition: DBObject.h:55

+ Here is the call graph for this function:

void DBObject::updatePrivileges ( const DBObject object)

Definition at line 143 of file DBObject.cpp.

References objectPrivs_, and AccessPrivileges::privileges.

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

143  {
144  objectPrivs_.privileges |= object.objectPrivs_.privileges;
145 }
AccessPrivileges objectPrivs_
Definition: DBObject.h:251
int64_t privileges
Definition: DBObject.h:135

+ Here is the caller graph for this function:

bool DBObject::valid ( ) const
inline

Definition at line 242 of file DBObject.h.

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

242  {
244  objectKey_.dbId != -1);
245  }
DBObjectKey objectKey_
Definition: DBObject.h:250
int32_t dbId
Definition: DBObject.h:56
int32_t permissionType
Definition: DBObject.h:55
DBObjectType objectType_
Definition: DBObject.h:249

Member Data Documentation

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

Definition at line 248 of file DBObject.h.

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

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

Definition at line 249 of file DBObject.h.

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

int32_t DBObject::ownerId_
private

Definition at line 252 of file DBObject.h.

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


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