获取Mysql、Oracle、SqlServer 库结构、表结构、表内数据工具类

(Es数据库后续补充、分页根据自身情况实现)


import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONObject;
import diy.application.dto.query.DataSourceQuery;
import diy.application.entity.DataSourceInfo;
import diy.application.entity.DataSourceTableConstruct;
import diy.application.entity.DataTableColumnComments;
import diy.application.mapper.DataSourceColumnCommentsMapper;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.xpack.sql.jdbc.EsDataSource;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.sql.*;
import java.util.*;
import java.util.function.Function;

import static diy.application.utils.Constant.*;



@Component
@Slf4j
public class DataSourceUtil {

    private DataSourceUtil() {
    }

    @Resource
    DataSourceColumnCommentsMapper dataSourceColumnCommentsMapper;

    private static final String TABLE_NAME_STR = "TABLE_NAME";

    private static final String TABLE_CAT_STR = "TABLE_CAT";

    private static final String TOTAL_STR = "total";


    public List<String> getSchemas(DataSourceInfo dataSourceInfo) throws SQLException {
        String dataSourceType = dataSourceInfo.getType();

        // JDBC类型
        if (DATA_SOURCE_JDBC.equalsIgnoreCase(dataSourceType)) {
            return getRDBSConnection(dataSourceInfo, null, null).getSchemas();
        }
        // ES类型
        else if (DATA_SOURCE_ES.equalsIgnoreCase(dataSourceType)) {
            return getEsSchemas(getEsConnection(dataSourceInfo));
        }

        return Collections.emptyList();
    }

    public List<String> getTables(DataSourceInfo dataSourceInfo, String schemaName) throws SQLException {
        String dataSourceType = dataSourceInfo.getType();

        // JDBC类型
        if (DATA_SOURCE_JDBC.equalsIgnoreCase(dataSourceType)) {
            return getRDBSConnection(dataSourceInfo, schemaName, null).getTables();
        }
        // ES类型
        else if (DATA_SOURCE_ES.equalsIgnoreCase(dataSourceType)) {
            Connection esConnection = getEsConnection(dataSourceInfo);
            return getEsSchemas(esConnection);
        }

        return Collections.emptyList();
    }

    public List<DataSourceTableConstruct> getTableConstruct(DataSourceInfo dataSourceInfo, String schemaName, String tableName) throws SQLException {
        String dataSourceType = dataSourceInfo.getType();

        // JDBC类型
        if (DATA_SOURCE_JDBC.equalsIgnoreCase(dataSourceType)) {
            List<DataSourceTableConstruct> dataSourceTableConstructList = getRDBSConnection(dataSourceInfo, schemaName, tableName).getTableConstruct();
            return refreshColumnComments(dataSourceTableConstructList);
        }
        // ES类型
        else if (DATA_SOURCE_ES.equalsIgnoreCase(dataSourceType)) {
            Connection esConnection = getEsConnection(dataSourceInfo);
            // return getEsSchemas(esConnection);
        }

        return Collections.emptyList();
    }

    public JSONObject getTableData(DataSourceInfo dataSourceInfo, DataSourceQuery dataSourceQuery) throws SQLException {
        String dataSourceType = dataSourceInfo.getType();

        // JDBC类型
        if (DATA_SOURCE_JDBC.equalsIgnoreCase(dataSourceType)) {
            String schemaName = dataSourceQuery.getSchemaName();
            String tableName = dataSourceQuery.getTableName();
            // 获取表格数据
            List<String> columnNameList = new ArrayList<>();
            List<Map<String, String>> tableData = getRDBSConnection(dataSourceInfo, schemaName, tableName).getTableData(dataSourceQuery, columnNameList);
            // 获取数据总条目
            Integer total = getRDBSConnection(dataSourceInfo, schemaName, tableName).getTotal();
            return constructTableData(columnNameList, tableData, total);
        }
        // ES类型
        else if (DATA_SOURCE_ES.equalsIgnoreCase(dataSourceType)) {
            Connection esConnection = getEsConnection(dataSourceInfo);
            // return getEsSchemas(esConnection);
        }

        return new JSONObject();
    }

