Cleanup abstract_db_handler
authorJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 18 Jun 2021 10:01:28 +0000 (19:01 +0900)
committer연정현/Tizen Platform Lab(SR)/Staff Engineer/삼성전자 <jungh.yeon@samsung.com>
Wed, 23 Jun 2021 03:31:11 +0000 (12:31 +0900)
- 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 <jungh.yeon@samsung.com>
src/server/database/abstract_db_handler.cc
src/server/database/abstract_db_handler.hh

index 7531899d07165f90cb0e6cd1c86986ab26f72f79..771621c25de05d292a4ff60d850f8563164f0cf1 100644 (file)
@@ -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_;
index 2c8e01051a099caf8ef476dda6df61fabdbe1c74..e552a78544e0f8a3fba2cb021d96597851e29c21 100644 (file)
@@ -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<std::pair<sqlite3*, uid_t>> GetConnection();
   void ClearDBHandle();
   const std::string& GetLocale();
+
   static std::shared_timed_mutex lock_;
+
  private:
   std::vector<std::pair<std::string, uid_t>> 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_;