This is an automated email from the ASF dual-hosted git repository.
jiangmaolin 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 c6e8b407260 Refactor MySQLAdminExecutorCreator (#32683)
c6e8b407260 is described below
commit c6e8b407260cc198de0309e52614b4f241dd5f5d
Author: Raigor <[email protected]>
AuthorDate: Mon Aug 26 19:16:23 2024 +0800
Refactor MySQLAdminExecutorCreator (#32683)
---
.../handler/admin/MySQLAdminExecutorCreator.java | 41 +++++++------
.../admin/MySQLAdminExecutorCreatorTest.java | 6 +-
.../executor/MySQLAdminExecutorFactoryTest.java | 67 ----------------------
3 files changed, 23 insertions(+), 91 deletions(-)
diff --git
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLAdminExecutorCreator.java
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLAdminExecutorCreator.java
index 6f60b67a084..c9098dd7ab0 100644
---
a/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLAdminExecutorCreator.java
+++
b/proxy/backend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLAdminExecutorCreator.java
@@ -40,14 +40,14 @@ import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.UseD
import
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ExpressionProjectionSegment;
import
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ProjectionSegment;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.dal.KillStatement;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.dal.SetStatement;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowCreateDatabaseStatement;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowDatabasesStatement;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowFunctionStatusStatement;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowProcedureStatusStatement;
-import
org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowTablesStatement;
-import
org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowDatabasesStatement;
-import
org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowCreateDatabaseStatement;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowProcessListStatement;
-import
org.apache.shardingsphere.sql.parser.statement.core.statement.dal.KillStatement;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.dal.ShowTablesStatement;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.dal.UseStatement;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.dml.SelectStatement;
@@ -71,42 +71,41 @@ public final class MySQLAdminExecutorCreator implements
DatabaseAdminExecutorCre
@Override
public Optional<DatabaseAdminExecutor> create(final SQLStatementContext
sqlStatementContext) {
- SQLStatement sqlStatement = sqlStatementContext.getSqlStatement();
- if (sqlStatement instanceof ShowFunctionStatusStatement) {
- return Optional.of(new
ShowFunctionStatusExecutor((ShowFunctionStatusStatement) sqlStatement));
- }
- if (sqlStatement instanceof ShowProcedureStatusStatement) {
- return Optional.of(new
ShowProcedureStatusExecutor((ShowProcedureStatusStatement) sqlStatement));
- }
- if (sqlStatement instanceof ShowTablesStatement) {
- return Optional.of(new ShowTablesExecutor((ShowTablesStatement)
sqlStatement, sqlStatementContext.getDatabaseType()));
- }
return Optional.empty();
}
@Override
public Optional<DatabaseAdminExecutor> create(final SQLStatementContext
sqlStatementContext, final String sql, final String databaseName, final
List<Object> parameters) {
SQLStatement sqlStatement = sqlStatementContext.getSqlStatement();
+ if (sqlStatement instanceof SelectStatement) {
+ return create((SelectStatement) sqlStatement, sql, databaseName,
parameters);
+ }
if (sqlStatement instanceof UseStatement) {
return Optional.of(new UseDatabaseExecutor((UseStatement)
sqlStatement));
}
if (sqlStatement instanceof ShowDatabasesStatement) {
return Optional.of(new
ShowDatabasesExecutor((ShowDatabasesStatement) sqlStatement));
}
- if (sqlStatement instanceof ShowProcessListStatement) {
- return Optional.of(new
ShowProcessListExecutor(((ShowProcessListStatement) sqlStatement).isFull()));
- }
- if (sqlStatement instanceof KillStatement) {
- return Optional.of(new KillProcessExecutor((KillStatement)
sqlStatement));
+ if (sqlStatement instanceof ShowTablesStatement) {
+ return Optional.of(new ShowTablesExecutor((ShowTablesStatement)
sqlStatement, sqlStatementContext.getDatabaseType()));
}
if (sqlStatement instanceof ShowCreateDatabaseStatement) {
return Optional.of(new
ShowCreateDatabaseExecutor((ShowCreateDatabaseStatement) sqlStatement));
}
+ if (sqlStatement instanceof ShowFunctionStatusStatement) {
+ return Optional.of(new
ShowFunctionStatusExecutor((ShowFunctionStatusStatement) sqlStatement));
+ }
+ if (sqlStatement instanceof ShowProcedureStatusStatement) {
+ return Optional.of(new
ShowProcedureStatusExecutor((ShowProcedureStatusStatement) sqlStatement));
+ }
if (sqlStatement instanceof SetStatement) {
return Optional.of(new
MySQLSetVariableAdminExecutor((SetStatement) sqlStatement));
}
- if (sqlStatement instanceof SelectStatement) {
- return create((SelectStatement) sqlStatement, sql, databaseName,
parameters);
+ if (sqlStatement instanceof ShowProcessListStatement) {
+ return Optional.of(new
ShowProcessListExecutor(((ShowProcessListStatement) sqlStatement).isFull()));
+ }
+ if (sqlStatement instanceof KillStatement) {
+ return Optional.of(new KillProcessExecutor((KillStatement)
sqlStatement));
}
return Optional.empty();
}
diff --git
a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLAdminExecutorCreatorTest.java
b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLAdminExecutorCreatorTest.java
index e909f9fb955..8f3d8d63a75 100644
---
a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLAdminExecutorCreatorTest.java
+++
b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/MySQLAdminExecutorCreatorTest.java
@@ -98,7 +98,7 @@ class MySQLAdminExecutorCreatorTest {
@Test
void assertCreateWithMySQLShowFunctionStatus() {
when(sqlStatementContext.getSqlStatement()).thenReturn(new
MySQLShowFunctionStatusStatement());
- Optional<DatabaseAdminExecutor> actual = new
MySQLAdminExecutorCreator().create(sqlStatementContext);
+ Optional<DatabaseAdminExecutor> actual = new
MySQLAdminExecutorCreator().create(sqlStatementContext, "", "",
Collections.emptyList());
assertTrue(actual.isPresent());
assertThat(actual.get(), instanceOf(ShowFunctionStatusExecutor.class));
}
@@ -106,7 +106,7 @@ class MySQLAdminExecutorCreatorTest {
@Test
void assertCreateWithShowProcedureStatus() {
when(sqlStatementContext.getSqlStatement()).thenReturn(new
MySQLShowProcedureStatusStatement());
- Optional<DatabaseAdminExecutor> actual = new
MySQLAdminExecutorCreator().create(sqlStatementContext);
+ Optional<DatabaseAdminExecutor> actual = new
MySQLAdminExecutorCreator().create(sqlStatementContext, "", "",
Collections.emptyList());
assertTrue(actual.isPresent());
assertThat(actual.get(),
instanceOf(ShowProcedureStatusExecutor.class));
}
@@ -114,7 +114,7 @@ class MySQLAdminExecutorCreatorTest {
@Test
void assertCreateWithShowTables() {
when(sqlStatementContext.getSqlStatement()).thenReturn(new
MySQLShowTablesStatement());
- Optional<DatabaseAdminExecutor> actual = new
MySQLAdminExecutorCreator().create(sqlStatementContext);
+ Optional<DatabaseAdminExecutor> actual = new
MySQLAdminExecutorCreator().create(sqlStatementContext, "", "",
Collections.emptyList());
assertTrue(actual.isPresent());
assertThat(actual.get(), instanceOf(ShowTablesExecutor.class));
}
diff --git
a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLAdminExecutorFactoryTest.java
b/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLAdminExecutorFactoryTest.java
deleted file mode 100644
index 00b04721b81..00000000000
---
a/proxy/backend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/MySQLAdminExecutorFactoryTest.java
+++ /dev/null
@@ -1,67 +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.proxy.backend.mysql.handler.admin.executor;
-
-import
org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
-import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor;
-import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.MySQLAdminExecutorCreator;
-import
org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLShowFunctionStatusStatement;
-import
org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLShowProcedureStatusStatement;
-import
org.apache.shardingsphere.sql.parser.statement.mysql.dal.MySQLShowTablesStatement;
-import org.junit.jupiter.api.Test;
-
-import java.util.Optional;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class MySQLAdminExecutorFactoryTest {
-
- @Test
- void assertNewInstanceWithMySQLShowFunctionStatusStatement() {
- MySQLShowFunctionStatusStatement statement =
mock(MySQLShowFunctionStatusStatement.class);
- CommonSQLStatementContext statementContext =
mock(CommonSQLStatementContext.class);
- when(statementContext.getSqlStatement()).thenReturn(statement);
- Optional<DatabaseAdminExecutor> executor = new
MySQLAdminExecutorCreator().create(statementContext);
- assertTrue(executor.isPresent());
- assertThat(executor.get(),
instanceOf(ShowFunctionStatusExecutor.class));
- }
-
- @Test
- void assertNewInstanceWithMySQLShowProcedureStatusStatement() {
- MySQLShowProcedureStatusStatement statement =
mock(MySQLShowProcedureStatusStatement.class);
- CommonSQLStatementContext statementContext =
mock(CommonSQLStatementContext.class);
- when(statementContext.getSqlStatement()).thenReturn(statement);
- Optional<DatabaseAdminExecutor> executor = new
MySQLAdminExecutorCreator().create(statementContext);
- assertTrue(executor.isPresent());
- assertThat(executor.get(),
instanceOf(ShowProcedureStatusExecutor.class));
- }
-
- @Test
- void assertNewInstanceWithMySQLShowTablesStatement() {
- MySQLShowTablesStatement statement =
mock(MySQLShowTablesStatement.class);
- CommonSQLStatementContext statementContext =
mock(CommonSQLStatementContext.class);
- when(statementContext.getSqlStatement()).thenReturn(statement);
- Optional<DatabaseAdminExecutor> executor = new
MySQLAdminExecutorCreator().create(statementContext);
- assertTrue(executor.isPresent());
- assertThat(executor.get(), instanceOf(ShowTablesExecutor.class));
- }
-}