Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 测试数据源连接不使用缓存,解决#664 #665

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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