From: Junghyun Yeon Date: Fri, 18 Jun 2021 10:01:28 +0000 (+0900) Subject: Cleanup abstract_db_handler X-Git-Tag: submit/tizen/20210628.110559~1^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c99ddb83643b83c9ce4eff6d72a47210049d8acb;p=platform%2Fcore%2Fappfw%2Fpkgmgr-info.git Cleanup abstract_db_handler - Move initialization of member variable into initialize lists for consistency. - Remove flag parameter of open or creating database functions. - Add some empty lines at class definition for readability. Signed-off-by: Junghyun Yeon --- diff --git a/src/server/database/abstract_db_handler.cc b/src/server/database/abstract_db_handler.cc index 7531899d..771621c2 100644 --- a/src/server/database/abstract_db_handler.cc +++ b/src/server/database/abstract_db_handler.cc @@ -46,10 +46,11 @@ int __readdb_busy_handler(void *data, int count) { } } -int __open_read_db(const char *path, sqlite3 **db, int flags) { +int __open_read_db(const char *path, sqlite3 **db) { int ret; - ret = sqlite3_open_v2(path, db, flags, NULL); + ret = sqlite3_open_v2(path, db, + SQLITE_OPEN_READONLY | SQLITE_OPEN_URI, NULL); if (ret != SQLITE_OK) { sqlite3_close_v2(*db); return ret; @@ -85,10 +86,10 @@ int __writedb_busy_handler(void *data, int count) { } int __open_write_db(uid_t uid, const char* path, - sqlite3** db, int flags) { + sqlite3** db) { int ret; - ret = sqlite3_open_v2(path, db, flags, NULL); + ret = sqlite3_open_v2(path, db, SQLITE_OPEN_READWRITE, NULL); if (ret != SQLITE_OK) { sqlite3_close_v2(*db); return ret; @@ -115,10 +116,11 @@ int __open_write_db(uid_t uid, const char* path, } int __open_create_db(uid_t uid, const char* path, - sqlite3** db, int flags) { + sqlite3** db) { int ret; - ret = sqlite3_open_v2(path, db, flags, NULL); + ret = sqlite3_open_v2(path, db, + SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL); if (ret != SQLITE_OK) { sqlite3_close_v2(*db); return ret; @@ -175,17 +177,15 @@ bool AbstractDBHandler::Connect() { return false; } auto dbpath_list = GetDBPath(); - int ret = 0; sqlite3* db; for (auto& dbpath : dbpath_list) { + int ret = 0; if (op_type_ == pkgmgr_common::DBOperationType::OPERATION_TYPE_READ) { - ret = __open_read_db(dbpath.first.c_str(), &db, SQLITE_OPEN_READONLY | - SQLITE_OPEN_URI); + ret = __open_read_db(dbpath.first.c_str(), &db); } else if (op_type_ == pkgmgr_common::DBOperationType::OPERATION_TYPE_WRITE) { if (ConvertUID(dbpath.second) != ConvertUID(uid_)) continue; - ret = __open_write_db(uid_, dbpath.first.c_str(), &db, - SQLITE_OPEN_READWRITE); + ret = __open_write_db(uid_, dbpath.first.c_str(), &db); } else { if (ConvertUID(dbpath.second) != ConvertUID(uid_)) continue; @@ -194,8 +194,7 @@ bool AbstractDBHandler::Connect() { _LOGE("Database for user %d is already exists", uid_); return false; } - ret = __open_create_db(uid_, dbpath.first.c_str(), &db, - SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE); + ret = __open_create_db(uid_, dbpath.first.c_str(), &db); } if (ret != SQLITE_OK) @@ -222,17 +221,25 @@ void AbstractDBHandler::SetOpType(pkgmgr_common::DBOperationType type) { op_type_ = type; } -const std::string& AbstractDBHandler::GetLocale() { return locale_; } +const std::string& AbstractDBHandler::GetLocale() { + return locale_; +} -int AbstractDBHandler::GetPID() { return pid_; } +int AbstractDBHandler::GetPID() { + return pid_; +} -uid_t AbstractDBHandler::GetUID() { return uid_; } +uid_t AbstractDBHandler::GetUID() { + return uid_; +} void AbstractDBHandler::SetLocale(std::string locale) { locale_ = std::move(locale); } -void AbstractDBHandler::SetDBType(pkgmgr_common::DBType type) { db_type_ = type; } +void AbstractDBHandler::SetDBType(pkgmgr_common::DBType type) { + db_type_ = type; +} pkgmgr_common::DBOperationType AbstractDBHandler::GetOpType() { return op_type_; diff --git a/src/server/database/abstract_db_handler.hh b/src/server/database/abstract_db_handler.hh index 2c8e0105..e552a785 100644 --- a/src/server/database/abstract_db_handler.hh +++ b/src/server/database/abstract_db_handler.hh @@ -36,7 +36,10 @@ namespace database { class EXPORT_API AbstractDBHandler { public: - AbstractDBHandler(uid_t uid, pid_t pid) : uid_(uid), pid_(pid) {}; + AbstractDBHandler(uid_t uid, pid_t pid) + : db_type_(pkgmgr_common::DBType::DB_TYPE_NONE), + op_type_(pkgmgr_common::DBOperationType::OPERATION_TYPE_NONE), + uid_(uid), pid_(pid) {}; virtual ~AbstractDBHandler(); virtual int Execute() = 0; void SetLocale(std::string locale); @@ -51,12 +54,14 @@ class EXPORT_API AbstractDBHandler { virtual std::vector> GetConnection(); void ClearDBHandle(); const std::string& GetLocale(); + static std::shared_timed_mutex lock_; + private: std::vector> GetDBPath(); - pkgmgr_common::DBType db_type_ = pkgmgr_common::DBType::DB_TYPE_NONE; - pkgmgr_common::DBOperationType op_type_ = - pkgmgr_common::DBOperationType::OPERATION_TYPE_NONE; + + pkgmgr_common::DBType db_type_; + pkgmgr_common::DBOperationType op_type_; uid_t uid_; pid_t pid_; std::string locale_;