Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3491692
D5991.id21737.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D5991.id21737.diff
View Options
diff --git a/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.h b/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.h
--- a/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.h
+++ b/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.h
@@ -10,6 +10,7 @@
public:
static const DatabaseQueryExecutor &getQueryExecutor();
static void clearSensitiveData();
+ static void initializeQueryExecutor(std::string &databasePath);
};
} // namespace comm
diff --git a/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.cpp b/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.cpp
--- a/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.cpp
+++ b/native/cpp/CommonCpp/DatabaseManagers/DatabaseManager.cpp
@@ -1,8 +1,17 @@
#include "DatabaseManager.h"
+#include "../Tools/CommSecureStore.h"
+#include "Logger.h"
#include "SQLiteQueryExecutor.h"
namespace comm {
+typedef std::string DatabaseManagerStatus;
+const DatabaseManagerStatus DB_MANAGER_WORKABLE = "WORKABLE";
+const DatabaseManagerStatus DB_MANAGER_FIRST_FAILURE = "FIRST_FAILURE";
+const DatabaseManagerStatus DB_MANAGER_SECOND_FAILURE = "SECOND_FAILURE";
+
+const std::string DATABASE_MANAGER_STATUS_KEY = "DATABASE_MANAGER_STATUS";
+
const DatabaseQueryExecutor &DatabaseManager::getQueryExecutor() {
// TODO: conditionally create desired type of db manager
// maybe basing on some preprocessor flag
@@ -14,4 +23,32 @@
SQLiteQueryExecutor::clearSensitiveData();
}
+void DatabaseManager::initializeQueryExecutor(std::string &databasePath) {
+ comm::CommSecureStore commSecureStore{};
+ try {
+ SQLiteQueryExecutor::initialize(databasePath);
+ DatabaseManager::getQueryExecutor();
+ commSecureStore.set(DATABASE_MANAGER_STATUS_KEY, DB_MANAGER_WORKABLE);
+ Logger::log("Database manager initialized");
+ } catch (...) {
+ folly::Optional<std::string> databaseManagerStatus =
+ commSecureStore.get(DATABASE_MANAGER_STATUS_KEY);
+ if (!databaseManagerStatus.hasValue() ||
+ databaseManagerStatus.value() == DB_MANAGER_WORKABLE) {
+ commSecureStore.set(
+ DATABASE_MANAGER_STATUS_KEY, DB_MANAGER_FIRST_FAILURE);
+ Logger::log("Database manager initialization issue, terminating app");
+ throw;
+ }
+ if (databaseManagerStatus.value() == DB_MANAGER_FIRST_FAILURE) {
+ commSecureStore.set(
+ DATABASE_MANAGER_STATUS_KEY, DB_MANAGER_SECOND_FAILURE);
+ Logger::log(
+ "Database manager initialization issue, app proceeding, but "
+ "database needs to be deleted");
+ return;
+ }
+ }
+}
+
} // namespace comm
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 19, 7:55 PM (20 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2678105
Default Alt Text
D5991.id21737.diff (2 KB)
Attached To
Mode
D5991: [native] add function to initialize `DatabaseQueryExecutor`
Attached
Detach File
Event Timeline
Log In to Comment