    public JSONObject getTableDataByStr(DataSourceInfo dataSourceInfo, DataSourceQuery dataSourceQuery) throws SQLException {
        String dataSourceType = dataSourceInfo.getType();
        String executeSql = dataSourceQuery.getExecuteStr().replace("\r", " ").replace("\n", " ");
        // JDBC类型
        if (DATA_SOURCE_JDBC.equalsIgnoreCase(dataSourceType)) {
            // 获取表格数据
            List<String> columnNameList = new ArrayList<>();
            List<Map<String, String>> tableData = getRDBSConnection(dataSourceInfo, null, null)
                    .getTableDataBySql(dataSourceQuery, executeSql, columnNameList);
            // 获取数据总条目
            return constructTableData(columnNameList, tableData, tableData.size());
        }
        // ES类型
        else if (DATA_SOURCE_ES.equalsIgnoreCase(dataSourceType)) {
            Connection esConnection = getEsConnection(dataSourceInfo);
            // return getEsSchemas(esConnection);
        }

        return new JSONObject();
    }


    /**
     * 数据组装
     *
     * @return "tableConfig":{"columns":[{"prop":"schema_name","label":"column_name"}],"data":[{"schema_name":"DW"}]}
     */
    private JSONObject constructTableData(List<String> columnNameList, List<Map<String, String>> tableData, Integer total) {

        JSONObject response = new JSONObject();
        JSONObject tableConfig = new JSONObject();
        // 整理columns
        ArrayList<Map<String, String>> columns = new ArrayList<>();
        HashMap<String, String> map;
        for (String columnName : columnNameList) {
            map = new HashMap<>();
            map.put("prop", columnName);
            map.put("label", columnName);
            columns.add(map);
        }
        tableConfig.putOpt("columns", columns);

        // 整理data
        tableConfig.putOpt("data", tableData);
        // 总数
        tableConfig.putOpt(TOTAL_STR, total);

        response.putOpt("tableConfig", tableConfig);
        return response;
    }


    /**
     * 刷新注释
     *
     * @param list list
     */
    private List<DataSourceTableConstruct> refreshColumnComments(List<DataSourceTableConstruct> list) {
        if (CollUtil.isEmpty(list)) {
            return list;
        }

        // 查询有自定义注释的列
        List<DataTableColumnComments> dataTableColumnComments = dataSourceColumnCommentsMapper.selectColumnComments(list);
        for (DataSourceTableConstruct a : list) {
            for (DataTableColumnComments b : dataTableColumnComments) {
                // 匹配赋值
                if (ObjectUtil.equals(a.getDataSourceId(), b.getDataSourceId()) && ObjectUtil.equals(a.getSchemaName(), b.getSchemaName())
                        && ObjectUtil.equals(a.getTableName(), b.getTableName()) && ObjectUtil.equals(a.getColumnName(), b.getColumnName())) {
                    a.setCommentId(b.getId());
                    a.setComments(b.getComments());
                }
            }
        }
        return list;
    }


    /**
     * 获取jdbc连接
     *
     * @param dataSourceInfo dataSource
     */
    @SneakyThrows
    public RDBSInterface getRDBSConnection(DataSourceInfo dataSourceInfo, String schemaName, String tableName) throws SQLException {
        String url = dataSourceInfo.getUrl();
        String userName = dataSourceInfo.getUserName();
        String password = dataSourceInfo.getPassword();
        // 获取Connection、获取数据库信息
        Connection connection = DriverManager.getConnection(url, userName, password);
        return Objects.requireNonNull(getRDBSConnection(dataSourceInfo, (String x) -> {
            try {
                Class.forName(x);
            } catch (ClassNotFoundException e) {
                log.error(e.getMessage(), e);
                throw new RuntimeException();
            }
            return connection;
        }, schemaName, tableName));
    }

