roodkcab commented on a change in pull request #13034:
URL: https://github.com/apache/shardingsphere/pull/13034#discussion_r728822369
##########
File path:
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/mysql/executor/information/AbstractSelectInformationExecutor.java
##########
@@ -153,7 +153,14 @@ protected Object getSourceData(final String schemaName)
throws SQLException {
ShardingSphereResource resource =
ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName).getResource();
Optional<Entry<String, DataSource>> dataSourceEntry =
resource.getDataSources().entrySet().stream().findFirst();
log.info("Actual SQL: {} ::: {}",
dataSourceEntry.orElseThrow(DatabaseNotExistedException::new).getKey(), sql);
- return
dataSourceEntry.get().getValue().getConnection().prepareStatement(sql).executeQuery();
+ Connection conn = dataSourceEntry.get().getValue().getConnection();
+ try {
+ return conn.prepareStatement(sql).executeQuery();
+ } catch (SQLException e) {
+ throw e;
+ } finally {
+ conn.close();
+ }
Review comment:
use callback in try-with-resouce
```
try (Connection conn = dataSourceEntry.get().getValue().getConnection();
PreparedStatement ps = conn.prepareStatement(sql);) {
callback(ps.executeQuery());
}
```
where build callback functor from constructRowData
then turn ```constructRowData(schemaName, getSourceData(schemaName))``` into
```getSourceData(schemaName, constructRowData(schemaName))```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]