From f9123ccfad4778d01fc9d6b19981113a5c917016 Mon Sep 17 00:00:00 2001 From: "chen.ma" Date: Wed, 19 Oct 2022 00:37:03 +0800 Subject: [PATCH] Optimize the H2 initialization logic (#807) --- .../server/init/LocalDataSourceLoader.java | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/hippo4j-server/src/main/java/cn/hippo4j/server/init/LocalDataSourceLoader.java b/hippo4j-server/src/main/java/cn/hippo4j/server/init/LocalDataSourceLoader.java index 76784710..ae59559b 100644 --- a/hippo4j-server/src/main/java/cn/hippo4j/server/init/LocalDataSourceLoader.java +++ b/hippo4j-server/src/main/java/cn/hippo4j/server/init/LocalDataSourceLoader.java @@ -71,10 +71,6 @@ public class LocalDataSourceLoader implements InstantiationAwareBeanPostProcesso jdbcUrl = StringUtil.replace(properties.getUrl(), "/hippo4j_manager?", "?"); } Connection connection = DriverManager.getConnection(jdbcUrl, properties.getUsername(), properties.getPassword()); - // TODO Compatible with h2 to execute `INSERT IGNORE INTO` statement error - if (Objects.equals(dataBaseProperties.getDialect(), "h2") && ifNonExecute(connection)) { - return; - } execute(connection, dataBaseProperties.getInitScript()); } catch (Exception ex) { log.error("Datasource init error.", ex); @@ -82,20 +78,6 @@ public class LocalDataSourceLoader implements InstantiationAwareBeanPostProcesso } } - private boolean ifNonExecute(final Connection conn) throws SQLException { - try ( - Statement statement = conn.createStatement(); - ResultSet resultSet = statement.executeQuery("SELECT COUNT(*) FROM `user`")) { - if (resultSet.next()) { - int countUser = resultSet.getInt(1); - return countUser > 0 ? true : false; - } - } catch (Exception ignored) { - log.error("Query data for errors.", ignored); - } - return false; - } - private void execute(final Connection conn, final String script) throws Exception { ScriptRunner runner = new ScriptRunner(conn); try {