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 96c41e33b2c Use MySQLSystemSchemaExecutorFactory and
MySQLSpecialSchemaExecutorFactory to simplify MySQLSelectAdminExecutorFactory
(#37534)
96c41e33b2c is described below
commit 96c41e33b2c9eed483b64cac1dd17e577eaadb87
Author: Liang Zhang <[email protected]>
AuthorDate: Fri Dec 26 16:12:42 2025 +0800
Use MySQLSystemSchemaExecutorFactory and MySQLSpecialSchemaExecutorFactory
to simplify MySQLSelectAdminExecutorFactory (#37534)
* Use MySQLCommonSchemaExecutorFactory to simplify other
MySQLSchemaExecutorFactory
* Use MySQLSystemSchemaExecutorFactory to simplify other
MySQLSchemaExecutorFactory
* Use MySQLSystemSchemaExecutorFactory and
MySQLSpecialSchemaExecutorFactory to simplify MySQLSelectAdminExecutorFactory
* Use MySQLSystemSchemaExecutorFactory and
MySQLSpecialSchemaExecutorFactory to simplify MySQLSelectAdminExecutorFactory
* Use MySQLSystemSchemaExecutorFactory and
MySQLSpecialSchemaExecutorFactory to simplify MySQLSelectAdminExecutorFactory
* Use MySQLSystemSchemaExecutorFactory and
MySQLSpecialSchemaExecutorFactory to simplify MySQLSelectAdminExecutorFactory
* Use MySQLSystemSchemaExecutorFactory and
MySQLSpecialSchemaExecutorFactory to simplify MySQLSelectAdminExecutorFactory
* Use MySQLSystemSchemaExecutorFactory and
MySQLSpecialSchemaExecutorFactory to simplify MySQLSelectAdminExecutorFactory
* Use MySQLSystemSchemaExecutorFactory and
MySQLSpecialSchemaExecutorFactory to simplify MySQLSelectAdminExecutorFactory
---
.../factory/MySQLSelectAdminExecutorFactory.java | 34 +++------
.../schema/MySQLMySQLSchemaExecutorFactory.java | 57 --------------
.../MySQLPerformanceSchemaExecutorFactory.java | 57 --------------
... => MySQLSpecialTableQueryExecutorFactory.java} | 33 ++++----
... => MySQLSystemSchemaQueryExecutorFactory.java} | 38 +++++++--
.../type/MySQLSchemataQueryExecutorFactory.java | 42 ++++++++++
.../MySQLInformationSchemaExecutorFactoryTest.java | 89 ----------------------
.../MySQLMySQLSchemaExecutorFactoryTest.java | 80 -------------------
.../MySQLPerformanceSchemaExecutorFactoryTest.java | 80 -------------------
.../schema/MySQLSysSchemaExecutorFactoryTest.java | 81 --------------------
10 files changed, 95 insertions(+), 496 deletions(-)
diff --git
a/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/MySQLSelectAdminExecutorFactory.java
b/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/MySQLSelectAdminExecutorFactory.java
index b71070c7d2c..98fff0ef297 100644
---
a/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/MySQLSelectAdminExecutorFactory.java
+++
b/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/MySQLSelectAdminExecutorFactory.java
@@ -17,17 +17,17 @@
package org.apache.shardingsphere.proxy.backend.mysql.handler.admin.factory;
+import com.cedarsoftware.util.CaseInsensitiveSet;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import
org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor;
-import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.factory.schema.MySQLInformationSchemaExecutorFactory;
-import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.factory.schema.MySQLMySQLSchemaExecutorFactory;
-import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.factory.schema.MySQLPerformanceSchemaExecutorFactory;
-import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.factory.schema.MySQLSysSchemaExecutorFactory;
+import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.factory.schema.MySQLSystemSchemaQueryExecutorFactory;
import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.factory.withoutfrom.MySQLSelectWithoutFromAdminExecutorFactory;
+import java.util.Arrays;
+import java.util.Collection;
import java.util.List;
import java.util.Optional;
@@ -37,13 +37,7 @@ import java.util.Optional;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class MySQLSelectAdminExecutorFactory {
- private static final String INFORMATION_SCHEMA = "information_schema";
-
- private static final String PERFORMANCE_SCHEMA = "performance_schema";
-
- private static final String MYSQL_SCHEMA = "mysql";
-
- private static final String SYS_SCHEMA = "sys";
+ private static final Collection<String> SYSTEM_SCHEMAS = new
CaseInsensitiveSet<>(Arrays.asList("information_schema", "performance_schema",
"mysql", "sys"));
/**
* New instance of select admin executor for MySQL.
@@ -60,18 +54,10 @@ public final class MySQLSelectAdminExecutorFactory {
if (!selectStatementContext.getSqlStatement().getFrom().isPresent()) {
return
MySQLSelectWithoutFromAdminExecutorFactory.newInstance(selectStatementContext,
sql, databaseName, metaData);
}
- if (INFORMATION_SCHEMA.equalsIgnoreCase(databaseName) &&
!metaData.getDatabase(databaseName).isComplete()) {
- return
MySQLInformationSchemaExecutorFactory.newInstance(selectStatementContext, sql,
parameters);
- }
- if (PERFORMANCE_SCHEMA.equalsIgnoreCase(databaseName) &&
!metaData.getDatabase(databaseName).isComplete()) {
- return
MySQLPerformanceSchemaExecutorFactory.newInstance(selectStatementContext, sql,
parameters);
- }
- if (MYSQL_SCHEMA.equalsIgnoreCase(databaseName) &&
!metaData.getDatabase(databaseName).isComplete()) {
- return
MySQLMySQLSchemaExecutorFactory.newInstance(selectStatementContext, sql,
parameters);
- }
- if (SYS_SCHEMA.equalsIgnoreCase(databaseName) &&
!metaData.getDatabase(databaseName).isComplete()) {
- return
MySQLSysSchemaExecutorFactory.newInstance(selectStatementContext, sql,
parameters);
- }
- return Optional.empty();
+ return getSchemaName(databaseName, metaData).flatMap(optional ->
MySQLSystemSchemaQueryExecutorFactory.newInstance(selectStatementContext, sql,
parameters, optional));
+ }
+
+ private static Optional<String> getSchemaName(final String databaseName,
final ShardingSphereMetaData metaData) {
+ return SYSTEM_SCHEMAS.contains(databaseName) &&
!metaData.getDatabase(databaseName).isComplete() ? Optional.of(databaseName) :
Optional.empty();
}
}
diff --git
a/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/MySQLMySQLSchemaExecutorFactory.java
b/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/MySQLMySQLSchemaExecutorFactory.java
deleted file mode 100644
index 2db30b33f48..00000000000
---
a/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/MySQLMySQLSchemaExecutorFactory.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.proxy.backend.mysql.handler.admin.factory.schema;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import
org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
-import
org.apache.shardingsphere.infra.metadata.database.schema.manager.SystemSchemaManager;
-import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor;
-import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseMetaDataExecutor;
-import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
-import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.dml.SelectStatement;
-
-import java.util.List;
-import java.util.Optional;
-
-/**
- * Construct the mysql schema executor's factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class MySQLMySQLSchemaExecutorFactory {
-
- /**
- * Create executor.
- *
- * @param selectStatementContext select statement context
- * @param sql SQL being executed
- * @param parameters parameters
- * @return executor
- */
- public static Optional<DatabaseAdminExecutor> newInstance(final
SelectStatementContext selectStatementContext, final String sql, final
List<Object> parameters) {
- SelectStatement sqlStatement =
selectStatementContext.getSqlStatement();
- if (!sqlStatement.getFrom().isPresent() ||
!(sqlStatement.getFrom().get() instanceof SimpleTableSegment)) {
- return Optional.empty();
- }
- String tableName = ((SimpleTableSegment)
sqlStatement.getFrom().get()).getTableName().getIdentifier().getValue();
- if (SystemSchemaManager.isSystemTable("mysql", "mysql", tableName)) {
- return Optional.of(new DatabaseMetaDataExecutor(sql, parameters));
- }
- return Optional.empty();
- }
-}
diff --git
a/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/MySQLPerformanceSchemaExecutorFactory.java
b/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/MySQLPerformanceSchemaExecutorFactory.java
deleted file mode 100644
index 15182cfbe33..00000000000
---
a/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/MySQLPerformanceSchemaExecutorFactory.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.proxy.backend.mysql.handler.admin.factory.schema;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import
org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
-import
org.apache.shardingsphere.infra.metadata.database.schema.manager.SystemSchemaManager;
-import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor;
-import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseMetaDataExecutor;
-import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
-import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.dml.SelectStatement;
-
-import java.util.List;
-import java.util.Optional;
-
-/**
- * Construct the performance schema executor's factory.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class MySQLPerformanceSchemaExecutorFactory {
-
- /**
- * Create executor.
- *
- * @param selectStatementContext select statement context
- * @param sql SQL being executed
- * @param parameters parameters
- * @return executor
- */
- public static Optional<DatabaseAdminExecutor> newInstance(final
SelectStatementContext selectStatementContext, final String sql, final
List<Object> parameters) {
- SelectStatement sqlStatement =
selectStatementContext.getSqlStatement();
- if (!sqlStatement.getFrom().isPresent() ||
!(sqlStatement.getFrom().get() instanceof SimpleTableSegment)) {
- return Optional.empty();
- }
- String tableName = ((SimpleTableSegment)
sqlStatement.getFrom().get()).getTableName().getIdentifier().getValue();
- if (SystemSchemaManager.isSystemTable("mysql", "performance_schema",
tableName)) {
- return Optional.of(new DatabaseMetaDataExecutor(sql, parameters));
- }
- return Optional.empty();
- }
-}
diff --git
a/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/MySQLSysSchemaExecutorFactory.java
b/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/MySQLSpecialTableQueryExecutorFactory.java
similarity index 50%
rename from
proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/MySQLSysSchemaExecutorFactory.java
rename to
proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/MySQLSpecialTableQueryExecutorFactory.java
index ca7f3561c8b..271ffca47ac 100644
---
a/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/MySQLSysSchemaExecutorFactory.java
+++
b/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/MySQLSpecialTableQueryExecutorFactory.java
@@ -17,23 +17,25 @@
package
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.factory.schema;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
import
org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
-import
org.apache.shardingsphere.infra.metadata.database.schema.manager.SystemSchemaManager;
import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor;
-import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseMetaDataExecutor;
-import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
-import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.dml.SelectStatement;
import java.util.List;
import java.util.Optional;
/**
- * Construct the sys schema executor's factory.
+ * MySQL special table query executor factory.
*/
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class MySQLSysSchemaExecutorFactory {
+public interface MySQLSpecialTableQueryExecutorFactory {
+
+ /**
+ * Whether to be processed special table.
+ *
+ * @param schemaName schema name
+ * @param tableName table name
+ * @return to be processed special table or not
+ */
+ boolean accept(String schemaName, String tableName);
/**
* Create executor.
@@ -41,17 +43,8 @@ public final class MySQLSysSchemaExecutorFactory {
* @param selectStatementContext select statement context
* @param sql SQL being executed
* @param parameters parameters
+ * @param tableName table name
* @return executor
*/
- public static Optional<DatabaseAdminExecutor> newInstance(final
SelectStatementContext selectStatementContext, final String sql, final
List<Object> parameters) {
- SelectStatement sqlStatement =
selectStatementContext.getSqlStatement();
- if (!sqlStatement.getFrom().isPresent() ||
!(sqlStatement.getFrom().get() instanceof SimpleTableSegment)) {
- return Optional.empty();
- }
- String tableName = ((SimpleTableSegment)
sqlStatement.getFrom().get()).getTableName().getIdentifier().getValue();
- if (SystemSchemaManager.isSystemTable("mysql", "sys", tableName)) {
- return Optional.of(new DatabaseMetaDataExecutor(sql, parameters));
- }
- return Optional.empty();
- }
+ Optional<DatabaseAdminExecutor> newInstance(SelectStatementContext
selectStatementContext, String sql, List<Object> parameters, String tableName);
}
diff --git
a/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/MySQLInformationSchemaExecutorFactory.java
b/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/MySQLSystemSchemaQueryExecutorFactory.java
similarity index 60%
rename from
proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/MySQLInformationSchemaExecutorFactory.java
rename to
proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/MySQLSystemSchemaQueryExecutorFactory.java
index 74394194631..f68d368af12 100644
---
a/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/MySQLInformationSchemaExecutorFactory.java
+++
b/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/MySQLSystemSchemaQueryExecutorFactory.java
@@ -23,20 +23,26 @@ import
org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectS
import
org.apache.shardingsphere.infra.metadata.database.schema.manager.SystemSchemaManager;
import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor;
import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseMetaDataExecutor;
-import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.select.SelectInformationSchemataExecutor;
+import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.factory.schema.type.MySQLSchemataQueryExecutorFactory;
import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.dml.SelectStatement;
+import java.util.Collection;
+import java.util.HashSet;
import java.util.List;
import java.util.Optional;
/**
- * Construct the information schema executor's factory.
+ * MySQL system schema query executor factory.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class MySQLInformationSchemaExecutorFactory {
+public final class MySQLSystemSchemaQueryExecutorFactory {
- private static final String SCHEMATA_TABLE = "SCHEMATA";
+ private static final Collection<MySQLSpecialTableQueryExecutorFactory>
SPECIAL_TABLE_EXECUTOR_FACTORIES = new HashSet<>();
+
+ static {
+ SPECIAL_TABLE_EXECUTOR_FACTORIES.add(new
MySQLSchemataQueryExecutorFactory());
+ }
/**
* Create executor.
@@ -44,20 +50,36 @@ public final class MySQLInformationSchemaExecutorFactory {
* @param selectStatementContext select statement context
* @param sql SQL being executed
* @param parameters parameters
+ * @param schemaName schema name
* @return executor
*/
- public static Optional<DatabaseAdminExecutor> newInstance(final
SelectStatementContext selectStatementContext, final String sql, final
List<Object> parameters) {
+ public static Optional<DatabaseAdminExecutor> newInstance(final
SelectStatementContext selectStatementContext, final String sql, final
List<Object> parameters, final String schemaName) {
SelectStatement sqlStatement =
selectStatementContext.getSqlStatement();
if (!sqlStatement.getFrom().isPresent() ||
!(sqlStatement.getFrom().get() instanceof SimpleTableSegment)) {
return Optional.empty();
}
String tableName = ((SimpleTableSegment)
sqlStatement.getFrom().get()).getTableName().getIdentifier().getValue();
- if (SCHEMATA_TABLE.equalsIgnoreCase(tableName)) {
- return Optional.of(new
SelectInformationSchemataExecutor(sqlStatement, sql, parameters));
+ Optional<DatabaseAdminExecutor> specialTableExecutor =
findSpecialTableExecutor(selectStatementContext, sql, parameters, schemaName,
tableName);
+ if (specialTableExecutor.isPresent()) {
+ return specialTableExecutor;
}
- if (SystemSchemaManager.isSystemTable("mysql", "information_schema",
tableName)) {
+ if (SystemSchemaManager.isSystemTable("mysql", schemaName, tableName))
{
return Optional.of(new DatabaseMetaDataExecutor(sql, parameters));
}
return Optional.empty();
}
+
+ private static Optional<DatabaseAdminExecutor>
findSpecialTableExecutor(final SelectStatementContext selectStatementContext,
+
final String sql, final List<Object> parameters, final String schemaName, final
String tableName) {
+ for (MySQLSpecialTableQueryExecutorFactory each :
SPECIAL_TABLE_EXECUTOR_FACTORIES) {
+ if (!each.accept(schemaName, tableName)) {
+ continue;
+ }
+ Optional<DatabaseAdminExecutor> specialTableExecutor =
each.newInstance(selectStatementContext, sql, parameters, tableName);
+ if (specialTableExecutor.isPresent()) {
+ return specialTableExecutor;
+ }
+ }
+ return Optional.empty();
+ }
}
diff --git
a/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/type/MySQLSchemataQueryExecutorFactory.java
b/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/type/MySQLSchemataQueryExecutorFactory.java
new file mode 100644
index 00000000000..a3360cfad6f
--- /dev/null
+++
b/proxy/backend/dialect/mysql/src/main/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/type/MySQLSchemataQueryExecutorFactory.java
@@ -0,0 +1,42 @@
+/*
+ * 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.factory.schema.type;
+
+import
org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
+import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor;
+import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.select.SelectInformationSchemataExecutor;
+import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.factory.schema.MySQLSpecialTableQueryExecutorFactory;
+
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * Schemata table query executor factory for MySQL.
+ */
+public final class MySQLSchemataQueryExecutorFactory implements
MySQLSpecialTableQueryExecutorFactory {
+
+ @Override
+ public boolean accept(final String schemaName, final String tableName) {
+ return "information_schema".equalsIgnoreCase(schemaName) &&
"SCHEMATA".equalsIgnoreCase(tableName);
+ }
+
+ @Override
+ public Optional<DatabaseAdminExecutor> newInstance(final
SelectStatementContext selectStatementContext, final String sql, final
List<Object> parameters, final String tableName) {
+ return Optional.of(new
SelectInformationSchemataExecutor(selectStatementContext.getSqlStatement(),
sql, parameters));
+ }
+}
diff --git
a/proxy/backend/dialect/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/MySQLInformationSchemaExecutorFactoryTest.java
b/proxy/backend/dialect/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/MySQLInformationSchemaExecutorFactoryTest.java
deleted file mode 100644
index c099eb56f74..00000000000
---
a/proxy/backend/dialect/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/MySQLInformationSchemaExecutorFactoryTest.java
+++ /dev/null
@@ -1,89 +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.factory.schema;
-
-import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
-import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
-import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor;
-import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseMetaDataExecutor;
-import
org.apache.shardingsphere.proxy.backend.mysql.handler.admin.executor.select.SelectInformationSchemataExecutor;
-import
org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
-import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
-import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableSegment;
-import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment;
-import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.dml.SelectStatement;
-import
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
-import org.junit.jupiter.api.Test;
-
-import java.util.Collections;
-import java.util.Optional;
-
-import static org.hamcrest.CoreMatchers.instanceOf;
-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;
-
-class MySQLInformationSchemaExecutorFactoryTest {
-
- private final DatabaseType databaseType =
TypedSPILoader.getService(DatabaseType.class, "MySQL");
-
- @Test
- void assertCreateSchemataExecutor() {
- Optional<DatabaseAdminExecutor> actual =
MySQLInformationSchemaExecutorFactory.newInstance(mockSelectStatementContext("SCHEMATA"),
"sql", Collections.emptyList());
- assertTrue(actual.isPresent());
- assertThat(actual.get(),
instanceOf(SelectInformationSchemataExecutor.class));
- }
-
- @Test
- void assertCreateMetaDataExecutorForSystemTable() {
- Optional<DatabaseAdminExecutor> actual =
MySQLInformationSchemaExecutorFactory.newInstance(mockSelectStatementContext("referential_constraints"),
"sql", Collections.emptyList());
- assertTrue(actual.isPresent());
- assertThat(actual.get(), instanceOf(DatabaseMetaDataExecutor.class));
- }
-
- @Test
- void assertReturnEmptyForNonSystemTable() {
-
assertFalse(MySQLInformationSchemaExecutorFactory.newInstance(mockSelectStatementContext("custom_table"),
"sql", Collections.emptyList()).isPresent());
- }
-
- @Test
- void assertReturnEmptyWhenFromIsMissing() {
-
assertFalse(MySQLInformationSchemaExecutorFactory.newInstance(mockSelectStatementContext(new
SelectStatement(databaseType)), "sql", Collections.emptyList()).isPresent());
- }
-
- @Test
- void assertReturnEmptyWhenFromIsNotSimpleTableSegment() {
- SelectStatement selectStatement = new SelectStatement(databaseType);
- selectStatement.setFrom(mock(TableSegment.class));
-
assertFalse(MySQLInformationSchemaExecutorFactory.newInstance(mockSelectStatementContext(selectStatement),
"sql", Collections.emptyList()).isPresent());
- }
-
- private SelectStatementContext mockSelectStatementContext(final String
tableName) {
- SelectStatement selectStatement = new SelectStatement(databaseType);
- selectStatement.setFrom(new SimpleTableSegment(new TableNameSegment(0,
0, new IdentifierValue(tableName))));
- return mockSelectStatementContext(selectStatement);
- }
-
- private SelectStatementContext mockSelectStatementContext(final
SelectStatement selectStatement) {
- SelectStatementContext result = mock(SelectStatementContext.class);
- when(result.getSqlStatement()).thenReturn(selectStatement);
- return result;
- }
-}
diff --git
a/proxy/backend/dialect/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/MySQLMySQLSchemaExecutorFactoryTest.java
b/proxy/backend/dialect/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/MySQLMySQLSchemaExecutorFactoryTest.java
deleted file mode 100644
index d8b516f9d27..00000000000
---
a/proxy/backend/dialect/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/MySQLMySQLSchemaExecutorFactoryTest.java
+++ /dev/null
@@ -1,80 +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.factory.schema;
-
-import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
-import
org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
-import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
-import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor;
-import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseMetaDataExecutor;
-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.type.dml.SelectStatement;
-import
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
-import org.junit.jupiter.api.Test;
-
-import java.util.Collections;
-import java.util.Optional;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.isA;
-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;
-
-class MySQLMySQLSchemaExecutorFactoryTest {
-
- private final DatabaseType databaseType =
TypedSPILoader.getService(DatabaseType.class, "MySQL");
-
- @Test
- void assertCreateMetaDataExecutorForSystemTable() {
- Optional<DatabaseAdminExecutor> actual =
MySQLMySQLSchemaExecutorFactory.newInstance(mockSelectStatementContext("db"),
"sql", Collections.emptyList());
- assertTrue(actual.isPresent());
- assertThat(actual.get(), isA(DatabaseMetaDataExecutor.class));
- }
-
- @Test
- void assertReturnEmptyForNonSystemTable() {
-
assertFalse(MySQLMySQLSchemaExecutorFactory.newInstance(mockSelectStatementContext("custom_table"),
"sql", Collections.emptyList()).isPresent());
- }
-
- @Test
- void assertReturnEmptyWhenFromIsMissing() {
-
assertFalse(MySQLMySQLSchemaExecutorFactory.newInstance(mockSelectStatementContext(new
SelectStatement(databaseType)), "sql", Collections.emptyList()).isPresent());
- }
-
- @Test
- void assertReturnEmptyWhenFromIsNotSimpleTableSegment() {
- SelectStatement selectStatement = new SelectStatement(databaseType);
-
selectStatement.setFrom(mock(org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableSegment.class));
-
assertFalse(MySQLMySQLSchemaExecutorFactory.newInstance(mockSelectStatementContext(selectStatement),
"sql", Collections.emptyList()).isPresent());
- }
-
- private SelectStatementContext mockSelectStatementContext(final String
tableName) {
- SelectStatement selectStatement = new SelectStatement(databaseType);
- selectStatement.setFrom(new SimpleTableSegment(new TableNameSegment(0,
0, new IdentifierValue(tableName))));
- return mockSelectStatementContext(selectStatement);
- }
-
- private SelectStatementContext mockSelectStatementContext(final
SelectStatement selectStatement) {
- SelectStatementContext result = mock(SelectStatementContext.class);
- when(result.getSqlStatement()).thenReturn(selectStatement);
- return result;
- }
-}
diff --git
a/proxy/backend/dialect/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/MySQLPerformanceSchemaExecutorFactoryTest.java
b/proxy/backend/dialect/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/MySQLPerformanceSchemaExecutorFactoryTest.java
deleted file mode 100644
index 7b0dc801c0f..00000000000
---
a/proxy/backend/dialect/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/MySQLPerformanceSchemaExecutorFactoryTest.java
+++ /dev/null
@@ -1,80 +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.factory.schema;
-
-import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
-import
org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
-import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
-import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor;
-import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseMetaDataExecutor;
-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.type.dml.SelectStatement;
-import
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
-import org.junit.jupiter.api.Test;
-
-import java.util.Collections;
-import java.util.Optional;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.isA;
-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;
-
-class MySQLPerformanceSchemaExecutorFactoryTest {
-
- private final DatabaseType databaseType =
TypedSPILoader.getService(DatabaseType.class, "MySQL");
-
- @Test
- void assertCreateMetaDataExecutorForSystemTable() {
- Optional<DatabaseAdminExecutor> actual =
MySQLPerformanceSchemaExecutorFactory.newInstance(mockSelectStatementContext("variables_info"),
"sql", Collections.emptyList());
- assertTrue(actual.isPresent());
- assertThat(actual.get(), isA(DatabaseMetaDataExecutor.class));
- }
-
- @Test
- void assertReturnEmptyForNonSystemTable() {
-
assertFalse(MySQLPerformanceSchemaExecutorFactory.newInstance(mockSelectStatementContext("custom_table"),
"sql", Collections.emptyList()).isPresent());
- }
-
- @Test
- void assertReturnEmptyWhenFromIsMissing() {
-
assertFalse(MySQLPerformanceSchemaExecutorFactory.newInstance(mockSelectStatementContext(new
SelectStatement(databaseType)), "sql", Collections.emptyList()).isPresent());
- }
-
- @Test
- void assertReturnEmptyWhenFromIsNotSimpleTableSegment() {
- SelectStatement selectStatement = new SelectStatement(databaseType);
-
selectStatement.setFrom(mock(org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableSegment.class));
-
assertFalse(MySQLPerformanceSchemaExecutorFactory.newInstance(mockSelectStatementContext(selectStatement),
"sql", Collections.emptyList()).isPresent());
- }
-
- private SelectStatementContext mockSelectStatementContext(final String
tableName) {
- SelectStatement selectStatement = new SelectStatement(databaseType);
- selectStatement.setFrom(new SimpleTableSegment(new TableNameSegment(0,
0, new IdentifierValue(tableName))));
- return mockSelectStatementContext(selectStatement);
- }
-
- private SelectStatementContext mockSelectStatementContext(final
SelectStatement selectStatement) {
- SelectStatementContext result = mock(SelectStatementContext.class);
- when(result.getSqlStatement()).thenReturn(selectStatement);
- return result;
- }
-}
diff --git
a/proxy/backend/dialect/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/MySQLSysSchemaExecutorFactoryTest.java
b/proxy/backend/dialect/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/MySQLSysSchemaExecutorFactoryTest.java
deleted file mode 100644
index 1759b94a378..00000000000
---
a/proxy/backend/dialect/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/factory/schema/MySQLSysSchemaExecutorFactoryTest.java
+++ /dev/null
@@ -1,81 +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.factory.schema;
-
-import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
-import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
-import
org.apache.shardingsphere.infra.binder.context.statement.type.dml.SelectStatementContext;
-import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseAdminExecutor;
-import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.DatabaseMetaDataExecutor;
-import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
-import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableSegment;
-import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment;
-import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.dml.SelectStatement;
-import
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
-import org.junit.jupiter.api.Test;
-
-import java.util.Collections;
-import java.util.Optional;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.isA;
-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;
-
-class MySQLSysSchemaExecutorFactoryTest {
-
- private final DatabaseType databaseType =
TypedSPILoader.getService(DatabaseType.class, "MySQL");
-
- @Test
- void assertCreateMetaDataExecutorForSystemTable() {
- Optional<DatabaseAdminExecutor> actual =
MySQLSysSchemaExecutorFactory.newInstance(mockSelectStatementContext("session"),
"sql", Collections.emptyList());
- assertTrue(actual.isPresent());
- assertThat(actual.get(), isA(DatabaseMetaDataExecutor.class));
- }
-
- @Test
- void assertReturnEmptyForNonSystemTable() {
-
assertFalse(MySQLSysSchemaExecutorFactory.newInstance(mockSelectStatementContext("custom_table"),
"sql", Collections.emptyList()).isPresent());
- }
-
- @Test
- void assertReturnEmptyWhenFromIsMissing() {
-
assertFalse(MySQLSysSchemaExecutorFactory.newInstance(mockSelectStatementContext(new
SelectStatement(databaseType)), "sql", Collections.emptyList()).isPresent());
- }
-
- @Test
- void assertReturnEmptyWhenFromIsNotSimpleTableSegment() {
- SelectStatement selectStatement = new SelectStatement(databaseType);
- selectStatement.setFrom(mock(TableSegment.class));
-
assertFalse(MySQLSysSchemaExecutorFactory.newInstance(mockSelectStatementContext(selectStatement),
"sql", Collections.emptyList()).isPresent());
- }
-
- private SelectStatementContext mockSelectStatementContext(final String
tableName) {
- SelectStatement selectStatement = new SelectStatement(databaseType);
- selectStatement.setFrom(new SimpleTableSegment(new TableNameSegment(0,
0, new IdentifierValue(tableName))));
- return mockSelectStatementContext(selectStatement);
- }
-
- private SelectStatementContext mockSelectStatementContext(final
SelectStatement selectStatement) {
- SelectStatementContext result = mock(SelectStatementContext.class);
- when(result.getSqlStatement()).thenReturn(selectStatement);
- return result;
- }
-}