Skip to content

Commit

Permalink
[Feat] sync h2 dialect improvement from dev-2.1.5 (#3765)
Browse files Browse the repository at this point in the history
Co-authored-by: benjobs <[email protected]>
  • Loading branch information
wolfboys and benjobs authored Jun 16, 2024
1 parent 1326b9f commit dd6a96f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ server:
# system database, default h2, mysql|pgsql|h2
datasource:
dialect: h2 #h2, mysql, pgsql
h2-data-dir: ~/streampark/h2-data # 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ insert into `t_setting` values (15, 'ingress.mode.default', null, 'Ingress domai
-- ----------------------------
-- Records of t_user
-- ----------------------------
insert into `t_user` values (100000, 'admin', '', 'rh8b1ojwog777yrg0daesf04gk', '2513f3748847298ea324dffbf67fe68681dd92315bda830065facd8efe08f54f', null, 1, 0, null, '1', now(), now(),null,0,null,null);
insert into `t_user` values (100000, 'admin', '', 'rh8b1ojwog777yrg0daesf04gk', '2513f3748847298ea324dffbf67fe68681dd92315bda830065facd8efe08f54f', null, 1, 0, 100000, '1', now(), now(),null,0,null,null);

-- ----------------------------
-- Records of t_member
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,37 @@ private static void dataSourceConfig(Properties userConfig, Properties springCon
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 h2DataDir = userConfig.getProperty("datasource.h2-data-dir", null);
if (StringUtils.isBlank(h2DataDir)) {
h2DataDir = System.getProperty("user.home", "~") + "/streampark/h2-data/metadata";
} else {
h2DataDir += h2DataDir.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'",
h2DataDir));

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityMan

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");
Expand Down

0 comments on commit dd6a96f

Please sign in to comment.