    private RDBSInterface getRDBSConnection(DataSourceInfo dataSourceInfo, Function<String, Connection> function,
                                            String schemaName, String tableName) {
        Connection connection;
        Integer dataSourceInfoId = dataSourceInfo.getId();
        String url = dataSourceInfo.getUrl();
        if (url.contains(DATA_SOURCE_MYSQL)) {
            connection = function.apply(MYSQL_DRIVER);
            return new RDBSInterface.MysqlInfo(dataSourceInfoId, connection, schemaName, tableName);
        } else if (url.contains(DATA_SOURCE_ORACLE)) {
            connection = function.apply(ORACLE_DRIVER);
            return new RDBSInterface.OracleInfo(dataSourceInfoId, connection, schemaName, tableName);
        } else if (url.contains(DATA_SOURCE_SQLSERVER)) {
            connection = function.apply(SQL_SERVER_DRIVER);
            return new RDBSInterface.SqlServerInfo(dataSourceInfoId, connection, schemaName, tableName);
        }
        return null;
    }


    /**
     * 关系型数据库
     * Mysql Oracle SqlServer
     */
    private interface RDBSInterface {

        List<String> getSchemas() throws SQLException;

        List<String> getTables() throws SQLException;

        List<DataSourceTableConstruct> getTableConstruct() throws SQLException;

        List<Map<String, String>> getTableData(DataSourceQuery dataSourceQuery, List<String> columnNameList) throws SQLException;

        List<Map<String, String>> getTableDataBySql(DataSourceQuery dataSourceQuery, String executeSql, List<String> columnNameList) throws SQLException;

        Integer getTotal() throws SQLException;

        // 执行sql获取指定columnName的值
        default List<String> getAssignColumnValue(Connection conn, String sql, String columnName) throws SQLException {
            try (PreparedStatement preparedStatement = conn.prepareStatement(sql)) {
                ResultSet res = preparedStatement.executeQuery();
                List<String> schemaNameList = new ArrayList<>();
                while (res.next()) {
                    String schemaName = res.getString(columnName);
                    schemaNameList.add(schemaName);
                }
                return schemaNameList;
            } finally {
                conn.close();
            }
        }

        // 执行sql获取指定columnNameList的值
        default List<Map<String, String>> getTableData(Connection conn, String sql, List<String> columnNameList) throws SQLException {
            HashMap<String, String> hashMap;
            List<Map<String, String>> hashMapList = new ArrayList<>();
            String columnValue = "";
            try (PreparedStatement preparedStatement = conn.prepareStatement(sql)) {
                ResultSet res = preparedStatement.executeQuery();
                ResultSetMetaData metaData = res.getMetaData();
                // 获取列名称
                int columnCount = metaData.getColumnCount();
                for (int i = 0; i < columnCount; i++) {
                    columnNameList.add(metaData.getColumnName(i + 1));
                }
                while (res.next()) {
                    hashMap = new HashMap<>();
                    for (String columnNameStr : columnNameList) {
                        columnValue = res.getString(columnNameStr);
                        hashMap.put(columnNameStr, ObjectUtil.isEmpty(columnValue) ? "" : columnValue);
                    }
                    hashMapList.add(hashMap);
                }
                return hashMapList;
            } finally {
                conn.close();
            }
        }

