main
黄海 9 months ago
parent 691c5b15b5
commit 027c12d130

@ -104,38 +104,16 @@ public class BaseApplication extends JFinalConfig {
}
/**
*
*/
private String connectionTestQuery = "select 1";
// 连接池中允许的最大连接数。缺省值10推荐的公式((core_count * 2) + effective_spindle_count)
private int maxPoolSize = 10;
// 一个连接 idle 状态的最大时长(毫秒),超时则被释放(retired),缺省:10分钟
private long idleTimeoutMs = 600000;
private long maxLifetimeMs = 1800000;
// 等待连接池分配连接的最大时长(毫秒),超过这个时长还没可用的连接则发生 SQLException 缺省:30秒
private long connectionTimeoutMs = 30000;
@SneakyThrows
@Override
public void configPlugin(Plugins me) {
HikariCpPlugin masterPlugin = new HikariCpPlugin(PropKit.get("mysql.jdbcUrl"), PropKit.get("mysql.user"),
PropKit.get("mysql.password").trim(), PropKit.get("mysql.driverClassName"));
masterPlugin.setConnectionTestQuery(connectionTestQuery);
masterPlugin.setConnectionTimeout(connectionTimeoutMs);
masterPlugin.setIdleTimeout(idleTimeoutMs);
masterPlugin.setMaxLifetime(maxLifetimeMs);
masterPlugin.setMaximumPoolSize(maxPoolSize);
String jdbcUrlSlave = PropKit.get("mysql.jdbcUrlSlave");
if (StrKit.isBlank(jdbcUrlSlave)) jdbcUrlSlave = PropKit.get("mysql.jdbcUrl");
HikariCpPlugin slavePlugin = new HikariCpPlugin(jdbcUrlSlave, PropKit.get("mysql.user"),
PropKit.get("mysql.password").trim(), PropKit.get("mysql.driverClassName"));
slavePlugin.setConnectionTestQuery(connectionTestQuery);
slavePlugin.setConnectionTimeout(connectionTimeoutMs);
slavePlugin.setIdleTimeout(idleTimeoutMs);
slavePlugin.setMaxLifetime(maxLifetimeMs);
slavePlugin.setMaximumPoolSize(maxPoolSize);
me.add(masterPlugin);
me.add(slavePlugin);

@ -16,8 +16,11 @@ import org.slf4j.LoggerFactory;
import java.io.*;
import java.net.JarURLConnection;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.security.CodeSource;
import java.security.ProtectionDomain;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
@ -57,25 +60,32 @@ public class CommonUtil {
return IoUtil.read(is, "UTF-8");
}
/**
* sqllist
*
* @return
*/
public static List<String> getAllSql() throws IOException {
public static List<String> getAllSql() throws IOException, URISyntaxException {
List<String> list = new ArrayList<>();
if (isRunInJar()) {
URL url = CommonUtil.class.getClassLoader().getResource("Sql/");
String jarPath = url.toString().substring(0, url.toString().indexOf("!/") + 2);
URL jarURL = new URL(jarPath);
JarURLConnection jarCon = (JarURLConnection) jarURL.openConnection();
JarFile jarFile = jarCon.getJarFile();
Enumeration<JarEntry> jarEntrys = jarFile.entries();
while (jarEntrys.hasMoreElements()) {
JarEntry entry = jarEntrys.nextElement();
String name = entry.getName();
if (name.startsWith("Sql/") && !entry.isDirectory()) {
list.add(name);
// 获取当前类的ProtectionDomain
ProtectionDomain domain = CommonUtil.class.getProtectionDomain();
// 获取CodeSource
CodeSource source = domain.getCodeSource();
// 获取Jar文件的URL
URL jarUrl = source.getLocation();
// 获取Jar文件的路径
String jarPath = jarUrl.toURI().getSchemeSpecificPart();
// 打开Jar文件
JarFile jarFile = new JarFile(jarPath);
// 遍历Jar中的所有条目
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
// 检查条目是否是SQL文件
if (entry.getName().startsWith("Sql/") && entry.getName().toLowerCase().endsWith(".sql")) {
list.add(entry.getName());
}
}
} else {//如果运行在文件系统中直接加载sql文件

@ -10,7 +10,7 @@ mysql:
driverClassName: com.mysql.cj.jdbc.Driver
user: ylt
password: Ycharge666
jdbcUrl : jdbc:mysql://rm-bp1ux6tuk49er80t9.mysql.rds.aliyuncs.com:3306/ds_db?useUnicode=true&characterEncoding=UTF-8
jdbcUrl : jdbc:mysql://rm-bp1ux6tuk49er80t9.mysql.rds.aliyuncs.com:3306/ds_db?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&failOverReadOnly=false
redis:

@ -10,7 +10,7 @@ mysql:
driverClassName: com.mysql.cj.jdbc.Driver
user: root
password: DsideaL147258369
jdbcUrl : jdbc:mysql://10.10.14.210:22066/ds_db?rewriteBatchedStatements=true&useUnicode=true&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
jdbcUrl : jdbc:mysql://10.10.14.210:22066/ds_db?rewriteBatchedStatements=true&useUnicode=true&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&failOverReadOnly=false
redis:

@ -10,7 +10,7 @@ mysql:
driverClassName: com.mysql.cj.jdbc.Driver
user: ylt
password: Ycharge666
jdbcUrl : jdbc:mysql://rm-bp1ux6tuk49er80t9.mysql.rds.aliyuncs.com:3306/ds_db?useUnicode=true&characterEncoding=UTF-8
jdbcUrl : jdbc:mysql://rm-bp1ux6tuk49er80t9.mysql.rds.aliyuncs.com:3306/ds_db?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&failOverReadOnly=false
redis:

Loading…
Cancel
Save