TabooLib v4.6-R4

+ SQL update.
This commit is contained in:
坏黑 2018-11-03 23:02:20 +08:00
parent 9ae4c0701e
commit 271f1b56b0
4 changed files with 65 additions and 45 deletions

View File

@ -38,6 +38,7 @@ public class TabooLibLoader implements Listener {
static TabooLibDeprecated tabooLibDeprecated;
static Map<String, List<Class>> pluginClasses = Maps.newHashMap();
static List<Loader> loaders = Lists.newArrayList();
static List<Runnable> tasks = Lists.newArrayList();
static void setup() {
testInternet();
@ -56,6 +57,15 @@ public class TabooLibLoader implements Listener {
} catch (Exception e) {
e.printStackTrace();
}
Bukkit.getScheduler().runTask(TabooLib.instance(), () -> {
for (Runnable task : tasks) {
try {
task.run();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
static void unregister() {
@ -80,6 +90,10 @@ public class TabooLibLoader implements Listener {
return classes == null ? new ArrayList<>() : new ArrayList<>(classes);
}
public static void runTaskOnEnabled(Runnable runnable) {
tasks.add(runnable);
}
static boolean isLoader(Class pluginClass) {
return !Loader.class.equals(pluginClass) && Loader.class.isAssignableFrom(pluginClass);
}

View File

@ -1,10 +1,13 @@
package me.skymc.taboolib.mysql.builder;
import com.ilummc.tlib.util.Strings;
import me.skymc.taboolib.string.ArrayUtils;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.plugin.Plugin;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* @Author sky
@ -19,6 +22,7 @@ public class SQLHost {
private String database;
private Plugin plugin;
private boolean autoClose;
private List<String> flags = ArrayUtils.asList("characterEncoding=utf-8", "useSSL=false");
public SQLHost(ConfigurationSection section, Plugin plugin) {
this(section, plugin, false);
@ -70,14 +74,26 @@ public class SQLHost {
return autoClose;
}
public List<String> getFlags() {
return flags;
}
public String getConnectionUrl() {
return Strings.replaceWithOrder("jdbc:mysql://{0}:{1}/{2}?characterEncoding=utf-8&useSSL=false", this.host, this.port, this.database);
return Strings.replaceWithOrder("jdbc:mysql://{0}:{1}/{2}" + getFlagsInUrl(), this.host, this.port, this.database);
}
public String getConnectionUrlSimple() {
return Strings.replaceWithOrder("jdbc:mysql://{0}:{1}/{2}", this.host, this.port, this.database);
}
public String getFlagsInUrl() {
if (flags.isEmpty()) {
return "";
}
String collect = flags.stream().map(f -> f + "&").collect(Collectors.joining());
return "?" + collect.substring(0, collect.length() - 1);
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@ -64,28 +64,18 @@ public class HikariHandler {
config.setJdbcUrl(sqlHost.getConnectionUrl());
config.setUsername(sqlHost.getUser());
config.setPassword(sqlHost.getPassword());
config.setConnectionTestQuery("SELECT 1");
config.setAutoCommit(settings.getBoolean("DefaultSettings.AutoCommit", true));
config.setMinimumIdle(settings.getInt("DefaultSettings.MinimumIdle", 1));
config.setMinimumIdle(settings.getInt("DefaultSettings.MinimumIdle", -1));
config.setMaximumPoolSize(settings.getInt("DefaultSettings.MaximumPoolSize", 10));
config.setValidationTimeout(settings.getInt("DefaultSettings.ValidationTimeout", 3000));
config.setConnectionTimeout(settings.getInt("DefaultSettings.ConnectionTimeout", 10000));
config.setIdleTimeout(settings.getInt("DefaultSettings.IdleTimeout", 60000));
config.setMaxLifetime(settings.getInt("DefaultSettings.MaxLifetime", 60000));
config.setValidationTimeout(settings.getInt("DefaultSettings.ValidationTimeout", 5000));
config.setConnectionTimeout(settings.getInt("DefaultSettings.ConnectionTimeout", 30000));
config.setIdleTimeout(settings.getInt("DefaultSettings.IdleTimeout", 600000));
config.setMaxLifetime(settings.getInt("DefaultSettings.MaxLifetime", 1800000));
if (settings.contains("DefaultSettings.ConnectionTestQuery")) {
config.setConnectionTestQuery(settings.getString("DefaultSettings.ConnectionTestQuery"));
}
if (settings.contains("DefaultSettings.DataSourceProperty")) {
settings.getConfigurationSection("DefaultSettings.DataSourceProperty").getKeys(false).forEach(key -> config.addDataSourceProperty(key, settings.getString("DefaultSettings.DataSourceProperty." + key)));
} else {
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
config.addDataSourceProperty("useServerPrepStmts", "true");
config.addDataSourceProperty("useLocalSessionState", "true");
config.addDataSourceProperty("useLocalTransactionState", "true");
config.addDataSourceProperty("rewriteBatchedStatements", "true");
config.addDataSourceProperty("cacheResultSetMetadata", "true");
config.addDataSourceProperty("cacheServerConfiguration", "true");
config.addDataSourceProperty("elideSetAutoCommits", "true");
config.addDataSourceProperty("maintainTimeStats", "false");
}
return config;
}

View File

@ -1,32 +1,32 @@
# 默认连接池配置
DefaultSettings:
DriverClassName: 'com.mysql.jdbc.Driver'
# 自动提交从池中返回的连接
AutoCommit: true
# 池中维护的最小空闲连接数
MinimumIdle: 1
# 连接池大小
# 池中最大连接数,包括闲置和使用中的连接
MaximumPoolSize: 10
# 用来指定验证连接有效性的超时时间(毫秒/默认: 5秒
ValidationTimeout: 3000
# 等待连接池分配连接的最大时长(毫秒/默认: 30秒
# 超过这个时长还没可用的连接则发生 SQLException
ConnectionTimeout: 10000
# 一个连接idle状态的最大时长毫秒/默认: 10分钟超时则被释放
IdleTimeout: 60000
# 一个连接的生命时长(毫秒/默认: 30分钟超时而且没被使用则被释放
MaxLifetime: 60000
# 是否自定义配置为true时下面两个参数才生效
DataSourceProperty:
cachePrepStmts: true
# 连接池大小默认25官方推荐250-500
prepStmtCacheSize: 250
# 单条语句最大长度默认256官方推荐2048
prepStmtCacheSqlLimit: 2048
# 新版本MySQL支持服务器端准备开启能够得到显著性能提升
useServerPrepStmts: true
useLocalSessionState: true
useLocalTransactionState: true
rewriteBatchedStatements: true
cacheResultSetMetadata: true
cacheServerConfiguration: true
elideSetAutoCommits: true
maintainTimeStats: false
# 用来指定验证连接有效性的超时时间
ValidationTimeout: 5000
# 等待来自池的连接的最大毫秒数
ConnectionTimeout: 30000
# 一个连接idle状态的最大时长超时则被释放
IdleTimeout: 600000
# 一个连接的生命时长,超时而且没被使用则被释放
MaxLifetime: 1800000
# 如果您的驱动程序支持JDBC4我们强烈建议您不要设置此属性
ConnectionTestQuery: SELECT 1
# 其他自定义配置
DataSourceProperty: {}
# cachePrepStmts: true
# prepStmtCacheSize: 250
# prepStmtCacheSqlLimit: 2048
# useServerPrepStmts: true
# useLocalSessionState: true
# useLocalTransactionState: true
# rewriteBatchedStatements: true
# cacheResultSetMetadata: true
# cacheServerConfiguration: true
# elideSetAutoCommits: true
# maintainTimeStats: false