DruidPlugin插件升级(druid1.2.12以上)

数据库插件druid1.2.12版本以上增加了设置超时的参数,DruidPlugin插件需要升级;

druid1.2.12以下版本,查询数据库的读超时时间是永久;druid1.2.12版本以上版本,默认是10秒超时,太短了,执行存储过程很可能异常;

临时解决办法:

import com.jfinal.plugin.druid.DruidPlugin;


/**

 * 支持Druid1.2.12版本以上增加的connectTimeout和socketTimeout配置

 * 

 * @author iPan

 * @date 2023-12-13

 */

public class DruidPlugin_1_2_12 extends DruidPlugin {

// protected Integer connectTimeout = DruidAbstractDataSource.DEFAULT_TIME_CONNECT_TIMEOUT_MILLIS;

// protected Integer socketTimeout = DruidAbstractDataSource.DEFAULT_TIME_SOCKET_TIMEOUT_MILLIS;

protected Integer connectTimeout = null; // 毫秒

protected Integer socketTimeout = null; // 毫秒

protected Integer queryTimeout = null; // 秒

    protected Integer transactionQueryTimeout = null; // 秒

public DruidPlugin_1_2_12(String url, String username, String password) {

super(url, username, password);

}


public DruidPlugin_1_2_12(String url, String username, String password, String driverClass, String filters) {

super(url, username, password, driverClass, filters);

}


public DruidPlugin_1_2_12(String url, String username, String password, String driverClass) {

super(url, username, password, driverClass);

}


public Integer getConnectTimeout() {

return connectTimeout;

}


public void setConnectTimeout(Integer connectTimeout) {

this.connectTimeout = connectTimeout;

}


public Integer getSocketTimeout() {

return socketTimeout;

}


public void setSocketTimeout(Integer socketTimeout) {

this.socketTimeout = socketTimeout;

}

public Integer getQueryTimeout() {

return queryTimeout;

}


public void setQueryTimeout(Integer queryTimeout) {

this.queryTimeout = queryTimeout;

}


public Integer getTransactionQueryTimeout() {

return transactionQueryTimeout;

}


public void setTransactionQueryTimeout(Integer transactionQueryTimeout) {

this.transactionQueryTimeout = transactionQueryTimeout;

}


@Override

public boolean start() {

boolean ret = super.start();

if (ret == false) return false;

// druid1.2.12新增参数

if (connectTimeout != null) {

ds.setConnectTimeout(connectTimeout);

}

if (socketTimeout != null) {

ds.setSocketTimeout(socketTimeout);

}

if (queryTimeout != null) {

ds.setQueryTimeout(queryTimeout);

}

if (transactionQueryTimeout != null) {

ds.setTransactionQueryTimeout(transactionQueryTimeout);

}

return ret;

}

}



评论区

热门分享

扫码入社