diff --git a/dinky-common/src/main/java/org/dinky/data/model/Table.java b/dinky-common/src/main/java/org/dinky/data/model/Table.java
index 1aba079b15..ee47b21189 100644
--- a/dinky-common/src/main/java/org/dinky/data/model/Table.java
+++ b/dinky-common/src/main/java/org/dinky/data/model/Table.java
@@ -25,6 +25,7 @@
import java.beans.Transient;
import java.io.Serializable;
+import java.sql.SQLException;
import java.text.MessageFormat;
import java.util.Date;
import java.util.HashMap;
@@ -56,15 +57,26 @@ public class Table implements Serializable, Comparable
, Cloneable {
private Long rows;
private Date createTime;
private Date updateTime;
- /** 表类型 */
+ /**
+ * 表类型
+ */
private TableType tableType = TableType.SINGLE_DATABASE_AND_TABLE;
- /** 分库或分表对应的表名 */
+ /**
+ * 分库或分表对应的表名
+ */
private List schemaTableNameList;
private List columns;
public Table() {}
+ public Table(List columns, String databaseName, String tableName, String tableComment) throws SQLException {
+ this.name = tableName;
+ this.schema = databaseName;
+ this.comment = tableComment;
+ this.columns = columns;
+ }
+
public Table(String name, String schema, List columns) {
this.name = name;
this.schema = schema;
diff --git a/dinky-metadata/dinky-metadata-base/src/main/java/org/dinky/metadata/driver/AbstractJdbcDriver.java b/dinky-metadata/dinky-metadata-base/src/main/java/org/dinky/metadata/driver/AbstractJdbcDriver.java
index c8f6e62ca3..9b80cdab8f 100644
--- a/dinky-metadata/dinky-metadata-base/src/main/java/org/dinky/metadata/driver/AbstractJdbcDriver.java
+++ b/dinky-metadata/dinky-metadata-base/src/main/java/org/dinky/metadata/driver/AbstractJdbcDriver.java
@@ -41,6 +41,7 @@
import org.dinky.utils.TextUtil;
import java.sql.Connection;
+import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -79,9 +80,8 @@
public abstract class AbstractJdbcDriver extends AbstractDriver {
protected ThreadLocal conn = new ThreadLocal<>();
-
- private DruidDataSource dataSource;
protected String validationQuery = "select 1";
+ private DruidDataSource dataSource;
abstract String getDriverClass();
@@ -292,6 +292,23 @@ public List listTables(String schemaName) {
return tableList;
}
+ @Override
+ public Table getTable(String schemaName, String tableName) {
+ try {
+ DatabaseMetaData metaData = conn.get().getMetaData();
+ ResultSet tables = metaData.getTables(schemaName, null, tableName, new String[] {"TABLE"});
+ while (tables.next()) {
+ String tableComment = tables.getString("REMARKS");
+ List columns = listColumns(schemaName, tableName);
+ return new Table(columns, schemaName, tableName, tableComment);
+ }
+ } catch (SQLException e) {
+ log.error("GetTable error:", e);
+ throw new RuntimeException(e);
+ }
+ return null;
+ }
+
@Override
public List listColumns(String schemaName, String tableName) {
List columns = new ArrayList<>();
@@ -516,8 +533,11 @@ public int executeUpdate(String sql) throws Exception {
}
/**
- * 标准sql where与order语法都是相同的 不同数据库limit语句不一样,需要单独交由driver去处理,例如oracle 通过{@query(String sql,
- * Integer limit)}去截断返回数据,但是在大量数据情况下会导致数据库负载过高。
+ * 标准sql where与order语法都是相同的
+ * 不同数据库limit语句不一样,需要单独交由driver去处理,例如oracle
+ * 通过{@query(String sql,
+ * Integer
+ * limit)}去截断返回数据,但是在大量数据情况下会导致数据库负载过高。
*/
@Override
public StringBuilder genQueryOption(QueryData queryData) {
@@ -614,7 +634,6 @@ public JdbcSelectResult query(String sql, Integer limit) {
/**
* 如果执行多条语句返回最后一条语句执行结果
- *
*/
@Override
public JdbcSelectResult executeSql(String sql, Integer limit) {