        // 获取统一格式数据表结构
        default List<DataSourceTableConstruct> getTableConstruct(Connection conn, String sql) throws SQLException {
            try (PreparedStatement preparedStatement = conn.prepareStatement(sql)) {
                ResultSet res = preparedStatement.executeQuery();
                List<DataSourceTableConstruct> dataSourceTableInfoArrayList = new ArrayList<>();
                DataSourceTableConstruct dataSourceTableInfo;
                while (res.next()) {
                    dataSourceTableInfo = new DataSourceTableConstruct();
                    dataSourceTableInfo.setDataSourceId(Integer.valueOf(res.getString("data_source_id")));
                    dataSourceTableInfo.setSchemaName(res.getString("schema_name"));
                    dataSourceTableInfo.setTableName(res.getString("table_name"));
                    dataSourceTableInfo.setColumnName(res.getString("column_name"));
                    dataSourceTableInfo.setDataType(res.getString("data_type"));
                    dataSourceTableInfo.setCommentsOri(res.getString("comments_ori"));
                    dataSourceTableInfoArrayList.add(dataSourceTableInfo);
                }
                return dataSourceTableInfoArrayList;
            } finally {
                conn.close();
            }
        }

        // 数据源总数
        default Integer getTotal(Connection conn, String schemaName, String tableName) throws SQLException {
            String sql = "select count(*) from " + schemaName + "." + tableName;

            try (PreparedStatement preparedStatement = conn.prepareStatement(sql)) {
                ResultSet res = preparedStatement.executeQuery();
                if (res.next()) {
                    return res.getInt(1);
                }
            } finally {
                conn.close();
            }
            return ZERO;
        }

        class MysqlInfo implements RDBSInterface {

            Integer dataSourceId;
            Connection conn;
            String schemaName;
            String tableName;

            public MysqlInfo(Integer dataSourceId, Connection conn, String schemaName, String tableName) {
                this.dataSourceId = dataSourceId;
                this.conn = conn;
                this.schemaName = schemaName;
                this.tableName = tableName;
            }

            @Override
            public List<String> getSchemas() throws SQLException {
                return getAssignColumnValue(conn, "show databases", "Database");
            }

            @Override
            public List<String> getTables() throws SQLException {
                return getAssignColumnValue(conn, "select table_name from information_schema.tables where table_schema = '" + schemaName + "'", TABLE_NAME_STR);
            }

            @Override
            public List<DataSourceTableConstruct> getTableConstruct() throws SQLException {
                String sql = "select '" + dataSourceId + "' data_source_id, '" + schemaName + "' schema_name, '" + tableName + "' table_name, " +
                        "column_name, data_type, column_comment comments_ori from information_schema.columns where table_schema='" +
                        schemaName + "' and table_name='" + tableName + "'";
                return getTableConstruct(conn, sql);
            }

            @Override
            public List<Map<String, String>> getTableData(DataSourceQuery dataSourceQuery, List<String> columnNameList) throws SQLException {
                List<Integer> pageParam = getPageParam(dataSourceQuery);
                String sql = "select * from " + schemaName + "." + tableName + " limit " + pageParam.get(0) + ", " + pageParam.get(1);
                return getTableData(conn, sql, columnNameList);
            }

            @Override
            public List<Map<String, String>> getTableDataBySql(DataSourceQuery dataSourceQuery, String executeSql, List<String> columnNameList) throws SQLException {
                if (ObjectUtil.isNotEmpty(dataSourceQuery.getPageNo())) {
                    List<Integer> pageParam = getPageParam(dataSourceQuery);
                    executeSql = "select hole.* from (" + executeSql + ") hole" + " limit " + pageParam.get(0) + ", " + pageParam.get(1);
                }
                return getTableData(conn, executeSql, columnNameList);
            }

            private List<Integer> getPageParam(DataSourceQuery dataSourceQuery) {
                Integer pageNo = dataSourceQuery.getPageNo();
                Integer pageSize = dataSourceQuery.getPageSize();
                int firstIndex = (pageNo - 1) * pageSize + 1;
                int lastIndex = pageNo * pageSize;
                return Arrays.asList(firstIndex, lastIndex);
            }

            @Override
            public Integer getTotal() throws SQLException {
                return getTotal(conn, schemaName, tableName);
            }

        }

        class OracleInfo implements RDBSInterface {

            Integer dataSourceId;
            Connection conn;
            String schemaName;
            String tableName;

