This is an automated email from the ASF dual-hosted git repository.
sunnianjun 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 6860e622093 Remove useless CreateDatabaseStatementContext (#32109)
6860e622093 is described below
commit 6860e622093ef46f4df42611dd4dfce3896e171e
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Jul 15 14:30:27 2024 +0800
Remove useless CreateDatabaseStatementContext (#32109)
---
.../generator/ConstraintTokenGeneratorTest.java | 6 +--
...DistinctProjectionPrefixTokenGeneratorTest.java | 6 +--
.../token/generator/IndexTokenGeneratorTest.java | 6 +--
.../token/generator/TableTokenGeneratorTest.java | 4 +-
.../ddl/CreateDatabaseStatementContext.java | 36 ----------------
.../ddl/CreateDatabaseStatementContextTest.java | 48 ----------------------
6 files changed, 11 insertions(+), 95 deletions(-)
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/generator/ConstraintTokenGeneratorTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/generator/ConstraintTokenGeneratorTest.java
index 9f0e18b5615..76341a49dac 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/generator/ConstraintTokenGeneratorTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/generator/ConstraintTokenGeneratorTest.java
@@ -17,8 +17,8 @@
package org.apache.shardingsphere.sharding.rewrite.token.generator;
+import
org.apache.shardingsphere.infra.binder.context.statement.UnknownSQLStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.ddl.AlterTableStatementContext;
-import
org.apache.shardingsphere.infra.binder.context.statement.ddl.CreateDatabaseStatementContext;
import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.SQLToken;
import
org.apache.shardingsphere.sharding.rewrite.token.generator.impl.ConstraintTokenGenerator;
import org.apache.shardingsphere.sharding.rewrite.token.pojo.ConstraintToken;
@@ -32,8 +32,8 @@ import java.util.Collections;
import java.util.LinkedList;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -43,7 +43,7 @@ class ConstraintTokenGeneratorTest {
@Test
void assertIsGenerateSQLToken() {
ConstraintTokenGenerator generator = new ConstraintTokenGenerator();
-
assertFalse(generator.isGenerateSQLToken(mock(CreateDatabaseStatementContext.class)));
+
assertFalse(generator.isGenerateSQLToken(mock(UnknownSQLStatementContext.class)));
AlterTableStatementContext alterTableStatementContext =
mock(AlterTableStatementContext.class);
Collection<ConstraintSegment> constraintSegments = new LinkedList<>();
when(alterTableStatementContext.getConstraints()).thenReturn(constraintSegments);
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/generator/DistinctProjectionPrefixTokenGeneratorTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/generator/DistinctProjectionPrefixTokenGeneratorTest.java
index 0eb51b961e3..2a380cce82e 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/generator/DistinctProjectionPrefixTokenGeneratorTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/generator/DistinctProjectionPrefixTokenGeneratorTest.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.sharding.rewrite.token.generator;
import
org.apache.shardingsphere.infra.binder.context.segment.select.projection.impl.AggregationDistinctProjection;
-import
org.apache.shardingsphere.infra.binder.context.statement.ddl.CreateDatabaseStatementContext;
+import
org.apache.shardingsphere.infra.binder.context.statement.UnknownSQLStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
import
org.apache.shardingsphere.sharding.rewrite.token.generator.impl.DistinctProjectionPrefixTokenGenerator;
import org.junit.jupiter.api.Test;
@@ -27,8 +27,8 @@ import java.util.LinkedList;
import java.util.List;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
@@ -39,7 +39,7 @@ class DistinctProjectionPrefixTokenGeneratorTest {
@Test
void assertIsGenerateSQLToken() {
DistinctProjectionPrefixTokenGenerator generator = new
DistinctProjectionPrefixTokenGenerator();
-
assertFalse(generator.isGenerateSQLToken(mock(CreateDatabaseStatementContext.class)));
+
assertFalse(generator.isGenerateSQLToken(mock(UnknownSQLStatementContext.class)));
SelectStatementContext selectStatementContext =
mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
List<AggregationDistinctProjection> aggregationDistinctProjections =
new LinkedList<>();
when(selectStatementContext.getProjectionsContext().getAggregationDistinctProjections()).thenReturn(aggregationDistinctProjections);
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/generator/IndexTokenGeneratorTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/generator/IndexTokenGeneratorTest.java
index 2f16242691d..f9dc599a331 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/generator/IndexTokenGeneratorTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/generator/IndexTokenGeneratorTest.java
@@ -17,8 +17,8 @@
package org.apache.shardingsphere.sharding.rewrite.token.generator;
+import
org.apache.shardingsphere.infra.binder.context.statement.UnknownSQLStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.ddl.AlterIndexStatementContext;
-import
org.apache.shardingsphere.infra.binder.context.statement.ddl.CreateDatabaseStatementContext;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.SQLToken;
@@ -47,9 +47,9 @@ class IndexTokenGeneratorTest {
@Test
void assertIsGenerateSQLToken() {
- CreateDatabaseStatementContext createDatabaseStatementContext =
mock(CreateDatabaseStatementContext.class);
+ UnknownSQLStatementContext sqlStatementContext =
mock(UnknownSQLStatementContext.class);
IndexTokenGenerator generator = new IndexTokenGenerator();
-
assertFalse(generator.isGenerateSQLToken(createDatabaseStatementContext));
+ assertFalse(generator.isGenerateSQLToken(sqlStatementContext));
AlterIndexStatementContext alterIndexStatementContext =
mock(AlterIndexStatementContext.class);
Collection<IndexSegment> indexSegments = new LinkedList<>();
when(alterIndexStatementContext.getIndexes()).thenReturn(indexSegments);
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/generator/TableTokenGeneratorTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/generator/TableTokenGeneratorTest.java
index 538b2c70e39..ddc937ff2f3 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/generator/TableTokenGeneratorTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rewrite/token/generator/TableTokenGeneratorTest.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.sharding.rewrite.token.generator;
import
org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
-import
org.apache.shardingsphere.infra.binder.context.statement.ddl.CreateDatabaseStatementContext;
+import
org.apache.shardingsphere.infra.binder.context.statement.UnknownSQLStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.ddl.CreateTableStatementContext;
import
org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.SQLToken;
@@ -88,7 +88,7 @@ class TableTokenGeneratorTest {
@Test
void assertGenerateSQLTokenWhenSQLStatementIsNotTableAvailable() {
ShardingTableTokenGenerator generator = new
ShardingTableTokenGenerator();
- SQLStatementContext sqlStatementContext =
mock(CreateDatabaseStatementContext.class);
+ SQLStatementContext sqlStatementContext =
mock(UnknownSQLStatementContext.class);
assertThat(generator.generateSQLTokens(sqlStatementContext),
is(Collections.emptyList()));
}
}
diff --git
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateDatabaseStatementContext.java
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateDatabaseStatementContext.java
deleted file mode 100644
index 25874a18db8..00000000000
---
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateDatabaseStatementContext.java
+++ /dev/null
@@ -1,36 +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.infra.binder.context.statement.CommonSQLStatementContext;
-import
org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CreateDatabaseStatement;
-
-/**
- * Create database statement context.
- */
-public final class CreateDatabaseStatementContext extends
CommonSQLStatementContext {
-
- public CreateDatabaseStatementContext(final CreateDatabaseStatement
sqlStatement) {
- super(sqlStatement);
- }
-
- @Override
- public CreateDatabaseStatement getSqlStatement() {
- return (CreateDatabaseStatement) super.getSqlStatement();
- }
-}
diff --git
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateDatabaseStatementContextTest.java
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateDatabaseStatementContextTest.java
deleted file mode 100644
index 342df881e64..00000000000
---
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateDatabaseStatementContextTest.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.ddl;
-
-import
org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
-import
org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CreateDatabaseStatement;
-import
org.apache.shardingsphere.sql.parser.statement.mysql.ddl.MySQLCreateDatabaseStatement;
-import
org.apache.shardingsphere.sql.parser.statement.postgresql.ddl.PostgreSQLCreateDatabaseStatement;
-import org.junit.jupiter.api.Test;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.mock;
-
-class CreateDatabaseStatementContextTest {
-
- @Test
- void assertMySQLNewInstance() {
- assertNewInstance(mock(MySQLCreateDatabaseStatement.class));
- }
-
- @Test
- void assertPostgreSQLNewInstance() {
- assertNewInstance(mock(PostgreSQLCreateDatabaseStatement.class));
- }
-
- private void assertNewInstance(final CreateDatabaseStatement
createDatabaseStatement) {
- CreateDatabaseStatementContext actual = new
CreateDatabaseStatementContext(createDatabaseStatement);
- assertThat(actual, instanceOf(CommonSQLStatementContext.class));
- assertThat(actual.getSqlStatement(), is(createDatabaseStatement));
- }
-}