This is an automated email from the ASF dual-hosted git repository.

benjobs pushed a commit to branch metadata
in repository https://gitbox.apache.org/repos/asf/incubator-streampark.git

commit 852713da86dc819fe2c00221f97a0a8c80e319c8
Author: benjobs <[email protected]>
AuthorDate: Sat Jun 15 17:35:08 2024 +0800

    [Improve] h2 dialect improvement
---
 .../src/main/assembly/conf/config.yaml             |  5 ++--
 .../console/base/config/SpringProperties.java      | 33 ++++++++++++++++++----
 .../console/system/authentication/ShiroConfig.java |  1 +
 3 files changed, 31 insertions(+), 8 deletions(-)

diff --git 
a/streampark-console/streampark-console-service/src/main/assembly/conf/config.yaml
 
b/streampark-console/streampark-console-service/src/main/assembly/conf/config.yaml
index c6845eaad..6895c8715 100644
--- 
a/streampark-console/streampark-console-service/src/main/assembly/conf/config.yaml
+++ 
b/streampark-console/streampark-console-service/src/main/assembly/conf/config.yaml
@@ -35,10 +35,11 @@ server:
 # system database, default h2, mysql|pgsql|h2
 datasource:
   dialect: h2  #h2, mysql, pgsql
+  h2-data-dir:  # if datasource.dialect is h2 ,you can configure the data dir
   # if datasource.dialect is mysql or pgsql, you need to configure the 
following connection information
-  # mysql/postgresql connect user
+  # mysql/postgresql/h2 connect user
   username:
-  # mysql/postgresql connect password
+  # mysql/postgresql/h2 connect password
   password:
   # mysql/postgresql connect jdbcURL
   # mysql example: datasource.url: 
jdbc:mysql://localhost:3306/streampark?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8
diff --git 
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/SpringProperties.java
 
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/SpringProperties.java
index 1d755f668..7ad981958 100644
--- 
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/SpringProperties.java
+++ 
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/base/config/SpringProperties.java
@@ -87,17 +87,38 @@ public class SpringProperties {
         springConfig.put("spring.datasource.driver-class-name", 
"org.postgresql.Driver");
         break;
       case "h2":
-        springConfig.put("spring.datasource.driver-class-name", 
"org.h2.Driver");
-        springConfig.put("spring.datasource.username", "sa");
-        springConfig.put("spring.datasource.password", "sa");
+        String h2Dir = userConfig.getProperty("datasource.h2-data-dir", null);
+
+        if (StringUtils.isBlank(h2Dir)) {
+          h2Dir = "~/streampark/metadata";
+        } else {
+          h2Dir += h2Dir.endsWith("/") ? "metadata" : "/metadata";
+        }
+
         springConfig.put(
             "spring.datasource.url",
-            
"jdbc:h2:mem:streampark;MODE=MySQL;DB_CLOSE_DELAY=-1;DATABASE_TO_LOWER=true;INIT=runscript
 from 'classpath:db/schema-h2.sql'");
+            String.format(
+                
"jdbc:h2:file:%s;MODE=MySQL;DB_CLOSE_DELAY=-1;DATABASE_TO_LOWER=true;INIT=runscript
 from 'classpath:db/schema-h2.sql'",
+                h2Dir));
+
+        String userName = userConfig.getProperty("spring.datasource.username", 
"admin");
+        String password = userConfig.getProperty("spring.datasource.password", 
"streampark");
+
+        springConfig.put("spring.jpa.database-platform", 
"org.hibernate.dialect.H2Dialect");
+        springConfig.put("spring.datasource.driver-class-name", 
"org.h2.Driver");
+        springConfig.put("spring.datasource.username", userName);
+        springConfig.put("spring.datasource.password", password);
         springConfig.put("spring.sql.init.data-locations", 
"classpath:db/data-h2.sql");
         springConfig.put("spring.sql.init.continue-on-error", "true");
-        springConfig.put("spring.sql.init.username", "sa");
-        springConfig.put("spring.sql.init.password", "sa");
+        springConfig.put("spring.sql.init.username", userName);
+        springConfig.put("spring.sql.init.password", password);
         springConfig.put("spring.sql.init.mode", "always");
+
+        // h2
+        springConfig.put("spring.h2.console.path", "/h2-console");
+        springConfig.put("spring.h2.console.enabled", true);
+        springConfig.put("spring.h2.console.settings.web-allow-others", true);
+        springConfig.put("spring.h2.console.settings.trace", true);
         break;
       default:
         throw new UnsupportedOperationException("Unsupported datasource 
dialect: " + dialect);
diff --git 
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/authentication/ShiroConfig.java
 
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/authentication/ShiroConfig.java
index 3384723ae..2b14903c3 100644
--- 
a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/authentication/ShiroConfig.java
+++ 
b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/authentication/ShiroConfig.java
@@ -43,6 +43,7 @@ public class ShiroConfig {
 
     LinkedHashMap<String, String> filterChainDefinitionMap = new 
LinkedHashMap<>();
     filterChainDefinitionMap.put("/actuator/**", "anon");
+    filterChainDefinitionMap.put("/h2-console/**", "anon");
 
     filterChainDefinitionMap.put("/doc.html", "anon");
     filterChainDefinitionMap.put("/swagger-ui.html", "anon");

Reply via email to