            public OracleInfo(Integer dataSourceId, Connection conn, String schemaName, String tableName) {
                this.dataSourceId = dataSourceId;
                this.conn = conn;
                this.schemaName = schemaName;
                this.tableName = tableName;
            }

            @Override
            public List<String> getSchemas() throws SQLException {
                return getAssignColumnValue(conn, "SELECT USERNAME FROM ALL_USERS", "USERNAME");
            }

            @Override
            public List<String> getTables() throws SQLException {
                return getAssignColumnValue(conn, "SELECT TABLE_NAME FROM ALL_TABLES WHERE OWNER = '" + schemaName + "' ORDER BY TABLE_NAME", TABLE_NAME_STR);
            }

            @Override
            public List<DataSourceTableConstruct> getTableConstruct() throws SQLException {
                String sql = "SELECT '" + dataSourceId + "' DATA_SOURCE_ID, '" + schemaName + "' SCHEMA_NAME, '" + tableName + "' TABLE_NAME, " +
                        "A.COLUMN_NAME,A.DATA_TYPE,B.COMMENTS COMMENTS_ORI FROM ALL_TAB_COLS A JOIN (SELECT * FROM DBA_COL_COMMENTS WHERE TABLE_NAME = '" + tableName + "') B " +
                        "ON A.COLUMN_NAME = B.COLUMN_NAME WHERE A.TABLE_NAME = '" + tableName + "'";
                return getTableConstruct(conn, sql);
            }

            @Override
            public List<Map<String, String>> getTableData(DataSourceQuery dataSourceQuery, List<String> columnNameList) throws SQLException {
                String executeSql = "select * from " + schemaName + "." + tableName;
                return getTableDataByPage(dataSourceQuery, executeSql, columnNameList);
            }

            @Override
            public List<Map<String, String>> getTableDataBySql(DataSourceQuery dataSourceQuery, String executeSql, List<String> columnNameList) throws SQLException {
                if (dataSourceQuery.isByPage()) {
                    return getTableDataByPage(dataSourceQuery, executeSql, columnNameList);
                } else {
                    return getTableData(conn, executeSql, columnNameList);
                }
            }

            private List<Map<String, String>> getTableDataByPage(DataSourceQuery dataSourceQuery, String executeSql, List<String> columnNameList) throws SQLException {
                List<Integer> pageParam = getPageParam(dataSourceQuery);
                List<Map<String, String>> hashMapList = new ArrayList<>();

                String columnValue = "";
                try (PreparedStatement preparedStatement = conn.prepareStatement(executeSql)) {
                    // 如果要分页,则使用 Oracle 的 FETCH 分页
                    preparedStatement.setFetchSize(dataSourceQuery.getPageSize());
                    preparedStatement.setMaxRows(pageParam.get(1));

                    ResultSet res = preparedStatement.executeQuery();
                    ResultSetMetaData metaData = res.getMetaData();
                    // 获取列名称
                    int columnCount = metaData.getColumnCount();
                    for (int i = 0; i < columnCount; i++) {
                        columnNameList.add(metaData.getColumnName(i + 1));
                    }

                    int rowNum = 1;
                    Map<String, String> hashMap;
                    while (res.next() && rowNum > pageParam.get(0)) {
                        hashMap = new HashMap<>();
                        for (String columnNameStr : columnNameList) {
                            columnValue = res.getString(columnNameStr);
                            hashMap.put(columnNameStr, ObjectUtil.isEmpty(columnValue) ? "" : columnValue);
                        }
                        hashMapList.add(hashMap);
                        rowNum++;
                    }
                } finally {
                    conn.close();
                }
                return hashMapList;
            }


            private List<Integer> getPageParam(DataSourceQuery dataSourceQuery) {
                Integer pageNo = dataSourceQuery.getPageNo();
                Integer pageSize = dataSourceQuery.getPageSize();
                int from = (pageNo - 1) * pageSize;
                int to = pageNo * pageSize;
                return Arrays.asList(from, to);
            }

