|
|
|
@ -5,11 +5,7 @@ import cn.hutool.core.io.FileUtil;
|
|
|
|
|
import com.dsideal.YunXiaoTools.Controller.DataBaseController;
|
|
|
|
|
import com.jfinal.config.*;
|
|
|
|
|
import com.jfinal.kit.PropKit;
|
|
|
|
|
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
|
|
|
|
|
import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
|
|
|
|
|
import com.jfinal.plugin.activerecord.dialect.PostgreSqlDialect;
|
|
|
|
|
import com.jfinal.plugin.cron4j.Cron4jPlugin;
|
|
|
|
|
import com.jfinal.plugin.hikaricp.HikariCpPlugin;
|
|
|
|
|
import com.jfinal.server.undertow.UndertowServer;
|
|
|
|
|
import com.jfinal.template.Engine;
|
|
|
|
|
import lombok.SneakyThrows;
|
|
|
|
@ -47,59 +43,8 @@ public class Start 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;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void configPlugin(Plugins me) {
|
|
|
|
|
String jdbcUrl, user, password, driverClassName=PropKit.get("driverClassName");
|
|
|
|
|
if (DEPLOY_ID == 1) {
|
|
|
|
|
jdbcUrl = PropKit.get("read.jdbcUrl");
|
|
|
|
|
user = PropKit.get("read.user");
|
|
|
|
|
password = PropKit.get("read.password");
|
|
|
|
|
} else {
|
|
|
|
|
jdbcUrl = PropKit.get("write.jdbcUrl");
|
|
|
|
|
user = PropKit.get("write.user");
|
|
|
|
|
password = PropKit.get("write.password");
|
|
|
|
|
}
|
|
|
|
|
HikariCpPlugin hp = new HikariCpPlugin(jdbcUrl, user, password, driverClassName);
|
|
|
|
|
hp.setConnectionTestQuery(this.connectionTestQuery);
|
|
|
|
|
hp.setConnectionTimeout(this.connectionTimeoutMs);
|
|
|
|
|
hp.setIdleTimeout(this.idleTimeoutMs);
|
|
|
|
|
hp.setMaxLifetime(this.maxLifetimeMs);
|
|
|
|
|
hp.setMaximumPoolSize(this.maxPoolSize);
|
|
|
|
|
me.add(hp);
|
|
|
|
|
|
|
|
|
|
ActiveRecordPlugin arp = new ActiveRecordPlugin(hp);
|
|
|
|
|
if (DEPLOY_ID == 1) {
|
|
|
|
|
arp.setDialect(new MysqlDialect());
|
|
|
|
|
} else {
|
|
|
|
|
arp.setDialect(new PostgreSqlDialect());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String basePath = Start.class.getClassLoader().getResource(".").getPath();
|
|
|
|
|
File sqlDir = new File(basePath + "/Sql");
|
|
|
|
|
File[] sqlFiles = sqlDir.listFiles();
|
|
|
|
|
File[] var10 = sqlFiles != null ? sqlFiles : new File[0];
|
|
|
|
|
int var11 = var10.length;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < var11; ++i) {
|
|
|
|
|
File sqlFile = var10[i];
|
|
|
|
|
if (sqlFile.getName().indexOf(".sql") > 0) {
|
|
|
|
|
arp.addSqlTemplate("/Sql/" + sqlFile.getName());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
me.add(arp);
|
|
|
|
|
|
|
|
|
|
//加载定时器
|
|
|
|
|
me.add(new Cron4jPlugin(PropKit.use("cron4j.properties")));
|
|
|
|
|
}
|
|
|
|
|