You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2021/08/26 10:50:53 UTC
[shardingsphere] branch master updated: Filter incomplete schema &
(#12027)
This is an automated email from the ASF dual-hosted git repository.
panjuan 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 1e419d0 Filter incomplete schema & (#12027)
1e419d0 is described below
commit 1e419d080c364079bd645ec5bd6b4698d3307f4f
Author: lanchengx <52...@users.noreply.github.com>
AuthorDate: Thu Aug 26 05:50:23 2021 -0500
Filter incomplete schema & (#12027)
Set the schema to the connection.
---
.../text/data/impl/UnicastDatabaseBackendHandler.java | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandler.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandler.java
index 632769a..68307c5 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandler.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/data/impl/UnicastDatabaseBackendHandler.java
@@ -30,6 +30,7 @@ import org.apache.shardingsphere.proxy.backend.text.data.DatabaseBackendHandler;
import java.sql.SQLException;
import java.util.Collection;
+import java.util.Optional;
/**
* Database backend handler with unicast schema.
@@ -49,12 +50,18 @@ public final class UnicastDatabaseBackendHandler implements DatabaseBackendHandl
@Override
public ResponseHeader execute() throws SQLException {
- String schemaName = null == backendConnection.getSchemaName() ? getFirstSchemaName() : backendConnection.getSchemaName();
+ String originSchema = backendConnection.getSchemaName();
+ String schemaName = null == originSchema ? getFirstSchemaName() : originSchema;
if (!ProxyContext.getInstance().getMetaData(schemaName).isComplete()) {
throw new RuleNotExistedException();
}
- databaseCommunicationEngine = databaseCommunicationEngineFactory.newTextProtocolInstance(sqlStatementContext, sql, backendConnection);
- return databaseCommunicationEngine.execute();
+ try {
+ backendConnection.setCurrentSchema(schemaName);
+ databaseCommunicationEngine = databaseCommunicationEngineFactory.newTextProtocolInstance(sqlStatementContext, sql, backendConnection);
+ return databaseCommunicationEngine.execute();
+ } finally {
+ backendConnection.setCurrentSchema(originSchema);
+ }
}
private String getFirstSchemaName() {
@@ -62,7 +69,11 @@ public final class UnicastDatabaseBackendHandler implements DatabaseBackendHandl
if (schemaNames.isEmpty()) {
throw new NoDatabaseSelectedException();
}
- return schemaNames.iterator().next();
+ Optional<String> result = schemaNames.stream().filter(each -> ProxyContext.getInstance().getMetaData(each).isComplete()).findFirst();
+ if (!result.isPresent()) {
+ throw new RuleNotExistedException();
+ }
+ return result.get();
}
@Override