From 56db6f8f7d9d634db832fc93b19209484cdc6bc1 Mon Sep 17 00:00:00 2001 From: Konstantin Krivopustov Date: Wed, 5 Apr 2017 16:17:27 +0400 Subject: [PATCH] PL-8744 Handling of database connection problems on middleware startup (fail immediately if main database is unavailable) --- .../cuba/core/sys/AppContextLoader.java | 58 +++++++------------ 1 file changed, 20 insertions(+), 38 deletions(-) diff --git a/modules/core/src/com/haulmont/cuba/core/sys/AppContextLoader.java b/modules/core/src/com/haulmont/cuba/core/sys/AppContextLoader.java index fe5b1ec0c3..d147a004a7 100644 --- a/modules/core/src/com/haulmont/cuba/core/sys/AppContextLoader.java +++ b/modules/core/src/com/haulmont/cuba/core/sys/AppContextLoader.java @@ -110,49 +110,31 @@ public class AppContextLoader extends AbstractWebAppContextLoader { } protected void updateDatabase(DbUpdater updater) { - while (true) { - try { - updater.updateDatabase(); - return; - } catch (DbInitializationException e) { - if (e.isRetryPossible()) { - log.error("Error updating database: {}\nWaiting 5 sec and retrying...", e.toString()); - try { - Thread.sleep(5000); - } catch (InterruptedException e1) { - Thread.currentThread().interrupt(); - } - } else { - throw new RuntimeException("Error updating database", e); - } - } + try { + updater.updateDatabase(); + } catch (DbInitializationException e) { + throw new RuntimeException("\n" + + "==============================================================================\n" + + "ERROR: Cannot check and update database. See the stacktrace below for details.\n" + + "==============================================================================", e); } } protected void checkDatabase(DbUpdater updater) { - while (true) { - try { - boolean initialized = updater.dbInitialized(); - if (!initialized) { - throw new IllegalStateException("\n" + - "============================================================================\n" + - "ERROR: Database is not initialized. Set 'cuba.automaticDatabaseUpdate'\n" + - "application property to 'true' to initialize and update database on startup.\n" + - "============================================================================"); - } - return; - } catch (DbInitializationException e) { - if (e.isRetryPossible()) { - log.error("Error connecting to database: {}\nWaiting 5 sec and retrying...", e.toString()); - try { - Thread.sleep(5000); - } catch (InterruptedException e1) { - Thread.currentThread().interrupt(); - } - } else { - throw new RuntimeException("Error checking database", e); - } + try { + boolean initialized = updater.dbInitialized(); + if (!initialized) { + throw new IllegalStateException("\n" + + "============================================================================\n" + + "ERROR: Database is not initialized. Set 'cuba.automaticDatabaseUpdate'\n" + + "application property to 'true' to initialize and update database on startup.\n" + + "============================================================================"); } + } catch (DbInitializationException e) { + throw new RuntimeException("\n" + + "===================================================================\n" + + "ERROR: Cannot check database. See the stacktrace below for details.\n" + + "===================================================================", e); } } }