首页 > 其他分享 >HBaseIntrospector

HBaseIntrospector

时间:2023-12-28 21:33:55浏览次数:35  
标签:java HBaseIntrospector dbMetadataUtils resultSet table TABLE config

package x;import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author muzhi
 * @author <a href="mailto:[email protected]">Muzhi Zhang</a>
 * @version 1.0.0
 * @date 2023-12-12 00:59
 */
public class HBaseIntrospector extends DatabaseIntrospector {
    public HBaseIntrospector(DBMetadataUtils dbMetadataUtils) {
        super(dbMetadataUtils);
    }

    public HBaseIntrospector(DBMetadataUtils dbMetadataUtils, boolean forceBigDecimals, boolean useCamelCase) {
        super(dbMetadataUtils, forceBigDecimals, useCamelCase);
    }

    @Override
    public List<String> getCatalogs() throws SQLException {
        return super.getCatalogs();
    }

    @Override
    public List<String> getSchemas() throws SQLException {
        return super.getSchemas();
    }

    @Override
    protected Map<IntrospectedTable, List<IntrospectedColumn>> getColumns(DatabaseConfig config) throws SQLException {
        DatabaseMetaData metaData = dbMetadataUtils.getDatabaseMetaData();
        String[] types = {"TABLE"}; //"SYSTEM TABLE"
        ResultSet resultSet = metaData.getTables(config.getCatalog(), config.getSchemaPattern(), config.getTableNamePattern(), types);
        List<String> tables = new ArrayList<>();
        while (resultSet.next()) {
            tables.add(resultSet.getString("TABLE_NAME"));
        }
        return super.getColumns(config);
    }

    @Override
    public List<IntrospectedTable> introspectTables(DatabaseConfig config) throws SQLException {
        DatabaseMetaData metaData = dbMetadataUtils.getDatabaseMetaData();
        String[] types = {"TABLE"}; //"SYSTEM TABLE"
        ResultSet resultSet = metaData.getTables(config.getCatalog(), config.getSchemaPattern(), config.getTableNamePattern(), types);
        ResultSet columnsSet = metaData.getColumns(config.getCatalog(), config.getSchemaPattern(), config.getTableNamePattern(), "%");
        List<IntrospectedTable> result = new ArrayList<>();
        while (resultSet.next()) {
            String tableName = resultSet.getString("TABLE_NAME");
            IntrospectedTable table = new IntrospectedTable();
            table.setName(tableName);
            table.setCatalog(config.getCatalog());
            result.add(table);
        }
        while (columnsSet.next()) {
            String tableName = resultSet.getString("TABLE_NAME");
            IntrospectedTable table = new IntrospectedTable();
            table.setName(tableName);
            table.setCatalog(config.getCatalog());
            result.add(table);
        }
        return result;
    }
}

 

标签:java,HBaseIntrospector,dbMetadataUtils,resultSet,table,TABLE,config
From: https://www.cnblogs.com/exmyth/p/17933620.html

相关文章