Skip to content

Commit c1e2ee4

Browse files
committed
处理低版本服务端 HikariCP 无法使用 SQLite 驱动的问题
1 parent 3464db8 commit c1e2ee4

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

MiraiMC-Base/src/main/java/me/dreamvoid/miraimc/internal/Utils.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -180,23 +180,23 @@ public static File getMiraiDir(){
180180
return PluginConfig.General.MiraiWorkingDir.equals("default") ? new File(PluginConfig.PluginDir,"MiraiBot") : new File(PluginConfig.General.MiraiWorkingDir);
181181
}
182182

183-
public static void resolveException(Exception exception, Logger logger, String reason) {
183+
public static void resolveException(Throwable throwable, Logger logger, String reason) {
184184
if(!reason.isEmpty()) logger.severe(reason);
185185
logger.severe("如果你确信这是 MiraiMC 的错误,前往 GitHub 报告 issue 并附上完整服务器日志。");
186186

187-
Throwable throwable = exception;
188-
while(throwable != null){
189-
if (throwable == exception) {
190-
logger.severe(exception.toString());
187+
Throwable t = throwable;
188+
while(t != null){
189+
if (t == throwable) {
190+
logger.severe(throwable.toString());
191191
} else {
192-
logger.severe("Caused by: " + throwable);
192+
logger.severe("Caused by: " + t);
193193
}
194194

195-
for(StackTraceElement element : throwable.getStackTrace()){
195+
for(StackTraceElement element : t.getStackTrace()){
196196
getLogger().severe(String.format("\tat %s.%s(%s:%d)", element.getClassName(), element.getMethodName(), element.getFileName(), element.getLineNumber()));
197197
}
198198

199-
throwable = throwable.getCause();
199+
t = t.getCause();
200200
}
201201
}
202202

MiraiMC-Base/src/main/java/me/dreamvoid/miraimc/internal/database/SQLite.java

+18-14
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,25 @@ public void initialize() throws ClassNotFoundException {
4242
return;
4343
}
4444

45-
HikariConfig config = new HikariConfig();
46-
config.setDriverClassName(driver);
47-
config.setPoolName("MiraiMC-SQLite");
48-
config.setJdbcUrl("jdbc:sqlite:" + new File(PluginConfig.Database.Drivers.SQLite.Path.replace("%plugin_folder%", PluginConfig.PluginDir.toPath().toString())).toPath());
49-
config.setConnectionTimeout(PluginConfig.Database.Settings.Pool.ConnectionTimeout);
50-
config.setIdleTimeout(PluginConfig.Database.Settings.Pool.IdleTimeout);
51-
config.setMaxLifetime(PluginConfig.Database.Settings.Pool.MaxLifetime);
52-
config.setMaximumPoolSize(PluginConfig.Database.Settings.Pool.MaximumPoolSize);
53-
config.setKeepaliveTime(PluginConfig.Database.Settings.Pool.KeepaliveTime);
54-
config.setMinimumIdle(PluginConfig.Database.Settings.Pool.MinimumIdle);
55-
config.addDataSourceProperty("cachePrepStmts", "true" );
56-
config.addDataSourceProperty("prepStmtCacheSize", "250" );
57-
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048" );
45+
try {
46+
HikariConfig config = new HikariConfig();
47+
config.setDriverClassName(driver);
48+
config.setPoolName("MiraiMC-SQLite");
49+
config.setJdbcUrl("jdbc:sqlite:" + new File(PluginConfig.Database.Drivers.SQLite.Path.replace("%plugin_folder%", PluginConfig.PluginDir.toPath().toString())).toPath());
50+
config.setConnectionTimeout(PluginConfig.Database.Settings.Pool.ConnectionTimeout);
51+
config.setIdleTimeout(PluginConfig.Database.Settings.Pool.IdleTimeout);
52+
config.setMaxLifetime(PluginConfig.Database.Settings.Pool.MaxLifetime);
53+
config.setMaximumPoolSize(PluginConfig.Database.Settings.Pool.MaximumPoolSize);
54+
config.setKeepaliveTime(PluginConfig.Database.Settings.Pool.KeepaliveTime);
55+
config.setMinimumIdle(PluginConfig.Database.Settings.Pool.MinimumIdle);
56+
config.addDataSourceProperty("cachePrepStmts", "true");
57+
config.addDataSourceProperty("prepStmtCacheSize", "250");
58+
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
5859

59-
ds = new HikariDataSource(config);
60+
ds = new HikariDataSource(config);
61+
} catch (AbstractMethodError error){
62+
Utils.resolveException(error, Utils.getLogger(), "发生了一个意料之中的问题,请查阅文档了解更多信息:https://docs.miraimc.dreamvoid.me/troubleshoot/faq");
63+
}
6064
}
6165

6266
@Override

0 commit comments

Comments
 (0)