You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2025/06/15 06:08:00 UTC
(shardingsphere) branch master updated: Remove redundant TableContextAvailable interface (#35711)
This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 7bf0fbd4e40 Remove redundant TableContextAvailable interface (#35711)
7bf0fbd4e40 is described below
commit 7bf0fbd4e40385817ea2e57b5a3f3b7bdaa9f881
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sun Jun 15 14:07:54 2025 +0800
Remove redundant TableContextAvailable interface (#35711)
* Remove redundant TableContextAvailable interface
* Remove redundant TableContextAvailable interface
* Remove redundant TableContextAvailable interface
* Remove redundant TableContextAvailable interface
* Remove redundant TableContextAvailable interface
* Remove redundant TableContextAvailable interface
* Remove redundant TableContextAvailable interface
* Remove redundant TableContextAvailable interface
* Remove redundant TableContextAvailable interface
* Remove redundant TableContextAvailable interface
* Remove redundant TableContextAvailable interface
* Remove redundant TableContextAvailable interface
* Remove redundant TableContextAvailable interface
---
.../engine/BroadcastRouteEngineFactoryTest.java | 18 +++++++--------
.../dal/show/EncryptShowColumnsMergedResult.java | 7 +++---
.../show/EncryptShowCreateTableMergedResult.java | 5 ++---
.../context/EncryptSQLRewriteContextDecorator.java | 6 +----
.../EncryptAssignmentParameterRewriter.java | 5 ++---
.../EncryptPredicateParameterRewriter.java | 3 +--
.../EncryptInsertAssignmentTokenGenerator.java | 3 +--
.../EncryptUpdateAssignmentTokenGenerator.java | 4 +---
.../EncryptPredicateValueTokenGenerator.java | 3 +--
.../select/EncryptIndexColumnTokenGenerator.java | 8 +++----
.../show/EncryptShowColumnsMergedResultTest.java | 7 +++---
.../EncryptShowCreateTableMergedResultTest.java | 3 ++-
.../EncryptSQLRewriteContextDecoratorTest.java | 3 ++-
.../route/ReadwriteSplittingSQLRouterTest.java | 8 +++----
...dowDMLStatementDataSourceMappingsRetriever.java | 3 +--
...MLShardingConditionsShardingAuditAlgorithm.java | 3 +--
.../sharding/auditor/ShardingSQLAuditor.java | 7 +-----
.../checker/ShardingRouteCacheableChecker.java | 3 +--
.../sql/common/ShardingSupportedCommonChecker.java | 3 +--
.../merge/dal/ShardingDALResultMerger.java | 5 +----
.../ShardingSQLRewriteContextDecorator.java | 6 +----
.../impl/ShardingTableTokenGenerator.java | 10 +--------
.../rewrite/token/pojo/ConstraintToken.java | 3 +--
.../rewrite/token/pojo/ShardingTokenUtils.java | 9 ++------
.../util/ShardingRouteContextCheckUtils.java | 3 +--
.../route/engine/condition/ShardingConditions.java | 7 +++---
.../engine/type/ShardingRouteEngineFactory.java | 13 +++--------
.../type/standard/ShardingStandardRouteEngine.java | 9 ++++----
...ardingConditionsShardingAuditAlgorithmTest.java | 10 ++++-----
.../sharding/auditor/ShardingSQLAuditorTest.java | 11 +++++----
.../cache/route/CachedShardingSQLRouterTest.java | 7 +++++-
.../merge/dal/ShardingDALResultMergerTest.java | 9 ++++----
.../impl/ShardingTableTokenGeneratorTest.java | 13 ++++++++---
.../rewrite/token/pojo/ConstraintTokenTest.java | 10 +++------
.../rewrite/token/pojo/IndexTokenTest.java | 17 +++++---------
.../rewrite/token/pojo/ShardingTokenUtilsTest.java | 10 ++++-----
.../type/ShardingRouteEngineFactoryTest.java | 7 +++---
.../ShardingTableBroadcastRouteEngineTest.java | 6 ++---
.../standard/ShardingStandardRouteEngineTest.java | 26 ++++++++++------------
.../extractor/SQLStatementContextExtractor.java | 4 +---
.../context/statement/SQLStatementContext.java | 8 +++++++
.../TableAvailableSQLStatementContext.java | 3 +--
.../statement/UnknownSQLStatementContext.java | 8 +++++++
.../type/dal/ExplainStatementContext.java | 3 +--
.../type/dal/ShowColumnsStatementContext.java | 3 +--
.../type/dal/ShowIndexStatementContext.java | 3 +--
.../type/dal/ShowTableStatusStatementContext.java | 7 ++++++
.../type/dal/ShowTablesStatementContext.java | 7 ++++++
.../type/ddl/AlterIndexStatementContext.java | 3 +--
.../type/ddl/AlterTableStatementContext.java | 3 +--
.../type/ddl/AlterViewStatementContext.java | 3 +--
.../statement/type/ddl/CloseStatementContext.java | 7 +++---
.../type/ddl/CreateIndexStatementContext.java | 3 +--
.../type/ddl/CreateTableStatementContext.java | 3 +--
.../type/ddl/CreateViewStatementContext.java | 3 +--
.../statement/type/ddl/CursorStatementContext.java | 7 +++---
.../type/ddl/DropIndexStatementContext.java | 3 +--
.../statement/type/ddl/FetchStatementContext.java | 7 +++---
.../statement/type/ddl/MoveStatementContext.java | 7 +++---
.../statement/type/dml/DeleteStatementContext.java | 3 +--
.../statement/type/dml/InsertStatementContext.java | 3 +--
.../statement/type/dml/SelectStatementContext.java | 3 +--
.../statement/type/dml/UpdateStatementContext.java | 3 +--
.../infra/checker/SupportedSQLCheckEngine.java | 5 +----
.../connection/kernel/KernelProcessorTest.java | 4 ++--
.../sql/context/ExecutionContextBuilder.java | 5 +----
.../sql/context/ExecutionContextBuilderTest.java | 8 +++----
.../infra/executor/sql/log/SQLLoggerTest.java | 6 ++++-
.../generator/generic/RemoveTokenGenerator.java | 11 +++++----
.../infra/rewrite/SQLRewriteEntryTest.java | 6 +++--
.../rewrite/context/SQLRewriteContextTest.java | 10 ++++++---
.../engine/GenericSQLRewriteEngineTest.java | 10 +++++----
.../rewrite/engine/RouteSQLRewriteEngineTest.java | 7 +++---
.../infra/route/engine/SQLRouteEngineTest.java | 6 ++++-
.../tableless/TablelessRouteEngineFactoryTest.java | 5 ++---
.../infra/session/query/QueryContext.java | 8 ++-----
.../infra/session/query/QueryContextTest.java | 11 ++++++---
.../BatchPreparedStatementExecutor.java | 6 +----
.../DriverJDBCPushDownExecuteUpdateExecutor.java | 6 +----
.../statement/ShardingSpherePreparedStatement.java | 10 ++-------
.../core/statement/ShardingSphereStatement.java | 10 ++-------
.../BatchPreparedStatementExecutorTest.java | 5 ++---
.../resultset/ShardingSphereResultSetTest.java | 8 +++----
.../metadata/generator/PipelineDDLDecorator.java | 21 +++++++++--------
.../single/route/SingleSQLRouter.java | 6 +----
.../shardingsphere/single/rule/SingleRule.java | 5 +----
.../sqlfederation/engine/SQLFederationEngine.java | 14 +++++-------
.../impl/StandardSQLFederationProcessor.java | 9 ++------
.../implementor/EnumerableScanImplementor.java | 10 +++------
.../pushdown/PushDownMetaDataRefreshEngine.java | 3 +--
.../refresher/util/SchemaRefreshUtils.java | 3 +--
.../proxy/backend/connector/ProxySQLExecutor.java | 12 ++++------
.../connector/StandardDatabaseConnector.java | 8 ++-----
.../backend/distsql/DistSQLStatementContext.java | 8 +++++++
.../handler/ProxyBackendHandlerFactory.java | 5 ++---
.../handler/distsql/rul/PreviewExecutor.java | 7 ++----
.../connector/DatabaseConnectorFactoryTest.java | 2 ++
.../backend/connector/ProxySQLExecutorTest.java | 6 ++---
.../connector/StandardDatabaseConnectorTest.java | 5 +++++
.../data/DatabaseBackendHandlerFactoryTest.java | 14 ++++++------
.../impl/UnicastDatabaseBackendHandlerTest.java | 5 ++++-
.../handler/tcl/TCLBackendHandlerFactoryTest.java | 13 ++++++-----
.../admin/OpenGaussAdminExecutorCreator.java | 5 ++---
.../admin/OpenGaussAdminExecutorCreatorTest.java | 6 ++---
.../prepare/MySQLComStmtPrepareExecutor.java | 5 ++---
.../command/query/extended/PortalTest.java | 4 +++-
106 files changed, 322 insertions(+), 401 deletions(-)
diff --git a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/route/engine/BroadcastRouteEngineFactoryTest.java b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/route/engine/BroadcastRouteEngineFactoryTest.java
index 1d08c1e3942..5d510462435 100644
--- a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/route/engine/BroadcastRouteEngineFactoryTest.java
+++ b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/route/engine/BroadcastRouteEngineFactoryTest.java
@@ -25,7 +25,6 @@ import org.apache.shardingsphere.infra.binder.context.extractor.SQLStatementCont
import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CloseStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.session.query.QueryContext;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
@@ -54,7 +53,6 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.withSettings;
@ExtendWith(AutoMockExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
@@ -100,8 +98,8 @@ class BroadcastRouteEngineFactoryTest {
@Test
void assertNewInstanceWithDALStatement() {
- SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, withSettings().extraInterfaces(TableContextAvailable.class));
- when(((TableContextAvailable) sqlStatementContext).getTablesContext()).thenReturn(createTablesContext());
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class);
+ when(sqlStatementContext.getTablesContext()).thenReturn(createTablesContext());
when(sqlStatementContext.getSqlStatement()).thenReturn(mock(DALStatement.class));
when(queryContext.getSqlStatementContext()).thenReturn(sqlStatementContext);
assertThat(BroadcastRouteEngineFactory.newInstance(queryContext, Collections.emptyList()), instanceOf(BroadcastTableBroadcastRouteEngine.class));
@@ -109,8 +107,8 @@ class BroadcastRouteEngineFactoryTest {
@Test
void assertNewInstanceWithDCLStatementWithBroadcastTables() {
- SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, withSettings().extraInterfaces(TableContextAvailable.class));
- when(((TableContextAvailable) sqlStatementContext).getTablesContext()).thenReturn(createTablesContext());
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class);
+ when(sqlStatementContext.getTablesContext()).thenReturn(createTablesContext());
when(sqlStatementContext.getSqlStatement()).thenReturn(mock(DCLStatement.class));
when(queryContext.getSqlStatementContext()).thenReturn(sqlStatementContext);
assertThat(BroadcastRouteEngineFactory.newInstance(queryContext, Collections.emptyList()), instanceOf(BroadcastTableBroadcastRouteEngine.class));
@@ -118,8 +116,8 @@ class BroadcastRouteEngineFactoryTest {
@Test
void assertNewInstanceWithSelectStatementAndIsAllBroadcastTables() {
- SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, withSettings().extraInterfaces(TableContextAvailable.class));
- when(((TableContextAvailable) sqlStatementContext).getTablesContext()).thenReturn(createTablesContext());
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class);
+ when(sqlStatementContext.getTablesContext()).thenReturn(createTablesContext());
when(sqlStatementContext.getSqlStatement()).thenReturn(mock(SelectStatement.class));
when(queryContext.getSqlStatementContext()).thenReturn(sqlStatementContext);
assertThat(BroadcastRouteEngineFactory.newInstance(queryContext, Collections.emptyList()), instanceOf(BroadcastUnicastRouteEngine.class));
@@ -127,8 +125,8 @@ class BroadcastRouteEngineFactoryTest {
@Test
void assertNewInstanceWithUpdateStatementAndIsAllBroadcastTables() {
- SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, withSettings().extraInterfaces(TableContextAvailable.class));
- when(((TableContextAvailable) sqlStatementContext).getTablesContext()).thenReturn(createTablesContext());
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class);
+ when(sqlStatementContext.getTablesContext()).thenReturn(createTablesContext());
when(sqlStatementContext.getSqlStatement()).thenReturn(mock(UpdateStatement.class));
when(queryContext.getSqlStatementContext()).thenReturn(sqlStatementContext);
assertThat(BroadcastRouteEngineFactory.newInstance(queryContext, Collections.emptyList()), instanceOf(BroadcastDatabaseBroadcastRouteEngine.class));
diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/merge/dal/show/EncryptShowColumnsMergedResult.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/merge/dal/show/EncryptShowColumnsMergedResult.java
index 06c0e4121c6..92125774ace 100644
--- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/merge/dal/show/EncryptShowColumnsMergedResult.java
+++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/merge/dal/show/EncryptShowColumnsMergedResult.java
@@ -21,9 +21,8 @@ import org.apache.shardingsphere.encrypt.exception.syntax.UnsupportedEncryptSQLE
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.encrypt.rule.table.EncryptTable;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
-import org.apache.shardingsphere.infra.merge.result.MergedResult;
import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
+import org.apache.shardingsphere.infra.merge.result.MergedResult;
import java.io.InputStream;
import java.io.Reader;
@@ -46,9 +45,9 @@ public final class EncryptShowColumnsMergedResult implements MergedResult {
private final EncryptRule rule;
public EncryptShowColumnsMergedResult(final MergedResult mergedResult, final SQLStatementContext sqlStatementContext, final EncryptRule rule) {
- ShardingSpherePreconditions.checkState(sqlStatementContext instanceof TableContextAvailable && 1 == ((TableContextAvailable) sqlStatementContext).getTablesContext().getSimpleTables().size(),
+ ShardingSpherePreconditions.checkState(1 == sqlStatementContext.getTablesContext().getSimpleTables().size(),
() -> new UnsupportedEncryptSQLException("SHOW COLUMNS FOR MULTI TABLES"));
- tableName = ((TableContextAvailable) sqlStatementContext).getTablesContext().getSimpleTables().iterator().next().getTableName().getIdentifier().getValue();
+ tableName = sqlStatementContext.getTablesContext().getSimpleTables().iterator().next().getTableName().getIdentifier().getValue();
this.mergedResult = mergedResult;
this.rule = rule;
}
diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/merge/dal/show/EncryptShowCreateTableMergedResult.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/merge/dal/show/EncryptShowCreateTableMergedResult.java
index 2d0cd6081ea..cd6175bb648 100644
--- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/merge/dal/show/EncryptShowCreateTableMergedResult.java
+++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/merge/dal/show/EncryptShowCreateTableMergedResult.java
@@ -21,7 +21,6 @@ import org.apache.shardingsphere.encrypt.exception.syntax.UnsupportedEncryptSQLE
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.encrypt.rule.table.EncryptTable;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
@@ -58,10 +57,10 @@ public final class EncryptShowCreateTableMergedResult implements MergedResult {
private final SQLParserEngine sqlParserEngine;
public EncryptShowCreateTableMergedResult(final RuleMetaData globalRuleMetaData, final MergedResult mergedResult, final SQLStatementContext sqlStatementContext, final EncryptRule rule) {
- ShardingSpherePreconditions.checkState(sqlStatementContext instanceof TableContextAvailable && 1 == ((TableContextAvailable) sqlStatementContext).getTablesContext().getSimpleTables().size(),
+ ShardingSpherePreconditions.checkState(1 == sqlStatementContext.getTablesContext().getSimpleTables().size(),
() -> new UnsupportedEncryptSQLException("SHOW CREATE TABLE FOR MULTI TABLES"));
this.mergedResult = mergedResult;
- tableName = ((TableContextAvailable) sqlStatementContext).getTablesContext().getSimpleTables().iterator().next().getTableName().getIdentifier().getValue();
+ tableName = sqlStatementContext.getTablesContext().getSimpleTables().iterator().next().getTableName().getIdentifier().getValue();
this.rule = rule;
sqlParserEngine = globalRuleMetaData.getSingleRule(SQLParserRule.class).getSQLParserEngine(sqlStatementContext.getDatabaseType());
}
diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/context/EncryptSQLRewriteContextDecorator.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/context/EncryptSQLRewriteContextDecorator.java
index 7c982e0d9a8..7cfd1dde326 100644
--- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/context/EncryptSQLRewriteContextDecorator.java
+++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/context/EncryptSQLRewriteContextDecorator.java
@@ -27,7 +27,6 @@ import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
import org.apache.shardingsphere.infra.binder.context.extractor.SQLStatementContextExtractor;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.binder.context.type.WhereAvailable;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.rewrite.context.SQLRewriteContext;
@@ -65,10 +64,7 @@ public final class EncryptSQLRewriteContextDecorator implements SQLRewriteContex
}
private boolean containsEncryptTable(final EncryptRule rule, final SQLStatementContext sqlStatementContext) {
- if (!(sqlStatementContext instanceof TableContextAvailable)) {
- return false;
- }
- for (SimpleTableSegment each : ((TableContextAvailable) sqlStatementContext).getTablesContext().getSimpleTables()) {
+ for (SimpleTableSegment each : sqlStatementContext.getTablesContext().getSimpleTables()) {
if (rule.findEncryptTable(each.getTableName().getIdentifier().getValue()).isPresent()) {
return true;
}
diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/parameter/rewriter/EncryptAssignmentParameterRewriter.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/parameter/rewriter/EncryptAssignmentParameterRewriter.java
index 546c75eb51c..7b166cdbc6e 100644
--- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/parameter/rewriter/EncryptAssignmentParameterRewriter.java
+++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/parameter/rewriter/EncryptAssignmentParameterRewriter.java
@@ -24,7 +24,6 @@ import org.apache.shardingsphere.encrypt.rule.column.EncryptColumn;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.UpdateStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
import org.apache.shardingsphere.infra.rewrite.parameter.builder.ParameterBuilder;
import org.apache.shardingsphere.infra.rewrite.parameter.builder.impl.GroupedParameterBuilder;
@@ -66,8 +65,8 @@ public final class EncryptAssignmentParameterRewriter implements ParameterRewrit
@Override
public void rewrite(final ParameterBuilder paramBuilder, final SQLStatementContext sqlStatementContext, final List<Object> params) {
- String tableName = ((TableContextAvailable) sqlStatementContext).getTablesContext().getSimpleTables().iterator().next().getTableName().getIdentifier().getValue();
- String schemaName = ((TableContextAvailable) sqlStatementContext).getTablesContext().getSchemaName()
+ String tableName = sqlStatementContext.getTablesContext().getSimpleTables().iterator().next().getTableName().getIdentifier().getValue();
+ String schemaName = sqlStatementContext.getTablesContext().getSchemaName()
.orElseGet(() -> new DatabaseTypeRegistry(sqlStatementContext.getDatabaseType()).getDefaultSchemaName(databaseName));
for (ColumnAssignmentSegment each : getSetAssignmentSegment(sqlStatementContext.getSqlStatement()).getAssignments()) {
String columnName = each.getColumns().get(0).getIdentifier().getValue();
diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/parameter/rewriter/EncryptPredicateParameterRewriter.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/parameter/rewriter/EncryptPredicateParameterRewriter.java
index afb08815cde..c72ecf54b13 100644
--- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/parameter/rewriter/EncryptPredicateParameterRewriter.java
+++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/parameter/rewriter/EncryptPredicateParameterRewriter.java
@@ -25,7 +25,6 @@ import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.encrypt.rule.column.EncryptColumn;
import org.apache.shardingsphere.encrypt.rule.table.EncryptTable;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.binder.context.type.WhereAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
import org.apache.shardingsphere.infra.rewrite.parameter.builder.ParameterBuilder;
@@ -56,7 +55,7 @@ public final class EncryptPredicateParameterRewriter implements ParameterRewrite
@Override
public void rewrite(final ParameterBuilder paramBuilder, final SQLStatementContext sqlStatementContext, final List<Object> params) {
- String schemaName = ((TableContextAvailable) sqlStatementContext).getTablesContext().getSchemaName()
+ String schemaName = sqlStatementContext.getTablesContext().getSchemaName()
.orElseGet(() -> new DatabaseTypeRegistry(sqlStatementContext.getDatabaseType()).getDefaultSchemaName(databaseName));
for (EncryptCondition each : encryptConditions) {
encryptParameters(paramBuilder, each.getPositionIndexMap(), getEncryptedValues(schemaName, each, new EncryptConditionValues(each).get(params)));
diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/assignment/EncryptInsertAssignmentTokenGenerator.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/assignment/EncryptInsertAssignmentTokenGenerator.java
index 0c480883d02..df9f30c5263 100644
--- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/assignment/EncryptInsertAssignmentTokenGenerator.java
+++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/assignment/EncryptInsertAssignmentTokenGenerator.java
@@ -23,7 +23,6 @@ import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.InsertStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.generator.CollectionSQLTokenGenerator;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.SQLToken;
@@ -46,7 +45,7 @@ public final class EncryptInsertAssignmentTokenGenerator implements CollectionSQ
@Override
public boolean isGenerateSQLToken(final SQLStatementContext sqlStatementContext) {
return sqlStatementContext instanceof InsertStatementContext && (((InsertStatementContext) sqlStatementContext).getSqlStatement()).getSetAssignment().isPresent()
- && containsEncryptTable(((TableContextAvailable) sqlStatementContext).getTablesContext().getSimpleTables());
+ && containsEncryptTable(sqlStatementContext.getTablesContext().getSimpleTables());
}
private boolean containsEncryptTable(final Collection<SimpleTableSegment> simpleTableSegments) {
diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/assignment/EncryptUpdateAssignmentTokenGenerator.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/assignment/EncryptUpdateAssignmentTokenGenerator.java
index 2551316b508..83d0eace5c5 100644
--- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/assignment/EncryptUpdateAssignmentTokenGenerator.java
+++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/assignment/EncryptUpdateAssignmentTokenGenerator.java
@@ -23,7 +23,6 @@ import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.UpdateStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.generator.CollectionSQLTokenGenerator;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.SQLToken;
@@ -45,8 +44,7 @@ public final class EncryptUpdateAssignmentTokenGenerator implements CollectionSQ
@Override
public boolean isGenerateSQLToken(final SQLStatementContext sqlStatementContext) {
- return sqlStatementContext instanceof UpdateStatementContext
- && containsEncryptTable(((TableContextAvailable) sqlStatementContext).getTablesContext().getSimpleTables());
+ return sqlStatementContext instanceof UpdateStatementContext && containsEncryptTable(sqlStatementContext.getTablesContext().getSimpleTables());
}
private boolean containsEncryptTable(final Collection<SimpleTableSegment> simpleTableSegments) {
diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/predicate/EncryptPredicateValueTokenGenerator.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/predicate/EncryptPredicateValueTokenGenerator.java
index 01612506882..a2d13ef05ac 100644
--- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/predicate/EncryptPredicateValueTokenGenerator.java
+++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/predicate/EncryptPredicateValueTokenGenerator.java
@@ -34,7 +34,6 @@ import org.apache.shardingsphere.encrypt.rule.column.item.LikeQueryColumnItem;
import org.apache.shardingsphere.encrypt.rule.table.EncryptTable;
import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.binder.context.type.WhereAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -74,7 +73,7 @@ public final class EncryptPredicateValueTokenGenerator implements CollectionSQLT
@Override
public Collection<SQLToken> generateSQLTokens(final SQLStatementContext sqlStatementContext) {
Collection<SQLToken> result = new LinkedHashSet<>(encryptConditions.size(), 1F);
- String schemaName = ((TableContextAvailable) sqlStatementContext).getTablesContext().getSchemaName()
+ String schemaName = sqlStatementContext.getTablesContext().getSchemaName()
.orElseGet(() -> new DatabaseTypeRegistry(sqlStatementContext.getDatabaseType()).getDefaultSchemaName(database.getName()));
for (EncryptCondition each : encryptConditions) {
Optional<EncryptTable> encryptTable = rule.findEncryptTable(each.getTableName());
diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/select/EncryptIndexColumnTokenGenerator.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/select/EncryptIndexColumnTokenGenerator.java
index d097e19d2a0..4176ed80094 100644
--- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/select/EncryptIndexColumnTokenGenerator.java
+++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/select/EncryptIndexColumnTokenGenerator.java
@@ -27,7 +27,6 @@ import org.apache.shardingsphere.infra.binder.context.segment.select.projection.
import org.apache.shardingsphere.infra.binder.context.segment.select.projection.impl.ColumnProjection;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.IndexAvailable;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.database.core.metadata.database.enums.QuoteCharacter;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.generator.CollectionSQLTokenGenerator;
@@ -53,14 +52,13 @@ public final class EncryptIndexColumnTokenGenerator implements CollectionSQLToke
@Override
public boolean isGenerateSQLToken(final SQLStatementContext sqlStatementContext) {
- return sqlStatementContext instanceof IndexAvailable && sqlStatementContext instanceof TableContextAvailable
- && !((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames().isEmpty()
- && !((IndexAvailable) sqlStatementContext).getIndexColumns().isEmpty();
+ return !sqlStatementContext.getTablesContext().getTableNames().isEmpty()
+ && sqlStatementContext instanceof IndexAvailable && !((IndexAvailable) sqlStatementContext).getIndexColumns().isEmpty();
}
@Override
public Collection<SQLToken> generateSQLTokens(final SQLStatementContext sqlStatementContext) {
- String tableName = ((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames().iterator().next();
+ String tableName = sqlStatementContext.getTablesContext().getTableNames().iterator().next();
EncryptTable encryptTable = rule.getEncryptTable(tableName);
Collection<SQLToken> result = new LinkedList<>();
for (ColumnSegment each : ((IndexAvailable) sqlStatementContext).getIndexColumns()) {
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dal/show/EncryptShowColumnsMergedResultTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dal/show/EncryptShowColumnsMergedResultTest.java
index 54188abaad0..dafe62f9fe2 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dal/show/EncryptShowColumnsMergedResultTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dal/show/EncryptShowColumnsMergedResultTest.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.encrypt.rule.table.EncryptTable;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dal.ShowColumnsStatementContext;
-import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment;
@@ -59,14 +58,16 @@ class EncryptShowColumnsMergedResultTest {
@Test
void assertNewInstanceWithNotTableAvailableStatement() {
- SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class);
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
assertThrows(UnsupportedEncryptSQLException.class, () -> new EncryptShowColumnsMergedResult(mergedResult, sqlStatementContext, mock(EncryptRule.class)));
}
@Test
void assertNewInstanceWithEmptyTable() {
- SelectStatementContext sqlStatementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
when(sqlStatementContext.getTablesContext().getSimpleTables()).thenReturn(Collections.emptyList());
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
assertThrows(UnsupportedEncryptSQLException.class, () -> new EncryptShowColumnsMergedResult(mergedResult, sqlStatementContext, mock(EncryptRule.class)));
}
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dal/show/EncryptShowCreateTableMergedResultTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dal/show/EncryptShowCreateTableMergedResultTest.java
index 8597a413a5a..9c04ff33094 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dal/show/EncryptShowCreateTableMergedResultTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dal/show/EncryptShowCreateTableMergedResultTest.java
@@ -72,7 +72,8 @@ class EncryptShowCreateTableMergedResultTest {
@Test
void assertNewInstanceWithNotTableAvailableStatement() {
- SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class);
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
assertThrows(UnsupportedEncryptSQLException.class, () -> new EncryptShowCreateTableMergedResult(mock(RuleMetaData.class), mergedResult, sqlStatementContext, mock(EncryptRule.class)));
}
diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/context/EncryptSQLRewriteContextDecoratorTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/context/EncryptSQLRewriteContextDecoratorTest.java
index 9beb53c90ca..f7ab3246fb1 100644
--- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/context/EncryptSQLRewriteContextDecoratorTest.java
+++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/context/EncryptSQLRewriteContextDecoratorTest.java
@@ -54,7 +54,8 @@ class EncryptSQLRewriteContextDecoratorTest {
@Test
void assertDecorateWithNotTableAvailable() {
SQLRewriteContext sqlRewriteContext = mock(SQLRewriteContext.class);
- SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class);
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
when(sqlRewriteContext.getSqlStatementContext()).thenReturn(sqlStatementContext);
decorator.decorate(rule, mock(ConfigurationProperties.class), sqlRewriteContext, mock(RouteContext.class));
assertTrue(sqlRewriteContext.getSqlTokens().isEmpty());
diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/route/ReadwriteSplittingSQLRouterTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/route/ReadwriteSplittingSQLRouterTest.java
index 4a937c4931d..f5549971616 100644
--- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/route/ReadwriteSplittingSQLRouterTest.java
+++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/route/ReadwriteSplittingSQLRouterTest.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.readwritesplitting.route;
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.hint.HintValueContext;
@@ -43,6 +42,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.SelectS
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
@@ -72,7 +72,7 @@ class ReadwriteSplittingSQLRouterTest {
private ReadwriteSplittingRule staticRule;
- @Mock
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
private CommonSQLStatementContext sqlStatementContext;
private ReadwriteSplittingSQLRouter sqlRouter;
@@ -81,14 +81,14 @@ class ReadwriteSplittingSQLRouterTest {
void setUp() {
staticRule = new ReadwriteSplittingRule("logic_db", new ReadwriteSplittingRuleConfiguration(Collections.singleton(new ReadwriteSplittingDataSourceGroupRuleConfiguration(DATASOURCE_NAME,
WRITE_DATASOURCE, Collections.singletonList(READ_DATASOURCE), "")), Collections.emptyMap()), mock(ComputeNodeInstanceContext.class));
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
sqlRouter = (ReadwriteSplittingSQLRouter) OrderedSPILoader.getServices(SQLRouter.class, Collections.singleton(staticRule)).get(staticRule);
}
@Test
void assertDecorateRouteContextToPrimaryDataSource() {
RouteContext actual = mockRouteContext();
- QueryContext queryContext =
- new QueryContext(mock(SQLStatementContext.class), "", Collections.emptyList(), new HintValueContext(), mockConnectionContext(), mock(ShardingSphereMetaData.class));
+ QueryContext queryContext = new QueryContext(sqlStatementContext, "", Collections.emptyList(), new HintValueContext(), mockConnectionContext(), mock(ShardingSphereMetaData.class));
RuleMetaData ruleMetaData = new RuleMetaData(Collections.singleton(staticRule));
ShardingSphereDatabase database = new ShardingSphereDatabase("foo_db",
mock(DatabaseType.class), mock(ResourceMetaData.class, RETURNS_DEEP_STUBS), ruleMetaData, Collections.emptyList());
diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowDMLStatementDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowDMLStatementDataSourceMappingsRetriever.java
index 156c49b8744..d82f8fda6e4 100644
--- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowDMLStatementDataSourceMappingsRetriever.java
+++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowDMLStatementDataSourceMappingsRetriever.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.infra.binder.context.statement.type.dml.DeleteS
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.UpdateStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.session.query.QueryContext;
import org.apache.shardingsphere.shadow.route.retriever.ShadowDataSourceMappingsRetriever;
import org.apache.shardingsphere.shadow.route.retriever.dml.table.column.ShadowColumnDataSourceMappingsRetriever;
@@ -50,7 +49,7 @@ public final class ShadowDMLStatementDataSourceMappingsRetriever implements Shad
private final ShadowColumnDataSourceMappingsRetriever shadowColumnDataSourceMappingsRetriever;
public ShadowDMLStatementDataSourceMappingsRetriever(final QueryContext queryContext, final ShadowOperationType operationType) {
- tableNames = ((TableContextAvailable) queryContext.getSqlStatementContext()).getTablesContext().getTableNames();
+ tableNames = queryContext.getSqlStatementContext().getTablesContext().getTableNames();
tableHintDataSourceMappingsRetriever = new ShadowTableHintDataSourceMappingsRetriever(operationType, queryContext.getHintValueContext().isShadow());
shadowColumnDataSourceMappingsRetriever = createShadowDataSourceMappingsRetriever(queryContext);
}
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/audit/DMLShardingConditionsShardingAuditAlgorithm.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/audit/DMLShardingConditionsShardingAuditAlgorithm.java
index bd487c7f18a..cec49f40702 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/audit/DMLShardingConditionsShardingAuditAlgorithm.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/audit/DMLShardingConditionsShardingAuditAlgorithm.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.sharding.algorithm.audit;
import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
@@ -41,7 +40,7 @@ public final class DMLShardingConditionsShardingAuditAlgorithm implements Shardi
public void check(final SQLStatementContext sqlStatementContext, final List<Object> params, final RuleMetaData globalRuleMetaData, final ShardingSphereDatabase database) {
if (sqlStatementContext.getSqlStatement() instanceof DMLStatement) {
ShardingRule rule = database.getRuleMetaData().getSingleRule(ShardingRule.class);
- if (((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames().stream().anyMatch(rule::isShardingTable)) {
+ if (sqlStatementContext.getTablesContext().getTableNames().stream().anyMatch(rule::isShardingTable)) {
ShardingSpherePreconditions.checkNotEmpty(
new ShardingConditionEngine(globalRuleMetaData, database, rule).createShardingConditions(sqlStatementContext, params), DMLWithoutShardingKeyException::new);
}
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/auditor/ShardingSQLAuditor.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/auditor/ShardingSQLAuditor.java
index 9fb5aaddf43..2981404c201 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/auditor/ShardingSQLAuditor.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/auditor/ShardingSQLAuditor.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.sharding.auditor;
import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.executor.audit.SQLAuditor;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
@@ -29,7 +28,6 @@ import org.apache.shardingsphere.sharding.constant.ShardingOrder;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import java.util.Collection;
-import java.util.Collections;
import java.util.LinkedList;
/**
@@ -60,11 +58,8 @@ public final class ShardingSQLAuditor implements SQLAuditor<ShardingRule> {
}
private Collection<ShardingAuditStrategyConfiguration> getShardingAuditStrategies(final SQLStatementContext sqlStatementContext, final ShardingRule rule) {
- if (!(sqlStatementContext instanceof TableContextAvailable)) {
- return Collections.emptyList();
- }
Collection<ShardingAuditStrategyConfiguration> result = new LinkedList<>();
- for (String each : ((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames()) {
+ for (String each : sqlStatementContext.getTablesContext().getTableNames()) {
rule.findShardingTable(each).ifPresent(optional -> result.add(rule.getAuditStrategyConfiguration(optional)));
}
return result;
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableChecker.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableChecker.java
index 5cf27b9cb46..3a9b219cb2e 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableChecker.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/cache/checker/ShardingRouteCacheableChecker.java
@@ -28,7 +28,6 @@ import org.apache.shardingsphere.infra.binder.context.statement.type.dml.DeleteS
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.UpdateStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.session.query.QueryContext;
import org.apache.shardingsphere.sharding.api.config.cache.ShardingCacheOptionsConfiguration;
@@ -145,7 +144,7 @@ public final class ShardingRouteCacheableChecker {
}
private ShardingRouteCacheableCheckResult checkUpdateOrDeleteCacheable(final SQLStatementContext sqlStatementContext, final List<Object> params) {
- Collection<String> tableNames = ((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames();
+ Collection<String> tableNames = sqlStatementContext.getTablesContext().getTableNames();
if (1 != tableNames.size()) {
return new ShardingRouteCacheableCheckResult(false, Collections.emptyList());
}
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/common/ShardingSupportedCommonChecker.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/common/ShardingSupportedCommonChecker.java
index 8bbf6b26f4c..bc2ad3c4c56 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/common/ShardingSupportedCommonChecker.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/common/ShardingSupportedCommonChecker.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.sharding.checker.sql.common;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.exception.dialect.exception.syntax.table.NoSuchTableException;
import org.apache.shardingsphere.infra.exception.dialect.exception.syntax.table.TableExistsException;
@@ -88,7 +87,7 @@ public final class ShardingSupportedCommonChecker {
* @param sqlStatementContext sqlStatementContext
*/
public static void checkMultipleTable(final ShardingRule shardingRule, final SQLStatementContext sqlStatementContext) {
- Collection<String> tableNames = ((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames();
+ Collection<String> tableNames = sqlStatementContext.getTablesContext().getTableNames();
boolean isAllShardingTables = shardingRule.isAllShardingTables(tableNames) && (1 == tableNames.size() || shardingRule.isAllConfigBindingTables(tableNames));
boolean isAllSingleTables = !shardingRule.containsShardingTable(tableNames);
ShardingSpherePreconditions.checkState(isAllShardingTables || isAllSingleTables, () -> new DMLWithMultipleShardingTablesException(tableNames));
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dal/ShardingDALResultMerger.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dal/ShardingDALResultMerger.java
index e28b5020899..97a2b6510e1 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dal/ShardingDALResultMerger.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/merge/dal/ShardingDALResultMerger.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.sharding.merge.dal;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
import org.apache.shardingsphere.infra.merge.engine.merger.ResultMerger;
@@ -81,8 +80,6 @@ public final class ShardingDALResultMerger implements ResultMerger {
private ShardingSphereSchema getSchema(final SQLStatementContext sqlStatementContext, final ShardingSphereDatabase database) {
String defaultSchemaName = new DatabaseTypeRegistry(sqlStatementContext.getDatabaseType()).getDefaultSchemaName(database.getName());
- return sqlStatementContext instanceof TableContextAvailable
- ? ((TableContextAvailable) sqlStatementContext).getTablesContext().getSchemaName().map(database::getSchema).orElseGet(() -> database.getSchema(defaultSchemaName))
- : database.getSchema(defaultSchemaName);
+ return sqlStatementContext.getTablesContext().getSchemaName().map(database::getSchema).orElseGet(() -> database.getSchema(defaultSchemaName));
}
}
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/context/ShardingSQLRewriteContextDecorator.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/context/ShardingSQLRewriteContextDecorator.java
index e0e483b096c..66b7769c0c3 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/context/ShardingSQLRewriteContextDecorator.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/context/ShardingSQLRewriteContextDecorator.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementCont
import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.AlterIndexStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.DropIndexStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.CursorAvailable;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.rewrite.context.SQLRewriteContext;
import org.apache.shardingsphere.infra.rewrite.context.SQLRewriteContextDecorator;
@@ -67,10 +66,7 @@ public final class ShardingSQLRewriteContextDecorator implements SQLRewriteConte
}
private boolean containsShardingTable(final ShardingRule rule, final SQLStatementContext sqlStatementContext) {
- if (!(sqlStatementContext instanceof TableContextAvailable)) {
- return false;
- }
- for (SimpleTableSegment each : ((TableContextAvailable) sqlStatementContext).getTablesContext().getSimpleTables()) {
+ for (SimpleTableSegment each : sqlStatementContext.getTablesContext().getSimpleTables()) {
if (rule.isShardingTable(each.getTableName().getIdentifier().getValue())) {
return true;
}
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ShardingTableTokenGenerator.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ShardingTableTokenGenerator.java
index bea38e2d7a9..c683a2fcbaa 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ShardingTableTokenGenerator.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ShardingTableTokenGenerator.java
@@ -22,7 +22,6 @@ import lombok.Setter;
import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
import org.apache.shardingsphere.infra.binder.context.aware.CursorAware;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.generator.CollectionSQLTokenGenerator;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.generator.aware.RouteContextAware;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.SQLToken;
@@ -33,7 +32,6 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment;
import java.util.Collection;
-import java.util.Collections;
import java.util.LinkedList;
/**
@@ -54,18 +52,12 @@ public final class ShardingTableTokenGenerator implements CollectionSQLTokenGene
}
private boolean isAllBindingTables(final SQLStatementContext sqlStatementContext) {
- Collection<String> shardingLogicTableNames = sqlStatementContext instanceof TableContextAvailable
- ? rule.getShardingLogicTableNames(((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames())
- : Collections.emptyList();
+ Collection<String> shardingLogicTableNames = rule.getShardingLogicTableNames(sqlStatementContext.getTablesContext().getTableNames());
return shardingLogicTableNames.size() > 1 && rule.isAllConfigBindingTables(shardingLogicTableNames);
}
@Override
public Collection<SQLToken> generateSQLTokens(final SQLStatementContext sqlStatementContext) {
- return sqlStatementContext instanceof TableContextAvailable ? generateSQLTokens((TableContextAvailable) sqlStatementContext) : Collections.emptyList();
- }
-
- private Collection<SQLToken> generateSQLTokens(final TableContextAvailable sqlStatementContext) {
Collection<SQLToken> result = new LinkedList<>();
for (SimpleTableSegment each : sqlStatementContext.getTablesContext().getSimpleTables()) {
TableNameSegment tableNameSegment = each.getTableName();
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/ConstraintToken.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/ConstraintToken.java
index 74a2d877650..848360166fa 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/ConstraintToken.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/ConstraintToken.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.sharding.rewrite.token.pojo;
import lombok.Getter;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.RouteUnitAware;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.SQLToken;
import org.apache.shardingsphere.infra.rewrite.sql.token.common.pojo.Substitutable;
@@ -59,7 +58,7 @@ public final class ConstraintToken extends SQLToken implements Substitutable, Ro
private String getConstraintValue(final RouteUnit routeUnit) {
StringBuilder result = new StringBuilder(identifier.getValue());
Map<String, String> logicAndActualTables = ShardingTokenUtils.getLogicAndActualTableMap(routeUnit, sqlStatementContext, shardingRule);
- ((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames().stream().findFirst().map(logicAndActualTables::get).ifPresent(optional -> result.append('_').append(optional));
+ sqlStatementContext.getTablesContext().getTableNames().stream().findFirst().map(logicAndActualTables::get).ifPresent(optional -> result.append('_').append(optional));
return result.toString();
}
}
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/ShardingTokenUtils.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/ShardingTokenUtils.java
index 4c153d1709b..f4e77e66660 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/ShardingTokenUtils.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/ShardingTokenUtils.java
@@ -21,13 +21,11 @@ import com.cedarsoftware.util.CaseInsensitiveMap;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.route.context.RouteMapper;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import java.util.Collection;
-import java.util.Collections;
import java.util.Map;
/**
@@ -45,11 +43,8 @@ public final class ShardingTokenUtils {
* @return key is logic table name, values is actual table belong to this data source
*/
public static Map<String, String> getLogicAndActualTableMap(final RouteUnit routeUnit, final SQLStatementContext sqlStatementContext, final ShardingRule rule) {
- if (!(sqlStatementContext instanceof TableContextAvailable)) {
- return Collections.emptyMap();
- }
- Collection<String> tableNames = ((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames();
- Map<String, String> result = new CaseInsensitiveMap<>(tableNames.size(), 1F);
+ Collection<String> tableNames = sqlStatementContext.getTablesContext().getTableNames();
+ Map<String, String> result = new CaseInsensitiveMap<>();
for (RouteMapper each : routeUnit.getTableMappers()) {
result.put(each.getLogicName(), each.getActualName());
result.putAll(rule.getLogicAndActualTablesFromBindingTable(routeUnit.getDataSourceMapper().getLogicName(), each.getLogicName(), each.getActualName(), tableNames));
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/checker/util/ShardingRouteContextCheckUtils.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/checker/util/ShardingRouteContextCheckUtils.java
index 83bfae8ebf3..eb4af5c7459 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/checker/util/ShardingRouteContextCheckUtils.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/checker/util/ShardingRouteContextCheckUtils.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.sharding.route.engine.checker.util;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.infra.route.context.RouteMapper;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
@@ -104,7 +103,7 @@ public final class ShardingRouteContextCheckUtils {
public static Optional<ShardingConditions> createShardingConditions(final SQLStatementContext sqlStatementContext, final ShardingRule shardingRule,
final Collection<ColumnAssignmentSegment> assignments, final List<Object> params) {
Collection<ShardingConditionValue> values = new LinkedList<>();
- String tableName = ((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames().iterator().next();
+ String tableName = sqlStatementContext.getTablesContext().getTableNames().iterator().next();
for (ColumnAssignmentSegment each : assignments) {
String shardingColumn = each.getColumns().get(0).getIdentifier().getValue();
if (shardingRule.findShardingColumn(shardingColumn, tableName).isPresent()) {
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/ShardingConditions.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/ShardingConditions.java
index 9b4dd031b51..c9e56631729 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/ShardingConditions.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/condition/ShardingConditions.java
@@ -22,7 +22,6 @@ import lombok.ToString;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.sharding.api.config.strategy.sharding.HintShardingStrategyConfiguration;
import org.apache.shardingsphere.sharding.api.config.strategy.sharding.NoneShardingStrategyConfiguration;
import org.apache.shardingsphere.sharding.api.config.strategy.sharding.ShardingStrategyConfiguration;
@@ -115,7 +114,7 @@ public final class ShardingConditions {
boolean selectContainsSubquery = sqlStatementContext instanceof SelectStatementContext && ((SelectStatementContext) sqlStatementContext).isContainsSubquery();
boolean insertSelectContainsSubquery = sqlStatementContext instanceof InsertStatementContext && null != ((InsertStatementContext) sqlStatementContext).getInsertSelectContext()
&& ((InsertStatementContext) sqlStatementContext).getInsertSelectContext().getSelectStatementContext().isContainsSubquery();
- return (selectContainsSubquery || insertSelectContainsSubquery) && !rule.getShardingLogicTableNames(((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames()).isEmpty();
+ return (selectContainsSubquery || insertSelectContainsSubquery) && !rule.getShardingLogicTableNames(sqlStatementContext.getTablesContext().getTableNames()).isEmpty();
}
private boolean isSubqueryContainsShardingCondition(final List<ShardingCondition> conditions, final SQLStatementContext sqlStatementContext) {
@@ -184,8 +183,8 @@ public final class ShardingConditions {
}
private Collection<String> findHintStrategyTables(final SQLStatementContext sqlStatementContext) {
- Collection<String> result = new HashSet<>(((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames().size(), 1F);
- for (String each : ((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames()) {
+ Collection<String> result = new HashSet<>(sqlStatementContext.getTablesContext().getTableNames().size(), 1F);
+ for (String each : sqlStatementContext.getTablesContext().getTableNames()) {
Optional<ShardingTable> shardingTable = rule.findShardingTable(each);
if (!shardingTable.isPresent()) {
continue;
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactory.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactory.java
index 98785ed07ef..4d70e2d03d3 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactory.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactory.java
@@ -21,7 +21,6 @@ import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.CursorAvailable;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.hint.HintValueContext;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -49,7 +48,6 @@ import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DropPro
import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.DMLStatement;
import java.util.Collection;
-import java.util.Collections;
/**
* Sharding routing engine factory.
@@ -120,19 +118,14 @@ public final class ShardingRouteEngineFactory {
}
private static boolean isDCLForSingleTable(final SQLStatementContext sqlStatementContext) {
- if (sqlStatementContext instanceof TableContextAvailable) {
- TableContextAvailable tableSegmentsAvailable = (TableContextAvailable) sqlStatementContext;
- return 1 == tableSegmentsAvailable.getTablesContext().getSimpleTables().size()
- && !"*".equals(tableSegmentsAvailable.getTablesContext().getSimpleTables().iterator().next().getTableName().getIdentifier().getValue());
- }
- return false;
+ return 1 == sqlStatementContext.getTablesContext().getSimpleTables().size()
+ && !"*".equals(sqlStatementContext.getTablesContext().getSimpleTables().iterator().next().getTableName().getIdentifier().getValue());
}
private static ShardingRouteEngine getDQLRouteEngine(final ShardingRule rule, final SQLStatementContext sqlStatementContext,
final QueryContext queryContext, final ShardingConditions shardingConditions, final Collection<String> logicTableNames,
final ConfigurationProperties props) {
- Collection<String> tableNames =
- sqlStatementContext instanceof TableContextAvailable ? ((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames() : Collections.emptyList();
+ Collection<String> tableNames = sqlStatementContext.getTablesContext().getTableNames();
if (sqlStatementContext.getSqlStatement() instanceof DMLStatement && shardingConditions.isAlwaysFalse() || tableNames.isEmpty()) {
return new ShardingUnicastRouteEngine(sqlStatementContext, tableNames, queryContext.getConnectionContext());
}
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/standard/ShardingStandardRouteEngine.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/standard/ShardingStandardRouteEngine.java
index c1a15cba4a5..8753601e035 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/standard/ShardingStandardRouteEngine.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/standard/ShardingStandardRouteEngine.java
@@ -19,15 +19,14 @@ package org.apache.shardingsphere.sharding.route.engine.type.standard;
import com.cedarsoftware.util.CaseInsensitiveSet;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.datanode.DataNode;
+import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.hint.HintManager;
import org.apache.shardingsphere.infra.hint.HintValueContext;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.infra.route.context.RouteMapper;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
-import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import org.apache.shardingsphere.sharding.api.config.strategy.sharding.HintShardingStrategyConfiguration;
import org.apache.shardingsphere.sharding.api.config.strategy.sharding.ShardingStrategyConfiguration;
import org.apache.shardingsphere.sharding.exception.algorithm.MismatchedShardingDataSourceRouteInfoException;
@@ -112,7 +111,7 @@ public final class ShardingStandardRouteEngine implements ShardingRouteEngine {
}
private boolean isRoutingBySQLHint() {
- Collection<String> tableNames = ((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames();
+ Collection<String> tableNames = sqlStatementContext.getTablesContext().getTableNames();
for (String each : tableNames) {
if (hintValueContext.containsHintShardingValue(each)) {
return true;
@@ -202,7 +201,7 @@ public final class ShardingStandardRouteEngine implements ShardingRouteEngine {
private List<ShardingConditionValue> getDatabaseShardingValuesFromSQLHint() {
Collection<Comparable<?>> shardingValues = new LinkedList<>();
- Collection<String> tableNames = ((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames();
+ Collection<String> tableNames = sqlStatementContext.getTablesContext().getTableNames();
for (String each : tableNames) {
if (each.equals(logicTableName) && hintValueContext.containsHintShardingDatabaseValue(each)) {
shardingValues.addAll(hintValueContext.getHintShardingDatabaseValue(each));
@@ -220,7 +219,7 @@ public final class ShardingStandardRouteEngine implements ShardingRouteEngine {
private List<ShardingConditionValue> getTableShardingValuesFromSQLHint() {
Collection<Comparable<?>> shardingValues = new LinkedList<>();
- Collection<String> tableNames = ((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames();
+ Collection<String> tableNames = sqlStatementContext.getTablesContext().getTableNames();
for (String each : tableNames) {
if (each.equals(logicTableName) && hintValueContext.containsHintShardingTableValue(each)) {
shardingValues.addAll(hintValueContext.getHintShardingTableValue(each));
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/audit/DMLShardingConditionsShardingAuditAlgorithmTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/audit/DMLShardingConditionsShardingAuditAlgorithmTest.java
index 3d3ec03b253..a6919aa6713 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/audit/DMLShardingConditionsShardingAuditAlgorithmTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/audit/DMLShardingConditionsShardingAuditAlgorithmTest.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.sharding.algorithm.audit;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
@@ -39,7 +38,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.withSettings;
@ExtendWith(MockitoExtension.class)
class DMLShardingConditionsShardingAuditAlgorithmTest {
@@ -61,8 +59,8 @@ class DMLShardingConditionsShardingAuditAlgorithmTest {
@Test
void assertCheckWithoutShardingTable() {
- SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, withSettings().extraInterfaces(TableContextAvailable.class).defaultAnswer(RETURNS_DEEP_STUBS));
- when(((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames()).thenReturn(Collections.singleton("foo_tbl"));
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(Collections.singleton("foo_tbl"));
when(sqlStatementContext.getSqlStatement()).thenReturn(mock(DMLStatement.class));
when(database.getRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(mock(ShardingRule.class))));
assertDoesNotThrow(() -> shardingAuditAlgorithm.check(sqlStatementContext, Collections.emptyList(), mock(RuleMetaData.class), database));
@@ -70,8 +68,8 @@ class DMLShardingConditionsShardingAuditAlgorithmTest {
@Test
void assertCheckWithShardingTable() {
- SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, withSettings().extraInterfaces(TableContextAvailable.class).defaultAnswer(RETURNS_DEEP_STUBS));
- when(((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames()).thenReturn(Collections.singleton("foo_tbl"));
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(Collections.singleton("foo_tbl"));
when(sqlStatementContext.getSqlStatement()).thenReturn(mock(DMLStatement.class));
ShardingRule rule = mock(ShardingRule.class);
when(rule.isShardingTable("foo_tbl")).thenReturn(true);
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/auditor/ShardingSQLAuditorTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/auditor/ShardingSQLAuditorTest.java
index 9b11ca91549..ee48d319853 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/auditor/ShardingSQLAuditorTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/auditor/ShardingSQLAuditorTest.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.sharding.auditor;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.executor.audit.SQLAuditor;
import org.apache.shardingsphere.infra.hint.HintValueContext;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
@@ -48,6 +47,7 @@ import java.util.Optional;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@@ -58,7 +58,7 @@ import static org.mockito.Mockito.when;
@MockitoSettings(strictness = Strictness.LENIENT)
class ShardingSQLAuditorTest {
- @Mock(extraInterfaces = TableContextAvailable.class, answer = Answers.RETURNS_DEEP_STUBS)
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
private SQLStatementContext sqlStatementContext;
@Mock
@@ -81,8 +81,8 @@ class ShardingSQLAuditorTest {
@BeforeEach
void setUp() {
when(hintValueContext.getDisableAuditNames()).thenReturn(Collections.singleton("foo_auditor"));
- when(((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames()).thenReturn(Collections.singletonList("foo_tbl"));
- when(((TableContextAvailable) sqlStatementContext).getTablesContext().getDatabaseName()).thenReturn(Optional.empty());
+ when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(Collections.singletonList("foo_tbl"));
+ when(sqlStatementContext.getTablesContext().getDatabaseName()).thenReturn(Optional.empty());
ShardingTable shardingTable = mock(ShardingTable.class);
when(rule.findShardingTable("foo_tbl")).thenReturn(Optional.of(shardingTable));
when(rule.getAuditStrategyConfiguration(shardingTable)).thenReturn(auditStrategy);
@@ -92,7 +92,10 @@ class ShardingSQLAuditorTest {
@Test
void assertAuditSuccessWithNotTableAvailable() {
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
QueryContext queryContext = mock(QueryContext.class);
+ when(queryContext.getSqlStatementContext()).thenReturn(sqlStatementContext);
sqlAuditor.audit(queryContext, globalRuleMetaData, database, rule);
verify(queryContext, times(0)).getHintValueContext();
}
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/cache/route/CachedShardingSQLRouterTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/cache/route/CachedShardingSQLRouterTest.java
index 2b59a35e3a2..9deec4d7475 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/cache/route/CachedShardingSQLRouterTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/cache/route/CachedShardingSQLRouterTest.java
@@ -37,8 +37,11 @@ import org.apache.shardingsphere.sharding.cache.route.cache.ShardingRouteCacheKe
import org.apache.shardingsphere.sharding.cache.route.cache.ShardingRouteCacheValue;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
import java.util.Arrays;
import java.util.Collection;
@@ -57,17 +60,19 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
class CachedShardingSQLRouterTest {
@Mock
private ShardingCache shardingCache;
- @Mock
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
private SQLStatementContext sqlStatementContext;
@Test
void assertCreateRouteContextWithSQLExceedMaxAllowedLength() {
when(shardingCache.getConfiguration()).thenReturn(new ShardingCacheConfiguration(1, null));
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
QueryContext queryContext =
new QueryContext(sqlStatementContext, "select 1", Collections.emptyList(), new HintValueContext(), mockConnectionContext(), mock(ShardingSphereMetaData.class));
Optional<RouteContext> actual = new CachedShardingSQLRouter().loadRouteContext(null, queryContext, mock(RuleMetaData.class), null, shardingCache, Collections.emptyList(), null);
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/ShardingDALResultMergerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/ShardingDALResultMergerTest.java
index f5409fa2916..692e652c014 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/ShardingDALResultMergerTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/dal/ShardingDALResultMergerTest.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.sharding.merge.dal;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.QueryResult;
import org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataMergedResult;
@@ -49,7 +48,6 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.withSettings;
@ExtendWith(MockitoExtension.class)
class ShardingDALResultMergerTest {
@@ -98,15 +96,16 @@ class ShardingDALResultMergerTest {
@Test
void assertMergeWithNotTableAvailable() throws SQLException {
- SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class);
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
when(sqlStatementContext.getDatabaseType()).thenReturn(databaseType);
assertThat(resultMerger.merge(queryResults, sqlStatementContext, mock(), mock()), instanceOf(TransparentMergedResult.class));
}
private SQLStatementContext mockSQLStatementContext(final DALStatement dalStatement) {
- SQLStatementContext result = mock(SQLStatementContext.class, withSettings().extraInterfaces(TableContextAvailable.class).defaultAnswer(RETURNS_DEEP_STUBS));
+ SQLStatementContext result = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
when(result.getSqlStatement()).thenReturn(dalStatement);
- when(((TableContextAvailable) result).getTablesContext().getSchemaName()).thenReturn(Optional.empty());
+ when(result.getTablesContext().getSchemaName()).thenReturn(Optional.empty());
when(result.getDatabaseType()).thenReturn(databaseType);
return result;
}
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ShardingTableTokenGeneratorTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ShardingTableTokenGeneratorTest.java
index 598210ccc84..f48e6b19073 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ShardingTableTokenGeneratorTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/generator/impl/ShardingTableTokenGeneratorTest.java
@@ -35,6 +35,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.Optional;
import static org.hamcrest.CoreMatchers.instanceOf;
@@ -68,7 +69,9 @@ class ShardingTableTokenGeneratorTest {
@Test
void assertIsNotGenerateSQLTokenWithNotTableAvailable() {
generator.setRouteContext(new RouteContext());
- assertFalse(generator.isGenerateSQLToken(mock(SQLStatementContext.class)));
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
+ assertFalse(generator.isGenerateSQLToken(sqlStatementContext));
}
@Test
@@ -86,12 +89,16 @@ class ShardingTableTokenGeneratorTest {
RouteContext routeContext = mock(RouteContext.class);
when(routeContext.containsTableSharding()).thenReturn(true);
generator.setRouteContext(routeContext);
- assertTrue(generator.isGenerateSQLToken(mock(SQLStatementContext.class)));
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
+ assertTrue(generator.isGenerateSQLToken(sqlStatementContext));
}
@Test
void assertGenerateSQLTokenWithNotTableAvailable() {
- assertTrue(generator.generateSQLTokens(mock(SQLStatementContext.class)).isEmpty());
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
+ assertTrue(generator.generateSQLTokens(sqlStatementContext).isEmpty());
}
@Test
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/ConstraintTokenTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/ConstraintTokenTest.java
index fb536d716ce..06b073ce91b 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/ConstraintTokenTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/ConstraintTokenTest.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.sharding.rewrite.token.pojo;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.route.context.RouteMapper;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
@@ -32,15 +31,12 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.withSettings;
class ConstraintTokenTest {
@Test
void assertToString() {
- assertThat(new ConstraintToken(0, 1, new IdentifierValue("uc"),
- mock(SQLStatementContext.class, withSettings().extraInterfaces(TableContextAvailable.class).defaultAnswer(RETURNS_DEEP_STUBS)), mock(ShardingRule.class)).toString(getRouteUnit()),
- is("uc"));
+ assertThat(new ConstraintToken(0, 1, new IdentifierValue("uc"), mock(SQLStatementContext.class, RETURNS_DEEP_STUBS), mock(ShardingRule.class)).toString(getRouteUnit()), is("uc"));
}
@Test
@@ -50,8 +46,8 @@ class ConstraintTokenTest {
}
private SQLStatementContext mockSQLStatementContext() {
- SQLStatementContext result = mock(SQLStatementContext.class, withSettings().extraInterfaces(TableContextAvailable.class).defaultAnswer(RETURNS_DEEP_STUBS));
- when(((TableContextAvailable) result).getTablesContext().getTableNames()).thenReturn(Collections.singletonList("T_ORDER"));
+ SQLStatementContext result = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(result.getTablesContext().getTableNames()).thenReturn(Collections.singletonList("T_ORDER"));
return result;
}
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/IndexTokenTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/IndexTokenTest.java
index 342664ae42c..e0e7ac8f6ee 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/IndexTokenTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/IndexTokenTest.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.sharding.rewrite.token.pojo;
-import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateIndexStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
@@ -41,26 +40,22 @@ class IndexTokenTest {
@Test
void assertToStringWithNotShardingTable() {
- IndexToken indexToken = new IndexToken(0, 0, new IdentifierValue("foo_idx"), mock(SelectStatementContext.class, RETURNS_DEEP_STUBS), mock(ShardingRule.class), mockSchema());
+ SelectStatementContext selectStatementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
+ when(selectStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
+ IndexToken indexToken = new IndexToken(0, 0, new IdentifierValue("foo_idx"), selectStatementContext, mock(ShardingRule.class), mockSchema());
assertThat(indexToken.toString(mockRouteUnit()), is("foo_idx"));
}
@Test
void assertToStringWithShardingTable() {
+ SelectStatementContext selectStatementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
+ when(selectStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
ShardingRule rule = mock(ShardingRule.class);
when(rule.isShardingTable("foo_tbl")).thenReturn(true);
- IndexToken indexToken = new IndexToken(0, 0, new IdentifierValue("foo_idx"), mock(SelectStatementContext.class, RETURNS_DEEP_STUBS), rule, mockSchema());
+ IndexToken indexToken = new IndexToken(0, 0, new IdentifierValue("foo_idx"), selectStatementContext, rule, mockSchema());
assertThat(indexToken.toString(mockRouteUnit()), is("foo_idx_foo_tbl_0"));
}
- @Test
- void assertToStringWithShardingTableButNotTableAvailable() {
- ShardingRule rule = mock(ShardingRule.class);
- when(rule.isShardingTable("foo_tbl")).thenReturn(true);
- IndexToken indexToken = new IndexToken(0, 0, new IdentifierValue("foo_idx"), mock(SQLStatementContext.class, RETURNS_DEEP_STUBS), rule, mockSchema());
- assertThat(indexToken.toString(mockRouteUnit()), is("foo_idx"));
- }
-
@Test
void assertToStringWithShardingTableAndGeneratedIndex() {
CreateIndexStatementContext sqlStatementContext = mock(CreateIndexStatementContext.class, RETURNS_DEEP_STUBS);
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/ShardingTokenUtilsTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/ShardingTokenUtilsTest.java
index b11af045a11..22e5fbd4206 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/ShardingTokenUtilsTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/pojo/ShardingTokenUtilsTest.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.sharding.rewrite.token.pojo;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.route.context.RouteMapper;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
@@ -34,13 +33,14 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.withSettings;
class ShardingTokenUtilsTest {
@Test
void assertGetLogicAndActualTablesWithNotTableAvailable() {
- Map<String, String> actual = ShardingTokenUtils.getLogicAndActualTableMap(mock(RouteUnit.class), mock(SQLStatementContext.class), mock(ShardingRule.class));
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
+ Map<String, String> actual = ShardingTokenUtils.getLogicAndActualTableMap(mock(RouteUnit.class), sqlStatementContext, mock(ShardingRule.class));
assertTrue(actual.isEmpty());
}
@@ -56,8 +56,8 @@ class ShardingTokenUtilsTest {
}
private static SQLStatementContext mockSQLStatementContext() {
- SQLStatementContext result = mock(SQLStatementContext.class, withSettings().extraInterfaces(TableContextAvailable.class).defaultAnswer(RETURNS_DEEP_STUBS));
- when(((TableContextAvailable) result).getTablesContext().getTableNames()).thenReturn(Arrays.asList("foo_tbl", "bar_tbl"));
+ SQLStatementContext result = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(result.getTablesContext().getTableNames()).thenReturn(Arrays.asList("foo_tbl", "bar_tbl"));
return result;
}
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactoryTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactoryTest.java
index a41f50f2aa7..9a16dda3786 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactoryTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactoryTest.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementCont
import org.apache.shardingsphere.infra.binder.context.statement.TableAvailableSQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CursorStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.hint.HintValueContext;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
@@ -83,7 +82,7 @@ class ShardingRouteEngineFactoryTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private ShardingSphereDatabase database;
- @Mock(extraInterfaces = TableContextAvailable.class)
+ @Mock
private SQLStatementContext sqlStatementContext;
@Mock
@@ -98,7 +97,7 @@ class ShardingRouteEngineFactoryTest {
@BeforeEach
void setUp() {
- when(((TableContextAvailable) sqlStatementContext).getTablesContext()).thenReturn(tablesContext);
+ when(sqlStatementContext.getTablesContext()).thenReturn(tablesContext);
when(tablesContext.getTableNames()).thenReturn(tableNames);
}
@@ -179,7 +178,7 @@ class ShardingRouteEngineFactoryTest {
SQLStatement sqlStatement = mock(SQLStatement.class);
when(sqlStatementContext.getSqlStatement()).thenReturn(sqlStatement);
tableNames.add("");
- when(shardingRule.getShardingLogicTableNames(((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames())).thenReturn(tableNames);
+ when(shardingRule.getShardingLogicTableNames(sqlStatementContext.getTablesContext().getTableNames())).thenReturn(tableNames);
when(shardingRule.isAllShardingTables(tableNames)).thenReturn(true);
QueryContext queryContext = new QueryContext(sqlStatementContext, "", Collections.emptyList(), new HintValueContext(), mockConnectionContext(), mock(ShardingSphereMetaData.class));
ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, database, queryContext, shardingConditions, tableNames, props);
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingTableBroadcastRouteEngineTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingTableBroadcastRouteEngineTest.java
index 9524e08f59e..e97f49a7bf2 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingTableBroadcastRouteEngineTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/broadcast/ShardingTableBroadcastRouteEngineTest.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.sharding.route.engine.type.broadcast;
import org.apache.groovy.util.Maps;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.DropIndexStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -50,7 +49,6 @@ import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.withSettings;
class ShardingTableBroadcastRouteEngineTest {
@@ -132,8 +130,8 @@ class ShardingTableBroadcastRouteEngineTest {
}
private SQLStatementContext createSQLStatementContext(final Collection<String> tableNames) {
- SQLStatementContext result = mock(SQLStatementContext.class, withSettings().extraInterfaces(TableContextAvailable.class).defaultAnswer(RETURNS_DEEP_STUBS));
- when(((TableContextAvailable) result).getTablesContext().getTableNames()).thenReturn(tableNames);
+ SQLStatementContext result = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(result.getTablesContext().getTableNames()).thenReturn(tableNames);
return result;
}
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/ShardingStandardRouteEngineTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/ShardingStandardRouteEngineTest.java
index 5669dad8465..60c5dc80544 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/ShardingStandardRouteEngineTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/ShardingStandardRouteEngineTest.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.sharding.route.engine.type.standard;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.hint.HintManager;
import org.apache.shardingsphere.infra.hint.HintValueContext;
@@ -43,7 +42,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.withSettings;
class ShardingStandardRouteEngineTest {
@@ -101,8 +99,8 @@ class ShardingStandardRouteEngineTest {
@Test
void assertRouteByHint() {
- SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, withSettings().extraInterfaces(TableContextAvailable.class).defaultAnswer(RETURNS_DEEP_STUBS));
- when(((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames()).thenReturn(Collections.singleton("t_hint_test"));
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(Collections.singleton("t_hint_test"));
ShardingStandardRouteEngine routeEngine = createShardingStandardRouteEngine("t_hint_test",
new ShardingConditions(Collections.emptyList(), sqlStatementContext, mock(ShardingRule.class)), sqlStatementContext, new HintValueContext());
HintManager hintManager = HintManager.getInstance();
@@ -119,8 +117,8 @@ class ShardingStandardRouteEngineTest {
@Test
void assertRouteByMixedWithHintDataSource() {
- SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, withSettings().extraInterfaces(TableContextAvailable.class).defaultAnswer(RETURNS_DEEP_STUBS));
- when(((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames()).thenReturn(Collections.singleton("t_hint_ds_test"));
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(Collections.singleton("t_hint_ds_test"));
ShardingStandardRouteEngine routeEngine = createShardingStandardRouteEngine("t_hint_ds_test",
ShardingRouteEngineFixtureBuilder.createShardingConditions("t_hint_ds_test"), sqlStatementContext, new HintValueContext());
HintManager hintManager = HintManager.getInstance();
@@ -136,8 +134,8 @@ class ShardingStandardRouteEngineTest {
@Test
void assertRouteByMixedWithHintDataSourceOnly() {
- SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, withSettings().extraInterfaces(TableContextAvailable.class).defaultAnswer(RETURNS_DEEP_STUBS));
- when(((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames()).thenReturn(Collections.singleton("t_hint_ds_test"));
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(Collections.singleton("t_hint_ds_test"));
ShardingStandardRouteEngine routeEngine = createShardingStandardRouteEngine("t_hint_ds_test",
new ShardingConditions(Collections.emptyList(), sqlStatementContext, mock(ShardingRule.class)), sqlStatementContext, new HintValueContext());
HintManager hintManager = HintManager.getInstance();
@@ -157,8 +155,8 @@ class ShardingStandardRouteEngineTest {
@Test
void assertRouteByMixedWithHintTable() {
- SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, withSettings().extraInterfaces(TableContextAvailable.class).defaultAnswer(RETURNS_DEEP_STUBS));
- when(((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames()).thenReturn(Collections.singleton("t_hint_table_test"));
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(Collections.singleton("t_hint_table_test"));
ShardingStandardRouteEngine routeEngine = createShardingStandardRouteEngine("t_hint_table_test",
ShardingRouteEngineFixtureBuilder.createShardingConditions("t_hint_table_test"), sqlStatementContext, new HintValueContext());
HintManager hintManager = HintManager.getInstance();
@@ -174,8 +172,8 @@ class ShardingStandardRouteEngineTest {
@Test
void assertRouteByMixedWithHintTableOnly() {
- SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, withSettings().extraInterfaces(TableContextAvailable.class).defaultAnswer(RETURNS_DEEP_STUBS));
- when(((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames()).thenReturn(Collections.singleton("t_hint_table_test"));
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(Collections.singleton("t_hint_table_test"));
ShardingStandardRouteEngine routeEngine = createShardingStandardRouteEngine("t_hint_table_test",
new ShardingConditions(Collections.emptyList(), sqlStatementContext, mock(ShardingRule.class)), sqlStatementContext, new HintValueContext());
HintManager hintManager = HintManager.getInstance();
@@ -195,8 +193,8 @@ class ShardingStandardRouteEngineTest {
@Test
void assertRouteByIntervalTableShardingStrategyOnly() {
- SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, withSettings().extraInterfaces(TableContextAvailable.class).defaultAnswer(RETURNS_DEEP_STUBS));
- when(((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames()).thenReturn(Collections.singleton("t_interval_test"));
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(Collections.singleton("t_interval_test"));
ShardingStandardRouteEngine routeEngine = createShardingStandardRouteEngine("t_interval_test",
ShardingRouteEngineFixtureBuilder.createIntervalShardingConditions("t_interval_test"), sqlStatementContext, new HintValueContext());
RouteContext routeContext = routeEngine.route(ShardingRouteEngineFixtureBuilder.createIntervalTableShardingRule());
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/extractor/SQLStatementContextExtractor.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/extractor/SQLStatementContextExtractor.java
index 88164f91555..ebc58efbf2b 100644
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/extractor/SQLStatementContextExtractor.java
+++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/extractor/SQLStatementContextExtractor.java
@@ -27,7 +27,6 @@ import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateV
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.IndexAvailable;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.binder.context.type.WhereAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -60,8 +59,7 @@ public final class SQLStatementContextExtractor {
* @return table names
*/
public static Collection<String> getTableNames(final ShardingSphereDatabase database, final SQLStatementContext sqlStatementContext) {
- Collection<String> tableNames =
- sqlStatementContext instanceof TableContextAvailable ? ((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames() : Collections.emptyList();
+ Collection<String> tableNames = sqlStatementContext.getTablesContext().getTableNames();
if (!tableNames.isEmpty()) {
return tableNames;
}
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/SQLStatementContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/SQLStatementContext.java
index 1e71de29685..0019995fe12 100644
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/SQLStatementContext.java
+++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/SQLStatementContext.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.infra.binder.context.statement;
+import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement;
@@ -32,6 +33,13 @@ public interface SQLStatementContext {
*/
SQLStatement getSqlStatement();
+ /**
+ * Get tables context.
+ *
+ * @return tables context
+ */
+ TablesContext getTablesContext();
+
/**
* Get database type.
*
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/TableAvailableSQLStatementContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/TableAvailableSQLStatementContext.java
index 95ac707d289..256ff44c01b 100644
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/TableAvailableSQLStatementContext.java
+++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/TableAvailableSQLStatementContext.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.infra.binder.context.statement;
import lombok.Getter;
import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement;
@@ -30,7 +29,7 @@ import java.util.Collection;
* Table available SQL statement context.
*/
@Getter
-public final class TableAvailableSQLStatementContext extends CommonSQLStatementContext implements TableContextAvailable {
+public final class TableAvailableSQLStatementContext extends CommonSQLStatementContext {
private final TablesContext tablesContext;
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/UnknownSQLStatementContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/UnknownSQLStatementContext.java
index 3869b65c5a5..3317e166528 100644
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/UnknownSQLStatementContext.java
+++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/UnknownSQLStatementContext.java
@@ -17,9 +17,12 @@
package org.apache.shardingsphere.infra.binder.context.statement;
+import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement;
+import java.util.Collections;
+
/**
* Unknown SQL statement context.
*/
@@ -28,4 +31,9 @@ public final class UnknownSQLStatementContext extends CommonSQLStatementContext
public UnknownSQLStatementContext(final DatabaseType databaseType, final SQLStatement sqlStatement) {
super(databaseType, sqlStatement);
}
+
+ @Override
+ public TablesContext getTablesContext() {
+ return new TablesContext(Collections.emptyList());
+ }
}
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dal/ExplainStatementContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dal/ExplainStatementContext.java
index afdf4720256..988ac14e61c 100644
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dal/ExplainStatementContext.java
+++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dal/ExplainStatementContext.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContex
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContextFactory;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.sql.parser.statement.core.extractor.TableExtractor;
@@ -36,7 +35,7 @@ import java.util.List;
* Explain statement context.
*/
@Getter
-public final class ExplainStatementContext extends CommonSQLStatementContext implements TableContextAvailable {
+public final class ExplainStatementContext extends CommonSQLStatementContext {
private final TablesContext tablesContext;
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dal/ShowColumnsStatementContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dal/ShowColumnsStatementContext.java
index fcd99a468c4..44a40027a27 100644
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dal/ShowColumnsStatementContext.java
+++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dal/ShowColumnsStatementContext.java
@@ -21,7 +21,6 @@ import lombok.Getter;
import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.RemoveAvailable;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.sql.parser.statement.core.segment.SQLSegment;
import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowColumnsStatement;
@@ -33,7 +32,7 @@ import java.util.LinkedList;
* Show columns statement context.
*/
@Getter
-public final class ShowColumnsStatementContext extends CommonSQLStatementContext implements TableContextAvailable, RemoveAvailable {
+public final class ShowColumnsStatementContext extends CommonSQLStatementContext implements RemoveAvailable {
private final TablesContext tablesContext;
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dal/ShowIndexStatementContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dal/ShowIndexStatementContext.java
index f78b30a976e..159718dfce9 100644
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dal/ShowIndexStatementContext.java
+++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dal/ShowIndexStatementContext.java
@@ -21,7 +21,6 @@ import lombok.Getter;
import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.RemoveAvailable;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.sql.parser.statement.core.segment.SQLSegment;
import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowIndexStatement;
@@ -33,7 +32,7 @@ import java.util.LinkedList;
* Show index statement context.
*/
@Getter
-public final class ShowIndexStatementContext extends CommonSQLStatementContext implements TableContextAvailable, RemoveAvailable {
+public final class ShowIndexStatementContext extends CommonSQLStatementContext implements RemoveAvailable {
private final TablesContext tablesContext;
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dal/ShowTableStatusStatementContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dal/ShowTableStatusStatementContext.java
index a047f202323..25fa525b4b1 100644
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dal/ShowTableStatusStatementContext.java
+++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dal/ShowTableStatusStatementContext.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.infra.binder.context.statement.type.dal;
+import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.RemoveAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
@@ -24,6 +25,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.SQLSegment;
import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowTableStatusStatement;
import java.util.Collection;
+import java.util.Collections;
import java.util.LinkedList;
/**
@@ -40,6 +42,11 @@ public final class ShowTableStatusStatementContext extends CommonSQLStatementCon
return (ShowTableStatusStatement) super.getSqlStatement();
}
+ @Override
+ public TablesContext getTablesContext() {
+ return new TablesContext(Collections.emptyList());
+ }
+
@Override
public Collection<SQLSegment> getRemoveSegments() {
Collection<SQLSegment> result = new LinkedList<>();
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dal/ShowTablesStatementContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dal/ShowTablesStatementContext.java
index b49332dd631..72dcc39cbc0 100644
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dal/ShowTablesStatementContext.java
+++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dal/ShowTablesStatementContext.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.infra.binder.context.statement.type.dal;
import lombok.Getter;
+import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.RemoveAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
@@ -25,6 +26,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.SQLSegment;
import org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowTablesStatement;
import java.util.Collection;
+import java.util.Collections;
import java.util.LinkedList;
/**
@@ -42,6 +44,11 @@ public final class ShowTablesStatementContext extends CommonSQLStatementContext
return (ShowTablesStatement) super.getSqlStatement();
}
+ @Override
+ public TablesContext getTablesContext() {
+ return new TablesContext(Collections.emptyList());
+ }
+
@Override
public Collection<SQLSegment> getRemoveSegments() {
Collection<SQLSegment> result = new LinkedList<>();
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/AlterIndexStatementContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/AlterIndexStatementContext.java
index 1634ed95136..1dd94546b6e 100644
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/AlterIndexStatementContext.java
+++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/AlterIndexStatementContext.java
@@ -21,7 +21,6 @@ import lombok.Getter;
import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.IndexAvailable;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment;
@@ -35,7 +34,7 @@ import java.util.LinkedList;
* Alter index statement context.
*/
@Getter
-public final class AlterIndexStatementContext extends CommonSQLStatementContext implements TableContextAvailable, IndexAvailable {
+public final class AlterIndexStatementContext extends CommonSQLStatementContext implements IndexAvailable {
private final TablesContext tablesContext;
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/AlterTableStatementContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/AlterTableStatementContext.java
index 6484ebb4262..04177d4c406 100644
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/AlterTableStatementContext.java
+++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/AlterTableStatementContext.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContex
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.ConstraintAvailable;
import org.apache.shardingsphere.infra.binder.context.type.IndexAvailable;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.ColumnDefinitionSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.alter.AddColumnDefinitionSegment;
@@ -45,7 +44,7 @@ import java.util.LinkedList;
* Alter table statement context.
*/
@Getter
-public final class AlterTableStatementContext extends CommonSQLStatementContext implements TableContextAvailable, IndexAvailable, ConstraintAvailable {
+public final class AlterTableStatementContext extends CommonSQLStatementContext implements IndexAvailable, ConstraintAvailable {
private final TablesContext tablesContext;
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/AlterViewStatementContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/AlterViewStatementContext.java
index 4bd3e360675..98c04211b1e 100644
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/AlterViewStatementContext.java
+++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/AlterViewStatementContext.java
@@ -21,7 +21,6 @@ import lombok.Getter;
import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.binder.context.type.WhereAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
@@ -44,7 +43,7 @@ import java.util.Optional;
* Alter view statement context.
*/
@Getter
-public final class AlterViewStatementContext extends CommonSQLStatementContext implements TableContextAvailable, WhereAvailable {
+public final class AlterViewStatementContext extends CommonSQLStatementContext implements WhereAvailable {
private final TablesContext tablesContext;
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CloseStatementContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CloseStatementContext.java
index 8b18ac2085d..3a3fd75db9c 100644
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CloseStatementContext.java
+++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CloseStatementContext.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.infra.binder.context.aware.CursorAware;
import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.CursorAvailable;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.binder.context.type.WhereAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.cursor.CursorNameSegment;
@@ -39,12 +38,12 @@ import java.util.Optional;
* Close statement context.
*/
@Getter
-public final class CloseStatementContext extends CommonSQLStatementContext implements CursorAvailable, TableContextAvailable, WhereAvailable, CursorAware {
-
- private CursorStatementContext cursorStatementContext;
+public final class CloseStatementContext extends CommonSQLStatementContext implements CursorAvailable, WhereAvailable, CursorAware {
private TablesContext tablesContext;
+ private CursorStatementContext cursorStatementContext;
+
public CloseStatementContext(final DatabaseType databaseType, final CloseStatement sqlStatement) {
super(databaseType, sqlStatement);
tablesContext = new TablesContext(Collections.emptyList());
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CreateIndexStatementContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CreateIndexStatementContext.java
index dfdd2cca08b..eaeda82ab39 100644
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CreateIndexStatementContext.java
+++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CreateIndexStatementContext.java
@@ -21,7 +21,6 @@ import lombok.Getter;
import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.IndexAvailable;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.database.schema.util.IndexMetaDataUtils;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexNameSegment;
@@ -37,7 +36,7 @@ import java.util.Collections;
* Create index statement context.
*/
@Getter
-public final class CreateIndexStatementContext extends CommonSQLStatementContext implements TableContextAvailable, IndexAvailable {
+public final class CreateIndexStatementContext extends CommonSQLStatementContext implements IndexAvailable {
private final TablesContext tablesContext;
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CreateTableStatementContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CreateTableStatementContext.java
index d29ec8f6914..441e984aaf3 100644
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CreateTableStatementContext.java
+++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CreateTableStatementContext.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContex
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.ConstraintAvailable;
import org.apache.shardingsphere.infra.binder.context.type.IndexAvailable;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.column.ColumnDefinitionSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.constraint.ConstraintDefinitionSegment;
@@ -40,7 +39,7 @@ import java.util.stream.Collectors;
* Create table statement context.
*/
@Getter
-public final class CreateTableStatementContext extends CommonSQLStatementContext implements TableContextAvailable, IndexAvailable, ConstraintAvailable {
+public final class CreateTableStatementContext extends CommonSQLStatementContext implements IndexAvailable, ConstraintAvailable {
private final TablesContext tablesContext;
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CreateViewStatementContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CreateViewStatementContext.java
index 14f7c557422..67e5a1aed71 100644
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CreateViewStatementContext.java
+++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CreateViewStatementContext.java
@@ -21,7 +21,6 @@ import lombok.Getter;
import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.binder.context.type.WhereAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
@@ -40,7 +39,7 @@ import java.util.List;
* Create view statement context.
*/
@Getter
-public final class CreateViewStatementContext extends CommonSQLStatementContext implements TableContextAvailable, WhereAvailable {
+public final class CreateViewStatementContext extends CommonSQLStatementContext implements WhereAvailable {
private final TablesContext tablesContext;
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CursorStatementContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CursorStatementContext.java
index c2bb75ed924..6700092f97c 100644
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CursorStatementContext.java
+++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/CursorStatementContext.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContex
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.CursorAvailable;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.binder.context.type.WhereAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
@@ -44,7 +43,9 @@ import java.util.Optional;
* Cursor statement context.
*/
@Getter
-public final class CursorStatementContext extends CommonSQLStatementContext implements CursorAvailable, TableContextAvailable, WhereAvailable {
+public final class CursorStatementContext extends CommonSQLStatementContext implements CursorAvailable, WhereAvailable {
+
+ private final TablesContext tablesContext;
private final Collection<WhereSegment> whereSegments = new LinkedList<>();
@@ -52,8 +53,6 @@ public final class CursorStatementContext extends CommonSQLStatementContext impl
private final Collection<BinaryOperationExpression> joinConditions = new LinkedList<>();
- private final TablesContext tablesContext;
-
private final SelectStatementContext selectStatementContext;
public CursorStatementContext(final ShardingSphereMetaData metaData, final DatabaseType databaseType,
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/DropIndexStatementContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/DropIndexStatementContext.java
index e2edbebe5c0..761c090432e 100644
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/DropIndexStatementContext.java
+++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/DropIndexStatementContext.java
@@ -21,7 +21,6 @@ import lombok.Getter;
import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.IndexAvailable;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexSegment;
import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment;
@@ -34,7 +33,7 @@ import java.util.Collections;
* Drop index statement context.
*/
@Getter
-public final class DropIndexStatementContext extends CommonSQLStatementContext implements TableContextAvailable, IndexAvailable {
+public final class DropIndexStatementContext extends CommonSQLStatementContext implements IndexAvailable {
private final TablesContext tablesContext;
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/FetchStatementContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/FetchStatementContext.java
index cde8d2b1b88..5eb5123c2e4 100644
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/FetchStatementContext.java
+++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/FetchStatementContext.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.infra.binder.context.aware.CursorAware;
import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.CursorAvailable;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.binder.context.type.WhereAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.cursor.CursorNameSegment;
@@ -39,12 +38,12 @@ import java.util.Optional;
* Fetch statement context.
*/
@Getter
-public final class FetchStatementContext extends CommonSQLStatementContext implements CursorAvailable, TableContextAvailable, WhereAvailable, CursorAware {
-
- private CursorStatementContext cursorStatementContext;
+public final class FetchStatementContext extends CommonSQLStatementContext implements CursorAvailable, WhereAvailable, CursorAware {
private TablesContext tablesContext;
+ private CursorStatementContext cursorStatementContext;
+
public FetchStatementContext(final DatabaseType databaseType, final FetchStatement sqlStatement) {
super(databaseType, sqlStatement);
tablesContext = new TablesContext(Collections.emptyList());
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/MoveStatementContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/MoveStatementContext.java
index 5f0d1192c8a..f9531fdf167 100644
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/MoveStatementContext.java
+++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/ddl/MoveStatementContext.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.infra.binder.context.aware.CursorAware;
import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.CursorAvailable;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.binder.context.type.WhereAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.cursor.CursorNameSegment;
@@ -39,12 +38,12 @@ import java.util.Optional;
* Move statement context.
*/
@Getter
-public final class MoveStatementContext extends CommonSQLStatementContext implements CursorAvailable, TableContextAvailable, WhereAvailable, CursorAware {
-
- private CursorStatementContext cursorStatementContext;
+public final class MoveStatementContext extends CommonSQLStatementContext implements CursorAvailable, WhereAvailable, CursorAware {
private TablesContext tablesContext;
+ private CursorStatementContext cursorStatementContext;
+
public MoveStatementContext(final DatabaseType databaseType, final MoveStatement sqlStatement) {
super(databaseType, sqlStatement);
tablesContext = new TablesContext(Collections.emptyList());
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dml/DeleteStatementContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dml/DeleteStatementContext.java
index a30d3341cb7..cbfcf71bcfd 100644
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dml/DeleteStatementContext.java
+++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dml/DeleteStatementContext.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.infra.binder.context.statement.type.dml;
import lombok.Getter;
import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.binder.context.type.WhereAvailable;
import org.apache.shardingsphere.infra.binder.context.type.WithAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
@@ -44,7 +43,7 @@ import java.util.Optional;
* Delete statement context.
*/
@Getter
-public final class DeleteStatementContext extends CommonSQLStatementContext implements TableContextAvailable, WhereAvailable, WithAvailable {
+public final class DeleteStatementContext extends CommonSQLStatementContext implements WhereAvailable, WithAvailable {
private final TablesContext tablesContext;
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dml/InsertStatementContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dml/InsertStatementContext.java
index ebff997f9ba..94736359df8 100644
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dml/InsertStatementContext.java
+++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dml/InsertStatementContext.java
@@ -27,7 +27,6 @@ import org.apache.shardingsphere.infra.binder.context.segment.insert.values.Inse
import org.apache.shardingsphere.infra.binder.context.segment.insert.values.OnDuplicateUpdateContext;
import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.binder.context.type.WhereAvailable;
import org.apache.shardingsphere.infra.binder.context.type.WithAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
@@ -68,7 +67,7 @@ import java.util.concurrent.atomic.AtomicInteger;
/**
* Insert SQL statement context.
*/
-public final class InsertStatementContext extends CommonSQLStatementContext implements TableContextAvailable, ParameterAware, WhereAvailable, WithAvailable {
+public final class InsertStatementContext extends CommonSQLStatementContext implements ParameterAware, WhereAvailable, WithAvailable {
private final ShardingSphereMetaData metaData;
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dml/SelectStatementContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dml/SelectStatementContext.java
index e2f61db1dd5..82b93c35576 100644
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dml/SelectStatementContext.java
+++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dml/SelectStatementContext.java
@@ -38,7 +38,6 @@ import org.apache.shardingsphere.infra.binder.context.segment.select.projection.
import org.apache.shardingsphere.infra.binder.context.segment.select.projection.impl.SubqueryProjection;
import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.binder.context.type.WhereAvailable;
import org.apache.shardingsphere.infra.binder.context.type.WithAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
@@ -90,7 +89,7 @@ import java.util.stream.Collectors;
*/
@Getter
@Setter
-public final class SelectStatementContext extends CommonSQLStatementContext implements TableContextAvailable, WhereAvailable, ParameterAware, WithAvailable {
+public final class SelectStatementContext extends CommonSQLStatementContext implements WhereAvailable, ParameterAware, WithAvailable {
private final TablesContext tablesContext;
diff --git a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dml/UpdateStatementContext.java b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dml/UpdateStatementContext.java
index 77fe989328f..8b1b2cc1b61 100644
--- a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dml/UpdateStatementContext.java
+++ b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/type/dml/UpdateStatementContext.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.infra.binder.context.statement.type.dml;
import lombok.Getter;
import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.binder.context.type.WhereAvailable;
import org.apache.shardingsphere.infra.binder.context.type.WithAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
@@ -42,7 +41,7 @@ import java.util.Optional;
* Update SQL statement context.
*/
@Getter
-public final class UpdateStatementContext extends CommonSQLStatementContext implements TableContextAvailable, WhereAvailable, WithAvailable {
+public final class UpdateStatementContext extends CommonSQLStatementContext implements WhereAvailable, WithAvailable {
private final TablesContext tablesContext;
diff --git a/infra/checker/src/main/java/org/apache/shardingsphere/infra/checker/SupportedSQLCheckEngine.java b/infra/checker/src/main/java/org/apache/shardingsphere/infra/checker/SupportedSQLCheckEngine.java
index 9bf0ced7a15..923c794020d 100644
--- a/infra/checker/src/main/java/org/apache/shardingsphere/infra/checker/SupportedSQLCheckEngine.java
+++ b/infra/checker/src/main/java/org/apache/shardingsphere/infra/checker/SupportedSQLCheckEngine.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.infra.checker;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
@@ -55,8 +54,6 @@ public final class SupportedSQLCheckEngine {
private ShardingSphereSchema getCurrentSchema(final SQLStatementContext sqlStatementContext, final ShardingSphereDatabase database) {
ShardingSphereSchema defaultSchema = database.getSchema(new DatabaseTypeRegistry(sqlStatementContext.getDatabaseType()).getDefaultSchemaName(database.getName()));
- return sqlStatementContext instanceof TableContextAvailable
- ? ((TableContextAvailable) sqlStatementContext).getTablesContext().getSchemaName().map(database::getSchema).orElse(defaultSchema)
- : defaultSchema;
+ return sqlStatementContext.getTablesContext().getSchemaName().map(database::getSchema).orElse(defaultSchema);
}
}
diff --git a/infra/context/src/test/java/org/apache/shardingsphere/infra/connection/kernel/KernelProcessorTest.java b/infra/context/src/test/java/org/apache/shardingsphere/infra/connection/kernel/KernelProcessorTest.java
index 3f29d0e231f..91de8801d50 100644
--- a/infra/context/src/test/java/org/apache/shardingsphere/infra/connection/kernel/KernelProcessorTest.java
+++ b/infra/context/src/test/java/org/apache/shardingsphere/infra/connection/kernel/KernelProcessorTest.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.infra.connection.kernel;
-import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
@@ -60,7 +59,8 @@ class KernelProcessorTest {
@Test
void assertGenerateExecutionContext() {
DatabaseType databaseType = TypedSPILoader.getService(DatabaseType.class, "FIXTURE");
- SQLStatementContext sqlStatementContext = mock(CommonSQLStatementContext.class);
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
when(sqlStatementContext.getSqlStatement()).thenReturn(mock(SelectStatement.class));
when(sqlStatementContext.getDatabaseType()).thenReturn(databaseType);
ConnectionContext connectionContext = mock(ConnectionContext.class);
diff --git a/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/context/ExecutionContextBuilder.java b/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/context/ExecutionContextBuilder.java
index 3d40508f8a5..157503fbd0a 100644
--- a/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/context/ExecutionContextBuilder.java
+++ b/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/context/ExecutionContextBuilder.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.infra.executor.sql.context;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.rewrite.engine.result.GenericSQLRewriteResult;
import org.apache.shardingsphere.infra.rewrite.engine.result.RouteSQLRewriteResult;
@@ -77,9 +76,7 @@ public final class ExecutionContextBuilder {
}
private static List<RouteMapper> getGenericTableRouteMappers(final SQLStatementContext sqlStatementContext) {
- return sqlStatementContext instanceof TableContextAvailable
- ? ((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames().stream().map(each -> new RouteMapper(each, each)).collect(Collectors.toList())
- : Collections.emptyList();
+ return sqlStatementContext.getTablesContext().getTableNames().stream().map(each -> new RouteMapper(each, each)).collect(Collectors.toList());
}
private static List<RouteMapper> getRouteTableRouteMappers(final Collection<RouteMapper> tableMappers) {
diff --git a/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/context/ExecutionContextBuilderTest.java b/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/context/ExecutionContextBuilderTest.java
index 36906373449..30e7f953c85 100644
--- a/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/context/ExecutionContextBuilderTest.java
+++ b/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/context/ExecutionContextBuilderTest.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.infra.executor.sql.context;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
@@ -49,7 +48,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.withSettings;
class ExecutionContextBuilderTest {
@@ -70,7 +68,9 @@ class ExecutionContextBuilderTest {
when(resourceMetaData.getAllInstanceDataSourceNames()).thenReturn(Arrays.asList(firstDataSourceName, "lastDataSourceName"));
RuleMetaData ruleMetaData = new RuleMetaData(Collections.emptyList());
ShardingSphereDatabase database = new ShardingSphereDatabase("foo_db", mock(DatabaseType.class), resourceMetaData, ruleMetaData, buildSchemas());
- Collection<ExecutionUnit> actual = ExecutionContextBuilder.build(database, genericSQLRewriteResult, mock(SQLStatementContext.class));
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
+ Collection<ExecutionUnit> actual = ExecutionContextBuilder.build(database, genericSQLRewriteResult, sqlStatementContext);
Collection<ExecutionUnit> expected = Collections.singletonList(new ExecutionUnit(firstDataSourceName, new SQLUnit(sql, Collections.singletonList("foo_param"))));
assertThat(actual, is(expected));
}
@@ -84,7 +84,7 @@ class ExecutionContextBuilderTest {
when(resourceMetaData.getAllInstanceDataSourceNames()).thenReturn(Arrays.asList(firstDataSourceName, "lastDataSourceName"));
RuleMetaData ruleMetaData = new RuleMetaData(Collections.emptyList());
ShardingSphereDatabase database = new ShardingSphereDatabase("foo_db", mock(DatabaseType.class), resourceMetaData, ruleMetaData, buildSchemas());
- SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, withSettings().extraInterfaces(TableContextAvailable.class).defaultAnswer(RETURNS_DEEP_STUBS));
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
Collection<ExecutionUnit> actual = ExecutionContextBuilder.build(database, genericSQLRewriteResult, sqlStatementContext);
Collection<ExecutionUnit> expected = Collections.singletonList(new ExecutionUnit(firstDataSourceName, new SQLUnit(sql, Collections.singletonList("foo_param"))));
assertThat(actual, is(expected));
diff --git a/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/log/SQLLoggerTest.java b/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/log/SQLLoggerTest.java
index 5922c2ade71..b0dbf342ae8 100644
--- a/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/log/SQLLoggerTest.java
+++ b/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/log/SQLLoggerTest.java
@@ -46,6 +46,7 @@ import java.util.stream.Collectors;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -74,11 +75,14 @@ class SQLLoggerTest {
ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class);
when(metaData.containsDatabase("foo_db")).thenReturn(true);
when(metaData.getDatabase("foo_db")).thenReturn(mock(ShardingSphereDatabase.class));
- queryContext = new QueryContext(mock(SQLStatementContext.class), SQL, Collections.emptyList(), new HintValueContext(), connectionContext, metaData);
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
+ queryContext = new QueryContext(sqlStatementContext, SQL, Collections.emptyList(), new HintValueContext(), connectionContext, metaData);
executionUnits = prepareExecutionUnits(Arrays.asList("db1", "db2", "db3"));
appenderList.clear();
}
+ @SuppressWarnings("CollectionWithoutInitialCapacity")
private Collection<ExecutionUnit> prepareExecutionUnits(final Collection<String> dataSourceNames) {
return dataSourceNames.stream().map(each -> new ExecutionUnit(each, new SQLUnit(SQL, new ArrayList<>()))).collect(Collectors.toList());
}
diff --git a/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/token/common/generator/generic/RemoveTokenGenerator.java b/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/token/common/generator/generic/RemoveTokenGenerator.java
index 3c50a7861c3..cc38083878e 100644
--- a/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/token/common/generator/generic/RemoveTokenGenerator.java
+++ b/infra/rewrite/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/token/common/generator/generic/RemoveTokenGenerator.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.infra.rewrite.sql.token.common.generator.gener
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.IndexAvailable;
import org.apache.shardingsphere.infra.binder.context.type.RemoveAvailable;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.database.core.metadata.database.metadata.DialectDatabaseMetaData;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
@@ -46,7 +45,7 @@ public final class RemoveTokenGenerator implements CollectionSQLTokenGenerator<S
if (sqlStatementContext instanceof RemoveAvailable && !((RemoveAvailable) sqlStatementContext).getRemoveSegments().isEmpty()) {
return true;
}
- if (sqlStatementContext instanceof TableContextAvailable && !((TableContextAvailable) sqlStatementContext).getTablesContext().getSimpleTables().isEmpty()) {
+ if (!sqlStatementContext.getTablesContext().getSimpleTables().isEmpty()) {
return true;
}
return sqlStatementContext instanceof IndexAvailable && !((IndexAvailable) sqlStatementContext).getIndexes().isEmpty();
@@ -58,8 +57,8 @@ public final class RemoveTokenGenerator implements CollectionSQLTokenGenerator<S
if (sqlStatementContext instanceof RemoveAvailable && !((RemoveAvailable) sqlStatementContext).getRemoveSegments().isEmpty()) {
result.addAll(generateRemoveAvailableSQLTokens(((RemoveAvailable) sqlStatementContext).getRemoveSegments()));
}
- if (sqlStatementContext instanceof TableContextAvailable && !((TableContextAvailable) sqlStatementContext).getTablesContext().getSimpleTables().isEmpty()) {
- result.addAll(generateTableAvailableSQLTokens((TableContextAvailable) sqlStatementContext, sqlStatementContext.getDatabaseType()));
+ if (!sqlStatementContext.getTablesContext().getSimpleTables().isEmpty()) {
+ result.addAll(generateTableAvailableSQLTokens(sqlStatementContext, sqlStatementContext.getDatabaseType()));
}
if (sqlStatementContext instanceof IndexAvailable && !((IndexAvailable) sqlStatementContext).getIndexes().isEmpty()) {
result.addAll(generateIndexAvailableSQLTokens((IndexAvailable) sqlStatementContext));
@@ -71,9 +70,9 @@ public final class RemoveTokenGenerator implements CollectionSQLTokenGenerator<S
return removeSegments.stream().map(each -> new RemoveToken(each.getStartIndex(), each.getStopIndex())).collect(Collectors.toList());
}
- private Collection<RemoveToken> generateTableAvailableSQLTokens(final TableContextAvailable tableAvailable, final DatabaseType databaseType) {
+ private Collection<RemoveToken> generateTableAvailableSQLTokens(final SQLStatementContext sqlStatementContext, final DatabaseType databaseType) {
Collection<RemoveToken> result = new LinkedList<>();
- for (SimpleTableSegment each : tableAvailable.getTablesContext().getSimpleTables()) {
+ for (SimpleTableSegment each : sqlStatementContext.getTablesContext().getSimpleTables()) {
if (!each.getOwner().isPresent()) {
continue;
}
diff --git a/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntryTest.java b/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntryTest.java
index 7de54af9cf3..ff800ca263a 100644
--- a/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntryTest.java
+++ b/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/SQLRewriteEntryTest.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.infra.rewrite;
-import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.hint.HintValueContext;
@@ -47,6 +47,7 @@ import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -70,7 +71,8 @@ class SQLRewriteEntryTest {
QueryContext result = mock(QueryContext.class);
when(result.getSql()).thenReturn("SELECT ?");
when(result.getParameters()).thenReturn(Collections.singletonList(1));
- CommonSQLStatementContext sqlStatementContext = mock(CommonSQLStatementContext.class);
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
when(sqlStatementContext.getDatabaseType()).thenReturn(databaseType);
when(result.getSqlStatementContext()).thenReturn(sqlStatementContext);
when(result.getHintValueContext()).thenReturn(new HintValueContext());
diff --git a/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/context/SQLRewriteContextTest.java b/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/context/SQLRewriteContextTest.java
index 9262c00ef57..f4c11f2d139 100644
--- a/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/context/SQLRewriteContextTest.java
+++ b/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/context/SQLRewriteContextTest.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.infra.rewrite.context;
-import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.hint.HintValueContext;
@@ -32,6 +32,7 @@ import org.apache.shardingsphere.infra.session.query.QueryContext;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
@@ -50,15 +51,17 @@ import static org.mockito.Mockito.when;
@MockitoSettings(strictness = Strictness.LENIENT)
class SQLRewriteContextTest {
- @Mock
- private CommonSQLStatementContext sqlStatementContext;
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private SQLStatementContext sqlStatementContext;
@Mock
private SQLToken sqlToken;
+ @SuppressWarnings("rawtypes")
@Mock
private OptionalSQLTokenGenerator optionalSQLTokenGenerator;
+ @SuppressWarnings("rawtypes")
@Mock
private CollectionSQLTokenGenerator collectionSQLTokenGenerator;
@@ -71,6 +74,7 @@ class SQLRewriteContextTest {
@SuppressWarnings("unchecked")
@BeforeEach
void setUp() {
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
when(optionalSQLTokenGenerator.generateSQLToken(sqlStatementContext)).thenReturn(sqlToken);
when(collectionSQLTokenGenerator.generateSQLTokens(sqlStatementContext)).thenReturn(Collections.singleton(sqlToken));
when(database.getName()).thenReturn("foo_db");
diff --git a/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/engine/GenericSQLRewriteEngineTest.java b/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/engine/GenericSQLRewriteEngineTest.java
index 2f8258bf020..fe0b35c9b0c 100644
--- a/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/engine/GenericSQLRewriteEngineTest.java
+++ b/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/engine/GenericSQLRewriteEngineTest.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.infra.rewrite.engine;
-import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.hint.HintValueContext;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -51,7 +51,8 @@ class GenericSQLRewriteEngineTest {
when(database.getProtocolType()).thenReturn(databaseType);
Map<String, StorageUnit> storageUnits = mockStorageUnits(databaseType);
when(database.getResourceMetaData().getStorageUnits()).thenReturn(storageUnits);
- CommonSQLStatementContext sqlStatementContext = mock(CommonSQLStatementContext.class);
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
when(sqlStatementContext.getDatabaseType()).thenReturn(databaseType);
QueryContext queryContext = mockQueryContext(sqlStatementContext);
GenericSQLRewriteResult actual = new GenericSQLRewriteEngine(rule, database, mock(RuleMetaData.class)).rewrite(new SQLRewriteContext(database, queryContext), queryContext);
@@ -59,7 +60,7 @@ class GenericSQLRewriteEngineTest {
assertThat(actual.getSqlRewriteUnit().getParameters(), is(Collections.emptyList()));
}
- private QueryContext mockQueryContext(final CommonSQLStatementContext sqlStatementContext) {
+ private QueryContext mockQueryContext(final SQLStatementContext sqlStatementContext) {
QueryContext result = mock(QueryContext.class, RETURNS_DEEP_STUBS);
when(result.getSqlStatementContext()).thenReturn(sqlStatementContext);
when(result.getSql()).thenReturn("SELECT 1");
@@ -72,7 +73,8 @@ class GenericSQLRewriteEngineTest {
void assertRewriteStorageTypeIsEmpty() {
SQLTranslatorRule rule = new SQLTranslatorRule(new DefaultSQLTranslatorRuleConfigurationBuilder().build());
ShardingSphereDatabase database = new ShardingSphereDatabase("foo_db", mock(), new ResourceMetaData(Collections.emptyMap()), mock(), Collections.singleton(new ShardingSphereSchema("test")));
- CommonSQLStatementContext sqlStatementContext = mock(CommonSQLStatementContext.class);
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
DatabaseType databaseType = mock(DatabaseType.class);
when(sqlStatementContext.getDatabaseType()).thenReturn(databaseType);
QueryContext queryContext = mockQueryContext(sqlStatementContext);
diff --git a/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/engine/RouteSQLRewriteEngineTest.java b/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/engine/RouteSQLRewriteEngineTest.java
index b019528d274..0f23e9bcb4d 100644
--- a/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/engine/RouteSQLRewriteEngineTest.java
+++ b/infra/rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/engine/RouteSQLRewriteEngineTest.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.infra.rewrite.engine;
-import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
+import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
@@ -54,7 +54,8 @@ class RouteSQLRewriteEngineTest {
void assertRewriteWithStandardParameterBuilder() {
DatabaseType databaseType = mock(DatabaseType.class);
ShardingSphereDatabase database = mockDatabase(databaseType);
- CommonSQLStatementContext sqlStatementContext = mock(CommonSQLStatementContext.class);
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
when(sqlStatementContext.getDatabaseType()).thenReturn(databaseType);
QueryContext queryContext = mockQueryContext(sqlStatementContext, "SELECT ?");
SQLRewriteContext sqlRewriteContext = new SQLRewriteContext(database, queryContext);
@@ -68,7 +69,7 @@ class RouteSQLRewriteEngineTest {
assertThat(actual.getSqlRewriteUnits().get(routeUnit).getParameters(), is(Collections.singletonList(1)));
}
- private QueryContext mockQueryContext(final CommonSQLStatementContext sqlStatementContext, final String sql) {
+ private QueryContext mockQueryContext(final SQLStatementContext sqlStatementContext, final String sql) {
QueryContext result = mock(QueryContext.class, RETURNS_DEEP_STUBS);
when(result.getSqlStatementContext()).thenReturn(sqlStatementContext);
when(result.getSql()).thenReturn(sql);
diff --git a/infra/route/core/src/test/java/org/apache/shardingsphere/infra/route/engine/SQLRouteEngineTest.java b/infra/route/core/src/test/java/org/apache/shardingsphere/infra/route/engine/SQLRouteEngineTest.java
index 51745cb3a55..d497d76a0ea 100644
--- a/infra/route/core/src/test/java/org/apache/shardingsphere/infra/route/engine/SQLRouteEngineTest.java
+++ b/infra/route/core/src/test/java/org/apache/shardingsphere/infra/route/engine/SQLRouteEngineTest.java
@@ -38,6 +38,8 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.junit.jupiter.MockitoSettings;
+import org.mockito.quality.Strictness;
import javax.sql.DataSource;
import java.util.Arrays;
@@ -54,6 +56,7 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
+@MockitoSettings(strictness = Strictness.LENIENT)
class SQLRouteEngineTest {
private final SQLRouteEngine sqlRouteEngine =
@@ -65,7 +68,7 @@ class SQLRouteEngineTest {
@Mock
private ShardingSphereMetaData metaData;
- @Mock
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
private CommonSQLStatementContext sqlStatementContext;
@Mock
@@ -79,6 +82,7 @@ class SQLRouteEngineTest {
storageUnits.put("ds_0", mock(StorageUnit.class));
storageUnits.put("ds_1", mock(StorageUnit.class));
when(database.getResourceMetaData().getStorageUnits()).thenReturn(storageUnits);
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
connectionContext.setCurrentDatabaseName("foo_db");
}
diff --git a/infra/route/core/src/test/java/org/apache/shardingsphere/infra/route/engine/tableless/TablelessRouteEngineFactoryTest.java b/infra/route/core/src/test/java/org/apache/shardingsphere/infra/route/engine/tableless/TablelessRouteEngineFactoryTest.java
index 8cb29fd25c2..babdfe7b469 100644
--- a/infra/route/core/src/test/java/org/apache/shardingsphere/infra/route/engine/tableless/TablelessRouteEngineFactoryTest.java
+++ b/infra/route/core/src/test/java/org/apache/shardingsphere/infra/route/engine/tableless/TablelessRouteEngineFactoryTest.java
@@ -21,7 +21,6 @@ import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContex
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CloseStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.hint.HintValueContext;
@@ -68,7 +67,7 @@ class TablelessRouteEngineFactoryTest {
private final DatabaseType databaseType = TypedSPILoader.getService(DatabaseType.class, "FIXTURE");
- @Mock(extraInterfaces = TableContextAvailable.class)
+ @Mock
private SQLStatementContext sqlStatementContext;
@Mock
@@ -80,7 +79,7 @@ class TablelessRouteEngineFactoryTest {
@BeforeEach
void setUp() {
when(sqlStatementContext.getDatabaseType()).thenReturn(databaseType);
- when(((TableContextAvailable) sqlStatementContext).getTablesContext()).thenReturn(tablesContext);
+ when(sqlStatementContext.getTablesContext()).thenReturn(tablesContext);
when(tablesContext.getTableNames()).thenReturn(new LinkedList<>());
}
diff --git a/infra/session/src/main/java/org/apache/shardingsphere/infra/session/query/QueryContext.java b/infra/session/src/main/java/org/apache/shardingsphere/infra/session/query/QueryContext.java
index c563d40519b..0d8e080807e 100644
--- a/infra/session/src/main/java/org/apache/shardingsphere/infra/session/query/QueryContext.java
+++ b/infra/session/src/main/java/org/apache/shardingsphere/infra/session/query/QueryContext.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.infra.session.query;
import com.google.common.base.Joiner;
import lombok.Getter;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.exception.dialect.exception.syntax.database.NoDatabaseSelectedException;
import org.apache.shardingsphere.infra.exception.dialect.exception.syntax.database.UnknownDatabaseException;
@@ -74,11 +73,8 @@ public final class QueryContext {
}
private Collection<String> getUsedDatabaseNames(final SQLStatementContext sqlStatementContext, final ConnectionContext connectionContext) {
- if (sqlStatementContext instanceof TableContextAvailable) {
- Collection<String> result = ((TableContextAvailable) sqlStatementContext).getTablesContext().getDatabaseNames();
- return result.isEmpty() ? getCurrentDatabaseNames(connectionContext) : result;
- }
- return getCurrentDatabaseNames(connectionContext);
+ Collection<String> result = sqlStatementContext.getTablesContext().getDatabaseNames();
+ return result.isEmpty() ? getCurrentDatabaseNames(connectionContext) : result;
}
private Collection<String> getCurrentDatabaseNames(final ConnectionContext connectionContext) {
diff --git a/infra/session/src/test/java/org/apache/shardingsphere/infra/session/query/QueryContextTest.java b/infra/session/src/test/java/org/apache/shardingsphere/infra/session/query/QueryContextTest.java
index c3edc83c216..70bc8c08260 100644
--- a/infra/session/src/test/java/org/apache/shardingsphere/infra/session/query/QueryContextTest.java
+++ b/infra/session/src/test/java/org/apache/shardingsphere/infra/session/query/QueryContextTest.java
@@ -32,6 +32,7 @@ import java.util.Optional;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -45,26 +46,30 @@ class QueryContextTest {
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
when(metaData.containsDatabase("foo_db")).thenReturn(true);
when(metaData.getDatabase("foo_db")).thenReturn(database);
- QueryContext actual = new QueryContext(mock(SQLStatementContext.class), "SELECT 1", Collections.emptyList(), mock(HintValueContext.class), connectionContext, metaData);
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
+ QueryContext actual = new QueryContext(sqlStatementContext, "SELECT 1", Collections.emptyList(), mock(HintValueContext.class), connectionContext, metaData);
assertThat(actual.getUsedDatabase(), is(database));
}
@Test
void assertGetUsedDatabaseWhenNoDatabaseSelected() {
- SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class);
ConnectionContext connectionContext = mock(ConnectionContext.class);
ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class);
when(connectionContext.getCurrentDatabaseName()).thenReturn(Optional.empty());
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
QueryContext queryContext = new QueryContext(sqlStatementContext, "SELECT 1", Collections.emptyList(), mock(HintValueContext.class), connectionContext, metaData);
assertThrows(NoDatabaseSelectedException.class, queryContext::getUsedDatabase);
}
@Test
void assertGetUsedDatabaseWhenUseUnknownDatabase() {
- SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class);
ConnectionContext connectionContext = mock(ConnectionContext.class);
ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class);
when(connectionContext.getCurrentDatabaseName()).thenReturn(Optional.of("unknown_db"));
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
QueryContext queryContext = new QueryContext(sqlStatementContext, "SELECT 1", Collections.emptyList(), mock(HintValueContext.class), connectionContext, metaData);
assertThrows(UnknownDatabaseException.class, queryContext::getUsedDatabase);
}
diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/batch/preparedstatement/BatchPreparedStatementExecutor.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/batch/preparedstatement/BatchPreparedStatementExecutor.java
index b50e2708c88..8ba266b2c67 100644
--- a/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/batch/preparedstatement/BatchPreparedStatementExecutor.java
+++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/batch/preparedstatement/BatchPreparedStatementExecutor.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.driver.executor.engine.batch.preparedstatement
import lombok.Getter;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroup;
import org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroupContext;
@@ -153,11 +152,8 @@ public final class BatchPreparedStatementExecutor {
}
private boolean isNeedAccumulate(final SQLStatementContext sqlStatementContext) {
- if (!(sqlStatementContext instanceof TableContextAvailable)) {
- return false;
- }
for (DataNodeRuleAttribute each : database.getRuleMetaData().getAttributes(DataNodeRuleAttribute.class)) {
- if (each.isNeedAccumulate(((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames())) {
+ if (each.isNeedAccumulate(sqlStatementContext.getTablesContext().getTableNames())) {
return true;
}
}
diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/pushdown/jdbc/DriverJDBCPushDownExecuteUpdateExecutor.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/pushdown/jdbc/DriverJDBCPushDownExecuteUpdateExecutor.java
index a29d16ae1f6..9beb454ec9a 100644
--- a/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/pushdown/jdbc/DriverJDBCPushDownExecuteUpdateExecutor.java
+++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/pushdown/jdbc/DriverJDBCPushDownExecuteUpdateExecutor.java
@@ -24,7 +24,6 @@ import org.apache.shardingsphere.driver.executor.callback.replay.StatementReplay
import org.apache.shardingsphere.driver.executor.engine.transaction.DriverTransactionalExecutor;
import org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.core.metadata.database.metadata.option.transaction.DialectTransactionOption;
import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
@@ -144,12 +143,9 @@ public final class DriverJDBCPushDownExecuteUpdateExecutor {
}
private boolean isNeedAccumulate(final Collection<ShardingSphereRule> rules, final SQLStatementContext sqlStatementContext) {
- if (!(sqlStatementContext instanceof TableContextAvailable)) {
- return false;
- }
for (ShardingSphereRule each : rules) {
Optional<DataNodeRuleAttribute> ruleAttribute = each.getAttributes().findAttribute(DataNodeRuleAttribute.class);
- if (ruleAttribute.isPresent() && ruleAttribute.get().isNeedAccumulate(((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames())) {
+ if (ruleAttribute.isPresent() && ruleAttribute.get().isNeedAccumulate(sqlStatementContext.getTablesContext().getTableNames())) {
return true;
}
}
diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
index 68425465025..7428d6b9e7b 100644
--- a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
+++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java
@@ -32,7 +32,6 @@ import org.apache.shardingsphere.infra.binder.context.aware.ParameterAware;
import org.apache.shardingsphere.infra.binder.context.segment.insert.keygen.GeneratedKeyContext;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.InsertStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.binder.engine.SQLBindEngine;
import org.apache.shardingsphere.infra.database.core.keygen.GeneratedKeyColumnProvider;
import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader;
@@ -143,9 +142,7 @@ public final class ShardingSpherePreparedStatement extends AbstractPreparedState
DatabaseType databaseType = metaData.getDatabase(connection.getCurrentDatabaseName()).getProtocolType();
SQLStatement sqlStatement = metaData.getGlobalRuleMetaData().getSingleRule(SQLParserRule.class).getSQLParserEngine(databaseType).parse(sql, true);
sqlStatementContext = new SQLBindEngine(metaData, connection.getCurrentDatabaseName(), hintValueContext).bind(databaseType, sqlStatement, Collections.emptyList());
- String usedDatabaseName = sqlStatementContext instanceof TableContextAvailable
- ? ((TableContextAvailable) sqlStatementContext).getTablesContext().getDatabaseName().orElse(connection.getCurrentDatabaseName())
- : connection.getCurrentDatabaseName();
+ String usedDatabaseName = sqlStatementContext.getTablesContext().getDatabaseName().orElse(connection.getCurrentDatabaseName());
connection.getDatabaseConnectionManager().getConnectionContext().setCurrentDatabaseName(connection.getCurrentDatabaseName());
usedDatabase = metaData.getDatabase(usedDatabaseName);
statementOption = returnGeneratedKeys ? new StatementOption(true, columns) : new StatementOption(resultSetType, resultSetConcurrency, resultSetHoldability);
@@ -376,11 +373,8 @@ public final class ShardingSpherePreparedStatement extends AbstractPreparedState
@Override
public boolean isAccumulate() {
- if (!(sqlStatementContext instanceof TableContextAvailable)) {
- return false;
- }
for (DataNodeRuleAttribute each : usedDatabase.getRuleMetaData().getAttributes(DataNodeRuleAttribute.class)) {
- if (each.isNeedAccumulate(((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames())) {
+ if (each.isNeedAccumulate(sqlStatementContext.getTablesContext().getTableNames())) {
return true;
}
}
diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
index 8b1109597d4..77e79d4e395 100644
--- a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
+++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java
@@ -31,7 +31,6 @@ import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
import org.apache.shardingsphere.infra.binder.context.segment.insert.keygen.GeneratedKeyContext;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.InsertStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.binder.engine.SQLBindEngine;
import org.apache.shardingsphere.infra.database.core.keygen.GeneratedKeyColumnProvider;
import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader;
@@ -267,9 +266,7 @@ public final class ShardingSphereStatement extends AbstractStatementAdapter {
handleAutoCommit(queryContext.getSqlStatementContext().getSqlStatement());
sqlStatementContext = queryContext.getSqlStatementContext();
ShardingSpherePreconditions.checkNotNull(sqlStatementContext, () -> new IllegalStateException("Statement context can not be null"));
- usedDatabaseName = sqlStatementContext instanceof TableContextAvailable
- ? ((TableContextAvailable) sqlStatementContext).getTablesContext().getDatabaseName().orElse(connection.getCurrentDatabaseName())
- : connection.getCurrentDatabaseName();
+ usedDatabaseName = sqlStatementContext.getTablesContext().getDatabaseName().orElse(connection.getCurrentDatabaseName());
connection.getDatabaseConnectionManager().getConnectionContext().setCurrentDatabaseName(connection.getCurrentDatabaseName());
clearStatements();
}
@@ -336,11 +333,8 @@ public final class ShardingSphereStatement extends AbstractStatementAdapter {
@Override
public boolean isAccumulate() {
- if (!(sqlStatementContext instanceof TableContextAvailable)) {
- return false;
- }
for (DataNodeRuleAttribute each : metaData.getDatabase(usedDatabaseName).getRuleMetaData().getAttributes(DataNodeRuleAttribute.class)) {
- if (each.isNeedAccumulate(((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames())) {
+ if (each.isNeedAccumulate(sqlStatementContext.getTablesContext().getTableNames())) {
return true;
}
}
diff --git a/jdbc/src/test/java/org/apache/shardingsphere/driver/executor/engine/batch/preparedstatement/BatchPreparedStatementExecutorTest.java b/jdbc/src/test/java/org/apache/shardingsphere/driver/executor/engine/batch/preparedstatement/BatchPreparedStatementExecutorTest.java
index bf3559615ae..69da6e4b83d 100644
--- a/jdbc/src/test/java/org/apache/shardingsphere/driver/executor/engine/batch/preparedstatement/BatchPreparedStatementExecutorTest.java
+++ b/jdbc/src/test/java/org/apache/shardingsphere/driver/executor/engine/batch/preparedstatement/BatchPreparedStatementExecutorTest.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.driver.executor.engine.batch.preparedstatement
import lombok.SneakyThrows;
import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
import org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroup;
import org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroupContext;
@@ -76,7 +75,7 @@ class BatchPreparedStatementExecutorTest {
private BatchPreparedStatementExecutor executor;
- @Mock(extraInterfaces = TableContextAvailable.class)
+ @Mock
private SQLStatementContext sqlStatementContext;
@BeforeEach
@@ -84,7 +83,7 @@ class BatchPreparedStatementExecutorTest {
SQLExecutorExceptionHandler.setExceptionThrown(true);
String processId = new UUID(ThreadLocalRandom.current().nextLong(), ThreadLocalRandom.current().nextLong()).toString().replace("-", "");
executor = new BatchPreparedStatementExecutor(mockDatabase(), new JDBCExecutor(executorEngine, mock(ConnectionContext.class, RETURNS_DEEP_STUBS)), processId);
- when(((TableContextAvailable) sqlStatementContext).getTablesContext()).thenReturn(mock(TablesContext.class));
+ when(sqlStatementContext.getTablesContext()).thenReturn(mock(TablesContext.class));
}
private ShardingSphereDatabase mockDatabase() {
diff --git a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetTest.java b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetTest.java
index 01409d04af4..6abdf9f3e72 100644
--- a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetTest.java
+++ b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/resultset/ShardingSphereResultSetTest.java
@@ -21,7 +21,6 @@ import org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConne
import org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement;
import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
@@ -60,7 +59,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.withSettings;
class ShardingSphereResultSetTest {
@@ -75,10 +73,10 @@ class ShardingSphereResultSetTest {
}
private SQLStatementContext createSQLStatementContext() {
- SQLStatementContext result = mock(SQLStatementContext.class, withSettings().extraInterfaces(TableContextAvailable.class));
+ SQLStatementContext result = mock(SQLStatementContext.class);
TablesContext tablesContext = mock(TablesContext.class);
when(tablesContext.getTableNames()).thenReturn(Collections.emptyList());
- when(((TableContextAvailable) result).getTablesContext()).thenReturn(tablesContext);
+ when(result.getTablesContext()).thenReturn(tablesContext);
return result;
}
@@ -563,7 +561,7 @@ class ShardingSphereResultSetTest {
@Test
void assertGetObjectWithShort() throws SQLException {
- short result = (short) 0;
+ short result = 0;
when(mergeResultSet.getValue(1, short.class)).thenReturn(result);
assertThat(shardingSphereResultSet.getObject(1, short.class), is(result));
when(mergeResultSet.getValue(1, Short.class)).thenReturn(result);
diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/generator/PipelineDDLDecorator.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/generator/PipelineDDLDecorator.java
index 287a0233aac..feb5559b7ce 100644
--- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/generator/PipelineDDLDecorator.java
+++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/generator/PipelineDDLDecorator.java
@@ -25,7 +25,6 @@ import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateI
import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateTableStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.ConstraintAvailable;
import org.apache.shardingsphere.infra.binder.context.type.IndexAvailable;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.binder.engine.SQLBindEngine;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.hint.HintValueContext;
@@ -85,18 +84,18 @@ public final class PipelineDDLDecorator {
Map<SQLSegment, String> replaceMap = new TreeMap<>(Comparator.comparing(SQLSegment::getStartIndex));
if (sqlStatementContext instanceof CreateTableStatementContext) {
appendFromIndexAndConstraint(replaceMap, targetTableName, sqlStatementContext);
- appendFromTable(replaceMap, targetTableName, (TableContextAvailable) sqlStatementContext);
+ appendFromTable(replaceMap, targetTableName, sqlStatementContext);
}
if (sqlStatementContext.getSqlStatement() instanceof CommentStatement) {
- appendFromTable(replaceMap, targetTableName, (TableContextAvailable) sqlStatementContext);
+ appendFromTable(replaceMap, targetTableName, sqlStatementContext);
}
if (sqlStatementContext instanceof CreateIndexStatementContext) {
- appendFromTable(replaceMap, targetTableName, (TableContextAvailable) sqlStatementContext);
+ appendFromTable(replaceMap, targetTableName, sqlStatementContext);
appendFromIndexAndConstraint(replaceMap, targetTableName, sqlStatementContext);
}
if (sqlStatementContext instanceof AlterTableStatementContext) {
appendFromIndexAndConstraint(replaceMap, targetTableName, sqlStatementContext);
- appendFromTable(replaceMap, targetTableName, (TableContextAvailable) sqlStatementContext);
+ appendFromTable(replaceMap, targetTableName, sqlStatementContext);
}
return doDecorateActualTable(replaceMap, sql);
}
@@ -106,10 +105,10 @@ public final class PipelineDDLDecorator {
}
private void appendFromIndexAndConstraint(final Map<SQLSegment, String> replaceMap, final String targetTableName, final SQLStatementContext sqlStatementContext) {
- if (!(sqlStatementContext instanceof TableContextAvailable) || ((TableContextAvailable) sqlStatementContext).getTablesContext().getSimpleTables().isEmpty()) {
+ if (sqlStatementContext.getTablesContext().getSimpleTables().isEmpty()) {
return;
}
- TableNameSegment tableNameSegment = ((TableContextAvailable) sqlStatementContext).getTablesContext().getSimpleTables().iterator().next().getTableName();
+ TableNameSegment tableNameSegment = sqlStatementContext.getTablesContext().getSimpleTables().iterator().next().getTableName();
if (!tableNameSegment.getIdentifier().getValue().equals(targetTableName)) {
if (sqlStatementContext instanceof IndexAvailable) {
for (IndexSegment each : ((IndexAvailable) sqlStatementContext).getIndexes()) {
@@ -126,7 +125,7 @@ public final class PipelineDDLDecorator {
}
}
- private void appendFromTable(final Map<SQLSegment, String> replaceMap, final String targetTableName, final TableContextAvailable sqlStatementContext) {
+ private void appendFromTable(final Map<SQLSegment, String> replaceMap, final String targetTableName, final SQLStatementContext sqlStatementContext) {
for (SimpleTableSegment each : sqlStatementContext.getTablesContext().getSimpleTables()) {
if (!targetTableName.equals(each.getTableName().getIdentifier().getValue())) {
replaceMap.put(each.getTableName(), targetTableName);
@@ -161,15 +160,15 @@ public final class PipelineDDLDecorator {
SQLStatementContext sqlStatementContext = parseSQL(databaseName, parserEngine, databaseType, sql);
if (sqlStatementContext instanceof CreateTableStatementContext || sqlStatementContext.getSqlStatement() instanceof CommentStatement
|| sqlStatementContext instanceof CreateIndexStatementContext || sqlStatementContext instanceof AlterTableStatementContext) {
- if (((TableContextAvailable) sqlStatementContext).getTablesContext().getSimpleTables().isEmpty()) {
+ if (sqlStatementContext.getTablesContext().getSimpleTables().isEmpty()) {
return sql;
}
- Optional<String> sqlSchemaName = ((TableContextAvailable) sqlStatementContext).getTablesContext().getSchemaName();
+ Optional<String> sqlSchemaName = sqlStatementContext.getTablesContext().getSchemaName();
if (sqlSchemaName.isPresent() && sqlSchemaName.get().equals(schemaName)) {
return sql;
}
Map<SQLSegment, String> replaceMap = new TreeMap<>(Comparator.comparing(SQLSegment::getStartIndex));
- TableNameSegment tableNameSegment = ((TableContextAvailable) sqlStatementContext).getTablesContext().getSimpleTables().iterator().next().getTableName();
+ TableNameSegment tableNameSegment = sqlStatementContext.getTablesContext().getSimpleTables().iterator().next().getTableName();
replaceMap.put(tableNameSegment, schemaName + "." + tableNameSegment.getIdentifier().getValue());
return doDecorateActualTable(replaceMap, sql);
}
diff --git a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/route/SingleSQLRouter.java b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/route/SingleSQLRouter.java
index a054745de40..cdec20951a9 100644
--- a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/route/SingleSQLRouter.java
+++ b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/route/SingleSQLRouter.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.single.route;
import com.cedarsoftware.util.CaseInsensitiveSet;
import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
@@ -38,7 +37,6 @@ import org.apache.shardingsphere.single.rule.SingleRule;
import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CreateTableStatement;
import java.util.Collection;
-import java.util.Collections;
import java.util.LinkedList;
/**
@@ -77,9 +75,7 @@ public final class SingleSQLRouter implements EntranceSQLRouter<SingleRule>, Dec
String logicDataSource = rule.getDataSourceNames().iterator().next();
String actualDataSource = database.getResourceMetaData().getStorageUnits().keySet().iterator().next();
RouteContext result = new RouteContext();
- Collection<String> tableNames = queryContext.getSqlStatementContext() instanceof TableContextAvailable
- ? ((TableContextAvailable) queryContext.getSqlStatementContext()).getTablesContext().getTableNames()
- : Collections.emptyList();
+ Collection<String> tableNames = queryContext.getSqlStatementContext().getTablesContext().getTableNames();
result.getRouteUnits().add(new RouteUnit(new RouteMapper(logicDataSource, actualDataSource), createTableMappers(tableNames)));
return result;
}
diff --git a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleRule.java b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleRule.java
index 14720f9a811..640eacb16fb 100644
--- a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleRule.java
+++ b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/rule/SingleRule.java
@@ -21,7 +21,6 @@ import com.cedarsoftware.util.CaseInsensitiveSet;
import lombok.Getter;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.IndexAvailable;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
import org.apache.shardingsphere.infra.datanode.DataNode;
@@ -42,7 +41,6 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table
import javax.sql.DataSource;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Collections;
import java.util.LinkedList;
import java.util.Map;
import java.util.Optional;
@@ -173,8 +171,7 @@ public final class SingleRule implements DatabaseRule {
* @return qualified tables
*/
public Collection<QualifiedTable> getQualifiedTables(final SQLStatementContext sqlStatementContext, final ShardingSphereDatabase database) {
- Collection<SimpleTableSegment> tables =
- sqlStatementContext instanceof TableContextAvailable ? ((TableContextAvailable) sqlStatementContext).getTablesContext().getSimpleTables() : Collections.emptyList();
+ Collection<SimpleTableSegment> tables = sqlStatementContext.getTablesContext().getSimpleTables();
Collection<QualifiedTable> result = getQualifiedTables(database, protocolType, tables);
if (result.isEmpty() && sqlStatementContext instanceof IndexAvailable) {
result = IndexMetaDataUtils.getTableNames(database, protocolType, ((IndexAvailable) sqlStatementContext).getIndexes());
diff --git a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/engine/SQLFederationEngine.java b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/engine/SQLFederationEngine.java
index 7c6991349d0..2e99deb7468 100644
--- a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/engine/SQLFederationEngine.java
+++ b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/engine/SQLFederationEngine.java
@@ -25,7 +25,6 @@ import org.apache.calcite.schema.SchemaPlus;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dal.ExplainStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
import org.apache.shardingsphere.infra.database.core.metadata.database.metadata.DialectDatabaseMetaData;
@@ -140,8 +139,7 @@ public final class SQLFederationEngine implements AutoCloseable {
if (allQueryUseSQLFederation) {
return true;
}
- Collection<String> databaseNames =
- sqlStatementContext instanceof TableContextAvailable ? ((TableContextAvailable) sqlStatementContext).getTablesContext().getDatabaseNames() : Collections.emptyList();
+ Collection<String> databaseNames = sqlStatementContext.getTablesContext().getDatabaseNames();
if (databaseNames.size() > 1) {
return true;
}
@@ -223,10 +221,9 @@ public final class SQLFederationEngine implements AutoCloseable {
DialectDatabaseMetaData dialectDatabaseMetaData = new DatabaseTypeRegistry(sqlStatementContext.getDatabaseType()).getDialectDatabaseMetaData();
// TODO set default schema according to search path result
if (dialectDatabaseMetaData.getSchemaOption().getDefaultSchema().isPresent()) {
- return sqlStatementContext instanceof TableContextAvailable
- && ((TableContextAvailable) sqlStatementContext).getTablesContext().getSimpleTables().stream().anyMatch(each -> each.getOwner().isPresent())
- ? Collections.singletonList(currentDatabaseName)
- : Arrays.asList(currentDatabaseName, currentSchemaName);
+ return sqlStatementContext.getTablesContext().getSimpleTables().stream().anyMatch(each -> each.getOwner().isPresent())
+ ? Collections.singletonList(currentDatabaseName)
+ : Arrays.asList(currentDatabaseName, currentSchemaName);
}
return Collections.singletonList(currentDatabaseName);
}
@@ -241,8 +238,7 @@ public final class SQLFederationEngine implements AutoCloseable {
private ExecutionPlanCacheKey buildCacheKey(final ShardingSphereMetaData metaData, final SQLStatementContext sqlStatementContext,
final String sql, final SQLStatementCompiler sqlStatementCompiler) {
ExecutionPlanCacheKey result = new ExecutionPlanCacheKey(sql, sqlStatementContext.getSqlStatement(), sqlStatementContext.getDatabaseType().getType(), sqlStatementCompiler);
- Collection<SimpleTableSegment> tableSegments =
- sqlStatementContext instanceof TableContextAvailable ? ((TableContextAvailable) sqlStatementContext).getTablesContext().getSimpleTables() : Collections.emptyList();
+ Collection<SimpleTableSegment> tableSegments = sqlStatementContext.getTablesContext().getSimpleTables();
for (SimpleTableSegment each : tableSegments) {
String originalDatabase = each.getTableName().getTableBoundInfo().map(optional -> optional.getOriginalDatabase().getValue()).orElse(currentDatabaseName);
String originalSchema = each.getTableName().getTableBoundInfo().map(optional -> optional.getOriginalSchema().getValue()).orElse(currentSchemaName);
diff --git a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/engine/processor/impl/StandardSQLFederationProcessor.java b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/engine/processor/impl/StandardSQLFederationProcessor.java
index 6fbcd83ca5c..eda730770f4 100644
--- a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/engine/processor/impl/StandardSQLFederationProcessor.java
+++ b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/engine/processor/impl/StandardSQLFederationProcessor.java
@@ -30,7 +30,6 @@ import org.apache.calcite.schema.Table;
import org.apache.shardingsphere.infra.binder.context.segment.select.projection.Projection;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.database.core.metadata.database.metadata.DialectDatabaseMetaData;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
@@ -86,9 +85,7 @@ public final class StandardSQLFederationProcessor implements SQLFederationProces
new ExecutorContext(prepareEngine, jdbcExecutor, callback, statistics, currentDatabaseName, currentSchemaName, federationContext.isPreview(), federationContext.getProcessId());
EnumerableScanImplementor scanImplementor = new EnumerableScanImplementor(federationContext.getQueryContext(), compilerContext, executorContext);
SQLStatementContext sqlStatementContext = federationContext.getQueryContext().getSqlStatementContext();
- Collection<SimpleTableSegment> simpleTables = sqlStatementContext instanceof TableContextAvailable
- ? ((TableContextAvailable) sqlStatementContext).getTablesContext().getSimpleTables()
- : Collections.emptyList();
+ Collection<SimpleTableSegment> simpleTables = sqlStatementContext.getTablesContext().getSimpleTables();
for (SimpleTableSegment each : simpleTables) {
Table table = getTable(currentDatabaseName, currentSchemaName, schemaPlus, each, sqlStatementContext.getDatabaseType(), federationContext.getQueryContext().getSql());
if (table instanceof SQLFederationTable) {
@@ -120,9 +117,7 @@ public final class StandardSQLFederationProcessor implements SQLFederationProces
@Override
public void release(final String currentDatabaseName, final String currentSchemaName, final QueryContext queryContext, final SchemaPlus schemaPlus) {
- Collection<SimpleTableSegment> simpleTables = queryContext.getSqlStatementContext() instanceof TableContextAvailable
- ? ((TableContextAvailable) queryContext.getSqlStatementContext()).getTablesContext().getSimpleTables()
- : Collections.emptyList();
+ Collection<SimpleTableSegment> simpleTables = queryContext.getSqlStatementContext().getTablesContext().getSimpleTables();
for (SimpleTableSegment each : simpleTables) {
Table table = getTable(currentDatabaseName, currentSchemaName, schemaPlus, each, queryContext.getSqlStatementContext().getDatabaseType(), queryContext.getSql());
if (table instanceof SQLFederationTable) {
diff --git a/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/implementor/EnumerableScanImplementor.java b/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/implementor/EnumerableScanImplementor.java
index 7f05164ab67..8adaffd414e 100644
--- a/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/implementor/EnumerableScanImplementor.java
+++ b/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/implementor/EnumerableScanImplementor.java
@@ -23,7 +23,6 @@ import org.apache.calcite.linq4j.AbstractEnumerable;
import org.apache.calcite.linq4j.Enumerable;
import org.apache.calcite.linq4j.Enumerator;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.binder.engine.SQLBindEngine;
import org.apache.shardingsphere.infra.connection.kernel.KernelProcessor;
import org.apache.shardingsphere.infra.database.core.metadata.database.metadata.option.table.DialectDriverQuerySystemCatalogOption;
@@ -100,8 +99,7 @@ public final class EnumerableScanImplementor implements ScanImplementor {
}
private boolean containsSystemSchema(final SQLStatementContext sqlStatementContext) {
- Collection<String> usedSchemaNames =
- sqlStatementContext instanceof TableContextAvailable ? ((TableContextAvailable) sqlStatementContext).getTablesContext().getSchemaNames() : Collections.emptyList();
+ Collection<String> usedSchemaNames = sqlStatementContext.getTablesContext().getSchemaNames();
Collection<String> systemSchemas = new SystemDatabase(sqlStatementContext.getDatabaseType()).getSystemSchemas();
for (String each : usedSchemaNames) {
if (systemSchemas.contains(each)) {
@@ -155,10 +153,8 @@ public final class EnumerableScanImplementor implements ScanImplementor {
if (driverQuerySystemCatalogOption.isPresent() && driverQuerySystemCatalogOption.get().isSystemTable(table.getName())) {
return createMemoryEnumerator(MemoryTableStatisticsBuilder.buildTableStatistics(table, queryContext.getMetaData(), driverQuerySystemCatalogOption.get()), table, databaseType);
}
- ShardingSpherePreconditions.checkState(sqlStatementContext instanceof TableContextAvailable,
- () -> new IllegalStateException(String.format("Can not support %s in sql federation", sqlStatementContext.getSqlStatement().getClass().getSimpleName())));
- String databaseName = ((TableContextAvailable) sqlStatementContext).getTablesContext().getDatabaseName().orElse(executorContext.getCurrentDatabaseName());
- String schemaName = ((TableContextAvailable) sqlStatementContext).getTablesContext().getSchemaName().orElse(executorContext.getCurrentSchemaName());
+ String databaseName = sqlStatementContext.getTablesContext().getDatabaseName().orElse(executorContext.getCurrentDatabaseName());
+ String schemaName = sqlStatementContext.getTablesContext().getSchemaName().orElse(executorContext.getCurrentSchemaName());
Optional<TableStatistics> tableStatistics = Optional.ofNullable(executorContext.getStatistics().getDatabaseStatistics(databaseName))
.map(optional -> optional.getSchemaStatistics(schemaName)).map(optional -> optional.getTableStatistics(table.getName()));
return tableStatistics.map(optional -> createMemoryEnumerator(optional, table, databaseType)).orElseGet(this::createEmptyEnumerable);
diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/PushDownMetaDataRefreshEngine.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/PushDownMetaDataRefreshEngine.java
index 17225a4e1f2..4e69052bf63 100644
--- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/PushDownMetaDataRefreshEngine.java
+++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/PushDownMetaDataRefreshEngine.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.mode.metadata.refresher.pushdown;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -71,7 +70,7 @@ public final class PushDownMetaDataRefreshEngine {
return;
}
Collection<String> logicDataSourceNames = routeUnits.stream().map(each -> each.getDataSourceMapper().getLogicName()).collect(Collectors.toList());
- String schemaName = sqlStatementContext instanceof TableContextAvailable ? SchemaRefreshUtils.getSchemaName(database, sqlStatementContext) : null;
+ String schemaName = SchemaRefreshUtils.getSchemaName(database, sqlStatementContext);
DatabaseType databaseType = routeUnits.stream().map(each -> database.getResourceMetaData().getStorageUnits().get(each.getDataSourceMapper().getActualName()))
.filter(Objects::nonNull).findFirst().map(StorageUnit::getStorageType).orElseGet(sqlStatementContext::getDatabaseType);
refresher.get().refresh(metaDataManagerPersistService, database, logicDataSourceNames.isEmpty() ? null : logicDataSourceNames.iterator().next(),
diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/util/SchemaRefreshUtils.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/util/SchemaRefreshUtils.java
index e5a2a9f93d6..bd80919b014 100644
--- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/util/SchemaRefreshUtils.java
+++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/refresher/util/SchemaRefreshUtils.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.mode.metadata.refresher.util;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -38,7 +37,7 @@ public final class SchemaRefreshUtils {
* @return schema name
*/
public static String getSchemaName(final ShardingSphereDatabase database, final SQLStatementContext sqlStatementContext) {
- return ((TableContextAvailable) sqlStatementContext).getTablesContext().getSchemaName()
+ return sqlStatementContext.getTablesContext().getSchemaName()
.orElseGet(() -> new DatabaseTypeRegistry(sqlStatementContext.getDatabaseType()).getDefaultSchemaName(database.getName())).toLowerCase();
}
}
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutor.java
index 3565266c260..e807fbabf36 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutor.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutor.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.proxy.backend.connector;
import com.google.common.base.Strings;
import lombok.Getter;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
import org.apache.shardingsphere.infra.database.core.metadata.database.metadata.DialectDatabaseMetaData;
import org.apache.shardingsphere.infra.database.core.metadata.database.metadata.option.transaction.DialectTransactionOption;
@@ -117,9 +116,7 @@ public final class ProxySQLExecutor {
private String getSchemaName(final SQLStatementContext sqlStatementContext, final ShardingSphereDatabase database) {
String defaultSchemaName = new DatabaseTypeRegistry(sqlStatementContext.getDatabaseType()).getDefaultSchemaName(database.getName());
- return sqlStatementContext instanceof TableContextAvailable
- ? ((TableContextAvailable) sqlStatementContext).getTablesContext().getSchemaName().orElse(defaultSchemaName)
- : defaultSchemaName;
+ return sqlStatementContext.getTablesContext().getSchemaName().orElse(defaultSchemaName);
}
/**
@@ -169,10 +166,9 @@ public final class ProxySQLExecutor {
}
private String getTableName(final ExecutionContext executionContext) {
- return executionContext.getSqlStatementContext() instanceof TableContextAvailable
- && !((TableContextAvailable) executionContext.getSqlStatementContext()).getTablesContext().getSimpleTables().isEmpty()
- ? ((TableContextAvailable) executionContext.getSqlStatementContext()).getTablesContext().getSimpleTables().iterator().next().getTableName().getIdentifier().getValue()
- : "unknown_table";
+ return executionContext.getSqlStatementContext().getTablesContext().getSimpleTables().isEmpty()
+ ? "unknown_table"
+ : executionContext.getSqlStatementContext().getTablesContext().getSimpleTables().iterator().next().getTableName().getIdentifier().getValue();
}
/**
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/StandardDatabaseConnector.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/StandardDatabaseConnector.java
index da0094db194..e21433bedaa 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/StandardDatabaseConnector.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/StandardDatabaseConnector.java
@@ -25,7 +25,6 @@ import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CursorS
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.CursorAvailable;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
import org.apache.shardingsphere.infra.connection.kernel.KernelProcessor;
import org.apache.shardingsphere.infra.database.core.metadata.database.metadata.DialectDatabaseMetaData;
@@ -144,8 +143,7 @@ public final class StandardDatabaseConnector implements DatabaseConnector {
}
private void checkBackendReady(final SQLStatementContext sqlStatementContext) {
- boolean isSystemSchema = SystemSchemaUtils.containsSystemSchema(sqlStatementContext.getDatabaseType(),
- sqlStatementContext instanceof TableContextAvailable ? ((TableContextAvailable) sqlStatementContext).getTablesContext().getSchemaNames() : Collections.emptyList(), database);
+ boolean isSystemSchema = SystemSchemaUtils.containsSystemSchema(sqlStatementContext.getDatabaseType(), sqlStatementContext.getTablesContext().getSchemaNames(), database);
ShardingSpherePreconditions.checkState(isSystemSchema || database.containsDataSource(), () -> new EmptyStorageUnitException(database.getName()));
ShardingSpherePreconditions.checkState(isSystemSchema || database.isComplete(), () -> new EmptyRuleException(database.getName()));
}
@@ -329,9 +327,7 @@ public final class StandardDatabaseConnector implements DatabaseConnector {
}
private boolean isNeedAccumulate() {
- Collection<String> tableNames = queryContext.getSqlStatementContext() instanceof TableContextAvailable
- ? ((TableContextAvailable) queryContext.getSqlStatementContext()).getTablesContext().getTableNames()
- : Collections.emptyList();
+ Collection<String> tableNames = queryContext.getSqlStatementContext().getTablesContext().getTableNames();
for (DataNodeRuleAttribute each : database.getRuleMetaData().getAttributes(DataNodeRuleAttribute.class)) {
if (each.isNeedAccumulate(tableNames)) {
return true;
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/distsql/DistSQLStatementContext.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/distsql/DistSQLStatementContext.java
index e7da0fb5c3b..80c994ba738 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/distsql/DistSQLStatementContext.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/distsql/DistSQLStatementContext.java
@@ -20,9 +20,12 @@ package org.apache.shardingsphere.proxy.backend.distsql;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
+import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
+import java.util.Collections;
+
/**
* SQL statement context for DistSQL.
*/
@@ -32,6 +35,11 @@ public final class DistSQLStatementContext implements SQLStatementContext {
private final DistSQLStatement sqlStatement;
+ @Override
+ public TablesContext getTablesContext() {
+ return new TablesContext(Collections.emptyList());
+ }
+
@Override
public DatabaseType getDatabaseType() {
throw new UnsupportedOperationException("Cannot get database type of DistSQLStatementContext");
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactory.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactory.java
index f94757498e4..6f18c6d031a 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactory.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactory.java
@@ -24,7 +24,6 @@ import org.apache.shardingsphere.distsql.statement.ral.queryable.QueryableRALSta
import org.apache.shardingsphere.distsql.statement.rql.RQLStatement;
import org.apache.shardingsphere.distsql.statement.rul.RULStatement;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.binder.engine.SQLBindEngine;
import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
@@ -138,8 +137,8 @@ public final class ProxyBackendHandlerFactory {
if (databaseOperateHandler.isPresent()) {
return databaseOperateHandler.get();
}
- String databaseName = sqlStatementContext instanceof TableContextAvailable && ((TableContextAvailable) sqlStatementContext).getTablesContext().getDatabaseName().isPresent()
- ? ((TableContextAvailable) sqlStatementContext).getTablesContext().getDatabaseName().get()
+ String databaseName = sqlStatementContext.getTablesContext().getDatabaseName().isPresent()
+ ? sqlStatementContext.getTablesContext().getDatabaseName().get()
: connectionSession.getUsedDatabaseName();
if (null == databaseName) {
return DatabaseBackendHandlerFactory.newInstance(queryContext, connectionSession, preferPreparedStatement);
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/PreviewExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/PreviewExecutor.java
index 74c9771825c..54eb254fd10 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/PreviewExecutor.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/PreviewExecutor.java
@@ -28,7 +28,6 @@ import org.apache.shardingsphere.infra.binder.context.aware.CursorAware;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CursorStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.CursorAvailable;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.binder.engine.SQLBindEngine;
import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
import org.apache.shardingsphere.infra.connection.kernel.KernelProcessor;
@@ -57,8 +56,8 @@ import org.apache.shardingsphere.parser.rule.SQLParserRule;
import org.apache.shardingsphere.proxy.backend.connector.ProxyDatabaseConnectionManager;
import org.apache.shardingsphere.proxy.backend.context.BackendExecutorContext;
import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement;
-import org.apache.shardingsphere.sqlfederation.engine.SQLFederationEngine;
import org.apache.shardingsphere.sqlfederation.context.SQLFederationContext;
+import org.apache.shardingsphere.sqlfederation.engine.SQLFederationEngine;
import java.sql.Connection;
import java.sql.SQLException;
@@ -107,9 +106,7 @@ public final class PreviewExecutor implements DistSQLQueryExecutor<PreviewStatem
private String getSchemaName(final SQLStatementContext sqlStatementContext, final ShardingSphereDatabase database) {
String defaultSchemaName = new DatabaseTypeRegistry(sqlStatementContext.getDatabaseType()).getDefaultSchemaName(database.getName());
- return sqlStatementContext instanceof TableContextAvailable
- ? ((TableContextAvailable) sqlStatementContext).getTablesContext().getSchemaName().orElse(defaultSchemaName)
- : defaultSchemaName;
+ return sqlStatementContext.getTablesContext().getSchemaName().orElse(defaultSchemaName);
}
private Collection<ExecutionUnit> getExecutionUnits(final ContextManager contextManager, final String schemaName, final ShardingSphereMetaData metaData,
diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnectorFactoryTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnectorFactoryTest.java
index 6d4ea439f22..5788b472a42 100644
--- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnectorFactoryTest.java
+++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnectorFactoryTest.java
@@ -59,6 +59,7 @@ class DatabaseConnectorFactoryTest {
ProxyDatabaseConnectionManager databaseConnectionManager = mock(ProxyDatabaseConnectionManager.class, RETURNS_DEEP_STUBS);
when(databaseConnectionManager.getConnectionSession().getUsedDatabaseName()).thenReturn("foo_db");
SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
when(sqlStatementContext.getDatabaseType()).thenReturn(databaseType);
ShardingSphereDatabase database = mockDatabase();
ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class);
@@ -82,6 +83,7 @@ class DatabaseConnectorFactoryTest {
ProxyDatabaseConnectionManager databaseConnectionManager = mock(ProxyDatabaseConnectionManager.class, RETURNS_DEEP_STUBS);
when(databaseConnectionManager.getConnectionSession().getUsedDatabaseName()).thenReturn("foo_db");
SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
when(sqlStatementContext.getDatabaseType()).thenReturn(databaseType);
ShardingSphereDatabase database = mockDatabase();
ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class);
diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutorTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutorTest.java
index b0b072e4a63..bf826b51d59 100644
--- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutorTest.java
+++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/ProxySQLExecutorTest.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.infra.binder.context.statement.TableAvailableSQ
import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateTableStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CursorStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.InsertStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
@@ -74,7 +73,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.withSettings;
@ExtendWith(AutoMockExtension.class)
@StaticMockSettings(ProxyContext.class)
@@ -230,9 +228,9 @@ class ProxySQLExecutorTest {
private QueryContext mockQueryContext() {
QueryContext result = mock(QueryContext.class);
- SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, withSettings().extraInterfaces(TableContextAvailable.class).defaultAnswer(RETURNS_DEEP_STUBS));
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
when(sqlStatementContext.getDatabaseType()).thenReturn(databaseType);
- when(((TableContextAvailable) sqlStatementContext).getTablesContext().getSchemaName()).thenReturn(Optional.of("foo_db"));
+ when(sqlStatementContext.getTablesContext().getSchemaName()).thenReturn(Optional.of("foo_db"));
when(result.getSqlStatementContext()).thenReturn(sqlStatementContext);
return result;
}
diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/StandardDatabaseConnectorTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/StandardDatabaseConnectorTest.java
index 009eae0a99f..3b8821cc450 100644
--- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/StandardDatabaseConnectorTest.java
+++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/connector/StandardDatabaseConnectorTest.java
@@ -138,6 +138,7 @@ class StandardDatabaseConnectorTest {
@Test
void assertBinaryProtocolQueryHeader() throws SQLException, NoSuchFieldException, IllegalAccessException {
SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
when(sqlStatementContext.getDatabaseType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE"));
DatabaseConnector engine = createDatabaseConnector(JDBCDriverType.PREPARED_STATEMENT, createQueryContext(sqlStatementContext));
Field queryHeadersField = StandardDatabaseConnector.class.getDeclaredField("queryHeaders");
@@ -201,6 +202,7 @@ class StandardDatabaseConnectorTest {
@Test
void assertAddStatementCorrectly() {
SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
when(sqlStatementContext.getDatabaseType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE"));
DatabaseConnector engine = createDatabaseConnector(JDBCDriverType.STATEMENT, createQueryContext(sqlStatementContext));
engine.add(statement);
@@ -212,6 +214,7 @@ class StandardDatabaseConnectorTest {
@Test
void assertAddResultSetCorrectly() {
SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
when(sqlStatementContext.getDatabaseType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE"));
DatabaseConnector engine = createDatabaseConnector(JDBCDriverType.STATEMENT, createQueryContext(sqlStatementContext));
engine.add(resultSet);
@@ -223,6 +226,7 @@ class StandardDatabaseConnectorTest {
@Test
void assertCloseCorrectly() throws SQLException {
SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
when(sqlStatementContext.getDatabaseType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE"));
DatabaseConnector engine = createDatabaseConnector(JDBCDriverType.STATEMENT, createQueryContext(sqlStatementContext));
Collection<ResultSet> cachedResultSets = getField(engine, "cachedResultSets");
@@ -240,6 +244,7 @@ class StandardDatabaseConnectorTest {
@Test
void assertCloseResultSetsWithExceptionThrown() throws SQLException {
SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
when(sqlStatementContext.getDatabaseType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "FIXTURE"));
DatabaseConnector engine = createDatabaseConnector(JDBCDriverType.STATEMENT, createQueryContext(sqlStatementContext));
Collection<ResultSet> cachedResultSets = getField(engine, "cachedResultSets");
diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/data/DatabaseBackendHandlerFactoryTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/data/DatabaseBackendHandlerFactoryTest.java
index 02c403d96b9..ad49656885c 100644
--- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/data/DatabaseBackendHandlerFactoryTest.java
+++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/data/DatabaseBackendHandlerFactoryTest.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.proxy.backend.handler.data;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.hint.HintValueContext;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -49,7 +48,6 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.withSettings;
@ExtendWith(AutoMockExtension.class)
@StaticMockSettings(ProxyContext.class)
@@ -60,8 +58,9 @@ class DatabaseBackendHandlerFactoryTest {
@Test
void assertNewInstanceReturnedUnicastDatabaseBackendHandlerWithDAL() {
String sql = "DESC tbl";
- SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class);
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
when(sqlStatementContext.getSqlStatement()).thenReturn(mock(DALStatement.class));
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
DatabaseBackendHandler actual = DatabaseBackendHandlerFactory.newInstance(
new QueryContext(sqlStatementContext, sql, Collections.emptyList(), new HintValueContext(), mockConnectionContext(), mock(ShardingSphereMetaData.class)),
mock(ConnectionSession.class), false);
@@ -77,8 +76,9 @@ class DatabaseBackendHandlerFactoryTest {
@Test
void assertNewInstanceReturnedUnicastDatabaseBackendHandlerWithQueryWithoutFrom() {
String sql = "SELECT 1";
- SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class);
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
when(sqlStatementContext.getSqlStatement()).thenReturn(mock(SelectStatement.class));
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
DatabaseBackendHandler actual =
DatabaseBackendHandlerFactory.newInstance(
new QueryContext(sqlStatementContext, sql, Collections.emptyList(), new HintValueContext(), mockConnectionContext(), mock(ShardingSphereMetaData.class)),
@@ -101,10 +101,10 @@ class DatabaseBackendHandlerFactoryTest {
}
private SQLStatementContext mockSQLStatementContext() {
- SQLStatementContext result = mock(SQLStatementContext.class, withSettings().extraInterfaces(TableContextAvailable.class).defaultAnswer(RETURNS_DEEP_STUBS));
+ SQLStatementContext result = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
when(result.getSqlStatement()).thenReturn(mock(SQLStatement.class));
- when(((TableContextAvailable) result).getTablesContext().getSchemaNames()).thenReturn(Collections.emptyList());
- when(((TableContextAvailable) result).getTablesContext().getDatabaseName()).thenReturn(Optional.empty());
+ when(result.getTablesContext().getSchemaNames()).thenReturn(Collections.emptyList());
+ when(result.getTablesContext().getDatabaseName()).thenReturn(Optional.empty());
return result;
}
diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandlerTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandlerTest.java
index 2f374518b14..747a618efaf 100644
--- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandlerTest.java
+++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/data/impl/UnicastDatabaseBackendHandlerTest.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.proxy.backend.handler.data.impl;
import lombok.SneakyThrows;
+import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.hint.HintValueContext;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
@@ -88,8 +89,10 @@ class UnicastDatabaseBackendHandlerTest {
void setUp() throws SQLException {
when(connectionSession.getCurrentDatabaseName()).thenReturn(String.format(DATABASE_PATTERN, 0));
mockDatabaseConnector(new UpdateResponseHeader(mock()));
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
unicastDatabaseBackendHandler = new UnicastDatabaseBackendHandler(
- new QueryContext(mock(), EXECUTE_SQL, Collections.emptyList(), new HintValueContext(), mockConnectionContext(), mock()), connectionSession);
+ new QueryContext(sqlStatementContext, EXECUTE_SQL, Collections.emptyList(), new HintValueContext(), mockConnectionContext(), mock()), connectionSession);
setBackendHandlerFactory(unicastDatabaseBackendHandler);
}
diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/tcl/TCLBackendHandlerFactoryTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/tcl/TCLBackendHandlerFactoryTest.java
index 86a61d18aa5..a74ec67a00c 100644
--- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/tcl/TCLBackendHandlerFactoryTest.java
+++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/tcl/TCLBackendHandlerFactoryTest.java
@@ -74,11 +74,11 @@ class TCLBackendHandlerFactoryTest {
when(connectionSession.getProtocolType()).thenReturn(databaseType);
when(databaseConnectionManager.getConnectionSession()).thenReturn(connectionSession);
when(databaseConnectionManager.getConnectionSession().getConnectionContext().getTransactionContext()).thenReturn(new TransactionConnectionContext());
- SQLStatementContext context = mock(SQLStatementContext.class);
- when(context.getSqlStatement()).thenReturn(mock(CommitStatement.class));
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class);
+ when(sqlStatementContext.getSqlStatement()).thenReturn(mock(CommitStatement.class));
ContextManager contextManager = mockContextManager();
when(ProxyContext.getInstance().getContextManager()).thenReturn(contextManager);
- ProxyBackendHandler proxyBackendHandler = TCLBackendHandlerFactory.newInstance(context, null, connectionSession);
+ ProxyBackendHandler proxyBackendHandler = TCLBackendHandlerFactory.newInstance(sqlStatementContext, null, connectionSession);
assertThat(proxyBackendHandler, instanceOf(TCLBackendHandler.class));
TCLBackendHandler backendHandler = (TCLBackendHandler) proxyBackendHandler;
assertFieldOfInstance(backendHandler, "operationType", is(TransactionOperationType.COMMIT));
@@ -113,8 +113,9 @@ class TCLBackendHandlerFactoryTest {
@Test
void assertBroadcastBackendHandlerReturnedWhenTCLStatementNotHit() {
- SQLStatementContext context = mock(SQLStatementContext.class);
- when(context.getSqlStatement()).thenReturn(mock(TCLStatement.class));
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
+ when(sqlStatementContext.getSqlStatement()).thenReturn(mock(TCLStatement.class));
DatabaseConnectorFactory mockFactory = mock(DatabaseConnectorFactory.class);
when(DatabaseConnectorFactory.getInstance()).thenReturn(mockFactory);
when(mockFactory.newInstance(any(QueryContext.class), nullable(ProxyDatabaseConnectionManager.class), anyBoolean())).thenReturn(mock(DatabaseConnector.class));
@@ -123,7 +124,7 @@ class TCLBackendHandlerFactoryTest {
ConnectionSession connectionSession = mock(ConnectionSession.class);
ConnectionContext connectionContext = mockConnectionContext();
when(connectionSession.getConnectionContext()).thenReturn(connectionContext);
- assertThat(TCLBackendHandlerFactory.newInstance(context, null, connectionSession), instanceOf(DatabaseConnector.class));
+ assertThat(TCLBackendHandlerFactory.newInstance(sqlStatementContext, null, connectionSession), instanceOf(DatabaseConnector.class));
}
private ConnectionContext mockConnectionContext() {
diff --git a/proxy/backend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussAdminExecutorCreator.java b/proxy/backend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussAdminExecutorCreator.java
index 24e3574f2ab..fadbebad306 100644
--- a/proxy/backend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussAdminExecutorCreator.java
+++ b/proxy/backend/type/opengauss/src/main/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussAdminExecutorCreator.java
@@ -21,7 +21,6 @@ import com.cedarsoftware.util.CaseInsensitiveMap;
import com.cedarsoftware.util.CaseInsensitiveSet;
import com.google.common.base.Strings;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.database.schema.manager.SystemSchemaManager;
@@ -84,7 +83,7 @@ public final class OpenGaussAdminExecutorCreator implements DatabaseAdminExecuto
@Override
public Optional<DatabaseAdminExecutor> create(final SQLStatementContext sqlStatementContext, final String sql, final String databaseName, final List<Object> parameters) {
- Map<String, Collection<String>> selectedSchemaTables = sqlStatementContext instanceof TableContextAvailable ? getSelectedSchemaTables(sqlStatementContext) : Collections.emptyMap();
+ Map<String, Collection<String>> selectedSchemaTables = getSelectedSchemaTables(sqlStatementContext);
if (isSQLFederationSystemCatalogQuery(selectedSchemaTables) || isSQLFederationSystemCatalogQueryExpressions(sqlStatementContext)) {
return Optional.of(new OpenGaussSystemCatalogAdminQueryExecutor(sqlStatementContext, sql, databaseName, parameters));
}
@@ -96,7 +95,7 @@ public final class OpenGaussAdminExecutorCreator implements DatabaseAdminExecuto
private Map<String, Collection<String>> getSelectedSchemaTables(final SQLStatementContext sqlStatementContext) {
Map<String, Collection<String>> result = new CaseInsensitiveMap<>();
- for (SimpleTableSegment each : ((TableContextAvailable) sqlStatementContext).getTablesContext().getSimpleTables()) {
+ for (SimpleTableSegment each : sqlStatementContext.getTablesContext().getSimpleTables()) {
TableNameSegment tableNameSegment = each.getTableName();
String schemaName = tableNameSegment.getTableBoundInfo().map(optional -> optional.getOriginalSchema().getValue()).orElse(null);
schemaName = Strings.isNullOrEmpty(schemaName) ? each.getOwner().map(optional -> optional.getIdentifier().getValue()).orElse(null) : schemaName;
diff --git a/proxy/backend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussAdminExecutorCreatorTest.java b/proxy/backend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussAdminExecutorCreatorTest.java
index cc3a7b0c3df..6b1d1f080b9 100644
--- a/proxy/backend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussAdminExecutorCreatorTest.java
+++ b/proxy/backend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussAdminExecutorCreatorTest.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.proxy.backend.opengauss.handler.admin;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.database.core.spi.DatabaseTypedSPILoader;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.statistics.collector.DialectDatabaseStatisticsCollector;
@@ -44,7 +43,6 @@ import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.withSettings;
@ExtendWith(AutoMockExtension.class)
@StaticMockSettings(DatabaseTypedSPILoader.class)
@@ -94,8 +92,8 @@ class OpenGaussAdminExecutorCreatorTest {
void assertCreateOtherExecutor() {
initDialectDatabaseStatisticsCollector(false);
OpenGaussAdminExecutorCreator creator = new OpenGaussAdminExecutorCreator();
- SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, withSettings().extraInterfaces(TableContextAvailable.class).defaultAnswer(RETURNS_DEEP_STUBS));
- when(((TableContextAvailable) sqlStatementContext).getTablesContext().getTableNames()).thenReturn(Collections.emptyList());
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(Collections.emptyList());
assertThat(creator.create(sqlStatementContext), is(Optional.empty()));
assertThat(creator.create(sqlStatementContext, "", "", Collections.emptyList()), is(Optional.empty()));
}
diff --git a/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutor.java b/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutor.java
index 8f4205d76b4..52212bce36a 100644
--- a/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutor.java
+++ b/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutor.java
@@ -32,7 +32,6 @@ import org.apache.shardingsphere.infra.binder.context.segment.select.projection.
import org.apache.shardingsphere.infra.binder.context.segment.select.projection.impl.ColumnProjection;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
-import org.apache.shardingsphere.infra.binder.context.type.TableContextAvailable;
import org.apache.shardingsphere.infra.binder.engine.SQLBindEngine;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
@@ -167,9 +166,9 @@ public final class MySQLComStmtPrepareExecutor implements CommandExecutor {
}
private ShardingSphereSchema getSchema(final SQLStatementContext sqlStatementContext) {
- String databaseName = ((TableContextAvailable) sqlStatementContext).getTablesContext().getDatabaseName().orElseGet(connectionSession::getCurrentDatabaseName);
+ String databaseName = sqlStatementContext.getTablesContext().getDatabaseName().orElseGet(connectionSession::getCurrentDatabaseName);
ShardingSphereDatabase database = ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getDatabase(databaseName);
- return ((TableContextAvailable) sqlStatementContext).getTablesContext().getSchemaName().map(database::getSchema)
+ return sqlStatementContext.getTablesContext().getSchemaName().map(database::getSchema)
.orElseGet(() -> database.getSchema(new DatabaseTypeRegistry(sqlStatementContext.getDatabaseType()).getDefaultSchemaName(database.getName())));
}
diff --git a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PortalTest.java b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PortalTest.java
index 23410d6d7e3..05621889ab9 100644
--- a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PortalTest.java
+++ b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PortalTest.java
@@ -259,7 +259,9 @@ class PortalTest {
@Test
void assertDescribeBeforeBind() {
PostgreSQLServerPreparedStatement preparedStatement = mock(PostgreSQLServerPreparedStatement.class);
- when(preparedStatement.getSqlStatementContext()).thenReturn(mock(SQLStatementContext.class));
+ SQLStatementContext sqlStatementContext = mock(SQLStatementContext.class, RETURNS_DEEP_STUBS);
+ when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.emptyList());
+ when(preparedStatement.getSqlStatementContext()).thenReturn(sqlStatementContext);
assertThrows(IllegalStateException.class, () -> new Portal("", preparedStatement, Collections.emptyList(), Collections.emptyList(), databaseConnectionManager).describe());
}