            @Override
            public Integer getTotal() throws SQLException {
                return getTotal(conn, schemaName, tableName);
            }

        }

        class SqlServerInfo implements RDBSInterface {

            Integer dataSourceId;
            Connection conn;
            String schemaName;
            String tableName;

            public SqlServerInfo(Integer dataSourceId, Connection conn, String schemaName, String tableName) {
                this.dataSourceId = dataSourceId;
                this.conn = conn;
                this.schemaName = schemaName;
                this.tableName = tableName;
            }

            @Override
            public List<String> getSchemas() throws SQLException {
                return getAssignColumnValue(conn, "select name from sys.schemas where schema_id > 4", "name");
            }

            @Override
            public List<String> getTables() throws SQLException {
                return getAssignColumnValue(conn, "select name from sys.tables where schema_id = SCHEMA_ID('" + schemaName + "') order by name", "name");
            }

            @Override
            public List<DataSourceTableConstruct> getTableConstruct() throws SQLException {
                String sql = "SELECT '" + dataSourceId + "' DATA_SOURCE_ID, '" + schemaName + "' SCHEMA_NAME, '" + tableName + "' TABLE_NAME, c.name AS column_name, " +
                        "t.Name AS data_type, " +
                        "CAST(ep.value AS varchar(max)) AS COMMENTS_ORI " +
                        "FROM sys.columns c " +
                        "JOIN sys.types t ON c.user_type_id = t.user_type_id " +
                        "LEFT JOIN sys.extended_properties ep ON ep.major_id = c.object_id " +
                        "AND ep.minor_id = c.column_id " +
                        "WHERE c.object_id = OBJECT_ID('" + schemaName + "." + tableName + "')";
                return getTableConstruct(conn, sql);
            }

            @Override
            public List<Map<String, String>> getTableData(DataSourceQuery dataSourceQuery, List<String> columnNameList) throws SQLException {
                List<Integer> pageParam = getPageParam(dataSourceQuery);
                String sql = "SELECT * from (SELECT row_number() over (order by id asc) as rownumber, * FROM " +
                        schemaName + "." + tableName + ") as t Where t.rownumber > " + pageParam.get(0) + " And t.rownumber <= " + pageParam.get(1);
                return getTableData(conn, sql, columnNameList);
            }

            @Override
            public List<Map<String, String>> getTableDataBySql(DataSourceQuery dataSourceQuery, String executeSql, List<String> columnNameList) throws SQLException {
                if (ObjectUtil.isNotEmpty(dataSourceQuery.getPageNo())) {
                    List<Integer> pageParam = getPageParam(dataSourceQuery);
                    executeSql = "SELECT * from (SELECT row_number() over (order by id asc) as rownumber,* ) as t " +
                            "Where t.rownumber > " + pageParam.get(0) + " And t.rownumber <= " + pageParam.get(1);
                }
                return getTableData(conn, executeSql, columnNameList);
            }

            private List<Integer> getPageParam(DataSourceQuery dataSourceQuery) {
                Integer pageNo = dataSourceQuery.getPageNo();
                Integer pageSize = dataSourceQuery.getPageSize();
                int firstIndex = (pageNo - 1) * pageSize;
                int lastIndex = pageNo * pageSize;
                return Arrays.asList(firstIndex, lastIndex);
            }

            @Override
            public Integer getTotal() throws SQLException {
                return getTotal(conn, schemaName, tableName);
            }

        }

    }


    /**
     * 获取ES connection
     *
     * @param dataSourceInfo dataSourceInfo
     * @return Connection
     */
    private Connection getEsConnection(DataSourceInfo dataSourceInfo) throws SQLException {
        String url = dataSourceInfo.getUrl();
        EsDataSource esDataSource = new EsDataSource();
        esDataSource.setUrl(url);
        return esDataSource.getConnection();
    }

