#include <tzplatform_config.h>
#include <string>
+#include <vector>
#include "db_handle_provider.hh"
#include "pkgmgr-info.h"
AbstractDBHandler::~AbstractDBHandler() {
// Is this necessary?
- sqlite3_close(db_);
+ for (auto db_handle : db_handle_list_)
+ sqlite3_close(db_handle);
}
-std::string AbstractDBHandler::GetDBPath() {
- std::string db_path;
+std::vector<std::string> AbstractDBHandler::GetDBPath() {
+ std::vector<std::string> db_path;
if (db_type_ == DB_TYPE_FILE_PKGDB) {
db_path = DBHandleProvider::GetInst(uid_).GetParserDBPath();
} else if (db_type_ == DB_TYPE_FILE_CERTDB) {
- db_path = DBHandleProvider::GetInst(uid_).GetCertDBPath();
+ db_path.emplace_back(DBHandleProvider::GetInst(uid_).GetCertDBPath());
}
return db_path;
// error log
return false;
}
- std::string db_path = GetDBPath();
+ auto dbpath_list = GetDBPath();
int ret = 0;
+ sqlite3* db;
+ for (auto dbpath : dbpath_list) {
+ if (op_type_ == OPERATION_TYPE_READ)
+ ret = __open_read_db(dbpath.c_str(), &db, SQLITE_OPEN_READONLY |
+ SQLITE_OPEN_URI);
+ else
+ ret = __open_write_db(uid_, dbpath.c_str(), &db,
+ SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
+ // TODO: if write request has received, only one database should be delivered
+ if (ret != SQLITE_OK)
+ return false;
+
+ db_handle_list_.emplace_back(db);
+ }
+
+ return true;
+/*
if (op_type_ == OPERATION_TYPE_READ)
ret = __open_read_db(db_path.c_str(), &db_, SQLITE_OPEN_READONLY |
SQLITE_OPEN_URI);
return false;
}
return true;
+*/
}
-sqlite3* AbstractDBHandler::GetConnection() { return db_; }
+std::vector<sqlite3*> AbstractDBHandler::GetConnection() {
+ return db_handle_list_;
+}
void AbstractDBHandler::SetOpType(OperationType type) {
op_type_ = type;
#define ABSTRACT_DB_HANDLER_HH_
#include <string>
+#include <vector>
#include <sys/types.h>
#include <sqlite3.h>
protected:
bool Connect();
- sqlite3* GetConnection();
+ std::vector<sqlite3*> GetConnection();
std::string GetLocale();
private:
- std::string GetDBPath();
+ std::vector<std::string> GetDBPath();
DBType db_type_ = DB_TYPE_NONE;
OperationType op_type_ = OPERATION_TYPE_NONE;
uid_t uid_;
std::string locale_;
- sqlite3* db_ = nullptr;
+ std::vector<sqlite3*> db_handle_list_;
};
} // namespace database
#include "appinfo_db_handler.hh"
+#include <vector>
+
#include "pkgmgrinfo_internal.h"
+
namespace {
void _move(gpointer key, gpointer value, gpointer user_data) {
if (!Connect()) return PMINFO_R_ERROR;
GHashTable* list = nullptr;
+ std::vector<sqlite3*> conn_list = GetConnection();
+ int ret = PMINFO_R_OK;
+ for (auto conn : conn_list) {
+ ret = appinfo_internal_filter_get_list(conn, filter_, uid_,
+ GetLocale().c_str(), &list);
+ if (ret != PMINFO_R_OK)
+ break;
+ }
+/*
int ret = appinfo_internal_filter_get_list(GetConnection(), filter_, uid_,
GetLocale().c_str(), &list);
-
+*/
g_hash_table_foreach(list, _move, &handle_list_);
g_hash_table_destroy(list);
return ret;
#include "cert_get_db_handler.hh"
+#include <vector>
+
#include "pkgmgrinfo_internal.h"
namespace pkgmgr_common {
return ret;
handle_ = static_cast<pkgmgr_certinfo_x*>(handle);
- // TODO: db handle should be delivered
- ret = certinfo_internal_get(GetConnection(), pkgid_.c_str(), uid_, handle_);
+ std::vector<sqlite3*> conn_list = GetConnection();
+ for (auto& conn : conn_list)
+ ret = certinfo_internal_get(conn, pkgid_.c_str(), uid_, handle_);
return ret;
}
#include "db_handle_provider.hh"
#include "cert_set_db_handler.hh"
+#include <vector>
+
#include "pkgmgrinfo_internal.h"
namespace pkgmgr_common {
SetDBType(DB_TYPE_FILE_CERTDB);
DBHandleProvider::GetInst(uid_).SetMemoryMode(true);
- int ret = certinfo_internal_set(
- GetConnection(), handle_->pkgid, handle_, uid_);
+ std::vector<sqlite3*> conn_list = GetConnection();
+ int ret;
+ for (auto& conn : conn_list)
+ ret = certinfo_internal_set(
+ conn, handle_->pkgid, handle_, uid_);
return ret;
}
return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
}
+bool IsUserRequest(uid_t uid) {
+ return (uid > REGULAR_USER);
+}
+
uid_t ConvertUID(uid_t uid) {
if (uid < REGULAR_USER)
return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
std::vector<std::string> db_path_list;
if (is_memory_) {
db_path_list.emplace_back(parser_memory_db_path_);
- db_path_list.emplace_back(global_parser_memory_db_path_);
+ if (IsUserRequest(uid_))
+ db_path_list.emplace_back(global_parser_memory_db_path_);
} else {
db_path_list.emplace_back(parser_file_db_path_);
- db_path_list.emplace_back(global_parser_file_db_path_);
+ if (IsUserRequest(uid_))
+ db_path_list.emplace_back(global_parser_file_db_path_);
}
return db_path_list;
}
#include "depinfo_db_handler.hh"
+#include <vector>
+
#include "pkgmgrinfo_internal.h"
namespace pkgmgr_common {
if (!Connect()) return PMINFO_R_ERROR;
GList *list = nullptr;
- int ret = pkginfo_internal_filter_get_depends_on(
- GetConnection(), pkgid_.c_str(), &list);
-
+ std::vector<sqlite3*> conn_list = GetConnection();
+ int ret;
+ for (auto& conn : conn_list) {
+ ret = pkginfo_internal_filter_get_depends_on(
+ conn, pkgid_.c_str(), &list);
+ if (ret != PMINFO_R_OK)
+ break;
+ }
return ret;
}
#include "pkg_get_db_handler.hh"
+#include <vector>
+
#include "pkgmgrinfo_internal.h"
namespace {
// TODO: db handle should be delivered
GHashTable* list;
- int ret = pkginfo_internal_filter_get_list(GetConnection(), filter_, uid_,
- GetLocale().c_str(), &list);
- if (ret != PMINFO_R_OK) {
- // TODO: error log
- return ret;
+ std::vector<sqlite3*> conn_list = GetConnection();
+ int ret;
+ for (auto& conn : conn_list) {
+ ret = pkginfo_internal_filter_get_list(conn, filter_, uid_,
+ GetLocale().c_str(), &list);
+ if (ret != PMINFO_R_OK) {
+ g_hash_table_destroy(list);
+ return ret;
+ }
}
+ // TODO: possible memory leak?
g_hash_table_foreach(list, _move, &handle_list_);
g_hash_table_destroy(list);
#include "db_handle_provider.hh"
#include "pkg_set_db_handler.hh"
+#include <vector>
+
#include "pkgmgr_parser_db.h"
namespace pkgmgr_common {
int ret = 0;
DBHandleProvider::GetInst(uid_).SetMemoryMode(true);
+ std::vector<sqlite3*> conn_list = GetConnection();
+ sqlite3* conn = conn_list.front();
if (write_type_ == Insert) {
- ret = pkgmgr_parser_insert_pkg_info(GetConnection(), package_, uid_);
+ ret = pkgmgr_parser_insert_pkg_info(conn, package_, uid_);
} else if (write_type_ == Update) {
- ret = pkgmgr_parser_update_pkg_info(GetConnection(), package_, uid_);
+ ret = pkgmgr_parser_update_pkg_info(conn, package_, uid_);
} else if (write_type_ == Delete) {
- ret = pkgmgr_parser_delete_pkg_info(GetConnection(), package_->package, uid_);
+ ret = pkgmgr_parser_delete_pkg_info(conn, package_->package, uid_);
} else {
}
#include "query_handler.hh"
+#include <vector>
+
#include "pkgmgrinfo_internal.h"
namespace pkgmgr_common {
if (query_.size() == 0)
return PMINFO_R_ERROR;
+ int ret;
+ std::vector<sqlite3*> conn_list = GetConnection();
if (GetOpType() == OPERATION_TYPE_READ) {
- int ret = get_query_result(GetConnection(), query_[0].c_str(), &list, &row, &col);
- if (ret != PMINFO_R_OK) {
- // TODO: error log
- return ret;
- }
+ for (auto& conn : conn_list) {
+ ret = get_query_result(conn, query_[0].c_str(), &list, &row, &col);
+ if (ret != PMINFO_R_OK) {
+ // TODO: error log
+ return ret;
+ }
- result_.clear();
- result_.resize(row);
- GList* tmp = list;
- for (int i = 0; i < row; ++i) {
- for (int j = 0; j < col; ++j) {
- result_[i].emplace_back(reinterpret_cast<char *>(tmp->data));
- tmp = tmp->next;
+ result_.clear();
+ result_.resize(row);
+ GList* tmp = list;
+ for (int i = 0; i < row; ++i) {
+ for (int j = 0; j < col; ++j) {
+ result_[i].emplace_back(reinterpret_cast<char *>(tmp->data));
+ tmp = tmp->next;
+ }
}
- }
- g_list_free(list);
+ g_list_free(list);
+ }
return ret;
} else {
const char **queries = (const char **)calloc(query_.size(), sizeof(char *));
for (const auto& query : query_)
queries[i++] = query.c_str();
- int ret = execute_write_queries(GetConnection(), queries, query_.size());
-
+ for (auto& conn : conn_list) {
+ ret = execute_write_queries(conn, queries, query_.size());
+ }
free(queries);
return ret;
}