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

[Refactor][Connector] Refactor DataSource Client #318

Merged
merged 2 commits into from
Dec 18, 2023
Merged
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
1 change: 0 additions & 1 deletion datavines-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package io.datavines.connector.api;

import io.datavines.common.datasource.jdbc.BaseJdbcDataSourceInfo;
import io.datavines.common.exception.DataVinesException;
import org.slf4j.Logger;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;
Expand All @@ -37,6 +39,8 @@ public interface DataSourceClient {

Connection getConnection(Map<String,Object> configMap) throws SQLException;

Connection getConnection(Map<String,Object> configMap, Logger logger) throws DataVinesException;

Connection getConnection(Properties properties) throws SQLException;

JdbcTemplate getJdbcTemplate(BaseJdbcDataSourceInfo baseJdbcDataSourceInfo) throws SQLException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@

import io.datavines.common.datasource.jdbc.BaseJdbcDataSourceInfo;
import io.datavines.common.datasource.jdbc.JdbcConnectionInfo;
import io.datavines.connector.api.DataSourceClient;

public class ClickHouseConnector extends JdbcConnector {

public ClickHouseConnector(DataSourceClient dataSourceClient) {
super(dataSourceClient);
}
@Override
public BaseJdbcDataSourceInfo getDatasourceInfo(JdbcConnectionInfo jdbcConnectionInfo) {
return new ClickHouseDataSourceInfo(jdbcConnectionInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public Dialect getDialect() {

@Override
public Connector getConnector() {
return new ClickHouseConnector();
return new ClickHouseConnector(getDataSourceClient());
}

@Override
public Executor getExecutor() {
return new ClickHouseExecutor(new JdbcDataSourceClient());
return new ClickHouseExecutor(getDataSourceClient());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

import io.datavines.common.datasource.jdbc.BaseJdbcDataSourceInfo;
import io.datavines.common.datasource.jdbc.JdbcConnectionInfo;
import io.datavines.connector.api.DataSourceClient;

public class ClickHouseExecutor extends BaseJdbcExecutor {

public ClickHouseExecutor(JdbcDataSourceClient jdbcDataSourceClient) {
public ClickHouseExecutor(DataSourceClient jdbcDataSourceClient) {
super(jdbcDataSourceClient);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.datavines.common.param.TestConnectionRequestParam;
import io.datavines.common.utils.JSONUtils;
import io.datavines.common.utils.StringUtils;
import io.datavines.connector.api.DataSourceClient;

import java.sql.*;

Expand All @@ -31,6 +32,10 @@ public class DatabendConnector extends JdbcConnector {

protected static final String[] TABLE_TYPES = new String[]{TABLE};

public DatabendConnector(DataSourceClient dataSourceClient) {
super(dataSourceClient);
}

@Override
public ResultSet getMetadataTables(DatabaseMetaData metaData, String catalog, String schema) throws SQLException {
return metaData.getTables(catalog, schema, null, TABLE_TYPES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public ConnectorParameterConverter getConnectorParameterConverter() {

@Override
public Connector getConnector() {
return new DatabendConnector();
return new DatabendConnector(getDataSourceClient());
}

@Override
Expand All @@ -37,7 +37,7 @@ public Dialect getDialect() {

@Override
public Executor getExecutor() {
return new DatabendExecutor(new JdbcDataSourceClient());
return new DatabendExecutor(getDataSourceClient());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

import io.datavines.common.datasource.jdbc.BaseJdbcDataSourceInfo;
import io.datavines.common.datasource.jdbc.JdbcConnectionInfo;
import io.datavines.connector.api.DataSourceClient;

public class DatabendExecutor extends BaseJdbcExecutor {

public DatabendExecutor(JdbcDataSourceClient jdbcDataSourceClient) {
public DatabendExecutor(DataSourceClient jdbcDataSourceClient) {
super(jdbcDataSourceClient);
}
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,19 @@

import io.datavines.common.datasource.jdbc.BaseJdbcDataSourceInfo;
import io.datavines.common.datasource.jdbc.JdbcConnectionInfo;
import io.datavines.connector.api.DataSourceClient;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DmConnector extends JdbcConnector {
public class DmConnector extends JdbcConnector {

public DmConnector(DataSourceClient dataSourceClient) {
super(dataSourceClient);
}

@Override
public BaseJdbcDataSourceInfo getDatasourceInfo(JdbcConnectionInfo jdbcConnectionInfo) {
return new DmDataSourceInfo(jdbcConnectionInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
import io.datavines.connector.api.*;

public class DmConnectorFactory extends AbstractJdbcConnectorFactory {

@Override
public Connector getConnector() {
return new DmConnector();
return new DmConnector(getDataSourceClient());
}

@Override
Expand All @@ -36,7 +37,7 @@ public ConnectorParameterConverter getConnectorParameterConverter() {

@Override
public Executor getExecutor() {
return new DmExecutor(new JdbcDataSourceClient());
return new DmExecutor(getDataSourceClient());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

import io.datavines.common.datasource.jdbc.BaseJdbcDataSourceInfo;
import io.datavines.common.datasource.jdbc.JdbcConnectionInfo;
import io.datavines.connector.api.DataSourceClient;

public class DmExecutor extends BaseJdbcExecutor{

public DmExecutor(JdbcDataSourceClient jdbcDataSourceClient) {
public DmExecutor(DataSourceClient jdbcDataSourceClient) {
super(jdbcDataSourceClient);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
*/
package io.datavines.connector.plugin;

import io.datavines.connector.api.DataSourceClient;

public class DorisConnector extends MysqlConnector {

public DorisConnector(DataSourceClient dataSourceClient) {
super(dataSourceClient);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ public Dialect getDialect() {

@Override
public Connector getConnector() {
return new DorisConnector();
return new DorisConnector(getDataSourceClient());
}

@Override
public Executor getExecutor() {
return new DorisExecutor(new JdbcDataSourceClient());
return new DorisExecutor(getDataSourceClient());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@

import io.datavines.common.datasource.jdbc.BaseJdbcDataSourceInfo;
import io.datavines.common.datasource.jdbc.JdbcConnectionInfo;
import io.datavines.connector.api.DataSourceClient;

public class DorisExecutor extends MysqlExecutor {

public DorisExecutor(JdbcDataSourceClient jdbcDataSourceClient) {
super(jdbcDataSourceClient);
public DorisExecutor(DataSourceClient dataSourceClient) {
super(dataSourceClient);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@

import io.datavines.common.datasource.jdbc.BaseJdbcDataSourceInfo;
import io.datavines.common.datasource.jdbc.JdbcConnectionInfo;
import io.datavines.common.param.form.type.InputParam;
import io.datavines.connector.api.DataSourceClient;

import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;

public class HiveConnector extends JdbcConnector {

public HiveConnector(DataSourceClient dataSourceClient) {
super(dataSourceClient);
}

@Override
public BaseJdbcDataSourceInfo getDatasourceInfo(JdbcConnectionInfo jdbcConnectionInfo) {
return new HiveDataSourceInfo(jdbcConnectionInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ public Dialect getDialect() {

@Override
public Connector getConnector() {
return new HiveConnector();
return new HiveConnector(getDataSourceClient());
}

@Override
public Executor getExecutor() {
return new HiveExecutor(new JdbcDataSourceClient());
return new HiveExecutor(getDataSourceClient());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
import io.datavines.common.datasource.jdbc.JdbcConnectionInfo;
import io.datavines.common.datasource.jdbc.utils.HiveSqlUtils;
import io.datavines.common.entity.ListWithQueryColumn;
import io.datavines.connector.api.DataSourceClient;
import org.springframework.jdbc.core.JdbcTemplate;

public class HiveExecutor extends BaseJdbcExecutor {

public HiveExecutor(JdbcDataSourceClient jdbcDataSourceClient) {
super(jdbcDataSourceClient);
public HiveExecutor(DataSourceClient dataSourceClient) {
super(dataSourceClient);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@

import io.datavines.common.datasource.jdbc.BaseJdbcDataSourceInfo;
import io.datavines.common.datasource.jdbc.JdbcConnectionInfo;
import io.datavines.connector.api.DataSourceClient;

public class ImpalaConnector extends JdbcConnector {

public ImpalaConnector(DataSourceClient dataSourceClient) {
super(dataSourceClient);
}

@Override
public BaseJdbcDataSourceInfo getDatasourceInfo(JdbcConnectionInfo jdbcConnectionInfo) {
return new ImpalaDataSourceInfo(jdbcConnectionInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public Dialect getDialect() {

@Override
public Connector getConnector() {
return new ImpalaConnector();
return new ImpalaConnector(getDataSourceClient());
}

@Override
public Executor getExecutor() {
return new ImpalaExecutor(new JdbcDataSourceClient());
return new ImpalaExecutor(getDataSourceClient());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@

import io.datavines.common.datasource.jdbc.BaseJdbcDataSourceInfo;
import io.datavines.common.datasource.jdbc.JdbcConnectionInfo;
import io.datavines.connector.api.DataSourceClient;

public class ImpalaExecutor extends BaseJdbcExecutor {

public ImpalaExecutor(JdbcDataSourceClient jdbcDataSourceClient) {
super(jdbcDataSourceClient);
public ImpalaExecutor(DataSourceClient dataSourceClient) {
super(dataSourceClient);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.datavines.common.param.ConnectorResponse;
import io.datavines.common.param.ExecuteRequestParam;
import io.datavines.common.utils.JSONUtils;
import io.datavines.connector.api.DataSourceClient;
import io.datavines.connector.api.Executor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.core.JdbcTemplate;
Expand All @@ -30,10 +31,10 @@

public abstract class BaseJdbcExecutor implements Executor, IJdbcDataSourceInfo {

private final JdbcDataSourceClient jdbcDataSourceClient;
private final DataSourceClient dataSourceClient;

public BaseJdbcExecutor(JdbcDataSourceClient jdbcDataSourceClient) {
this.jdbcDataSourceClient = jdbcDataSourceClient;
public BaseJdbcExecutor(DataSourceClient dataSourceClient) {
this.dataSourceClient = dataSourceClient;
}

protected ListWithQueryColumn query(JdbcTemplate jdbcTemplate, String sql, int limit) {
Expand All @@ -47,7 +48,7 @@ public ConnectorResponse queryForPage(ExecuteRequestParam param) throws SQLExcep

JdbcConnectionInfo jdbcConnectionInfo = JSONUtils.parseObject(dataSourceParam, JdbcConnectionInfo.class);

JdbcTemplate jdbcTemplate = jdbcDataSourceClient.getJdbcTemplate(
JdbcTemplate jdbcTemplate = dataSourceClient.getJdbcTemplate(
JdbcDataSourceInfoManager.getDatasourceInfo(dataSourceParam, getDatasourceInfo(jdbcConnectionInfo)));

String sql = param.getScript();
Expand All @@ -68,7 +69,7 @@ public ConnectorResponse queryForOne(ExecuteRequestParam param) throws SQLExcept
String dataSourceParam = param.getDataSourceParam();

JdbcConnectionInfo jdbcConnectionInfo = JSONUtils.parseObject(dataSourceParam, JdbcConnectionInfo.class);
JdbcTemplate jdbcTemplate = jdbcDataSourceClient.getJdbcTemplate(
JdbcTemplate jdbcTemplate = dataSourceClient.getJdbcTemplate(
JdbcDataSourceInfoManager.getDatasourceInfo(dataSourceParam, getDatasourceInfo(jdbcConnectionInfo)));

String sql = param.getScript() + " limit 1";
Expand All @@ -89,7 +90,7 @@ public ConnectorResponse queryForList(ExecuteRequestParam param) throws Exceptio
String dataSourceParam = param.getDataSourceParam();
JdbcConnectionInfo jdbcConnectionInfo = JSONUtils.parseObject(dataSourceParam, JdbcConnectionInfo.class);

JdbcTemplate jdbcTemplate = jdbcDataSourceClient.getJdbcTemplate(
JdbcTemplate jdbcTemplate = dataSourceClient.getJdbcTemplate(
JdbcDataSourceInfoManager.getDatasourceInfo(dataSourceParam, getDatasourceInfo(jdbcConnectionInfo)));

String sql = param.getScript();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ protected InputParam getSchemaInput(boolean isEn) {
protected InputParam getDatabaseInput(boolean isEn) {
return getInputParam("database",
isEn ? "database" : "数据库",
isEn ? "please enter database" : "请填入数据库", 1,
Validate.newBuilder().setRequired(true).setMessage(isEn ? "please enter database" : "请填入数据库").build(),
isEn ? "please enter database" : "请填入数据库", 1, null,
null);
}

Expand Down
Loading
Loading