OmniSciDB  7bf56492aa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 ()
 
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 192 of file DBObject.h.

Constructor & Destructor Documentation

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

Definition at line 113 of file DBObject.cpp.

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

114  : objectName_(name) {
115  objectType_ = objectAndPermissionType;
116  objectKey_.permissionType = objectAndPermissionType;
117  ownerId_ = 0;
118 }
int32_t ownerId_
Definition: DBObject.h:233
DBObjectKey objectKey_
Definition: DBObject.h:231
std::string objectName_
Definition: DBObject.h:229
int32_t permissionType
Definition: DBObject.h:55
DBObjectType objectType_
Definition: DBObject.h:230
DBObject::DBObject ( const int32_t  id,
const DBObjectType objectAndPermissionType 
)

Definition at line 120 of file DBObject.cpp.

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

121  : objectName_("") {
122  objectType_ = objectAndPermissionType;
123  objectKey_.permissionType = objectAndPermissionType;
124  objectKey_.objectId = id;
125  ownerId_ = 0;
126 }
int32_t objectId
Definition: DBObject.h:57
int32_t ownerId_
Definition: DBObject.h:233
DBObjectKey objectKey_
Definition: DBObject.h:231
std::string objectName_
Definition: DBObject.h:229
int32_t permissionType
Definition: DBObject.h:55
DBObjectType objectType_
Definition: DBObject.h:230
DBObject::DBObject ( DBObjectKey  key,
AccessPrivileges  privs,
int32_t  owner 
)
inline

Definition at line 196 of file DBObject.h.

197  : objectName_("")
199  , objectKey_(key)
200  , objectPrivs_(privs)
201  , ownerId_(owner){};
int32_t ownerId_
Definition: DBObject.h:233
AccessPrivileges objectPrivs_
Definition: DBObject.h:232
DBObjectKey objectKey_
Definition: DBObject.h:231
std::string objectName_
Definition: DBObject.h:229
DBObjectType objectType_
Definition: DBObject.h:230
DBObject::DBObject ( const DBObject object)

Definition at line 128 of file DBObject.cpp.

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

129  : objectName_(object.objectName_), ownerId_(object.ownerId_) {
130  objectType_ = object.objectType_;
131  setObjectKey(object.objectKey_);
132  copyPrivileges(object);
133 }
void copyPrivileges(const DBObject &object)
Definition: DBObject.cpp:135
void setObjectKey(const DBObjectKey &objectKey)
Definition: DBObject.h:213
int32_t ownerId_
Definition: DBObject.h:233
DBObjectKey objectKey_
Definition: DBObject.h:231
std::string objectName_
Definition: DBObject.h:229
DBObjectType objectType_
Definition: DBObject.h:230

+ Here is the call graph for this function:

DBObject::~DBObject ( )
inline

Definition at line 203 of file DBObject.h.

203 {}

Member Function Documentation

void DBObject::copyPrivileges ( const DBObject object)

Definition at line 135 of file DBObject.cpp.

References objectPrivs_.

Referenced by DBObject().

135  {
136  objectPrivs_ = object.objectPrivs_;
137 }
AccessPrivileges objectPrivs_
Definition: DBObject.h:232

+ Here is the caller graph for this function:

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

Definition at line 207 of file DBObject.h.

References objectName_.

Referenced by loadKey(), and serialize_db_object().

207 { return objectName_; }
std::string objectName_
Definition: DBObject.h:229

+ Here is the caller graph for this function:

DBObjectKey DBObject::getObjectKey ( ) const
inline

load key not called?

Definition at line 209 of file DBObject.h.

References CHECK(), DBObjectKey::dbId, and objectKey_.

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

209  {
210  CHECK(-1 != objectKey_.dbId);
211  return objectKey_;
212  }
DBObjectKey objectKey_
Definition: DBObject.h:231
CHECK(cgen_state)
int32_t dbId
Definition: DBObject.h:56

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int32_t DBObject::getOwner ( ) const
inline

Definition at line 222 of file DBObject.h.

References ownerId_.

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

Definition at line 214 of file DBObject.h.

References objectPrivs_.

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

214 { return objectPrivs_; }
AccessPrivileges objectPrivs_
Definition: DBObject.h:232

+ Here is the caller graph for this function:

DBObjectType DBObject::getType ( ) const
inline

Definition at line 208 of file DBObject.h.

References objectType_.

Referenced by serialize_db_object().

208 { return objectType_; }
DBObjectType objectType_
Definition: DBObject.h:230

+ Here is the caller graph for this function:

void DBObject::grantPrivileges ( const DBObject object)
inline

Definition at line 219 of file DBObject.h.

References updatePrivileges().

219 { updatePrivileges(object); }
void updatePrivileges(const DBObject &object)
Definition: DBObject.cpp:139

+ Here is the call graph for this function:

void DBObject::loadKey ( )

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

