update pool

Raod 3 years ago
parent 01923ae1f4
commit 976539bd5c

@ -1,28 +0,0 @@
package com.anjiplus.template.gaea.business.modules.dataSource.pool.exception;
/**
* @author binbin.hou
* @since 1.0.0
*/
public class JdbcPoolException extends RuntimeException {
public JdbcPoolException() {
}
public JdbcPoolException(String message) {
super(message);
}
public JdbcPoolException(String message, Throwable cause) {
super(message, cause);
}
public JdbcPoolException(Throwable cause) {
super(cause);
}
public JdbcPoolException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}

@ -16,9 +16,9 @@ import com.anjiplus.template.gaea.business.modules.dataSource.controller.dto.Dat
import com.anjiplus.template.gaea.business.modules.dataSource.controller.param.ConnectionParam; import com.anjiplus.template.gaea.business.modules.dataSource.controller.param.ConnectionParam;
import com.anjiplus.template.gaea.business.modules.dataSource.dao.DataSourceMapper; import com.anjiplus.template.gaea.business.modules.dataSource.dao.DataSourceMapper;
import com.anjiplus.template.gaea.business.modules.dataSource.dao.entity.DataSource; import com.anjiplus.template.gaea.business.modules.dataSource.dao.entity.DataSource;
import com.anjiplus.template.gaea.business.modules.dataSource.pool.constant.JdbcConstants; import com.anjiplus.template.gaea.business.util.JdbcConstants;
import com.anjiplus.template.gaea.business.modules.dataSource.pool.util.JdbcUtil;
import com.anjiplus.template.gaea.business.modules.dataSource.service.DataSourceService; import com.anjiplus.template.gaea.business.modules.dataSource.service.DataSourceService;
import com.anjiplus.template.gaea.business.util.JdbcUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;

@ -1,4 +1,4 @@
package com.anjiplus.template.gaea.business.modules.dataSource.pool.util; package com.anjiplus.template.gaea.business.util;
import com.anji.plus.gaea.exception.BusinessExceptionBuilder; import com.anji.plus.gaea.exception.BusinessExceptionBuilder;
import com.anjiplus.template.gaea.business.code.ResponseCode; import com.anjiplus.template.gaea.business.code.ResponseCode;

