Skip to content

Commit

Permalink
fix: 测试数据源连接不使用缓存,解决WeiYe-Jing#664
Browse files Browse the repository at this point in the history
  • Loading branch information
listenabe committed Jun 2, 2024
1 parent f0aac36 commit 5242638
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ public class JobDatasource extends Model<JobDatasource> {
*/
@ApiModelProperty(value = "数据库名", hidden = true)
private String databaseName;

@TableField(exist = false)
private Boolean isCache = true;
/**
* 获取主键值
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class JobDatasourceServiceImpl extends ServiceImpl<JobDatasourceMapper, J

@Override
public Boolean dataSourceTest(JobDatasource jobDatasource) throws IOException {
// 测试连接的时候不使用缓存, 否则名称相同时, 获取的是缓存中的连接
jobDatasource.setIsCache(Boolean.FALSE);
if (JdbcConstants.HBASE.equals(jobDatasource.getDatasource())) {
return new HBaseQueryTool(jobDatasource).dataSourceTest();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.wugui.datax.admin.util.JdbcUtils;
import com.zaxxer.hikari.HikariDataSource;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -57,7 +58,7 @@ public abstract class BaseQueryTool implements QueryToolInterface {
* @param jobDatasource
*/
BaseQueryTool(JobDatasource jobDatasource) throws SQLException {
if (LocalCacheUtil.get(jobDatasource.getDatasourceName()) == null) {
if (LocalCacheUtil.get(jobDatasource.getDatasourceName()) == null || BooleanUtils.isNotTrue(jobDatasource.getIsCache())) {
getDataSource(jobDatasource);
} else {
this.connection = (Connection) LocalCacheUtil.get(jobDatasource.getDatasourceName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.wugui.datatx.core.util.Constants;
import com.wugui.datax.admin.core.util.LocalCacheUtil;
import com.wugui.datax.admin.entity.JobDatasource;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.client.*;
Expand All @@ -25,7 +26,7 @@ public class HBaseQueryTool {
private Table table;

public HBaseQueryTool(JobDatasource jobDatasource) throws IOException {
if (LocalCacheUtil.get(jobDatasource.getDatasourceName()) == null) {
if (LocalCacheUtil.get(jobDatasource.getDatasourceName()) == null || BooleanUtils.isNotTrue(jobDatasource.getIsCache())) {
getDataSource(jobDatasource);
} else {
connection = (Connection) LocalCacheUtil.get(jobDatasource.getDatasourceName());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
package com.wugui.datax.admin.tool.query;

import com.google.common.collect.Lists;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;
import com.mongodb.MongoCredential;
import com.wugui.datax.admin.core.util.LocalCacheUtil;
import com.wugui.datax.admin.entity.JobDatasource;
import com.wugui.datax.admin.tool.database.ColumnInfo;
import com.wugui.datax.admin.util.JdbcUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.BooleanUtils;

import java.io.IOException;
import java.sql.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
Expand All @@ -32,7 +26,8 @@ public class Hbase20XsqlQueryTool extends BaseQueryTool implements QueryToolInte
public Hbase20XsqlQueryTool(JobDatasource jobJdbcDatasource) throws SQLException {
super(jobJdbcDatasource);

if (LocalCacheUtil.get(jobJdbcDatasource.getDatasourceName()) == null) {
if (LocalCacheUtil.get(jobJdbcDatasource.getDatasourceName()) == null
|| BooleanUtils.isNotTrue(jobJdbcDatasource.getIsCache())) {
getDataSource(jobJdbcDatasource);
} else {
conn = (Connection) LocalCacheUtil.get(jobJdbcDatasource.getDatasourceName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.mongodb.client.MongoIterable;
import com.wugui.datax.admin.core.util.LocalCacheUtil;
import com.wugui.datax.admin.entity.JobDatasource;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.bson.Document;

Expand All @@ -25,7 +26,7 @@ public class MongoDBQueryTool {


public MongoDBQueryTool(JobDatasource jobDatasource) throws IOException {
if (LocalCacheUtil.get(jobDatasource.getDatasourceName()) == null) {
if (LocalCacheUtil.get(jobDatasource.getDatasourceName()) == null || BooleanUtils.isNotTrue(jobDatasource.getIsCache())) {
getDataSource(jobDatasource);
} else {
connection = (MongoClient) LocalCacheUtil.get(jobDatasource.getDatasourceName());
Expand Down

0 comments on commit 5242638

Please sign in to comment.