From 658d3b669d98eb5b164b01d8f885058c45a2b083 Mon Sep 17 00:00:00 2001 From: inrgihc Date: Fri, 26 Jul 2024 23:34:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3issue:IAFCGH?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dbswitch/provider/meta/AbstractMetadataProvider.java | 9 +++++---- .../java/com/gitee/dbswitch/schema/TableDescription.java | 3 +++ .../postgresql/PostgresMetadataQueryProvider.java | 3 ++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/dbswitch-core/src/main/java/com/gitee/dbswitch/provider/meta/AbstractMetadataProvider.java b/dbswitch-core/src/main/java/com/gitee/dbswitch/provider/meta/AbstractMetadataProvider.java index 9dd84513..e3346727 100644 --- a/dbswitch-core/src/main/java/com/gitee/dbswitch/provider/meta/AbstractMetadataProvider.java +++ b/dbswitch-core/src/main/java/com/gitee/dbswitch/provider/meta/AbstractMetadataProvider.java @@ -18,8 +18,8 @@ import com.gitee.dbswitch.schema.ColumnDescription; import com.gitee.dbswitch.schema.ColumnMetaData; import com.gitee.dbswitch.schema.IndexDescription; import com.gitee.dbswitch.schema.IndexFieldMeta; -import com.gitee.dbswitch.schema.TableDescription; import com.gitee.dbswitch.schema.SourceProperties; +import com.gitee.dbswitch.schema.TableDescription; import java.sql.Connection; import java.sql.ResultSet; import java.sql.ResultSetMetaData; @@ -48,6 +48,8 @@ public abstract class AbstractMetadataProvider extends AbstractCommonProvider implements MetadataProvider { + protected static final String[] TABLE_TYPES = new String[]{"TABLE", "VIEW", "PARTITIONED TABLE"}; + protected String catalogName = null; protected AbstractMetadataProvider(ProductFactoryProvider factoryProvider) { @@ -75,9 +77,8 @@ public abstract class AbstractMetadataProvider public List queryTableList(Connection connection, String schemaName) { List ret = new ArrayList<>(); Set uniqueSet = new LinkedHashSet<>(); - String[] types = new String[]{"TABLE", "VIEW"}; try (ResultSet tables = connection.getMetaData() - .getTables(catalogName, schemaName, "%", types)) { + .getTables(catalogName, schemaName, "%", TABLE_TYPES)) { while (tables.next()) { String tableName = tables.getString("TABLE_NAME"); if (uniqueSet.contains(tableName)) { @@ -103,7 +104,7 @@ public abstract class AbstractMetadataProvider public TableDescription queryTableMeta(Connection connection, String schemaName, String tableName) { try (ResultSet tables = connection.getMetaData() - .getTables(catalogName, schemaName, tableName, new String[]{"TABLE", "VIEW"})) { + .getTables(catalogName, schemaName, tableName, TABLE_TYPES)) { if (tables.next()) { TableDescription td = new TableDescription(); td.setSchemaName(schemaName); diff --git a/dbswitch-core/src/main/java/com/gitee/dbswitch/schema/TableDescription.java b/dbswitch-core/src/main/java/com/gitee/dbswitch/schema/TableDescription.java index c9bf760c..33cc7161 100644 --- a/dbswitch-core/src/main/java/com/gitee/dbswitch/schema/TableDescription.java +++ b/dbswitch-core/src/main/java/com/gitee/dbswitch/schema/TableDescription.java @@ -52,6 +52,9 @@ public class TableDescription { } public void setTableType(String tableType) { + if ("PARTITIONED TABLE".equals(tableType)) { + tableType = "TABLE"; + } this.tableType = ProductTableEnum.valueOf(tableType.toUpperCase()); } diff --git a/dbswitch-product/dbswitch-product-postgresql/src/main/java/com/gitee/dbswitch/product/postgresql/PostgresMetadataQueryProvider.java b/dbswitch-product/dbswitch-product-postgresql/src/main/java/com/gitee/dbswitch/product/postgresql/PostgresMetadataQueryProvider.java index 6e908dc0..59317e52 100644 --- a/dbswitch-product/dbswitch-product-postgresql/src/main/java/com/gitee/dbswitch/product/postgresql/PostgresMetadataQueryProvider.java +++ b/dbswitch-product/dbswitch-product-postgresql/src/main/java/com/gitee/dbswitch/product/postgresql/PostgresMetadataQueryProvider.java @@ -79,7 +79,8 @@ public class PostgresMetadataQueryProvider extends AbstractMetadataProvider { } // 低版本的PostgreSQL的表的DDL获取方法 - return PostgresUtils.getTableDDL(this, connection, schemaName, tableName); + String ddlSql = PostgresUtils.getTableDDL(this, connection, schemaName, tableName); + return DDLFormatterUtils.format(ddlSql); } @Override