@ -1,9 +1,22 @@
package com.anjiplus.template.gaea.business.modules.dataSource.pool.constant; package com.anjiplus.template.gaea.business.util;
/** /**
* Created by raodeming on 2021/3/19. * Created by raodeming on 2021/3/19.
*/ */
public class JdbcConstants { public class JdbcConstants {
/**
*
*/
public final static String KUDU_IMAPLA = "kudu_impala";
public final static String HTTP = "http";
public final static String MYSQL = "mysql";
public final static String ORACLE = "oracle";
public final static String ELASTIC_SEARCH_SQL = "elasticsearch_sql";
public final static String JTDS = "jtds"; public final static String JTDS = "jtds";
public final static String MOCK = "mock"; public final static String MOCK = "mock";
public final static String HSQL = "hsql"; public final static String HSQL = "hsql";
@ -16,12 +29,10 @@ public class JdbcConstants {
public final static String SQL_SERVER_DRIVER = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; public final static String SQL_SERVER_DRIVER = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
public final static String SQL_SERVER_DRIVER_SQLJDBC4 = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; public final static String SQL_SERVER_DRIVER_SQLJDBC4 = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
public final static String SQL_SERVER_DRIVER_JTDS = "net.sourceforge.jtds.jdbc.Driver"; public final static String SQL_SERVER_DRIVER_JTDS = "net.sourceforge.jtds.jdbc.Driver";
public final static String ORACLE = "oracle";
public final static String ORACLE_DRIVER = "oracle.jdbc.OracleDriver"; public final static String ORACLE_DRIVER = "oracle.jdbc.OracleDriver";
public final static String ORACLE_DRIVER2 = "oracle.jdbc.driver.OracleDriver"; public final static String ORACLE_DRIVER2 = "oracle.jdbc.driver.OracleDriver";
public final static String ALI_ORACLE = "AliOracle"; public final static String ALI_ORACLE = "AliOracle";
public final static String ALI_ORACLE_DRIVER = "com.alibaba.jdbc.AlibabaDriver"; public final static String ALI_ORACLE_DRIVER = "com.alibaba.jdbc.AlibabaDriver";
public final static String MYSQL = "mysql";
public final static String MYSQL_DRIVER = "com.mysql.jdbc.Driver"; public final static String MYSQL_DRIVER = "com.mysql.jdbc.Driver";
public final static String MYSQL_DRIVER_6 = "com.mysql.cj.jdbc.Driver"; public final static String MYSQL_DRIVER_6 = "com.mysql.cj.jdbc.Driver";
public final static String MYSQL_DRIVER_REPLICATE = "com.mysql.jdbc."; public final static String MYSQL_DRIVER_REPLICATE = "com.mysql.jdbc.";
@ -62,10 +73,8 @@ public class JdbcConstants {
public final static String ALIYUN_DRDS = "aliyun_drds"; public final static String ALIYUN_DRDS = "aliyun_drds";
public final static String PRESTO = "presto"; public final static String PRESTO = "presto";
public final static String ELASTIC_SEARCH = "elasticsearch"; public final static String ELASTIC_SEARCH = "elasticsearch";
public final static String ELASTIC_SEARCH_SQL = "elasticsearch_sql";
public final static String ELASTIC_SEARCH_DRIVER = "com.alibaba.xdriver.elastic.jdbc.ElasticDriver"; public final static String ELASTIC_SEARCH_DRIVER = "com.alibaba.xdriver.elastic.jdbc.ElasticDriver";
public final static String CLICKHOUSE = "clickhouse"; public final static String CLICKHOUSE = "clickhouse";
public final static String CLICKHOUSE_DRIVER = "ru.yandex.clickhouse.ClickHouseDriver"; public final static String CLICKHOUSE_DRIVER = "ru.yandex.clickhouse.ClickHouseDriver";
public final static String KUDU_IMAPLA = "kudu_impala";
public final static String HTTP = "http";
} }

@ -1,18 +1,15 @@
package com.anjiplus.template.gaea.business.modules.dataSource.pool.util; package com.anjiplus.template.gaea.business.util;
import com.alibaba.druid.pool.DruidDataSource; import com.alibaba.druid.pool.DruidDataSource;
import com.anjiplus.template.gaea.business.modules.dataSource.controller.dto.DataSourceDto; import com.anjiplus.template.gaea.business.modules.dataSource.controller.dto.DataSourceDto;
import com.anjiplus.template.gaea.business.modules.dataSource.pool.datasource.PooledDataSource;
import com.anjiplus.template.gaea.business.modules.dataSource.pool.datasource.UnPooledDataSource;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
/** /**
* Created by raodeming on 2021/3/18. * Created by raodeming on 2021/3/18.
@ -20,7 +17,9 @@ import java.util.concurrent.locks.ReentrantLock;
@Slf4j @Slf4j
public class JdbcUtil { public class JdbcUtil {
//所有数据源的连接池存在map里 /**
* map
*/
static Map<Long, DruidDataSource> map = new ConcurrentHashMap<>(); static Map<Long, DruidDataSource> map = new ConcurrentHashMap<>();
public static DruidDataSource getJdbcConnectionPool(DataSourceDto dataSource) { public static DruidDataSource getJdbcConnectionPool(DataSourceDto dataSource) {
@ -55,6 +54,7 @@ public class JdbcUtil {
/** /**
* *
*
* @param id * @param id
*/ */
public static void removeJdbcConnectionPool(Long id) { public static void removeJdbcConnectionPool(Long id) {
@ -72,6 +72,7 @@ public class JdbcUtil {
/** /**
* *
*
* @param dataSource * @param dataSource
* @return * @return
* @throws SQLException * @throws SQLException
@ -83,20 +84,20 @@ public class JdbcUtil {
/** /**
* *
*
* @param dataSource * @param dataSource
* @return * @return
* @throws ClassNotFoundException driverName * @throws ClassNotFoundException driverName
* @throws SQLException * @throws SQLException
*/ */
public static Connection getUnPooledConnection(DataSourceDto dataSource) throws SQLException { public static Connection getUnPooledConnection(DataSourceDto dataSource) throws SQLException {
UnPooledDataSource source = new UnPooledDataSource(); DriverClassUtil.loadDriverClass(dataSource.getDriverName(), dataSource.getJdbcUrl());
source.setJdbcUrl(dataSource.getJdbcUrl()); if (StringUtils.isBlank(dataSource.getUsername()) && StringUtils.isBlank(dataSource.getPassword())) {
source.setDriverClass(dataSource.getDriverName()); return DriverManager.getConnection(dataSource.getJdbcUrl());
source.setUser(dataSource.getUsername()); }
source.setPassword(dataSource.getPassword()); return DriverManager.getConnection(dataSource.getJdbcUrl(),
return source.getConnection(); dataSource.getUsername(), dataSource.getPassword());
} }
} }
Loading…
Cancel
Save