    /**
     * 查看ES所有数据库.
     *
     * @param connection connection
     */
    private List<String> getEsSchemas(Connection connection) throws SQLException {
        ResultSet schemas = connection.getMetaData().getCatalogs();
        ArrayList<String> list = new ArrayList<>();
        while (schemas.next()) {
            list.add(String.valueOf(schemas.getObject(TABLE_CAT_STR)));
        }
        return list;
    }

    /**
     * 查看ES数据库所有表.
     *
     * @param connection connection
     */
    public static void getEsTables(Connection connection) throws Exception {
        ResultSet tables = connection.getMetaData().getTables(null, null, null, null);
        while (tables.next()) {
//            System.out.println(tables.getString(TABLE_NAME_STR));
            String TABLE_CAT = tables.getString(TABLE_CAT_STR);
            String TABLE_SCHEM = tables.getString("TABLE_SCHEM");
            String TABLE_NAME = tables.getString(TABLE_NAME_STR);
            String TABLE_TYPE = tables.getString("TABLE_TYPE");
            String REMARKS = tables.getString("REMARKS");
            log.info("表类别:{}、表模式:{}、表名称:{}、表类型:{}、表描述:{}", TABLE_CAT, TABLE_SCHEM, TABLE_NAME, TABLE_TYPE, REMARKS);
        }
    }

    /**
     * 查看ES表所有字段.
     *
     * @param connection connection
     */
    public static void getEsColumns(Connection connection) throws Exception {
        ResultSet tables = connection.getMetaData().getColumns(null, null, "test_index", null);
        while (tables.next()) {
            String TABLE_CAT = tables.getString("TABLE_CAT");
            String TABLE_SCHEM = tables.getString("TABLE_SCHEM");
            String TABLE_NAME = tables.getString(TABLE_NAME_STR);
            String columnName = tables.getString("COLUMN_NAME");
            String typeName = tables.getString("TYPE_NAME");
            String columnSize = tables.getString("COLUMN_SIZE");
            String REMARKS = tables.getString("REMARKS");
            log.info("表类别:{}、表模式:{}、表名称:{}、字段名称:{}、字段类型:{}、字段大小:{}、字段描述:{}",
                    TABLE_CAT, TABLE_SCHEM, TABLE_NAME, columnName, typeName, columnSize, REMARKS);
        }
    }
}

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel(value = "DataSource对象", description = "数据源")
public class DataSourceQuery {

    @ApiModelProperty(value = "数据源名称")
    private String dataSourceName;

    @ApiModelProperty(value = "连接状态")
    private Integer dataSourceStatus;

    @ApiModelProperty(value = "数据源id")
    private Integer id;

    @ApiModelProperty(value = "schemaName")
    private String schemaName;

    @ApiModelProperty(value = "tableName")
    private String tableName;

}


import com.baomidou.mybatisplus.annotation.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;

@Data
@TableName("data_source")
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class DataSourceInfo implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /**
     * 数据源类型
     */
    private String type;

    /**
     * 数据源名称
     */
    private String dataSourceName;

    /**
     * url
     */
    private String url;

    /**
     * 数据库用户名
     */
    private String userName;

    /**
     * 数据库密码
     */
    private String password;

    /**
     * 数据源状态
     */
    private Integer dataSourceStatus;

    /**
     * 数据源描述
     */
    private String description;

    /**
     * 创建人
     */
    @TableField(value = "create_by", fill = FieldFill.INSERT)
    private String createBy;

    /**
     * 创建时间
     */
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private Date createTime;

    /**
     * 更新人
     */
    @TableField(value = "update_by", fill = FieldFill.INSERT_UPDATE)
    private String updateBy;

    /**
     * 更新时间
     */
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    private Date updateTime;

    /**
     * 是否删除(0-未删, 1-已删)
     */
    private Integer isDeleted;

}

import lombok.Data;

@Data
public class DataSourceTableConstruct {

    private Integer dataSourceId;

    private String schemaName;

    private String tableName;

    private String columnName;

    private String dataType;

    private Integer commentId;

    private String comments;

}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值