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 4b2ae1264d0 Merge TableAvailableSQLStatementContext and
CommonSQLStatementContext (#35713)
4b2ae1264d0 is described below
commit 4b2ae1264d0607c215f98be792db9219fca505e3
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Jun 15 20:23:53 2025 +0800
Merge TableAvailableSQLStatementContext and CommonSQLStatementContext
(#35713)
* Merge TableAvailableSQLStatementContext and CommonSQLStatementContext
* Merge TableAvailableSQLStatementContext and CommonSQLStatementContext
* Merge TableAvailableSQLStatementContext and CommonSQLStatementContext
---
.../unicast/BroadcastUnicastRouteEngineTest.java | 4 +-
.../merge/dal/EncryptDALResultDecoratorTest.java | 4 +-
.../EncryptShowCreateTableMergedResultTest.java | 4 +-
.../ShardingCreateFunctionSupportedChecker.java | 5 +--
.../sql/ddl/ShardingDropTableSupportedChecker.java | 5 +--
.../ddl/ShardingRenameTableSupportedChecker.java | 5 +--
.../sql/dml/ShardingCopySupportedChecker.java | 5 +--
.../sql/dml/ShardingLoadDataSupportedChecker.java | 5 +--
.../sql/dml/ShardingLoadXmlSupportedChecker.java | 5 +--
.../ddl/ShardingDropTableRouteContextChecker.java | 14 +++----
.../ShardingRenameTableRouteContextChecker.java | 3 +-
...ShardingCreateFunctionSupportedCheckerTest.java | 15 ++++---
.../ddl/ShardingDropTableSupportedCheckerTest.java | 6 +--
.../ShardingRenameTableSupportedCheckerTest.java | 12 +++---
.../sql/dml/ShardingCopySupportedCheckerTest.java | 7 ++--
.../dml/ShardingLoadDataSupportedCheckerTest.java | 9 +++--
.../dml/ShardingLoadXmlSupportedCheckerTest.java | 9 +++--
.../ShardingDropTableRouteContextCheckerTest.java | 10 ++---
...ShardingRenameTableRouteContextCheckerTest.java | 5 ++-
.../type/ShardingRouteEngineFactoryTest.java | 6 +--
.../statement/CommonSQLStatementContext.java | 14 ++++++-
.../statement/SQLStatementContextFactory.java | 23 +++++------
.../TableAvailableSQLStatementContext.java | 7 +---
.../TableAvailableSQLStatementContextTest.java | 47 ----------------------
.../sql/table/SingleDropTableSupportedChecker.java | 5 +--
.../sql/SingleDropTableSupportedCheckerTest.java | 6 +--
.../core/statement/dal/AnalyzeTableStatement.java | 3 +-
.../core/statement/dcl/GrantStatement.java | 3 +-
.../core/statement/dcl/RevokeStatement.java | 3 +-
.../core/statement/ddl/CommentStatement.java | 10 ++++-
.../core/statement/ddl/DropTableStatement.java | 3 +-
.../core/statement/ddl/DropViewStatement.java | 8 +++-
.../core/statement/ddl/TruncateStatement.java | 3 +-
.../backend/connector/ProxySQLExecutorTest.java | 7 ++--
34 files changed, 129 insertions(+), 151 deletions(-)
diff --git
a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/route/engine/type/unicast/BroadcastUnicastRouteEngineTest.java
b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/route/engine/type/unicast/BroadcastUnicastRouteEngineTest.java
index cf569769612..4481808297c 100644
---
a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/route/engine/type/unicast/BroadcastUnicastRouteEngineTest.java
+++
b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/route/engine/type/unicast/BroadcastUnicastRouteEngineTest.java
@@ -18,8 +18,8 @@
package org.apache.shardingsphere.broadcast.route.engine.type.unicast;
import org.apache.shardingsphere.broadcast.rule.BroadcastRule;
+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.TableAvailableSQLStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.type.ddl.AlterViewStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.type.ddl.CreateViewStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.CursorAvailable;
@@ -77,7 +77,7 @@ class BroadcastUnicastRouteEngineTest {
@Test
void assertRouteToFirstDataSourceWithDropViewStatementContext() {
- SQLStatementContext sqlStatementContext =
mock(TableAvailableSQLStatementContext.class);
+ SQLStatementContext sqlStatementContext =
mock(CommonSQLStatementContext.class);
when(sqlStatementContext.getSqlStatement()).thenReturn(mock(DropViewStatement.class));
assertRoute(sqlStatementContext, is("ds_0"));
}
diff --git
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dal/EncryptDALResultDecoratorTest.java
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dal/EncryptDALResultDecoratorTest.java
index b5d846ef590..f80e45cc59a 100644
---
a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dal/EncryptDALResultDecoratorTest.java
+++
b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dal/EncryptDALResultDecoratorTest.java
@@ -20,8 +20,8 @@ package org.apache.shardingsphere.encrypt.merge.dal;
import
org.apache.shardingsphere.encrypt.merge.dal.show.EncryptShowColumnsMergedResult;
import
org.apache.shardingsphere.encrypt.merge.dal.show.EncryptShowCreateTableMergedResult;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
+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.TableAvailableSQLStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.type.dal.ExplainStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.type.dal.ShowColumnsStatementContext;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
@@ -106,7 +106,7 @@ class EncryptDALResultDecoratorTest {
}
private SQLStatementContext mockShowCreateTableStatementContext() {
- TableAvailableSQLStatementContext result =
mock(TableAvailableSQLStatementContext.class, RETURNS_DEEP_STUBS);
+ CommonSQLStatementContext result =
mock(CommonSQLStatementContext.class, RETURNS_DEEP_STUBS);
when(result.getDatabaseType()).thenReturn(databaseType);
SimpleTableSegment simpleTableSegment = new SimpleTableSegment(new
TableNameSegment(1, 7, new IdentifierValue("foo_tbl")));
when(result.getTablesContext().getSimpleTables()).thenReturn(Collections.singleton(simpleTableSegment));
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 9c04ff33094..cf925877e43 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
@@ -23,8 +23,8 @@ import
org.apache.shardingsphere.encrypt.config.rule.EncryptTableRuleConfigurati
import
org.apache.shardingsphere.encrypt.exception.syntax.UnsupportedEncryptSQLException;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
import org.apache.shardingsphere.encrypt.rule.table.EncryptTable;
+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.TableAvailableSQLStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
@@ -208,7 +208,7 @@ class EncryptShowCreateTableMergedResultTest {
}
private EncryptShowCreateTableMergedResult createMergedResult(final
MergedResult mergedResult, final String tableName, final EncryptRule rule) {
- TableAvailableSQLStatementContext sqlStatementContext =
mock(TableAvailableSQLStatementContext.class, RETURNS_DEEP_STUBS);
+ CommonSQLStatementContext sqlStatementContext =
mock(CommonSQLStatementContext.class, RETURNS_DEEP_STUBS);
when(sqlStatementContext.getTablesContext().getSimpleTables()).thenReturn(Collections.singleton(new
SimpleTableSegment(new TableNameSegment(1, 4, new
IdentifierValue(tableName)))));
when(sqlStatementContext.getDatabaseType()).thenReturn(databaseType);
RuleMetaData globalRuleMetaData = mock(RuleMetaData.class);
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateFunctionSupportedChecker.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateFunctionSupportedChecker.java
index dd7d763258f..9822a4c906f 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateFunctionSupportedChecker.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateFunctionSupportedChecker.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.sharding.checker.sql.ddl;
import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import
org.apache.shardingsphere.infra.binder.context.statement.TableAvailableSQLStatementContext;
import org.apache.shardingsphere.infra.checker.SupportedSQLChecker;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
@@ -35,7 +34,7 @@ import java.util.Optional;
/**
* Create function supported checker for sharding.
*/
-public final class ShardingCreateFunctionSupportedChecker implements
SupportedSQLChecker<TableAvailableSQLStatementContext, ShardingRule> {
+public final class ShardingCreateFunctionSupportedChecker implements
SupportedSQLChecker<SQLStatementContext, ShardingRule> {
@Override
public boolean isCheck(final SQLStatementContext sqlStatementContext) {
@@ -43,7 +42,7 @@ public final class ShardingCreateFunctionSupportedChecker
implements SupportedSQ
}
@Override
- public void check(final ShardingRule rule, final ShardingSphereDatabase
database, final ShardingSphereSchema currentSchema, final
TableAvailableSQLStatementContext sqlStatementContext) {
+ public void check(final ShardingRule rule, final ShardingSphereDatabase
database, final ShardingSphereSchema currentSchema, final SQLStatementContext
sqlStatementContext) {
CreateFunctionStatement createFunctionStatement =
(CreateFunctionStatement) sqlStatementContext.getSqlStatement();
Optional<RoutineBodySegment> routineBodySegment =
createFunctionStatement.getRoutineBody();
if (!routineBodySegment.isPresent()) {
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingDropTableSupportedChecker.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingDropTableSupportedChecker.java
index 1a0800b4c32..52219dab9be 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingDropTableSupportedChecker.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingDropTableSupportedChecker.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.sharding.checker.sql.ddl;
import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import
org.apache.shardingsphere.infra.binder.context.statement.TableAvailableSQLStatementContext;
import org.apache.shardingsphere.infra.checker.SupportedSQLChecker;
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -31,7 +30,7 @@ import
org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DropTab
/**
* Drop table supported checker for sharding.
*/
-public final class ShardingDropTableSupportedChecker implements
SupportedSQLChecker<TableAvailableSQLStatementContext, ShardingRule> {
+public final class ShardingDropTableSupportedChecker implements
SupportedSQLChecker<SQLStatementContext, ShardingRule> {
@Override
public boolean isCheck(final SQLStatementContext sqlStatementContext) {
@@ -39,7 +38,7 @@ public final class ShardingDropTableSupportedChecker
implements SupportedSQLChec
}
@Override
- public void check(final ShardingRule rule, final ShardingSphereDatabase
database, final ShardingSphereSchema currentSchema, final
TableAvailableSQLStatementContext sqlStatementContext) {
+ public void check(final ShardingRule rule, final ShardingSphereDatabase
database, final ShardingSphereSchema currentSchema, final SQLStatementContext
sqlStatementContext) {
DropTableStatement dropTableStatement = (DropTableStatement)
sqlStatementContext.getSqlStatement();
if (!dropTableStatement.isIfExists()) {
ShardingSphereSchema schema =
sqlStatementContext.getTablesContext().getSchemaName().map(database::getSchema).orElse(currentSchema);
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingRenameTableSupportedChecker.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingRenameTableSupportedChecker.java
index 8252cdf2bdd..d23946e9b6d 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingRenameTableSupportedChecker.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingRenameTableSupportedChecker.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.sharding.checker.sql.ddl;
import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import
org.apache.shardingsphere.infra.binder.context.statement.TableAvailableSQLStatementContext;
import org.apache.shardingsphere.infra.checker.SupportedSQLChecker;
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -36,7 +35,7 @@ import java.util.stream.Collectors;
/**
* Rename table supported checker for sharding.
*/
-public final class ShardingRenameTableSupportedChecker implements
SupportedSQLChecker<TableAvailableSQLStatementContext, ShardingRule> {
+public final class ShardingRenameTableSupportedChecker implements
SupportedSQLChecker<SQLStatementContext, ShardingRule> {
@Override
public boolean isCheck(final SQLStatementContext sqlStatementContext) {
@@ -44,7 +43,7 @@ public final class ShardingRenameTableSupportedChecker
implements SupportedSQLCh
}
@Override
- public void check(final ShardingRule rule, final ShardingSphereDatabase
database, final ShardingSphereSchema currentSchema, final
TableAvailableSQLStatementContext sqlStatementContext) {
+ public void check(final ShardingRule rule, final ShardingSphereDatabase
database, final ShardingSphereSchema currentSchema, final SQLStatementContext
sqlStatementContext) {
Collection<String> tableNames =
sqlStatementContext.getTablesContext().getSimpleTables().stream()
.map(each ->
each.getTableName().getIdentifier().getValue()).collect(Collectors.toList());
List<SimpleTableSegment> renameTables = ((RenameTableStatement)
sqlStatementContext.getSqlStatement())
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingCopySupportedChecker.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingCopySupportedChecker.java
index 6a9be23d2a4..35569f35a8b 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingCopySupportedChecker.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingCopySupportedChecker.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.sharding.checker.sql.dml;
import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import
org.apache.shardingsphere.infra.binder.context.statement.TableAvailableSQLStatementContext;
import org.apache.shardingsphere.infra.checker.SupportedSQLChecker;
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -32,7 +31,7 @@ import
org.apache.shardingsphere.sql.parser.statement.core.statement.dml.CopySta
* Copy supported checker for sharding.
*/
@HighFrequencyInvocation
-public final class ShardingCopySupportedChecker implements
SupportedSQLChecker<TableAvailableSQLStatementContext, ShardingRule> {
+public final class ShardingCopySupportedChecker implements
SupportedSQLChecker<SQLStatementContext, ShardingRule> {
@Override
public boolean isCheck(final SQLStatementContext sqlStatementContext) {
@@ -40,7 +39,7 @@ public final class ShardingCopySupportedChecker implements
SupportedSQLChecker<T
}
@Override
- public void check(final ShardingRule rule, final ShardingSphereDatabase
database, final ShardingSphereSchema currentSchema, final
TableAvailableSQLStatementContext sqlStatementContext) {
+ public void check(final ShardingRule rule, final ShardingSphereDatabase
database, final ShardingSphereSchema currentSchema, final SQLStatementContext
sqlStatementContext) {
String tableName = ((CopyStatement)
sqlStatementContext.getSqlStatement()).getTable().map(optional ->
optional.getTableName().getIdentifier().getValue()).orElse("");
ShardingSpherePreconditions.checkState(!rule.isShardingTable(tableName), () ->
new UnsupportedShardingOperationException("COPY", tableName));
}
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingLoadDataSupportedChecker.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingLoadDataSupportedChecker.java
index ee3d775b244..1068747d4dc 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingLoadDataSupportedChecker.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingLoadDataSupportedChecker.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.sharding.checker.sql.dml;
import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import
org.apache.shardingsphere.infra.binder.context.statement.TableAvailableSQLStatementContext;
import org.apache.shardingsphere.infra.checker.SupportedSQLChecker;
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -32,7 +31,7 @@ import
org.apache.shardingsphere.sql.parser.statement.core.statement.dml.LoadDat
* Load data supported checker for sharding.
*/
@HighFrequencyInvocation
-public final class ShardingLoadDataSupportedChecker implements
SupportedSQLChecker<TableAvailableSQLStatementContext, ShardingRule> {
+public final class ShardingLoadDataSupportedChecker implements
SupportedSQLChecker<SQLStatementContext, ShardingRule> {
@Override
public boolean isCheck(final SQLStatementContext sqlStatementContext) {
@@ -40,7 +39,7 @@ public final class ShardingLoadDataSupportedChecker
implements SupportedSQLCheck
}
@Override
- public void check(final ShardingRule rule, final ShardingSphereDatabase
database, final ShardingSphereSchema currentSchema, final
TableAvailableSQLStatementContext sqlStatementContext) {
+ public void check(final ShardingRule rule, final ShardingSphereDatabase
database, final ShardingSphereSchema currentSchema, final SQLStatementContext
sqlStatementContext) {
String tableName = ((LoadDataStatement)
sqlStatementContext.getSqlStatement()).getTable().getTableName().getIdentifier().getValue();
ShardingSpherePreconditions.checkState(!rule.isShardingTable(tableName), () ->
new UnsupportedShardingOperationException("LOAD DATA", tableName));
}
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingLoadXmlSupportedChecker.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingLoadXmlSupportedChecker.java
index cd6a17e4ab9..9d2f0c7b684 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingLoadXmlSupportedChecker.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingLoadXmlSupportedChecker.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.sharding.checker.sql.dml;
import org.apache.shardingsphere.infra.annotation.HighFrequencyInvocation;
import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import
org.apache.shardingsphere.infra.binder.context.statement.TableAvailableSQLStatementContext;
import org.apache.shardingsphere.infra.checker.SupportedSQLChecker;
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -32,7 +31,7 @@ import
org.apache.shardingsphere.sql.parser.statement.core.statement.dml.LoadXML
* Load xml supported checker for sharding.
*/
@HighFrequencyInvocation
-public final class ShardingLoadXmlSupportedChecker implements
SupportedSQLChecker<TableAvailableSQLStatementContext, ShardingRule> {
+public final class ShardingLoadXmlSupportedChecker implements
SupportedSQLChecker<SQLStatementContext, ShardingRule> {
@Override
public boolean isCheck(final SQLStatementContext sqlStatementContext) {
@@ -40,7 +39,7 @@ public final class ShardingLoadXmlSupportedChecker implements
SupportedSQLChecke
}
@Override
- public void check(final ShardingRule rule, final ShardingSphereDatabase
database, final ShardingSphereSchema currentSchema, final
TableAvailableSQLStatementContext sqlStatementContext) {
+ public void check(final ShardingRule rule, final ShardingSphereDatabase
database, final ShardingSphereSchema currentSchema, final SQLStatementContext
sqlStatementContext) {
String tableName = ((LoadXMLStatement)
sqlStatementContext.getSqlStatement()).getTable().getTableName().getIdentifier().getValue();
ShardingSpherePreconditions.checkState(!rule.isShardingTable(tableName), () ->
new UnsupportedShardingOperationException("LOAD XML", tableName));
}
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingDropTableRouteContextChecker.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingDropTableRouteContextChecker.java
index e841938a474..0c70f45ee2a 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingDropTableRouteContextChecker.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingDropTableRouteContextChecker.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.sharding.route.engine.checker.ddl;
import com.cedarsoftware.util.CaseInsensitiveSet;
-import
org.apache.shardingsphere.infra.binder.context.statement.TableAvailableSQLStatementContext;
+import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.datanode.DataNode;
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
@@ -45,16 +45,14 @@ public final class ShardingDropTableRouteContextChecker
implements ShardingRoute
@Override
public void check(final ShardingRule shardingRule, final QueryContext
queryContext, final ShardingSphereDatabase database, final
ConfigurationProperties props, final RouteContext routeContext) {
- TableAvailableSQLStatementContext dropTableStatementContext =
(TableAvailableSQLStatementContext) queryContext.getSqlStatementContext();
- checkTableInUsed(shardingRule, dropTableStatementContext,
routeContext);
- for (SimpleTableSegment each : ((DropTableStatement)
dropTableStatementContext.getSqlStatement()).getTables()) {
- if
(ShardingSupportedCheckUtils.isRouteUnitDataNodeDifferentSize(shardingRule,
routeContext, each.getTableName().getIdentifier().getValue())) {
- throw new ShardingDDLRouteException("DROP", "TABLE",
dropTableStatementContext.getTablesContext().getTableNames());
- }
+ checkTableInUsed(shardingRule, queryContext.getSqlStatementContext(),
routeContext);
+ for (SimpleTableSegment each : ((DropTableStatement)
queryContext.getSqlStatementContext().getSqlStatement()).getTables()) {
+
ShardingSpherePreconditions.checkState(!ShardingSupportedCheckUtils.isRouteUnitDataNodeDifferentSize(shardingRule,
routeContext, each.getTableName().getIdentifier().getValue()),
+ () -> new ShardingDDLRouteException("DROP", "TABLE",
queryContext.getSqlStatementContext().getTablesContext().getTableNames()));
}
}
- private void checkTableInUsed(final ShardingRule shardingRule, final
TableAvailableSQLStatementContext sqlStatementContext, final RouteContext
routeContext) {
+ private void checkTableInUsed(final ShardingRule shardingRule, final
SQLStatementContext sqlStatementContext, final RouteContext routeContext) {
Collection<String> dropTables =
sqlStatementContext.getTablesContext().getTableNames();
Collection<String> otherRuleActualTables =
shardingRule.getShardingTables().values().stream().filter(each ->
!dropTables.contains(each.getLogicTable()))
.flatMap(each ->
each.getActualDataNodes().stream().map(DataNode::getTableName)).collect(Collectors.toCollection(CaseInsensitiveSet::new));
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingRenameTableRouteContextChecker.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingRenameTableRouteContextChecker.java
index 912ea64cc5e..cef8b21936e 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingRenameTableRouteContextChecker.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingRenameTableRouteContextChecker.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.sharding.route.engine.checker.ddl;
-import
org.apache.shardingsphere.infra.binder.context.statement.TableAvailableSQLStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -41,7 +40,7 @@ public final class ShardingRenameTableRouteContextChecker
implements ShardingRou
for (RenameTableDefinitionSegment each :
renameTableStatement.getRenameTables()) {
String primaryTable =
each.getTable().getTableName().getIdentifier().getValue();
ShardingSpherePreconditions.checkState(!ShardingSupportedCheckUtils.isRouteUnitDataNodeDifferentSize(shardingRule,
routeContext, primaryTable),
- () -> new ShardingDDLRouteException("RENAME", "TABLE",
((TableAvailableSQLStatementContext)
queryContext.getSqlStatementContext()).getTablesContext().getTableNames()));
+ () -> new ShardingDDLRouteException("RENAME", "TABLE",
queryContext.getSqlStatementContext().getTablesContext().getTableNames()));
}
}
}
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateFunctionSupportedCheckerTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateFunctionSupportedCheckerTest.java
index b56b4cd023b..993aa9609a8 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateFunctionSupportedCheckerTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateFunctionSupportedCheckerTest.java
@@ -17,7 +17,8 @@
package org.apache.shardingsphere.sharding.checker.sql.ddl;
-import
org.apache.shardingsphere.infra.binder.context.statement.TableAvailableSQLStatementContext;
+import
org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
+import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import
org.apache.shardingsphere.infra.exception.dialect.exception.syntax.table.NoSuchTableException;
import
org.apache.shardingsphere.infra.exception.dialect.exception.syntax.table.TableExistsException;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -68,7 +69,8 @@ class ShardingCreateFunctionSupportedCheckerTest {
routineBody.getValidStatements().add(selectValidStatementSegment);
CreateFunctionStatement sqlStatement =
mock(CreateFunctionStatement.class);
when(sqlStatement.getRoutineBody()).thenReturn(Optional.of(routineBody));
- TableAvailableSQLStatementContext sqlStatementContext = new
TableAvailableSQLStatementContext(mock(), sqlStatement,
Collections.singleton(fromTable));
+
when(sqlStatement.getTables()).thenReturn(Collections.singleton(fromTable));
+ SQLStatementContext sqlStatementContext = new
CommonSQLStatementContext(mock(), sqlStatement);
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
when(schema.containsTable("bar_tbl")).thenReturn(true);
@@ -86,7 +88,8 @@ class ShardingCreateFunctionSupportedCheckerTest {
routineBody.getValidStatements().add(validStatementSegment);
CreateFunctionStatement sqlStatement =
mock(CreateFunctionStatement.class);
when(sqlStatement.getRoutineBody()).thenReturn(Optional.of(routineBody));
- TableAvailableSQLStatementContext sqlStatementContext = new
TableAvailableSQLStatementContext(mock(), sqlStatement,
Collections.singleton(fromTable));
+
when(sqlStatement.getTables()).thenReturn(Collections.singleton(fromTable));
+ SQLStatementContext sqlStatementContext = new
CommonSQLStatementContext(mock(), sqlStatement);
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class,
RETURNS_DEEP_STUBS);
when(rule.isShardingTable("foo_tbl")).thenReturn(true);
assertThrows(UnsupportedShardingOperationException.class, () -> new
ShardingCreateFunctionSupportedChecker().check(rule, database, mock(),
sqlStatementContext));
@@ -103,7 +106,8 @@ class ShardingCreateFunctionSupportedCheckerTest {
routineBody.getValidStatements().add(validStatementSegment);
CreateFunctionStatement sqlStatement =
mock(CreateFunctionStatement.class);
when(sqlStatement.getRoutineBody()).thenReturn(Optional.of(routineBody));
- TableAvailableSQLStatementContext sqlStatementContext = new
TableAvailableSQLStatementContext(mock(), sqlStatement,
Collections.singleton(fromTable));
+
when(sqlStatement.getTables()).thenReturn(Collections.singleton(fromTable));
+ SQLStatementContext sqlStatementContext = new
CommonSQLStatementContext(mock(), sqlStatement);
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class,
RETURNS_DEEP_STUBS);
assertThrows(NoSuchTableException.class, () -> new
ShardingCreateFunctionSupportedChecker().check(rule, database, mock(),
sqlStatementContext));
}
@@ -119,7 +123,8 @@ class ShardingCreateFunctionSupportedCheckerTest {
routineBody.getValidStatements().add(validStatementSegment);
CreateFunctionStatement sqlStatement =
mock(CreateFunctionStatement.class);
when(sqlStatement.getRoutineBody()).thenReturn(Optional.of(routineBody));
- TableAvailableSQLStatementContext sqlStatementContext = new
TableAvailableSQLStatementContext(mock(), sqlStatement,
Collections.singleton(table));
+
when(sqlStatement.getTables()).thenReturn(Collections.singleton(table));
+ SQLStatementContext sqlStatementContext = new
CommonSQLStatementContext(mock(), sqlStatement);
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class,
RETURNS_DEEP_STUBS);
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
when(schema.containsTable("foo_tbl")).thenReturn(true);
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingDropTableSupportedCheckerTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingDropTableSupportedCheckerTest.java
index 976b6e7c530..c3f2dab3054 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingDropTableSupportedCheckerTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingDropTableSupportedCheckerTest.java
@@ -17,7 +17,8 @@
package org.apache.shardingsphere.sharding.checker.sql.ddl;
-import
org.apache.shardingsphere.infra.binder.context.statement.TableAvailableSQLStatementContext;
+import
org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
+import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.datanode.DataNode;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
@@ -35,7 +36,6 @@ import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
-import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
@@ -66,7 +66,7 @@ class ShardingDropTableSupportedCheckerTest {
DropTableStatement sqlStatement = new DropTableStatement();
SimpleTableSegment table = new SimpleTableSegment(new
TableNameSegment(0, 0, new IdentifierValue("t_order_item")));
sqlStatement.getTables().add(table);
- TableAvailableSQLStatementContext sqlStatementContext = new
TableAvailableSQLStatementContext(mock(), sqlStatement,
Collections.singleton(table));
+ SQLStatementContext sqlStatementContext = new
CommonSQLStatementContext(mock(), sqlStatement);
ShardingSphereDatabase database = mock(ShardingSphereDatabase.class,
RETURNS_DEEP_STUBS);
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
when(schema.containsTable("t_order_item")).thenReturn(true);
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingRenameTableSupportedCheckerTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingRenameTableSupportedCheckerTest.java
index ea9f22f4679..f9fa6d04647 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingRenameTableSupportedCheckerTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingRenameTableSupportedCheckerTest.java
@@ -17,7 +17,8 @@
package org.apache.shardingsphere.sharding.checker.sql.ddl;
-import
org.apache.shardingsphere.infra.binder.context.statement.TableAvailableSQLStatementContext;
+import
org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
+import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import
org.apache.shardingsphere.sharding.exception.syntax.UnsupportedShardingOperationException;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import
org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.table.RenameTableDefinitionSegment;
@@ -47,18 +48,18 @@ class ShardingRenameTableSupportedCheckerTest {
@Test
void assertCheckShardingTable() {
- TableAvailableSQLStatementContext sqlStatementContext =
createRenameTableStatementContext("t_order", "t_user_order");
+ SQLStatementContext sqlStatementContext =
createRenameTableStatementContext("t_order", "t_user_order");
when(rule.containsShardingTable(argThat(tableNames ->
tableNames.contains("t_order") ||
tableNames.contains("t_user_order")))).thenReturn(true);
assertThrows(UnsupportedShardingOperationException.class, () -> new
ShardingRenameTableSupportedChecker().check(rule, mock(), mock(),
sqlStatementContext));
}
@Test
void assertCheckNormalCase() {
- TableAvailableSQLStatementContext sqlStatementContext =
createRenameTableStatementContext("t_not_sharding_table",
"t_not_sharding_table_new");
+ SQLStatementContext sqlStatementContext =
createRenameTableStatementContext("t_not_sharding_table",
"t_not_sharding_table_new");
assertDoesNotThrow(() -> new
ShardingRenameTableSupportedChecker().check(rule, mock(), mock(),
sqlStatementContext));
}
- private TableAvailableSQLStatementContext
createRenameTableStatementContext(final String originTableName, final String
newTableName) {
+ private SQLStatementContext createRenameTableStatementContext(final String
originTableName, final String newTableName) {
RenameTableStatement sqlStatement = mock(RenameTableStatement.class);
RenameTableDefinitionSegment renameTableDefinitionSegment = new
RenameTableDefinitionSegment(0, 0);
SimpleTableSegment table = new SimpleTableSegment(new
TableNameSegment(0, 0, new IdentifierValue(originTableName)));
@@ -66,6 +67,7 @@ class ShardingRenameTableSupportedCheckerTest {
renameTableDefinitionSegment.setTable(table);
renameTableDefinitionSegment.setRenameTable(renameTable);
when(sqlStatement.getRenameTables()).thenReturn(Collections.singleton(renameTableDefinitionSegment));
- return new TableAvailableSQLStatementContext(mock(), sqlStatement,
Arrays.asList(table, renameTable));
+ when(sqlStatement.getTables()).thenReturn(Arrays.asList(table,
renameTable));
+ return new CommonSQLStatementContext(mock(), sqlStatement);
}
}
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingCopySupportedCheckerTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingCopySupportedCheckerTest.java
index 9b87a1cd193..3e2a30fa218 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingCopySupportedCheckerTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingCopySupportedCheckerTest.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.sharding.checker.sql.dml;
-import
org.apache.shardingsphere.infra.binder.context.statement.TableAvailableSQLStatementContext;
+import
org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
import
org.apache.shardingsphere.sharding.exception.syntax.UnsupportedShardingOperationException;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
@@ -29,7 +29,6 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
-import java.util.Collections;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
@@ -54,10 +53,10 @@ class ShardingCopySupportedCheckerTest {
assertThrows(UnsupportedShardingOperationException.class, () -> new
ShardingCopySupportedChecker().check(rule, mock(), mock(),
createSQLStatementContext()));
}
- private TableAvailableSQLStatementContext createSQLStatementContext() {
+ private CommonSQLStatementContext createSQLStatementContext() {
CopyStatement sqlStatement = mock(CopyStatement.class);
SimpleTableSegment table = new SimpleTableSegment(new
TableNameSegment(0, 0, new IdentifierValue("foo_tbl")));
when(sqlStatement.getTable()).thenReturn(Optional.of(table));
- return new TableAvailableSQLStatementContext(mock(), sqlStatement,
Collections.singleton(table));
+ return new CommonSQLStatementContext(mock(), sqlStatement);
}
}
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingLoadDataSupportedCheckerTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingLoadDataSupportedCheckerTest.java
index 7015d2e2216..4f4841b32da 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingLoadDataSupportedCheckerTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingLoadDataSupportedCheckerTest.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.sharding.checker.sql.dml;
-import
org.apache.shardingsphere.infra.binder.context.statement.TableAvailableSQLStatementContext;
+import
org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
import
org.apache.shardingsphere.sharding.exception.syntax.UnsupportedShardingOperationException;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
@@ -47,7 +47,8 @@ class ShardingLoadDataSupportedCheckerTest {
LoadDataStatement sqlStatement = mock(LoadDataStatement.class);
SimpleTableSegment table = new SimpleTableSegment(new
TableNameSegment(0, 0, new IdentifierValue("foo_tbl")));
when(sqlStatement.getTable()).thenReturn(table);
- assertDoesNotThrow(() -> new
ShardingLoadDataSupportedChecker().check(rule, mock(), mock(), new
TableAvailableSQLStatementContext(mock(), sqlStatement,
Collections.singleton(table))));
+
when(sqlStatement.getTables()).thenReturn(Collections.singleton(table));
+ assertDoesNotThrow(() -> new
ShardingLoadDataSupportedChecker().check(rule, mock(), mock(), new
CommonSQLStatementContext(mock(), sqlStatement)));
}
@Test
@@ -55,8 +56,8 @@ class ShardingLoadDataSupportedCheckerTest {
LoadDataStatement sqlStatement = mock(LoadDataStatement.class);
SimpleTableSegment table = new SimpleTableSegment(new
TableNameSegment(0, 0, new IdentifierValue("foo_tbl")));
when(sqlStatement.getTable()).thenReturn(table);
+
when(sqlStatement.getTables()).thenReturn(Collections.singleton(table));
when(rule.isShardingTable("foo_tbl")).thenReturn(true);
- assertThrows(UnsupportedShardingOperationException.class,
- () -> new ShardingLoadDataSupportedChecker().check(rule,
mock(), mock(), new TableAvailableSQLStatementContext(mock(), sqlStatement,
Collections.singleton(table))));
+ assertThrows(UnsupportedShardingOperationException.class, () -> new
ShardingLoadDataSupportedChecker().check(rule, mock(), mock(), new
CommonSQLStatementContext(mock(), sqlStatement)));
}
}
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingLoadXmlSupportedCheckerTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingLoadXmlSupportedCheckerTest.java
index bab930e7103..8f90c96980e 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingLoadXmlSupportedCheckerTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingLoadXmlSupportedCheckerTest.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.sharding.checker.sql.dml;
-import
org.apache.shardingsphere.infra.binder.context.statement.TableAvailableSQLStatementContext;
+import
org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
import
org.apache.shardingsphere.sharding.exception.syntax.UnsupportedShardingOperationException;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
@@ -47,7 +47,8 @@ class ShardingLoadXmlSupportedCheckerTest {
LoadXMLStatement sqlStatement = mock(LoadXMLStatement.class);
SimpleTableSegment table = new SimpleTableSegment(new
TableNameSegment(0, 0, new IdentifierValue("foo_tbl")));
when(sqlStatement.getTable()).thenReturn(table);
- assertDoesNotThrow(() -> new
ShardingLoadXmlSupportedChecker().check(rule, mock(), mock(), new
TableAvailableSQLStatementContext(mock(), sqlStatement,
Collections.singleton(table))));
+
when(sqlStatement.getTables()).thenReturn(Collections.singleton(table));
+ assertDoesNotThrow(() -> new
ShardingLoadXmlSupportedChecker().check(rule, mock(), mock(), new
CommonSQLStatementContext(mock(), sqlStatement)));
}
@Test
@@ -56,7 +57,7 @@ class ShardingLoadXmlSupportedCheckerTest {
SimpleTableSegment table = new SimpleTableSegment(new
TableNameSegment(0, 0, new IdentifierValue("foo_tbl")));
when(sqlStatement.getTable()).thenReturn(table);
when(rule.isShardingTable("foo_tbl")).thenReturn(true);
- assertThrows(UnsupportedShardingOperationException.class,
- () -> new ShardingLoadXmlSupportedChecker().check(rule,
mock(), mock(), new TableAvailableSQLStatementContext(mock(), sqlStatement,
Collections.singleton(table))));
+
when(sqlStatement.getTables()).thenReturn(Collections.singleton(table));
+ assertThrows(UnsupportedShardingOperationException.class, () -> new
ShardingLoadXmlSupportedChecker().check(rule, mock(), mock(), new
CommonSQLStatementContext(mock(), sqlStatement)));
}
}
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingDropTableRouteContextCheckerTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingDropTableRouteContextCheckerTest.java
index f4e0c7092fc..68b14e8e13c 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingDropTableRouteContextCheckerTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingDropTableRouteContextCheckerTest.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.sharding.route.engine.checker.ddl;
-import
org.apache.shardingsphere.infra.binder.context.statement.TableAvailableSQLStatementContext;
+import
org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.datanode.DataNode;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -94,7 +94,7 @@ class ShardingDropTableRouteContextCheckerTest {
routeUnits.add(routeUnit);
RouteContext routeContext = mock(RouteContext.class);
when(routeContext.getRouteUnits()).thenReturn(routeUnits);
- when(queryContext.getSqlStatementContext()).thenReturn(new
TableAvailableSQLStatementContext(mock(), sqlStatement,
Collections.singleton(table)));
+ when(queryContext.getSqlStatementContext()).thenReturn(new
CommonSQLStatementContext(mock(), sqlStatement));
assertThrows(InUsedTablesException.class, () -> new
ShardingDropTableRouteContextChecker().check(shardingRule, queryContext,
database, mock(ConfigurationProperties.class), routeContext));
}
@@ -128,7 +128,7 @@ class ShardingDropTableRouteContextCheckerTest {
routeUnits.add(new RouteUnit(new RouteMapper("ds_0", "ds_0"),
Collections.singleton(new RouteMapper("t_order", "t_order_0"))));
routeUnits.add(new RouteUnit(new RouteMapper("ds_1", "ds_1"),
Collections.singleton(new RouteMapper("t_order", "t_order_0"))));
when(routeContext.getRouteUnits()).thenReturn(routeUnits);
- when(queryContext.getSqlStatementContext()).thenReturn(new
TableAvailableSQLStatementContext(mock(), sqlStatement,
Collections.singleton(table)));
+ when(queryContext.getSqlStatementContext()).thenReturn(new
CommonSQLStatementContext(mock(), sqlStatement));
assertDoesNotThrow(() -> new
ShardingDropTableRouteContextChecker().check(shardingRule, queryContext,
mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS),
mock(ConfigurationProperties.class), routeContext));
}
@@ -143,7 +143,7 @@ class ShardingDropTableRouteContextCheckerTest {
Collection<RouteUnit> routeUnits = new LinkedList<>();
routeUnits.add(new RouteUnit(new RouteMapper("ds_0", "ds_0"),
Collections.singleton(new RouteMapper("t_order", "t_order_0"))));
when(routeContext.getRouteUnits()).thenReturn(routeUnits);
- when(queryContext.getSqlStatementContext()).thenReturn(new
TableAvailableSQLStatementContext(mock(), sqlStatement,
Collections.singleton(table)));
+ when(queryContext.getSqlStatementContext()).thenReturn(new
CommonSQLStatementContext(mock(), sqlStatement));
assertThrows(ShardingDDLRouteException.class, () -> new
ShardingDropTableRouteContextChecker().check(shardingRule, queryContext,
mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS),
mock(ConfigurationProperties.class), routeContext));
}
@@ -158,7 +158,7 @@ class ShardingDropTableRouteContextCheckerTest {
routeUnits.add(new RouteUnit(new RouteMapper("ds_0", "ds_0"),
Collections.singleton(new RouteMapper("t_config", "t_config"))));
routeUnits.add(new RouteUnit(new RouteMapper("ds_1", "ds_1"),
Collections.singleton(new RouteMapper("t_config", "t_config"))));
when(routeContext.getRouteUnits()).thenReturn(routeUnits);
- when(queryContext.getSqlStatementContext()).thenReturn(new
TableAvailableSQLStatementContext(mock(), sqlStatement,
Collections.singleton(table)));
+ when(queryContext.getSqlStatementContext()).thenReturn(new
CommonSQLStatementContext(mock(), sqlStatement));
assertDoesNotThrow(() -> new
ShardingDropTableRouteContextChecker().check(shardingRule, queryContext,
mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS),
mock(ConfigurationProperties.class), routeContext));
}
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingRenameTableRouteContextCheckerTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingRenameTableRouteContextCheckerTest.java
index 48c83833a44..4c65bd0c66d 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingRenameTableRouteContextCheckerTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingRenameTableRouteContextCheckerTest.java
@@ -17,8 +17,8 @@
package org.apache.shardingsphere.sharding.route.engine.checker.ddl;
+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.TableAvailableSQLStatementContext;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.datanode.DataNode;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -93,6 +93,7 @@ class ShardingRenameTableRouteContextCheckerTest {
SimpleTableSegment renameTable = new SimpleTableSegment(new
TableNameSegment(0, 0, new IdentifierValue("bar_tbl")));
renameTableDefinitionSegment.setRenameTable(renameTable);
when(sqlStatement.getRenameTables()).thenReturn(Collections.singleton(renameTableDefinitionSegment));
- return new TableAvailableSQLStatementContext(mock(), sqlStatement,
Arrays.asList(table, renameTable));
+ when(sqlStatement.getTables()).thenReturn(Arrays.asList(table,
renameTable));
+ return new CommonSQLStatementContext(mock(), sqlStatement);
}
}
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 9a16dda3786..bfaa2e9add9 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
@@ -18,8 +18,8 @@
package org.apache.shardingsphere.sharding.route.engine.type;
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.SQLStatementContext;
-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.config.props.ConfigurationProperties;
@@ -129,8 +129,8 @@ class ShardingRouteEngineFactoryTest {
@Test
void assertNewInstanceForDCLForSingleTable() {
GrantStatement sqlStatement = new GrantStatement();
- TableAvailableSQLStatementContext sqlStatementContext = new
TableAvailableSQLStatementContext(mock(),
- sqlStatement, Collections.singleton(new SimpleTableSegment(new
TableNameSegment(0, 0, new IdentifierValue("tbl")))));
+ sqlStatement.getTables().add(new SimpleTableSegment(new
TableNameSegment(0, 0, new IdentifierValue("tbl"))));
+ SQLStatementContext sqlStatementContext = new
CommonSQLStatementContext(mock(), sqlStatement);
QueryContext queryContext = new QueryContext(sqlStatementContext, "",
Collections.emptyList(), new HintValueContext(), mockConnectionContext(),
mock(ShardingSphereMetaData.class));
ShardingRouteEngine actual =
ShardingRouteEngineFactory.newInstance(shardingRule, database, queryContext,
shardingConditions, Collections.singletonList("tbl"), props);
assertThat(actual,
instanceOf(ShardingTableBroadcastRouteEngine.class));
diff --git
a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/CommonSQLStatementContext.java
b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/CommonSQLStatementContext.java
index 666f6b8acb8..90b05b2e395 100644
---
a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/CommonSQLStatementContext.java
+++
b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/CommonSQLStatementContext.java
@@ -19,17 +19,29 @@ package
org.apache.shardingsphere.infra.binder.context.statement;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
+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
org.apache.shardingsphere.sql.parser.statement.core.statement.TableAvailable;
+
+import java.util.Collections;
/**
* Common SQL statement context.
*/
@RequiredArgsConstructor
@Getter
-public abstract class CommonSQLStatementContext implements SQLStatementContext
{
+public class CommonSQLStatementContext implements SQLStatementContext {
private final DatabaseType databaseType;
private final SQLStatement sqlStatement;
+
+ private final TablesContext tablesContext;
+
+ public CommonSQLStatementContext(final DatabaseType databaseType, final
SQLStatement sqlStatement) {
+ this.databaseType = databaseType;
+ this.sqlStatement = sqlStatement;
+ tablesContext = new TablesContext(sqlStatement instanceof
TableAvailable ? ((TableAvailable) sqlStatement).getTables() :
Collections.emptyList());
+ }
}
diff --git
a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/SQLStatementContextFactory.java
b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/SQLStatementContextFactory.java
index 7f105fefbd6..035a84e4a7a 100644
---
a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/SQLStatementContextFactory.java
+++
b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/SQLStatementContextFactory.java
@@ -113,7 +113,7 @@ public final class SQLStatementContextFactory {
DialectTableAvailableSQLStatementContextWarpProvider.class,
databaseType);
if (sqlStatement instanceof TableAvailable &&
dialectTableAvailableSQLStatementContextWarpProvider
.map(optional ->
dialectTableAvailableSQLStatementContextWarpProvider.get().getNeedToWarpTableAvailableSQLStatementContextTypes().contains(sqlStatement.getClass())).orElse(false))
{
- return new TableAvailableSQLStatementContext(databaseType,
sqlStatement, ((TableAvailable) sqlStatement).getTables());
+ return new CommonSQLStatementContext(databaseType, sqlStatement);
}
if (sqlStatement instanceof DMLStatement) {
return getDMLStatementContext(metaData, databaseType,
(DMLStatement) sqlStatement, params, currentDatabaseName);
@@ -162,10 +162,10 @@ public final class SQLStatementContextFactory {
return new AlterTableStatementContext(databaseType,
(AlterTableStatement) sqlStatement);
}
if (sqlStatement instanceof RenameTableStatement) {
- return new TableAvailableSQLStatementContext(databaseType,
sqlStatement, ((RenameTableStatement) sqlStatement).getTables());
+ return new CommonSQLStatementContext(databaseType, sqlStatement);
}
if (sqlStatement instanceof DropTableStatement) {
- return new TableAvailableSQLStatementContext(databaseType,
sqlStatement, ((DropTableStatement) sqlStatement).getTables());
+ return new CommonSQLStatementContext(databaseType, sqlStatement);
}
if (sqlStatement instanceof CreateIndexStatement) {
return new CreateIndexStatementContext(databaseType,
(CreateIndexStatement) sqlStatement);
@@ -177,10 +177,10 @@ public final class SQLStatementContextFactory {
return new DropIndexStatementContext(databaseType,
(DropIndexStatement) sqlStatement);
}
if (sqlStatement instanceof TruncateStatement) {
- return new TableAvailableSQLStatementContext(databaseType,
sqlStatement, ((TruncateStatement) sqlStatement).getTables());
+ return new CommonSQLStatementContext(databaseType, sqlStatement);
}
if (sqlStatement instanceof CreateFunctionStatement) {
- return new TableAvailableSQLStatementContext(databaseType,
sqlStatement, ((CreateFunctionStatement) sqlStatement).getTables());
+ return new CommonSQLStatementContext(databaseType, sqlStatement);
}
if (sqlStatement instanceof CreateProcedureStatement) {
return new CreateProcedureStatementContext(databaseType,
(CreateProcedureStatement) sqlStatement);
@@ -192,14 +192,13 @@ public final class SQLStatementContextFactory {
return new AlterViewStatementContext(metaData, databaseType,
params, (AlterViewStatement) sqlStatement, currentDatabaseName);
}
if (sqlStatement instanceof DropViewStatement) {
- return new TableAvailableSQLStatementContext(databaseType,
sqlStatement, ((DropViewStatement) sqlStatement).getViews());
+ return new CommonSQLStatementContext(databaseType, sqlStatement);
}
if (sqlStatement instanceof PrepareStatement) {
- return new TableAvailableSQLStatementContext(databaseType,
sqlStatement, ((PrepareStatement) sqlStatement).getTables());
+ return new CommonSQLStatementContext(databaseType, sqlStatement);
}
if (sqlStatement instanceof CommentStatement) {
- return new TableAvailableSQLStatementContext(databaseType,
sqlStatement,
- null == ((CommentStatement) sqlStatement).getTable() ?
Collections.emptyList() : Collections.singletonList(((CommentStatement)
sqlStatement).getTable()));
+ return new CommonSQLStatementContext(databaseType, sqlStatement);
}
if (sqlStatement instanceof CursorStatement) {
return new CursorStatementContext(metaData, databaseType, params,
(CursorStatement) sqlStatement, currentDatabaseName);
@@ -218,10 +217,10 @@ public final class SQLStatementContextFactory {
private static SQLStatementContext getDCLStatementContext(final
DatabaseType databaseType, final DCLStatement sqlStatement) {
if (sqlStatement instanceof GrantStatement) {
- return new TableAvailableSQLStatementContext(databaseType,
sqlStatement, ((GrantStatement) sqlStatement).getTables());
+ return new CommonSQLStatementContext(databaseType, sqlStatement);
}
if (sqlStatement instanceof RevokeStatement) {
- return new TableAvailableSQLStatementContext(databaseType,
sqlStatement, ((RevokeStatement) sqlStatement).getTables());
+ return new CommonSQLStatementContext(databaseType, sqlStatement);
}
return new UnknownSQLStatementContext(databaseType, sqlStatement);
}
@@ -244,7 +243,7 @@ public final class SQLStatementContextFactory {
return new ShowIndexStatementContext(databaseType,
(ShowIndexStatement) sqlStatement);
}
if (sqlStatement instanceof AnalyzeTableStatement) {
- return new TableAvailableSQLStatementContext(databaseType,
sqlStatement, ((AnalyzeTableStatement) sqlStatement).getTables());
+ return new CommonSQLStatementContext(databaseType, sqlStatement);
}
return new UnknownSQLStatementContext(databaseType, sqlStatement);
}
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 256ff44c01b..54d7bc4e8ef 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
@@ -17,7 +17,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.database.core.type.DatabaseType;
import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
@@ -28,13 +27,9 @@ import java.util.Collection;
/**
* Table available SQL statement context.
*/
-@Getter
public final class TableAvailableSQLStatementContext extends
CommonSQLStatementContext {
- private final TablesContext tablesContext;
-
public TableAvailableSQLStatementContext(final DatabaseType databaseType,
final SQLStatement sqlStatement, final Collection<SimpleTableSegment> tables) {
- super(databaseType, sqlStatement);
- tablesContext = new TablesContext(tables);
+ super(databaseType, sqlStatement, new TablesContext(tables));
}
}
diff --git
a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/TableAvailableSQLStatementContextTest.java
b/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/TableAvailableSQLStatementContextTest.java
deleted file mode 100644
index 3dae832bbd9..00000000000
---
a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/TableAvailableSQLStatementContextTest.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.binder.context.statement;
-
-import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo;
-import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
-import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment;
-import
org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement;
-import
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
-import org.junit.jupiter.api.Test;
-
-import java.util.Collections;
-import java.util.stream.Collectors;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.mock;
-
-class TableAvailableSQLStatementContextTest {
-
- @Test
- void assertNewInstance() {
- SQLStatement sqlStatement = mock(SQLStatement.class);
- TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new
IdentifierValue("foo_tbl"));
- tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new
IdentifierValue("foo_db"), new IdentifierValue("foo_schema")));
- SimpleTableSegment table = new SimpleTableSegment(tableNameSegment);
- TableAvailableSQLStatementContext actual = new
TableAvailableSQLStatementContext(mock(), sqlStatement,
Collections.singleton(table));
- assertThat(actual.getSqlStatement(), is(sqlStatement));
-
assertThat(actual.getTablesContext().getSimpleTables().stream().map(each ->
each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()),
- is(Collections.singletonList("foo_tbl")));
- }
-}
diff --git
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/checker/sql/table/SingleDropTableSupportedChecker.java
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/checker/sql/table/SingleDropTableSupportedChecker.java
index d25cb9a8070..5ec74f0f1ab 100644
---
a/kernel/single/core/src/main/java/org/apache/shardingsphere/single/checker/sql/table/SingleDropTableSupportedChecker.java
+++
b/kernel/single/core/src/main/java/org/apache/shardingsphere/single/checker/sql/table/SingleDropTableSupportedChecker.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.single.checker.sql.table;
import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import
org.apache.shardingsphere.infra.binder.context.statement.TableAvailableSQLStatementContext;
import org.apache.shardingsphere.infra.checker.SupportedSQLChecker;
import
org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import
org.apache.shardingsphere.infra.exception.kernel.syntax.UnsupportedDropCascadeTableException;
@@ -30,7 +29,7 @@ import
org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.DropTab
/**
* Drop table supported checker for single.
*/
-public final class SingleDropTableSupportedChecker implements
SupportedSQLChecker<TableAvailableSQLStatementContext, SingleRule> {
+public final class SingleDropTableSupportedChecker implements
SupportedSQLChecker<SQLStatementContext, SingleRule> {
@Override
public boolean isCheck(final SQLStatementContext sqlStatementContext) {
@@ -38,7 +37,7 @@ public final class SingleDropTableSupportedChecker implements
SupportedSQLChecke
}
@Override
- public void check(final SingleRule rule, final ShardingSphereDatabase
database, final ShardingSphereSchema currentSchema, final
TableAvailableSQLStatementContext sqlStatementContext) {
+ public void check(final SingleRule rule, final ShardingSphereDatabase
database, final ShardingSphereSchema currentSchema, final SQLStatementContext
sqlStatementContext) {
ShardingSpherePreconditions.checkState(!((DropTableStatement)
sqlStatementContext.getSqlStatement()).isContainsCascade(),
UnsupportedDropCascadeTableException::new);
}
}
diff --git
a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/checker/sql/SingleDropTableSupportedCheckerTest.java
b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/checker/sql/SingleDropTableSupportedCheckerTest.java
index d8ae952848d..0a15e92a5b8 100644
---
a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/checker/sql/SingleDropTableSupportedCheckerTest.java
+++
b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/checker/sql/SingleDropTableSupportedCheckerTest.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.single.checker.sql;
-import
org.apache.shardingsphere.infra.binder.context.statement.TableAvailableSQLStatementContext;
+import
org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
import
org.apache.shardingsphere.infra.database.core.metadata.database.enums.TableType;
import
org.apache.shardingsphere.infra.exception.kernel.syntax.UnsupportedDropCascadeTableException;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -63,10 +63,10 @@ class SingleDropTableSupportedCheckerTest {
return result;
}
- private TableAvailableSQLStatementContext createSQLStatementContext(final
boolean containsCascade) {
+ private CommonSQLStatementContext createSQLStatementContext(final boolean
containsCascade) {
DropTableStatement dropSchemaStatement =
mock(DropTableStatement.class, RETURNS_DEEP_STUBS);
when(dropSchemaStatement.isContainsCascade()).thenReturn(containsCascade);
when(dropSchemaStatement.getTables()).thenReturn(Collections.emptyList());
- return new TableAvailableSQLStatementContext(mock(),
dropSchemaStatement, Collections.emptyList());
+ return new CommonSQLStatementContext(mock(), dropSchemaStatement);
}
}
diff --git
a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/AnalyzeTableStatement.java
b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/AnalyzeTableStatement.java
index 1ea65ac5709..04a75b6f2ac 100644
---
a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/AnalyzeTableStatement.java
+++
b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dal/AnalyzeTableStatement.java
@@ -21,6 +21,7 @@ import lombok.Getter;
import lombok.RequiredArgsConstructor;
import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.AbstractSQLStatement;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.TableAvailable;
import java.util.Collection;
@@ -29,7 +30,7 @@ import java.util.Collection;
*/
@RequiredArgsConstructor
@Getter
-public final class AnalyzeTableStatement extends AbstractSQLStatement
implements DALStatement {
+public final class AnalyzeTableStatement extends AbstractSQLStatement
implements DALStatement, TableAvailable {
private final Collection<SimpleTableSegment> tables;
}
diff --git
a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dcl/GrantStatement.java
b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dcl/GrantStatement.java
index c8dc93ff149..4fd9e322a90 100644
---
a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dcl/GrantStatement.java
+++
b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dcl/GrantStatement.java
@@ -20,6 +20,7 @@ package
org.apache.shardingsphere.sql.parser.statement.core.statement.dcl;
import lombok.Getter;
import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.AbstractSQLStatement;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.TableAvailable;
import java.util.Collection;
import java.util.LinkedList;
@@ -28,7 +29,7 @@ import java.util.LinkedList;
* Grant statement.
*/
@Getter
-public class GrantStatement extends AbstractSQLStatement implements
DCLStatement {
+public class GrantStatement extends AbstractSQLStatement implements
DCLStatement, TableAvailable {
private final Collection<SimpleTableSegment> tables = new LinkedList<>();
}
diff --git
a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dcl/RevokeStatement.java
b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dcl/RevokeStatement.java
index 9f00f6d0eec..19387998485 100644
---
a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dcl/RevokeStatement.java
+++
b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dcl/RevokeStatement.java
@@ -20,6 +20,7 @@ package
org.apache.shardingsphere.sql.parser.statement.core.statement.dcl;
import lombok.Getter;
import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.AbstractSQLStatement;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.TableAvailable;
import java.util.Collection;
import java.util.LinkedList;
@@ -28,7 +29,7 @@ import java.util.LinkedList;
* Revoke statement.
*/
@Getter
-public class RevokeStatement extends AbstractSQLStatement implements
DCLStatement {
+public class RevokeStatement extends AbstractSQLStatement implements
DCLStatement, TableAvailable {
private final Collection<SimpleTableSegment> tables = new LinkedList<>();
}
diff --git
a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/ddl/CommentStatement.java
b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/ddl/CommentStatement.java
index a6df4a9f6d9..a4cfddd6ce8 100644
---
a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/ddl/CommentStatement.java
+++
b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/ddl/CommentStatement.java
@@ -23,8 +23,11 @@ import
org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.Ind
import
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment;
import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.AbstractSQLStatement;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.TableAvailable;
import
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
+import java.util.Collection;
+import java.util.Collections;
import java.util.Optional;
/**
@@ -32,7 +35,7 @@ import java.util.Optional;
*/
@Getter
@Setter
-public class CommentStatement extends AbstractSQLStatement implements
DDLStatement {
+public class CommentStatement extends AbstractSQLStatement implements
DDLStatement, TableAvailable {
private SimpleTableSegment table;
@@ -50,4 +53,9 @@ public class CommentStatement extends AbstractSQLStatement
implements DDLStateme
public Optional<IndexTypeSegment> getIndexType() {
return Optional.ofNullable(indexType);
}
+
+ @Override
+ public Collection<SimpleTableSegment> getTables() {
+ return null == table ? Collections.emptyList() :
Collections.singletonList(table);
+ }
}
diff --git
a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/ddl/DropTableStatement.java
b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/ddl/DropTableStatement.java
index d0fe22f8d62..504b6bd6911 100644
---
a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/ddl/DropTableStatement.java
+++
b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/ddl/DropTableStatement.java
@@ -21,6 +21,7 @@ import lombok.Getter;
import lombok.Setter;
import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.AbstractSQLStatement;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.TableAvailable;
import java.util.Collection;
import java.util.LinkedList;
@@ -30,7 +31,7 @@ import java.util.LinkedList;
*/
@Getter
@Setter
-public final class DropTableStatement extends AbstractSQLStatement implements
DDLStatement {
+public final class DropTableStatement extends AbstractSQLStatement implements
DDLStatement, TableAvailable {
private final Collection<SimpleTableSegment> tables = new LinkedList<>();
diff --git
a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/ddl/DropViewStatement.java
b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/ddl/DropViewStatement.java
index a709bf42962..5bf1387a46d 100644
---
a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/ddl/DropViewStatement.java
+++
b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/ddl/DropViewStatement.java
@@ -21,6 +21,7 @@ import lombok.Getter;
import lombok.Setter;
import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.AbstractSQLStatement;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.TableAvailable;
import java.util.Collection;
import java.util.LinkedList;
@@ -30,9 +31,14 @@ import java.util.LinkedList;
*/
@Getter
@Setter
-public final class DropViewStatement extends AbstractSQLStatement implements
DDLStatement {
+public final class DropViewStatement extends AbstractSQLStatement implements
DDLStatement, TableAvailable {
private final Collection<SimpleTableSegment> views = new LinkedList<>();
private boolean ifExists;
+
+ @Override
+ public Collection<SimpleTableSegment> getTables() {
+ return views;
+ }
}
diff --git
a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/ddl/TruncateStatement.java
b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/ddl/TruncateStatement.java
index 1478a8ae2fd..ef8091b42e3 100644
---
a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/ddl/TruncateStatement.java
+++
b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/ddl/TruncateStatement.java
@@ -20,6 +20,7 @@ package
org.apache.shardingsphere.sql.parser.statement.core.statement.ddl;
import lombok.Getter;
import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.AbstractSQLStatement;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.TableAvailable;
import java.util.Collection;
import java.util.LinkedList;
@@ -28,7 +29,7 @@ import java.util.LinkedList;
* Truncate table statement.
*/
@Getter
-public final class TruncateStatement extends AbstractSQLStatement implements
DDLStatement {
+public final class TruncateStatement extends AbstractSQLStatement implements
DDLStatement, TableAvailable {
private final Collection<SimpleTableSegment> tables = new LinkedList<>();
}
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 bf826b51d59..071b4acca99 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
@@ -17,8 +17,8 @@
package org.apache.shardingsphere.proxy.backend.connector;
+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.TableAvailableSQLStatementContext;
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;
@@ -252,9 +252,10 @@ class ProxySQLExecutorTest {
return new CreateTableStatementContext(databaseType, sqlStatement);
}
- private TableAvailableSQLStatementContext
createTruncateStatementContext(final DatabaseType databaseType) {
+ private SQLStatementContext createTruncateStatementContext(final
DatabaseType databaseType) {
TruncateStatement sqlStatement = mock(TruncateStatement.class);
- return new TableAvailableSQLStatementContext(databaseType,
sqlStatement, Collections.singletonList(new SimpleTableSegment(new
TableNameSegment(0, 0, new IdentifierValue("t_order")))));
+
when(sqlStatement.getTables()).thenReturn(Collections.singletonList(new
SimpleTableSegment(new TableNameSegment(0, 0, new
IdentifierValue("t_order")))));
+ return new CommonSQLStatementContext(databaseType, sqlStatement);
}
private CursorStatementContext mockCursorStatementContext() {