177  {
179  if (!getName().empty()) {
181  if (!Catalog_Namespace::SysCatalog::instance().getMetadataForDB(getName(), db)) {
182  throw std::runtime_error("Failure generating DB object key. Database " + getName() +
183  " does not exist.");
184  }
185  objectKey_.dbId = db.dbId;
186  ownerId_ = db.dbOwner;
187  } else {
188  objectKey_.dbId = 0; // very special case only used for initialisation of a role
189  }
190 }
int32_t ownerId_
Definition: DBObject.h:233
DBObjectKey objectKey_
Definition: DBObject.h:231
static SysCatalog & instance()
Definition: SysCatalog.h:256
CHECK(cgen_state)
std::string getName() const
Definition: DBObject.h:207
int32_t dbId
Definition: DBObject.h:56
DBObjectType objectType_
Definition: DBObject.h:230

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

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

+ Here is the call graph for this function:

void DBObject::resetPrivileges ( )
inline

Definition at line 216 of file DBObject.h.

References objectPrivs_, and AccessPrivileges::reset().

216 { objectPrivs_.reset(); }
AccessPrivileges objectPrivs_
Definition: DBObject.h:232

+ Here is the call graph for this function:

void DBObject::revokePrivileges ( const DBObject object)

Definition at line 143 of file DBObject.cpp.

References objectPrivs_, and AccessPrivileges::privileges.

143  {
144  objectPrivs_.privileges &= ~(object.objectPrivs_.privileges);
145 }
AccessPrivileges objectPrivs_
Definition: DBObject.h:232
int64_t privileges
Definition: DBObject.h:133
void DBObject::setName ( std::string  name)
inline

Definition at line 206 of file DBObject.h.

References objectName_.

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

206 { objectName_ = name; }
std::string objectName_
Definition: DBObject.h:229

+ Here is the caller graph for this function:

void DBObject::setObjectKey ( const DBObjectKey objectKey)
inline

Definition at line 213 of file DBObject.h.

References objectKey_.

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

213 { objectKey_ = objectKey; }
DBObjectKey objectKey_
Definition: DBObject.h:231

+ Here is the caller graph for this function:

void DBObject::setObjectType ( const DBObjectType objectType)

Definition at line 150 of file DBObject.cpp.

References objectType_.

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

150  {
151  objectType_ = objectType;
152 }
DBObjectType objectType_
Definition: DBObject.h:230

+ Here is the caller graph for this function:

void DBObject::setOwner ( int32_t  userId)
inline

Definition at line 223 of file DBObject.h.

References ownerId_.

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

223 { ownerId_ = userId; }
int32_t ownerId_
Definition: DBObject.h:233

+ Here is the caller graph for this function:

void DBObject::setPermissionType ( const DBObjectType permissionType)

Definition at line 147 of file DBObject.cpp.

References objectKey_, and DBObjectKey::permissionType.

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

147  {
148  objectKey_.permissionType = permissionType;
149 }
DBObjectKey objectKey_
Definition: DBObject.h:231
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 154 of file DBObject.cpp.

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

154  {
155  std::vector<std::string> objectKey;
156  switch (objectKey_.permissionType) {
158  objectKey.push_back(std::to_string(objectKey_.permissionType));
159  objectKey.push_back(std::to_string(objectKey_.dbId));
160  objectKey.push_back(std::to_string(-1));
161  break;
162  case TableDBObjectType:
164  case ViewDBObjectType:
165  case ServerDBObjectType:
166  objectKey.push_back(std::to_string(objectKey_.permissionType));
167  objectKey.push_back(std::to_string(objectKey_.dbId));
168  objectKey.push_back(std::to_string(objectKey_.objectId));
169  break;
170  default: {
171  CHECK(false);
172  }
173  }
174  return objectKey;
175 }
int32_t objectId
Definition: DBObject.h:57
std::string to_string(char const *&&v)
DBObjectKey objectKey_
Definition: DBObject.h:231
CHECK(cgen_state)
int32_t dbId
Definition: DBObject.h:56
int32_t permissionType
Definition: DBObject.h:55

+ Here is the call graph for this function:

void DBObject::updatePrivileges ( const DBObject object)

Definition at line 139 of file DBObject.cpp.

References objectPrivs_, and AccessPrivileges::privileges.

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

139  {
140  objectPrivs_.privileges |= object.objectPrivs_.privileges;
141 }
AccessPrivileges objectPrivs_
Definition: DBObject.h:232
int64_t privileges
Definition: DBObject.h:133

+ Here is the caller graph for this function:

Member Data Documentation

DBObjectKey DBObject::objectKey_
private

Definition at line 231 of file DBObject.h.

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

std::string DBObject::objectName_
private

Definition at line 229 of file DBObject.h.

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

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

Definition at line 230 of file DBObject.h.

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

int32_t DBObject::ownerId_
private

Definition at line 233 of file DBObject.h.

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


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