From 5f89ff794490b06a3e050933b9b7a01b905bcc39 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Sun, 9 Feb 2025 22:05:35 +0100 Subject: [PATCH] [DEV] add variable to permit not check if the DB exist --- .../archidata/migration/MigrationEngine.java | 58 ++++++++++--------- .../archidata/tools/ConfigBaseVariable.java | 9 +++ 2 files changed, 41 insertions(+), 26 deletions(-) diff --git a/src/org/kar/archidata/migration/MigrationEngine.java b/src/org/kar/archidata/migration/MigrationEngine.java index 8b30a00..7ddd4f2 100644 --- a/src/org/kar/archidata/migration/MigrationEngine.java +++ b/src/org/kar/archidata/migration/MigrationEngine.java @@ -11,6 +11,7 @@ import org.kar.archidata.dataAccess.DataFactory; import org.kar.archidata.dataAccess.QueryOptions; import org.kar.archidata.db.DbConfig; import org.kar.archidata.migration.model.Migration; +import org.kar.archidata.tools.ConfigBaseVariable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -130,35 +131,40 @@ public class MigrationEngine { } private void createTableIfAbleOrWaitAdmin(final DbConfig configInput) throws MigrationException { - final DbConfig config = configInput.clone(); - config.setDbName(null); - final String dbName = configInput.getDbName(); - LOGGER.info("Verify existance of '{}'", dbName); - try (final DBAccess da = DBAccess.createInterface(config)) { - boolean exist = da.isDBExist(dbName); - if (!exist) { - LOGGER.warn("DB: '{}' DOES NOT EXIST ==> create one", dbName); - // create the local DB: - da.createDB(dbName); - } - exist = da.isDBExist(dbName); - while (!exist) { - LOGGER.error("DB: '{}' DOES NOT EXIST after trying to create one ", dbName); - LOGGER.error("Waiting administrator create a new one, we check after 30 seconds..."); - try { - Thread.sleep(30000); - } catch (final InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + if (ConfigBaseVariable.getDBAbleToCreate()) { + final DbConfig config = configInput.clone(); + config.setDbName(null); + final String dbName = configInput.getDbName(); + LOGGER.info("Verify existance of '{}'", dbName); + try (final DBAccess da = DBAccess.createInterface(config)) { + boolean exist = da.isDBExist(dbName); + if (!exist) { + LOGGER.warn("DB: '{}' DOES NOT EXIST ==> create one", dbName); + // create the local DB: + da.createDB(dbName); } exist = da.isDBExist(dbName); + while (!exist) { + LOGGER.error("DB: '{}' DOES NOT EXIST after trying to create one ", dbName); + LOGGER.error("Waiting administrator create a new one, we check after 30 seconds..."); + try { + Thread.sleep(30000); + } catch (final InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + exist = da.isDBExist(dbName); + } + } catch (final InternalServerErrorException e) { + e.printStackTrace(); + throw new MigrationException("TODO ..."); + } catch (final IOException e) { + e.printStackTrace(); + throw new MigrationException("TODO ..."); } - } catch (final InternalServerErrorException e) { - e.printStackTrace(); - throw new MigrationException("TODO ..."); - } catch (final IOException e) { - e.printStackTrace(); - throw new MigrationException("TODO ..."); + } else { + final String dbName = configInput.getDbName(); + LOGGER.warn("DB: '{}' is not check if it EXIST", dbName); } } diff --git a/src/org/kar/archidata/tools/ConfigBaseVariable.java b/src/org/kar/archidata/tools/ConfigBaseVariable.java index 13b23a5..a467873 100644 --- a/src/org/kar/archidata/tools/ConfigBaseVariable.java +++ b/src/org/kar/archidata/tools/ConfigBaseVariable.java @@ -3,6 +3,7 @@ package org.kar.archidata.tools; public class ConfigBaseVariable { static public String tmpDataFolder; static public String dataFolder; + static public String dbAbleToCreate; static public String dbType; static public String dbHost; static public String dbPort; @@ -23,6 +24,7 @@ public class ConfigBaseVariable { public static void clearAllValue() { tmpDataFolder = System.getenv("DATA_TMP_FOLDER"); dataFolder = System.getenv("DATA_FOLDER"); + dbAbleToCreate = System.getenv("DB_ABLE_TO_CREATE"); dbType = System.getenv("DB_TYPE"); dbHost = System.getenv("DB_HOST"); dbPort = System.getenv("DB_PORT"); @@ -58,6 +60,13 @@ public class ConfigBaseVariable { return dataFolder; } + public static boolean getDBAbleToCreate() { + if (dbAbleToCreate == null) { + return true; + } + return Boolean.getBoolean(dbAbleToCreate); + } + public static String getDBType() { if (dbType == null) { return "mysql";