Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3490575
D5992.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
D5992.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
@@ -4,9 +4,15 @@
// TODO: includes may be conditional if we base on the preprocessor
#include "SQLiteQueryExecutor.h"
+#include <mutex>
+
namespace comm {
class DatabaseManager {
+ static std::once_flag initialized;
+
+ static void setDatabaseStatusAsWorkable();
+
public:
static const DatabaseQueryExecutor &getQueryExecutor();
static void clearSensitiveData();
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
@@ -5,10 +5,12 @@
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";
+std::once_flag DatabaseManager::initialized;
+
+typedef const std::string DatabaseManagerStatus;
+DatabaseManagerStatus DB_MANAGER_WORKABLE = "WORKABLE";
+DatabaseManagerStatus DB_MANAGER_FIRST_FAILURE = "FIRST_FAILURE";
+DatabaseManagerStatus DB_MANAGER_SECOND_FAILURE = "SECOND_FAILURE";
const std::string DATABASE_MANAGER_STATUS_KEY = "DATABASE_MANAGER_STATUS";
@@ -16,11 +18,18 @@
// TODO: conditionally create desired type of db manager
// maybe basing on some preprocessor flag
thread_local SQLiteQueryExecutor instance;
+
+ // creating an instance means that migration code was executed
+ // and finished without error and database is workable
+ std::call_once(DatabaseManager::initialized, []() {
+ DatabaseManager::setDatabaseStatusAsWorkable();
+ });
return instance;
}
void DatabaseManager::clearSensitiveData() {
SQLiteQueryExecutor::clearSensitiveData();
+ DatabaseManager::setDatabaseStatusAsWorkable();
}
void DatabaseManager::initializeQueryExecutor(std::string &databasePath) {
@@ -51,4 +60,9 @@
}
}
+void DatabaseManager::setDatabaseStatusAsWorkable() {
+ comm::CommSecureStore commSecureStore{};
+ commSecureStore.set(DATABASE_MANAGER_STATUS_KEY, DB_MANAGER_WORKABLE);
+}
+
} // namespace comm
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Dec 19, 4:42 PM (20 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2678031
Default Alt Text
D5992.diff (2 KB)
Attached To
Mode
D5992: [native] add function to set database status after successful structure creation
Attached
Detach File
Event Timeline
Log In to Comment