mirror of
https://gitee.com/dromara/dbswitch.git
synced 2025-10-15 22:30:24 +00:00
!197 隐藏PG,GP数据库分区表的子表
* 代码调整 * 隐藏PG,GP数据库分区表的子表 * SQLServer,Postgres系统schema过滤
This commit is contained in:
@@ -20,6 +20,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
public class GreenplumMetadataQueryProvider extends PostgresMetadataQueryProvider {
|
||||
|
||||
static {
|
||||
systemSchemas.add("pg_aoseg");
|
||||
systemSchemas.add("gp_toolkit");
|
||||
}
|
||||
|
||||
|
@@ -40,13 +40,18 @@ public class PostgresMetadataQueryProvider extends AbstractMetadataProvider {
|
||||
+ "where pg_namespace.nspname='%s' and pg_class.relname ='%s'),true) ";
|
||||
private static final String SHOW_CREATE_VIEW_SQL_2 =
|
||||
"select pg_get_viewdef('\"%s\".\"%s\"', true)";
|
||||
private static final String SHOW_SUB_PARTITIONED_TABLE = "SELECT c.relname AS table_name \n"
|
||||
+ "FROM pg_class c JOIN pg_namespace n ON n.oid = c.relnamespace JOIN pg_inherits i ON c.oid = i.inhrelid \n"
|
||||
+ "WHERE n.nspname = '%s'";
|
||||
|
||||
static {
|
||||
systemSchemas.add("pg_temp");
|
||||
systemSchemas.add("pg_aoseg");
|
||||
systemSchemas.add("information_schema");
|
||||
systemSchemas.add("pg_catalog");
|
||||
systemSchemas.add("pg_bitmapindex");
|
||||
systemSchemas.add("pg_toast");
|
||||
systemSchemas.add("partman");
|
||||
systemSchemas.add("repack");
|
||||
}
|
||||
|
||||
public PostgresMetadataQueryProvider(ProductFactoryProvider factoryProvider) {
|
||||
@@ -61,6 +66,15 @@ public class PostgresMetadataQueryProvider extends AbstractMetadataProvider {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TableDescription> queryTableList(Connection connection, String schemaName) {
|
||||
List<TableDescription> tableList = super.queryTableList(connection, schemaName);
|
||||
Set<String> partitionedTable = getPartitionedTable(connection, schemaName,
|
||||
SHOW_SUB_PARTITIONED_TABLE);
|
||||
return tableList.stream().filter(t -> !partitionedTable.contains(t.getTableName()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTableDDL(Connection connection, String schemaName, String tableName) {
|
||||
String sql = PostgresqlConst.CREATE_TABLE_SQL_TPL
|
||||
@@ -263,4 +277,18 @@ public class PostgresMetadataQueryProvider extends AbstractMetadataProvider {
|
||||
return results;
|
||||
}
|
||||
|
||||
protected Set<String> getPartitionedTable(Connection connection, String schemaName, String sql) {
|
||||
String query = String.format(sql, schemaName);
|
||||
Set<String> partitionedTable = new HashSet<>();
|
||||
try (Statement st = connection.createStatement()) {
|
||||
ResultSet resultSet = st.executeQuery(query);
|
||||
while (resultSet.next()) {
|
||||
partitionedTable.add(resultSet.getString(1));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return partitionedTable;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -25,6 +25,7 @@ public final class PostgresUtils {
|
||||
provider, columnDescriptions, pks, schema, table, false);
|
||||
}
|
||||
|
||||
|
||||
private PostgresUtils() {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
@@ -47,6 +47,8 @@ public class SqlserverMetadataQueryProvider extends AbstractMetadataProvider {
|
||||
excludesSchemaNames.add("db_backupoperator");
|
||||
excludesSchemaNames.add("db_datareader");
|
||||
excludesSchemaNames.add("db_owner");
|
||||
excludesSchemaNames.add("sys");
|
||||
excludesSchemaNames.add("INFORMATION_SCHEMA");
|
||||
}
|
||||
|
||||
public SqlserverMetadataQueryProvider(ProductFactoryProvider factoryProvider) {
|
||||
|
Reference in New Issue
Block a user