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 0eef39b0cd6 Add TableAvailableSQLStatementContext (#35582)
0eef39b0cd6 is described below
commit 0eef39b0cd6ad19dcdaaf1f2f31d2254899e9214
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Jun 4 11:43:48 2025 +0800
Add TableAvailableSQLStatementContext (#35582)
---
.../merge/dal/EncryptDALResultDecoratorTest.java | 8 +--
.../EncryptShowCreateTableMergedResultTest.java | 4 +-
.../type/ShardingRouteEngineFactoryTest.java | 8 +--
.../statement/SQLStatementContextFactory.java | 24 +++------
...java => TableAvailableSQLStatementContext.java} | 22 +++++----
.../dal/AnalyzeTableStatementContext.java | 44 -----------------
.../statement/dal/FlushStatementContext.java | 44 -----------------
.../dal/ShowCreateTableStatementContext.java | 44 -----------------
.../statement/dcl/DenyUserStatementContext.java | 44 -----------------
.../statement/dcl/GrantStatementContext.java | 44 -----------------
.../statement/dcl/RevokeStatementContext.java | 44 -----------------
.../statement/ddl/TruncateStatementContext.java | 44 -----------------
... => TableAvailableSQLStatementContextTest.java} | 12 ++---
.../dal/AnalyzeTableStatementContextTest.java | 57 ----------------------
.../dal/OptimizeTableStatementContextTest.java | 52 --------------------
.../dal/ShowCreateTableStatementContextTest.java | 48 ------------------
.../statement/dcl/GrantStatementContextTest.java | 5 +-
.../statement/dcl/RevokeStatementContextTest.java | 51 -------------------
.../ddl/TruncateStatementContextTest.java | 52 --------------------
.../backend/connector/ProxySQLExecutorTest.java | 9 ++--
20 files changed, 42 insertions(+), 618 deletions(-)
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 df4426573f5..086a30014ea 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
@@ -21,9 +21,9 @@ import
org.apache.shardingsphere.encrypt.merge.dal.show.EncryptShowColumnsMerged
import
org.apache.shardingsphere.encrypt.merge.dal.show.EncryptShowCreateTableMergedResult;
import org.apache.shardingsphere.encrypt.rule.EncryptRule;
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.dal.ExplainStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.dal.ShowColumnsStatementContext;
-import
org.apache.shardingsphere.infra.binder.context.statement.dal.ShowCreateTableStatementContext;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
@@ -75,7 +75,7 @@ class EncryptDALResultDecoratorTest {
@Test
void assertMergedResultWithShowCreateTableStatement() {
- sqlStatementContext = getShowCreateTableStatementContext();
+ sqlStatementContext = mockShowCreateTableStatementContext();
RuleMetaData ruleMetaData = mock(RuleMetaData.class);
when(ruleMetaData.getSingleRule(SQLParserRule.class)).thenReturn(mock(SQLParserRule.class));
EncryptDALResultDecorator decorator = new
EncryptDALResultDecorator(ruleMetaData);
@@ -105,8 +105,8 @@ class EncryptDALResultDecoratorTest {
return result;
}
- private SQLStatementContext getShowCreateTableStatementContext() {
- ShowCreateTableStatementContext result =
mock(ShowCreateTableStatementContext.class, RETURNS_DEEP_STUBS);
+ private SQLStatementContext mockShowCreateTableStatementContext() {
+ TableAvailableSQLStatementContext result =
mock(TableAvailableSQLStatementContext.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 a87a7799bf0..68f7fea9c8b 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
@@ -24,7 +24,7 @@ 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.statement.dal.ShowCreateTableStatementContext;
+import
org.apache.shardingsphere.infra.binder.context.statement.TableAvailableSQLStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.merge.result.MergedResult;
@@ -207,7 +207,7 @@ class EncryptShowCreateTableMergedResultTest {
}
private EncryptShowCreateTableMergedResult createMergedResult(final
MergedResult mergedResult, final String tableName, final EncryptRule rule) {
- ShowCreateTableStatementContext sqlStatementContext =
mock(ShowCreateTableStatementContext.class, RETURNS_DEEP_STUBS);
+ TableAvailableSQLStatementContext sqlStatementContext =
mock(TableAvailableSQLStatementContext.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/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 ae27cce26ba..524dd5e2193 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
@@ -19,7 +19,7 @@ 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.SQLStatementContext;
-import
org.apache.shardingsphere.infra.binder.context.statement.dcl.GrantStatementContext;
+import
org.apache.shardingsphere.infra.binder.context.statement.TableAvailableSQLStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.ddl.CursorStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.TableAvailable;
@@ -130,9 +130,9 @@ class ShardingRouteEngineFactoryTest {
@Test
void assertNewInstanceForDCLForSingleTable() {
- GrantStatement grantStatement = new GrantStatement();
- grantStatement.getTables().add(new SimpleTableSegment(new
TableNameSegment(0, 0, new IdentifierValue("tbl"))));
- GrantStatementContext sqlStatementContext = new
GrantStatementContext(mock(), grantStatement);
+ GrantStatement sqlStatement = new GrantStatement();
+ TableAvailableSQLStatementContext sqlStatementContext = new
TableAvailableSQLStatementContext(mock(),
+ sqlStatement, new SimpleTableSegment(new TableNameSegment(0,
0, new IdentifierValue("tbl"))));
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/SQLStatementContextFactory.java
b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/SQLStatementContextFactory.java
index dc30405590f..24af456853e 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
@@ -19,18 +19,11 @@ package
org.apache.shardingsphere.infra.binder.context.statement;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import
org.apache.shardingsphere.infra.binder.context.statement.dal.AnalyzeTableStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.dal.ExplainStatementContext;
-import
org.apache.shardingsphere.infra.binder.context.statement.dal.FlushStatementContext;
-import
org.apache.shardingsphere.infra.binder.context.statement.dal.OptimizeTableStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.dal.ShowColumnsStatementContext;
-import
org.apache.shardingsphere.infra.binder.context.statement.dal.ShowCreateTableStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.dal.ShowIndexStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.dal.ShowTableStatusStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.dal.ShowTablesStatementContext;
-import
org.apache.shardingsphere.infra.binder.context.statement.dcl.DenyUserStatementContext;
-import
org.apache.shardingsphere.infra.binder.context.statement.dcl.GrantStatementContext;
-import
org.apache.shardingsphere.infra.binder.context.statement.dcl.RevokeStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.ddl.AlterIndexStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.ddl.AlterTableStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.ddl.AlterViewStatementContext;
@@ -50,7 +43,6 @@ import
org.apache.shardingsphere.infra.binder.context.statement.ddl.FetchStateme
import
org.apache.shardingsphere.infra.binder.context.statement.ddl.MoveStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.ddl.PrepareStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.ddl.RenameTableStatementContext;
-import
org.apache.shardingsphere.infra.binder.context.statement.ddl.TruncateStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.dml.CopyStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.dml.DeleteStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext;
@@ -201,7 +193,7 @@ public final class SQLStatementContextFactory {
return new DropIndexStatementContext(databaseType,
(DropIndexStatement) sqlStatement);
}
if (sqlStatement instanceof TruncateStatement) {
- return new TruncateStatementContext(databaseType,
(TruncateStatement) sqlStatement);
+ return new TableAvailableSQLStatementContext(databaseType,
sqlStatement, ((TruncateStatement) sqlStatement).getTables());
}
if (sqlStatement instanceof CreateFunctionStatement) {
return new CreateFunctionStatementContext(databaseType,
(CreateFunctionStatement) sqlStatement);
@@ -241,13 +233,13 @@ public final class SQLStatementContextFactory {
private static SQLStatementContext getDCLStatementContext(final
DatabaseType databaseType, final DCLStatement sqlStatement) {
if (sqlStatement instanceof GrantStatement) {
- return new GrantStatementContext(databaseType, (GrantStatement)
sqlStatement);
+ return new TableAvailableSQLStatementContext(databaseType,
sqlStatement, ((GrantStatement) sqlStatement).getTables());
}
if (sqlStatement instanceof RevokeStatement) {
- return new RevokeStatementContext(databaseType, (RevokeStatement)
sqlStatement);
+ return new TableAvailableSQLStatementContext(databaseType,
sqlStatement, ((RevokeStatement) sqlStatement).getTables());
}
if (sqlStatement instanceof DenyUserStatement) {
- return new DenyUserStatementContext(databaseType,
(DenyUserStatement) sqlStatement);
+ return new TableAvailableSQLStatementContext(databaseType,
sqlStatement, ((DenyUserStatement) sqlStatement).getTable());
}
return new UnknownSQLStatementContext(databaseType, sqlStatement);
}
@@ -258,7 +250,7 @@ public final class SQLStatementContextFactory {
return new ExplainStatementContext(metaData, databaseType,
(ExplainStatement) sqlStatement, params, currentDatabaseName);
}
if (sqlStatement instanceof ShowCreateTableStatement) {
- return new ShowCreateTableStatementContext(databaseType,
(ShowCreateTableStatement) sqlStatement);
+ return new TableAvailableSQLStatementContext(databaseType,
sqlStatement, ((ShowCreateTableStatement) sqlStatement).getTable());
}
if (sqlStatement instanceof ShowColumnsStatement) {
return new ShowColumnsStatementContext(databaseType,
(ShowColumnsStatement) sqlStatement);
@@ -273,13 +265,13 @@ public final class SQLStatementContextFactory {
return new ShowIndexStatementContext(databaseType,
(ShowIndexStatement) sqlStatement);
}
if (sqlStatement instanceof AnalyzeTableStatement) {
- return new AnalyzeTableStatementContext(databaseType,
(AnalyzeTableStatement) sqlStatement);
+ return new TableAvailableSQLStatementContext(databaseType,
sqlStatement, ((AnalyzeTableStatement) sqlStatement).getTables());
}
if (sqlStatement instanceof FlushStatement) {
- return new FlushStatementContext(databaseType, (FlushStatement)
sqlStatement);
+ return new TableAvailableSQLStatementContext(databaseType,
sqlStatement, ((FlushStatement) sqlStatement).getTables());
}
if (sqlStatement instanceof OptimizeTableStatement) {
- return new OptimizeTableStatementContext(databaseType,
(OptimizeTableStatement) sqlStatement);
+ return new TableAvailableSQLStatementContext(databaseType,
sqlStatement, ((OptimizeTableStatement) sqlStatement).getTables());
}
return new UnknownSQLStatementContext(databaseType, sqlStatement);
}
diff --git
a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/OptimizeTableStatementContext.java
b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/TableAvailableSQLStatementContext.java
similarity index 63%
rename from
infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/OptimizeTableStatementContext.java
rename to
infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/TableAvailableSQLStatementContext.java
index 22c205900af..96c8613991f 100644
---
a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/OptimizeTableStatementContext.java
+++
b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/TableAvailableSQLStatementContext.java
@@ -15,30 +15,32 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.binder.context.statement.dal;
+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.statement.CommonSQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.TableAvailable;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
-import
org.apache.shardingsphere.sql.parser.statement.core.statement.dal.OptimizeTableStatement;
+import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement;
+
+import java.util.Collection;
/**
- * Optimize table statement context.
+ * Table available SQL statement context.
*/
@Getter
-public final class OptimizeTableStatementContext extends
CommonSQLStatementContext implements TableAvailable {
+public final class TableAvailableSQLStatementContext extends
CommonSQLStatementContext implements TableAvailable {
private final TablesContext tablesContext;
- public OptimizeTableStatementContext(final DatabaseType databaseType,
final OptimizeTableStatement sqlStatement) {
+ public TableAvailableSQLStatementContext(final DatabaseType databaseType,
final SQLStatement sqlStatement, final SimpleTableSegment table) {
super(databaseType, sqlStatement);
- tablesContext = new TablesContext(sqlStatement.getTables());
+ tablesContext = new TablesContext(table);
}
- @Override
- public OptimizeTableStatement getSqlStatement() {
- return (OptimizeTableStatement) super.getSqlStatement();
+ public TableAvailableSQLStatementContext(final DatabaseType databaseType,
final SQLStatement sqlStatement, final Collection<SimpleTableSegment> tables) {
+ super(databaseType, sqlStatement);
+ tablesContext = new TablesContext(tables);
}
}
diff --git
a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/AnalyzeTableStatementContext.java
b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/AnalyzeTableStatementContext.java
deleted file mode 100644
index c0d1d446639..00000000000
---
a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/AnalyzeTableStatementContext.java
+++ /dev/null
@@ -1,44 +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.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.TableAvailable;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
-import
org.apache.shardingsphere.sql.parser.statement.core.statement.dal.AnalyzeTableStatement;
-
-/**
- * Analyze table statement context.
- */
-@Getter
-public final class AnalyzeTableStatementContext extends
CommonSQLStatementContext implements TableAvailable {
-
- private final TablesContext tablesContext;
-
- public AnalyzeTableStatementContext(final DatabaseType databaseType, final
AnalyzeTableStatement sqlStatement) {
- super(databaseType, sqlStatement);
- tablesContext = new TablesContext(sqlStatement.getTables());
- }
-
- @Override
- public AnalyzeTableStatement getSqlStatement() {
- return (AnalyzeTableStatement) super.getSqlStatement();
- }
-}
diff --git
a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/FlushStatementContext.java
b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/FlushStatementContext.java
deleted file mode 100644
index d34969ccf5a..00000000000
---
a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/FlushStatementContext.java
+++ /dev/null
@@ -1,44 +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.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.TableAvailable;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
-import
org.apache.shardingsphere.sql.parser.statement.core.statement.dal.FlushStatement;
-
-/**
- * Flush statement context.
- */
-@Getter
-public final class FlushStatementContext extends CommonSQLStatementContext
implements TableAvailable {
-
- private final TablesContext tablesContext;
-
- public FlushStatementContext(final DatabaseType databaseType, final
FlushStatement sqlStatement) {
- super(databaseType, sqlStatement);
- tablesContext = new TablesContext(sqlStatement.getTables());
- }
-
- @Override
- public FlushStatement getSqlStatement() {
- return (FlushStatement) super.getSqlStatement();
- }
-}
diff --git
a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowCreateTableStatementContext.java
b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowCreateTableStatementContext.java
deleted file mode 100644
index 7c13f8ba4fb..00000000000
---
a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowCreateTableStatementContext.java
+++ /dev/null
@@ -1,44 +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.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.TableAvailable;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
-import
org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowCreateTableStatement;
-
-/**
- * Show create table statement context.
- */
-@Getter
-public final class ShowCreateTableStatementContext extends
CommonSQLStatementContext implements TableAvailable {
-
- private final TablesContext tablesContext;
-
- public ShowCreateTableStatementContext(final DatabaseType databaseType,
final ShowCreateTableStatement sqlStatement) {
- super(databaseType, sqlStatement);
- tablesContext = new TablesContext(sqlStatement.getTable());
- }
-
- @Override
- public ShowCreateTableStatement getSqlStatement() {
- return (ShowCreateTableStatement) super.getSqlStatement();
- }
-}
diff --git
a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/DenyUserStatementContext.java
b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/DenyUserStatementContext.java
deleted file mode 100644
index 149c74793b7..00000000000
---
a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/DenyUserStatementContext.java
+++ /dev/null
@@ -1,44 +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.dcl;
-
-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.TableAvailable;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
-import
org.apache.shardingsphere.sql.parser.statement.core.statement.dcl.DenyUserStatement;
-
-/**
- * Deny user statement context.
- */
-@Getter
-public final class DenyUserStatementContext extends CommonSQLStatementContext
implements TableAvailable {
-
- private final TablesContext tablesContext;
-
- public DenyUserStatementContext(final DatabaseType databaseType, final
DenyUserStatement sqlStatement) {
- super(databaseType, sqlStatement);
- tablesContext = new TablesContext(sqlStatement.getTable());
- }
-
- @Override
- public DenyUserStatement getSqlStatement() {
- return (DenyUserStatement) super.getSqlStatement();
- }
-}
diff --git
a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/GrantStatementContext.java
b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/GrantStatementContext.java
deleted file mode 100644
index 3835a795d2d..00000000000
---
a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/GrantStatementContext.java
+++ /dev/null
@@ -1,44 +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.dcl;
-
-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.TableAvailable;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
-import
org.apache.shardingsphere.sql.parser.statement.core.statement.dcl.GrantStatement;
-
-/**
- * Grant statement context.
- */
-@Getter
-public final class GrantStatementContext extends CommonSQLStatementContext
implements TableAvailable {
-
- private final TablesContext tablesContext;
-
- public GrantStatementContext(final DatabaseType databaseType, final
GrantStatement sqlStatement) {
- super(databaseType, sqlStatement);
- tablesContext = new TablesContext(sqlStatement.getTables());
- }
-
- @Override
- public GrantStatement getSqlStatement() {
- return (GrantStatement) super.getSqlStatement();
- }
-}
diff --git
a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/RevokeStatementContext.java
b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/RevokeStatementContext.java
deleted file mode 100644
index cb40431825d..00000000000
---
a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/RevokeStatementContext.java
+++ /dev/null
@@ -1,44 +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.dcl;
-
-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.TableAvailable;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
-import
org.apache.shardingsphere.sql.parser.statement.core.statement.dcl.RevokeStatement;
-
-/**
- * Revoke statement context.
- */
-@Getter
-public final class RevokeStatementContext extends CommonSQLStatementContext
implements TableAvailable {
-
- private final TablesContext tablesContext;
-
- public RevokeStatementContext(final DatabaseType databaseType, final
RevokeStatement sqlStatement) {
- super(databaseType, sqlStatement);
- tablesContext = new TablesContext(sqlStatement.getTables());
- }
-
- @Override
- public RevokeStatement getSqlStatement() {
- return (RevokeStatement) super.getSqlStatement();
- }
-}
diff --git
a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/TruncateStatementContext.java
b/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/TruncateStatementContext.java
deleted file mode 100644
index 45455984a6a..00000000000
---
a/infra/binder/core/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/TruncateStatementContext.java
+++ /dev/null
@@ -1,44 +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.ddl;
-
-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.TableAvailable;
-import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
-import
org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.TruncateStatement;
-
-/**
- * Truncate statement context.
- */
-@Getter
-public final class TruncateStatementContext extends CommonSQLStatementContext
implements TableAvailable {
-
- private final TablesContext tablesContext;
-
- public TruncateStatementContext(final DatabaseType databaseType, final
TruncateStatement sqlStatement) {
- super(databaseType, sqlStatement);
- tablesContext = new TablesContext(sqlStatement.getTables());
- }
-
- @Override
- public TruncateStatement getSqlStatement() {
- return (TruncateStatement) super.getSqlStatement();
- }
-}
diff --git
a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/DenyUserStatementContextTest.java
b/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/TableAvailableSQLStatementContextTest.java
similarity index 86%
rename from
infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/DenyUserStatementContextTest.java
rename to
infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/TableAvailableSQLStatementContextTest.java
index 60839db9ee7..7d7b8d21265 100644
---
a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/DenyUserStatementContextTest.java
+++
b/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/TableAvailableSQLStatementContextTest.java
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.binder.context.statement.dcl;
+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.dcl.DenyUserStatement;
+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;
@@ -30,18 +30,16 @@ import java.util.stream.Collectors;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-class DenyUserStatementContextTest {
+class TableAvailableSQLStatementContextTest {
@Test
void assertNewInstance() {
- DenyUserStatement sqlStatement = mock(DenyUserStatement.class);
+ 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);
- when(sqlStatement.getTable()).thenReturn(table);
- DenyUserStatementContext actual = new DenyUserStatementContext(mock(),
sqlStatement);
+ TableAvailableSQLStatementContext actual = new
TableAvailableSQLStatementContext(mock(), sqlStatement, 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/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/AnalyzeTableStatementContextTest.java
b/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/AnalyzeTableStatementContextTest.java
deleted file mode 100644
index 1393553faf6..00000000000
---
a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/AnalyzeTableStatementContextTest.java
+++ /dev/null
@@ -1,57 +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.dal;
-
-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.dal.AnalyzeTableStatement;
-import
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
-import org.junit.jupiter.api.Test;
-
-import java.util.Arrays;
-import java.util.stream.Collectors;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class AnalyzeTableStatementContextTest {
-
- @Test
- void assertNewInstance() {
- AnalyzeTableStatement analyzeTableStatement =
mockAnalyzeTableStatement();
- AnalyzeTableStatementContext actual = new
AnalyzeTableStatementContext(mock(), analyzeTableStatement);
- assertThat(actual.getSqlStatement(), is(analyzeTableStatement));
- assertThat(actual.getTablesContext().getSimpleTables().stream()
- .map(each ->
each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()),
is(Arrays.asList("foo_tbl", "bar_tbl")));
- }
-
- private AnalyzeTableStatement mockAnalyzeTableStatement() {
- AnalyzeTableStatement result = mock(AnalyzeTableStatement.class);
- when(result.getTables()).thenReturn(Arrays.asList(new
SimpleTableSegment(createTableNameSegment("foo_tbl")), new
SimpleTableSegment(createTableNameSegment("bar_tbl"))));
- return result;
- }
-
- private TableNameSegment createTableNameSegment(final String tableName) {
- TableNameSegment result = new TableNameSegment(0, 0, new
IdentifierValue(tableName));
- result.setTableBoundInfo(new TableSegmentBoundInfo(new
IdentifierValue("foo_db"), new IdentifierValue("foo_schema")));
- return result;
- }
-}
diff --git
a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/OptimizeTableStatementContextTest.java
b/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/OptimizeTableStatementContextTest.java
deleted file mode 100644
index feea27224e3..00000000000
---
a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/OptimizeTableStatementContextTest.java
+++ /dev/null
@@ -1,52 +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.dal;
-
-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.dal.OptimizeTableStatement;
-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;
-import static org.mockito.Mockito.when;
-
-class OptimizeTableStatementContextTest {
-
- @Test
- void assertNewInstance() {
- OptimizeTableStatement sqlStatement =
mock(OptimizeTableStatement.class);
- when(sqlStatement.getTables()).thenReturn(Collections.singleton(new
SimpleTableSegment(createTableNameSegment())));
- OptimizeTableStatementContext actual = new
OptimizeTableStatementContext(mock(), sqlStatement);
- assertThat(actual.getSqlStatement(), is(sqlStatement));
- assertThat(actual.getTablesContext().getSimpleTables().stream()
- .map(each ->
each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()),
is(Collections.singletonList("foo_tbl")));
- }
-
- private TableNameSegment createTableNameSegment() {
- TableNameSegment result = new TableNameSegment(0, 0, new
IdentifierValue("foo_tbl"));
- result.setTableBoundInfo(new TableSegmentBoundInfo(new
IdentifierValue("foo_db"), new IdentifierValue("foo_schema")));
- return result;
- }
-}
diff --git
a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowCreateTableStatementContextTest.java
b/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowCreateTableStatementContextTest.java
deleted file mode 100644
index 10937467c2d..00000000000
---
a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowCreateTableStatementContextTest.java
+++ /dev/null
@@ -1,48 +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.dal;
-
-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.dal.ShowCreateTableStatement;
-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;
-import static org.mockito.Mockito.when;
-
-class ShowCreateTableStatementContextTest {
-
- @Test
- void assertNewInstance() {
- ShowCreateTableStatement sqlStatement =
mock(ShowCreateTableStatement.class);
- TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new
IdentifierValue("foo_tbl"));
- tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new
IdentifierValue("foo_db"), new IdentifierValue("foo_schema")));
- when(sqlStatement.getTable()).thenReturn(new
SimpleTableSegment(tableNameSegment));
- ShowCreateTableStatementContext actual = new
ShowCreateTableStatementContext(mock(), sqlStatement);
- 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/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/GrantStatementContextTest.java
b/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/GrantStatementContextTest.java
index 4c5f3ff2792..621dea32bc1 100644
---
a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/GrantStatementContextTest.java
+++
b/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/GrantStatementContextTest.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.infra.binder.context.statement.dcl;
+import
org.apache.shardingsphere.infra.binder.context.statement.TableAvailableSQLStatementContext;
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;
@@ -36,8 +37,8 @@ class GrantStatementContextTest {
@Test
void assertNewInstance() {
GrantStatement sqlStatement = new GrantStatement();
- sqlStatement.getTables().addAll(Arrays.asList(new
SimpleTableSegment(createTableNameSegment("foo_tbl")), new
SimpleTableSegment(createTableNameSegment("bar_tbl"))));
- GrantStatementContext actual = new GrantStatementContext(mock(),
sqlStatement);
+ TableAvailableSQLStatementContext actual = new
TableAvailableSQLStatementContext(mock(),
+ sqlStatement, Arrays.asList(new
SimpleTableSegment(createTableNameSegment("foo_tbl")), new
SimpleTableSegment(createTableNameSegment("bar_tbl"))));
assertThat(actual.getSqlStatement(), is(sqlStatement));
assertThat(actual.getTablesContext().getSimpleTables().stream()
.map(each ->
each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()),
is(Arrays.asList("foo_tbl", "bar_tbl")));
diff --git
a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/RevokeStatementContextTest.java
b/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/RevokeStatementContextTest.java
deleted file mode 100644
index 8db99c4812f..00000000000
---
a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/RevokeStatementContextTest.java
+++ /dev/null
@@ -1,51 +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.dcl;
-
-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.dcl.RevokeStatement;
-import
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
-import org.junit.jupiter.api.Test;
-
-import java.util.Arrays;
-import java.util.stream.Collectors;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.mock;
-
-class RevokeStatementContextTest {
-
- @Test
- void assertNewInstance() {
- RevokeStatement revokeStatement = new RevokeStatement();
- revokeStatement.getTables().addAll(Arrays.asList(new
SimpleTableSegment(createTableNameSegment("foo_tbl")), new
SimpleTableSegment(createTableNameSegment("bar_tbl"))));
- RevokeStatementContext actual = new RevokeStatementContext(mock(),
revokeStatement);
- assertThat(actual.getSqlStatement(), is(revokeStatement));
- assertThat(actual.getTablesContext().getSimpleTables().stream()
- .map(each ->
each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()),
is(Arrays.asList("foo_tbl", "bar_tbl")));
- }
-
- private TableNameSegment createTableNameSegment(final String tableName) {
- TableNameSegment result = new TableNameSegment(0, 0, new
IdentifierValue(tableName));
- result.setTableBoundInfo(new TableSegmentBoundInfo(new
IdentifierValue("foo_db"), new IdentifierValue("foo_schema")));
- return result;
- }
-}
diff --git
a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/TruncateStatementContextTest.java
b/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/TruncateStatementContextTest.java
deleted file mode 100644
index 2faaf12361d..00000000000
---
a/infra/binder/core/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/TruncateStatementContextTest.java
+++ /dev/null
@@ -1,52 +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.ddl;
-
-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.ddl.TruncateStatement;
-import
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
-import org.junit.jupiter.api.Test;
-
-import java.util.Arrays;
-import java.util.stream.Collectors;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class TruncateStatementContextTest {
-
- @Test
- void assertNewInstance() {
- TruncateStatement truncateStatement = mock(TruncateStatement.class);
- when(truncateStatement.getTables()).thenReturn(Arrays.asList(new
SimpleTableSegment(createTableNameSegment("foo_tbl")), new
SimpleTableSegment(createTableNameSegment("bar_tbl"))));
- TruncateStatementContext actual = new TruncateStatementContext(mock(),
truncateStatement);
- assertThat(actual.getSqlStatement(), is(truncateStatement));
- assertThat(actual.getTablesContext().getSimpleTables().stream()
- .map(each ->
each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()),
is(Arrays.asList("foo_tbl", "bar_tbl")));
- }
-
- private TableNameSegment createTableNameSegment(final String tableName) {
- TableNameSegment result = new TableNameSegment(0, 0, new
IdentifierValue(tableName));
- result.setTableBoundInfo(new TableSegmentBoundInfo(new
IdentifierValue("foo_db"), new IdentifierValue("foo_schema")));
- return result;
- }
-}
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 cdd2690fef0..14bab0217a5 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
@@ -18,9 +18,9 @@
package org.apache.shardingsphere.proxy.backend.connector;
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.ddl.CreateTableStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.ddl.CursorStatementContext;
-import
org.apache.shardingsphere.infra.binder.context.statement.ddl.TruncateStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.dml.InsertStatementContext;
import org.apache.shardingsphere.infra.binder.context.type.TableAvailable;
import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
@@ -179,7 +179,7 @@ class ProxySQLExecutorTest {
}
@Test
- void
assertCheckExecutePrerequisitesWhenExecuteDDLInPostgreSQLTransaction() {
+ void
assertCheckExecutePrerequisitesWhenExecuteCreateTableInPostgreSQLTransaction() {
when(transactionRule.getDefaultType()).thenReturn(TransactionType.LOCAL);
ExecutionContext executionContext = new ExecutionContext(
new
QueryContext(createCreateTableStatementContext(postgresqlDatabaseType), "",
Collections.emptyList(), new HintValueContext(), mockConnectionContext(),
@@ -254,10 +254,9 @@ class ProxySQLExecutorTest {
return new CreateTableStatementContext(databaseType, sqlStatement);
}
- private TruncateStatementContext createTruncateStatementContext(final
DatabaseType databaseType) {
+ private TableAvailableSQLStatementContext
createTruncateStatementContext(final DatabaseType databaseType) {
TruncateStatement sqlStatement = mock(TruncateStatement.class);
-
when(sqlStatement.getTables()).thenReturn(Collections.singletonList(new
SimpleTableSegment(new TableNameSegment(0, 0, new
IdentifierValue("t_order")))));
- return new TruncateStatementContext(databaseType, sqlStatement);
+ return new TableAvailableSQLStatementContext(databaseType,
sqlStatement, Collections.singletonList(new SimpleTableSegment(new
TableNameSegment(0, 0, new IdentifierValue("t_order")))));
}
private CursorStatementContext mockCursorStatementContext() {