This is an automated email from the ASF dual-hosted git repository.
zhaojinchao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 918503a8844 Fix spotbugs issues in openGauss backend module (#25026)
918503a8844 is described below
commit 918503a884450b9a5f2c59e733df046010a80bd7
Author: 吴伟杰 <[email protected]>
AuthorDate: Thu Apr 6 14:59:27 2023 +0800
Fix spotbugs issues in openGauss backend module (#25026)
---
.../OpenGaussSystemCatalogAdminQueryExecutor.java | 26 +++++++++++++---------
src/resources/spotbugs.xml | 5 -----
2 files changed, 16 insertions(+), 15 deletions(-)
diff --git
a/proxy/backend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussSystemCatalogAdminQueryExecutor.java
b/proxy/backend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussSystemCatalogAdminQueryExecutor.java
index 1953a9f7b73..d8e3f034fa5 100644
---
a/proxy/backend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussSystemCatalogAdminQueryExecutor.java
+++
b/proxy/backend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussSystemCatalogAdminQueryExecutor.java
@@ -27,17 +27,18 @@ import
org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.dr
import
org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.driver.jdbc.type.memory.JDBCMemoryQueryResult;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminQueryExecutor;
-import
org.apache.shardingsphere.proxy.backend.opengauss.handler.admin.schema.OpenGaussSystemCatalog;
import
org.apache.shardingsphere.proxy.backend.opengauss.handler.admin.schema.OpenGaussDatabase;
+import
org.apache.shardingsphere.proxy.backend.opengauss.handler.admin.schema.OpenGaussSystemCatalog;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import
org.apache.shardingsphere.sharding.merge.common.IteratorStreamMergedResult;
import org.apache.shardingsphere.sql.parser.sql.common.util.SQLUtils;
+import java.sql.Connection;
import java.sql.DriverManager;
+import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
-import java.sql.Statement;
import java.util.Collection;
import java.util.Collections;
@@ -65,20 +66,25 @@ public final class OpenGaussSystemCatalogAdminQueryExecutor
implements DatabaseA
@Override
public void execute(final ConnectionSession connectionSession) throws
SQLException {
- try (CalciteConnection connection =
DriverManager.getConnection("jdbc:calcite:caseSensitive=false").unwrap(CalciteConnection.class))
{
- connection.getRootSchema().add(PG_CATALOG, new
ReflectiveSchema(constructOgCatalog()));
- connection.getRootSchema().add("version",
ScalarFunctionImpl.create(getClass(), "version"));
- connection.getRootSchema().add("gs_password_deadline",
ScalarFunctionImpl.create(getClass(), "gsPasswordDeadline"));
- connection.getRootSchema().add("intervaltonum",
ScalarFunctionImpl.create(getClass(), "intervalToNum"));
- connection.getRootSchema().add("gs_password_notifyTime",
ScalarFunctionImpl.create(getClass(), "gsPasswordNotifyTime"));
+ try (Connection connection =
DriverManager.getConnection("jdbc:calcite:caseSensitive=false")) {
+ prepareCalciteConnection(connection);
connection.setSchema(PG_CATALOG);
- try (Statement statement = connection.createStatement(); ResultSet
resultSet = statement.executeQuery(sql)) {
+ try (PreparedStatement statement =
connection.prepareStatement(sql); ResultSet resultSet =
statement.executeQuery()) {
queryResultMetaData = new
JDBCQueryResultMetaData(resultSet.getMetaData());
mergedResult = new
IteratorStreamMergedResult(Collections.singletonList(new
JDBCMemoryQueryResult(resultSet, connectionSession.getProtocolType())));
}
}
}
+ private void prepareCalciteConnection(final Connection connection) throws
SQLException {
+ CalciteConnection calciteConnection =
connection.unwrap(CalciteConnection.class);
+ calciteConnection.getRootSchema().add(PG_CATALOG, new
ReflectiveSchema(constructOgCatalog()));
+ calciteConnection.getRootSchema().add("version",
ScalarFunctionImpl.create(getClass(), "version"));
+ calciteConnection.getRootSchema().add("gs_password_deadline",
ScalarFunctionImpl.create(getClass(), "gsPasswordDeadline"));
+ calciteConnection.getRootSchema().add("intervaltonum",
ScalarFunctionImpl.create(getClass(), "intervalToNum"));
+ calciteConnection.getRootSchema().add("gs_password_notifyTime",
ScalarFunctionImpl.create(getClass(), "gsPasswordNotifyTime"));
+ }
+
private OpenGaussSystemCatalog constructOgCatalog() {
Collection<String> allDatabaseNames =
ProxyContext.getInstance().getAllDatabaseNames();
OpenGaussDatabase[] openGaussDatabases = new
OpenGaussDatabase[allDatabaseNames.size()];
diff --git a/src/resources/spotbugs.xml b/src/resources/spotbugs.xml
index 5eff3a404c5..69e799e9c7c 100644
--- a/src/resources/spotbugs.xml
+++ b/src/resources/spotbugs.xml
@@ -115,9 +115,4 @@
<Class
name="org.apache.shardingsphere.sqlfederation.original.OriginalSQLFederationExecutor"
/>
<Bug code="OBL" />
</Match>
- <!-- TODO weijie fix the ignored bug -->
- <Match>
- <Class
name="org.apache.shardingsphere.proxy.backend.opengauss.handler.admin.OpenGaussSystemCatalogAdminQueryExecutor"
/>
- <Bug code="ODR" />
- </Match>
</FindBugsFilter>