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 @@ -7,6 +7,10 @@ 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 @@ -6,6 +6,8 @@ namespace comm { +std::once_flag DatabaseManager::initialized; + typedef const std::string DatabaseManagerStatus; DatabaseManagerStatus DB_MANAGER_WORKABLE = "WORKABLE"; DatabaseManagerStatus DB_MANAGER_FIRST_FAILURE = "FIRST_FAILURE"; @@ -17,11 +19,15 @@ // TODO: conditionally create desired type of db manager // maybe basing on some preprocessor flag thread_local SQLiteQueryExecutor instance; + std::call_once(DatabaseManager::initialized, []() { + DatabaseManager::setDatabaseStatusAsWorkable(); + }); return instance; } void DatabaseManager::clearSensitiveData() { SQLiteQueryExecutor::clearSensitiveData(); + DatabaseManager::setDatabaseStatusAsWorkable(); } void DatabaseManager::initializeQueryExecutor() { @@ -51,4 +57,9 @@ } } +void DatabaseManager::setDatabaseStatusAsWorkable() { + comm::CommSecureStore commSecureStore{}; + commSecureStore.set(DATABASE_MANAGER_STATUS_KEY, DB_MANAGER_WORKABLE); +} + } // namespace comm