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

#359 #360

Closed
wants to merge 2 commits into from
Closed

#359 #360

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 @@ -60,7 +60,7 @@ public JdbcConnector(DataSourceClient dataSourceClient) {
this.dataSourceClient = dataSourceClient;
}

private Connection getConnection(String dataSourceParam, JdbcConnectionInfo jdbcConnectionInfo) throws SQLException {
public final Connection getConnection(String dataSourceParam, JdbcConnectionInfo jdbcConnectionInfo) throws SQLException {
return dataSourceClient.getConnection(JdbcDataSourceInfoManager.getDatasourceInfo(dataSourceParam, getDatasourceInfo(jdbcConnectionInfo)));
}

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

import io.datavines.common.datasource.jdbc.JdbcConnectionInfo;
import io.datavines.common.datasource.jdbc.entity.TableInfo;
import io.datavines.common.datasource.jdbc.utils.JdbcDataSourceUtils;
import io.datavines.common.param.ConnectorResponse;
import io.datavines.common.param.GetTablesRequestParam;
import io.datavines.common.utils.JSONUtils;
import io.datavines.common.utils.StringUtils;
import io.datavines.connector.api.DataSourceClient;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class StarRocksConnector extends MysqlConnector {

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

@Override
public ConnectorResponse getTables(GetTablesRequestParam param) throws SQLException {
ConnectorResponse.ConnectorResponseBuilder builder = ConnectorResponse.builder();
String dataSourceParam = param.getDataSourceParam();

JdbcConnectionInfo jdbcConnectionInfo = JSONUtils.parseObject(dataSourceParam, JdbcConnectionInfo.class);
if (jdbcConnectionInfo == null) {
throw new SQLException("jdbc datasource param is no validate");
}

Connection connection = getConnection(dataSourceParam, jdbcConnectionInfo);

List<TableInfo> tableList = null;
ResultSet tables;

try {
String schema = param.getDataBase();
tableList = new ArrayList<>();
tables = getMetadataTables(connection, schema);

if (null == tables) {
return builder.result(tableList).build();
}

while (tables.next()) {
String name = tables.getString(TABLE_NAME);
if (!StringUtils.isEmpty(name)) {
String type = TABLE;
try {
type = tables.getString(TABLE_TYPE);
} catch (Exception e) {
// ignore
}
tableList.add(new TableInfo(schema, name, type, tables.getString("TABLE_COMMENT")));
}
}

} catch (Exception e) {
logger.error("get table list error: ", e);
} finally {
JdbcDataSourceUtils.releaseConnection(connection);
}

return builder.result(tableList).build();
}

protected ResultSet getMetadataTables(Connection connection, String schema) throws SQLException {
java.sql.Statement stmt = connection.createStatement();
return stmt.executeQuery("select TABLE_NAME, TABLE_TYPE, TABLE_COMMENT from information_schema.tables where TABLE_SCHEMA = '" + schema + "'");
}
}
2 changes: 1 addition & 1 deletion datavines-server/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/datavines?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: 123456
password: admin123
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个地方不要修改原有的password

quartz:
properties:
org.quartz.jobStore.driverDelegateClass: org.quartz.impl.jdbcjobstore.StdJDBCDelegate
Loading