tom throw if no conn. configuration registered

This commit is contained in:
silverqx
2022-08-16 21:21:19 +02:00
parent 20af1a9186
commit 34b2267e45
2 changed files with 16 additions and 0 deletions
+2
View File
@@ -244,6 +244,8 @@ namespace Concerns
/*! Get database connection resolver. */
std::shared_ptr<ConnectionResolverInterface> resolver() const noexcept;
/*! Throw if no connection configuration is registered. */
void throwIfNoConnectionConfig() const;
/*! Throw if a default connection is empty. */
void throwIfEmptyDefaultConnection() const;
+14
View File
@@ -159,6 +159,8 @@ Application::Application(int &argc, char **argv, std::shared_ptr<DatabaseManager
int Application::run()
{
// Throw if no database connection configuration is registered
throwIfNoConnectionConfig();
// Default database connection is required if exactly one connection is registered
throwIfEmptyDefaultConnection();
@@ -653,6 +655,18 @@ std::shared_ptr<ConnectionResolverInterface> Application::resolver() const noexc
return std::dynamic_pointer_cast<ConnectionResolverInterface>(m_db);
}
void Application::throwIfNoConnectionConfig() const
{
// Nothing to do, some database connection configuration/s are already registered
if (m_db->originalConfigsSize() > 0)
return;
throw Exceptions::RuntimeError(
"No connection configuration is registered, please add at least one "
"database configuration to the DatabaseManager (eg. using "
"DB::create()).");
}
void Application::throwIfEmptyDefaultConnection() const
{
// Nothing to do, default connection is defined or more connections is registered