You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/09/01 12:02:28 UTC

[GitHub] [shardingsphere] dongzl commented on a diff in pull request #20708: Support load SQLServer view metadata.

dongzl commented on code in PR #20708:
URL: https://github.com/apache/shardingsphere/pull/20708#discussion_r960568645


##########
shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/loader/dialect/SQLServerSchemaMetaDataLoader.java:
##########
@@ -72,8 +76,25 @@ public Collection<SchemaMetaData> load(final DataSource dataSource, final Collec
                 tableMetaDataList.add(new TableMetaData(entry.getKey(), entry.getValue(), indexMetaDataList, Collections.emptyList()));
             }
         }
-        // TODO load views from SQLServer database.
-        return Collections.singletonList(new SchemaMetaData(defaultSchemaName, tableMetaDataList, Collections.emptyList()));
+        return Collections.singletonList(new SchemaMetaData(defaultSchemaName, tableMetaDataList, loadViewMetaData(dataSource, tables)));
+    }
+
+    private Collection<ViewMetaData> loadViewMetaData(final DataSource dataSource, final Collection<String> tables) throws SQLException {
+        Collection<ViewMetaData> result = new LinkedList<>();
+        try (
+                Connection connection = dataSource.getConnection();
+                PreparedStatement preparedStatement = connection.prepareStatement(VIEW_META_DATA_SQL)) {
+            String databaseName = "".equals(connection.getCatalog()) ? GlobalDataSourceRegistry.getInstance().getCachedDatabaseTables().get(tables.iterator().next()) : connection.getCatalog();

Review Comment:
   > Why use `GlobalDataSourceRegistry.getInstance().` here? This class can only support mysql instance config.
   
   Hi @strongduanmu , Thanks for your reply, I remove the `GlobalDataSourceRegistry`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org