From b4e8d08c7f6cf6e2e1a368dd06fb4e2653267bba Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Thu, 12 Dec 2024 11:11:26 +0800 Subject: [PATCH 01/32] Refactor SchemaMetaDataUtils (#34016) --- .../metadata/database/schema/util/SchemaMetaDataUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/util/SchemaMetaDataUtils.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/util/SchemaMetaDataUtils.java index 81e460adb3219..cbc2719114e10 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/util/SchemaMetaDataUtils.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/database/schema/util/SchemaMetaDataUtils.java @@ -137,7 +137,7 @@ private static boolean isSameDataSourceNameSchemaName(final GenericSchemaBuilder private static void addAllActualTableDataNode(final GenericSchemaBuilderMaterial material, final Map> dataSourceTableGroups, final DataNodes dataNodes, final String table) { Collection tableDataNodes = dataNodes.getDataNodes(table); - if (tableDataNodes.isEmpty()) { + if (tableDataNodes.isEmpty() && !material.getStorageUnits().isEmpty()) { addDataSourceTableGroups(material.getStorageUnits().keySet().iterator().next(), table, dataSourceTableGroups); } else { tableDataNodes.forEach(each -> addDataSourceTableGroups(each.getDataSourceName(), each.getTableName(), dataSourceTableGroups)); From e88ae4fbf5c4ec98d06b5af48859094d8fd7fbc9 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Thu, 12 Dec 2024 12:49:33 +0800 Subject: [PATCH 02/32] Code format for PipelineSQLSegmentBuilderTest (#34019) --- .../PipelineSQLSegmentBuilderTest.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/sqlbuilder/segment/PipelineSQLSegmentBuilderTest.java b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/sqlbuilder/segment/PipelineSQLSegmentBuilderTest.java index 4c6b1d74fd715..2fc48bae01b1c 100644 --- a/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/sqlbuilder/segment/PipelineSQLSegmentBuilderTest.java +++ b/kernel/data-pipeline/core/src/test/java/org/apache/shardingsphere/data/pipeline/core/sqlbuilder/segment/PipelineSQLSegmentBuilderTest.java @@ -27,35 +27,35 @@ class PipelineSQLSegmentBuilderTest { - private final PipelineSQLSegmentBuilder mySQLBuilder = new PipelineSQLSegmentBuilder(TypedSPILoader.getService(DatabaseType.class, "MySQL")); + private final PipelineSQLSegmentBuilder mysqlBuilder = new PipelineSQLSegmentBuilder(TypedSPILoader.getService(DatabaseType.class, "MySQL")); - private final PipelineSQLSegmentBuilder postgreSQLBuilder = new PipelineSQLSegmentBuilder(TypedSPILoader.getService(DatabaseType.class, "PostgreSQL")); + private final PipelineSQLSegmentBuilder postgresqlBuilder = new PipelineSQLSegmentBuilder(TypedSPILoader.getService(DatabaseType.class, "PostgreSQL")); @Test void assertGetEscapedIdentifier() { - assertThat(mySQLBuilder.getEscapedIdentifier("SELECT"), is("`SELECT`")); + assertThat(mysqlBuilder.getEscapedIdentifier("SELECT"), is("`SELECT`")); } @Test void assertGetUnescapedIdentifier() { - assertThat(mySQLBuilder.getEscapedIdentifier("SELECT1"), is("SELECT1")); + assertThat(mysqlBuilder.getEscapedIdentifier("SELECT1"), is("SELECT1")); } @Test void assertGetQualifiedTableNameWithUnsupportedSchema() { - assertThat(mySQLBuilder.getQualifiedTableName("foo_schema", "foo_tbl"), is("foo_tbl")); - assertThat(mySQLBuilder.getQualifiedTableName(new QualifiedTable("foo_schema", "foo_tbl")), is("foo_tbl")); + assertThat(mysqlBuilder.getQualifiedTableName("foo_schema", "foo_tbl"), is("foo_tbl")); + assertThat(mysqlBuilder.getQualifiedTableName(new QualifiedTable("foo_schema", "foo_tbl")), is("foo_tbl")); } @Test void assertGetQualifiedTableNameWithSupportedSchema() { - assertThat(postgreSQLBuilder.getQualifiedTableName("foo_schema", "foo_tbl"), is("foo_schema.foo_tbl")); - assertThat(postgreSQLBuilder.getQualifiedTableName(new QualifiedTable("foo_schema", "foo_tbl")), is("foo_schema.foo_tbl")); + assertThat(postgresqlBuilder.getQualifiedTableName("foo_schema", "foo_tbl"), is("foo_schema.foo_tbl")); + assertThat(postgresqlBuilder.getQualifiedTableName(new QualifiedTable("foo_schema", "foo_tbl")), is("foo_schema.foo_tbl")); } @Test void assertGetQualifiedTableNameWithSupportedSchemaAndNullSchema() { - assertThat(postgreSQLBuilder.getQualifiedTableName(null, "foo_tbl"), is("foo_tbl")); - assertThat(postgreSQLBuilder.getQualifiedTableName(new QualifiedTable(null, "foo_tbl")), is("foo_tbl")); + assertThat(postgresqlBuilder.getQualifiedTableName(null, "foo_tbl"), is("foo_tbl")); + assertThat(postgresqlBuilder.getQualifiedTableName(new QualifiedTable(null, "foo_tbl")), is("foo_tbl")); } } From 5439c67e0a18f96fc81acc5583246b9ff25d072c Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Thu, 12 Dec 2024 14:38:50 +0800 Subject: [PATCH 03/32] Remove DriverExecutorFacadeFactory (#34022) --- .../engine/facade/DriverExecutorFacade.java | 86 ++++++++++-- .../facade/DriverExecutorFacadeFactory.java | 42 ------ .../StandardDriverExecutorFacade.java | 129 ------------------ .../StandardDriverExecutorFacadeFactory.java | 46 ------- .../connection/ShardingSphereConnection.java | 23 ++-- .../ShardingSpherePreparedStatement.java | 27 ++-- .../statement/ShardingSphereStatement.java | 14 +- .../driver/state/ok/OKDriverState.java | 2 +- ....engine.facade.DriverExecutorFacadeFactory | 18 --- .../jdbc/adapter/ConnectionAdapterTest.java | 2 +- .../jdbc/adapter/StatementAdapterTest.java | 4 +- .../ShardingSphereConnectionTest.java | 24 ++-- .../UnsupportedOperationConnectionTest.java | 2 +- .../UnsupportedOperationStatementTest.java | 2 +- .../migration/api/MigrationJobAPI.java | 14 +- 15 files changed, 130 insertions(+), 305 deletions(-) delete mode 100644 jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/facade/DriverExecutorFacadeFactory.java delete mode 100644 jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/facade/standard/StandardDriverExecutorFacade.java delete mode 100644 jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/facade/standard/StandardDriverExecutorFacadeFactory.java delete mode 100644 jdbc/src/main/resources/META-INF/services/org.apache.shardingsphere.driver.executor.engine.facade.DriverExecutorFacadeFactory diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/facade/DriverExecutorFacade.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/facade/DriverExecutorFacade.java index 1ace4cab0ec3c..8301aef3b9b52 100644 --- a/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/facade/DriverExecutorFacade.java +++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/facade/DriverExecutorFacade.java @@ -21,10 +21,26 @@ import org.apache.shardingsphere.driver.executor.callback.execute.StatementExecuteCallback; import org.apache.shardingsphere.driver.executor.callback.execute.StatementExecuteUpdateCallback; import org.apache.shardingsphere.driver.executor.callback.replay.StatementReplayCallback; +import org.apache.shardingsphere.driver.executor.engine.DriverExecuteExecutor; +import org.apache.shardingsphere.driver.executor.engine.DriverExecuteQueryExecutor; +import org.apache.shardingsphere.driver.executor.engine.DriverExecuteUpdateExecutor; +import org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection; +import org.apache.shardingsphere.driver.jdbc.core.statement.StatementManager; import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; +import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey; +import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry; +import org.apache.shardingsphere.infra.executor.audit.SQLAuditEngine; +import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutionUnit; +import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutor; +import org.apache.shardingsphere.infra.executor.sql.execute.engine.raw.RawExecutor; +import org.apache.shardingsphere.infra.executor.sql.prepare.driver.DriverExecutionPrepareEngine; +import org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.StatementOption; +import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.session.query.QueryContext; +import org.apache.shardingsphere.sqlfederation.engine.SQLFederationEngine; +import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; @@ -35,7 +51,39 @@ /** * Driver executor facade. */ -public interface DriverExecutorFacade extends AutoCloseable { +public final class DriverExecutorFacade implements AutoCloseable { + + private final ShardingSphereConnection connection; + + private final StatementOption statementOption; + + private final StatementManager statementManager; + + private final String jdbcDriverType; + + private final SQLFederationEngine sqlFederationEngine; + + private final DriverExecuteQueryExecutor queryExecutor; + + private final DriverExecuteUpdateExecutor updateExecutor; + + private final DriverExecuteExecutor executeExecutor; + + public DriverExecutorFacade(final ShardingSphereConnection connection, final StatementOption statementOption, final StatementManager statementManager, final String jdbcDriverType) { + this.connection = connection; + this.statementOption = statementOption; + this.statementManager = statementManager; + this.jdbcDriverType = jdbcDriverType; + JDBCExecutor jdbcExecutor = new JDBCExecutor(connection.getContextManager().getExecutorEngine(), connection.getDatabaseConnectionManager().getConnectionContext()); + ShardingSphereMetaData metaData = connection.getContextManager().getMetaDataContexts().getMetaData(); + String currentSchemaName = new DatabaseTypeRegistry(metaData.getDatabase(connection.getCurrentDatabaseName()).getProtocolType()).getDefaultSchemaName(connection.getCurrentDatabaseName()); + sqlFederationEngine = + new SQLFederationEngine(connection.getCurrentDatabaseName(), currentSchemaName, metaData, connection.getContextManager().getMetaDataContexts().getStatistics(), jdbcExecutor); + RawExecutor rawExecutor = new RawExecutor(connection.getContextManager().getExecutorEngine(), connection.getDatabaseConnectionManager().getConnectionContext()); + queryExecutor = new DriverExecuteQueryExecutor(connection, metaData, jdbcExecutor, rawExecutor, sqlFederationEngine); + updateExecutor = new DriverExecuteUpdateExecutor(connection, metaData, jdbcExecutor, rawExecutor); + executeExecutor = new DriverExecuteExecutor(connection, metaData, jdbcExecutor, rawExecutor, sqlFederationEngine); + } /** * Execute query. @@ -50,8 +98,11 @@ public interface DriverExecutorFacade extends AutoCloseable { * @throws SQLException SQL exception */ @SuppressWarnings("rawtypes") - ResultSet executeQuery(ShardingSphereDatabase database, QueryContext queryContext, - Statement statement, Map columnLabelAndIndexMap, StatementAddCallback addCallback, StatementReplayCallback replayCallback) throws SQLException; + public ResultSet executeQuery(final ShardingSphereDatabase database, final QueryContext queryContext, final Statement statement, final Map columnLabelAndIndexMap, + final StatementAddCallback addCallback, final StatementReplayCallback replayCallback) throws SQLException { + SQLAuditEngine.audit(queryContext, connection.getContextManager().getMetaDataContexts().getMetaData().getGlobalRuleMetaData(), database); + return queryExecutor.executeQuery(database, queryContext, createDriverExecutionPrepareEngine(database, jdbcDriverType), statement, columnLabelAndIndexMap, addCallback, replayCallback); + } /** * Execute update. @@ -65,8 +116,11 @@ ResultSet executeQuery(ShardingSphereDatabase database, QueryContext queryContex * @throws SQLException SQL exception */ @SuppressWarnings("rawtypes") - int executeUpdate(ShardingSphereDatabase database, - QueryContext queryContext, StatementExecuteUpdateCallback executeUpdateCallback, StatementAddCallback addCallback, StatementReplayCallback replayCallback) throws SQLException; + public int executeUpdate(final ShardingSphereDatabase database, final QueryContext queryContext, + final StatementExecuteUpdateCallback executeUpdateCallback, final StatementAddCallback addCallback, final StatementReplayCallback replayCallback) throws SQLException { + SQLAuditEngine.audit(queryContext, connection.getContextManager().getMetaDataContexts().getMetaData().getGlobalRuleMetaData(), database); + return updateExecutor.executeUpdate(database, queryContext, createDriverExecutionPrepareEngine(database, jdbcDriverType), executeUpdateCallback, addCallback, replayCallback); + } /** * Execute. @@ -80,8 +134,17 @@ int executeUpdate(ShardingSphereDatabase database, * @throws SQLException SQL exception */ @SuppressWarnings("rawtypes") - boolean execute(ShardingSphereDatabase database, - QueryContext queryContext, StatementExecuteCallback executeCallback, StatementAddCallback addCallback, StatementReplayCallback replayCallback) throws SQLException; + public boolean execute(final ShardingSphereDatabase database, final QueryContext queryContext, + final StatementExecuteCallback executeCallback, final StatementAddCallback addCallback, final StatementReplayCallback replayCallback) throws SQLException { + SQLAuditEngine.audit(queryContext, connection.getContextManager().getMetaDataContexts().getMetaData().getGlobalRuleMetaData(), database); + return executeExecutor.execute(database, queryContext, createDriverExecutionPrepareEngine(database, jdbcDriverType), executeCallback, addCallback, replayCallback); + } + + private DriverExecutionPrepareEngine createDriverExecutionPrepareEngine(final ShardingSphereDatabase database, final String jdbcDriverType) { + int maxConnectionsSizePerQuery = connection.getContextManager().getMetaDataContexts().getMetaData().getProps().getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY); + return new DriverExecutionPrepareEngine<>(jdbcDriverType, maxConnectionsSizePerQuery, connection.getDatabaseConnectionManager(), statementManager, statementOption, + database.getRuleMetaData().getRules(), database.getResourceMetaData().getStorageUnits()); + } /** * Get result set. @@ -93,8 +156,13 @@ boolean execute(ShardingSphereDatabase database, * @return result set * @throws SQLException SQL exception */ - Optional getResultSet(ShardingSphereDatabase database, SQLStatementContext sqlStatementContext, Statement statement, List statements) throws SQLException; + public Optional getResultSet(final ShardingSphereDatabase database, + final SQLStatementContext sqlStatementContext, final Statement statement, final List statements) throws SQLException { + return executeExecutor.getResultSet(database, sqlStatementContext, statement, statements); + } @Override - void close() throws SQLException; + public void close() throws SQLException { + sqlFederationEngine.close(); + } } diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/facade/DriverExecutorFacadeFactory.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/facade/DriverExecutorFacadeFactory.java deleted file mode 100644 index 7c15bfd1ee0bd..0000000000000 --- a/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/facade/DriverExecutorFacadeFactory.java +++ /dev/null @@ -1,42 +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.driver.executor.engine.facade; - -import org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection; -import org.apache.shardingsphere.driver.jdbc.core.statement.StatementManager; -import org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.StatementOption; -import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI; -import org.apache.shardingsphere.infra.spi.type.typed.TypedSPI; - -/** - * Driver executor facade factory. - */ -@SingletonSPI -public interface DriverExecutorFacadeFactory extends TypedSPI { - - /** - * Create new instance of driver executor facade. - * - * @param connection connection - * @param statementOption statement option - * @param statementManager statement manager - * @param jdbcDriverType JDBC driver type - * @return created instance - */ - DriverExecutorFacade newInstance(ShardingSphereConnection connection, StatementOption statementOption, StatementManager statementManager, String jdbcDriverType); -} diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/facade/standard/StandardDriverExecutorFacade.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/facade/standard/StandardDriverExecutorFacade.java deleted file mode 100644 index c361dd670a75e..0000000000000 --- a/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/facade/standard/StandardDriverExecutorFacade.java +++ /dev/null @@ -1,129 +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.driver.executor.engine.facade.standard; - -import org.apache.shardingsphere.driver.executor.callback.add.StatementAddCallback; -import org.apache.shardingsphere.driver.executor.callback.execute.StatementExecuteCallback; -import org.apache.shardingsphere.driver.executor.callback.execute.StatementExecuteUpdateCallback; -import org.apache.shardingsphere.driver.executor.callback.replay.StatementReplayCallback; -import org.apache.shardingsphere.driver.executor.engine.DriverExecuteExecutor; -import org.apache.shardingsphere.driver.executor.engine.DriverExecuteQueryExecutor; -import org.apache.shardingsphere.driver.executor.engine.DriverExecuteUpdateExecutor; -import org.apache.shardingsphere.driver.executor.engine.facade.DriverExecutorFacade; -import org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection; -import org.apache.shardingsphere.driver.jdbc.core.statement.StatementManager; -import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; -import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey; -import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry; -import org.apache.shardingsphere.infra.executor.audit.SQLAuditEngine; -import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutionUnit; -import org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutor; -import org.apache.shardingsphere.infra.executor.sql.execute.engine.raw.RawExecutor; -import org.apache.shardingsphere.infra.executor.sql.prepare.driver.DriverExecutionPrepareEngine; -import org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.StatementOption; -import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; -import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; -import org.apache.shardingsphere.infra.session.query.QueryContext; -import org.apache.shardingsphere.sqlfederation.engine.SQLFederationEngine; - -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -/** - * Standard driver executor facade. - */ -public final class StandardDriverExecutorFacade implements DriverExecutorFacade { - - private final ShardingSphereConnection connection; - - private final StatementOption statementOption; - - private final StatementManager statementManager; - - private final String jdbcDriverType; - - private final SQLFederationEngine sqlFederationEngine; - - private final DriverExecuteQueryExecutor queryExecutor; - - private final DriverExecuteUpdateExecutor updateExecutor; - - private final DriverExecuteExecutor executeExecutor; - - public StandardDriverExecutorFacade(final ShardingSphereConnection connection, final StatementOption statementOption, final StatementManager statementManager, final String jdbcDriverType) { - this.connection = connection; - this.statementOption = statementOption; - this.statementManager = statementManager; - this.jdbcDriverType = jdbcDriverType; - JDBCExecutor jdbcExecutor = new JDBCExecutor(connection.getContextManager().getExecutorEngine(), connection.getDatabaseConnectionManager().getConnectionContext()); - ShardingSphereMetaData metaData = connection.getContextManager().getMetaDataContexts().getMetaData(); - String currentSchemaName = new DatabaseTypeRegistry(metaData.getDatabase(connection.getCurrentDatabaseName()).getProtocolType()).getDefaultSchemaName(connection.getCurrentDatabaseName()); - sqlFederationEngine = - new SQLFederationEngine(connection.getCurrentDatabaseName(), currentSchemaName, metaData, connection.getContextManager().getMetaDataContexts().getStatistics(), jdbcExecutor); - RawExecutor rawExecutor = new RawExecutor(connection.getContextManager().getExecutorEngine(), connection.getDatabaseConnectionManager().getConnectionContext()); - queryExecutor = new DriverExecuteQueryExecutor(connection, metaData, jdbcExecutor, rawExecutor, sqlFederationEngine); - updateExecutor = new DriverExecuteUpdateExecutor(connection, metaData, jdbcExecutor, rawExecutor); - executeExecutor = new DriverExecuteExecutor(connection, metaData, jdbcExecutor, rawExecutor, sqlFederationEngine); - } - - @Override - @SuppressWarnings("rawtypes") - public ResultSet executeQuery(final ShardingSphereDatabase database, final QueryContext queryContext, final Statement statement, final Map columnLabelAndIndexMap, - final StatementAddCallback addCallback, final StatementReplayCallback replayCallback) throws SQLException { - SQLAuditEngine.audit(queryContext, connection.getContextManager().getMetaDataContexts().getMetaData().getGlobalRuleMetaData(), database); - return queryExecutor.executeQuery(database, queryContext, createDriverExecutionPrepareEngine(database, jdbcDriverType), statement, columnLabelAndIndexMap, addCallback, replayCallback); - } - - @Override - @SuppressWarnings("rawtypes") - public int executeUpdate(final ShardingSphereDatabase database, final QueryContext queryContext, - final StatementExecuteUpdateCallback executeUpdateCallback, final StatementAddCallback addCallback, final StatementReplayCallback replayCallback) throws SQLException { - SQLAuditEngine.audit(queryContext, connection.getContextManager().getMetaDataContexts().getMetaData().getGlobalRuleMetaData(), database); - return updateExecutor.executeUpdate(database, queryContext, createDriverExecutionPrepareEngine(database, jdbcDriverType), executeUpdateCallback, addCallback, replayCallback); - } - - @Override - @SuppressWarnings("rawtypes") - public boolean execute(final ShardingSphereDatabase database, final QueryContext queryContext, - final StatementExecuteCallback executeCallback, final StatementAddCallback addCallback, final StatementReplayCallback replayCallback) throws SQLException { - SQLAuditEngine.audit(queryContext, connection.getContextManager().getMetaDataContexts().getMetaData().getGlobalRuleMetaData(), database); - return executeExecutor.execute(database, queryContext, createDriverExecutionPrepareEngine(database, jdbcDriverType), executeCallback, addCallback, replayCallback); - } - - private DriverExecutionPrepareEngine createDriverExecutionPrepareEngine(final ShardingSphereDatabase database, final String jdbcDriverType) { - int maxConnectionsSizePerQuery = connection.getContextManager().getMetaDataContexts().getMetaData().getProps().getValue(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY); - return new DriverExecutionPrepareEngine<>(jdbcDriverType, maxConnectionsSizePerQuery, connection.getDatabaseConnectionManager(), statementManager, statementOption, - database.getRuleMetaData().getRules(), database.getResourceMetaData().getStorageUnits()); - } - - @Override - public Optional getResultSet(final ShardingSphereDatabase database, - final SQLStatementContext sqlStatementContext, final Statement statement, final List statements) throws SQLException { - return executeExecutor.getResultSet(database, sqlStatementContext, statement, statements); - } - - @Override - public void close() throws SQLException { - sqlFederationEngine.close(); - } -} diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/facade/standard/StandardDriverExecutorFacadeFactory.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/facade/standard/StandardDriverExecutorFacadeFactory.java deleted file mode 100644 index f379966090012..0000000000000 --- a/jdbc/src/main/java/org/apache/shardingsphere/driver/executor/engine/facade/standard/StandardDriverExecutorFacadeFactory.java +++ /dev/null @@ -1,46 +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.driver.executor.engine.facade.standard; - -import org.apache.shardingsphere.driver.executor.engine.facade.DriverExecutorFacade; -import org.apache.shardingsphere.driver.executor.engine.facade.DriverExecutorFacadeFactory; -import org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection; -import org.apache.shardingsphere.driver.jdbc.core.statement.StatementManager; -import org.apache.shardingsphere.infra.executor.sql.prepare.driver.jdbc.StatementOption; - -/** - * Standard driver executor facade factory. - */ -public final class StandardDriverExecutorFacadeFactory implements DriverExecutorFacadeFactory { - - @Override - public DriverExecutorFacade newInstance(final ShardingSphereConnection connection, - final StatementOption statementOption, final StatementManager statementManager, final String jdbcDriverType) { - return new StandardDriverExecutorFacade(connection, statementOption, statementManager, jdbcDriverType); - } - - @Override - public Object getType() { - return "Standard"; - } - - @Override - public boolean isDefault() { - return true; - } -} diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java index 6e41678f3bc00..eff5feae3497e 100644 --- a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java +++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java @@ -71,8 +71,6 @@ public final class ShardingSphereConnection extends AbstractConnectionAdapter { @Getter private final String processId; - private final String executorType; - private boolean autoCommit = true; private int transactionIsolation = TRANSACTION_READ_UNCOMMITTED; @@ -81,12 +79,11 @@ public final class ShardingSphereConnection extends AbstractConnectionAdapter { private volatile boolean closed; - public ShardingSphereConnection(final String currentDatabaseName, final ContextManager contextManager, final String executorType) { + public ShardingSphereConnection(final String currentDatabaseName, final ContextManager contextManager) { this.currentDatabaseName = currentDatabaseName; this.contextManager = contextManager; databaseConnectionManager = new DriverDatabaseConnectionManager(currentDatabaseName, contextManager); processId = processEngine.connect(currentDatabaseName); - this.executorType = executorType; } /** @@ -108,47 +105,47 @@ public DatabaseMetaData getMetaData() throws SQLException { @Override public PreparedStatement prepareStatement(final String sql) throws SQLException { - return new ShardingSpherePreparedStatement(this, sql, executorType); + return new ShardingSpherePreparedStatement(this, sql); } @Override public PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency) throws SQLException { - return new ShardingSpherePreparedStatement(this, sql, resultSetType, resultSetConcurrency, executorType); + return new ShardingSpherePreparedStatement(this, sql, resultSetType, resultSetConcurrency); } @Override public PreparedStatement prepareStatement(final String sql, final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability) throws SQLException { - return new ShardingSpherePreparedStatement(this, sql, resultSetType, resultSetConcurrency, resultSetHoldability, executorType); + return new ShardingSpherePreparedStatement(this, sql, resultSetType, resultSetConcurrency, resultSetHoldability); } @Override public PreparedStatement prepareStatement(final String sql, final int autoGeneratedKeys) throws SQLException { - return new ShardingSpherePreparedStatement(this, sql, autoGeneratedKeys, executorType); + return new ShardingSpherePreparedStatement(this, sql, autoGeneratedKeys); } @Override public PreparedStatement prepareStatement(final String sql, final int[] columnIndexes) throws SQLException { - return new ShardingSpherePreparedStatement(this, sql, Statement.RETURN_GENERATED_KEYS, executorType); + return new ShardingSpherePreparedStatement(this, sql, Statement.RETURN_GENERATED_KEYS); } @Override public PreparedStatement prepareStatement(final String sql, final String[] columnNames) throws SQLException { - return new ShardingSpherePreparedStatement(this, sql, columnNames, executorType); + return new ShardingSpherePreparedStatement(this, sql, columnNames); } @Override public Statement createStatement() { - return new ShardingSphereStatement(this, executorType); + return new ShardingSphereStatement(this); } @Override public Statement createStatement(final int resultSetType, final int resultSetConcurrency) { - return new ShardingSphereStatement(this, resultSetType, resultSetConcurrency, executorType); + return new ShardingSphereStatement(this, resultSetType, resultSetConcurrency); } @Override public Statement createStatement(final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability) { - return new ShardingSphereStatement(this, resultSetType, resultSetConcurrency, resultSetHoldability, executorType); + return new ShardingSphereStatement(this, resultSetType, resultSetConcurrency, resultSetHoldability); } @Override diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java index 3304a614ea470..1a667159a82ad 100644 --- a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java +++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java @@ -22,7 +22,6 @@ import org.apache.shardingsphere.driver.executor.callback.add.StatementAddCallback; import org.apache.shardingsphere.driver.executor.engine.batch.preparedstatement.DriverExecuteBatchExecutor; import org.apache.shardingsphere.driver.executor.engine.facade.DriverExecutorFacade; -import org.apache.shardingsphere.driver.executor.engine.facade.DriverExecutorFacadeFactory; import org.apache.shardingsphere.driver.jdbc.adapter.AbstractPreparedStatementAdapter; import org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection; import org.apache.shardingsphere.driver.jdbc.core.resultset.GeneratedKeysResultSet; @@ -50,7 +49,6 @@ import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; import org.apache.shardingsphere.infra.rule.attribute.resoure.StorageConnectorReusableRuleAttribute; import org.apache.shardingsphere.infra.session.query.QueryContext; -import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.parser.rule.SQLParserRule; import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; import org.apache.shardingsphere.transaction.util.AutoCommitUtils; @@ -113,30 +111,29 @@ public final class ShardingSpherePreparedStatement extends AbstractPreparedState private ResultSet currentBatchGeneratedKeysResultSet; - public ShardingSpherePreparedStatement(final ShardingSphereConnection connection, final String sql, final String executorType) throws SQLException { - this(connection, sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT, false, null, executorType); + public ShardingSpherePreparedStatement(final ShardingSphereConnection connection, final String sql) throws SQLException { + this(connection, sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT, false, null); } - public ShardingSpherePreparedStatement(final ShardingSphereConnection connection, final String sql, final int resultSetType, final int resultSetConcurrency, - final String executorType) throws SQLException { - this(connection, sql, resultSetType, resultSetConcurrency, ResultSet.HOLD_CURSORS_OVER_COMMIT, false, null, executorType); + public ShardingSpherePreparedStatement(final ShardingSphereConnection connection, final String sql, final int resultSetType, final int resultSetConcurrency) throws SQLException { + this(connection, sql, resultSetType, resultSetConcurrency, ResultSet.HOLD_CURSORS_OVER_COMMIT, false, null); } - public ShardingSpherePreparedStatement(final ShardingSphereConnection connection, final String sql, final int autoGeneratedKeys, final String executorType) throws SQLException { - this(connection, sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT, RETURN_GENERATED_KEYS == autoGeneratedKeys, null, executorType); + public ShardingSpherePreparedStatement(final ShardingSphereConnection connection, final String sql, final int autoGeneratedKeys) throws SQLException { + this(connection, sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT, RETURN_GENERATED_KEYS == autoGeneratedKeys, null); } - public ShardingSpherePreparedStatement(final ShardingSphereConnection connection, final String sql, final String[] columns, final String executorType) throws SQLException { - this(connection, sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT, true, columns, executorType); + public ShardingSpherePreparedStatement(final ShardingSphereConnection connection, final String sql, final String[] columns) throws SQLException { + this(connection, sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT, true, columns); } public ShardingSpherePreparedStatement(final ShardingSphereConnection connection, final String sql, final int resultSetType, final int resultSetConcurrency, - final int resultSetHoldability, final String executorType) throws SQLException { - this(connection, sql, resultSetType, resultSetConcurrency, resultSetHoldability, false, null, executorType); + final int resultSetHoldability) throws SQLException { + this(connection, sql, resultSetType, resultSetConcurrency, resultSetHoldability, false, null); } private ShardingSpherePreparedStatement(final ShardingSphereConnection connection, final String sql, final int resultSetType, final int resultSetConcurrency, - final int resultSetHoldability, final boolean returnGeneratedKeys, final String[] columns, final String executorType) throws SQLException { + final int resultSetHoldability, final boolean returnGeneratedKeys, final String[] columns) throws SQLException { ShardingSpherePreconditions.checkNotEmpty(sql, () -> new EmptySQLException().toSQLException()); this.connection = connection; metaData = connection.getContextManager().getMetaDataContexts().getMetaData(); @@ -153,7 +150,7 @@ private ShardingSpherePreparedStatement(final ShardingSphereConnection connectio statementManager = new StatementManager(); connection.getStatementManagers().add(statementManager); parameterMetaData = new ShardingSphereParameterMetaData(sqlStatement); - driverExecutorFacade = TypedSPILoader.getService(DriverExecutorFacadeFactory.class, executorType).newInstance(connection, statementOption, statementManager, JDBCDriverType.PREPARED_STATEMENT); + driverExecutorFacade = new DriverExecutorFacade(connection, statementOption, statementManager, JDBCDriverType.PREPARED_STATEMENT); executeBatchExecutor = new DriverExecuteBatchExecutor(connection, metaData, statementOption, statementManager, usedDatabase); statementsCacheable = isStatementsCacheable(); } diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java index cb6b10cf525f7..2125b8fc4e993 100644 --- a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java +++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSphereStatement.java @@ -24,7 +24,6 @@ import org.apache.shardingsphere.driver.executor.callback.execute.StatementExecuteUpdateCallback; import org.apache.shardingsphere.driver.executor.engine.batch.statement.BatchStatementExecutor; import org.apache.shardingsphere.driver.executor.engine.facade.DriverExecutorFacade; -import org.apache.shardingsphere.driver.executor.engine.facade.DriverExecutorFacadeFactory; import org.apache.shardingsphere.driver.jdbc.adapter.AbstractStatementAdapter; import org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection; import org.apache.shardingsphere.driver.jdbc.core.resultset.GeneratedKeysResultSet; @@ -47,7 +46,6 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute; import org.apache.shardingsphere.infra.session.query.QueryContext; -import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.parser.rule.SQLParserRule; import org.apache.shardingsphere.sql.parser.statement.core.statement.SQLStatement; import org.apache.shardingsphere.transaction.util.AutoCommitUtils; @@ -91,21 +89,21 @@ public final class ShardingSphereStatement extends AbstractStatementAdapter { private ResultSet currentResultSet; - public ShardingSphereStatement(final ShardingSphereConnection connection, final String executorType) { - this(connection, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT, executorType); + public ShardingSphereStatement(final ShardingSphereConnection connection) { + this(connection, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT); } - public ShardingSphereStatement(final ShardingSphereConnection connection, final int resultSetType, final int resultSetConcurrency, final String executorType) { - this(connection, resultSetType, resultSetConcurrency, ResultSet.HOLD_CURSORS_OVER_COMMIT, executorType); + public ShardingSphereStatement(final ShardingSphereConnection connection, final int resultSetType, final int resultSetConcurrency) { + this(connection, resultSetType, resultSetConcurrency, ResultSet.HOLD_CURSORS_OVER_COMMIT); } - public ShardingSphereStatement(final ShardingSphereConnection connection, final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability, final String executorType) { + public ShardingSphereStatement(final ShardingSphereConnection connection, final int resultSetType, final int resultSetConcurrency, final int resultSetHoldability) { this.connection = connection; metaData = connection.getContextManager().getMetaDataContexts().getMetaData(); statementOption = new StatementOption(resultSetType, resultSetConcurrency, resultSetHoldability); statementManager = new StatementManager(); connection.getStatementManagers().add(statementManager); - driverExecutorFacade = TypedSPILoader.getService(DriverExecutorFacadeFactory.class, executorType).newInstance(connection, statementOption, statementManager, JDBCDriverType.STATEMENT); + driverExecutorFacade = new DriverExecutorFacade(connection, statementOption, statementManager, JDBCDriverType.STATEMENT); batchStatementExecutor = new BatchStatementExecutor(this); statements = new LinkedList<>(); usedDatabaseName = connection.getCurrentDatabaseName(); diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/state/ok/OKDriverState.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/state/ok/OKDriverState.java index 78f43c6abe361..75e3a07a70a9a 100644 --- a/jdbc/src/main/java/org/apache/shardingsphere/driver/state/ok/OKDriverState.java +++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/state/ok/OKDriverState.java @@ -30,6 +30,6 @@ public final class OKDriverState implements DriverState { @Override public Connection getConnection(final String databaseName, final ContextManager contextManager) { - return new ShardingSphereConnection(databaseName, contextManager, null); + return new ShardingSphereConnection(databaseName, contextManager); } } diff --git a/jdbc/src/main/resources/META-INF/services/org.apache.shardingsphere.driver.executor.engine.facade.DriverExecutorFacadeFactory b/jdbc/src/main/resources/META-INF/services/org.apache.shardingsphere.driver.executor.engine.facade.DriverExecutorFacadeFactory deleted file mode 100644 index 0dadb7fcb12b4..0000000000000 --- a/jdbc/src/main/resources/META-INF/services/org.apache.shardingsphere.driver.executor.engine.facade.DriverExecutorFacadeFactory +++ /dev/null @@ -1,18 +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. -# - -org.apache.shardingsphere.driver.executor.engine.facade.standard.StandardDriverExecutorFacadeFactory diff --git a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/ConnectionAdapterTest.java b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/ConnectionAdapterTest.java index d87d671b01d32..3814fc9110d7e 100644 --- a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/ConnectionAdapterTest.java +++ b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/ConnectionAdapterTest.java @@ -96,6 +96,6 @@ void assertSetSchema() throws SQLException { private Connection createConnectionAdaptor() { ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); when(contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(mock(TransactionRule.class, RETURNS_DEEP_STUBS)))); - return new ShardingSphereConnection("foo_db", contextManager, null); + return new ShardingSphereConnection("foo_db", contextManager); } } diff --git a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/StatementAdapterTest.java b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/StatementAdapterTest.java index 1e2d6ee697833..8b04db87af209 100644 --- a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/StatementAdapterTest.java +++ b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/StatementAdapterTest.java @@ -241,7 +241,7 @@ private ShardingSphereStatement mockShardingSphereStatement(final Statement... s when(connection.getCurrentDatabaseName()).thenReturn("db"); DatabaseType databaseType = TypedSPILoader.getService(DatabaseType.class, "FIXTURE"); when(connection.getContextManager().getMetaDataContexts().getMetaData().getDatabase("db").getProtocolType()).thenReturn(databaseType); - ShardingSphereStatement result = new ShardingSphereStatement(connection, null); + ShardingSphereStatement result = new ShardingSphereStatement(connection); result.getRoutedStatements().addAll(Arrays.asList(statements)); return result; } @@ -259,7 +259,7 @@ private ShardingSphereStatement mockShardingSphereStatementWithNeedAccumulate(fi new SQLFederationRule(new DefaultSQLFederationRuleConfigurationBuilder().build(), Collections.emptyList()), new SQLParserRule(new DefaultSQLParserRuleConfigurationBuilder().build())))); when(connection.getContextManager().getMetaDataContexts().getMetaData().getProps()).thenReturn(new ConfigurationProperties(new Properties())); - ShardingSphereStatement result = new ShardingSphereStatement(connection, null); + ShardingSphereStatement result = new ShardingSphereStatement(connection); result.getRoutedStatements().addAll(Arrays.asList(statements)); setExecutionContext(result); return result; diff --git a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnectionTest.java b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnectionTest.java index 0e1e716cbe763..f43be4e2d8ee9 100644 --- a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnectionTest.java +++ b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnectionTest.java @@ -53,7 +53,7 @@ class ShardingSphereConnectionTest { @Test void assertSetAutoCommitWithLocalTransaction() throws SQLException { Connection physicalConnection = mock(Connection.class); - try (ShardingSphereConnection connection = new ShardingSphereConnection("foo_db", mockContextManager(physicalConnection), null)) { + try (ShardingSphereConnection connection = new ShardingSphereConnection("foo_db", mockContextManager(physicalConnection))) { connection.getDatabaseConnectionManager().getConnections("foo_db", "ds", 0, 1, ConnectionMode.MEMORY_STRICTLY); connection.setAutoCommit(true); assertTrue(connection.getAutoCommit()); @@ -66,7 +66,7 @@ void assertSetAutoCommitWithDistributedTransaction() throws SQLException { ConnectionTransaction connectionTransaction = mock(ConnectionTransaction.class); when(connectionTransaction.getDistributedTransactionOperationType(true)).thenReturn(Optional.of(DistributedTransactionOperationType.COMMIT)); when(connectionTransaction.getTransactionType()).thenReturn(TransactionType.XA); - try (ShardingSphereConnection connection = new ShardingSphereConnection("foo_db", mockContextManager(), null)) { + try (ShardingSphereConnection connection = new ShardingSphereConnection("foo_db", mockContextManager())) { DriverDatabaseConnectionManager connectionManager = mockConnectionManager(connection, connectionTransaction); connection.setAutoCommit(true); assertTrue(connection.getAutoCommit()); @@ -77,7 +77,7 @@ void assertSetAutoCommitWithDistributedTransaction() throws SQLException { @Test void assertCommitWithLocalTransaction() throws SQLException { Connection physicalConnection = mock(Connection.class); - try (ShardingSphereConnection connection = new ShardingSphereConnection("foo_db", mockContextManager(physicalConnection), null)) { + try (ShardingSphereConnection connection = new ShardingSphereConnection("foo_db", mockContextManager(physicalConnection))) { connection.getDatabaseConnectionManager().getConnections("foo_db", "ds", 0, 1, ConnectionMode.MEMORY_STRICTLY); connection.setAutoCommit(false); assertFalse(connection.getAutoCommit()); @@ -94,7 +94,7 @@ void assertCommitWithDistributedTransaction() throws SQLException { ConnectionTransaction connectionTransaction = mock(ConnectionTransaction.class); when(connectionTransaction.getDistributedTransactionOperationType(false)).thenReturn(Optional.of(DistributedTransactionOperationType.BEGIN)); when(connectionTransaction.getTransactionType()).thenReturn(TransactionType.XA); - try (ShardingSphereConnection connection = new ShardingSphereConnection("foo_db", mockContextManager(), null)) { + try (ShardingSphereConnection connection = new ShardingSphereConnection("foo_db", mockContextManager())) { DriverDatabaseConnectionManager databaseConnectionManager = mockConnectionManager(connection, connectionTransaction); connection.setAutoCommit(false); assertFalse(connection.getAutoCommit()); @@ -107,7 +107,7 @@ void assertCommitWithDistributedTransaction() throws SQLException { @Test void assertRollbackWithLocalTransaction() throws SQLException { Connection physicalConnection = mock(Connection.class); - try (ShardingSphereConnection connection = new ShardingSphereConnection("foo_db", mockContextManager(physicalConnection), null)) { + try (ShardingSphereConnection connection = new ShardingSphereConnection("foo_db", mockContextManager(physicalConnection))) { connection.getDatabaseConnectionManager().getConnections("foo_db", "ds", 0, 1, ConnectionMode.MEMORY_STRICTLY); connection.setAutoCommit(false); assertFalse(connection.getAutoCommit()); @@ -121,7 +121,7 @@ void assertRollbackWithDistributedTransaction() throws SQLException { ConnectionTransaction connectionTransaction = mock(ConnectionTransaction.class); when(connectionTransaction.getDistributedTransactionOperationType(false)).thenReturn(Optional.of(DistributedTransactionOperationType.BEGIN)); when(connectionTransaction.getTransactionType()).thenReturn(TransactionType.XA); - try (ShardingSphereConnection connection = new ShardingSphereConnection("foo_db", mockContextManager(), null)) { + try (ShardingSphereConnection connection = new ShardingSphereConnection("foo_db", mockContextManager())) { final DriverDatabaseConnectionManager databaseConnectionManager = mockConnectionManager(connection, connectionTransaction); connection.setAutoCommit(false); assertFalse(connection.getAutoCommit()); @@ -142,14 +142,14 @@ private DriverDatabaseConnectionManager mockConnectionManager(final ShardingSphe @Test void assertIsValidWhenEmptyConnection() throws SQLException { - try (ShardingSphereConnection connection = new ShardingSphereConnection("foo_db", mockContextManager(), null)) { + try (ShardingSphereConnection connection = new ShardingSphereConnection("foo_db", mockContextManager())) { assertTrue(connection.isValid(0)); } } @Test void assertIsInvalid() throws SQLException { - try (ShardingSphereConnection connection = new ShardingSphereConnection("foo_db", mockContextManager(), null)) { + try (ShardingSphereConnection connection = new ShardingSphereConnection("foo_db", mockContextManager())) { connection.getDatabaseConnectionManager().getConnections("foo_db", "ds", 0, 1, ConnectionMode.MEMORY_STRICTLY); assertFalse(connection.isValid(0)); } @@ -157,7 +157,7 @@ void assertIsInvalid() throws SQLException { @Test void assertSetReadOnly() throws SQLException { - try (ShardingSphereConnection connection = new ShardingSphereConnection("foo_db", mockContextManager(), null)) { + try (ShardingSphereConnection connection = new ShardingSphereConnection("foo_db", mockContextManager())) { assertFalse(connection.isReadOnly()); Connection physicalConnection = connection.getDatabaseConnectionManager().getConnections("foo_db", "ds", 0, 1, ConnectionMode.MEMORY_STRICTLY).get(0); connection.setReadOnly(true); @@ -168,7 +168,7 @@ void assertSetReadOnly() throws SQLException { @Test void assertGetTransactionIsolationWithoutCachedConnections() throws SQLException { - try (ShardingSphereConnection connection = new ShardingSphereConnection("foo_db", mockContextManager(), null)) { + try (ShardingSphereConnection connection = new ShardingSphereConnection("foo_db", mockContextManager())) { assertThat(connection.getTransactionIsolation(), is(Connection.TRANSACTION_READ_UNCOMMITTED)); } @@ -176,7 +176,7 @@ void assertGetTransactionIsolationWithoutCachedConnections() throws SQLException @Test void assertSetTransactionIsolation() throws SQLException { - try (ShardingSphereConnection connection = new ShardingSphereConnection("foo_db", mockContextManager(), null)) { + try (ShardingSphereConnection connection = new ShardingSphereConnection("foo_db", mockContextManager())) { Connection physicalConnection = connection.getDatabaseConnectionManager().getConnections("foo_db", "ds", 0, 1, ConnectionMode.MEMORY_STRICTLY).get(0); connection.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE); verify(physicalConnection).setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE); @@ -185,7 +185,7 @@ void assertSetTransactionIsolation() throws SQLException { @Test void assertClose() throws SQLException { - try (ShardingSphereConnection connection = new ShardingSphereConnection("foo_db", mockContextManager(), null)) { + try (ShardingSphereConnection connection = new ShardingSphereConnection("foo_db", mockContextManager())) { connection.close(); assertTrue(connection.isClosed()); } diff --git a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationConnectionTest.java b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationConnectionTest.java index 5c09e25467426..2ae289e4ccddc 100644 --- a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationConnectionTest.java +++ b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationConnectionTest.java @@ -44,7 +44,7 @@ class UnsupportedOperationConnectionTest { void setUp() { ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); when(contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(new RuleMetaData(Collections.singleton(mock(TransactionRule.class, RETURNS_DEEP_STUBS)))); - shardingSphereConnection = new ShardingSphereConnection("foo_db", contextManager, null); + shardingSphereConnection = new ShardingSphereConnection("foo_db", contextManager); } @SuppressWarnings("JDBCResourceOpenedButNotSafelyClosed") diff --git a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationStatementTest.java b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationStatementTest.java index ed6da52a7ce41..cffd4b6273132 100644 --- a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationStatementTest.java +++ b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationStatementTest.java @@ -55,7 +55,7 @@ void setUp() { new SQLFederationRule(new DefaultSQLFederationRuleConfigurationBuilder().build(), Collections.emptyList()), new SQLParserRule(new DefaultSQLParserRuleConfigurationBuilder().build())))); when(connection.getContextManager().getMetaDataContexts().getMetaData().getProps()).thenReturn(new ConfigurationProperties(new Properties())); - shardingSphereStatement = new ShardingSphereStatement(connection, null); + shardingSphereStatement = new ShardingSphereStatement(connection); } @Test diff --git a/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/api/MigrationJobAPI.java b/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/api/MigrationJobAPI.java index 04f69fd3eb5d5..3043aefc834dc 100644 --- a/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/api/MigrationJobAPI.java +++ b/kernel/data-pipeline/scenario/migration/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/api/MigrationJobAPI.java @@ -196,16 +196,16 @@ private YamlRootConfiguration buildYamlRootConfiguration(final String databaseNa } private Collection getYamlRuleConfigurations(final Collection rules) { - Collection ruleConfigurations = new YamlRuleConfigurationSwapperEngine().swapToYamlRuleConfigurations(rules); - Optional originalSingleRuleConfig = - ruleConfigurations.stream().filter(YamlSingleRuleConfiguration.class::isInstance).map(YamlSingleRuleConfiguration.class::cast).findFirst(); - ruleConfigurations.removeIf(YamlSingleRuleConfiguration.class::isInstance); + Collection result = new YamlRuleConfigurationSwapperEngine().swapToYamlRuleConfigurations(rules); + Optional originalSingleRuleConfig = result.stream() + .filter(YamlSingleRuleConfiguration.class::isInstance).map(YamlSingleRuleConfiguration.class::cast).findFirst(); + result.removeIf(YamlSingleRuleConfiguration.class::isInstance); YamlSingleRuleConfiguration singleRuleConfig = new YamlSingleRuleConfiguration(); - // todo Provide only the necessary tables. + // TODO Provide only the necessary tables. singleRuleConfig.setTables(Collections.singletonList(SingleTableConstants.ALL_TABLES)); originalSingleRuleConfig.ifPresent(optional -> singleRuleConfig.setDefaultDataSource(optional.getDefaultDataSource())); - ruleConfigurations.add(singleRuleConfig); - return ruleConfigurations; + result.add(singleRuleConfig); + return result; } private Map buildTargetTableSchemaMap(final Map> sourceDataNodes) { From e42f4e52d4406be73a890d9c7fa56472c6d6a820 Mon Sep 17 00:00:00 2001 From: Zhengqiang Duan Date: Thu, 12 Dec 2024 16:05:41 +0800 Subject: [PATCH 04/32] Refactor ColumnSegmentBoundInfo and correct pass to SQLBindEngine databaseName (#34023) * Refactor ColumnSegmentBoundInfo and correct pass to SQLBindEngine databaseName * Refactor ColumnSegmentBoundInfo and correct pass to SQLBindEngine databaseName * fix unit test * fix unit test * fix unit test * fix unit test --- ...cryptSelectProjectionSupportedChecker.java | 2 +- ...ptPredicateColumnSupportedCheckerTest.java | 15 +++++---- ...tSelectProjectionSupportedCheckerTest.java | 17 +++++----- .../merge/dql/EncryptMergedResultTest.java | 11 ++++--- ...tSelectColumnsEncryptorComparatorTest.java | 5 +-- .../EncryptGeneratorFixtureBuilder.java | 7 ++-- .../EncryptProjectionTokenGeneratorTest.java | 5 +-- .../expression/type/ColumnSegmentBinder.java | 2 +- .../from/type/SimpleTableSegmentBinder.java | 3 +- .../engine/util/SubqueryTableBindUtils.java | 7 ++-- .../projection/impl/ColumnProjectionTest.java | 3 +- .../assign/AssignmentSegmentBinderTest.java | 3 +- .../type/ColumnSegmentBinderTest.java | 20 ++++++------ .../type/SubquerySegmentBinderTest.java | 5 +-- .../connection/ShardingSphereConnection.java | 1 - .../generator/PipelineDDLGenerator.java | 4 +-- .../context/SQLFederationExecutorContext.java | 2 +- .../enumerable/EnumerableScanExecutor.java | 4 +-- .../EnumerableScanExecutorTest.java | 2 +- .../generic/bound/ColumnSegmentBoundInfo.java | 32 ++++++++++++++----- .../generic/bound/TableSegmentBoundInfo.java | 7 ++-- .../handler/distsql/rul/PreviewExecutor.java | 3 +- .../MySQLComFieldListPacketExecutor.java | 8 ++--- .../query/MySQLMultiStatementsHandler.java | 4 +-- .../MySQLComQueryPacketExecutorTest.java | 4 +-- .../MySQLMultiStatementsHandlerTest.java | 2 +- .../OpenGaussComBatchBindExecutorTest.java | 2 +- .../PostgreSQLBatchedStatementsExecutor.java | 5 +-- ...dBatchedStatementsCommandExecutorTest.java | 2 +- ...stgreSQLBatchedStatementsExecutorTest.java | 2 +- 30 files changed, 112 insertions(+), 77 deletions(-) diff --git a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/sql/projection/EncryptSelectProjectionSupportedChecker.java b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/sql/projection/EncryptSelectProjectionSupportedChecker.java index 5cb206098d8ba..a0bdeb2d5c701 100644 --- a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/sql/projection/EncryptSelectProjectionSupportedChecker.java +++ b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/checker/sql/projection/EncryptSelectProjectionSupportedChecker.java @@ -94,7 +94,7 @@ private boolean containsEncryptProjectionInCombineSegment(final EncryptRule rule private ColumnSegmentBoundInfo getColumnSegmentBoundInfo(final Projection projection) { return projection instanceof ColumnProjection - ? new ColumnSegmentBoundInfo(null, null, ((ColumnProjection) projection).getOriginalTable(), ((ColumnProjection) projection).getOriginalColumn()) + ? new ColumnSegmentBoundInfo(null, ((ColumnProjection) projection).getOriginalTable(), ((ColumnProjection) projection).getOriginalColumn()) : new ColumnSegmentBoundInfo(new IdentifierValue(projection.getColumnLabel())); } diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/predicate/EncryptPredicateColumnSupportedCheckerTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/predicate/EncryptPredicateColumnSupportedCheckerTest.java index e5387f7573171..1c2ef0ba5aff8 100644 --- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/predicate/EncryptPredicateColumnSupportedCheckerTest.java +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/predicate/EncryptPredicateColumnSupportedCheckerTest.java @@ -26,6 +26,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.BinaryOperationExpression; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.ColumnSegmentBoundInfo; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; import org.junit.jupiter.api.Test; @@ -66,9 +67,11 @@ void assertCheckWithDifferentEncryptorsInJoinCondition() { private SQLStatementContext mockSelectStatementContextWithDifferentEncryptorsInJoinCondition() { ColumnSegment leftColumn = new ColumnSegment(0, 0, new IdentifierValue("user_name")); - leftColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), new IdentifierValue("t_user"), new IdentifierValue("user_name"))); + leftColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")), new IdentifierValue("t_user"), + new IdentifierValue("user_name"))); ColumnSegment rightColumn = new ColumnSegment(0, 0, new IdentifierValue("user_id")); - rightColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), new IdentifierValue("t_user"), new IdentifierValue("user_id"))); + rightColumn.setColumnBoundInfo( + new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")), new IdentifierValue("t_user"), new IdentifierValue("user_id"))); SelectStatementContext result = mock(SelectStatementContext.class); when(result.getJoinConditions()).thenReturn(Collections.singleton(new BinaryOperationExpression(0, 0, leftColumn, rightColumn, "=", ""))); return result; @@ -82,8 +85,8 @@ void assertCheckWithNotMatchedLikeQueryEncryptor() { private SQLStatementContext mockSelectStatementContextWithLike() { ColumnSegment columnSegment = new ColumnSegment(0, 0, new IdentifierValue("user_name")); - columnSegment.setColumnBoundInfo( - new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), new IdentifierValue("t_user"), new IdentifierValue("user_name"))); + columnSegment.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")), new IdentifierValue("t_user"), + new IdentifierValue("user_name"))); SelectStatementContext result = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS); when(result.getTablesContext().findTableNames(Collections.singleton(columnSegment), null)).thenReturn(Collections.singletonMap("user_name", "t_user")); when(result.getColumnSegments()).thenReturn(Collections.singleton(columnSegment)); @@ -100,8 +103,8 @@ void assertCheckSuccess() { private SQLStatementContext mockSelectStatementContextWithEqual() { ColumnSegment columnSegment = new ColumnSegment(0, 0, new IdentifierValue("user_name")); - columnSegment.setColumnBoundInfo( - new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), new IdentifierValue("t_user"), new IdentifierValue("user_name"))); + columnSegment.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")), new IdentifierValue("t_user"), + new IdentifierValue("user_name"))); SelectStatementContext result = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS); when(result.getTablesContext().findTableNames(Collections.singleton(columnSegment), null)).thenReturn(Collections.singletonMap("user_name", "t_user")); when(result.getColumnSegments()).thenReturn(Collections.singleton(columnSegment)); diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/projection/EncryptSelectProjectionSupportedCheckerTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/projection/EncryptSelectProjectionSupportedCheckerTest.java index 023781df499f1..6bdb6214a914b 100644 --- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/projection/EncryptSelectProjectionSupportedCheckerTest.java +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/projection/EncryptSelectProjectionSupportedCheckerTest.java @@ -27,6 +27,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.combine.CombineSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ShorthandProjectionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.ColumnSegmentBoundInfo; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; import org.junit.jupiter.api.Test; @@ -91,16 +92,16 @@ private SelectStatementContext mockSelectStatementContext() { when(combineSegment.getLeft().getStartIndex()).thenReturn(0); when(combineSegment.getRight().getStartIndex()).thenReturn(1); when(result.getSqlStatement().getCombine()).thenReturn(Optional.of(combineSegment)); - ColumnProjection leftColumn1 = new ColumnProjection(new IdentifierValue("f"), new IdentifierValue("foo_col_1"), null, databaseType, - null, null, new ColumnSegmentBoundInfo(new IdentifierValue(""), new IdentifierValue(""), new IdentifierValue("foo_tbl"), new IdentifierValue("foo_col_1"))); - ColumnProjection leftColumn2 = new ColumnProjection(new IdentifierValue("f"), new IdentifierValue("foo_col_2"), null, databaseType, - null, null, new ColumnSegmentBoundInfo(new IdentifierValue(""), new IdentifierValue(""), new IdentifierValue("foo_tbl"), new IdentifierValue("foo_col_2"))); + ColumnProjection leftColumn1 = new ColumnProjection(new IdentifierValue("f"), new IdentifierValue("foo_col_1"), null, databaseType, null, null, + new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue(""), new IdentifierValue("")), new IdentifierValue("foo_tbl"), new IdentifierValue("foo_col_1"))); + ColumnProjection leftColumn2 = new ColumnProjection(new IdentifierValue("f"), new IdentifierValue("foo_col_2"), null, databaseType, null, null, + new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue(""), new IdentifierValue("")), new IdentifierValue("foo_tbl"), new IdentifierValue("foo_col_2"))); SelectStatementContext leftSelectStatementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS); when(leftSelectStatementContext.getProjectionsContext().getExpandProjections()).thenReturn(Arrays.asList(leftColumn1, leftColumn2)); - ColumnProjection rightColumn1 = new ColumnProjection(new IdentifierValue("b"), new IdentifierValue("bar_col_1"), null, databaseType, - null, null, new ColumnSegmentBoundInfo(new IdentifierValue(""), new IdentifierValue(""), new IdentifierValue("bar_tbl"), new IdentifierValue("bar_col_1"))); - ColumnProjection rightColumn2 = new ColumnProjection(new IdentifierValue("b"), new IdentifierValue("bar_col_2"), null, databaseType, - null, null, new ColumnSegmentBoundInfo(new IdentifierValue(""), new IdentifierValue(""), new IdentifierValue("bar_tbl"), new IdentifierValue("bar_col_2"))); + ColumnProjection rightColumn1 = new ColumnProjection(new IdentifierValue("b"), new IdentifierValue("bar_col_1"), null, databaseType, null, null, + new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue(""), new IdentifierValue("")), new IdentifierValue("bar_tbl"), new IdentifierValue("bar_col_1"))); + ColumnProjection rightColumn2 = new ColumnProjection(new IdentifierValue("b"), new IdentifierValue("bar_col_2"), null, databaseType, null, null, + new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue(""), new IdentifierValue("")), new IdentifierValue("bar_tbl"), new IdentifierValue("bar_col_2"))); SelectStatementContext rightSelectStatementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS); when(rightSelectStatementContext.getProjectionsContext().getExpandProjections()).thenReturn(Arrays.asList(rightColumn1, rightColumn2)); Map subqueryContexts = new LinkedHashMap<>(2, 1F); diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptMergedResultTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptMergedResultTest.java index 755a38a13e7da..eb827dd98deab 100644 --- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptMergedResultTest.java +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptMergedResultTest.java @@ -33,6 +33,7 @@ import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.ColumnSegmentBoundInfo; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -107,8 +108,9 @@ void assertGetValueWithoutEncryptColumn() throws SQLException { @Test void assertGetValueWithEncryptColumn() throws SQLException { - ColumnProjection columnProjection = new ColumnProjection(new IdentifierValue("foo_tbl"), new IdentifierValue("foo_col"), new IdentifierValue("foo_alias"), databaseType, - null, null, new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), new IdentifierValue("foo_tbl"), new IdentifierValue("foo_col"))); + ColumnProjection columnProjection = + new ColumnProjection(new IdentifierValue("foo_tbl"), new IdentifierValue("foo_col"), new IdentifierValue("foo_alias"), databaseType, null, null, new ColumnSegmentBoundInfo( + new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")), new IdentifierValue("foo_tbl"), new IdentifierValue("foo_col"))); when(selectStatementContext.findColumnProjection(1)).thenReturn(Optional.of(columnProjection)); when(selectStatementContext.getTablesContext().getSchemaName()).thenReturn(Optional.of("foo_schema")); EncryptAlgorithm encryptAlgorithm = mock(EncryptAlgorithm.class); @@ -122,8 +124,9 @@ void assertGetValueWithEncryptColumn() throws SQLException { @Test void assertGetValueFailed() throws SQLException { - ColumnProjection columnProjection = new ColumnProjection(new IdentifierValue("foo_tbl"), new IdentifierValue("foo_col"), new IdentifierValue("foo_alias"), databaseType, - null, null, new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), new IdentifierValue("foo_tbl"), new IdentifierValue("foo_col"))); + ColumnProjection columnProjection = + new ColumnProjection(new IdentifierValue("foo_tbl"), new IdentifierValue("foo_col"), new IdentifierValue("foo_alias"), databaseType, null, null, new ColumnSegmentBoundInfo( + new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")), new IdentifierValue("foo_tbl"), new IdentifierValue("foo_col"))); when(selectStatementContext.findColumnProjection(1)).thenReturn(Optional.of(columnProjection)); when(selectStatementContext.getTablesContext().getSchemaName()).thenReturn(Optional.of("foo_schema")); EncryptAlgorithm encryptAlgorithm = mock(EncryptAlgorithm.class); diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/comparator/InsertSelectColumnsEncryptorComparatorTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/comparator/InsertSelectColumnsEncryptorComparatorTest.java index 76be5b0c8dcb3..9a73d2b1103cd 100644 --- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/comparator/InsertSelectColumnsEncryptorComparatorTest.java +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/comparator/InsertSelectColumnsEncryptorComparatorTest.java @@ -26,6 +26,7 @@ import org.apache.shardingsphere.infra.binder.context.segment.select.projection.impl.ColumnProjection; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.ColumnSegmentBoundInfo; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -59,13 +60,13 @@ void assertInsertSelectIsSame() { private ColumnProjection getSelectProjection(final String pwd, final IdentifierValue databaseValue, final IdentifierValue schemaValue) { return new ColumnProjection(new IdentifierValue("table2"), new IdentifierValue(pwd), null, null, null, null, - new ColumnSegmentBoundInfo(databaseValue, schemaValue, new IdentifierValue("table2"), new IdentifierValue(pwd))); + new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(databaseValue, schemaValue), new IdentifierValue("table2"), new IdentifierValue(pwd))); } private ColumnSegment getInsertColumnSegment(final IdentifierValue databaseValue, final IdentifierValue schemaValue, final String tableName, final String columnName) { ColumnSegment result = mock(ColumnSegment.class); when(result.getColumnBoundInfo()) - .thenReturn(new ColumnSegmentBoundInfo(databaseValue, schemaValue, new IdentifierValue(tableName), new IdentifierValue(columnName))); + .thenReturn(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(databaseValue, schemaValue), new IdentifierValue(tableName), new IdentifierValue(columnName))); return result; } diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/fixture/EncryptGeneratorFixtureBuilder.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/fixture/EncryptGeneratorFixtureBuilder.java index 72a37c30d60e1..80287886d790c 100644 --- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/fixture/EncryptGeneratorFixtureBuilder.java +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/fixture/EncryptGeneratorFixtureBuilder.java @@ -50,6 +50,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ProjectionsSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.ColumnSegmentBoundInfo; +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.dml.InsertStatement; @@ -128,10 +129,10 @@ private static InsertStatement createInsertSelectStatement(final boolean contain InsertStatement result = new MySQLInsertStatement(); result.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_user")))); ColumnSegment userIdColumn = new ColumnSegment(0, 0, new IdentifierValue("user_id")); - userIdColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_db"), new IdentifierValue("t_user"), + userIdColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_db")), new IdentifierValue("t_user"), new IdentifierValue("user_id"))); ColumnSegment userNameColumn = new ColumnSegment(0, 0, new IdentifierValue("user_name")); - userNameColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_db"), + userNameColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_db")), new IdentifierValue("t_user"), new IdentifierValue("user_name"))); List insertColumns = Arrays.asList(userIdColumn, userNameColumn); if (containsInsertColumns) { @@ -145,7 +146,7 @@ private static InsertStatement createInsertSelectStatement(final boolean contain ProjectionsSegment projections = new ProjectionsSegment(0, 0); projections.getProjections().add(new ColumnProjectionSegment(userIdColumn)); ColumnSegment statusColumn = new ColumnSegment(0, 0, new IdentifierValue("status")); - statusColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_db"), new IdentifierValue("t_user"), + statusColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_db")), new IdentifierValue("t_user"), new IdentifierValue("status"))); projections.getProjections().add(new ColumnProjectionSegment(statusColumn)); selectStatement.setProjections(projections); diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/projection/EncryptProjectionTokenGeneratorTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/projection/EncryptProjectionTokenGeneratorTest.java index 18b3e0c84ffa5..627e0b4b17151 100644 --- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/projection/EncryptProjectionTokenGeneratorTest.java +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/projection/EncryptProjectionTokenGeneratorTest.java @@ -32,6 +32,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.AliasSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.OwnerSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.ColumnSegmentBoundInfo; +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.value.identifier.IdentifierValue; @@ -80,7 +81,7 @@ void assertGenerateSQLTokensWhenOwnerMatchTableAlias() { SimpleTableSegment doctorTable = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("doctor"))); doctorTable.setAlias(new AliasSegment(0, 0, new IdentifierValue("a"))); ColumnSegment column = new ColumnSegment(0, 0, new IdentifierValue("mobile")); - column.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_db"), new IdentifierValue("doctor"), + column.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_db")), new IdentifierValue("doctor"), new IdentifierValue("mobile"))); column.setOwner(new OwnerSegment(0, 0, new IdentifierValue("a"))); ProjectionsSegment projections = mock(ProjectionsSegment.class); @@ -102,7 +103,7 @@ void assertGenerateSQLTokensWhenOwnerMatchTableAliasForSameTable() { SimpleTableSegment doctorTable = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("doctor"))); doctorTable.setAlias(new AliasSegment(0, 0, new IdentifierValue("a"))); ColumnSegment column = new ColumnSegment(0, 0, new IdentifierValue("mobile")); - column.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_db"), new IdentifierValue("doctor"), + column.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_db")), new IdentifierValue("doctor"), new IdentifierValue("mobile"))); column.setOwner(new OwnerSegment(0, 0, new IdentifierValue("a"))); ProjectionsSegment projections = mock(ProjectionsSegment.class); diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/ColumnSegmentBinder.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/ColumnSegmentBinder.java index e1d828befe82d..3e3a894764c12 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/ColumnSegmentBinder.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/ColumnSegmentBinder.java @@ -260,7 +260,7 @@ private static ColumnSegmentBoundInfo createColumnSegmentBoundInfo(final ColumnS : segmentOriginalTable; IdentifierValue segmentOriginalColumn = segment.getColumnBoundInfo().getOriginalColumn(); IdentifierValue originalColumn = Optional.ofNullable(inputColumnSegment).map(optional -> optional.getColumnBoundInfo().getOriginalColumn()).orElse(segmentOriginalColumn); - return new ColumnSegmentBoundInfo(originalDatabase, originalSchema, originalTable, originalColumn); + return new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(originalDatabase, originalSchema), originalTable, originalColumn); } /** diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/SimpleTableSegmentBinder.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/SimpleTableSegmentBinder.java index 8c74c0dd5b49c..e77dc4f7f4ebe 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/SimpleTableSegmentBinder.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/SimpleTableSegmentBinder.java @@ -42,6 +42,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ProjectionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.OwnerSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.ColumnSegmentBoundInfo; +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.value.identifier.IdentifierValue; @@ -158,7 +159,7 @@ private static ColumnSegment createColumnSegment(final SimpleTableSegment segmen final ShardingSphereColumn column, final QuoteCharacter quoteCharacter, final IdentifierValue tableName) { ColumnSegment result = new ColumnSegment(0, 0, new IdentifierValue(column.getName(), quoteCharacter)); result.setOwner(new OwnerSegment(0, 0, segment.getAlias().orElse(tableName))); - result.setColumnBoundInfo(new ColumnSegmentBoundInfo(databaseName, schemaName, tableName, new IdentifierValue(column.getName(), quoteCharacter))); + result.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(databaseName, schemaName), tableName, new IdentifierValue(column.getName(), quoteCharacter))); return result; } } diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/util/SubqueryTableBindUtils.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/util/SubqueryTableBindUtils.java index 74026fc429946..40d640b910bd5 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/util/SubqueryTableBindUtils.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/util/SubqueryTableBindUtils.java @@ -33,6 +33,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.AliasAvailable; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.OwnerSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.ColumnSegmentBoundInfo; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; import java.util.Collection; @@ -75,9 +76,9 @@ private static ColumnProjectionSegment createColumnProjection(final ColumnProjec if (!Strings.isNullOrEmpty(subqueryTableName.getValue())) { newColumnSegment.setOwner(new OwnerSegment(0, 0, subqueryTableName)); } - newColumnSegment.setColumnBoundInfo( - new ColumnSegmentBoundInfo(originalColumn.getColumn().getColumnBoundInfo().getOriginalDatabase(), originalColumn.getColumn().getColumnBoundInfo().getOriginalSchema(), - originalColumn.getColumn().getColumnBoundInfo().getOriginalTable(), originalColumn.getColumn().getColumnBoundInfo().getOriginalColumn())); + ColumnSegmentBoundInfo columnBoundInfo = originalColumn.getColumn().getColumnBoundInfo(); + newColumnSegment.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(columnBoundInfo.getOriginalDatabase(), columnBoundInfo.getOriginalSchema()), + columnBoundInfo.getOriginalTable(), columnBoundInfo.getOriginalColumn())); ColumnProjectionSegment result = new ColumnProjectionSegment(newColumnSegment); result.setVisible(originalColumn.isVisible()); return result; diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/ColumnProjectionTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/ColumnProjectionTest.java index 0b84d3971e6d9..81d57894a32ea 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/ColumnProjectionTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/ColumnProjectionTest.java @@ -20,6 +20,7 @@ import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.ColumnSegmentBoundInfo; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; import org.junit.jupiter.api.Test; @@ -53,7 +54,7 @@ void assertGetOriginalTableWithEmptyOriginalTableAndWithOwner() { @Test void assertGetOriginalTable() { ColumnProjection projection = new ColumnProjection(new IdentifierValue("owner"), new IdentifierValue("name"), new IdentifierValue("alias"), databaseType, - null, null, new ColumnSegmentBoundInfo(new IdentifierValue(""), new IdentifierValue(""), new IdentifierValue("tbl"), new IdentifierValue(""))); + null, null, new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(null, null), new IdentifierValue("tbl"), new IdentifierValue(""))); assertThat(projection.getOriginalTable(), is(new IdentifierValue("tbl"))); } diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/assign/AssignmentSegmentBinderTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/assign/AssignmentSegmentBinderTest.java index 1e7797b0df17b..fa7e5f76aacef 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/assign/AssignmentSegmentBinderTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/assign/AssignmentSegmentBinderTest.java @@ -29,6 +29,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.simple.LiteralExpressionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ColumnProjectionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.ColumnSegmentBoundInfo; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; import org.junit.jupiter.api.Test; @@ -47,7 +48,7 @@ class AssignmentSegmentBinderTest { void assertBindAssignmentSegment() { Collection assignments = new LinkedList<>(); ColumnSegment boundOrderIdColumn = new ColumnSegment(0, 0, new IdentifierValue("order_id")); - boundOrderIdColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_db"), + boundOrderIdColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_db")), new IdentifierValue("t_order"), new IdentifierValue("order_id"))); ColumnSegment columnSegment = new ColumnSegment(0, 0, new IdentifierValue("order_id")); assignments.add(new ColumnAssignmentSegment(0, 0, Collections.singletonList(columnSegment), new LiteralExpressionSegment(0, 0, 1))); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/ColumnSegmentBinderTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/ColumnSegmentBinderTest.java index 86127e9d1fad0..9952c36f686bf 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/ColumnSegmentBinderTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/ColumnSegmentBinderTest.java @@ -54,11 +54,11 @@ class ColumnSegmentBinderTest { void assertBindWithMultiTablesJoinAndNoOwner() { Multimap tableBinderContexts = LinkedHashMultimap.create(); ColumnSegment boundOrderIdColumn = new ColumnSegment(0, 0, new IdentifierValue("order_id")); - boundOrderIdColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), + boundOrderIdColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")), new IdentifierValue("t_order"), new IdentifierValue("order_id"))); tableBinderContexts.put(new CaseInsensitiveString("t_order"), new SimpleTableSegmentBinderContext(Collections.singleton(new ColumnProjectionSegment(boundOrderIdColumn)))); ColumnSegment boundItemIdColumn = new ColumnSegment(0, 0, new IdentifierValue("item_id")); - boundItemIdColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), + boundItemIdColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")), new IdentifierValue("t_order_item"), new IdentifierValue("item_id"))); tableBinderContexts.put(new CaseInsensitiveString("t_order_item"), new SimpleTableSegmentBinderContext(Collections.singleton(new ColumnProjectionSegment(boundItemIdColumn)))); ColumnSegment columnSegment = new ColumnSegment(0, 0, new IdentifierValue("order_id")); @@ -77,11 +77,11 @@ void assertBindWithMultiTablesJoinAndNoOwner() { void assertBindFromOuterTable() { Multimap outerTableBinderContexts = LinkedHashMultimap.create(); ColumnSegment boundOrderStatusColumn = new ColumnSegment(0, 0, new IdentifierValue("status")); - boundOrderStatusColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), + boundOrderStatusColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")), new IdentifierValue("t_order"), new IdentifierValue("status"))); outerTableBinderContexts.put(new CaseInsensitiveString("t_order"), new SimpleTableSegmentBinderContext(Collections.singleton(new ColumnProjectionSegment(boundOrderStatusColumn)))); ColumnSegment boundOrderItemStatusColumn = new ColumnSegment(0, 0, new IdentifierValue("status")); - boundOrderItemStatusColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), + boundOrderItemStatusColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")), new IdentifierValue("t_order_item"), new IdentifierValue("status"))); outerTableBinderContexts.put(new CaseInsensitiveString("t_order_item"), new SimpleTableSegmentBinderContext(Collections.singleton(new ColumnProjectionSegment(boundOrderItemStatusColumn)))); SQLStatementBinderContext binderContext = @@ -100,11 +100,11 @@ void assertBindFromOuterTable() { void assertBindWithSameTableAliasAndSameProjection() { Multimap tableBinderContexts = LinkedHashMultimap.create(); ColumnSegment boundOrderColumn = new ColumnSegment(0, 0, new IdentifierValue("status")); - boundOrderColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), + boundOrderColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")), new IdentifierValue("t_order"), new IdentifierValue("status"))); tableBinderContexts.put(new CaseInsensitiveString("temp"), new SimpleTableSegmentBinderContext(Collections.singleton(new ColumnProjectionSegment(boundOrderColumn)))); ColumnSegment boundOrderItemColumn = new ColumnSegment(0, 0, new IdentifierValue("status")); - boundOrderItemColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), + boundOrderItemColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")), new IdentifierValue("t_order_item"), new IdentifierValue("status"))); tableBinderContexts.put(new CaseInsensitiveString("temp"), new SimpleTableSegmentBinderContext(Collections.singleton(new ColumnProjectionSegment(boundOrderItemColumn)))); SQLStatementBinderContext binderContext = @@ -118,11 +118,11 @@ void assertBindWithSameTableAliasAndSameProjection() { void assertBindWithSameTableAliasAndDifferentProjection() { Multimap tableBinderContexts = LinkedHashMultimap.create(); ColumnSegment boundOrderColumn = new ColumnSegment(0, 0, new IdentifierValue("order_id")); - boundOrderColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), + boundOrderColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")), new IdentifierValue("t_order"), new IdentifierValue("order_id"))); tableBinderContexts.put(new CaseInsensitiveString("temp"), new SimpleTableSegmentBinderContext(Collections.singleton(new ColumnProjectionSegment(boundOrderColumn)))); ColumnSegment boundOrderItemColumn = new ColumnSegment(0, 0, new IdentifierValue("status")); - boundOrderItemColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), + boundOrderItemColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")), new IdentifierValue("t_order_item"), new IdentifierValue("status"))); tableBinderContexts.put(new CaseInsensitiveString("temp"), new SimpleTableSegmentBinderContext(Collections.singleton(new ColumnProjectionSegment(boundOrderItemColumn)))); SQLStatementBinderContext binderContext = @@ -142,11 +142,11 @@ void assertBindWithSameTableAliasAndDifferentProjection() { void assertBindOwner() { Multimap tableBinderContexts = LinkedHashMultimap.create(); ColumnSegment boundOrderIdColumn = new ColumnSegment(0, 0, new IdentifierValue("order_id")); - boundOrderIdColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), + boundOrderIdColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")), new IdentifierValue("t_order"), new IdentifierValue("order_id"))); tableBinderContexts.put(new CaseInsensitiveString("t_order"), new SimpleTableSegmentBinderContext(Collections.singleton(new ColumnProjectionSegment(boundOrderIdColumn)))); ColumnSegment boundItemIdColumn = new ColumnSegment(0, 0, new IdentifierValue("item_id")); - boundItemIdColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"), + boundItemIdColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema")), new IdentifierValue("t_order_item"), new IdentifierValue("item_id"))); tableBinderContexts.put(new CaseInsensitiveString("t_order_item"), new SimpleTableSegmentBinderContext(Collections.singleton(new ColumnProjectionSegment(boundItemIdColumn)))); ColumnSegment columnSegment = new ColumnSegment(0, 0, new IdentifierValue("order_id")); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/SubquerySegmentBinderTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/SubquerySegmentBinderTest.java index d6fe501b167ac..96fa3d2005521 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/SubquerySegmentBinderTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/engine/segment/expression/type/SubquerySegmentBinderTest.java @@ -36,6 +36,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ProjectionsSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.ColumnSegmentBoundInfo; +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.value.identifier.IdentifierValue; @@ -71,8 +72,8 @@ void assertBind() { SQLStatementBinderContext sqlStatementBinderContext = new SQLStatementBinderContext( createMetaData(), "foo_db", TypedSPILoader.getService(DatabaseType.class, "FIXTURE"), Collections.emptySet()); ColumnSegment boundNameColumn = new ColumnSegment(7, 13, new IdentifierValue("user_id")); - boundNameColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo( - new IdentifierValue("foo_db"), new IdentifierValue("foo_db"), new IdentifierValue("t_order_item"), new IdentifierValue("user_id"))); + boundNameColumn.setColumnBoundInfo(new ColumnSegmentBoundInfo(new TableSegmentBoundInfo( + new IdentifierValue("foo_db"), new IdentifierValue("foo_db")), new IdentifierValue("t_order_item"), new IdentifierValue("user_id"))); sqlStatementBinderContext.getExternalTableBinderContexts().put(new CaseInsensitiveString("t_order_item"), new SimpleTableSegmentBinderContext(Collections.singleton(new ColumnProjectionSegment(boundNameColumn)))); Multimap outerTableBinderContexts = LinkedHashMultimap.create(); diff --git a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java index eff5feae3497e..7da8af0ac3531 100644 --- a/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java +++ b/jdbc/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java @@ -288,7 +288,6 @@ public boolean isValid(final int timeout) throws SQLException { @Override public String getSchema() { - // TODO return databaseName for now in getSchema(), the same as before return currentDatabaseName; } diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/generator/PipelineDDLGenerator.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/generator/PipelineDDLGenerator.java index 16b27e2929ecc..d56e58ebc63e2 100644 --- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/generator/PipelineDDLGenerator.java +++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/generator/PipelineDDLGenerator.java @@ -128,8 +128,8 @@ private String decorateActualSQL(final String databaseName, final String targetT return doDecorateActualTable(replaceMap, sql); } - private SQLStatementContext parseSQL(final String databaseName, final SQLParserEngine parserEngine, final String sql) { - return new SQLBindEngine(null, databaseName, new HintValueContext()).bind(parserEngine.parse(sql, true), Collections.emptyList()); + private SQLStatementContext parseSQL(final String currentDatabaseName, final SQLParserEngine parserEngine, final String sql) { + return new SQLBindEngine(null, currentDatabaseName, new HintValueContext()).bind(parserEngine.parse(sql, true), Collections.emptyList()); } private void appendFromIndexAndConstraint(final Map replaceMap, final String targetTableName, final SQLStatementContext sqlStatementContext) { diff --git a/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/context/SQLFederationExecutorContext.java b/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/context/SQLFederationExecutorContext.java index 8b24e5e401676..f1db1c7770680 100644 --- a/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/context/SQLFederationExecutorContext.java +++ b/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/context/SQLFederationExecutorContext.java @@ -31,7 +31,7 @@ @Getter public final class SQLFederationExecutorContext { - private final String databaseName; + private final String currentDatabaseName; private final String schemaName; diff --git a/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutor.java b/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutor.java index 1aa6915c35653..3a21637fc6bd2 100644 --- a/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutor.java +++ b/kernel/sql-federation/executor/src/main/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutor.java @@ -104,7 +104,7 @@ public final class EnumerableScanExecutor implements ScanExecutor { @Override public Enumerable execute(final ShardingSphereTable table, final ScanExecutorContext scanContext) { - String databaseName = executorContext.getDatabaseName(); + String databaseName = executorContext.getCurrentDatabaseName(); String schemaName = executorContext.getSchemaName(); DatabaseType databaseType = optimizerContext.getParserContext(databaseName).getDatabaseType(); if (new SystemDatabase(databaseType).getSystemSchemas().contains(schemaName)) { @@ -206,7 +206,7 @@ private QueryContext createQueryContext(final ShardingSphereMetaData metaData, f optimizerContext.getSqlParserRule().getSqlStatementCache(), optimizerContext.getSqlParserRule().getParseTreeCache()).parse(sql, useCache); List params = getParameters(sqlString.getParamIndexes()); HintValueContext hintValueContext = new HintValueContext(); - SQLStatementContext sqlStatementContext = new SQLBindEngine(metaData, executorContext.getDatabaseName(), hintValueContext).bind(sqlStatement, params); + SQLStatementContext sqlStatementContext = new SQLBindEngine(metaData, executorContext.getCurrentDatabaseName(), hintValueContext).bind(sqlStatement, params); return new QueryContext(sqlStatementContext, sql, params, hintValueContext, federationContext.getQueryContext().getConnectionContext(), metaData, useCache); } diff --git a/kernel/sql-federation/executor/src/test/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutorTest.java b/kernel/sql-federation/executor/src/test/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutorTest.java index 47c57ef397f0b..46de51b87818e 100644 --- a/kernel/sql-federation/executor/src/test/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutorTest.java +++ b/kernel/sql-federation/executor/src/test/java/org/apache/shardingsphere/sqlfederation/executor/enumerable/EnumerableScanExecutorTest.java @@ -51,7 +51,7 @@ void assertExecuteWithStatistics() { OptimizerContext optimizerContext = mock(OptimizerContext.class, RETURNS_DEEP_STUBS); when(optimizerContext.getParserContext(any()).getDatabaseType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "PostgreSQL")); SQLFederationExecutorContext executorContext = mock(SQLFederationExecutorContext.class); - when(executorContext.getDatabaseName()).thenReturn("db"); + when(executorContext.getCurrentDatabaseName()).thenReturn("db"); when(executorContext.getSchemaName()).thenReturn("pg_catalog"); ShardingSphereStatistics statistics = mock(ShardingSphereStatistics.class, RETURNS_DEEP_STUBS); ShardingSphereDatabaseData databaseData = mock(ShardingSphereDatabaseData.class, RETURNS_DEEP_STUBS); diff --git a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/generic/bound/ColumnSegmentBoundInfo.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/generic/bound/ColumnSegmentBoundInfo.java index a4b8a674379e9..e3a6f8175ba7e 100644 --- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/generic/bound/ColumnSegmentBoundInfo.java +++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/generic/bound/ColumnSegmentBoundInfo.java @@ -23,25 +23,41 @@ /** * Column segment bound info. */ -@Getter public final class ColumnSegmentBoundInfo { - private final IdentifierValue originalDatabase; - - private final IdentifierValue originalSchema; + private final TableSegmentBoundInfo tableBoundInfo; + @Getter private final IdentifierValue originalTable; + @Getter private final IdentifierValue originalColumn; public ColumnSegmentBoundInfo(final IdentifierValue originalColumn) { - this(null, null, null, originalColumn); + this(null, null, originalColumn); } - public ColumnSegmentBoundInfo(final IdentifierValue originalDatabase, final IdentifierValue originalSchema, final IdentifierValue originalTable, final IdentifierValue originalColumn) { - this.originalDatabase = null == originalDatabase ? new IdentifierValue("") : originalDatabase; - this.originalSchema = null == originalSchema ? new IdentifierValue("") : originalSchema; + public ColumnSegmentBoundInfo(final TableSegmentBoundInfo tableBoundInfo, final IdentifierValue originalTable, final IdentifierValue originalColumn) { + this.tableBoundInfo = null == tableBoundInfo ? new TableSegmentBoundInfo(null, null) : tableBoundInfo; this.originalTable = null == originalTable ? new IdentifierValue("") : originalTable; this.originalColumn = null == originalColumn ? new IdentifierValue("") : originalColumn; } + + /** + * Get original database. + * + * @return original database + */ + public IdentifierValue getOriginalDatabase() { + return tableBoundInfo.getOriginalDatabase(); + } + + /** + * Get original schema. + * + * @return original schema + */ + public IdentifierValue getOriginalSchema() { + return tableBoundInfo.getOriginalSchema(); + } } diff --git a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/generic/bound/TableSegmentBoundInfo.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/generic/bound/TableSegmentBoundInfo.java index 97ec0c7f8aaf5..e996a70993b98 100644 --- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/generic/bound/TableSegmentBoundInfo.java +++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/generic/bound/TableSegmentBoundInfo.java @@ -18,17 +18,20 @@ package org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound; import lombok.Getter; -import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; /** * Table name bound info. */ -@RequiredArgsConstructor @Getter public final class TableSegmentBoundInfo { private final IdentifierValue originalDatabase; private final IdentifierValue originalSchema; + + public TableSegmentBoundInfo(final IdentifierValue originalDatabase, final IdentifierValue originalSchema) { + this.originalDatabase = null == originalDatabase ? new IdentifierValue("") : originalDatabase; + this.originalSchema = null == originalSchema ? new IdentifierValue("") : originalSchema; + } } diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/PreviewExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/PreviewExecutor.java index 5b83098164cc4..ae9a7909c67a3 100644 --- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/PreviewExecutor.java +++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rul/PreviewExecutor.java @@ -91,7 +91,8 @@ public Collection getRows(final PreviewStatement sqlSta SQLStatement toBePreviewedStatement = metaData.getGlobalRuleMetaData().getSingleRule(SQLParserRule.class).getSQLParserEngine(database.getProtocolType()).parse(toBePreviewedSQL, false); HintValueContext hintValueContext = connectionContext.getQueryContext().getHintValueContext(); hintValueContext.setSkipMetadataValidate(true); - SQLStatementContext toBePreviewedStatementContext = new SQLBindEngine(metaData, database.getName(), hintValueContext).bind(toBePreviewedStatement, Collections.emptyList()); + String currentDatabaseName = connectionContext.getQueryContext().getConnectionContext().getCurrentDatabaseName().orElse(null); + SQLStatementContext toBePreviewedStatementContext = new SQLBindEngine(metaData, currentDatabaseName, hintValueContext).bind(toBePreviewedStatement, Collections.emptyList()); QueryContext queryContext = new QueryContext(toBePreviewedStatementContext, toBePreviewedSQL, Collections.emptyList(), hintValueContext, connectionContext.getQueryContext().getConnectionContext(), metaData); if (toBePreviewedStatementContext instanceof CursorAvailable && toBePreviewedStatementContext instanceof CursorAware) { diff --git a/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java b/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java index e7ffdbf1a348a..344a5ef30d4f5 100644 --- a/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java +++ b/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/fieldlist/MySQLComFieldListPacketExecutor.java @@ -63,18 +63,18 @@ public final class MySQLComFieldListPacketExecutor implements CommandExecutor { @Override public Collection execute() throws SQLException { - String databaseName = connectionSession.getCurrentDatabaseName(); - String sql = String.format(SQL, packet.getTable(), databaseName); + String currentDatabaseName = connectionSession.getCurrentDatabaseName(); + String sql = String.format(SQL, packet.getTable(), currentDatabaseName); MetaDataContexts metaDataContexts = ProxyContext.getInstance().getContextManager().getMetaDataContexts(); SQLParserRule sqlParserRule = metaDataContexts.getMetaData().getGlobalRuleMetaData().getSingleRule(SQLParserRule.class); SQLStatement sqlStatement = sqlParserRule.getSQLParserEngine(TypedSPILoader.getService(DatabaseType.class, "MySQL")).parse(sql, false); HintValueContext hintValueContext = SQLHintUtils.extractHint(sql); - SQLStatementContext sqlStatementContext = new SQLBindEngine(metaDataContexts.getMetaData(), databaseName, hintValueContext).bind(sqlStatement, Collections.emptyList()); + SQLStatementContext sqlStatementContext = new SQLBindEngine(metaDataContexts.getMetaData(), currentDatabaseName, hintValueContext).bind(sqlStatement, Collections.emptyList()); ProxyDatabaseConnectionManager databaseConnectionManager = connectionSession.getDatabaseConnectionManager(); QueryContext queryContext = new QueryContext(sqlStatementContext, sql, Collections.emptyList(), hintValueContext, connectionSession.getConnectionContext(), metaDataContexts.getMetaData()); databaseConnector = DatabaseConnectorFactory.getInstance().newInstance(queryContext, databaseConnectionManager, false); databaseConnector.execute(); - return createColumnDefinition41Packets(databaseName); + return createColumnDefinition41Packets(currentDatabaseName); } private Collection createColumnDefinition41Packets(final String databaseName) throws SQLException { diff --git a/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandler.java b/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandler.java index a4d76ebb4bd31..8341bcd1ea17c 100644 --- a/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandler.java +++ b/proxy/frontend/type/mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandler.java @@ -124,7 +124,7 @@ private List extractMultiStatements(final Pattern pattern, final String private QueryContext createQueryContext(final String sql, final SQLStatement sqlStatement) { HintValueContext hintValueContext = SQLHintUtils.extractHint(sql); SQLStatementContext sqlStatementContext = - new SQLBindEngine(metaDataContexts.getMetaData(), connectionSession.getUsedDatabaseName(), hintValueContext).bind(sqlStatement, Collections.emptyList()); + new SQLBindEngine(metaDataContexts.getMetaData(), connectionSession.getCurrentDatabaseName(), hintValueContext).bind(sqlStatement, Collections.emptyList()); return new QueryContext(sqlStatementContext, sql, Collections.emptyList(), hintValueContext, connectionSession.getConnectionContext(), metaDataContexts.getMetaData()); } @@ -170,7 +170,7 @@ private Collection createExecutionContexts() { private ExecutionContext createExecutionContext(final QueryContext queryContext) { RuleMetaData globalRuleMetaData = metaDataContexts.getMetaData().getGlobalRuleMetaData(); - ShardingSphereDatabase currentDatabase = metaDataContexts.getMetaData().getDatabase(connectionSession.getUsedDatabaseName()); + ShardingSphereDatabase currentDatabase = metaDataContexts.getMetaData().getDatabase(connectionSession.getCurrentDatabaseName()); SQLAuditEngine.audit(queryContext, globalRuleMetaData, currentDatabase); return new KernelProcessor().generateExecutionContext(queryContext, globalRuleMetaData, metaDataContexts.getMetaData().getProps()); } diff --git a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java index 37cb1228c4165..4f5e961bd0786 100644 --- a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java +++ b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java @@ -124,7 +124,7 @@ void assertIsUpdateResponse() throws SQLException, NoSuchFieldException, Illegal void assertExecuteMultiUpdateStatements() throws SQLException, NoSuchFieldException, IllegalAccessException { when(connectionSession.getAttributeMap().hasAttr(MySQLConstants.OPTION_MULTI_STATEMENTS_ATTRIBUTE_KEY)).thenReturn(true); when(connectionSession.getAttributeMap().attr(MySQLConstants.OPTION_MULTI_STATEMENTS_ATTRIBUTE_KEY).get()).thenReturn(0); - when(connectionSession.getUsedDatabaseName()).thenReturn("foo_db"); + when(connectionSession.getCurrentDatabaseName()).thenReturn("foo_db"); when(packet.getSQL()).thenReturn("update t set v=v+1 where id=1;update t set v=v+1 where id=2;update t set v=v+1 where id=3"); ContextManager contextManager = mock(ContextManager.class); MetaDataContexts metaDataContexts = mockMetaDataContexts(); @@ -142,7 +142,7 @@ void assertExecuteMultiUpdateStatements() throws SQLException, NoSuchFieldExcept void assertExecuteMultiInsertOnDuplicateKeyStatements() throws SQLException, NoSuchFieldException, IllegalAccessException { when(connectionSession.getAttributeMap().hasAttr(MySQLConstants.OPTION_MULTI_STATEMENTS_ATTRIBUTE_KEY)).thenReturn(true); when(connectionSession.getAttributeMap().attr(MySQLConstants.OPTION_MULTI_STATEMENTS_ATTRIBUTE_KEY).get()).thenReturn(0); - when(connectionSession.getUsedDatabaseName()).thenReturn("foo_db"); + when(connectionSession.getCurrentDatabaseName()).thenReturn("foo_db"); when(packet.getSQL()).thenReturn("insert into t (id, v) values(1,1) on duplicate key update v=2;insert into t (id, v) values(2,1) on duplicate key update v=3"); ContextManager contextManager = mock(ContextManager.class, RETURNS_DEEP_STUBS); MetaDataContexts metaDataContexts = mockMetaDataContexts(); diff --git a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandlerTest.java b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandlerTest.java index ef34bdf065b58..7d3e282e0796e 100644 --- a/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandlerTest.java +++ b/proxy/frontend/type/mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLMultiStatementsHandlerTest.java @@ -154,7 +154,7 @@ void assertExecuteWithMultiInsertOnDuplicateKey() throws SQLException { private ConnectionSession mockConnectionSession() throws SQLException { ConnectionSession result = mock(ConnectionSession.class, RETURNS_DEEP_STUBS); - when(result.getUsedDatabaseName()).thenReturn("foo_db"); + when(result.getCurrentDatabaseName()).thenReturn("foo_db"); Connection connection = mock(Connection.class, RETURNS_DEEP_STUBS); when(connection.getMetaData().getURL()).thenReturn("jdbc:mysql://127.0.0.1/db"); Statement statement = mock(Statement.class); diff --git a/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/extended/bind/OpenGaussComBatchBindExecutorTest.java b/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/extended/bind/OpenGaussComBatchBindExecutorTest.java index 9fb696ed64725..bfe13d152b8d6 100644 --- a/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/extended/bind/OpenGaussComBatchBindExecutorTest.java +++ b/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/command/query/extended/bind/OpenGaussComBatchBindExecutorTest.java @@ -105,7 +105,7 @@ void assertExecute() throws SQLException { private ConnectionSession mockConnectionSession() throws SQLException { ConnectionSession result = mock(ConnectionSession.class); when(result.getConnectionContext()).thenReturn(new ConnectionContext(Collections::emptySet)); - when(result.getUsedDatabaseName()).thenReturn("foo_db"); + when(result.getCurrentDatabaseName()).thenReturn("foo_db"); ConnectionContext connectionContext = mockConnectionContext(); when(result.getConnectionContext()).thenReturn(connectionContext); ProxyDatabaseConnectionManager databaseConnectionManager = mock(ProxyDatabaseConnectionManager.class); diff --git a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutor.java b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutor.java index 8fa4ff66c726b..09453c5df0225 100644 --- a/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutor.java +++ b/proxy/frontend/type/postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutor.java @@ -107,7 +107,8 @@ public PostgreSQLBatchedStatementsExecutor(final ConnectionSession connectionSes } private SQLStatementContext createSQLStatementContext(final List params, final HintValueContext hintValueContext) { - return new SQLBindEngine(metaDataContexts.getMetaData(), connectionSession.getUsedDatabaseName(), hintValueContext).bind(preparedStatement.getSqlStatementContext().getSqlStatement(), params); + return new SQLBindEngine(metaDataContexts.getMetaData(), connectionSession.getCurrentDatabaseName(), hintValueContext).bind(preparedStatement.getSqlStatementContext().getSqlStatement(), + params); } private void prepareForRestOfParametersSet(final Iterator> paramSetsIterator, final SQLStatementContext sqlStatementContext, final HintValueContext hintValueContext) { @@ -129,7 +130,7 @@ private QueryContext createQueryContext(final SQLStatementContext sqlStatementCo private ExecutionContext createExecutionContext(final QueryContext queryContext) { RuleMetaData globalRuleMetaData = metaDataContexts.getMetaData().getGlobalRuleMetaData(); - ShardingSphereDatabase currentDatabase = metaDataContexts.getMetaData().getDatabase(connectionSession.getUsedDatabaseName()); + ShardingSphereDatabase currentDatabase = metaDataContexts.getMetaData().getDatabase(connectionSession.getCurrentDatabaseName()); SQLAuditEngine.audit(queryContext, globalRuleMetaData, currentDatabase); return kernelProcessor.generateExecutionContext(queryContext, globalRuleMetaData, metaDataContexts.getMetaData().getProps()); } diff --git a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLAggregatedBatchedStatementsCommandExecutorTest.java b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLAggregatedBatchedStatementsCommandExecutorTest.java index 2bc45f283654f..cb813d381c6d9 100644 --- a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLAggregatedBatchedStatementsCommandExecutorTest.java +++ b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLAggregatedBatchedStatementsCommandExecutorTest.java @@ -113,7 +113,7 @@ private ConnectionSession mockConnectionSession() throws SQLException { ConnectionSession result = mock(ConnectionSession.class); SQLStatementContext sqlStatementContext = mock(InsertStatementContext.class); when(sqlStatementContext.getSqlStatement()).thenReturn(parserEngine.parse(SQL, false)); - when(result.getUsedDatabaseName()).thenReturn("foo_db"); + when(result.getCurrentDatabaseName()).thenReturn("foo_db"); ConnectionContext connectionContext = new ConnectionContext(Collections::emptySet); connectionContext.setCurrentDatabaseName("foo_db"); when(result.getConnectionContext()).thenReturn(connectionContext); diff --git a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutorTest.java b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutorTest.java index 41c0b317820d7..81943995dae02 100644 --- a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutorTest.java +++ b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/extended/PostgreSQLBatchedStatementsExecutorTest.java @@ -153,7 +153,7 @@ private ContextManager mockContextManager() { private ConnectionSession mockConnectionSession() { ConnectionSession result = mock(ConnectionSession.class); - when(result.getUsedDatabaseName()).thenReturn("db"); + when(result.getCurrentDatabaseName()).thenReturn("db"); when(result.getDatabaseConnectionManager()).thenReturn(databaseConnectionManager); when(result.getStatementManager()).thenReturn(backendStatement); ConnectionContext connectionContext = new ConnectionContext(Collections::emptySet); From 24bd2851ecd2f6a2d34663b3de0c8ea8011eebb1 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Thu, 12 Dec 2024 16:26:22 +0800 Subject: [PATCH 05/32] Refactor MetaDataContextsFactory (#34025) --- .../metadata/MetaDataContextsFactory.java | 69 ++++++++++--------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsFactory.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsFactory.java index f2b67e77511f6..aad43443acc48 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsFactory.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/MetaDataContextsFactory.java @@ -77,15 +77,13 @@ public final class MetaDataContextsFactory { * * @param persistService persist service * @param param context manager builder parameter - * @param computeNodeInstanceContext compute node instance context + * @param instanceContext compute node instance context * @return meta data contexts * @throws SQLException SQL exception */ public static MetaDataContexts create(final MetaDataPersistService persistService, final ContextManagerBuilderParameter param, - final ComputeNodeInstanceContext computeNodeInstanceContext) throws SQLException { - return persistService.getDatabaseMetaDataFacade().getDatabase().loadAllDatabaseNames().isEmpty() - ? createByLocal(persistService, param, computeNodeInstanceContext) - : createByRepository(persistService, param, computeNodeInstanceContext); + final ComputeNodeInstanceContext instanceContext) throws SQLException { + return isCreateByLocal(persistService) ? createByLocal(persistService, param, instanceContext) : createByRepository(persistService, param, instanceContext); } /** @@ -99,34 +97,37 @@ public static MetaDataContexts create(final MetaDataPersistService persistServic return new MetaDataContexts(metaData, initStatistics(persistService, metaData)); } + private static boolean isCreateByLocal(final MetaDataPersistService persistService) { + return persistService.getDatabaseMetaDataFacade().getDatabase().loadAllDatabaseNames().isEmpty(); + } + private static MetaDataContexts createByLocal(final MetaDataPersistService persistService, final ContextManagerBuilderParameter param, - final ComputeNodeInstanceContext computeNodeInstanceContext) throws SQLException { + final ComputeNodeInstanceContext instanceContext) throws SQLException { Map effectiveDatabaseConfigs = param.getDatabaseConfigs(); Collection globalRuleConfigs; - if (computeNodeInstanceContext.getModeConfiguration().isCluster()) { - globalRuleConfigs = new RuleConfigurationPersistDecorateEngine(computeNodeInstanceContext).tryRestore(param.getGlobalRuleConfigs()); + if (instanceContext.getModeConfiguration().isCluster()) { + globalRuleConfigs = new RuleConfigurationPersistDecorateEngine(instanceContext).tryRestore(param.getGlobalRuleConfigs()); param.getGlobalRuleConfigs().clear(); param.getGlobalRuleConfigs().addAll(globalRuleConfigs); } else { globalRuleConfigs = param.getGlobalRuleConfigs(); } ConfigurationProperties props = new ConfigurationProperties(param.getProps()); - Map databases = ExternalMetaDataFactory.create(effectiveDatabaseConfigs, props, computeNodeInstanceContext); + Map databases = ExternalMetaDataFactory.create(effectiveDatabaseConfigs, props, instanceContext); MetaDataContexts result = newMetaDataContexts(persistService, param, globalRuleConfigs, databases, props); - persistDatabaseConfigurations(result, param, persistService, computeNodeInstanceContext); + persistDatabaseConfigurations(result, param, persistService, instanceContext); persistMetaData(result, persistService); return result; } - private static MetaDataContexts createByRepository(final MetaDataPersistService persistService, final ContextManagerBuilderParameter param, - final ComputeNodeInstanceContext computeNodeInstanceContext) { - Map effectiveDatabaseConfigs = - createEffectiveDatabaseConfigurations(getDatabaseNames(computeNodeInstanceContext, param.getDatabaseConfigs(), persistService), param.getDatabaseConfigs(), persistService); + private static MetaDataContexts createByRepository(final MetaDataPersistService persistService, final ContextManagerBuilderParameter param, final ComputeNodeInstanceContext instanceContext) { + Map effectiveDatabaseConfigs = createEffectiveDatabaseConfigurations( + getDatabaseNames(instanceContext, param.getDatabaseConfigs(), persistService), param.getDatabaseConfigs(), persistService); Collection globalRuleConfigs = persistService.getGlobalRuleService().load(); ConfigurationProperties props = new ConfigurationProperties(persistService.getPropsService().load()); - Map databases = InternalMetaDataFactory.create(persistService, effectiveDatabaseConfigs, props, computeNodeInstanceContext); + Map databases = InternalMetaDataFactory.create(persistService, effectiveDatabaseConfigs, props, instanceContext); MetaDataContexts result = newMetaDataContexts(persistService, param, globalRuleConfigs, databases, props); - restoreRules(result, computeNodeInstanceContext); + restoreRules(result, instanceContext); return result; } @@ -141,9 +142,9 @@ private static MetaDataContexts newMetaDataContexts(final MetaDataPersistService return new MetaDataContexts(shardingSphereMetaData, shardingSphereStatistics); } - private static Collection getDatabaseNames(final ComputeNodeInstanceContext computeNodeInstanceContext, + private static Collection getDatabaseNames(final ComputeNodeInstanceContext instanceContext, final Map databaseConfigs, final MetaDataPersistService persistService) { - return computeNodeInstanceContext.getInstance().getMetaData() instanceof JDBCInstanceMetaData + return instanceContext.getInstance().getMetaData() instanceof JDBCInstanceMetaData ? databaseConfigs.keySet() : persistService.getDatabaseMetaDataFacade().getDatabase().loadAllDatabaseNames(); } @@ -210,8 +211,8 @@ private static void useLoadedToReplaceInitBySchemaData(final ShardingSphereSchem } @SuppressWarnings({"unchecked", "rawtypes"}) - private static void restoreRules(final MetaDataContexts metaDataContexts, final ComputeNodeInstanceContext computeNodeInstanceContext) { - if (!computeNodeInstanceContext.getModeConfiguration().isCluster()) { + private static void restoreRules(final MetaDataContexts metaDataContexts, final ComputeNodeInstanceContext instanceContext) { + if (!instanceContext.getModeConfiguration().isCluster()) { return; } for (RuleConfigurationPersistDecorator each : ShardingSphereServiceLoader.getServiceInstances(RuleConfigurationPersistDecorator.class)) { @@ -225,8 +226,8 @@ private static void restoreRules(final MetaDataContexts metaDataContexts, final } private static void persistDatabaseConfigurations(final MetaDataContexts metadataContexts, final ContextManagerBuilderParameter param, final MetaDataPersistService persistService, - final ComputeNodeInstanceContext computeNodeInstanceContext) { - RuleConfigurationPersistDecorateEngine ruleConfigPersistDecorateEngine = new RuleConfigurationPersistDecorateEngine(computeNodeInstanceContext); + final ComputeNodeInstanceContext instanceContext) { + RuleConfigurationPersistDecorateEngine ruleConfigPersistDecorateEngine = new RuleConfigurationPersistDecorateEngine(instanceContext); persistService.persistGlobalRuleConfiguration(ruleConfigPersistDecorateEngine.decorate(metadataContexts.getMetaData().getGlobalRuleMetaData().getConfigurations()), param.getProps()); for (Entry entry : param.getDatabaseConfigs().entrySet()) { String databaseName = entry.getKey(); @@ -260,15 +261,15 @@ private static void persistMetaData(final MetaDataContexts metaDataContexts, fin * @param switchingResource switching resource * @param originalMetaDataContexts original meta data contexts * @param metaDataPersistService meta data persist service - * @param computeNodeInstanceContext compute node instance context + * @param instanceContext compute node instance context * @return meta data contexts * @throws SQLException SQL exception */ public static MetaDataContexts createBySwitchResource(final String databaseName, final boolean internalLoadMetaData, final SwitchingResource switchingResource, final MetaDataContexts originalMetaDataContexts, final MetaDataPersistService metaDataPersistService, - final ComputeNodeInstanceContext computeNodeInstanceContext) throws SQLException { + final ComputeNodeInstanceContext instanceContext) throws SQLException { ShardingSphereDatabase changedDatabase = createChangedDatabase( - databaseName, internalLoadMetaData, switchingResource, null, originalMetaDataContexts, metaDataPersistService, computeNodeInstanceContext); + databaseName, internalLoadMetaData, switchingResource, null, originalMetaDataContexts, metaDataPersistService, instanceContext); ConfigurationProperties props = originalMetaDataContexts.getMetaData().getProps(); ShardingSphereMetaData clonedMetaData = cloneMetaData(originalMetaDataContexts.getMetaData(), changedDatabase); RuleMetaData changedGlobalMetaData = new RuleMetaData( @@ -285,15 +286,15 @@ public static MetaDataContexts createBySwitchResource(final String databaseName, * @param ruleConfigs rule configs * @param originalMetaDataContexts original meta data contexts * @param metaDataPersistService meta data persist service - * @param computeNodeInstanceContext compute node instance context + * @param instanceContext compute node instance context * @return meta data contexts * @throws SQLException SQL exception */ public static MetaDataContexts createByAlterRule(final String databaseName, final boolean internalLoadMetaData, final Collection ruleConfigs, final MetaDataContexts originalMetaDataContexts, final MetaDataPersistService metaDataPersistService, - final ComputeNodeInstanceContext computeNodeInstanceContext) throws SQLException { + final ComputeNodeInstanceContext instanceContext) throws SQLException { ShardingSphereDatabase changedDatabase = createChangedDatabase( - databaseName, internalLoadMetaData, null, ruleConfigs, originalMetaDataContexts, metaDataPersistService, computeNodeInstanceContext); + databaseName, internalLoadMetaData, null, ruleConfigs, originalMetaDataContexts, metaDataPersistService, instanceContext); ShardingSphereMetaData clonedMetaData = cloneMetaData(originalMetaDataContexts.getMetaData(), changedDatabase); ConfigurationProperties props = originalMetaDataContexts.getMetaData().getProps(); RuleMetaData changedGlobalMetaData = new RuleMetaData( @@ -318,7 +319,7 @@ private static ShardingSphereMetaData cloneMetaData(final ShardingSphereMetaData * @param ruleConfigs rule configurations * @param originalMetaDataContext original meta data contexts * @param metaDataPersistService meta data persist service - * @param computeNodeInstanceContext compute node instance context + * @param instanceContext compute node instance context * @return changed database * @throws SQLException SQL exception */ @@ -326,22 +327,22 @@ public static ShardingSphereDatabase createChangedDatabase(final String database final SwitchingResource switchingResource, final Collection ruleConfigs, final MetaDataContexts originalMetaDataContext, final MetaDataPersistService metaDataPersistService, - final ComputeNodeInstanceContext computeNodeInstanceContext) throws SQLException { + final ComputeNodeInstanceContext instanceContext) throws SQLException { ResourceMetaData effectiveResourceMetaData = getEffectiveResourceMetaData(originalMetaDataContext.getMetaData().getDatabase(databaseName), switchingResource); Collection toBeCreatedRuleConfigs = null == ruleConfigs ? originalMetaDataContext.getMetaData().getDatabase(databaseName).getRuleMetaData().getConfigurations() : ruleConfigs; DatabaseConfiguration toBeCreatedDatabaseConfig = getDatabaseConfiguration(effectiveResourceMetaData, switchingResource, toBeCreatedRuleConfigs); return createChangedDatabase(originalMetaDataContext.getMetaData().getDatabase(databaseName).getName(), internalLoadMetaData, - metaDataPersistService, toBeCreatedDatabaseConfig, originalMetaDataContext.getMetaData().getProps(), computeNodeInstanceContext); + metaDataPersistService, toBeCreatedDatabaseConfig, originalMetaDataContext.getMetaData().getProps(), instanceContext); } private static ShardingSphereDatabase createChangedDatabase(final String databaseName, final boolean internalLoadMetaData, final MetaDataPersistService persistService, final DatabaseConfiguration databaseConfig, final ConfigurationProperties props, - final ComputeNodeInstanceContext computeNodeInstanceContext) throws SQLException { + final ComputeNodeInstanceContext instanceContext) throws SQLException { return internalLoadMetaData - ? InternalMetaDataFactory.create(databaseName, persistService, databaseConfig, props, computeNodeInstanceContext) - : ExternalMetaDataFactory.create(databaseName, databaseConfig, props, computeNodeInstanceContext); + ? InternalMetaDataFactory.create(databaseName, persistService, databaseConfig, props, instanceContext) + : ExternalMetaDataFactory.create(databaseName, databaseConfig, props, instanceContext); } private static ResourceMetaData getEffectiveResourceMetaData(final ShardingSphereDatabase database, final SwitchingResource resource) { From bb101dcf708f3be358b4c05719bb6f21b1121005 Mon Sep 17 00:00:00 2001 From: King Song <42347717+kid0510z@users.noreply.github.com> Date: Thu, 12 Dec 2024 17:12:02 +0800 Subject: [PATCH 06/32] Fix Windows startup script runs in the background and outputs log files (#34021) * Fix Windows startup script runs in the background and outputs log files * Add `2>&1` for start.bat --- distribution/proxy/src/main/resources/bin/start.bat | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/distribution/proxy/src/main/resources/bin/start.bat b/distribution/proxy/src/main/resources/bin/start.bat index 6a890b9f472d8..e1b8f8f97b010 100644 --- a/distribution/proxy/src/main/resources/bin/start.bat +++ b/distribution/proxy/src/main/resources/bin/start.bat @@ -19,6 +19,14 @@ cd %~dp0 +set LOGS_DIR=..\logs + +if not exist %LOGS_DIR% ( + mkdir %LOGS_DIR% +) + +set STDOUT_FILE=%LOGS_DIR%\stdout.log + set SERVER_NAME=ShardingSphere-Proxy set CLASS_PATH="..;..\lib\*;..\ext-lib\*" @@ -81,7 +89,7 @@ if %int_version% == 8 ( echo Starting the %SERVER_NAME% ... -java -server -Xmx2g -Xms2g -Xmn1g -Xss1m -XX:AutoBoxCacheMax=4096 -XX:+DisableExplicitGC -XX:LargePageSizeInBytes=128m %VERSION_OPTS% -Dfile.encoding=UTF-8 -Dio.netty.leakDetection.level=DISABLED -classpath %CLASS_PATH% %MAIN_CLASS% +javaw -server -Xmx2g -Xms2g -Xmn1g -Xss1m -XX:AutoBoxCacheMax=4096 -XX:+DisableExplicitGC -XX:LargePageSizeInBytes=128m %VERSION_OPTS% -Dfile.encoding=UTF-8 -Dio.netty.leakDetection.level=DISABLED -classpath %CLASS_PATH% %MAIN_CLASS% >> %STDOUT_FILE% 2>&1 goto exit From d0adaa8349c5690f963edee89fbea247320f5ffa Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Thu, 12 Dec 2024 18:06:55 +0800 Subject: [PATCH 07/32] Adjust package of cluster-mode-core module (#34027) * Move GlobalLockPersistService to persist package * Adjust package of cluster-mode-core module --- .../collect/StatisticsCollectJob.java | 2 +- .../cluster/ClusterContextManagerBuilder.java | 8 +++--- ...ClusterDeliverEventSubscriberRegistry.java | 3 +-- .../DeliverQualifiedDataSourceSubscriber.java | 2 +- .../ClusterStateDispatchEventBuilder.java | 2 +- ...ComputeNodeOnlineDispatchEventBuilder.java | 2 +- .../ComputeNodeStateDispatchEventBuilder.java | 2 +- .../builder/DispatchEventBuilder.java | 2 +- .../GlobalRuleDispatchEventBuilder.java | 2 +- .../KillProcessDispatchEventBuilder.java | 2 +- .../ListenerAssistedDispatchEventBuilder.java | 2 +- .../PropertiesDispatchEventBuilder.java | 2 +- ...alifiedDataSourceDispatchEventBuilder.java | 2 +- ...hardingSphereDataDispatchEventBuilder.java | 2 +- .../ShowProcessListDispatchEventBuilder.java | 2 +- .../DataChangedEventListenerRegistry.java | 4 +-- .../DatabaseMetaDataChangedListener.java | 2 +- .../GlobalMetaDataChangedListener.java | 4 +-- .../subscriber}/CacheEvictedSubscriber.java | 2 +- ...lusterDispatchEventSubscriberRegistry.java | 14 +--------- .../ComputeNodeStateSubscriber.java | 2 +- .../DatabaseDataChangedSubscriber.java | 2 +- ...lobalRuleConfigurationEventSubscriber.java | 2 +- .../ListenerAssistedSubscriber.java | 6 ++--- .../MetaDataChangedSubscriber.java | 4 +-- .../ProcessListChangedSubscriber.java | 2 +- .../PropertiesEventSubscriber.java | 2 +- .../QualifiedDataSourceSubscriber.java | 2 +- .../RuleItemChangedSubscriber.java | 2 +- .../subscriber}/StateChangedSubscriber.java | 2 +- .../StorageUnitEventSubscriber.java | 2 +- .../GlobalLockPersistService.java | 2 +- ...cluster.event.builder.DispatchEventBuilder | 27 ------------------- ...vent.dispatch.builder.DispatchEventBuilder | 27 +++++++++++++++++++ ...iverQualifiedDataSourceSubscriberTest.java | 2 +- .../ClusterStateDispatchEventBuilderTest.java | 2 +- ...uteNodeOnlineDispatchEventBuilderTest.java | 2 +- ...puteNodeStateDispatchEventBuilderTest.java | 2 +- .../GlobalRuleDispatchEventBuilderTest.java | 2 +- .../KillProcessDispatchEventBuilderTest.java | 2 +- ...tenerAssistedDispatchEventBuilderTest.java | 2 +- .../PropertiesDispatchEventBuilderTest.java | 2 +- ...iedDataSourceDispatchEventBuilderTest.java | 2 +- ...ingSphereDataDispatchEventBuilderTest.java | 2 +- ...owProcessListDispatchEventBuilderTest.java | 2 +- .../DataChangedEventListenerRegistryTest.java | 2 +- .../DatabaseMetaDataChangedListenerTest.java | 2 +- .../GlobalMetaDataChangedListenerTest.java | 4 +-- .../CacheEvictedSubscriberTest.java | 2 +- .../ComputeNodeStateSubscriberTest.java | 2 +- .../DatabaseDataChangedSubscriberTest.java | 2 +- ...lRuleConfigurationEventSubscriberTest.java | 2 +- .../ListenerAssistedSubscriberTest.java | 2 +- .../MetaDataChangedSubscriberTest.java | 2 +- .../ProcessListChangedSubscriberTest.java | 2 +- .../PropertiesEventSubscriberTest.java | 2 +- .../QualifiedDataSourceSubscriberTest.java | 2 +- .../RuleItemChangedSubscriberTest.java | 2 +- .../StateChangedSubscriberTest.java | 2 +- .../StorageUnitEventSubscriberTest.java | 2 +- .../GlobalLockPersistServiceTest.java | 2 +- 61 files changed, 95 insertions(+), 108 deletions(-) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/{subscriber/registry => deliver/subscriber}/ClusterDeliverEventSubscriberRegistry.java (88%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/{subscriber/deliver => deliver/subscriber}/DeliverQualifiedDataSourceSubscriber.java (95%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/{ => dispatch}/builder/ClusterStateDispatchEventBuilder.java (96%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/{ => dispatch}/builder/ComputeNodeOnlineDispatchEventBuilder.java (97%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/{ => dispatch}/builder/ComputeNodeStateDispatchEventBuilder.java (97%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/{ => dispatch}/builder/DispatchEventBuilder.java (95%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/{ => dispatch}/builder/GlobalRuleDispatchEventBuilder.java (96%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/{ => dispatch}/builder/KillProcessDispatchEventBuilder.java (97%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/{ => dispatch}/builder/ListenerAssistedDispatchEventBuilder.java (97%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/{ => dispatch}/builder/PropertiesDispatchEventBuilder.java (95%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/{ => dispatch}/builder/QualifiedDataSourceDispatchEventBuilder.java (97%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/{ => dispatch}/builder/ShardingSphereDataDispatchEventBuilder.java (98%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/{ => dispatch}/builder/ShowProcessListDispatchEventBuilder.java (97%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/{ => event/dispatch}/listener/DataChangedEventListenerRegistry.java (93%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/{ => event/dispatch}/listener/DatabaseMetaDataChangedListener.java (99%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/{ => event/dispatch}/listener/GlobalMetaDataChangedListener.java (89%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/{subscriber/dispatch => dispatch/subscriber}/CacheEvictedSubscriber.java (94%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/{subscriber/registry => dispatch/subscriber}/ClusterDispatchEventSubscriberRegistry.java (60%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/{subscriber/dispatch => dispatch/subscriber}/ComputeNodeStateSubscriber.java (97%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/{subscriber/dispatch => dispatch/subscriber}/DatabaseDataChangedSubscriber.java (98%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/{subscriber/dispatch => dispatch/subscriber}/GlobalRuleConfigurationEventSubscriber.java (97%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/{subscriber/dispatch => dispatch/subscriber}/ListenerAssistedSubscriber.java (93%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/{subscriber/dispatch => dispatch/subscriber}/MetaDataChangedSubscriber.java (97%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/{subscriber/dispatch => dispatch/subscriber}/ProcessListChangedSubscriber.java (98%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/{subscriber/dispatch => dispatch/subscriber}/PropertiesEventSubscriber.java (96%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/{subscriber/dispatch => dispatch/subscriber}/QualifiedDataSourceSubscriber.java (96%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/{subscriber/dispatch => dispatch/subscriber}/RuleItemChangedSubscriber.java (96%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/{subscriber/dispatch => dispatch/subscriber}/StateChangedSubscriber.java (95%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/{subscriber/dispatch => dispatch/subscriber}/StorageUnitEventSubscriber.java (98%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/{lock => persist}/GlobalLockPersistService.java (96%) delete mode 100644 mode/type/cluster/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.event.builder.DispatchEventBuilder create mode 100644 mode/type/cluster/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.DispatchEventBuilder rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/{subscriber/deliver => deliver/subscriber}/DeliverQualifiedDataSourceSubscriberTest.java (96%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/{ => dispatch}/builder/ClusterStateDispatchEventBuilderTest.java (96%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/{ => dispatch}/builder/ComputeNodeOnlineDispatchEventBuilderTest.java (97%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/{ => dispatch}/builder/ComputeNodeStateDispatchEventBuilderTest.java (98%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/{ => dispatch}/builder/GlobalRuleDispatchEventBuilderTest.java (96%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/{ => dispatch}/builder/KillProcessDispatchEventBuilderTest.java (97%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/{ => dispatch}/builder/ListenerAssistedDispatchEventBuilderTest.java (97%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/{ => dispatch}/builder/PropertiesDispatchEventBuilderTest.java (96%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/{ => dispatch}/builder/QualifiedDataSourceDispatchEventBuilderTest.java (97%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/{ => dispatch}/builder/ShardingSphereDataDispatchEventBuilderTest.java (99%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/{ => dispatch}/builder/ShowProcessListDispatchEventBuilderTest.java (97%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/{ => event/dispatch}/listener/DataChangedEventListenerRegistryTest.java (96%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/{ => event/dispatch}/listener/DatabaseMetaDataChangedListenerTest.java (99%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/{ => event/dispatch}/listener/GlobalMetaDataChangedListenerTest.java (93%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/{subscriber/dispatch => dispatch/subscriber}/CacheEvictedSubscriberTest.java (95%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/{subscriber/dispatch => dispatch/subscriber}/ComputeNodeStateSubscriberTest.java (97%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/{subscriber/dispatch => dispatch/subscriber}/DatabaseDataChangedSubscriberTest.java (98%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/{subscriber/dispatch => dispatch/subscriber}/GlobalRuleConfigurationEventSubscriberTest.java (96%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/{subscriber/dispatch => dispatch/subscriber}/ListenerAssistedSubscriberTest.java (97%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/{subscriber/dispatch => dispatch/subscriber}/MetaDataChangedSubscriberTest.java (98%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/{subscriber/dispatch => dispatch/subscriber}/ProcessListChangedSubscriberTest.java (98%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/{subscriber/dispatch => dispatch/subscriber}/PropertiesEventSubscriberTest.java (96%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/{subscriber/dispatch => dispatch/subscriber}/QualifiedDataSourceSubscriberTest.java (97%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/{subscriber/dispatch => dispatch/subscriber}/RuleItemChangedSubscriberTest.java (96%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/{subscriber/dispatch => dispatch/subscriber}/StateChangedSubscriberTest.java (95%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/{subscriber/dispatch => dispatch/subscriber}/StorageUnitEventSubscriberTest.java (97%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/{lock => persist}/GlobalLockPersistServiceTest.java (97%) diff --git a/kernel/schedule/core/src/main/java/org/apache/shardingsphere/schedule/core/job/statistics/collect/StatisticsCollectJob.java b/kernel/schedule/core/src/main/java/org/apache/shardingsphere/schedule/core/job/statistics/collect/StatisticsCollectJob.java index 2cad23628c05c..57127daecd50d 100644 --- a/kernel/schedule/core/src/main/java/org/apache/shardingsphere/schedule/core/job/statistics/collect/StatisticsCollectJob.java +++ b/kernel/schedule/core/src/main/java/org/apache/shardingsphere/schedule/core/job/statistics/collect/StatisticsCollectJob.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.elasticjob.simple.job.SimpleJob; import org.apache.shardingsphere.mode.lock.GlobalLockContext; import org.apache.shardingsphere.mode.manager.ContextManager; -import org.apache.shardingsphere.mode.manager.cluster.lock.GlobalLockPersistService; +import org.apache.shardingsphere.mode.manager.cluster.persist.GlobalLockPersistService; import org.apache.shardingsphere.mode.metadata.refresher.ShardingSphereStatisticsRefreshEngine; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; import org.apache.shardingsphere.mode.spi.PersistRepository; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java index 2f33885699dea..461e7ac6bdca4 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java @@ -31,11 +31,11 @@ import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.manager.ContextManagerBuilder; import org.apache.shardingsphere.mode.manager.ContextManagerBuilderParameter; -import org.apache.shardingsphere.mode.manager.cluster.event.subscriber.registry.ClusterDeliverEventSubscriberRegistry; -import org.apache.shardingsphere.mode.manager.cluster.event.subscriber.registry.ClusterDispatchEventSubscriberRegistry; +import org.apache.shardingsphere.mode.manager.cluster.event.deliver.subscriber.ClusterDeliverEventSubscriberRegistry; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.ClusterDispatchEventSubscriberRegistry; import org.apache.shardingsphere.mode.manager.cluster.exception.MissingRequiredClusterRepositoryConfigurationException; -import org.apache.shardingsphere.mode.manager.cluster.listener.DataChangedEventListenerRegistry; -import org.apache.shardingsphere.mode.manager.cluster.lock.GlobalLockPersistService; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener.DataChangedEventListenerRegistry; +import org.apache.shardingsphere.mode.manager.cluster.persist.GlobalLockPersistService; import org.apache.shardingsphere.mode.manager.cluster.workerid.ClusterWorkerIdGenerator; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/registry/ClusterDeliverEventSubscriberRegistry.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/ClusterDeliverEventSubscriberRegistry.java similarity index 88% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/registry/ClusterDeliverEventSubscriberRegistry.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/ClusterDeliverEventSubscriberRegistry.java index da02b05f300c6..06ce77c27b084 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/registry/ClusterDeliverEventSubscriberRegistry.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/ClusterDeliverEventSubscriberRegistry.java @@ -15,12 +15,11 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.subscriber.registry; +package org.apache.shardingsphere.mode.manager.cluster.event.deliver.subscriber; import lombok.Getter; import org.apache.shardingsphere.infra.util.eventbus.EventSubscriber; import org.apache.shardingsphere.mode.manager.ContextManager; -import org.apache.shardingsphere.mode.manager.cluster.event.subscriber.deliver.DeliverQualifiedDataSourceSubscriber; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; import java.util.Collection; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/deliver/DeliverQualifiedDataSourceSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/DeliverQualifiedDataSourceSubscriber.java similarity index 95% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/deliver/DeliverQualifiedDataSourceSubscriber.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/DeliverQualifiedDataSourceSubscriber.java index c7c78be8b0228..374867a36ed0c 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/deliver/DeliverQualifiedDataSourceSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/DeliverQualifiedDataSourceSubscriber.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.subscriber.deliver; +package org.apache.shardingsphere.mode.manager.cluster.event.deliver.subscriber; import com.google.common.eventbus.Subscribe; import lombok.RequiredArgsConstructor; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ClusterStateDispatchEventBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ClusterStateDispatchEventBuilder.java similarity index 96% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ClusterStateDispatchEventBuilder.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ClusterStateDispatchEventBuilder.java index 24026055faa3b..f59b38bd104d8 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ClusterStateDispatchEventBuilder.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ClusterStateDispatchEventBuilder.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; import org.apache.shardingsphere.infra.state.cluster.ClusterState; import org.apache.shardingsphere.metadata.persist.node.StatesNode; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ComputeNodeOnlineDispatchEventBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ComputeNodeOnlineDispatchEventBuilder.java similarity index 97% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ComputeNodeOnlineDispatchEventBuilder.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ComputeNodeOnlineDispatchEventBuilder.java index 6e6b7dc9e3248..fe4c2e8c9572b 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ComputeNodeOnlineDispatchEventBuilder.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ComputeNodeOnlineDispatchEventBuilder.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; import org.apache.shardingsphere.infra.instance.ComputeNodeData; import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ComputeNodeStateDispatchEventBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ComputeNodeStateDispatchEventBuilder.java similarity index 97% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ComputeNodeStateDispatchEventBuilder.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ComputeNodeStateDispatchEventBuilder.java index a5cea94fc1758..b734e010986b4 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ComputeNodeStateDispatchEventBuilder.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ComputeNodeStateDispatchEventBuilder.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; import com.google.common.base.Strings; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/DispatchEventBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/DispatchEventBuilder.java similarity index 95% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/DispatchEventBuilder.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/DispatchEventBuilder.java index eee63e1ec5681..1ea4ab224ae46 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/DispatchEventBuilder.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/DispatchEventBuilder.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI; import org.apache.shardingsphere.mode.event.DataChangedEvent; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/GlobalRuleDispatchEventBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/GlobalRuleDispatchEventBuilder.java similarity index 96% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/GlobalRuleDispatchEventBuilder.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/GlobalRuleDispatchEventBuilder.java index 4510eb833c42a..cad0a049df7f0 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/GlobalRuleDispatchEventBuilder.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/GlobalRuleDispatchEventBuilder.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; import org.apache.shardingsphere.metadata.persist.node.GlobalNode; import org.apache.shardingsphere.mode.event.DataChangedEvent; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/KillProcessDispatchEventBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/KillProcessDispatchEventBuilder.java similarity index 97% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/KillProcessDispatchEventBuilder.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/KillProcessDispatchEventBuilder.java index fbbf115f8f2e6..ed4230257ec5d 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/KillProcessDispatchEventBuilder.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/KillProcessDispatchEventBuilder.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; import org.apache.shardingsphere.metadata.persist.node.ComputeNode; import org.apache.shardingsphere.mode.event.DataChangedEvent; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ListenerAssistedDispatchEventBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ListenerAssistedDispatchEventBuilder.java similarity index 97% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ListenerAssistedDispatchEventBuilder.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ListenerAssistedDispatchEventBuilder.java index cbc54c00c1d8a..2ef539e489743 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ListenerAssistedDispatchEventBuilder.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ListenerAssistedDispatchEventBuilder.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; import org.apache.shardingsphere.metadata.persist.node.StatesNode; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/PropertiesDispatchEventBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/PropertiesDispatchEventBuilder.java similarity index 95% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/PropertiesDispatchEventBuilder.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/PropertiesDispatchEventBuilder.java index be79c1996387a..6f6dc31576dcc 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/PropertiesDispatchEventBuilder.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/PropertiesDispatchEventBuilder.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; import org.apache.shardingsphere.metadata.persist.node.GlobalNode; import org.apache.shardingsphere.mode.event.DataChangedEvent; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/QualifiedDataSourceDispatchEventBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/QualifiedDataSourceDispatchEventBuilder.java similarity index 97% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/QualifiedDataSourceDispatchEventBuilder.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/QualifiedDataSourceDispatchEventBuilder.java index 3ccab9bd6f7ec..5c2cad7adf1fc 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/QualifiedDataSourceDispatchEventBuilder.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/QualifiedDataSourceDispatchEventBuilder.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; import com.google.common.base.Strings; import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ShardingSphereDataDispatchEventBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ShardingSphereDataDispatchEventBuilder.java similarity index 98% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ShardingSphereDataDispatchEventBuilder.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ShardingSphereDataDispatchEventBuilder.java index 30bde19a65af7..5c599450b24a7 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ShardingSphereDataDispatchEventBuilder.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ShardingSphereDataDispatchEventBuilder.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; import com.google.common.base.Strings; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ShowProcessListDispatchEventBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ShowProcessListDispatchEventBuilder.java similarity index 97% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ShowProcessListDispatchEventBuilder.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ShowProcessListDispatchEventBuilder.java index 3fc29de65c917..69f0d72150658 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ShowProcessListDispatchEventBuilder.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ShowProcessListDispatchEventBuilder.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; import org.apache.shardingsphere.metadata.persist.node.ComputeNode; import org.apache.shardingsphere.mode.event.DataChangedEvent; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/listener/DataChangedEventListenerRegistry.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/DataChangedEventListenerRegistry.java similarity index 93% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/listener/DataChangedEventListenerRegistry.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/DataChangedEventListenerRegistry.java index ff1e5ef58ad57..6fbc64978a7fb 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/listener/DataChangedEventListenerRegistry.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/DataChangedEventListenerRegistry.java @@ -15,13 +15,13 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.listener; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener; import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader; import org.apache.shardingsphere.infra.util.eventbus.EventBusContext; import org.apache.shardingsphere.metadata.persist.node.DatabaseMetaDataNode; import org.apache.shardingsphere.mode.manager.ContextManager; -import org.apache.shardingsphere.mode.manager.cluster.event.builder.DispatchEventBuilder; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.DispatchEventBuilder; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; import java.util.Collection; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/listener/DatabaseMetaDataChangedListener.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/DatabaseMetaDataChangedListener.java similarity index 99% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/listener/DatabaseMetaDataChangedListener.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/DatabaseMetaDataChangedListener.java index ab7c363adb19a..14bf9d21c16d7 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/listener/DatabaseMetaDataChangedListener.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/DatabaseMetaDataChangedListener.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.listener; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener; import com.google.common.base.Preconditions; import lombok.RequiredArgsConstructor; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/listener/GlobalMetaDataChangedListener.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/GlobalMetaDataChangedListener.java similarity index 89% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/listener/GlobalMetaDataChangedListener.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/GlobalMetaDataChangedListener.java index 33a5047601fed..82baefae06fca 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/listener/GlobalMetaDataChangedListener.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/GlobalMetaDataChangedListener.java @@ -15,12 +15,12 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.listener; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener; import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.util.eventbus.EventBusContext; import org.apache.shardingsphere.mode.event.DataChangedEvent; -import org.apache.shardingsphere.mode.manager.cluster.event.builder.DispatchEventBuilder; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.DispatchEventBuilder; import org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEventListener; /** diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/CacheEvictedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/CacheEvictedSubscriber.java similarity index 94% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/CacheEvictedSubscriber.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/CacheEvictedSubscriber.java index a64b6a4d80049..09061e21e5093 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/CacheEvictedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/CacheEvictedSubscriber.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; import com.google.common.eventbus.Subscribe; import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/registry/ClusterDispatchEventSubscriberRegistry.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ClusterDispatchEventSubscriberRegistry.java similarity index 60% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/registry/ClusterDispatchEventSubscriberRegistry.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ClusterDispatchEventSubscriberRegistry.java index b46a1a1ac264e..178570194da95 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/registry/ClusterDispatchEventSubscriberRegistry.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ClusterDispatchEventSubscriberRegistry.java @@ -15,23 +15,11 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.subscriber.registry; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; import lombok.Getter; import org.apache.shardingsphere.infra.util.eventbus.EventSubscriber; import org.apache.shardingsphere.mode.manager.ContextManager; -import org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch.CacheEvictedSubscriber; -import org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch.ComputeNodeStateSubscriber; -import org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch.DatabaseDataChangedSubscriber; -import org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch.GlobalRuleConfigurationEventSubscriber; -import org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch.ListenerAssistedSubscriber; -import org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch.ProcessListChangedSubscriber; -import org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch.PropertiesEventSubscriber; -import org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch.QualifiedDataSourceSubscriber; -import org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch.MetaDataChangedSubscriber; -import org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch.RuleItemChangedSubscriber; -import org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch.StateChangedSubscriber; -import org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch.StorageUnitEventSubscriber; import java.util.Arrays; import java.util.Collection; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/ComputeNodeStateSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ComputeNodeStateSubscriber.java similarity index 97% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/ComputeNodeStateSubscriber.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ComputeNodeStateSubscriber.java index 6d661330cb908..1e61f6b31af76 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/ComputeNodeStateSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ComputeNodeStateSubscriber.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; import com.google.common.eventbus.Subscribe; import lombok.RequiredArgsConstructor; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/DatabaseDataChangedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/DatabaseDataChangedSubscriber.java similarity index 98% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/DatabaseDataChangedSubscriber.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/DatabaseDataChangedSubscriber.java index c28f0de9c47c1..45d8f76b3848e 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/DatabaseDataChangedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/DatabaseDataChangedSubscriber.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; import com.google.common.eventbus.Subscribe; import lombok.RequiredArgsConstructor; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/GlobalRuleConfigurationEventSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/GlobalRuleConfigurationEventSubscriber.java similarity index 97% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/GlobalRuleConfigurationEventSubscriber.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/GlobalRuleConfigurationEventSubscriber.java index 6093b87bd5f13..7b2989fe1c7a5 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/GlobalRuleConfigurationEventSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/GlobalRuleConfigurationEventSubscriber.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; import com.google.common.base.Preconditions; import com.google.common.eventbus.Subscribe; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/ListenerAssistedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ListenerAssistedSubscriber.java similarity index 93% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/ListenerAssistedSubscriber.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ListenerAssistedSubscriber.java index 8561b6d7a259c..f34020552034d 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/ListenerAssistedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ListenerAssistedSubscriber.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; import com.google.common.eventbus.Subscribe; import lombok.RequiredArgsConstructor; @@ -26,8 +26,8 @@ import org.apache.shardingsphere.mode.event.dispatch.assisted.DropDatabaseListenerAssistedEvent; import org.apache.shardingsphere.mode.lock.GlobalLockContext; import org.apache.shardingsphere.mode.manager.ContextManager; -import org.apache.shardingsphere.mode.manager.cluster.listener.DatabaseMetaDataChangedListener; -import org.apache.shardingsphere.mode.manager.cluster.lock.GlobalLockPersistService; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener.DatabaseMetaDataChangedListener; +import org.apache.shardingsphere.mode.manager.cluster.persist.GlobalLockPersistService; import org.apache.shardingsphere.mode.metadata.refresher.ShardingSphereStatisticsRefreshEngine; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/MetaDataChangedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/MetaDataChangedSubscriber.java similarity index 97% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/MetaDataChangedSubscriber.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/MetaDataChangedSubscriber.java index 83bc9c40765a7..126fddf451abd 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/MetaDataChangedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/MetaDataChangedSubscriber.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; import com.google.common.base.Preconditions; import com.google.common.eventbus.Subscribe; @@ -31,7 +31,7 @@ import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.view.DropViewEvent; import org.apache.shardingsphere.mode.lock.GlobalLockContext; import org.apache.shardingsphere.mode.manager.ContextManager; -import org.apache.shardingsphere.mode.manager.cluster.lock.GlobalLockPersistService; +import org.apache.shardingsphere.mode.manager.cluster.persist.GlobalLockPersistService; import org.apache.shardingsphere.mode.metadata.refresher.ShardingSphereStatisticsRefreshEngine; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/ProcessListChangedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ProcessListChangedSubscriber.java similarity index 98% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/ProcessListChangedSubscriber.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ProcessListChangedSubscriber.java index 2d7ddc3070268..a28e417f54003 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/ProcessListChangedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ProcessListChangedSubscriber.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; import com.google.common.eventbus.Subscribe; import lombok.RequiredArgsConstructor; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/PropertiesEventSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/PropertiesEventSubscriber.java similarity index 96% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/PropertiesEventSubscriber.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/PropertiesEventSubscriber.java index dcbbacebdffe1..6a5eaa80bad5c 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/PropertiesEventSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/PropertiesEventSubscriber.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; import com.google.common.base.Preconditions; import com.google.common.eventbus.Subscribe; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/QualifiedDataSourceSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/QualifiedDataSourceSubscriber.java similarity index 96% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/QualifiedDataSourceSubscriber.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/QualifiedDataSourceSubscriber.java index e188ef13277be..8929bbb953221 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/QualifiedDataSourceSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/QualifiedDataSourceSubscriber.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; import com.google.common.base.Preconditions; import com.google.common.eventbus.Subscribe; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/RuleItemChangedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/RuleItemChangedSubscriber.java similarity index 96% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/RuleItemChangedSubscriber.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/RuleItemChangedSubscriber.java index f2594d2e3d3bb..887fc62cdb9bd 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/RuleItemChangedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/RuleItemChangedSubscriber.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; import com.google.common.eventbus.Subscribe; import lombok.RequiredArgsConstructor; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/StateChangedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/StateChangedSubscriber.java similarity index 95% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/StateChangedSubscriber.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/StateChangedSubscriber.java index 84643696dd156..cf3c70e000ff5 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/StateChangedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/StateChangedSubscriber.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; import com.google.common.eventbus.Subscribe; import org.apache.shardingsphere.infra.util.eventbus.EventSubscriber; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/StorageUnitEventSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/StorageUnitEventSubscriber.java similarity index 98% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/StorageUnitEventSubscriber.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/StorageUnitEventSubscriber.java index 096c6067107da..f1f6248cb6e4a 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/StorageUnitEventSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/StorageUnitEventSubscriber.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; import com.google.common.base.Preconditions; import com.google.common.eventbus.Subscribe; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/lock/GlobalLockPersistService.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/GlobalLockPersistService.java similarity index 96% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/lock/GlobalLockPersistService.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/GlobalLockPersistService.java index b60670f4b58fd..11256bf25891c 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/lock/GlobalLockPersistService.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/GlobalLockPersistService.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.lock; +package org.apache.shardingsphere.mode.manager.cluster.persist; import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.mode.lock.GlobalLockDefinition; diff --git a/mode/type/cluster/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.event.builder.DispatchEventBuilder b/mode/type/cluster/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.event.builder.DispatchEventBuilder deleted file mode 100644 index 49e85446d1569..0000000000000 --- a/mode/type/cluster/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.event.builder.DispatchEventBuilder +++ /dev/null @@ -1,27 +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. -# - -org.apache.shardingsphere.mode.manager.cluster.event.builder.QualifiedDataSourceDispatchEventBuilder -org.apache.shardingsphere.mode.manager.cluster.event.builder.ComputeNodeStateDispatchEventBuilder -org.apache.shardingsphere.mode.manager.cluster.event.builder.ClusterStateDispatchEventBuilder -org.apache.shardingsphere.mode.manager.cluster.event.builder.ShardingSphereDataDispatchEventBuilder -org.apache.shardingsphere.mode.manager.cluster.event.builder.GlobalRuleDispatchEventBuilder -org.apache.shardingsphere.mode.manager.cluster.event.builder.PropertiesDispatchEventBuilder -org.apache.shardingsphere.mode.manager.cluster.event.builder.ListenerAssistedDispatchEventBuilder -org.apache.shardingsphere.mode.manager.cluster.event.builder.ComputeNodeOnlineDispatchEventBuilder -org.apache.shardingsphere.mode.manager.cluster.event.builder.ShowProcessListDispatchEventBuilder -org.apache.shardingsphere.mode.manager.cluster.event.builder.KillProcessDispatchEventBuilder diff --git a/mode/type/cluster/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.DispatchEventBuilder b/mode/type/cluster/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.DispatchEventBuilder new file mode 100644 index 0000000000000..bfbe576976707 --- /dev/null +++ b/mode/type/cluster/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.DispatchEventBuilder @@ -0,0 +1,27 @@ +# +# 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. +# + +org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.QualifiedDataSourceDispatchEventBuilder +org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.ComputeNodeStateDispatchEventBuilder +org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.ClusterStateDispatchEventBuilder +org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.ShardingSphereDataDispatchEventBuilder +org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.GlobalRuleDispatchEventBuilder +org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.PropertiesDispatchEventBuilder +org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.ListenerAssistedDispatchEventBuilder +org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.ComputeNodeOnlineDispatchEventBuilder +org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.ShowProcessListDispatchEventBuilder +org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.KillProcessDispatchEventBuilder diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/deliver/DeliverQualifiedDataSourceSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/DeliverQualifiedDataSourceSubscriberTest.java similarity index 96% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/deliver/DeliverQualifiedDataSourceSubscriberTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/DeliverQualifiedDataSourceSubscriberTest.java index fcdcfa23a096a..7325fd1ca84bb 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/deliver/DeliverQualifiedDataSourceSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/DeliverQualifiedDataSourceSubscriberTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.subscriber.deliver; +package org.apache.shardingsphere.mode.manager.cluster.event.deliver.subscriber; import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource; import org.apache.shardingsphere.mode.event.deliver.datasource.qualified.QualifiedDataSourceDeletedEvent; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ClusterStateDispatchEventBuilderTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ClusterStateDispatchEventBuilderTest.java similarity index 96% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ClusterStateDispatchEventBuilderTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ClusterStateDispatchEventBuilderTest.java index 911008bf022c7..9f6cdcd96fc8c 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ClusterStateDispatchEventBuilderTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ClusterStateDispatchEventBuilderTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; import org.apache.shardingsphere.infra.state.cluster.ClusterState; import org.apache.shardingsphere.mode.event.DataChangedEvent; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ComputeNodeOnlineDispatchEventBuilderTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ComputeNodeOnlineDispatchEventBuilderTest.java similarity index 97% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ComputeNodeOnlineDispatchEventBuilderTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ComputeNodeOnlineDispatchEventBuilderTest.java index b4c5e6fc9ac5c..08f8fbb2c63e3 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ComputeNodeOnlineDispatchEventBuilderTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ComputeNodeOnlineDispatchEventBuilderTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; import org.apache.shardingsphere.infra.instance.metadata.InstanceType; import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ComputeNodeStateDispatchEventBuilderTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ComputeNodeStateDispatchEventBuilderTest.java similarity index 98% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ComputeNodeStateDispatchEventBuilderTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ComputeNodeStateDispatchEventBuilderTest.java index 75427d184da85..0349b33fb9251 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ComputeNodeStateDispatchEventBuilderTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ComputeNodeStateDispatchEventBuilderTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; import org.apache.shardingsphere.infra.state.instance.InstanceState; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/GlobalRuleDispatchEventBuilderTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/GlobalRuleDispatchEventBuilderTest.java similarity index 96% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/GlobalRuleDispatchEventBuilderTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/GlobalRuleDispatchEventBuilderTest.java index 10cc7d3d157a6..21863e9293ebe 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/GlobalRuleDispatchEventBuilderTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/GlobalRuleDispatchEventBuilderTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; import org.apache.shardingsphere.mode.event.DataChangedEvent; import org.apache.shardingsphere.mode.event.DataChangedEvent.Type; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/KillProcessDispatchEventBuilderTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/KillProcessDispatchEventBuilderTest.java similarity index 97% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/KillProcessDispatchEventBuilderTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/KillProcessDispatchEventBuilderTest.java index e4654073de9a4..0afd4ab98804e 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/KillProcessDispatchEventBuilderTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/KillProcessDispatchEventBuilderTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; import org.apache.shardingsphere.metadata.persist.node.ComputeNode; import org.apache.shardingsphere.mode.event.DataChangedEvent; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ListenerAssistedDispatchEventBuilderTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ListenerAssistedDispatchEventBuilderTest.java similarity index 97% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ListenerAssistedDispatchEventBuilderTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ListenerAssistedDispatchEventBuilderTest.java index c2b40c9e824aa..1c0b76cfefe60 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ListenerAssistedDispatchEventBuilderTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ListenerAssistedDispatchEventBuilderTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; import org.apache.shardingsphere.mode.event.DataChangedEvent; import org.apache.shardingsphere.mode.event.DataChangedEvent.Type; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/PropertiesDispatchEventBuilderTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/PropertiesDispatchEventBuilderTest.java similarity index 96% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/PropertiesDispatchEventBuilderTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/PropertiesDispatchEventBuilderTest.java index 81ee568b38ceb..443f8752abdd9 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/PropertiesDispatchEventBuilderTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/PropertiesDispatchEventBuilderTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; import org.apache.shardingsphere.mode.event.DataChangedEvent; import org.apache.shardingsphere.mode.event.DataChangedEvent.Type; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/QualifiedDataSourceDispatchEventBuilderTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/QualifiedDataSourceDispatchEventBuilderTest.java similarity index 97% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/QualifiedDataSourceDispatchEventBuilderTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/QualifiedDataSourceDispatchEventBuilderTest.java index e227f233fec3d..3f94f3f30efd1 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/QualifiedDataSourceDispatchEventBuilderTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/QualifiedDataSourceDispatchEventBuilderTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; import org.apache.shardingsphere.infra.state.datasource.DataSourceState; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ShardingSphereDataDispatchEventBuilderTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ShardingSphereDataDispatchEventBuilderTest.java similarity index 99% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ShardingSphereDataDispatchEventBuilderTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ShardingSphereDataDispatchEventBuilderTest.java index fd9e485464d95..d2bd219f7e6b9 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ShardingSphereDataDispatchEventBuilderTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ShardingSphereDataDispatchEventBuilderTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; import org.apache.shardingsphere.mode.event.DataChangedEvent; import org.apache.shardingsphere.mode.event.DataChangedEvent.Type; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ShowProcessListDispatchEventBuilderTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ShowProcessListDispatchEventBuilderTest.java similarity index 97% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ShowProcessListDispatchEventBuilderTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ShowProcessListDispatchEventBuilderTest.java index f1fe24f66fb2c..3489950b1a779 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/builder/ShowProcessListDispatchEventBuilderTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ShowProcessListDispatchEventBuilderTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; import org.apache.shardingsphere.metadata.persist.node.ComputeNode; import org.apache.shardingsphere.mode.event.DataChangedEvent; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/listener/DataChangedEventListenerRegistryTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/DataChangedEventListenerRegistryTest.java similarity index 96% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/listener/DataChangedEventListenerRegistryTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/DataChangedEventListenerRegistryTest.java index fc42cf23a6e5e..4f2191b9f29b4 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/listener/DataChangedEventListenerRegistryTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/DataChangedEventListenerRegistryTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.listener; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/listener/DatabaseMetaDataChangedListenerTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/DatabaseMetaDataChangedListenerTest.java similarity index 99% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/listener/DatabaseMetaDataChangedListenerTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/DatabaseMetaDataChangedListenerTest.java index 0a24dd7de0631..ae80280424661 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/listener/DatabaseMetaDataChangedListenerTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/DatabaseMetaDataChangedListenerTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.listener; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener; import lombok.SneakyThrows; import org.apache.shardingsphere.infra.util.eventbus.EventBusContext; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/listener/GlobalMetaDataChangedListenerTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/GlobalMetaDataChangedListenerTest.java similarity index 93% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/listener/GlobalMetaDataChangedListenerTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/GlobalMetaDataChangedListenerTest.java index 5f4ea56684838..da92e8c510d11 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/listener/GlobalMetaDataChangedListenerTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/GlobalMetaDataChangedListenerTest.java @@ -15,12 +15,12 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.listener; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener; import org.apache.shardingsphere.infra.util.eventbus.EventBusContext; import org.apache.shardingsphere.mode.event.DataChangedEvent; import org.apache.shardingsphere.mode.event.DataChangedEvent.Type; -import org.apache.shardingsphere.mode.manager.cluster.event.builder.DispatchEventBuilder; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.DispatchEventBuilder; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/CacheEvictedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/CacheEvictedSubscriberTest.java similarity index 95% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/CacheEvictedSubscriberTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/CacheEvictedSubscriberTest.java index db0a4c2b0251e..5e4c99c7b7c64 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/CacheEvictedSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/CacheEvictedSubscriberTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; import org.apache.shardingsphere.infra.util.eventbus.EventBusContext; import org.apache.shardingsphere.infra.spi.type.ordered.cache.OrderedServicesCache; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/ComputeNodeStateSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ComputeNodeStateSubscriberTest.java similarity index 97% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/ComputeNodeStateSubscriberTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ComputeNodeStateSubscriberTest.java index 95d8b8ad677e6..f1d8102bde398 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/ComputeNodeStateSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ComputeNodeStateSubscriberTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; import org.apache.shardingsphere.infra.instance.ComputeNodeInstance; import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/DatabaseDataChangedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/DatabaseDataChangedSubscriberTest.java similarity index 98% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/DatabaseDataChangedSubscriberTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/DatabaseDataChangedSubscriberTest.java index 3b642e29d8f21..8b6120b4e524a 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/DatabaseDataChangedSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/DatabaseDataChangedSubscriberTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; import org.apache.shardingsphere.infra.yaml.data.pojo.YamlShardingSphereRowData; import org.apache.shardingsphere.mode.event.dispatch.metadata.data.DatabaseDataAddedEvent; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/GlobalRuleConfigurationEventSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/GlobalRuleConfigurationEventSubscriberTest.java similarity index 96% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/GlobalRuleConfigurationEventSubscriberTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/GlobalRuleConfigurationEventSubscriberTest.java index aafa9f41f82ee..7fa43bf8ed56e 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/GlobalRuleConfigurationEventSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/GlobalRuleConfigurationEventSubscriberTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; import org.apache.shardingsphere.mode.event.dispatch.config.AlterGlobalRuleConfigurationEvent; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/ListenerAssistedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ListenerAssistedSubscriberTest.java similarity index 97% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/ListenerAssistedSubscriberTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ListenerAssistedSubscriberTest.java index cf9f782b57bac..36fdb66f04a12 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/ListenerAssistedSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ListenerAssistedSubscriberTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; import org.apache.shardingsphere.infra.instance.metadata.InstanceType; import org.apache.shardingsphere.mode.event.dispatch.assisted.CreateDatabaseListenerAssistedEvent; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/MetaDataChangedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/MetaDataChangedSubscriberTest.java similarity index 98% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/MetaDataChangedSubscriberTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/MetaDataChangedSubscriberTest.java index 202e321fe0315..76a68c1c28c7e 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/MetaDataChangedSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/MetaDataChangedSubscriberTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; import org.apache.shardingsphere.infra.config.props.temporary.TemporaryConfigurationPropertyKey; import org.apache.shardingsphere.infra.instance.metadata.InstanceType; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/ProcessListChangedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ProcessListChangedSubscriberTest.java similarity index 98% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/ProcessListChangedSubscriberTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ProcessListChangedSubscriberTest.java index a1ce52b4977be..312558fcccf03 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/ProcessListChangedSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ProcessListChangedSubscriberTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; import org.apache.shardingsphere.infra.executor.sql.process.Process; import org.apache.shardingsphere.infra.executor.sql.process.ProcessRegistry; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/PropertiesEventSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/PropertiesEventSubscriberTest.java similarity index 96% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/PropertiesEventSubscriberTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/PropertiesEventSubscriberTest.java index 4e6c4ef9a001a..d806217958229 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/PropertiesEventSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/PropertiesEventSubscriberTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; import org.apache.shardingsphere.mode.event.dispatch.config.AlterPropertiesEvent; import org.apache.shardingsphere.mode.manager.ContextManager; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/QualifiedDataSourceSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/QualifiedDataSourceSubscriberTest.java similarity index 97% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/QualifiedDataSourceSubscriberTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/QualifiedDataSourceSubscriberTest.java index f2d94495610d7..5bc11d56106bf 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/QualifiedDataSourceSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/QualifiedDataSourceSubscriberTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource; import org.apache.shardingsphere.infra.rule.attribute.datasource.StaticDataSourceRuleAttribute; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/RuleItemChangedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/RuleItemChangedSubscriberTest.java similarity index 96% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/RuleItemChangedSubscriberTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/RuleItemChangedSubscriberTest.java index e776e5cf120f2..31b31a4ad5f61 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/RuleItemChangedSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/RuleItemChangedSubscriberTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterRuleItemEvent; import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropRuleItemEvent; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/StateChangedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/StateChangedSubscriberTest.java similarity index 95% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/StateChangedSubscriberTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/StateChangedSubscriberTest.java index a1c6eb893e7b1..21cd42d97fc97 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/StateChangedSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/StateChangedSubscriberTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; import org.apache.shardingsphere.infra.state.cluster.ClusterState; import org.apache.shardingsphere.mode.event.dispatch.state.cluster.ClusterStateEvent; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/StorageUnitEventSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/StorageUnitEventSubscriberTest.java similarity index 97% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/StorageUnitEventSubscriberTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/StorageUnitEventSubscriberTest.java index efa79c5a090b8..f119fd9217bf7 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/subscriber/dispatch/StorageUnitEventSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/StorageUnitEventSubscriberTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.subscriber.dispatch; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; import org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties; import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.AlterStorageUnitEvent; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/lock/GlobalLockPersistServiceTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/GlobalLockPersistServiceTest.java similarity index 97% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/lock/GlobalLockPersistServiceTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/GlobalLockPersistServiceTest.java index 561a7b3ec58c8..851face5ca088 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/lock/GlobalLockPersistServiceTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/GlobalLockPersistServiceTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.lock; +package org.apache.shardingsphere.mode.manager.cluster.persist; import org.apache.shardingsphere.mode.lock.GlobalLockDefinition; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; From a7ef4beffdab12ae154c40078810e7f7a10905ad Mon Sep 17 00:00:00 2001 From: Haoran Meng Date: Thu, 12 Dec 2024 18:42:41 +0800 Subject: [PATCH 08/32] Refactor refresh metadata after storage unit registered (#34028) --- .../ClusterMetaDataManagerPersistService.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/ClusterMetaDataManagerPersistService.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/ClusterMetaDataManagerPersistService.java index c2da0ec039206..38d026812dceb 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/ClusterMetaDataManagerPersistService.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/ClusterMetaDataManagerPersistService.java @@ -125,7 +125,7 @@ public void registerStorageUnits(final String databaseName, final Map getToBeDroppedResourceNames(final String databaseName return toBeDroppedResourceNames.stream().filter(propsMap::containsKey).collect(Collectors.toList()); } - private void afterStorageUnitsAltered(final String databaseName, final MetaDataContexts originalMetaDataContexts, final MetaDataContexts reloadMetaDataContexts) { - reloadMetaDataContexts.getMetaData().getDatabase(databaseName).getAllSchemas().forEach(each -> metaDataPersistService.getDatabaseMetaDataFacade() - .getSchema().alterByRuleAltered(reloadMetaDataContexts.getMetaData().getDatabase(databaseName).getName(), each)); + private void afterStorageUnitsRegistered(final String databaseName, final MetaDataContexts originalMetaDataContexts, final MetaDataContexts reloadMetaDataContexts) { Optional.ofNullable(reloadMetaDataContexts.getStatistics().getDatabaseData().get(databaseName)) .ifPresent(optional -> optional.getSchemaData().forEach((schemaName, schemaData) -> metaDataPersistService.getShardingSphereDataPersistService() .persist(originalMetaDataContexts.getMetaData().getDatabase(databaseName), schemaName, schemaData))); @@ -189,6 +187,12 @@ private void afterStorageUnitsAltered(final String databaseName, final MetaDataC originalMetaDataContexts.getMetaData().getDatabase(databaseName)); } + private void afterStorageUnitsAltered(final String databaseName, final MetaDataContexts originalMetaDataContexts, final MetaDataContexts reloadMetaDataContexts) { + reloadMetaDataContexts.getMetaData().getDatabase(databaseName).getAllSchemas().forEach(each -> metaDataPersistService.getDatabaseMetaDataFacade() + .getSchema().alterByRuleAltered(reloadMetaDataContexts.getMetaData().getDatabase(databaseName).getName(), each)); + afterStorageUnitsRegistered(databaseName, originalMetaDataContexts, reloadMetaDataContexts); + } + private void afterStorageUnitsDropped(final String databaseName, final MetaDataContexts originalMetaDataContexts, final MetaDataContexts reloadMetaDataContexts) { reloadMetaDataContexts.getMetaData().getDatabase(databaseName).getAllSchemas().forEach(each -> metaDataPersistService.getDatabaseMetaDataFacade() .getSchema().alterByRuleDropped(reloadMetaDataContexts.getMetaData().getDatabase(databaseName).getName(), each)); From 36ac4f50c6190b0a3d46e7a41d1c37c3f66303fe Mon Sep 17 00:00:00 2001 From: Haoran Meng Date: Thu, 12 Dec 2024 19:41:54 +0800 Subject: [PATCH 09/32] Update the unsupported items for jdbc (#34030) --- .../content/user-manual/shardingsphere-jdbc/unsupported.cn.md | 4 ++++ .../content/user-manual/shardingsphere-jdbc/unsupported.en.md | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/docs/document/content/user-manual/shardingsphere-jdbc/unsupported.cn.md b/docs/document/content/user-manual/shardingsphere-jdbc/unsupported.cn.md index 4a85fe694bb62..5593ede6ef31b 100644 --- a/docs/document/content/user-manual/shardingsphere-jdbc/unsupported.cn.md +++ b/docs/document/content/user-manual/shardingsphere-jdbc/unsupported.cn.md @@ -3,6 +3,10 @@ title = "不支持项" weight = 6 +++ +## 配置 + +* 不支持配置多个逻辑数据库。 + ## DataSource 接口 * 不支持 timeout 相关操作。 diff --git a/docs/document/content/user-manual/shardingsphere-jdbc/unsupported.en.md b/docs/document/content/user-manual/shardingsphere-jdbc/unsupported.en.md index 2c4055272b28a..d466046a88a0f 100644 --- a/docs/document/content/user-manual/shardingsphere-jdbc/unsupported.en.md +++ b/docs/document/content/user-manual/shardingsphere-jdbc/unsupported.en.md @@ -3,6 +3,10 @@ title = "Unsupported Items" weight = 6 +++ +## Configuration + +* Do not support configuring multiple logic databases + ## DataSource Interface * Do not support timeout related operations From 4c03a80f23399f04b91d9ec2682f5f8358859cca Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Thu, 12 Dec 2024 23:03:32 +0800 Subject: [PATCH 10/32] Refactor ClusterContextManagerBuilder (#34031) --- .../infra/config/mode/ModeConfigurationTest.java | 8 ++++---- .../cluster/ClusterContextManagerBuilder.java | 16 +++++++++------- .../ClusterDeliverEventSubscriberRegistry.java | 5 ++--- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/config/mode/ModeConfigurationTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/config/mode/ModeConfigurationTest.java index f936d2c5e1787..03eb1c3cb6e93 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/config/mode/ModeConfigurationTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/config/mode/ModeConfigurationTest.java @@ -26,9 +26,9 @@ class ModeConfigurationTest { @Test void assertIsCluster() { - ModeConfiguration standaloneModeConfiguration = new ModeConfiguration("Standalone", null); - assertFalse(standaloneModeConfiguration.isCluster()); - ModeConfiguration clusterModeConfiguration = new ModeConfiguration("Cluster", null); - assertTrue(clusterModeConfiguration.isCluster()); + ModeConfiguration standaloneModeConfig = new ModeConfiguration("Standalone", null); + assertFalse(standaloneModeConfig.isCluster()); + ModeConfiguration clusterModeConfig = new ModeConfiguration("Cluster", null); + assertTrue(clusterModeConfig.isCluster()); } } diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java index 461e7ac6bdca4..3723eadcf6e41 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java @@ -55,28 +55,30 @@ public ContextManager build(final ContextManagerBuilderParameter param, final Ev ModeConfiguration modeConfig = param.getModeConfiguration(); ClusterPersistRepositoryConfiguration config = (ClusterPersistRepositoryConfiguration) modeConfig.getRepository(); ComputeNodeInstanceContext computeNodeInstanceContext = new ComputeNodeInstanceContext(new ComputeNodeInstance(param.getInstanceMetaData(), param.getLabels()), modeConfig, eventBusContext); - ClusterPersistRepository repository = getClusterPersistRepository(config); - repository.init(config, computeNodeInstanceContext); + ClusterPersistRepository repository = getClusterPersistRepository(config, computeNodeInstanceContext); LockContext lockContext = new GlobalLockContext(new GlobalLockPersistService(repository)); computeNodeInstanceContext.init(new ClusterWorkerIdGenerator(repository, param.getInstanceMetaData().getId()), lockContext); MetaDataPersistService metaDataPersistService = new MetaDataPersistService(repository); MetaDataContexts metaDataContexts = MetaDataContextsFactory.create(metaDataPersistService, param, computeNodeInstanceContext); ContextManager result = new ContextManager(metaDataContexts, computeNodeInstanceContext, repository); - registerOnline(computeNodeInstanceContext, param, result); + registerOnline(computeNodeInstanceContext, param, result, repository); return result; } - private ClusterPersistRepository getClusterPersistRepository(final ClusterPersistRepositoryConfiguration config) { + private ClusterPersistRepository getClusterPersistRepository(final ClusterPersistRepositoryConfiguration config, final ComputeNodeInstanceContext computeNodeInstanceContext) { ShardingSpherePreconditions.checkNotNull(config, MissingRequiredClusterRepositoryConfigurationException::new); - return TypedSPILoader.getService(ClusterPersistRepository.class, config.getType(), config.getProps()); + ClusterPersistRepository result = TypedSPILoader.getService(ClusterPersistRepository.class, config.getType(), config.getProps()); + result.init(config, computeNodeInstanceContext); + return result; } - private void registerOnline(final ComputeNodeInstanceContext computeNodeInstanceContext, final ContextManagerBuilderParameter param, final ContextManager contextManager) { + private void registerOnline(final ComputeNodeInstanceContext computeNodeInstanceContext, final ContextManagerBuilderParameter param, final ContextManager contextManager, + final ClusterPersistRepository repository) { contextManager.getPersistServiceFacade().getComputeNodePersistService().registerOnline(computeNodeInstanceContext.getInstance()); contextManager.getComputeNodeInstanceContext().getAllClusterInstances().addAll(contextManager.getPersistServiceFacade().getComputeNodePersistService().loadAllComputeNodeInstances()); new DataChangedEventListenerRegistry(contextManager, getDatabaseNames(param, contextManager.getPersistServiceFacade().getMetaDataPersistService())).register(); EventSubscriberRegistry eventSubscriberRegistry = new EventSubscriberRegistry(contextManager.getComputeNodeInstanceContext().getEventBusContext()); - eventSubscriberRegistry.register(new ClusterDeliverEventSubscriberRegistry(contextManager).getSubscribers()); + eventSubscriberRegistry.register(new ClusterDeliverEventSubscriberRegistry(repository).getSubscribers()); eventSubscriberRegistry.register(new ClusterDispatchEventSubscriberRegistry(contextManager).getSubscribers()); } diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/ClusterDeliverEventSubscriberRegistry.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/ClusterDeliverEventSubscriberRegistry.java index 06ce77c27b084..490dc709411d9 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/ClusterDeliverEventSubscriberRegistry.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/ClusterDeliverEventSubscriberRegistry.java @@ -19,7 +19,6 @@ import lombok.Getter; import org.apache.shardingsphere.infra.util.eventbus.EventSubscriber; -import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; import java.util.Collection; @@ -33,7 +32,7 @@ public final class ClusterDeliverEventSubscriberRegistry { private final Collection subscribers; - public ClusterDeliverEventSubscriberRegistry(final ContextManager contextManager) { - subscribers = Collections.singleton(new DeliverQualifiedDataSourceSubscriber((ClusterPersistRepository) contextManager.getPersistServiceFacade().getRepository())); + public ClusterDeliverEventSubscriberRegistry(final ClusterPersistRepository repository) { + subscribers = Collections.singleton(new DeliverQualifiedDataSourceSubscriber(repository)); } } From ec5925c720972656c3b008fea9c2b7f2d235d369 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Thu, 12 Dec 2024 23:15:02 +0800 Subject: [PATCH 11/32] Remove useless @SuppressWarnings("unused") (#34032) --- .../event/dispatch/subscriber/CacheEvictedSubscriber.java | 1 - .../event/dispatch/subscriber/ComputeNodeStateSubscriber.java | 1 - .../event/dispatch/subscriber/DatabaseDataChangedSubscriber.java | 1 - .../subscriber/GlobalRuleConfigurationEventSubscriber.java | 1 - .../event/dispatch/subscriber/ListenerAssistedSubscriber.java | 1 - .../event/dispatch/subscriber/MetaDataChangedSubscriber.java | 1 - .../event/dispatch/subscriber/ProcessListChangedSubscriber.java | 1 - .../event/dispatch/subscriber/PropertiesEventSubscriber.java | 1 - .../event/dispatch/subscriber/QualifiedDataSourceSubscriber.java | 1 - .../event/dispatch/subscriber/RuleItemChangedSubscriber.java | 1 - .../event/dispatch/subscriber/StateChangedSubscriber.java | 1 - .../event/dispatch/subscriber/StorageUnitEventSubscriber.java | 1 - 12 files changed, 12 deletions(-) diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/CacheEvictedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/CacheEvictedSubscriber.java index 09061e21e5093..848bc0169e2f9 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/CacheEvictedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/CacheEvictedSubscriber.java @@ -25,7 +25,6 @@ /** * Cache evicted subscriber. */ -@SuppressWarnings("unused") public final class CacheEvictedSubscriber implements EventSubscriber { /** diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ComputeNodeStateSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ComputeNodeStateSubscriber.java index 1e61f6b31af76..eb42494dc3d54 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ComputeNodeStateSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ComputeNodeStateSubscriber.java @@ -32,7 +32,6 @@ * Compute node state subscriber. */ @RequiredArgsConstructor -@SuppressWarnings("unused") public final class ComputeNodeStateSubscriber implements EventSubscriber { private final ContextManager contextManager; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/DatabaseDataChangedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/DatabaseDataChangedSubscriber.java index 45d8f76b3848e..870ea1b802f55 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/DatabaseDataChangedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/DatabaseDataChangedSubscriber.java @@ -33,7 +33,6 @@ * Database data changed subscriber. */ @RequiredArgsConstructor -@SuppressWarnings("unused") public final class DatabaseDataChangedSubscriber implements EventSubscriber { private final ContextManager contextManager; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/GlobalRuleConfigurationEventSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/GlobalRuleConfigurationEventSubscriber.java index 7b2989fe1c7a5..5a5a3825dea5d 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/GlobalRuleConfigurationEventSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/GlobalRuleConfigurationEventSubscriber.java @@ -33,7 +33,6 @@ * Global rule configuration event subscriber. */ @RequiredArgsConstructor -@SuppressWarnings("unused") public final class GlobalRuleConfigurationEventSubscriber implements EventSubscriber { private final ContextManager contextManager; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ListenerAssistedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ListenerAssistedSubscriber.java index f34020552034d..99fb2cad6b718 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ListenerAssistedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ListenerAssistedSubscriber.java @@ -35,7 +35,6 @@ * Listener assisted subscriber. */ @RequiredArgsConstructor -@SuppressWarnings("unused") public final class ListenerAssistedSubscriber implements EventSubscriber { private final ContextManager contextManager; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/MetaDataChangedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/MetaDataChangedSubscriber.java index 126fddf451abd..16da01180e0d5 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/MetaDataChangedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/MetaDataChangedSubscriber.java @@ -38,7 +38,6 @@ /** * Meta data changed subscriber. */ -@SuppressWarnings("unused") public final class MetaDataChangedSubscriber implements EventSubscriber { private final ContextManager contextManager; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ProcessListChangedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ProcessListChangedSubscriber.java index a28e417f54003..65cbb902a9c2a 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ProcessListChangedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ProcessListChangedSubscriber.java @@ -41,7 +41,6 @@ * Process list changed subscriber. */ @RequiredArgsConstructor -@SuppressWarnings("unused") public final class ProcessListChangedSubscriber implements EventSubscriber { private final ContextManager contextManager; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/PropertiesEventSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/PropertiesEventSubscriber.java index 6a5eaa80bad5c..c0a066feabc40 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/PropertiesEventSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/PropertiesEventSubscriber.java @@ -28,7 +28,6 @@ * Properties event subscriber. */ @RequiredArgsConstructor -@SuppressWarnings("unused") public final class PropertiesEventSubscriber implements EventSubscriber { private final ContextManager contextManager; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/QualifiedDataSourceSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/QualifiedDataSourceSubscriber.java index 8929bbb953221..1b0af0cca00ff 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/QualifiedDataSourceSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/QualifiedDataSourceSubscriber.java @@ -31,7 +31,6 @@ * Qualified data source subscriber. */ @RequiredArgsConstructor -@SuppressWarnings("unused") public class QualifiedDataSourceSubscriber implements EventSubscriber { private final ContextManager contextManager; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/RuleItemChangedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/RuleItemChangedSubscriber.java index 887fc62cdb9bd..4d29f764dc141 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/RuleItemChangedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/RuleItemChangedSubscriber.java @@ -30,7 +30,6 @@ * Rule item changed subscriber. */ @RequiredArgsConstructor -@SuppressWarnings("unused") public final class RuleItemChangedSubscriber implements EventSubscriber { private final ContextManager contextManager; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/StateChangedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/StateChangedSubscriber.java index cf3c70e000ff5..1d2e7abb8cdae 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/StateChangedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/StateChangedSubscriber.java @@ -25,7 +25,6 @@ /** * State changed subscriber. */ -@SuppressWarnings("unused") public final class StateChangedSubscriber implements EventSubscriber { private final ContextManager contextManager; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/StorageUnitEventSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/StorageUnitEventSubscriber.java index f1f6248cb6e4a..d1ad60852ad52 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/StorageUnitEventSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/StorageUnitEventSubscriber.java @@ -33,7 +33,6 @@ * Storage unit event subscriber. */ @RequiredArgsConstructor -@SuppressWarnings("unused") public final class StorageUnitEventSubscriber implements EventSubscriber { private final ContextManager contextManager; From 2e2e400e3f887014471c8c9136e4dfaeb615012e Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Thu, 12 Dec 2024 23:40:32 +0800 Subject: [PATCH 12/32] Refactor mode persist package (#34033) --- .../core/job/statistics/collect/StatisticsCollectJob.java | 2 +- .../mode/manager/cluster/ClusterContextManagerBuilder.java | 2 +- .../event/dispatch/subscriber/ListenerAssistedSubscriber.java | 2 +- .../event/dispatch/subscriber/MetaDataChangedSubscriber.java | 2 +- .../persist/{ => builder}/ClusterPersistServiceBuilder.java | 4 +++- .../{ => service}/ClusterMetaDataManagerPersistService.java | 2 +- .../persist/{ => service}/ClusterProcessPersistService.java | 2 +- .../persist/{ => service}/GlobalLockPersistService.java | 2 +- .../persist/{ => service}/ReservationPersistService.java | 2 +- .../manager/cluster/workerid/ClusterWorkerIdGenerator.java | 2 +- ....shardingsphere.mode.persist.service.PersistServiceBuilder | 2 +- .../{ => builder}/ClusterPersistServiceBuilderTest.java | 4 +++- .../ClusterMetaDataManagerPersistServiceTest.java | 2 +- .../{ => service}/ClusterProcessPersistServiceTest.java | 2 +- .../persist/{ => service}/GlobalLockPersistServiceTest.java | 2 +- .../persist/{ => service}/ReservationPersistServiceTest.java | 2 +- .../cluster/workerid/ClusterWorkerIdGeneratorTest.java | 2 +- .../{ => builder}/StandalonePersistServiceBuilder.java | 4 +++- .../StandaloneMetaDataManagerPersistService.java | 2 +- .../{ => service}/StandaloneProcessPersistService.java | 2 +- ....shardingsphere.mode.persist.service.PersistServiceBuilder | 2 +- .../{ => builder}/StandalonePersistServiceBuilderTest.java | 4 +++- .../StandaloneMetaDataManagerPersistServiceTest.java | 2 +- .../{ => service}/StandaloneProcessPersistServiceTest.java | 2 +- 24 files changed, 32 insertions(+), 24 deletions(-) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/{ => builder}/ClusterPersistServiceBuilder.java (86%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/{ => service}/ClusterMetaDataManagerPersistService.java (99%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/{ => service}/ClusterProcessPersistService.java (98%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/{ => service}/GlobalLockPersistService.java (95%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/{ => service}/ReservationPersistService.java (96%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/{ => builder}/ClusterPersistServiceBuilderTest.java (87%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/{ => service}/ClusterMetaDataManagerPersistServiceTest.java (99%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/{ => service}/ClusterProcessPersistServiceTest.java (98%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/{ => service}/GlobalLockPersistServiceTest.java (96%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/{ => service}/ReservationPersistServiceTest.java (97%) rename mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/{ => builder}/StandalonePersistServiceBuilder.java (89%) rename mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/{ => service}/StandaloneMetaDataManagerPersistService.java (99%) rename mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/{ => service}/StandaloneProcessPersistService.java (99%) rename mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/{ => builder}/StandalonePersistServiceBuilderTest.java (89%) rename mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/{ => service}/StandaloneMetaDataManagerPersistServiceTest.java (99%) rename mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/{ => service}/StandaloneProcessPersistServiceTest.java (99%) diff --git a/kernel/schedule/core/src/main/java/org/apache/shardingsphere/schedule/core/job/statistics/collect/StatisticsCollectJob.java b/kernel/schedule/core/src/main/java/org/apache/shardingsphere/schedule/core/job/statistics/collect/StatisticsCollectJob.java index 57127daecd50d..df146a3d67dc7 100644 --- a/kernel/schedule/core/src/main/java/org/apache/shardingsphere/schedule/core/job/statistics/collect/StatisticsCollectJob.java +++ b/kernel/schedule/core/src/main/java/org/apache/shardingsphere/schedule/core/job/statistics/collect/StatisticsCollectJob.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.elasticjob.simple.job.SimpleJob; import org.apache.shardingsphere.mode.lock.GlobalLockContext; import org.apache.shardingsphere.mode.manager.ContextManager; -import org.apache.shardingsphere.mode.manager.cluster.persist.GlobalLockPersistService; +import org.apache.shardingsphere.mode.manager.cluster.persist.service.GlobalLockPersistService; import org.apache.shardingsphere.mode.metadata.refresher.ShardingSphereStatisticsRefreshEngine; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; import org.apache.shardingsphere.mode.spi.PersistRepository; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java index 3723eadcf6e41..a8c574fd3a5b7 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java @@ -35,7 +35,7 @@ import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.ClusterDispatchEventSubscriberRegistry; import org.apache.shardingsphere.mode.manager.cluster.exception.MissingRequiredClusterRepositoryConfigurationException; import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener.DataChangedEventListenerRegistry; -import org.apache.shardingsphere.mode.manager.cluster.persist.GlobalLockPersistService; +import org.apache.shardingsphere.mode.manager.cluster.persist.service.GlobalLockPersistService; import org.apache.shardingsphere.mode.manager.cluster.workerid.ClusterWorkerIdGenerator; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; import org.apache.shardingsphere.mode.metadata.MetaDataContextsFactory; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ListenerAssistedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ListenerAssistedSubscriber.java index 99fb2cad6b718..0b4a567d90f3f 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ListenerAssistedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ListenerAssistedSubscriber.java @@ -27,7 +27,7 @@ import org.apache.shardingsphere.mode.lock.GlobalLockContext; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener.DatabaseMetaDataChangedListener; -import org.apache.shardingsphere.mode.manager.cluster.persist.GlobalLockPersistService; +import org.apache.shardingsphere.mode.manager.cluster.persist.service.GlobalLockPersistService; import org.apache.shardingsphere.mode.metadata.refresher.ShardingSphereStatisticsRefreshEngine; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/MetaDataChangedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/MetaDataChangedSubscriber.java index 16da01180e0d5..415db2a76efe6 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/MetaDataChangedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/MetaDataChangedSubscriber.java @@ -31,7 +31,7 @@ import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.view.DropViewEvent; import org.apache.shardingsphere.mode.lock.GlobalLockContext; import org.apache.shardingsphere.mode.manager.ContextManager; -import org.apache.shardingsphere.mode.manager.cluster.persist.GlobalLockPersistService; +import org.apache.shardingsphere.mode.manager.cluster.persist.service.GlobalLockPersistService; import org.apache.shardingsphere.mode.metadata.refresher.ShardingSphereStatisticsRefreshEngine; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/ClusterPersistServiceBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/builder/ClusterPersistServiceBuilder.java similarity index 86% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/ClusterPersistServiceBuilder.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/builder/ClusterPersistServiceBuilder.java index 3b882fa7e4bb1..85b83c85274c8 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/ClusterPersistServiceBuilder.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/builder/ClusterPersistServiceBuilder.java @@ -15,8 +15,10 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.persist; +package org.apache.shardingsphere.mode.manager.cluster.persist.builder; +import org.apache.shardingsphere.mode.manager.cluster.persist.service.ClusterMetaDataManagerPersistService; +import org.apache.shardingsphere.mode.manager.cluster.persist.service.ClusterProcessPersistService; import org.apache.shardingsphere.mode.metadata.MetaDataContextManager; import org.apache.shardingsphere.mode.persist.service.MetaDataManagerPersistService; import org.apache.shardingsphere.mode.persist.service.PersistServiceBuilder; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/ClusterMetaDataManagerPersistService.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterMetaDataManagerPersistService.java similarity index 99% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/ClusterMetaDataManagerPersistService.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterMetaDataManagerPersistService.java index 38d026812dceb..6e8bb55042376 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/ClusterMetaDataManagerPersistService.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterMetaDataManagerPersistService.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.persist; +package org.apache.shardingsphere.mode.manager.cluster.persist.service; import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; import org.apache.shardingsphere.infra.datasource.pool.destroyer.DataSourcePoolDestroyer; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/ClusterProcessPersistService.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterProcessPersistService.java similarity index 98% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/ClusterProcessPersistService.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterProcessPersistService.java index e318f8103b165..024eabbe2f653 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/ClusterProcessPersistService.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterProcessPersistService.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.persist; +package org.apache.shardingsphere.mode.manager.cluster.persist.service; import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.executor.sql.process.Process; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/GlobalLockPersistService.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/GlobalLockPersistService.java similarity index 95% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/GlobalLockPersistService.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/GlobalLockPersistService.java index 11256bf25891c..2c6e43d96f2e0 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/GlobalLockPersistService.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/GlobalLockPersistService.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.persist; +package org.apache.shardingsphere.mode.manager.cluster.persist.service; import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.mode.lock.GlobalLockDefinition; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/ReservationPersistService.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ReservationPersistService.java similarity index 96% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/ReservationPersistService.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ReservationPersistService.java index 390d0a76b05a7..e946dc9156338 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/ReservationPersistService.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ReservationPersistService.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.persist; +package org.apache.shardingsphere.mode.manager.cluster.persist.service; import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.metadata.persist.node.ReservationNode; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/workerid/ClusterWorkerIdGenerator.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/workerid/ClusterWorkerIdGenerator.java index 77cd8c8b5f467..1f9bf9f76a003 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/workerid/ClusterWorkerIdGenerator.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/workerid/ClusterWorkerIdGenerator.java @@ -22,7 +22,7 @@ import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions; import org.apache.shardingsphere.infra.instance.workerid.WorkerIdAssignedException; import org.apache.shardingsphere.infra.instance.workerid.WorkerIdGenerator; -import org.apache.shardingsphere.mode.manager.cluster.persist.ReservationPersistService; +import org.apache.shardingsphere.mode.manager.cluster.persist.service.ReservationPersistService; import org.apache.shardingsphere.mode.persist.service.ComputeNodePersistService; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; diff --git a/mode/type/cluster/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.persist.service.PersistServiceBuilder b/mode/type/cluster/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.persist.service.PersistServiceBuilder index 002053ed59878..d2c393c4c3315 100644 --- a/mode/type/cluster/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.persist.service.PersistServiceBuilder +++ b/mode/type/cluster/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.persist.service.PersistServiceBuilder @@ -15,4 +15,4 @@ # limitations under the License. # -org.apache.shardingsphere.mode.manager.cluster.persist.ClusterPersistServiceBuilder +org.apache.shardingsphere.mode.manager.cluster.persist.builder.ClusterPersistServiceBuilder diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/ClusterPersistServiceBuilderTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/builder/ClusterPersistServiceBuilderTest.java similarity index 87% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/ClusterPersistServiceBuilderTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/builder/ClusterPersistServiceBuilderTest.java index eb8a7320b6373..52752cfb3d9a0 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/ClusterPersistServiceBuilderTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/builder/ClusterPersistServiceBuilderTest.java @@ -15,9 +15,11 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.persist; +package org.apache.shardingsphere.mode.manager.cluster.persist.builder; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; +import org.apache.shardingsphere.mode.manager.cluster.persist.service.ClusterMetaDataManagerPersistService; +import org.apache.shardingsphere.mode.manager.cluster.persist.service.ClusterProcessPersistService; import org.apache.shardingsphere.mode.metadata.MetaDataContextManager; import org.apache.shardingsphere.mode.persist.service.PersistServiceBuilder; import org.apache.shardingsphere.mode.spi.PersistRepository; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/ClusterMetaDataManagerPersistServiceTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterMetaDataManagerPersistServiceTest.java similarity index 99% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/ClusterMetaDataManagerPersistServiceTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterMetaDataManagerPersistServiceTest.java index 47feac6319c60..ecc993eb25f91 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/ClusterMetaDataManagerPersistServiceTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterMetaDataManagerPersistServiceTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.persist; +package org.apache.shardingsphere.mode.manager.cluster.persist.service; import lombok.SneakyThrows; import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/ClusterProcessPersistServiceTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterProcessPersistServiceTest.java similarity index 98% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/ClusterProcessPersistServiceTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterProcessPersistServiceTest.java index e69461d3a74a8..efebb308c673e 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/ClusterProcessPersistServiceTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterProcessPersistServiceTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.persist; +package org.apache.shardingsphere.mode.manager.cluster.persist.service; import org.apache.shardingsphere.infra.executor.sql.process.Process; import org.apache.shardingsphere.infra.executor.sql.process.lock.ProcessOperationLockRegistry; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/GlobalLockPersistServiceTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/GlobalLockPersistServiceTest.java similarity index 96% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/GlobalLockPersistServiceTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/GlobalLockPersistServiceTest.java index 851face5ca088..cf68d00d9fdc1 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/GlobalLockPersistServiceTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/GlobalLockPersistServiceTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.persist; +package org.apache.shardingsphere.mode.manager.cluster.persist.service; import org.apache.shardingsphere.mode.lock.GlobalLockDefinition; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/ReservationPersistServiceTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ReservationPersistServiceTest.java similarity index 97% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/ReservationPersistServiceTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ReservationPersistServiceTest.java index 5292992d5ca20..f7c482e1c1968 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/ReservationPersistServiceTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ReservationPersistServiceTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.persist; +package org.apache.shardingsphere.mode.manager.cluster.persist.service; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; import org.apache.shardingsphere.mode.repository.cluster.exception.ClusterRepositoryPersistException; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/workerid/ClusterWorkerIdGeneratorTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/workerid/ClusterWorkerIdGeneratorTest.java index e7f4d959d2e56..c570cd422768e 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/workerid/ClusterWorkerIdGeneratorTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/workerid/ClusterWorkerIdGeneratorTest.java @@ -20,7 +20,7 @@ import lombok.SneakyThrows; import org.apache.shardingsphere.infra.instance.workerid.WorkerIdAssignedException; import org.apache.shardingsphere.infra.instance.workerid.WorkerIdGenerator; -import org.apache.shardingsphere.mode.manager.cluster.persist.ReservationPersistService; +import org.apache.shardingsphere.mode.manager.cluster.persist.service.ReservationPersistService; import org.apache.shardingsphere.mode.persist.service.ComputeNodePersistService; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; import org.apache.shardingsphere.test.util.PropertiesBuilder; diff --git a/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/StandalonePersistServiceBuilder.java b/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/builder/StandalonePersistServiceBuilder.java similarity index 89% rename from mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/StandalonePersistServiceBuilder.java rename to mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/builder/StandalonePersistServiceBuilder.java index 0b3dfa2377e2e..24b40edcb1199 100644 --- a/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/StandalonePersistServiceBuilder.java +++ b/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/builder/StandalonePersistServiceBuilder.java @@ -15,8 +15,10 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.standalone.persist; +package org.apache.shardingsphere.mode.manager.standalone.persist.builder; +import org.apache.shardingsphere.mode.manager.standalone.persist.service.StandaloneMetaDataManagerPersistService; +import org.apache.shardingsphere.mode.manager.standalone.persist.service.StandaloneProcessPersistService; import org.apache.shardingsphere.mode.metadata.MetaDataContextManager; import org.apache.shardingsphere.mode.persist.service.MetaDataManagerPersistService; import org.apache.shardingsphere.mode.persist.service.PersistServiceBuilder; diff --git a/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/StandaloneMetaDataManagerPersistService.java b/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneMetaDataManagerPersistService.java similarity index 99% rename from mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/StandaloneMetaDataManagerPersistService.java rename to mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneMetaDataManagerPersistService.java index 9e98b5621d5da..264648a1035cf 100644 --- a/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/StandaloneMetaDataManagerPersistService.java +++ b/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneMetaDataManagerPersistService.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.standalone.persist; +package org.apache.shardingsphere.mode.manager.standalone.persist.service; import com.google.common.base.Strings; import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; diff --git a/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/StandaloneProcessPersistService.java b/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneProcessPersistService.java similarity index 99% rename from mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/StandaloneProcessPersistService.java rename to mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneProcessPersistService.java index ae266ca16ffb2..87b2303ba1d33 100644 --- a/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/StandaloneProcessPersistService.java +++ b/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneProcessPersistService.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.standalone.persist; +package org.apache.shardingsphere.mode.manager.standalone.persist.service; import org.apache.shardingsphere.infra.executor.sql.process.Process; import org.apache.shardingsphere.infra.executor.sql.process.ProcessRegistry; diff --git a/mode/type/standalone/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.persist.service.PersistServiceBuilder b/mode/type/standalone/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.persist.service.PersistServiceBuilder index e34ad39d108fd..47181acf88dc0 100644 --- a/mode/type/standalone/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.persist.service.PersistServiceBuilder +++ b/mode/type/standalone/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.persist.service.PersistServiceBuilder @@ -15,4 +15,4 @@ # limitations under the License. # -org.apache.shardingsphere.mode.manager.standalone.persist.StandalonePersistServiceBuilder +org.apache.shardingsphere.mode.manager.standalone.persist.builder.StandalonePersistServiceBuilder diff --git a/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/StandalonePersistServiceBuilderTest.java b/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/builder/StandalonePersistServiceBuilderTest.java similarity index 89% rename from mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/StandalonePersistServiceBuilderTest.java rename to mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/builder/StandalonePersistServiceBuilderTest.java index d17a28878a6fb..64c262a7669da 100644 --- a/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/StandalonePersistServiceBuilderTest.java +++ b/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/builder/StandalonePersistServiceBuilderTest.java @@ -15,9 +15,11 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.standalone.persist; +package org.apache.shardingsphere.mode.manager.standalone.persist.builder; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; +import org.apache.shardingsphere.mode.manager.standalone.persist.service.StandaloneMetaDataManagerPersistService; +import org.apache.shardingsphere.mode.manager.standalone.persist.service.StandaloneProcessPersistService; import org.apache.shardingsphere.mode.metadata.MetaDataContextManager; import org.apache.shardingsphere.mode.persist.service.PersistServiceBuilder; import org.apache.shardingsphere.mode.spi.PersistRepository; diff --git a/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/StandaloneMetaDataManagerPersistServiceTest.java b/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneMetaDataManagerPersistServiceTest.java similarity index 99% rename from mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/StandaloneMetaDataManagerPersistServiceTest.java rename to mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneMetaDataManagerPersistServiceTest.java index ca3cabb712148..9d7889375c883 100644 --- a/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/StandaloneMetaDataManagerPersistServiceTest.java +++ b/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneMetaDataManagerPersistServiceTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.standalone.persist; +package org.apache.shardingsphere.mode.manager.standalone.persist.service; import lombok.SneakyThrows; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; diff --git a/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/StandaloneProcessPersistServiceTest.java b/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneProcessPersistServiceTest.java similarity index 99% rename from mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/StandaloneProcessPersistServiceTest.java rename to mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneProcessPersistServiceTest.java index da33243ea0aa8..45c6a36b44c54 100644 --- a/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/StandaloneProcessPersistServiceTest.java +++ b/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneProcessPersistServiceTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.standalone.persist; +package org.apache.shardingsphere.mode.manager.standalone.persist.service; import org.apache.shardingsphere.infra.executor.sql.process.Process; import org.apache.shardingsphere.infra.executor.sql.process.ProcessRegistry; From 9b9af8e60bfed1faf3d99dd57de58b2a360a1e71 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Fri, 13 Dec 2024 00:19:30 +0800 Subject: [PATCH 13/32] Refactor mode event package (#34034) * Refactor mode event package * Refactor mode event package --- ...ClusterDeliverEventSubscriberRegistry.java | 1 + .../DeliverQualifiedDataSourceSubscriber.java | 2 +- .../ClusterStateDispatchEventBuilder.java | 3 ++- ...ComputeNodeOnlineDispatchEventBuilder.java | 3 ++- .../ComputeNodeStateDispatchEventBuilder.java | 3 ++- .../GlobalRuleDispatchEventBuilder.java | 3 ++- .../KillProcessDispatchEventBuilder.java | 3 ++- .../ListenerAssistedDispatchEventBuilder.java | 3 ++- .../PropertiesDispatchEventBuilder.java | 3 ++- ...alifiedDataSourceDispatchEventBuilder.java | 3 ++- ...hardingSphereDataDispatchEventBuilder.java | 3 ++- .../ShowProcessListDispatchEventBuilder.java | 3 ++- .../DataChangedEventListenerRegistry.java | 2 ++ .../DatabaseMetaDataChangedListener.java | 2 +- .../GlobalMetaDataChangedListener.java | 2 +- ...lusterDispatchEventSubscriberRegistry.java | 12 +++++++++++ .../{ => type}/CacheEvictedSubscriber.java | 2 +- .../ComputeNodeStateSubscriber.java | 2 +- .../DatabaseDataChangedSubscriber.java | 2 +- ...lobalRuleConfigurationEventSubscriber.java | 2 +- .../ListenerAssistedSubscriber.java | 4 ++-- .../{ => type}/MetaDataChangedSubscriber.java | 2 +- .../ProcessListChangedSubscriber.java | 2 +- .../{ => type}/PropertiesEventSubscriber.java | 2 +- .../QualifiedDataSourceSubscriber.java | 2 +- .../{ => type}/RuleItemChangedSubscriber.java | 2 +- .../{ => type}/StateChangedSubscriber.java | 2 +- .../StorageUnitEventSubscriber.java | 2 +- ...vent.dispatch.builder.DispatchEventBuilder | 20 +++++++++---------- ...iverQualifiedDataSourceSubscriberTest.java | 2 +- .../ClusterStateDispatchEventBuilderTest.java | 2 +- ...uteNodeOnlineDispatchEventBuilderTest.java | 2 +- ...puteNodeStateDispatchEventBuilderTest.java | 2 +- .../GlobalRuleDispatchEventBuilderTest.java | 2 +- .../KillProcessDispatchEventBuilderTest.java | 2 +- ...tenerAssistedDispatchEventBuilderTest.java | 2 +- .../PropertiesDispatchEventBuilderTest.java | 2 +- ...iedDataSourceDispatchEventBuilderTest.java | 2 +- ...ingSphereDataDispatchEventBuilderTest.java | 2 +- ...owProcessListDispatchEventBuilderTest.java | 2 +- .../DataChangedEventListenerRegistryTest.java | 2 ++ .../DatabaseMetaDataChangedListenerTest.java | 2 +- .../GlobalMetaDataChangedListenerTest.java | 2 +- .../CacheEvictedSubscriberTest.java | 2 +- .../ComputeNodeStateSubscriberTest.java | 2 +- .../DatabaseDataChangedSubscriberTest.java | 2 +- ...lRuleConfigurationEventSubscriberTest.java | 2 +- .../ListenerAssistedSubscriberTest.java | 2 +- .../MetaDataChangedSubscriberTest.java | 2 +- .../ProcessListChangedSubscriberTest.java | 2 +- .../PropertiesEventSubscriberTest.java | 2 +- .../QualifiedDataSourceSubscriberTest.java | 2 +- .../RuleItemChangedSubscriberTest.java | 2 +- .../StateChangedSubscriberTest.java | 2 +- .../StorageUnitEventSubscriberTest.java | 2 +- 55 files changed, 88 insertions(+), 61 deletions(-) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/{ => type}/DeliverQualifiedDataSourceSubscriber.java (98%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/{ => type}/ClusterStateDispatchEventBuilder.java (95%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/{ => type}/ComputeNodeOnlineDispatchEventBuilder.java (96%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/{ => type}/ComputeNodeStateDispatchEventBuilder.java (96%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/{ => type}/GlobalRuleDispatchEventBuilder.java (94%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/{ => type}/KillProcessDispatchEventBuilder.java (95%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/{ => type}/ListenerAssistedDispatchEventBuilder.java (95%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/{ => type}/PropertiesDispatchEventBuilder.java (94%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/{ => type}/QualifiedDataSourceDispatchEventBuilder.java (96%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/{ => type}/ShardingSphereDataDispatchEventBuilder.java (98%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/{ => type}/ShowProcessListDispatchEventBuilder.java (96%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/{ => type}/DatabaseMetaDataChangedListener.java (99%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/{ => type}/GlobalMetaDataChangedListener.java (98%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/{ => type}/CacheEvictedSubscriber.java (98%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/{ => type}/ComputeNodeStateSubscriber.java (99%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/{ => type}/DatabaseDataChangedSubscriber.java (99%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/{ => type}/GlobalRuleConfigurationEventSubscriber.java (99%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/{ => type}/ListenerAssistedSubscriber.java (98%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/{ => type}/MetaDataChangedSubscriber.java (99%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/{ => type}/ProcessListChangedSubscriber.java (99%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/{ => type}/PropertiesEventSubscriber.java (98%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/{ => type}/QualifiedDataSourceSubscriber.java (99%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/{ => type}/RuleItemChangedSubscriber.java (98%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/{ => type}/StateChangedSubscriber.java (98%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/{ => type}/StorageUnitEventSubscriber.java (99%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/{ => type}/DeliverQualifiedDataSourceSubscriberTest.java (98%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/{ => type}/ClusterStateDispatchEventBuilderTest.java (99%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/{ => type}/ComputeNodeOnlineDispatchEventBuilderTest.java (99%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/{ => type}/ComputeNodeStateDispatchEventBuilderTest.java (99%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/{ => type}/GlobalRuleDispatchEventBuilderTest.java (99%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/{ => type}/KillProcessDispatchEventBuilderTest.java (99%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/{ => type}/ListenerAssistedDispatchEventBuilderTest.java (99%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/{ => type}/PropertiesDispatchEventBuilderTest.java (99%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/{ => type}/QualifiedDataSourceDispatchEventBuilderTest.java (99%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/{ => type}/ShardingSphereDataDispatchEventBuilderTest.java (99%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/{ => type}/ShowProcessListDispatchEventBuilderTest.java (99%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/{ => type}/DatabaseMetaDataChangedListenerTest.java (99%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/{ => type}/GlobalMetaDataChangedListenerTest.java (99%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/{ => type}/CacheEvictedSubscriberTest.java (98%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/{ => type}/ComputeNodeStateSubscriberTest.java (99%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/{ => type}/DatabaseDataChangedSubscriberTest.java (99%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/{ => type}/GlobalRuleConfigurationEventSubscriberTest.java (99%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/{ => type}/ListenerAssistedSubscriberTest.java (99%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/{ => type}/MetaDataChangedSubscriberTest.java (99%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/{ => type}/ProcessListChangedSubscriberTest.java (99%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/{ => type}/PropertiesEventSubscriberTest.java (98%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/{ => type}/QualifiedDataSourceSubscriberTest.java (99%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/{ => type}/RuleItemChangedSubscriberTest.java (99%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/{ => type}/StateChangedSubscriberTest.java (98%) rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/{ => type}/StorageUnitEventSubscriberTest.java (99%) diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/ClusterDeliverEventSubscriberRegistry.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/ClusterDeliverEventSubscriberRegistry.java index 490dc709411d9..3f874da0067fe 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/ClusterDeliverEventSubscriberRegistry.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/ClusterDeliverEventSubscriberRegistry.java @@ -19,6 +19,7 @@ import lombok.Getter; import org.apache.shardingsphere.infra.util.eventbus.EventSubscriber; +import org.apache.shardingsphere.mode.manager.cluster.event.deliver.subscriber.type.DeliverQualifiedDataSourceSubscriber; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; import java.util.Collection; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/DeliverQualifiedDataSourceSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/type/DeliverQualifiedDataSourceSubscriber.java similarity index 98% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/DeliverQualifiedDataSourceSubscriber.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/type/DeliverQualifiedDataSourceSubscriber.java index 374867a36ed0c..252173f110531 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/DeliverQualifiedDataSourceSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/type/DeliverQualifiedDataSourceSubscriber.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.deliver.subscriber; +package org.apache.shardingsphere.mode.manager.cluster.event.deliver.subscriber.type; import com.google.common.eventbus.Subscribe; import lombok.RequiredArgsConstructor; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ClusterStateDispatchEventBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ClusterStateDispatchEventBuilder.java similarity index 95% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ClusterStateDispatchEventBuilder.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ClusterStateDispatchEventBuilder.java index f59b38bd104d8..2ad311b44ba1d 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ClusterStateDispatchEventBuilder.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ClusterStateDispatchEventBuilder.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type; import org.apache.shardingsphere.infra.state.cluster.ClusterState; import org.apache.shardingsphere.metadata.persist.node.StatesNode; @@ -23,6 +23,7 @@ import org.apache.shardingsphere.mode.event.DataChangedEvent.Type; import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; import org.apache.shardingsphere.mode.event.dispatch.state.cluster.ClusterStateEvent; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.DispatchEventBuilder; import java.util.Arrays; import java.util.Collection; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ComputeNodeOnlineDispatchEventBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ComputeNodeOnlineDispatchEventBuilder.java similarity index 96% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ComputeNodeOnlineDispatchEventBuilder.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ComputeNodeOnlineDispatchEventBuilder.java index fe4c2e8c9572b..99e65f7619ff1 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ComputeNodeOnlineDispatchEventBuilder.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ComputeNodeOnlineDispatchEventBuilder.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type; import org.apache.shardingsphere.infra.instance.ComputeNodeData; import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData; @@ -30,6 +30,7 @@ import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; import org.apache.shardingsphere.mode.event.dispatch.state.compute.instance.InstanceOfflineEvent; import org.apache.shardingsphere.mode.event.dispatch.state.compute.instance.InstanceOnlineEvent; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.DispatchEventBuilder; import java.util.Arrays; import java.util.Collection; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ComputeNodeStateDispatchEventBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ComputeNodeStateDispatchEventBuilder.java similarity index 96% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ComputeNodeStateDispatchEventBuilder.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ComputeNodeStateDispatchEventBuilder.java index b734e010986b4..ae3507e3406d1 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ComputeNodeStateDispatchEventBuilder.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ComputeNodeStateDispatchEventBuilder.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type; import com.google.common.base.Strings; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; @@ -26,6 +26,7 @@ import org.apache.shardingsphere.mode.event.dispatch.state.compute.ComputeNodeInstanceStateChangedEvent; import org.apache.shardingsphere.mode.event.dispatch.state.compute.LabelsEvent; import org.apache.shardingsphere.mode.event.dispatch.state.compute.WorkerIdEvent; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.DispatchEventBuilder; import java.util.ArrayList; import java.util.Arrays; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/GlobalRuleDispatchEventBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/GlobalRuleDispatchEventBuilder.java similarity index 94% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/GlobalRuleDispatchEventBuilder.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/GlobalRuleDispatchEventBuilder.java index cad0a049df7f0..c9652ad45fb79 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/GlobalRuleDispatchEventBuilder.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/GlobalRuleDispatchEventBuilder.java @@ -15,13 +15,14 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type; import org.apache.shardingsphere.metadata.persist.node.GlobalNode; import org.apache.shardingsphere.mode.event.DataChangedEvent; import org.apache.shardingsphere.mode.event.DataChangedEvent.Type; import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; import org.apache.shardingsphere.mode.event.dispatch.config.AlterGlobalRuleConfigurationEvent; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.DispatchEventBuilder; import org.apache.shardingsphere.mode.path.GlobalNodePath; import java.util.Arrays; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/KillProcessDispatchEventBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/KillProcessDispatchEventBuilder.java similarity index 95% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/KillProcessDispatchEventBuilder.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/KillProcessDispatchEventBuilder.java index ed4230257ec5d..19af769322733 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/KillProcessDispatchEventBuilder.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/KillProcessDispatchEventBuilder.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type; import org.apache.shardingsphere.metadata.persist.node.ComputeNode; import org.apache.shardingsphere.mode.event.DataChangedEvent; @@ -23,6 +23,7 @@ import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; import org.apache.shardingsphere.mode.event.dispatch.state.compute.KillLocalProcessCompletedEvent; import org.apache.shardingsphere.mode.event.dispatch.state.compute.KillLocalProcessEvent; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.DispatchEventBuilder; import java.util.Arrays; import java.util.Collection; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ListenerAssistedDispatchEventBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ListenerAssistedDispatchEventBuilder.java similarity index 95% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ListenerAssistedDispatchEventBuilder.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ListenerAssistedDispatchEventBuilder.java index 2ef539e489743..79d98eabd8bb3 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ListenerAssistedDispatchEventBuilder.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ListenerAssistedDispatchEventBuilder.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; import org.apache.shardingsphere.metadata.persist.node.StatesNode; @@ -24,6 +24,7 @@ import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; import org.apache.shardingsphere.mode.event.dispatch.assisted.CreateDatabaseListenerAssistedEvent; import org.apache.shardingsphere.mode.event.dispatch.assisted.DropDatabaseListenerAssistedEvent; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.DispatchEventBuilder; import org.apache.shardingsphere.mode.persist.pojo.ListenerAssisted; import org.apache.shardingsphere.mode.persist.pojo.ListenerAssistedType; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/PropertiesDispatchEventBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/PropertiesDispatchEventBuilder.java similarity index 94% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/PropertiesDispatchEventBuilder.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/PropertiesDispatchEventBuilder.java index 6f6dc31576dcc..fd6783c016132 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/PropertiesDispatchEventBuilder.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/PropertiesDispatchEventBuilder.java @@ -15,12 +15,13 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type; import org.apache.shardingsphere.metadata.persist.node.GlobalNode; import org.apache.shardingsphere.mode.event.DataChangedEvent; import org.apache.shardingsphere.mode.event.DataChangedEvent.Type; import org.apache.shardingsphere.mode.event.dispatch.config.AlterPropertiesEvent; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.DispatchEventBuilder; import org.apache.shardingsphere.mode.path.GlobalNodePath; import java.util.Arrays; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/QualifiedDataSourceDispatchEventBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/QualifiedDataSourceDispatchEventBuilder.java similarity index 96% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/QualifiedDataSourceDispatchEventBuilder.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/QualifiedDataSourceDispatchEventBuilder.java index 5c2cad7adf1fc..cab6b92954a91 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/QualifiedDataSourceDispatchEventBuilder.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/QualifiedDataSourceDispatchEventBuilder.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type; import com.google.common.base.Strings; import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource; @@ -28,6 +28,7 @@ import org.apache.shardingsphere.mode.event.DataChangedEvent.Type; import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; import org.apache.shardingsphere.mode.event.dispatch.state.storage.QualifiedDataSourceStateEvent; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.DispatchEventBuilder; import java.util.Arrays; import java.util.Collection; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ShardingSphereDataDispatchEventBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ShardingSphereDataDispatchEventBuilder.java similarity index 98% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ShardingSphereDataDispatchEventBuilder.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ShardingSphereDataDispatchEventBuilder.java index 5c599450b24a7..0ccb037e1dd8e 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ShardingSphereDataDispatchEventBuilder.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ShardingSphereDataDispatchEventBuilder.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type; import com.google.common.base.Strings; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; @@ -31,6 +31,7 @@ import org.apache.shardingsphere.mode.event.dispatch.metadata.data.ShardingSphereRowDataChangedEvent; import org.apache.shardingsphere.mode.event.dispatch.metadata.data.ShardingSphereRowDataDeletedEvent; import org.apache.shardingsphere.mode.event.dispatch.metadata.data.TableDataChangedEvent; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.DispatchEventBuilder; import java.util.Arrays; import java.util.Collection; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ShowProcessListDispatchEventBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ShowProcessListDispatchEventBuilder.java similarity index 96% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ShowProcessListDispatchEventBuilder.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ShowProcessListDispatchEventBuilder.java index 69f0d72150658..3be60739efee5 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ShowProcessListDispatchEventBuilder.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ShowProcessListDispatchEventBuilder.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type; import org.apache.shardingsphere.metadata.persist.node.ComputeNode; import org.apache.shardingsphere.mode.event.DataChangedEvent; @@ -23,6 +23,7 @@ import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; import org.apache.shardingsphere.mode.event.dispatch.state.compute.ReportLocalProcessesCompletedEvent; import org.apache.shardingsphere.mode.event.dispatch.state.compute.ReportLocalProcessesEvent; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.DispatchEventBuilder; import java.util.Arrays; import java.util.Collection; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/DataChangedEventListenerRegistry.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/DataChangedEventListenerRegistry.java index 6fbc64978a7fb..7daeb327d3471 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/DataChangedEventListenerRegistry.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/DataChangedEventListenerRegistry.java @@ -22,6 +22,8 @@ import org.apache.shardingsphere.metadata.persist.node.DatabaseMetaDataNode; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.DispatchEventBuilder; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener.type.DatabaseMetaDataChangedListener; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener.type.GlobalMetaDataChangedListener; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; import java.util.Collection; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/DatabaseMetaDataChangedListener.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListener.java similarity index 99% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/DatabaseMetaDataChangedListener.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListener.java index 14bf9d21c16d7..f17735beb28c7 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/DatabaseMetaDataChangedListener.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListener.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener.type; import com.google.common.base.Preconditions; import lombok.RequiredArgsConstructor; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/GlobalMetaDataChangedListener.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/GlobalMetaDataChangedListener.java similarity index 98% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/GlobalMetaDataChangedListener.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/GlobalMetaDataChangedListener.java index 82baefae06fca..cea2df2bbe04b 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/GlobalMetaDataChangedListener.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/GlobalMetaDataChangedListener.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener.type; import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.util.eventbus.EventBusContext; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ClusterDispatchEventSubscriberRegistry.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ClusterDispatchEventSubscriberRegistry.java index 178570194da95..efe9292425a27 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ClusterDispatchEventSubscriberRegistry.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ClusterDispatchEventSubscriberRegistry.java @@ -20,6 +20,18 @@ import lombok.Getter; import org.apache.shardingsphere.infra.util.eventbus.EventSubscriber; import org.apache.shardingsphere.mode.manager.ContextManager; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type.CacheEvictedSubscriber; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type.ComputeNodeStateSubscriber; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type.DatabaseDataChangedSubscriber; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type.GlobalRuleConfigurationEventSubscriber; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type.ListenerAssistedSubscriber; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type.MetaDataChangedSubscriber; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type.ProcessListChangedSubscriber; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type.PropertiesEventSubscriber; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type.QualifiedDataSourceSubscriber; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type.RuleItemChangedSubscriber; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type.StateChangedSubscriber; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type.StorageUnitEventSubscriber; import java.util.Arrays; import java.util.Collection; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/CacheEvictedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/CacheEvictedSubscriber.java similarity index 98% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/CacheEvictedSubscriber.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/CacheEvictedSubscriber.java index 848bc0169e2f9..de796a986f23d 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/CacheEvictedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/CacheEvictedSubscriber.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type; import com.google.common.eventbus.Subscribe; import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ComputeNodeStateSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/ComputeNodeStateSubscriber.java similarity index 99% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ComputeNodeStateSubscriber.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/ComputeNodeStateSubscriber.java index eb42494dc3d54..6eb8b274a64dc 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ComputeNodeStateSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/ComputeNodeStateSubscriber.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type; import com.google.common.eventbus.Subscribe; import lombok.RequiredArgsConstructor; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/DatabaseDataChangedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/DatabaseDataChangedSubscriber.java similarity index 99% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/DatabaseDataChangedSubscriber.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/DatabaseDataChangedSubscriber.java index 870ea1b802f55..c092df8e8985e 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/DatabaseDataChangedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/DatabaseDataChangedSubscriber.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type; import com.google.common.eventbus.Subscribe; import lombok.RequiredArgsConstructor; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/GlobalRuleConfigurationEventSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/GlobalRuleConfigurationEventSubscriber.java similarity index 99% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/GlobalRuleConfigurationEventSubscriber.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/GlobalRuleConfigurationEventSubscriber.java index 5a5a3825dea5d..eeff01817b06a 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/GlobalRuleConfigurationEventSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/GlobalRuleConfigurationEventSubscriber.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type; import com.google.common.base.Preconditions; import com.google.common.eventbus.Subscribe; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ListenerAssistedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/ListenerAssistedSubscriber.java similarity index 98% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ListenerAssistedSubscriber.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/ListenerAssistedSubscriber.java index 0b4a567d90f3f..b500cad5b03e0 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ListenerAssistedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/ListenerAssistedSubscriber.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type; import com.google.common.eventbus.Subscribe; import lombok.RequiredArgsConstructor; @@ -26,7 +26,7 @@ import org.apache.shardingsphere.mode.event.dispatch.assisted.DropDatabaseListenerAssistedEvent; import org.apache.shardingsphere.mode.lock.GlobalLockContext; import org.apache.shardingsphere.mode.manager.ContextManager; -import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener.DatabaseMetaDataChangedListener; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener.type.DatabaseMetaDataChangedListener; import org.apache.shardingsphere.mode.manager.cluster.persist.service.GlobalLockPersistService; import org.apache.shardingsphere.mode.metadata.refresher.ShardingSphereStatisticsRefreshEngine; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/MetaDataChangedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/MetaDataChangedSubscriber.java similarity index 99% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/MetaDataChangedSubscriber.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/MetaDataChangedSubscriber.java index 415db2a76efe6..59fb7baff17e5 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/MetaDataChangedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/MetaDataChangedSubscriber.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type; import com.google.common.base.Preconditions; import com.google.common.eventbus.Subscribe; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ProcessListChangedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/ProcessListChangedSubscriber.java similarity index 99% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ProcessListChangedSubscriber.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/ProcessListChangedSubscriber.java index 65cbb902a9c2a..ba8bd0a3cf3a3 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ProcessListChangedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/ProcessListChangedSubscriber.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type; import com.google.common.eventbus.Subscribe; import lombok.RequiredArgsConstructor; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/PropertiesEventSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/PropertiesEventSubscriber.java similarity index 98% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/PropertiesEventSubscriber.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/PropertiesEventSubscriber.java index c0a066feabc40..9f20377a7d0e7 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/PropertiesEventSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/PropertiesEventSubscriber.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type; import com.google.common.base.Preconditions; import com.google.common.eventbus.Subscribe; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/QualifiedDataSourceSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/QualifiedDataSourceSubscriber.java similarity index 99% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/QualifiedDataSourceSubscriber.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/QualifiedDataSourceSubscriber.java index 1b0af0cca00ff..a354fa0a0ca30 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/QualifiedDataSourceSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/QualifiedDataSourceSubscriber.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type; import com.google.common.base.Preconditions; import com.google.common.eventbus.Subscribe; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/RuleItemChangedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/RuleItemChangedSubscriber.java similarity index 98% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/RuleItemChangedSubscriber.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/RuleItemChangedSubscriber.java index 4d29f764dc141..3d84d50e1a030 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/RuleItemChangedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/RuleItemChangedSubscriber.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type; import com.google.common.eventbus.Subscribe; import lombok.RequiredArgsConstructor; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/StateChangedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/StateChangedSubscriber.java similarity index 98% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/StateChangedSubscriber.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/StateChangedSubscriber.java index 1d2e7abb8cdae..05f0d9d2cb5d0 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/StateChangedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/StateChangedSubscriber.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type; import com.google.common.eventbus.Subscribe; import org.apache.shardingsphere.infra.util.eventbus.EventSubscriber; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/StorageUnitEventSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/StorageUnitEventSubscriber.java similarity index 99% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/StorageUnitEventSubscriber.java rename to mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/StorageUnitEventSubscriber.java index d1ad60852ad52..9c8d9d82da7c6 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/StorageUnitEventSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/StorageUnitEventSubscriber.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type; import com.google.common.base.Preconditions; import com.google.common.eventbus.Subscribe; diff --git a/mode/type/cluster/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.DispatchEventBuilder b/mode/type/cluster/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.DispatchEventBuilder index bfbe576976707..8b04a9c552eec 100644 --- a/mode/type/cluster/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.DispatchEventBuilder +++ b/mode/type/cluster/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.DispatchEventBuilder @@ -15,13 +15,13 @@ # limitations under the License. # -org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.QualifiedDataSourceDispatchEventBuilder -org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.ComputeNodeStateDispatchEventBuilder -org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.ClusterStateDispatchEventBuilder -org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.ShardingSphereDataDispatchEventBuilder -org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.GlobalRuleDispatchEventBuilder -org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.PropertiesDispatchEventBuilder -org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.ListenerAssistedDispatchEventBuilder -org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.ComputeNodeOnlineDispatchEventBuilder -org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.ShowProcessListDispatchEventBuilder -org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.KillProcessDispatchEventBuilder +org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type.QualifiedDataSourceDispatchEventBuilder +org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type.ComputeNodeStateDispatchEventBuilder +org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type.ClusterStateDispatchEventBuilder +org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type.ShardingSphereDataDispatchEventBuilder +org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type.GlobalRuleDispatchEventBuilder +org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type.PropertiesDispatchEventBuilder +org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type.ListenerAssistedDispatchEventBuilder +org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type.ComputeNodeOnlineDispatchEventBuilder +org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type.ShowProcessListDispatchEventBuilder +org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type.KillProcessDispatchEventBuilder diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/DeliverQualifiedDataSourceSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/type/DeliverQualifiedDataSourceSubscriberTest.java similarity index 98% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/DeliverQualifiedDataSourceSubscriberTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/type/DeliverQualifiedDataSourceSubscriberTest.java index 7325fd1ca84bb..f9d25ff1cf5c0 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/DeliverQualifiedDataSourceSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/type/DeliverQualifiedDataSourceSubscriberTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.deliver.subscriber; +package org.apache.shardingsphere.mode.manager.cluster.event.deliver.subscriber.type; import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource; import org.apache.shardingsphere.mode.event.deliver.datasource.qualified.QualifiedDataSourceDeletedEvent; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ClusterStateDispatchEventBuilderTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ClusterStateDispatchEventBuilderTest.java similarity index 99% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ClusterStateDispatchEventBuilderTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ClusterStateDispatchEventBuilderTest.java index 9f6cdcd96fc8c..aad9757d62766 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ClusterStateDispatchEventBuilderTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ClusterStateDispatchEventBuilderTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type; import org.apache.shardingsphere.infra.state.cluster.ClusterState; import org.apache.shardingsphere.mode.event.DataChangedEvent; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ComputeNodeOnlineDispatchEventBuilderTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ComputeNodeOnlineDispatchEventBuilderTest.java similarity index 99% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ComputeNodeOnlineDispatchEventBuilderTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ComputeNodeOnlineDispatchEventBuilderTest.java index 08f8fbb2c63e3..6f2cf795b2b10 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ComputeNodeOnlineDispatchEventBuilderTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ComputeNodeOnlineDispatchEventBuilderTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type; import org.apache.shardingsphere.infra.instance.metadata.InstanceType; import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ComputeNodeStateDispatchEventBuilderTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ComputeNodeStateDispatchEventBuilderTest.java similarity index 99% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ComputeNodeStateDispatchEventBuilderTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ComputeNodeStateDispatchEventBuilderTest.java index 0349b33fb9251..faab13d4a2d71 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ComputeNodeStateDispatchEventBuilderTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ComputeNodeStateDispatchEventBuilderTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type; import org.apache.shardingsphere.infra.state.instance.InstanceState; import org.apache.shardingsphere.infra.util.yaml.YamlEngine; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/GlobalRuleDispatchEventBuilderTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/GlobalRuleDispatchEventBuilderTest.java similarity index 99% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/GlobalRuleDispatchEventBuilderTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/GlobalRuleDispatchEventBuilderTest.java index 21863e9293ebe..011e644bdb7d9 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/GlobalRuleDispatchEventBuilderTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/GlobalRuleDispatchEventBuilderTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type; import org.apache.shardingsphere.mode.event.DataChangedEvent; import org.apache.shardingsphere.mode.event.DataChangedEvent.Type; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/KillProcessDispatchEventBuilderTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/KillProcessDispatchEventBuilderTest.java similarity index 99% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/KillProcessDispatchEventBuilderTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/KillProcessDispatchEventBuilderTest.java index 0afd4ab98804e..f4ed553625cc3 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/KillProcessDispatchEventBuilderTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/KillProcessDispatchEventBuilderTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type; import org.apache.shardingsphere.metadata.persist.node.ComputeNode; import org.apache.shardingsphere.mode.event.DataChangedEvent; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ListenerAssistedDispatchEventBuilderTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ListenerAssistedDispatchEventBuilderTest.java similarity index 99% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ListenerAssistedDispatchEventBuilderTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ListenerAssistedDispatchEventBuilderTest.java index 1c0b76cfefe60..7fdfd5fc24f99 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ListenerAssistedDispatchEventBuilderTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ListenerAssistedDispatchEventBuilderTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type; import org.apache.shardingsphere.mode.event.DataChangedEvent; import org.apache.shardingsphere.mode.event.DataChangedEvent.Type; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/PropertiesDispatchEventBuilderTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/PropertiesDispatchEventBuilderTest.java similarity index 99% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/PropertiesDispatchEventBuilderTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/PropertiesDispatchEventBuilderTest.java index 443f8752abdd9..5b3bcbd53e2a6 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/PropertiesDispatchEventBuilderTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/PropertiesDispatchEventBuilderTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type; import org.apache.shardingsphere.mode.event.DataChangedEvent; import org.apache.shardingsphere.mode.event.DataChangedEvent.Type; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/QualifiedDataSourceDispatchEventBuilderTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/QualifiedDataSourceDispatchEventBuilderTest.java similarity index 99% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/QualifiedDataSourceDispatchEventBuilderTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/QualifiedDataSourceDispatchEventBuilderTest.java index 3f94f3f30efd1..ad3d7fe64742e 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/QualifiedDataSourceDispatchEventBuilderTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/QualifiedDataSourceDispatchEventBuilderTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type; import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; import org.apache.shardingsphere.infra.state.datasource.DataSourceState; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ShardingSphereDataDispatchEventBuilderTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ShardingSphereDataDispatchEventBuilderTest.java similarity index 99% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ShardingSphereDataDispatchEventBuilderTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ShardingSphereDataDispatchEventBuilderTest.java index d2bd219f7e6b9..dc2d3824fa06f 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ShardingSphereDataDispatchEventBuilderTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ShardingSphereDataDispatchEventBuilderTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type; import org.apache.shardingsphere.mode.event.DataChangedEvent; import org.apache.shardingsphere.mode.event.DataChangedEvent.Type; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ShowProcessListDispatchEventBuilderTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ShowProcessListDispatchEventBuilderTest.java similarity index 99% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ShowProcessListDispatchEventBuilderTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ShowProcessListDispatchEventBuilderTest.java index 3489950b1a779..f6a3165437c6b 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/ShowProcessListDispatchEventBuilderTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/builder/type/ShowProcessListDispatchEventBuilderTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.builder.type; import org.apache.shardingsphere.metadata.persist.node.ComputeNode; import org.apache.shardingsphere.mode.event.DataChangedEvent; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/DataChangedEventListenerRegistryTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/DataChangedEventListenerRegistryTest.java index 4f2191b9f29b4..7cf9672d944b8 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/DataChangedEventListenerRegistryTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/DataChangedEventListenerRegistryTest.java @@ -18,6 +18,8 @@ package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener; import org.apache.shardingsphere.mode.manager.ContextManager; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener.type.DatabaseMetaDataChangedListener; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener.type.GlobalMetaDataChangedListener; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; import org.junit.jupiter.api.Test; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/DatabaseMetaDataChangedListenerTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListenerTest.java similarity index 99% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/DatabaseMetaDataChangedListenerTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListenerTest.java index ae80280424661..b0f36cb514e02 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/DatabaseMetaDataChangedListenerTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListenerTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener.type; import lombok.SneakyThrows; import org.apache.shardingsphere.infra.util.eventbus.EventBusContext; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/GlobalMetaDataChangedListenerTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/GlobalMetaDataChangedListenerTest.java similarity index 99% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/GlobalMetaDataChangedListenerTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/GlobalMetaDataChangedListenerTest.java index da92e8c510d11..14ea417fa5771 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/GlobalMetaDataChangedListenerTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/GlobalMetaDataChangedListenerTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener.type; import org.apache.shardingsphere.infra.util.eventbus.EventBusContext; import org.apache.shardingsphere.mode.event.DataChangedEvent; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/CacheEvictedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/CacheEvictedSubscriberTest.java similarity index 98% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/CacheEvictedSubscriberTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/CacheEvictedSubscriberTest.java index 5e4c99c7b7c64..78ae91f2135f8 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/CacheEvictedSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/CacheEvictedSubscriberTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type; import org.apache.shardingsphere.infra.util.eventbus.EventBusContext; import org.apache.shardingsphere.infra.spi.type.ordered.cache.OrderedServicesCache; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ComputeNodeStateSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/ComputeNodeStateSubscriberTest.java similarity index 99% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ComputeNodeStateSubscriberTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/ComputeNodeStateSubscriberTest.java index f1d8102bde398..528f71cc98b7d 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ComputeNodeStateSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/ComputeNodeStateSubscriberTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type; import org.apache.shardingsphere.infra.instance.ComputeNodeInstance; import org.apache.shardingsphere.infra.instance.metadata.InstanceMetaData; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/DatabaseDataChangedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/DatabaseDataChangedSubscriberTest.java similarity index 99% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/DatabaseDataChangedSubscriberTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/DatabaseDataChangedSubscriberTest.java index 8b6120b4e524a..9d7bd49f1be7c 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/DatabaseDataChangedSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/DatabaseDataChangedSubscriberTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type; import org.apache.shardingsphere.infra.yaml.data.pojo.YamlShardingSphereRowData; import org.apache.shardingsphere.mode.event.dispatch.metadata.data.DatabaseDataAddedEvent; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/GlobalRuleConfigurationEventSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/GlobalRuleConfigurationEventSubscriberTest.java similarity index 99% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/GlobalRuleConfigurationEventSubscriberTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/GlobalRuleConfigurationEventSubscriberTest.java index 7fa43bf8ed56e..588a7f4cd31ad 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/GlobalRuleConfigurationEventSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/GlobalRuleConfigurationEventSubscriberTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type; import org.apache.shardingsphere.infra.config.rule.RuleConfiguration; import org.apache.shardingsphere.mode.event.dispatch.config.AlterGlobalRuleConfigurationEvent; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ListenerAssistedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/ListenerAssistedSubscriberTest.java similarity index 99% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ListenerAssistedSubscriberTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/ListenerAssistedSubscriberTest.java index 36fdb66f04a12..6debc68126376 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ListenerAssistedSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/ListenerAssistedSubscriberTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type; import org.apache.shardingsphere.infra.instance.metadata.InstanceType; import org.apache.shardingsphere.mode.event.dispatch.assisted.CreateDatabaseListenerAssistedEvent; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/MetaDataChangedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/MetaDataChangedSubscriberTest.java similarity index 99% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/MetaDataChangedSubscriberTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/MetaDataChangedSubscriberTest.java index 76a68c1c28c7e..12cf7bbfb7c86 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/MetaDataChangedSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/MetaDataChangedSubscriberTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type; import org.apache.shardingsphere.infra.config.props.temporary.TemporaryConfigurationPropertyKey; import org.apache.shardingsphere.infra.instance.metadata.InstanceType; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ProcessListChangedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/ProcessListChangedSubscriberTest.java similarity index 99% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ProcessListChangedSubscriberTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/ProcessListChangedSubscriberTest.java index 312558fcccf03..63d069f8a1c2e 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/ProcessListChangedSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/ProcessListChangedSubscriberTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type; import org.apache.shardingsphere.infra.executor.sql.process.Process; import org.apache.shardingsphere.infra.executor.sql.process.ProcessRegistry; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/PropertiesEventSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/PropertiesEventSubscriberTest.java similarity index 98% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/PropertiesEventSubscriberTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/PropertiesEventSubscriberTest.java index d806217958229..a2267d31a078b 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/PropertiesEventSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/PropertiesEventSubscriberTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type; import org.apache.shardingsphere.mode.event.dispatch.config.AlterPropertiesEvent; import org.apache.shardingsphere.mode.manager.ContextManager; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/QualifiedDataSourceSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/QualifiedDataSourceSubscriberTest.java similarity index 99% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/QualifiedDataSourceSubscriberTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/QualifiedDataSourceSubscriberTest.java index 5bc11d56106bf..05fe5b9b8852a 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/QualifiedDataSourceSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/QualifiedDataSourceSubscriberTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type; import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource; import org.apache.shardingsphere.infra.rule.attribute.datasource.StaticDataSourceRuleAttribute; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/RuleItemChangedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/RuleItemChangedSubscriberTest.java similarity index 99% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/RuleItemChangedSubscriberTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/RuleItemChangedSubscriberTest.java index 31b31a4ad5f61..a4b209a94270a 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/RuleItemChangedSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/RuleItemChangedSubscriberTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type; import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterRuleItemEvent; import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropRuleItemEvent; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/StateChangedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/StateChangedSubscriberTest.java similarity index 98% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/StateChangedSubscriberTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/StateChangedSubscriberTest.java index 21cd42d97fc97..8567b2ca8c9f5 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/StateChangedSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/StateChangedSubscriberTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type; import org.apache.shardingsphere.infra.state.cluster.ClusterState; import org.apache.shardingsphere.mode.event.dispatch.state.cluster.ClusterStateEvent; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/StorageUnitEventSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/StorageUnitEventSubscriberTest.java similarity index 99% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/StorageUnitEventSubscriberTest.java rename to mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/StorageUnitEventSubscriberTest.java index f119fd9217bf7..df1805f191e57 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/StorageUnitEventSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/StorageUnitEventSubscriberTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber; +package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type; import org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties; import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.AlterStorageUnitEvent; From f23d90899da4ae25037b4201bf1ddbe17296743e Mon Sep 17 00:00:00 2001 From: Zhengqiang Duan Date: Fri, 13 Dec 2024 09:19:41 +0800 Subject: [PATCH 14/32] Add TableSegmentBoundInfo for TableNameSegment and modify TablesContext logic (#34026) * Add TableSegmentBoundInfo for TableNameSegment and modify TablesContext logic * fix unit test * fix unit test * fix unit test --- .../BroadcastRouteEngineFactoryTest.java | 5 +- ...ncryptOrderByItemSupportedCheckerTest.java | 2 +- .../EncryptGeneratorFixtureBuilder.java | 2 +- .../EncryptProjectionTokenGeneratorTest.java | 6 +- .../EncryptGroupByItemTokenGeneratorTest.java | 2 +- ...LStatementDataSourceMappingsRetriever.java | 6 +- ...tStatementDataSourceMappingsRetriever.java | 16 +--- ...tementDataSourceMappingsRetrieverTest.java | 31 ++++--- ...hardingAlterIndexSupportedCheckerTest.java | 6 +- ...hardingAlterTableSupportedCheckerTest.java | 2 +- ...ShardingAlterViewSupportedCheckerTest.java | 6 +- ...ingCreateFunctionSupportedCheckerTest.java | 8 +- ...ardingCreateIndexSupportedCheckerTest.java | 12 +-- ...ngCreateProcedureSupportedCheckerTest.java | 8 +- ...ardingCreateTableSupportedCheckerTest.java | 4 +- ...ShardingDropIndexSupportedCheckerTest.java | 4 +- ...ShardingDropTableSupportedCheckerTest.java | 2 +- .../ShardingInsertSupportedCheckerTest.java | 4 +- ...ardingRenameTableSupportedCheckerTest.java | 2 +- .../dml/ShardingCopySupportedCheckerTest.java | 6 +- .../ShardingDeleteSupportedCheckerTest.java | 2 +- .../ShardingLoadDataSupportedCheckerTest.java | 4 +- .../ShardingLoadXmlSupportedCheckerTest.java | 4 +- .../ShardingUpdateSupportedCheckerTest.java | 4 +- .../ddl/ShardingDDLResultMergerTest.java | 2 +- .../fetch/FetchStreamMergedResultTest.java | 2 +- ...dingAlterTableRouteContextCheckerTest.java | 4 +- ...ingCreateTableRouteContextCheckerTest.java | 6 +- ...rdingDropIndexRouteContextCheckerTest.java | 4 +- ...rdingDropTableRouteContextCheckerTest.java | 8 +- ...ingRenameTableRouteContextCheckerTest.java | 2 +- ...ShardingUpdateRouteContextCheckerTest.java | 6 +- .../type/ShardingRouteEngineFactoryTest.java | 2 +- .../sharding/rule/ShardingRuleTest.java | 2 +- .../context/segment/table/TablesContext.java | 40 +++------ .../statement/SQLStatementContextFactory.java | 74 ++++++++-------- .../dal/AnalyzeTableStatementContext.java | 4 +- .../dal/ExplainStatementContext.java | 4 +- .../statement/dal/FlushStatementContext.java | 4 +- .../dal/OptimizeTableStatementContext.java | 4 +- .../dal/ShowColumnsStatementContext.java | 4 +- .../dal/ShowCreateTableStatementContext.java | 4 +- .../dal/ShowIndexStatementContext.java | 4 +- .../dcl/DenyUserStatementContext.java | 4 +- .../statement/dcl/GrantStatementContext.java | 4 +- .../statement/dcl/RevokeStatementContext.java | 4 +- .../ddl/AlterIndexStatementContext.java | 4 +- .../ddl/AlterTableStatementContext.java | 4 +- .../ddl/AlterViewStatementContext.java | 4 +- .../statement/ddl/CloseStatementContext.java | 4 +- .../ddl/CommentStatementContext.java | 4 +- .../ddl/CreateFunctionStatementContext.java | 4 +- .../ddl/CreateIndexStatementContext.java | 4 +- .../ddl/CreateProcedureStatementContext.java | 4 +- .../ddl/CreateTableStatementContext.java | 4 +- .../ddl/CreateViewStatementContext.java | 4 +- .../statement/ddl/CursorStatementContext.java | 4 +- .../ddl/DropIndexStatementContext.java | 4 +- .../ddl/DropTableStatementContext.java | 4 +- .../ddl/DropViewStatementContext.java | 4 +- .../statement/ddl/FetchStatementContext.java | 4 +- .../statement/ddl/MoveStatementContext.java | 4 +- .../ddl/PrepareStatementContext.java | 4 +- .../ddl/RenameTableStatementContext.java | 4 +- .../ddl/TruncateStatementContext.java | 4 +- .../statement/dml/CopyStatementContext.java | 4 +- .../statement/dml/DeleteStatementContext.java | 4 +- .../statement/dml/InsertStatementContext.java | 4 +- .../dml/LoadDataStatementContext.java | 4 +- .../dml/LoadXMLStatementContext.java | 4 +- .../statement/dml/SelectStatementContext.java | 2 +- .../statement/dml/UpdateStatementContext.java | 8 +- .../from/type/SimpleTableSegmentBinder.java | 1 + .../engine/ProjectionsContextEngineTest.java | 25 ++++-- .../segment/table/TablesContextTest.java | 87 ++++++++++--------- .../dal/AnalyzeTableStatementContextTest.java | 13 ++- .../dal/ExplainStatementContextTest.java | 2 +- .../OptimizeTableStatementContextTest.java | 7 +- .../dal/ShowColumnsStatementContextTest.java | 7 +- .../ShowCreateTableStatementContextTest.java | 7 +- .../dal/ShowIndexStatementContextTest.java | 7 +- .../dcl/DenyUserStatementContextTest.java | 7 +- .../dcl/GrantStatementContextTest.java | 11 ++- .../dcl/RevokeStatementContextTest.java | 11 ++- .../ddl/AlterIndexStatementContextTest.java | 2 +- .../ddl/AlterTableStatementContextTest.java | 11 ++- .../ddl/AlterViewStatementContextTest.java | 11 ++- .../CreateFunctionStatementContextTest.java | 2 +- .../ddl/CreateIndexStatementContextTest.java | 4 +- .../CreateProcedureStatementContextTest.java | 2 +- .../ddl/CreateTableStatementContextTest.java | 2 +- .../ddl/CreateViewStatementContextTest.java | 7 +- .../ddl/DropIndexStatementContextTest.java | 2 +- .../ddl/DropTableStatementContextTest.java | 2 +- .../ddl/DropViewStatementContextTest.java | 11 ++- .../ddl/PrepareStatementContextTest.java | 7 +- .../ddl/TruncateStatementContextTest.java | 11 ++- .../dml/DeleteStatementContextTest.java | 11 ++- .../dml/InsertStatementContextTest.java | 49 ++++++++--- .../dml/SelectStatementContextTest.java | 36 +++++--- .../dml/UpdateStatementContextTest.java | 15 +++- .../sql/process/ProcessEngineTest.java | 7 +- .../SingleDropTableSupportedCheckerTest.java | 2 +- .../single/route/SingleSQLRouterTest.java | 8 +- .../core/extractor/TableExtractor.java | 8 +- .../generic/table/TableNameSegment.java | 13 ++- .../connector/ProxySQLExecutorTest.java | 8 +- .../PostgreSQLAdminExecutorCreatorTest.java | 2 +- 108 files changed, 496 insertions(+), 368 deletions(-) diff --git a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/route/engine/BroadcastRouteEngineFactoryTest.java b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/route/engine/BroadcastRouteEngineFactoryTest.java index 1a82b8480b2b2..0eabb0847b6c5 100644 --- a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/route/engine/BroadcastRouteEngineFactoryTest.java +++ b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/route/engine/BroadcastRouteEngineFactoryTest.java @@ -26,10 +26,8 @@ import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext; import org.apache.shardingsphere.infra.binder.context.statement.ddl.CloseStatementContext; import org.apache.shardingsphere.infra.binder.context.type.TableAvailable; -import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.session.query.QueryContext; -import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; 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.DALStatement; @@ -137,7 +135,6 @@ void assertNewInstanceWithUpdateStatementAndIsAllBroadcastTables() { } private TablesContext createTablesContext() { - DatabaseType databaseType = TypedSPILoader.getService(DatabaseType.class, "FIXTURE"); - return new TablesContext(Collections.singleton(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("foo_tbl")))), databaseType, null); + return new TablesContext(Collections.singleton(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("foo_tbl")))), null); } } diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/orderby/EncryptOrderByItemSupportedCheckerTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/orderby/EncryptOrderByItemSupportedCheckerTest.java index d513329c082f8..bd54b59414a6a 100644 --- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/orderby/EncryptOrderByItemSupportedCheckerTest.java +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/checker/sql/orderby/EncryptOrderByItemSupportedCheckerTest.java @@ -123,7 +123,7 @@ private SelectStatementContext mockSelectStatementContext(final String tableName when(result.getOrderByContext().getItems()).thenReturn(Collections.singleton(orderByItem)); when(result.getGroupByContext().getItems()).thenReturn(Collections.emptyList()); when(result.getSubqueryContexts().values()).thenReturn(Collections.emptyList()); - when(result.getTablesContext()).thenReturn(new TablesContext(Collections.singleton(simpleTableSegment), databaseType, "foo_db")); + when(result.getTablesContext()).thenReturn(new TablesContext(Collections.singleton(simpleTableSegment))); return result; } } diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/fixture/EncryptGeneratorFixtureBuilder.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/fixture/EncryptGeneratorFixtureBuilder.java index 80287886d790c..5befae4ed0535 100644 --- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/fixture/EncryptGeneratorFixtureBuilder.java +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/fixture/EncryptGeneratorFixtureBuilder.java @@ -164,7 +164,7 @@ public static UpdateStatementContext createUpdateStatementContext() { updateStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_user")))); updateStatement.setWhere(createWhereSegment()); updateStatement.setSetAssignment(createSetAssignmentSegment()); - return new UpdateStatementContext(updateStatement, "foo_db"); + return new UpdateStatementContext(updateStatement); } private static WhereSegment createWhereSegment() { diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/projection/EncryptProjectionTokenGeneratorTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/projection/EncryptProjectionTokenGeneratorTest.java index 627e0b4b17151..5648193a7d5c0 100644 --- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/projection/EncryptProjectionTokenGeneratorTest.java +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/projection/EncryptProjectionTokenGeneratorTest.java @@ -92,7 +92,7 @@ void assertGenerateSQLTokensWhenOwnerMatchTableAlias() { when(sqlStatementContext.getSqlStatement().getProjections()).thenReturn(projections); when(sqlStatementContext.getSubqueryContexts().values()).thenReturn(Collections.emptyList()); SimpleTableSegment doctorOneTable = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("doctor1"))); - when(sqlStatementContext.getTablesContext()).thenReturn(new TablesContext(Arrays.asList(doctorTable, doctorOneTable), databaseType, "foo_db")); + when(sqlStatementContext.getTablesContext()).thenReturn(new TablesContext(Arrays.asList(doctorTable, doctorOneTable))); when(sqlStatementContext.getProjectionsContext().getProjections()).thenReturn(Collections.singleton(new ColumnProjection("a", "mobile", null, databaseType))); Collection actual = generator.generateSQLTokens(sqlStatementContext); assertThat(actual.size(), is(1)); @@ -114,7 +114,7 @@ void assertGenerateSQLTokensWhenOwnerMatchTableAliasForSameTable() { when(sqlStatementContext.getSqlStatement().getProjections()).thenReturn(projections); when(sqlStatementContext.getSubqueryContexts().values()).thenReturn(Collections.emptyList()); SimpleTableSegment sameDoctorTable = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("doctor"))); - when(sqlStatementContext.getTablesContext()).thenReturn(new TablesContext(Arrays.asList(doctorTable, sameDoctorTable), databaseType, "foo_db")); + when(sqlStatementContext.getTablesContext()).thenReturn(new TablesContext(Arrays.asList(doctorTable, sameDoctorTable))); when(sqlStatementContext.getProjectionsContext().getProjections()).thenReturn(Collections.singleton(new ColumnProjection("a", "mobile", null, databaseType))); Collection actual = generator.generateSQLTokens(sqlStatementContext); assertThat(actual.size(), is(1)); @@ -133,7 +133,7 @@ void assertGenerateSQLTokensWhenOwnerMatchTableName() { when(sqlStatementContext.getSubqueryContexts().values()).thenReturn(Collections.emptyList()); SimpleTableSegment doctorTable = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("doctor"))); SimpleTableSegment doctorOneTable = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("doctor1"))); - when(sqlStatementContext.getTablesContext()).thenReturn(new TablesContext(Arrays.asList(doctorTable, doctorOneTable), databaseType, "foo_db")); + when(sqlStatementContext.getTablesContext()).thenReturn(new TablesContext(Arrays.asList(doctorTable, doctorOneTable))); when(sqlStatementContext.getProjectionsContext().getProjections()).thenReturn(Collections.singleton(new ColumnProjection("doctor", "mobile", null, databaseType))); Collection actual = generator.generateSQLTokens(sqlStatementContext); assertThat(actual.size(), is(1)); diff --git a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/select/EncryptGroupByItemTokenGeneratorTest.java b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/select/EncryptGroupByItemTokenGeneratorTest.java index c503669a7be06..add57075398b5 100644 --- a/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/select/EncryptGroupByItemTokenGeneratorTest.java +++ b/features/encrypt/core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/select/EncryptGroupByItemTokenGeneratorTest.java @@ -86,7 +86,7 @@ private SelectStatementContext buildSelectStatementContext() { OrderByItem orderByItem = new OrderByItem(columnOrderByItemSegment); when(result.getGroupByContext().getItems()).thenReturn(Collections.singleton(orderByItem)); when(result.getSubqueryContexts().values()).thenReturn(Collections.emptyList()); - when(result.getTablesContext()).thenReturn(new TablesContext(Collections.singleton(simpleTableSegment), databaseType, "foo_db")); + when(result.getTablesContext()).thenReturn(new TablesContext(Collections.singleton(simpleTableSegment))); return result; } } diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowDMLStatementDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowDMLStatementDataSourceMappingsRetriever.java index bc711bb832e38..85e20e1b0c84a 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowDMLStatementDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/ShadowDMLStatementDataSourceMappingsRetriever.java @@ -43,14 +43,14 @@ @HighFrequencyInvocation public final class ShadowDMLStatementDataSourceMappingsRetriever implements ShadowDataSourceMappingsRetriever { - private final Map tableAliasNameMap; + private final Collection tableNames; private final ShadowTableHintDataSourceMappingsRetriever tableHintDataSourceMappingsRetriever; private final ShadowColumnDataSourceMappingsRetriever shadowColumnDataSourceMappingsRetriever; public ShadowDMLStatementDataSourceMappingsRetriever(final QueryContext queryContext, final ShadowOperationType operationType) { - tableAliasNameMap = ((TableAvailable) queryContext.getSqlStatementContext()).getTablesContext().getTableAliasNameMap(); + tableNames = ((TableAvailable) queryContext.getSqlStatementContext()).getTablesContext().getTableNames(); tableHintDataSourceMappingsRetriever = new ShadowTableHintDataSourceMappingsRetriever(operationType, queryContext.getHintValueContext().isShadow()); shadowColumnDataSourceMappingsRetriever = createShadowDataSourceMappingsRetriever(queryContext); } @@ -73,7 +73,7 @@ private ShadowColumnDataSourceMappingsRetriever createShadowDataSourceMappingsRe @Override public Map retrieve(final ShadowRule rule) { - Collection shadowTables = rule.filterShadowTables(tableAliasNameMap.values()); + Collection shadowTables = rule.filterShadowTables(tableNames); Map result = tableHintDataSourceMappingsRetriever.retrieve(rule, shadowTables); return result.isEmpty() && null != shadowColumnDataSourceMappingsRetriever ? shadowColumnDataSourceMappingsRetriever.retrieve(rule, shadowTables) : result; } diff --git a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/impl/ShadowSelectStatementDataSourceMappingsRetriever.java b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/impl/ShadowSelectStatementDataSourceMappingsRetriever.java index 1eed56d03eeae..aaefa816fd523 100644 --- a/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/impl/ShadowSelectStatementDataSourceMappingsRetriever.java +++ b/features/shadow/core/src/main/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/impl/ShadowSelectStatementDataSourceMappingsRetriever.java @@ -23,18 +23,16 @@ import org.apache.shardingsphere.shadow.route.retriever.dml.table.column.ShadowColumnDataSourceMappingsRetriever; import org.apache.shardingsphere.shadow.route.util.ShadowExtractor; import org.apache.shardingsphere.shadow.spi.ShadowOperationType; +import org.apache.shardingsphere.sql.parser.statement.core.extractor.ColumnExtractor; +import org.apache.shardingsphere.sql.parser.statement.core.extractor.ExpressionExtractor; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.AndPredicate; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.OwnerSegment; -import org.apache.shardingsphere.sql.parser.statement.core.extractor.ColumnExtractor; -import org.apache.shardingsphere.sql.parser.statement.core.extractor.ExpressionExtractor; import java.util.Collection; import java.util.LinkedList; import java.util.List; -import java.util.Optional; /** * Shadow select statement data source mappings retriever. @@ -60,7 +58,8 @@ protected Collection getShadowColumnConditions(final Stri if (1 != columns.size()) { continue; } - ShadowExtractor.extractValues(each, parameters).map(values -> new ShadowColumnCondition(getOwnerTableName(columns.iterator().next()), shadowColumnName, values)).ifPresent(result::add); + ShadowExtractor.extractValues(each, parameters).map(values -> new ShadowColumnCondition( + columns.iterator().next().getColumnBoundInfo().getOriginalTable().getValue(), shadowColumnName, values)).ifPresent(result::add); } return result; } @@ -74,11 +73,4 @@ private Collection getWhereSegment() { } return result; } - - private String getOwnerTableName(final ColumnSegment columnSegment) { - Optional owner = columnSegment.getOwner(); - return owner.isPresent() - ? sqlStatementContext.getTablesContext().getTableAliasNameMap().get(owner.get().getIdentifier().getValue()) - : sqlStatementContext.getTablesContext().getTableNames().iterator().next(); - } } diff --git a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/impl/ShadowSelectStatementDataSourceMappingsRetrieverTest.java b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/impl/ShadowSelectStatementDataSourceMappingsRetrieverTest.java index f66278379d7d0..f4b34481b3558 100644 --- a/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/impl/ShadowSelectStatementDataSourceMappingsRetrieverTest.java +++ b/features/shadow/core/src/test/java/org/apache/shardingsphere/shadow/route/retriever/dml/table/column/impl/ShadowSelectStatementDataSourceMappingsRetrieverTest.java @@ -20,11 +20,12 @@ import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; import org.apache.shardingsphere.shadow.condition.ShadowColumnCondition; import org.apache.shardingsphere.shadow.route.util.ShadowExtractor; +import org.apache.shardingsphere.sql.parser.statement.core.extractor.ColumnExtractor; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.OwnerSegment; -import org.apache.shardingsphere.sql.parser.statement.core.extractor.ColumnExtractor; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; import org.apache.shardingsphere.test.mock.AutoMockExtension; import org.apache.shardingsphere.test.mock.StaticMockSettings; @@ -36,7 +37,7 @@ import java.util.Collections; import java.util.Optional; -import static org.apache.shardingsphere.test.matcher.ShardingSphereAssertionMatchers.deepEqual; +import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; @@ -53,16 +54,22 @@ void assertRetrieveWithColumnOwner() { ExpressionSegment expressionSegment = mock(ExpressionSegment.class); when(whereSegment.getExpr()).thenReturn(expressionSegment); when(sqlStatementContext.getWhereSegments()).thenReturn(Arrays.asList(whereSegment, mock(WhereSegment.class, RETURNS_DEEP_STUBS))); - ColumnSegment columnSegment = mock(ColumnSegment.class); - when(columnSegment.getOwner()).thenReturn(Optional.of(new OwnerSegment(0, 0, new IdentifierValue("foo")))); + ColumnSegment columnSegment = mock(ColumnSegment.class, RETURNS_DEEP_STUBS); + when(columnSegment.getColumnBoundInfo().getOriginalTable().getValue()).thenReturn("foo_tbl"); + OwnerSegment ownerSegment = new OwnerSegment(0, 0, new IdentifierValue("foo")); + ownerSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + when(columnSegment.getOwner()).thenReturn(Optional.of(ownerSegment)); when(ColumnExtractor.extract(expressionSegment)).thenReturn(Collections.singleton(columnSegment)); when(ShadowExtractor.extractValues(expressionSegment, Collections.singletonList("foo"))).thenReturn(Optional.of(Collections.singleton("foo"))); when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(Collections.singleton("foo_tbl")); - when(sqlStatementContext.getTablesContext().getTableAliasNameMap().get("foo")).thenReturn("foo_tbl"); ShadowSelectStatementDataSourceMappingsRetriever retriever = new ShadowSelectStatementDataSourceMappingsRetriever(sqlStatementContext, Collections.singletonList("foo")); Collection actual = retriever.getShadowColumnConditions("foo_col"); - Collection expected = Collections.singletonList(new ShadowColumnCondition("foo_tbl", "foo_col", Collections.singleton("foo"))); - assertThat(actual, deepEqual(expected)); + assertThat(actual.size(), is(1)); + ShadowColumnCondition actualCondition = actual.iterator().next(); + assertThat(actualCondition.getTable(), is("foo_tbl")); + assertThat(actualCondition.getColumn(), is("foo_col")); + assertThat(actualCondition.getValues(), is(Collections.singleton("foo"))); + } @Test @@ -72,14 +79,18 @@ void assertRetrieveWithoutColumnOwner() { ExpressionSegment expressionSegment = mock(ExpressionSegment.class); when(whereSegment.getExpr()).thenReturn(expressionSegment); when(sqlStatementContext.getWhereSegments()).thenReturn(Arrays.asList(whereSegment, mock(WhereSegment.class, RETURNS_DEEP_STUBS))); - ColumnSegment columnSegment = mock(ColumnSegment.class); + ColumnSegment columnSegment = mock(ColumnSegment.class, RETURNS_DEEP_STUBS); + when(columnSegment.getColumnBoundInfo().getOriginalTable().getValue()).thenReturn("foo_tbl"); when(columnSegment.getOwner()).thenReturn(Optional.empty()); when(ColumnExtractor.extract(expressionSegment)).thenReturn(Collections.singleton(columnSegment)); when(ShadowExtractor.extractValues(expressionSegment, Collections.singletonList("foo"))).thenReturn(Optional.of(Collections.singleton("foo"))); when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(Collections.singleton("foo_tbl")); ShadowSelectStatementDataSourceMappingsRetriever retriever = new ShadowSelectStatementDataSourceMappingsRetriever(sqlStatementContext, Collections.singletonList("foo")); Collection actual = retriever.getShadowColumnConditions("foo_col"); - Collection expected = Collections.singletonList(new ShadowColumnCondition("foo_tbl", "foo_col", Collections.singleton("foo"))); - assertThat(actual, deepEqual(expected)); + assertThat(actual.size(), is(1)); + ShadowColumnCondition actualCondition = actual.iterator().next(); + assertThat(actualCondition.getTable(), is("foo_tbl")); + assertThat(actualCondition.getColumn(), is("foo_col")); + assertThat(actualCondition.getValues(), is(Collections.singleton("foo"))); } } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingAlterIndexSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingAlterIndexSupportedCheckerTest.java index 897a46822ec57..0c17547c6c5a7 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingAlterIndexSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingAlterIndexSupportedCheckerTest.java @@ -60,7 +60,7 @@ void assertCheckWhenIndexExistRenameIndexNotExistForPostgreSQL() { when(schema.getAllTables()).thenReturn(Collections.singleton(table)); when(table.containsIndex("t_order_index")).thenReturn(true); when(table.containsIndex("t_order_index_new")).thenReturn(false); - assertDoesNotThrow(() -> new ShardingAlterIndexSupportedChecker().check(rule, database, schema, new AlterIndexStatementContext(sqlStatement, "foo_db"))); + assertDoesNotThrow(() -> new ShardingAlterIndexSupportedChecker().check(rule, database, schema, new AlterIndexStatementContext(sqlStatement))); } @Test @@ -70,7 +70,7 @@ void assertCheckWhenIndexNotExistRenameIndexNotExistForPostgreSQL() { sqlStatement.setRenameIndex(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_order_index_new")))); ShardingSphereTable table = mock(ShardingSphereTable.class); when(database.getSchema("public").getTable("t_order")).thenReturn(table); - assertThrows(IndexNotFoundException.class, () -> new ShardingAlterIndexSupportedChecker().check(rule, database, mock(), new AlterIndexStatementContext(sqlStatement, "foo_db"))); + assertThrows(IndexNotFoundException.class, () -> new ShardingAlterIndexSupportedChecker().check(rule, database, mock(), new AlterIndexStatementContext(sqlStatement))); } @Test @@ -84,6 +84,6 @@ void assertCheckAlterIndexWhenIndexExistRenameIndexExistForPostgreSQL() { when(table.containsIndex("t_order_index")).thenReturn(true); when(table.containsIndex("t_order_index_new")).thenReturn(true); assertThrows(DuplicateIndexException.class, - () -> new ShardingAlterIndexSupportedChecker().check(rule, database, schema, new AlterIndexStatementContext(sqlStatement, "foo_db"))); + () -> new ShardingAlterIndexSupportedChecker().check(rule, database, schema, new AlterIndexStatementContext(sqlStatement))); } } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingAlterTableSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingAlterTableSupportedCheckerTest.java index 0ed445f918ce7..7fbb8d3588836 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingAlterTableSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingAlterTableSupportedCheckerTest.java @@ -51,7 +51,7 @@ void assertCheckWithRenameTableWithShardingTable() { PostgreSQLAlterTableStatement sqlStatement = new PostgreSQLAlterTableStatement(); sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); sqlStatement.setRenameTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order_new")))); - AlterTableStatementContext sqlStatementContext = new AlterTableStatementContext(sqlStatement, "foo_db"); + AlterTableStatementContext sqlStatementContext = new AlterTableStatementContext(sqlStatement); when(rule.containsShardingTable(Arrays.asList("t_order", "t_order_new"))).thenReturn(true); assertThrows(UnsupportedShardingOperationException.class, () -> new ShardingAlterTableSupportedChecker().check(rule, database, mock(), sqlStatementContext)); } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingAlterViewSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingAlterViewSupportedCheckerTest.java index 0b7c2ce56b7c0..1acaea3299c45 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingAlterViewSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingAlterViewSupportedCheckerTest.java @@ -49,7 +49,7 @@ void assertPreValidateAlterViewForMySQL() { MySQLAlterViewStatement sqlStatement = new MySQLAlterViewStatement(); sqlStatement.setView(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order_view")))); sqlStatement.setSelect(selectStatement); - AlterViewStatementContext sqlStatementContext = new AlterViewStatementContext(sqlStatement, "foo_db"); + AlterViewStatementContext sqlStatementContext = new AlterViewStatementContext(sqlStatement); when(rule.isShardingTable("t_order")).thenReturn(false); assertDoesNotThrow(() -> new ShardingAlterViewSupportedChecker().check(rule, mock(), mock(), sqlStatementContext)); } @@ -61,7 +61,7 @@ void assertPreValidateAlterViewWithShardingTableForMySQL() { MySQLAlterViewStatement sqlStatement = new MySQLAlterViewStatement(); sqlStatement.setView(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order_view")))); sqlStatement.setSelect(selectStatement); - AlterViewStatementContext sqlStatementContext = new AlterViewStatementContext(sqlStatement, "foo_db"); + AlterViewStatementContext sqlStatementContext = new AlterViewStatementContext(sqlStatement); when(rule.isShardingTable("t_order")).thenReturn(true); assertThrows(EngagedViewException.class, () -> new ShardingAlterViewSupportedChecker().check(rule, mock(), mock(), sqlStatementContext)); } @@ -71,7 +71,7 @@ void assertPreValidateAlterRenamedView() { OpenGaussAlterViewStatement sqlStatement = new OpenGaussAlterViewStatement(); sqlStatement.setView(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order_view")))); sqlStatement.setRenameView(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order_new")))); - AlterViewStatementContext sqlStatementContext = new AlterViewStatementContext(sqlStatement, "foo_db"); + AlterViewStatementContext sqlStatementContext = new AlterViewStatementContext(sqlStatement); assertDoesNotThrow(() -> new ShardingAlterViewSupportedChecker().check(rule, mock(), mock(), sqlStatementContext)); } } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateFunctionSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateFunctionSupportedCheckerTest.java index c37805b434698..517500fbdae6c 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateFunctionSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateFunctionSupportedCheckerTest.java @@ -64,7 +64,7 @@ void assertCheckCreateFunctionForMySQL() { routineBody.getValidStatements().add(selectValidStatementSegment); MySQLCreateFunctionStatement sqlStatement = new MySQLCreateFunctionStatement(); sqlStatement.setRoutineBody(routineBody); - CreateFunctionStatementContext sqlStatementContext = new CreateFunctionStatementContext(sqlStatement, "foo_db"); + CreateFunctionStatementContext sqlStatementContext = new CreateFunctionStatementContext(sqlStatement); ShardingSphereDatabase database = mock(ShardingSphereDatabase.class); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); when(schema.containsTable("t_order_item")).thenReturn(true); @@ -81,7 +81,7 @@ void assertCheckCreateFunctionWithShardingTableForMySQL() { routineBody.getValidStatements().add(validStatementSegment); MySQLCreateFunctionStatement sqlStatement = new MySQLCreateFunctionStatement(); sqlStatement.setRoutineBody(routineBody); - CreateFunctionStatementContext sqlStatementContext = new CreateFunctionStatementContext(sqlStatement, "foo_db"); + CreateFunctionStatementContext sqlStatementContext = new CreateFunctionStatementContext(sqlStatement); ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); when(rule.isShardingTable("t_order")).thenReturn(true); assertThrows(UnsupportedShardingOperationException.class, () -> new ShardingCreateFunctionSupportedChecker().check(rule, database, mock(), sqlStatementContext)); @@ -97,7 +97,7 @@ void assertCheckCreateFunctionWithNoSuchTableForMySQL() { routineBody.getValidStatements().add(validStatementSegment); MySQLCreateFunctionStatement sqlStatement = new MySQLCreateFunctionStatement(); sqlStatement.setRoutineBody(routineBody); - CreateFunctionStatementContext sqlStatementContext = new CreateFunctionStatementContext(sqlStatement, "foo_db"); + CreateFunctionStatementContext sqlStatementContext = new CreateFunctionStatementContext(sqlStatement); ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); assertThrows(NoSuchTableException.class, () -> new ShardingCreateFunctionSupportedChecker().check(rule, database, mock(), sqlStatementContext)); } @@ -112,7 +112,7 @@ void assertCheckCreateFunctionWithTableExistsForMySQL() { routineBody.getValidStatements().add(validStatementSegment); MySQLCreateFunctionStatement sqlStatement = new MySQLCreateFunctionStatement(); sqlStatement.setRoutineBody(routineBody); - CreateFunctionStatementContext sqlStatementContext = new CreateFunctionStatementContext(sqlStatement, "foo_db"); + CreateFunctionStatementContext sqlStatementContext = new CreateFunctionStatementContext(sqlStatement); ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); when(schema.containsTable("t_order")).thenReturn(true); diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateIndexSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateIndexSupportedCheckerTest.java index 3f115e5e965e8..1fedc80468e83 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateIndexSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateIndexSupportedCheckerTest.java @@ -57,7 +57,7 @@ void assertCheckWhenTableExistIndexNotExistForPostgreSQL() { sqlStatement.setIndex(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_order_index")))); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); when(schema.containsTable("t_order")).thenReturn(true); - assertDoesNotThrow(() -> new ShardingCreateIndexSupportedChecker().check(rule, database, schema, new CreateIndexStatementContext(sqlStatement, "foo_db"))); + assertDoesNotThrow(() -> new ShardingCreateIndexSupportedChecker().check(rule, database, schema, new CreateIndexStatementContext(sqlStatement))); } @Test @@ -67,7 +67,7 @@ void assertCheckWhenTableNotExistIndexNotExistForPostgreSQL() { sqlStatement.setIndex(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("t_order_index")))); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); when(schema.containsTable("t_order")).thenReturn(false); - assertThrows(NoSuchTableException.class, () -> new ShardingCreateIndexSupportedChecker().check(rule, database, schema, new CreateIndexStatementContext(sqlStatement, "foo_db"))); + assertThrows(NoSuchTableException.class, () -> new ShardingCreateIndexSupportedChecker().check(rule, database, schema, new CreateIndexStatementContext(sqlStatement))); } @Test @@ -78,7 +78,7 @@ void assertCheckWhenTableExistIndexExistForPostgreSQL() { ShardingSphereSchema schema = mock(ShardingSphereSchema.class); when(schema.containsTable("t_order")).thenReturn(true); when(schema.containsIndex("t_order", "t_order_index")).thenReturn(true); - assertThrows(DuplicateIndexException.class, () -> new ShardingCreateIndexSupportedChecker().check(rule, database, schema, new CreateIndexStatementContext(sqlStatement, "foo_db"))); + assertThrows(DuplicateIndexException.class, () -> new ShardingCreateIndexSupportedChecker().check(rule, database, schema, new CreateIndexStatementContext(sqlStatement))); } @Test @@ -89,7 +89,7 @@ void assertCheckWithoutIndexNameWhenTableExistIndexNotExistForPostgreSQL() { sqlStatement.setGeneratedIndexStartIndex(10); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); when(schema.containsTable("t_order")).thenReturn(true); - assertDoesNotThrow(() -> new ShardingCreateIndexSupportedChecker().check(rule, database, schema, new CreateIndexStatementContext(sqlStatement, "foo_db"))); + assertDoesNotThrow(() -> new ShardingCreateIndexSupportedChecker().check(rule, database, schema, new CreateIndexStatementContext(sqlStatement))); } @Test @@ -100,7 +100,7 @@ void assertCheckWithoutIndexNameWhenTableNotExistIndexNotExistForPostgreSQL() { sqlStatement.setGeneratedIndexStartIndex(10); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); when(schema.containsTable("t_order")).thenReturn(false); - assertThrows(NoSuchTableException.class, () -> new ShardingCreateIndexSupportedChecker().check(rule, database, schema, new CreateIndexStatementContext(sqlStatement, "foo_db"))); + assertThrows(NoSuchTableException.class, () -> new ShardingCreateIndexSupportedChecker().check(rule, database, schema, new CreateIndexStatementContext(sqlStatement))); } @Test @@ -112,6 +112,6 @@ void assertCheckWithoutIndexNameWhenTableExistIndexExistForPostgreSQL() { ShardingSphereSchema schema = mock(ShardingSphereSchema.class); when(schema.containsTable("t_order")).thenReturn(true); when(schema.containsIndex("t_order", "content_idx")).thenReturn(true); - assertThrows(DuplicateIndexException.class, () -> new ShardingCreateIndexSupportedChecker().check(rule, database, schema, new CreateIndexStatementContext(sqlStatement, "foo_db"))); + assertThrows(DuplicateIndexException.class, () -> new ShardingCreateIndexSupportedChecker().check(rule, database, schema, new CreateIndexStatementContext(sqlStatement))); } } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateProcedureSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateProcedureSupportedCheckerTest.java index 48b55eaa30b8e..e48488ffe9472 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateProcedureSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateProcedureSupportedCheckerTest.java @@ -68,7 +68,7 @@ void assertCheckForMySQL() { ShardingSphereSchema schema = mock(ShardingSphereSchema.class); when(schema.containsTable("t_order_item")).thenReturn(true); when(rule.isShardingTable("t_order_item")).thenReturn(false); - CreateProcedureStatementContext sqlStatementContext = new CreateProcedureStatementContext(sqlStatement, "foo_db"); + CreateProcedureStatementContext sqlStatementContext = new CreateProcedureStatementContext(sqlStatement); assertDoesNotThrow(() -> new ShardingCreateProcedureSupportedChecker().check(rule, database, schema, sqlStatementContext)); } @@ -82,7 +82,7 @@ void assertCheckWithShardingTableForMySQL() { routineBody.getValidStatements().add(validStatementSegment); MySQLCreateProcedureStatement sqlStatement = new MySQLCreateProcedureStatement(); sqlStatement.setRoutineBody(routineBody); - CreateProcedureStatementContext sqlStatementContext = new CreateProcedureStatementContext(sqlStatement, "foo_db"); + CreateProcedureStatementContext sqlStatementContext = new CreateProcedureStatementContext(sqlStatement); ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); when(rule.isShardingTable("t_order")).thenReturn(true); assertThrows(UnsupportedShardingOperationException.class, () -> new ShardingCreateProcedureSupportedChecker().check(rule, database, mock(), sqlStatementContext)); @@ -98,7 +98,7 @@ void assertCheckWithNoSuchTableForMySQL() { routineBody.getValidStatements().add(validStatementSegment); MySQLCreateProcedureStatement sqlStatement = new MySQLCreateProcedureStatement(); sqlStatement.setRoutineBody(routineBody); - CreateProcedureStatementContext sqlStatementContext = new CreateProcedureStatementContext(sqlStatement, "foo_db"); + CreateProcedureStatementContext sqlStatementContext = new CreateProcedureStatementContext(sqlStatement); ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); assertThrows(NoSuchTableException.class, () -> new ShardingCreateProcedureSupportedChecker().check(rule, database, mock(), sqlStatementContext)); } @@ -113,7 +113,7 @@ void assertCheckWithTableExistsForMySQL() { routineBody.getValidStatements().add(validStatementSegment); MySQLCreateProcedureStatement sqlStatement = new MySQLCreateProcedureStatement(); sqlStatement.setRoutineBody(routineBody); - CreateProcedureStatementContext sqlStatementContext = new CreateProcedureStatementContext(sqlStatement, "foo_db"); + CreateProcedureStatementContext sqlStatementContext = new CreateProcedureStatementContext(sqlStatement); ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); when(schema.containsTable("t_order")).thenReturn(true); diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateTableSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateTableSupportedCheckerTest.java index 539c40418be03..6231def67420d 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateTableSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingCreateTableSupportedCheckerTest.java @@ -83,7 +83,7 @@ void assertCheckForSQLServer() { } private void assertCheck(final CreateTableStatement sqlStatement) { - CreateTableStatementContext sqlStatementContext = new CreateTableStatementContext(sqlStatement, "sharding_db"); + CreateTableStatementContext sqlStatementContext = new CreateTableStatementContext(sqlStatement); ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); when(schema.containsTable("t_order")).thenReturn(true); @@ -105,7 +105,7 @@ void assertCheckIfNotExistsForPostgreSQL() { } private void assertCheckIfNotExists(final CreateTableStatement sqlStatement) { - CreateTableStatementContext sqlStatementContext = new CreateTableStatementContext(sqlStatement, "foo_db"); + CreateTableStatementContext sqlStatementContext = new CreateTableStatementContext(sqlStatement); ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); new ShardingCreateTableSupportedChecker().check(rule, database, mock(), sqlStatementContext); } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingDropIndexSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingDropIndexSupportedCheckerTest.java index c6784dd59e775..3ae4f537141bf 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingDropIndexSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingDropIndexSupportedCheckerTest.java @@ -59,7 +59,7 @@ void assertCheckWhenIndexExistForPostgreSQL() { when(schema.getAllTables()).thenReturn(Collections.singleton(table)); when(table.containsIndex("t_order_index")).thenReturn(true); when(table.containsIndex("t_order_index_new")).thenReturn(true); - assertDoesNotThrow(() -> new ShardingDropIndexSupportedChecker().check(rule, database, schema, new DropIndexStatementContext(sqlStatement, "foo_db"))); + assertDoesNotThrow(() -> new ShardingDropIndexSupportedChecker().check(rule, database, schema, new DropIndexStatementContext(sqlStatement))); } @Test @@ -70,6 +70,6 @@ void assertCheckWhenIndexNotExistForPostgreSQL() { ShardingSphereTable table = mock(ShardingSphereTable.class); when(database.getSchema("public").getAllTables()).thenReturn(Collections.singleton(table)); when(database.getSchema("public").getTable("t_order")).thenReturn(table); - assertThrows(IndexNotFoundException.class, () -> new ShardingDropIndexSupportedChecker().check(rule, database, mock(), new DropIndexStatementContext(sqlStatement, "foo_db"))); + assertThrows(IndexNotFoundException.class, () -> new ShardingDropIndexSupportedChecker().check(rule, database, mock(), new DropIndexStatementContext(sqlStatement))); } } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingDropTableSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingDropTableSupportedCheckerTest.java index 38489b6b6dff0..5223b63b3747d 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingDropTableSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingDropTableSupportedCheckerTest.java @@ -64,7 +64,7 @@ void init() { void assertCheckForMySQL() { MySQLDropTableStatement sqlStatement = new MySQLDropTableStatement(false); sqlStatement.getTables().add(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order_item")))); - DropTableStatementContext sqlStatementContext = new DropTableStatementContext(sqlStatement, "db_schema"); + DropTableStatementContext sqlStatementContext = new DropTableStatementContext(sqlStatement); ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); when(schema.containsTable("t_order_item")).thenReturn(true); diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingInsertSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingInsertSupportedCheckerTest.java index 52fce0fd43062..da9a6cebc883b 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingInsertSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingInsertSupportedCheckerTest.java @@ -148,13 +148,13 @@ private InsertStatement createInsertSelectStatement() { private TablesContext createSingleTablesContext() { List result = new LinkedList<>(); result.add(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("user")))); - return new TablesContext(result, databaseType, "foo_db"); + return new TablesContext(result); } private TablesContext createMultiTablesContext() { List result = new LinkedList<>(); result.add(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("user")))); result.add(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("order")))); - return new TablesContext(result, databaseType, "foo_db"); + return new TablesContext(result); } } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingRenameTableSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingRenameTableSupportedCheckerTest.java index d4aaae3d616ea..9b8000cfb055b 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingRenameTableSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/ddl/ShardingRenameTableSupportedCheckerTest.java @@ -61,6 +61,6 @@ private RenameTableStatementContext createRenameTableStatementContext(final Stri renameTableDefinitionSegment.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue(originTableName)))); renameTableDefinitionSegment.setRenameTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue(newTableName)))); sqlStatement.getRenameTables().add(renameTableDefinitionSegment); - return new RenameTableStatementContext(sqlStatement, "foo_db"); + return new RenameTableStatementContext(sqlStatement); } } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingCopySupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingCopySupportedCheckerTest.java index 271eed7fd04f8..9b15a14b9f549 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingCopySupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingCopySupportedCheckerTest.java @@ -46,14 +46,14 @@ class ShardingCopySupportedCheckerTest { void assertCheckWhenTableSegmentForPostgreSQL() { PostgreSQLCopyStatement sqlStatement = new PostgreSQLCopyStatement(); sqlStatement.setTableSegment(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); - assertDoesNotThrow(() -> new ShardingCopySupportedChecker().check(rule, mock(), mock(), new CopyStatementContext(sqlStatement, "foo_db"))); + assertDoesNotThrow(() -> new ShardingCopySupportedChecker().check(rule, mock(), mock(), new CopyStatementContext(sqlStatement))); } @Test void assertCheckWhenTableSegmentForOpenGauss() { OpenGaussCopyStatement sqlStatement = new OpenGaussCopyStatement(); sqlStatement.setTableSegment(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); - assertDoesNotThrow(() -> new ShardingCopySupportedChecker().check(rule, mock(), mock(), new CopyStatementContext(sqlStatement, "foo_db"))); + assertDoesNotThrow(() -> new ShardingCopySupportedChecker().check(rule, mock(), mock(), new CopyStatementContext(sqlStatement))); } @Test @@ -68,7 +68,7 @@ void assertCheckCopyWithShardingTableForOpenGauss() { private void assertCheckCopyTable(final CopyStatement sqlStatement) { sqlStatement.setTableSegment(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); - CopyStatementContext sqlStatementContext = new CopyStatementContext(sqlStatement, "foo_db"); + CopyStatementContext sqlStatementContext = new CopyStatementContext(sqlStatement); String tableName = "t_order"; when(rule.isShardingTable(tableName)).thenReturn(true); new ShardingCopySupportedChecker().check(rule, mock(), mock(), sqlStatementContext); diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingDeleteSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingDeleteSupportedCheckerTest.java index 7644a8f410994..7af8a2b3de8f5 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingDeleteSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingDeleteSupportedCheckerTest.java @@ -83,7 +83,7 @@ private void assertCheckWhenDeleteMultiTables(final DeleteStatement sqlStatement Collection tableNames = new HashSet<>(Arrays.asList("user", "order", "order_item")); when(rule.isAllShardingTables(tableNames)).thenReturn(false); when(rule.containsShardingTable(tableNames)).thenReturn(true); - DeleteStatementContext sqlStatementContext = new DeleteStatementContext(sqlStatement, "foo_db"); + DeleteStatementContext sqlStatementContext = new DeleteStatementContext(sqlStatement); new ShardingDeleteSupportedChecker().check(rule, mock(), mock(), sqlStatementContext); } } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingLoadDataSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingLoadDataSupportedCheckerTest.java index 9cda9b658229c..37c8bfd91fb57 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingLoadDataSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingLoadDataSupportedCheckerTest.java @@ -43,13 +43,13 @@ class ShardingLoadDataSupportedCheckerTest { @Test void assertCheckWithSingleTable() { MySQLLoadDataStatement sqlStatement = new MySQLLoadDataStatement(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); - assertDoesNotThrow(() -> new ShardingLoadDataSupportedChecker().check(rule, mock(), mock(), new LoadDataStatementContext(sqlStatement, "foo_db"))); + assertDoesNotThrow(() -> new ShardingLoadDataSupportedChecker().check(rule, mock(), mock(), new LoadDataStatementContext(sqlStatement))); } @Test void assertCheckWithShardingTable() { MySQLLoadDataStatement sqlStatement = new MySQLLoadDataStatement(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); when(rule.isShardingTable("t_order")).thenReturn(true); - assertThrows(UnsupportedShardingOperationException.class, () -> new ShardingLoadDataSupportedChecker().check(rule, mock(), mock(), new LoadDataStatementContext(sqlStatement, "foo_db"))); + assertThrows(UnsupportedShardingOperationException.class, () -> new ShardingLoadDataSupportedChecker().check(rule, mock(), mock(), new LoadDataStatementContext(sqlStatement))); } } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingLoadXmlSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingLoadXmlSupportedCheckerTest.java index 718e3787a3181..0538a83d47873 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingLoadXmlSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingLoadXmlSupportedCheckerTest.java @@ -43,13 +43,13 @@ class ShardingLoadXmlSupportedCheckerTest { @Test void assertCheckWithSingleTable() { MySQLLoadXMLStatement sqlStatement = new MySQLLoadXMLStatement(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); - assertDoesNotThrow(() -> new ShardingLoadXmlSupportedChecker().check(rule, mock(), mock(), new LoadXMLStatementContext(sqlStatement, "foo_db"))); + assertDoesNotThrow(() -> new ShardingLoadXmlSupportedChecker().check(rule, mock(), mock(), new LoadXMLStatementContext(sqlStatement))); } @Test void assertCheckWithShardingTable() { MySQLLoadXMLStatement sqlStatement = new MySQLLoadXMLStatement(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); when(rule.isShardingTable("t_order")).thenReturn(true); - assertThrows(UnsupportedShardingOperationException.class, () -> new ShardingLoadXmlSupportedChecker().check(rule, mock(), mock(), new LoadXMLStatementContext(sqlStatement, "foo_db"))); + assertThrows(UnsupportedShardingOperationException.class, () -> new ShardingLoadXmlSupportedChecker().check(rule, mock(), mock(), new LoadXMLStatementContext(sqlStatement))); } } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingUpdateSupportedCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingUpdateSupportedCheckerTest.java index 867ebf0f93dc1..d49c5da1e3515 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingUpdateSupportedCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingUpdateSupportedCheckerTest.java @@ -55,7 +55,7 @@ class ShardingUpdateSupportedCheckerTest { void assertCheckWhenUpdateSingleTable() { UpdateStatement updateStatement = createUpdateStatement(); updateStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("user")))); - UpdateStatementContext sqlStatementContext = new UpdateStatementContext(updateStatement, "foo_db"); + UpdateStatementContext sqlStatementContext = new UpdateStatementContext(updateStatement); Collection tableNames = sqlStatementContext.getTablesContext().getTableNames(); when(rule.isAllShardingTables(tableNames)).thenReturn(true); when(rule.containsShardingTable(tableNames)).thenReturn(true); @@ -69,7 +69,7 @@ void assertCheckWhenUpdateMultipleTables() { joinTableSegment.setLeft(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("user")))); joinTableSegment.setRight(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("order")))); updateStatement.setTable(joinTableSegment); - UpdateStatementContext sqlStatementContext = new UpdateStatementContext(updateStatement, "foo_db"); + UpdateStatementContext sqlStatementContext = new UpdateStatementContext(updateStatement); Collection tableNames = sqlStatementContext.getTablesContext().getTableNames(); when(rule.containsShardingTable(tableNames)).thenReturn(true); assertThrows(DMLWithMultipleShardingTablesException.class, () -> new ShardingUpdateSupportedChecker().check(rule, mock(), mock(), sqlStatementContext)); diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ddl/ShardingDDLResultMergerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ddl/ShardingDDLResultMergerTest.java index b92876ccb3e6b..8914d07529f0f 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ddl/ShardingDDLResultMergerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ddl/ShardingDDLResultMergerTest.java @@ -77,7 +77,7 @@ void assertMergeWithFetchStreamMergedResult() throws SQLException { } private FetchStatementContext createFetchStatementContext(final ShardingSphereDatabase database) { - FetchStatementContext result = new FetchStatementContext(mockFetchStatement(), "foo_db"); + FetchStatementContext result = new FetchStatementContext(mockFetchStatement()); result.setCursorStatementContext(createCursorStatementContext(database)); return result; } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ddl/fetch/FetchStreamMergedResultTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ddl/fetch/FetchStreamMergedResultTest.java index 6bb043a312b7c..55f0b15ffe152 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ddl/fetch/FetchStreamMergedResultTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/merge/ddl/fetch/FetchStreamMergedResultTest.java @@ -91,7 +91,7 @@ void setUp() { } private static FetchStatementContext createFetchStatementContext(final boolean containsAllDirectionType) { - FetchStatementContext result = new FetchStatementContext(createFetchStatement(containsAllDirectionType), "foo_db"); + FetchStatementContext result = new FetchStatementContext(createFetchStatement(containsAllDirectionType)); result.setCursorStatementContext(mockCursorStatementContext()); return result; } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingAlterTableRouteContextCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingAlterTableRouteContextCheckerTest.java index cf04e3fe042f1..ec44b25c16cf6 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingAlterTableRouteContextCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingAlterTableRouteContextCheckerTest.java @@ -72,7 +72,7 @@ void assertCheckWithSameRouteResultShardingTableForPostgreSQL() { routeUnits.add(new RouteUnit(new RouteMapper("ds_0", "ds_0"), Collections.singletonList(new RouteMapper("t_order", "t_order_0")))); routeUnits.add(new RouteUnit(new RouteMapper("ds_1", "ds_1"), Collections.singletonList(new RouteMapper("t_order", "t_order_0")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); - when(queryContext.getSqlStatementContext()).thenReturn(new AlterTableStatementContext(sqlStatement, "foo_db")); + when(queryContext.getSqlStatementContext()).thenReturn(new AlterTableStatementContext(sqlStatement)); assertDoesNotThrow(() -> new ShardingAlterTableRouteContextChecker().check(shardingRule, queryContext, database, mock(ConfigurationProperties.class), routeContext)); } @@ -85,7 +85,7 @@ void assertCheckWithDifferentRouteResultShardingTableForPostgreSQL() { Collection routeUnits = new LinkedList<>(); routeUnits.add(new RouteUnit(new RouteMapper("ds_0", "ds_0"), Collections.singletonList(new RouteMapper("t_order", "t_order_0")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); - when(queryContext.getSqlStatementContext()).thenReturn(new AlterTableStatementContext(sqlStatement, "foo_db")); + when(queryContext.getSqlStatementContext()).thenReturn(new AlterTableStatementContext(sqlStatement)); assertThrows(ShardingDDLRouteException.class, () -> new ShardingAlterTableRouteContextChecker().check(shardingRule, queryContext, database, mock(ConfigurationProperties.class), routeContext)); } } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingCreateTableRouteContextCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingCreateTableRouteContextCheckerTest.java index f848860a00c20..e2f568eb205ae 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingCreateTableRouteContextCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingCreateTableRouteContextCheckerTest.java @@ -72,7 +72,7 @@ void assertCheckWithSameRouteResultShardingTableForPostgreSQL() { routeUnits.add(new RouteUnit(new RouteMapper("ds_0", "ds_0"), Collections.singletonList(new RouteMapper("t_order", "t_order_0")))); routeUnits.add(new RouteUnit(new RouteMapper("ds_1", "ds_1"), Collections.singletonList(new RouteMapper("t_order", "t_order_0")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); - when(queryContext.getSqlStatementContext()).thenReturn(new CreateTableStatementContext(sqlStatement, "foo_db")); + when(queryContext.getSqlStatementContext()).thenReturn(new CreateTableStatementContext(sqlStatement)); assertDoesNotThrow(() -> new ShardingCreateTableRouteContextChecker().check(shardingRule, queryContext, database, mock(ConfigurationProperties.class), routeContext)); } @@ -85,7 +85,7 @@ void assertCheckWithDifferentRouteResultShardingTableForPostgreSQL() { Collection routeUnits = new LinkedList<>(); routeUnits.add(new RouteUnit(new RouteMapper("ds_0", "ds_0"), Collections.singletonList(new RouteMapper("t_order", "t_order_0")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); - when(queryContext.getSqlStatementContext()).thenReturn(new CreateTableStatementContext(sqlStatement, "foo_db")); + when(queryContext.getSqlStatementContext()).thenReturn(new CreateTableStatementContext(sqlStatement)); assertThrows(ShardingDDLRouteException.class, () -> new ShardingCreateTableRouteContextChecker().check(shardingRule, queryContext, database, mock(ConfigurationProperties.class), routeContext)); } @@ -94,7 +94,7 @@ void assertCheckWithDifferentRouteResultShardingTableForPostgreSQL() { void assertCheckWithSameRouteResultBroadcastTableForPostgreSQL() { PostgreSQLCreateTableStatement sqlStatement = new PostgreSQLCreateTableStatement(false); sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_config")))); - when(queryContext.getSqlStatementContext()).thenReturn(new CreateTableStatementContext(sqlStatement, "foo_db")); + when(queryContext.getSqlStatementContext()).thenReturn(new CreateTableStatementContext(sqlStatement)); assertDoesNotThrow(() -> new ShardingCreateTableRouteContextChecker().check(shardingRule, queryContext, database, mock(ConfigurationProperties.class), routeContext)); } } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingDropIndexRouteContextCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingDropIndexRouteContextCheckerTest.java index 1118626b51e10..9d57556c3eedf 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingDropIndexRouteContextCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingDropIndexRouteContextCheckerTest.java @@ -79,7 +79,7 @@ void assertCheckWithSameRouteResultShardingTableIndexForPostgreSQL() { routeUnits.add(new RouteUnit(new RouteMapper("ds_0", "ds_0"), Collections.singletonList(new RouteMapper("t_order", "t_order_0")))); routeUnits.add(new RouteUnit(new RouteMapper("ds_1", "ds_1"), Collections.singletonList(new RouteMapper("t_order", "t_order_0")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); - when(queryContext.getSqlStatementContext()).thenReturn(new DropIndexStatementContext(sqlStatement, "foo_db")); + when(queryContext.getSqlStatementContext()).thenReturn(new DropIndexStatementContext(sqlStatement)); assertDoesNotThrow(() -> new ShardingDropIndexRouteContextChecker().check(shardingRule, queryContext, database, mock(ConfigurationProperties.class), routeContext)); } @@ -98,7 +98,7 @@ void assertCheckWithDifferentRouteResultShardingTableIndexForPostgreSQL() { Collection routeUnits = new LinkedList<>(); routeUnits.add(new RouteUnit(new RouteMapper("ds_0", "ds_0"), Collections.singletonList(new RouteMapper("t_order", "t_order_0")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); - when(queryContext.getSqlStatementContext()).thenReturn(new DropIndexStatementContext(sqlStatement, "foo_db")); + when(queryContext.getSqlStatementContext()).thenReturn(new DropIndexStatementContext(sqlStatement)); assertThrows(ShardingDDLRouteException.class, () -> new ShardingDropIndexRouteContextChecker().check(shardingRule, queryContext, database, mock(ConfigurationProperties.class), routeContext)); } } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingDropTableRouteContextCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingDropTableRouteContextCheckerTest.java index 68958c4eda4f1..4a26cb3d8aff9 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingDropTableRouteContextCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingDropTableRouteContextCheckerTest.java @@ -94,7 +94,7 @@ void assertCheckWhenDropTableInUsedForMySQL() { routeUnits.add(routeUnit); RouteContext routeContext = mock(RouteContext.class); when(routeContext.getRouteUnits()).thenReturn(routeUnits); - when(queryContext.getSqlStatementContext()).thenReturn(new DropTableStatementContext(sqlStatement, "foo_db")); + when(queryContext.getSqlStatementContext()).thenReturn(new DropTableStatementContext(sqlStatement)); assertThrows(InUsedTablesException.class, () -> new ShardingDropTableRouteContextChecker().check(shardingRule, queryContext, database, mock(ConfigurationProperties.class), routeContext)); } @@ -127,7 +127,7 @@ void assertCheckWithSameRouteResultShardingTableForPostgreSQL() { routeUnits.add(new RouteUnit(new RouteMapper("ds_0", "ds_0"), Collections.singleton(new RouteMapper("t_order", "t_order_0")))); routeUnits.add(new RouteUnit(new RouteMapper("ds_1", "ds_1"), Collections.singleton(new RouteMapper("t_order", "t_order_0")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); - when(queryContext.getSqlStatementContext()).thenReturn(new DropTableStatementContext(sqlStatement, "foo_db")); + when(queryContext.getSqlStatementContext()).thenReturn(new DropTableStatementContext(sqlStatement)); assertDoesNotThrow(() -> new ShardingDropTableRouteContextChecker().check(shardingRule, queryContext, mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS), mock(ConfigurationProperties.class), routeContext)); } @@ -141,7 +141,7 @@ void assertCheckWithDifferentRouteResultShardingTableForPostgreSQL() { Collection routeUnits = new LinkedList<>(); routeUnits.add(new RouteUnit(new RouteMapper("ds_0", "ds_0"), Collections.singleton(new RouteMapper("t_order", "t_order_0")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); - when(queryContext.getSqlStatementContext()).thenReturn(new DropTableStatementContext(sqlStatement, "foo_db")); + when(queryContext.getSqlStatementContext()).thenReturn(new DropTableStatementContext(sqlStatement)); assertThrows(ShardingDDLRouteException.class, () -> new ShardingDropTableRouteContextChecker().check(shardingRule, queryContext, mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS), mock(ConfigurationProperties.class), routeContext)); } @@ -155,7 +155,7 @@ void assertCheckWithSameRouteResultBroadcastTableForPostgreSQL() { routeUnits.add(new RouteUnit(new RouteMapper("ds_0", "ds_0"), Collections.singleton(new RouteMapper("t_config", "t_config")))); routeUnits.add(new RouteUnit(new RouteMapper("ds_1", "ds_1"), Collections.singleton(new RouteMapper("t_config", "t_config")))); when(routeContext.getRouteUnits()).thenReturn(routeUnits); - when(queryContext.getSqlStatementContext()).thenReturn(new DropTableStatementContext(sqlStatement, "foo_db")); + when(queryContext.getSqlStatementContext()).thenReturn(new DropTableStatementContext(sqlStatement)); assertDoesNotThrow(() -> new ShardingDropTableRouteContextChecker().check(shardingRule, queryContext, mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS), mock(ConfigurationProperties.class), routeContext)); } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingRenameTableRouteContextCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingRenameTableRouteContextCheckerTest.java index 8500bab365c68..5be926ffb604f 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingRenameTableRouteContextCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/ddl/ShardingRenameTableRouteContextCheckerTest.java @@ -91,6 +91,6 @@ private SQLStatementContext createRenameTableStatementContext() { renameTableDefinitionSegment.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); renameTableDefinitionSegment.setRenameTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_user_order")))); sqlStatement.getRenameTables().add(renameTableDefinitionSegment); - return new RenameTableStatementContext(sqlStatement, "foo_db"); + return new RenameTableStatementContext(sqlStatement); } } diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/dml/ShardingUpdateRouteContextCheckerTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/dml/ShardingUpdateRouteContextCheckerTest.java index 9ec657382d831..160e2a9926420 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/dml/ShardingUpdateRouteContextCheckerTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/checker/dml/ShardingUpdateRouteContextCheckerTest.java @@ -72,7 +72,7 @@ class ShardingUpdateRouteContextCheckerTest { @Test void assertCheckWhenNotUpdateShardingColumn() { - UpdateStatementContext sqlStatementContext = new UpdateStatementContext(createUpdateStatement(), "foo_db"); + UpdateStatementContext sqlStatementContext = new UpdateStatementContext(createUpdateStatement()); when(queryContext.getSqlStatementContext()).thenReturn(sqlStatementContext); assertDoesNotThrow(() -> new ShardingUpdateRouteContextChecker().check(shardingRule, queryContext, database, mock(ConfigurationProperties.class), mock(RouteContext.class))); } @@ -80,14 +80,14 @@ void assertCheckWhenNotUpdateShardingColumn() { @Test void assertCheckWhenUpdateShardingColumnWithSameRouteContext() { mockShardingRuleForUpdateShardingColumn(); - when(queryContext.getSqlStatementContext()).thenReturn(new UpdateStatementContext(createUpdateStatement(), "foo_db")); + when(queryContext.getSqlStatementContext()).thenReturn(new UpdateStatementContext(createUpdateStatement())); assertDoesNotThrow(() -> new ShardingUpdateRouteContextChecker().check(shardingRule, queryContext, database, mock(ConfigurationProperties.class), createSingleRouteContext())); } @Test void assertCheckWhenUpdateShardingColumnWithDifferentRouteContext() { mockShardingRuleForUpdateShardingColumn(); - when(queryContext.getSqlStatementContext()).thenReturn(new UpdateStatementContext(createUpdateStatement(), "foo_db")); + when(queryContext.getSqlStatementContext()).thenReturn(new UpdateStatementContext(createUpdateStatement())); assertThrows(UnsupportedUpdatingShardingValueException.class, () -> new ShardingUpdateRouteContextChecker().check(shardingRule, queryContext, database, mock(ConfigurationProperties.class), createFullRouteContext())); } 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 cbbe43c2a274c..755d1da8837d0 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 @@ -160,7 +160,7 @@ void assertNewInstanceForDCLForSingleTableForSQL92() { private void assertNewInstanceForDCLForSingleTable(final GrantStatement grantStatement) { grantStatement.getTables().add(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl")))); - GrantStatementContext sqlStatementContext = new GrantStatementContext(grantStatement, "foo_db"); + GrantStatementContext sqlStatementContext = new GrantStatementContext(grantStatement); 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/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java index 2ce342a18e82d..4d2c328ee126f 100644 --- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java +++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/rule/ShardingRuleTest.java @@ -675,7 +675,7 @@ void assertIsAllBindingTableWithJoinQueryWithDatabaseJoinConditionInUpperCaseAnd Collection tableSegments = Arrays.asList( new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("LOGIC_TABLE"))), new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("SUB_LOGIC_TABLE")))); - TablesContext tablesContext = new TablesContext(tableSegments, Collections.emptyMap(), databaseType, "foo_db"); + TablesContext tablesContext = new TablesContext(tableSegments, Collections.emptyMap()); when(sqlStatementContext.getTablesContext()).thenReturn(tablesContext); when(sqlStatementContext.getDatabaseType()).thenReturn(databaseType); ShardingSphereDatabase database = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContext.java index e137bbe16b19e..50fb33851a60e 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContext.java @@ -27,17 +27,13 @@ import org.apache.shardingsphere.infra.binder.context.segment.select.subquery.SubqueryTableContext; import org.apache.shardingsphere.infra.binder.context.segment.select.subquery.engine.SubqueryTableContextEngine; import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext; -import org.apache.shardingsphere.infra.database.core.metadata.database.DialectDatabaseMetaData; -import org.apache.shardingsphere.infra.database.core.type.DatabaseType; -import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; -import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.OwnerSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SubqueryTableSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableSegment; -import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; import java.util.Collection; import java.util.Collections; @@ -69,33 +65,29 @@ public final class TablesContext { @Getter(AccessLevel.NONE) private final Map> subqueryTables = new HashMap<>(); - private final Map tableAliasNameMap = new HashMap<>(); - - public TablesContext(final SimpleTableSegment table, final DatabaseType databaseType, final String currentDatabaseName) { - this(null == table ? Collections.emptyList() : Collections.singletonList(table), databaseType, currentDatabaseName); + public TablesContext(final SimpleTableSegment table) { + this(null == table ? Collections.emptyList() : Collections.singletonList(table)); } - public TablesContext(final Collection tables, final DatabaseType databaseType, final String currentDatabaseName) { - this(tables, Collections.emptyMap(), databaseType, currentDatabaseName); + public TablesContext(final Collection tables) { + this(tables, Collections.emptyMap()); } - public TablesContext(final Collection tables, final Map subqueryContexts, - final DatabaseType databaseType, final String currentDatabaseName) { + public TablesContext(final Collection tables, final Map subqueryContexts) { if (tables.isEmpty()) { return; } this.tables.addAll(tables); for (TableSegment each : tables) { if (each instanceof SimpleTableSegment) { - String tableName = ((SimpleTableSegment) each).getTableName().getIdentifier().getValue(); - if (!"DUAL".equalsIgnoreCase(tableName)) { - SimpleTableSegment simpleTableSegment = (SimpleTableSegment) each; + SimpleTableSegment simpleTableSegment = (SimpleTableSegment) each; + TableNameSegment tableName = simpleTableSegment.getTableName(); + if (!"DUAL".equalsIgnoreCase(tableName.getIdentifier().getValue())) { simpleTables.add(simpleTableSegment); - tableNames.add(tableName); - // TODO use SQL binder result when statement which contains tables support bind logic - simpleTableSegment.getOwner().ifPresent(optional -> schemaNames.add(optional.getIdentifier().getValue())); - databaseNames.add(findDatabaseName(simpleTableSegment, databaseType).orElse(currentDatabaseName)); - tableAliasNameMap.put(each.getAlias().map(IdentifierValue::getValue).orElse(tableName).toLowerCase(), tableName.toLowerCase()); + tableNames.add(tableName.getIdentifier().getValue()); + // TODO support bind with all statement contains table segement @duanzhengqiang + tableName.getTableBoundInfo().ifPresent(optional -> schemaNames.add(optional.getOriginalSchema().getValue())); + tableName.getTableBoundInfo().ifPresent(optional -> databaseNames.add(optional.getOriginalDatabase().getValue())); } } if (each instanceof SubqueryTableSegment) { @@ -104,12 +96,6 @@ public TablesContext(final Collection tables, final Map< } } - private Optional findDatabaseName(final SimpleTableSegment tableSegment, final DatabaseType databaseType) { - DialectDatabaseMetaData dialectDatabaseMetaData = new DatabaseTypeRegistry(databaseType).getDialectDatabaseMetaData(); - Optional owner = dialectDatabaseMetaData.getDefaultSchema().isPresent() ? tableSegment.getOwner().flatMap(OwnerSegment::getOwner) : tableSegment.getOwner(); - return owner.map(optional -> optional.getIdentifier().getValue()); - } - private Map> createSubqueryTables(final Map subqueryContexts, final SubqueryTableSegment subqueryTable) { if (!subqueryContexts.containsKey(subqueryTable.getSubquery().getStartIndex())) { return Collections.emptyMap(); diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/SQLStatementContextFactory.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/SQLStatementContextFactory.java index fdfdf048fc28f..dce944382f904 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/SQLStatementContextFactory.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/SQLStatementContextFactory.java @@ -134,10 +134,10 @@ public static SQLStatementContext newInstance(final ShardingSphereMetaData metaD return getDDLStatementContext(metaData, (DDLStatement) sqlStatement, params, currentDatabaseName); } if (sqlStatement instanceof DCLStatement) { - return getDCLStatementContext((DCLStatement) sqlStatement, currentDatabaseName); + return getDCLStatementContext((DCLStatement) sqlStatement); } if (sqlStatement instanceof DALStatement) { - return getDALStatementContext((DALStatement) sqlStatement, currentDatabaseName); + return getDALStatementContext((DALStatement) sqlStatement); } return new UnknownSQLStatementContext(sqlStatement); } @@ -147,22 +147,22 @@ private static SQLStatementContext getDMLStatementContext(final ShardingSphereMe return new SelectStatementContext(metaData, params, (SelectStatement) sqlStatement, currentDatabaseName, Collections.emptyList()); } if (sqlStatement instanceof UpdateStatement) { - return new UpdateStatementContext((UpdateStatement) sqlStatement, currentDatabaseName); + return new UpdateStatementContext((UpdateStatement) sqlStatement); } if (sqlStatement instanceof DeleteStatement) { - return new DeleteStatementContext((DeleteStatement) sqlStatement, currentDatabaseName); + return new DeleteStatementContext((DeleteStatement) sqlStatement); } if (sqlStatement instanceof InsertStatement) { return new InsertStatementContext(metaData, params, (InsertStatement) sqlStatement, currentDatabaseName); } if (sqlStatement instanceof CopyStatement) { - return new CopyStatementContext((CopyStatement) sqlStatement, currentDatabaseName); + return new CopyStatementContext((CopyStatement) sqlStatement); } if (sqlStatement instanceof LoadDataStatement) { - return new LoadDataStatementContext((LoadDataStatement) sqlStatement, currentDatabaseName); + return new LoadDataStatementContext((LoadDataStatement) sqlStatement); } if (sqlStatement instanceof LoadXMLStatement) { - return new LoadXMLStatementContext((LoadXMLStatement) sqlStatement, currentDatabaseName); + return new LoadXMLStatementContext((LoadXMLStatement) sqlStatement); } if (sqlStatement instanceof CallStatement || sqlStatement instanceof DoStatement || sqlStatement instanceof MergeStatement) { return new UnknownSQLStatementContext(sqlStatement); @@ -175,87 +175,87 @@ private static SQLStatementContext getDDLStatementContext(final ShardingSphereMe return new CreateSchemaStatementContext((CreateSchemaStatement) sqlStatement); } if (sqlStatement instanceof CreateTableStatement) { - return new CreateTableStatementContext((CreateTableStatement) sqlStatement, currentDatabaseName); + return new CreateTableStatementContext((CreateTableStatement) sqlStatement); } if (sqlStatement instanceof AlterTableStatement) { - return new AlterTableStatementContext((AlterTableStatement) sqlStatement, currentDatabaseName); + return new AlterTableStatementContext((AlterTableStatement) sqlStatement); } if (sqlStatement instanceof RenameTableStatement) { - return new RenameTableStatementContext((RenameTableStatement) sqlStatement, currentDatabaseName); + return new RenameTableStatementContext((RenameTableStatement) sqlStatement); } if (sqlStatement instanceof DropTableStatement) { - return new DropTableStatementContext((DropTableStatement) sqlStatement, currentDatabaseName); + return new DropTableStatementContext((DropTableStatement) sqlStatement); } if (sqlStatement instanceof CreateIndexStatement) { - return new CreateIndexStatementContext((CreateIndexStatement) sqlStatement, currentDatabaseName); + return new CreateIndexStatementContext((CreateIndexStatement) sqlStatement); } if (sqlStatement instanceof AlterIndexStatement) { - return new AlterIndexStatementContext((AlterIndexStatement) sqlStatement, currentDatabaseName); + return new AlterIndexStatementContext((AlterIndexStatement) sqlStatement); } if (sqlStatement instanceof DropIndexStatement) { - return new DropIndexStatementContext((DropIndexStatement) sqlStatement, currentDatabaseName); + return new DropIndexStatementContext((DropIndexStatement) sqlStatement); } if (sqlStatement instanceof TruncateStatement) { - return new TruncateStatementContext((TruncateStatement) sqlStatement, currentDatabaseName); + return new TruncateStatementContext((TruncateStatement) sqlStatement); } if (sqlStatement instanceof CreateFunctionStatement) { - return new CreateFunctionStatementContext((CreateFunctionStatement) sqlStatement, currentDatabaseName); + return new CreateFunctionStatementContext((CreateFunctionStatement) sqlStatement); } if (sqlStatement instanceof CreateProcedureStatement) { - return new CreateProcedureStatementContext((CreateProcedureStatement) sqlStatement, currentDatabaseName); + return new CreateProcedureStatementContext((CreateProcedureStatement) sqlStatement); } if (sqlStatement instanceof CreateViewStatement) { - return new CreateViewStatementContext((CreateViewStatement) sqlStatement, currentDatabaseName); + return new CreateViewStatementContext((CreateViewStatement) sqlStatement); } if (sqlStatement instanceof AlterViewStatement) { - return new AlterViewStatementContext((AlterViewStatement) sqlStatement, currentDatabaseName); + return new AlterViewStatementContext((AlterViewStatement) sqlStatement); } if (sqlStatement instanceof DropViewStatement) { - return new DropViewStatementContext((DropViewStatement) sqlStatement, currentDatabaseName); + return new DropViewStatementContext((DropViewStatement) sqlStatement); } if (sqlStatement instanceof PrepareStatement) { - return new PrepareStatementContext((PrepareStatement) sqlStatement, currentDatabaseName); + return new PrepareStatementContext((PrepareStatement) sqlStatement); } if (sqlStatement instanceof CommentStatement) { - return new CommentStatementContext((CommentStatement) sqlStatement, currentDatabaseName); + return new CommentStatementContext((CommentStatement) sqlStatement); } if (sqlStatement instanceof CursorStatement) { return new CursorStatementContext(metaData, params, (CursorStatement) sqlStatement, currentDatabaseName); } if (sqlStatement instanceof CloseStatement) { - return new CloseStatementContext((CloseStatement) sqlStatement, currentDatabaseName); + return new CloseStatementContext((CloseStatement) sqlStatement); } if (sqlStatement instanceof MoveStatement) { - return new MoveStatementContext((MoveStatement) sqlStatement, currentDatabaseName); + return new MoveStatementContext((MoveStatement) sqlStatement); } if (sqlStatement instanceof FetchStatement) { - return new FetchStatementContext((FetchStatement) sqlStatement, currentDatabaseName); + return new FetchStatementContext((FetchStatement) sqlStatement); } return new UnknownSQLStatementContext(sqlStatement); } - private static SQLStatementContext getDCLStatementContext(final DCLStatement sqlStatement, final String currentDatabaseName) { + private static SQLStatementContext getDCLStatementContext(final DCLStatement sqlStatement) { if (sqlStatement instanceof GrantStatement) { - return new GrantStatementContext((GrantStatement) sqlStatement, currentDatabaseName); + return new GrantStatementContext((GrantStatement) sqlStatement); } if (sqlStatement instanceof RevokeStatement) { - return new RevokeStatementContext((RevokeStatement) sqlStatement, currentDatabaseName); + return new RevokeStatementContext((RevokeStatement) sqlStatement); } if (sqlStatement instanceof DenyUserStatement) { - return new DenyUserStatementContext((DenyUserStatement) sqlStatement, currentDatabaseName); + return new DenyUserStatementContext((DenyUserStatement) sqlStatement); } return new UnknownSQLStatementContext(sqlStatement); } - private static SQLStatementContext getDALStatementContext(final DALStatement sqlStatement, final String currentDatabaseName) { + private static SQLStatementContext getDALStatementContext(final DALStatement sqlStatement) { if (sqlStatement instanceof ExplainStatement) { - return new ExplainStatementContext((ExplainStatement) sqlStatement, currentDatabaseName); + return new ExplainStatementContext((ExplainStatement) sqlStatement); } if (sqlStatement instanceof ShowCreateTableStatement) { - return new ShowCreateTableStatementContext((ShowCreateTableStatement) sqlStatement, currentDatabaseName); + return new ShowCreateTableStatementContext((ShowCreateTableStatement) sqlStatement); } if (sqlStatement instanceof ShowColumnsStatement) { - return new ShowColumnsStatementContext((ShowColumnsStatement) sqlStatement, currentDatabaseName); + return new ShowColumnsStatementContext((ShowColumnsStatement) sqlStatement); } if (sqlStatement instanceof ShowTablesStatement) { return new ShowTablesStatementContext((ShowTablesStatement) sqlStatement); @@ -264,16 +264,16 @@ private static SQLStatementContext getDALStatementContext(final DALStatement sql return new ShowTableStatusStatementContext((ShowTableStatusStatement) sqlStatement); } if (sqlStatement instanceof ShowIndexStatement) { - return new ShowIndexStatementContext((ShowIndexStatement) sqlStatement, currentDatabaseName); + return new ShowIndexStatementContext((ShowIndexStatement) sqlStatement); } if (sqlStatement instanceof AnalyzeTableStatement) { - return new AnalyzeTableStatementContext((AnalyzeTableStatement) sqlStatement, currentDatabaseName); + return new AnalyzeTableStatementContext((AnalyzeTableStatement) sqlStatement); } if (sqlStatement instanceof FlushStatement) { - return new FlushStatementContext((FlushStatement) sqlStatement, currentDatabaseName); + return new FlushStatementContext((FlushStatement) sqlStatement); } if (sqlStatement instanceof OptimizeTableStatement) { - return new OptimizeTableStatementContext((OptimizeTableStatement) sqlStatement, currentDatabaseName); + return new OptimizeTableStatementContext((OptimizeTableStatement) sqlStatement); } return new UnknownSQLStatementContext(sqlStatement); } diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/AnalyzeTableStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/AnalyzeTableStatementContext.java index a17889aa1a9a2..8264edfec5da4 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/AnalyzeTableStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/AnalyzeTableStatementContext.java @@ -31,9 +31,9 @@ public final class AnalyzeTableStatementContext extends CommonSQLStatementContex private final TablesContext tablesContext; - public AnalyzeTableStatementContext(final AnalyzeTableStatement sqlStatement, final String currentDatabaseName) { + public AnalyzeTableStatementContext(final AnalyzeTableStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(sqlStatement.getTables(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(sqlStatement.getTables()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ExplainStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ExplainStatementContext.java index 57ed251ced076..b97ba364c0d28 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ExplainStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ExplainStatementContext.java @@ -37,9 +37,9 @@ public final class ExplainStatementContext extends CommonSQLStatementContext imp private final TablesContext tablesContext; - public ExplainStatementContext(final ExplainStatement sqlStatement, final String currentDatabaseName) { + public ExplainStatementContext(final ExplainStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(extractTablesFromExplain(sqlStatement), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(extractTablesFromExplain(sqlStatement)); } private Collection extractTablesFromExplain(final ExplainStatement sqlStatement) { diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/FlushStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/FlushStatementContext.java index 2854ff80d2825..0ce573efb189d 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/FlushStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/FlushStatementContext.java @@ -31,9 +31,9 @@ public final class FlushStatementContext extends CommonSQLStatementContext imple private final TablesContext tablesContext; - public FlushStatementContext(final FlushStatement sqlStatement, final String currentDatabaseName) { + public FlushStatementContext(final FlushStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(sqlStatement.getTables(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(sqlStatement.getTables()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/OptimizeTableStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/OptimizeTableStatementContext.java index bf9cedb76342b..2fd4a2c617042 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/OptimizeTableStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/OptimizeTableStatementContext.java @@ -31,9 +31,9 @@ public final class OptimizeTableStatementContext extends CommonSQLStatementConte private final TablesContext tablesContext; - public OptimizeTableStatementContext(final OptimizeTableStatement sqlStatement, final String currentDatabaseName) { + public OptimizeTableStatementContext(final OptimizeTableStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(sqlStatement.getTables(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(sqlStatement.getTables()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowColumnsStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowColumnsStatementContext.java index c0501b126805e..7f0279ba3e99c 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowColumnsStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowColumnsStatementContext.java @@ -36,9 +36,9 @@ public final class ShowColumnsStatementContext extends CommonSQLStatementContext private final TablesContext tablesContext; - public ShowColumnsStatementContext(final ShowColumnsStatement sqlStatement, final String currentDatabaseName) { + public ShowColumnsStatementContext(final ShowColumnsStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(sqlStatement.getTable(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(sqlStatement.getTable()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowCreateTableStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowCreateTableStatementContext.java index d626c28aa05ff..b6ab3f2293ddd 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowCreateTableStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowCreateTableStatementContext.java @@ -31,9 +31,9 @@ public final class ShowCreateTableStatementContext extends CommonSQLStatementCon private final TablesContext tablesContext; - public ShowCreateTableStatementContext(final ShowCreateTableStatement sqlStatement, final String currentDatabaseName) { + public ShowCreateTableStatementContext(final ShowCreateTableStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(sqlStatement.getTable(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(sqlStatement.getTable()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowIndexStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowIndexStatementContext.java index 2a0d3bd8a58c8..653da167b4177 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowIndexStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowIndexStatementContext.java @@ -36,9 +36,9 @@ public final class ShowIndexStatementContext extends CommonSQLStatementContext i private final TablesContext tablesContext; - public ShowIndexStatementContext(final ShowIndexStatement sqlStatement, final String currentDatabaseName) { + public ShowIndexStatementContext(final ShowIndexStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(sqlStatement.getTable(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(sqlStatement.getTable()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/DenyUserStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/DenyUserStatementContext.java index 36010fb630246..49341412bb1f1 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/DenyUserStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/DenyUserStatementContext.java @@ -31,9 +31,9 @@ public final class DenyUserStatementContext extends CommonSQLStatementContext im private final TablesContext tablesContext; - public DenyUserStatementContext(final DenyUserStatement sqlStatement, final String currentDatabaseName) { + public DenyUserStatementContext(final DenyUserStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(sqlStatement.getTable(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(sqlStatement.getTable()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/GrantStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/GrantStatementContext.java index 3c7acfa3d1d27..b7e62ab80077b 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/GrantStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/GrantStatementContext.java @@ -31,9 +31,9 @@ public final class GrantStatementContext extends CommonSQLStatementContext imple private final TablesContext tablesContext; - public GrantStatementContext(final GrantStatement sqlStatement, final String currentDatabaseName) { + public GrantStatementContext(final GrantStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(sqlStatement.getTables(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(sqlStatement.getTables()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/RevokeStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/RevokeStatementContext.java index 6a5ff0fb8975d..eec519646120a 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/RevokeStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/RevokeStatementContext.java @@ -31,9 +31,9 @@ public final class RevokeStatementContext extends CommonSQLStatementContext impl private final TablesContext tablesContext; - public RevokeStatementContext(final RevokeStatement sqlStatement, final String currentDatabaseName) { + public RevokeStatementContext(final RevokeStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(sqlStatement.getTables(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(sqlStatement.getTables()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterIndexStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterIndexStatementContext.java index 15da776f23e7b..28b335fdfa8da 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterIndexStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterIndexStatementContext.java @@ -39,10 +39,10 @@ public final class AlterIndexStatementContext extends CommonSQLStatementContext private final TablesContext tablesContext; - public AlterIndexStatementContext(final AlterIndexStatement sqlStatement, final String currentDatabaseName) { + public AlterIndexStatementContext(final AlterIndexStatement sqlStatement) { super(sqlStatement); SimpleTableSegment simpleTableSegment = sqlStatement.getSimpleTable().orElse(null); - tablesContext = new TablesContext(simpleTableSegment, getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(simpleTableSegment); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterTableStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterTableStatementContext.java index 3dfe294409b5e..21be1d92fe533 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterTableStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterTableStatementContext.java @@ -48,9 +48,9 @@ public final class AlterTableStatementContext extends CommonSQLStatementContext private final TablesContext tablesContext; - public AlterTableStatementContext(final AlterTableStatement sqlStatement, final String currentDatabaseName) { + public AlterTableStatementContext(final AlterTableStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(getTables(sqlStatement), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(getTables(sqlStatement)); } private Collection getTables(final AlterTableStatement sqlStatement) { diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterViewStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterViewStatementContext.java index 5406c78f1be9c..1b0e25a3c07b0 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterViewStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterViewStatementContext.java @@ -38,7 +38,7 @@ public final class AlterViewStatementContext extends CommonSQLStatementContext i private final TablesContext tablesContext; - public AlterViewStatementContext(final AlterViewStatement sqlStatement, final String currentDatabaseName) { + public AlterViewStatementContext(final AlterViewStatement sqlStatement) { super(sqlStatement); Collection tables = new LinkedList<>(); tables.add(sqlStatement.getView()); @@ -49,7 +49,7 @@ public AlterViewStatementContext(final AlterViewStatement sqlStatement, final St tables.addAll(extractor.getRewriteTables()); }); sqlStatement.getRenameView().ifPresent(tables::add); - tablesContext = new TablesContext(tables, getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(tables); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CloseStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CloseStatementContext.java index 95bb62adeb9a7..e8b4a9c867d1f 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CloseStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CloseStatementContext.java @@ -44,9 +44,9 @@ public final class CloseStatementContext extends CommonSQLStatementContext imple private TablesContext tablesContext; - public CloseStatementContext(final CloseStatement sqlStatement, final String currentDatabaseName) { + public CloseStatementContext(final CloseStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(Collections.emptyList(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(Collections.emptyList()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CommentStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CommentStatementContext.java index 79605ca3ba48d..1fa10fbbc4ff4 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CommentStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CommentStatementContext.java @@ -33,9 +33,9 @@ public final class CommentStatementContext extends CommonSQLStatementContext imp private final TablesContext tablesContext; - public CommentStatementContext(final CommentStatement sqlStatement, final String currentDatabaseName) { + public CommentStatementContext(final CommentStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(null == sqlStatement.getTable() ? Collections.emptyList() : Collections.singletonList(sqlStatement.getTable()), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(null == sqlStatement.getTable() ? Collections.emptyList() : Collections.singletonList(sqlStatement.getTable())); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateFunctionStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateFunctionStatementContext.java index a07f00f2a20ec..0264709615d3e 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateFunctionStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateFunctionStatementContext.java @@ -37,11 +37,11 @@ public final class CreateFunctionStatementContext extends CommonSQLStatementCont private final TablesContext tablesContext; - public CreateFunctionStatementContext(final CreateFunctionStatement sqlStatement, final String currentDatabaseName) { + public CreateFunctionStatementContext(final CreateFunctionStatement sqlStatement) { super(sqlStatement); Optional routineBodySegment = sqlStatement.getRoutineBody(); Collection tables = routineBodySegment.map(optional -> new TableExtractor().extractExistTableFromRoutineBody(optional)).orElseGet(Collections::emptyList); - tablesContext = new TablesContext(tables, getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(tables); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateIndexStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateIndexStatementContext.java index 0b08db3bfaa62..e43ff274ecc79 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateIndexStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateIndexStatementContext.java @@ -42,9 +42,9 @@ public final class CreateIndexStatementContext extends CommonSQLStatementContext private final boolean generatedIndex; - public CreateIndexStatementContext(final CreateIndexStatement sqlStatement, final String currentDatabaseName) { + public CreateIndexStatementContext(final CreateIndexStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(sqlStatement.getTable(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(sqlStatement.getTable()); generatedIndex = null == sqlStatement.getIndex(); } diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateProcedureStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateProcedureStatementContext.java index b9ba75d010428..1bf88c0469827 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateProcedureStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateProcedureStatementContext.java @@ -37,11 +37,11 @@ public final class CreateProcedureStatementContext extends CommonSQLStatementCon private final TablesContext tablesContext; - public CreateProcedureStatementContext(final CreateProcedureStatement sqlStatement, final String currentDatabaseName) { + public CreateProcedureStatementContext(final CreateProcedureStatement sqlStatement) { super(sqlStatement); Optional routineBodySegment = sqlStatement.getRoutineBody(); Collection tables = routineBodySegment.map(optional -> new TableExtractor().extractExistTableFromRoutineBody(optional)).orElseGet(Collections::emptyList); - tablesContext = new TablesContext(tables, getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(tables); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateTableStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateTableStatementContext.java index d12cc0aa63b67..091fac0a2b574 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateTableStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateTableStatementContext.java @@ -42,9 +42,9 @@ public final class CreateTableStatementContext extends CommonSQLStatementContext private final TablesContext tablesContext; - public CreateTableStatementContext(final CreateTableStatement sqlStatement, final String currentDatabaseName) { + public CreateTableStatementContext(final CreateTableStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(getTables(sqlStatement), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(getTables(sqlStatement)); } private Collection getTables(final CreateTableStatement sqlStatement) { diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateViewStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateViewStatementContext.java index 83d2f8fd8d665..730d89b76db23 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateViewStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateViewStatementContext.java @@ -32,11 +32,11 @@ public final class CreateViewStatementContext extends CommonSQLStatementContext private final TablesContext tablesContext; - public CreateViewStatementContext(final CreateViewStatement sqlStatement, final String currentDatabaseName) { + public CreateViewStatementContext(final CreateViewStatement sqlStatement) { super(sqlStatement); TableExtractor extractor = new TableExtractor(); extractor.extractTablesFromCreateViewStatement(sqlStatement); - tablesContext = new TablesContext(extractor.getRewriteTables(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(extractor.getRewriteTables()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CursorStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CursorStatementContext.java index 4d6e67c71fe43..22c316fa3447f 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CursorStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CursorStatementContext.java @@ -25,13 +25,13 @@ import org.apache.shardingsphere.infra.binder.context.type.TableAvailable; import org.apache.shardingsphere.infra.binder.context.type.WhereAvailable; import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; +import org.apache.shardingsphere.sql.parser.statement.core.extractor.TableExtractor; import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.cursor.CursorNameSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.BinaryOperationExpression; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.ddl.CursorStatement; -import org.apache.shardingsphere.sql.parser.statement.core.extractor.TableExtractor; import java.util.Collection; import java.util.Collections; @@ -57,7 +57,7 @@ public final class CursorStatementContext extends CommonSQLStatementContext impl public CursorStatementContext(final ShardingSphereMetaData metaData, final List params, final CursorStatement sqlStatement, final String currentDatabaseName) { super(sqlStatement); - tablesContext = new TablesContext(getSimpleTableSegments(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(getSimpleTableSegments()); selectStatementContext = new SelectStatementContext(metaData, params, sqlStatement.getSelect(), currentDatabaseName, Collections.emptyList()); whereSegments.addAll(selectStatementContext.getWhereSegments()); columnSegments.addAll(selectStatementContext.getColumnSegments()); diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropIndexStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropIndexStatementContext.java index 0389b137afed8..88b389a5a1182 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropIndexStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropIndexStatementContext.java @@ -38,10 +38,10 @@ public final class DropIndexStatementContext extends CommonSQLStatementContext i private final TablesContext tablesContext; - public DropIndexStatementContext(final DropIndexStatement sqlStatement, final String currentDatabaseName) { + public DropIndexStatementContext(final DropIndexStatement sqlStatement) { super(sqlStatement); SimpleTableSegment simpleTableSegment = sqlStatement.getSimpleTable().orElse(null); - tablesContext = new TablesContext(simpleTableSegment, getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(simpleTableSegment); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropTableStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropTableStatementContext.java index 8babf0c8fa33a..9741d893d0d56 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropTableStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropTableStatementContext.java @@ -31,9 +31,9 @@ public final class DropTableStatementContext extends CommonSQLStatementContext i private final TablesContext tablesContext; - public DropTableStatementContext(final DropTableStatement sqlStatement, final String currentDatabaseName) { + public DropTableStatementContext(final DropTableStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(sqlStatement.getTables(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(sqlStatement.getTables()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropViewStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropViewStatementContext.java index 99ae13b289faa..6c5d158a01c9f 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropViewStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropViewStatementContext.java @@ -31,9 +31,9 @@ public final class DropViewStatementContext extends CommonSQLStatementContext im private final TablesContext tablesContext; - public DropViewStatementContext(final DropViewStatement sqlStatement, final String currentDatabaseName) { + public DropViewStatementContext(final DropViewStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(sqlStatement.getViews(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(sqlStatement.getViews()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/FetchStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/FetchStatementContext.java index 385b1736a17dd..2dbb0dd950897 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/FetchStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/FetchStatementContext.java @@ -44,9 +44,9 @@ public final class FetchStatementContext extends CommonSQLStatementContext imple private TablesContext tablesContext; - public FetchStatementContext(final FetchStatement sqlStatement, final String currentDatabaseName) { + public FetchStatementContext(final FetchStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(Collections.emptyList(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(Collections.emptyList()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/MoveStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/MoveStatementContext.java index d3f91659fc6b8..380ea200bb974 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/MoveStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/MoveStatementContext.java @@ -44,9 +44,9 @@ public final class MoveStatementContext extends CommonSQLStatementContext implem private TablesContext tablesContext; - public MoveStatementContext(final MoveStatement sqlStatement, final String currentDatabaseName) { + public MoveStatementContext(final MoveStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(Collections.emptyList(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(Collections.emptyList()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/PrepareStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/PrepareStatementContext.java index a97c1d8eaa9c5..007a3eda53d0c 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/PrepareStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/PrepareStatementContext.java @@ -36,9 +36,9 @@ public final class PrepareStatementContext extends CommonSQLStatementContext imp private final TablesContext tablesContext; - public PrepareStatementContext(final PrepareStatement sqlStatement, final String currentDatabaseName) { + public PrepareStatementContext(final PrepareStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(extractTablesFromPreparedStatement(sqlStatement), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(extractTablesFromPreparedStatement(sqlStatement)); } private Collection extractTablesFromPreparedStatement(final PrepareStatement sqlStatement) { diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/RenameTableStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/RenameTableStatementContext.java index 34d4b87f68fc9..550f36707ec9a 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/RenameTableStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/RenameTableStatementContext.java @@ -36,9 +36,9 @@ public final class RenameTableStatementContext extends CommonSQLStatementContext private final TablesContext tablesContext; - public RenameTableStatementContext(final RenameTableStatement sqlStatement, final String currentDatabaseName) { + public RenameTableStatementContext(final RenameTableStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(getTables(sqlStatement), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(getTables(sqlStatement)); } private Collection getTables(final RenameTableStatement sqlStatement) { diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/TruncateStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/TruncateStatementContext.java index b4a5d8323957a..e97aa018d29e8 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/TruncateStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/TruncateStatementContext.java @@ -31,9 +31,9 @@ public final class TruncateStatementContext extends CommonSQLStatementContext im private final TablesContext tablesContext; - public TruncateStatementContext(final TruncateStatement sqlStatement, final String currentDatabaseName) { + public TruncateStatementContext(final TruncateStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(sqlStatement.getTables(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(sqlStatement.getTables()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/CopyStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/CopyStatementContext.java index 4b157bd6969db..ce39780ad4858 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/CopyStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/CopyStatementContext.java @@ -31,9 +31,9 @@ public final class CopyStatementContext extends CommonSQLStatementContext implem private final TablesContext tablesContext; - public CopyStatementContext(final CopyStatement sqlStatement, final String currentDatabaseName) { + public CopyStatementContext(final CopyStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(sqlStatement.getTableSegment(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(sqlStatement.getTableSegment()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/DeleteStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/DeleteStatementContext.java index 4bde06fb361cd..d5a01ab9b1eb8 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/DeleteStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/DeleteStatementContext.java @@ -50,9 +50,9 @@ public final class DeleteStatementContext extends CommonSQLStatementContext impl private final Collection joinConditions = new LinkedList<>(); - public DeleteStatementContext(final DeleteStatement sqlStatement, final String currentDatabaseName) { + public DeleteStatementContext(final DeleteStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(getAllSimpleTableSegments(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(getAllSimpleTableSegments()); getSqlStatement().getWhere().ifPresent(whereSegments::add); ColumnExtractor.extractColumnSegments(columnSegments, whereSegments); ExpressionExtractor.extractJoinConditions(joinConditions, whereSegments); diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/InsertStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/InsertStatementContext.java index 2f48a3daada07..4b8de3e31b5e6 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/InsertStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/InsertStatementContext.java @@ -37,6 +37,7 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; import org.apache.shardingsphere.sql.parser.statement.core.enums.SubqueryType; +import org.apache.shardingsphere.sql.parser.statement.core.extractor.TableExtractor; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.assignment.ColumnAssignmentSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.assignment.InsertValuesSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.assignment.SetAssignmentSegment; @@ -49,7 +50,6 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.InsertStatement; -import org.apache.shardingsphere.sql.parser.statement.core.extractor.TableExtractor; import java.util.ArrayList; import java.util.Collection; @@ -101,7 +101,7 @@ public InsertStatementContext(final ShardingSphereMetaData metaData, final List< insertValueContexts = getInsertValueContexts(params, parametersOffset, valueExpressions); insertSelectContext = getInsertSelectContext(metaData, params, parametersOffset, currentDatabaseName).orElse(null); onDuplicateKeyUpdateValueContext = getOnDuplicateKeyUpdateValueContext(params, parametersOffset).orElse(null); - tablesContext = new TablesContext(getAllSimpleTableSegments(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(getAllSimpleTableSegments()); List insertColumnNames = getInsertColumnNames(); ShardingSphereSchema schema = getSchema(metaData, currentDatabaseName); columnNames = containsInsertColumns() diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/LoadDataStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/LoadDataStatementContext.java index 6b172406f9117..8cb65ff7e9be8 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/LoadDataStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/LoadDataStatementContext.java @@ -31,9 +31,9 @@ public final class LoadDataStatementContext extends CommonSQLStatementContext im private final TablesContext tablesContext; - public LoadDataStatementContext(final LoadDataStatement sqlStatement, final String currentDatabaseName) { + public LoadDataStatementContext(final LoadDataStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(sqlStatement.getTableSegment(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(sqlStatement.getTableSegment()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/LoadXMLStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/LoadXMLStatementContext.java index d4d804d138c0c..a3a32ca505e82 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/LoadXMLStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/LoadXMLStatementContext.java @@ -31,9 +31,9 @@ public final class LoadXMLStatementContext extends CommonSQLStatementContext imp private final TablesContext tablesContext; - public LoadXMLStatementContext(final LoadXMLStatement sqlStatement, final String currentDatabaseName) { + public LoadXMLStatementContext(final LoadXMLStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(sqlStatement.getTableSegment(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(sqlStatement.getTableSegment()); } @Override diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/SelectStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/SelectStatementContext.java index b094b2e3dc71b..36d9a28221d11 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/SelectStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/SelectStatementContext.java @@ -120,7 +120,7 @@ public SelectStatementContext(final ShardingSphereMetaData metaData, final List< Collection tableSegments = getAllTableSegments(inheritedTables); ExpressionExtractor.extractJoinConditions(joinConditions, whereSegments); subqueryContexts = createSubqueryContexts(metaData, params, currentDatabaseName, tableSegments); - tablesContext = new TablesContext(tableSegments, subqueryContexts, getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(tableSegments, subqueryContexts); groupByContext = new GroupByContextEngine().createGroupByContext(sqlStatement); orderByContext = new OrderByContextEngine().createOrderBy(sqlStatement, groupByContext); projectionsContext = new ProjectionsContextEngine(getDatabaseType()).createProjectionsContext(getSqlStatement().getProjections(), groupByContext, orderByContext); diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/UpdateStatementContext.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/UpdateStatementContext.java index bf0938e4b04a1..b8f1ad79bdcf4 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/UpdateStatementContext.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/UpdateStatementContext.java @@ -22,14 +22,14 @@ import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext; import org.apache.shardingsphere.infra.binder.context.type.TableAvailable; import org.apache.shardingsphere.infra.binder.context.type.WhereAvailable; +import org.apache.shardingsphere.sql.parser.statement.core.extractor.ColumnExtractor; +import org.apache.shardingsphere.sql.parser.statement.core.extractor.ExpressionExtractor; import org.apache.shardingsphere.sql.parser.statement.core.extractor.TableExtractor; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.BinaryOperationExpression; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.UpdateStatement; -import org.apache.shardingsphere.sql.parser.statement.core.extractor.ColumnExtractor; -import org.apache.shardingsphere.sql.parser.statement.core.extractor.ExpressionExtractor; import java.util.Collection; import java.util.LinkedList; @@ -48,9 +48,9 @@ public final class UpdateStatementContext extends CommonSQLStatementContext impl private final Collection joinConditions = new LinkedList<>(); - public UpdateStatementContext(final UpdateStatement sqlStatement, final String currentDatabaseName) { + public UpdateStatementContext(final UpdateStatement sqlStatement) { super(sqlStatement); - tablesContext = new TablesContext(getAllSimpleTableSegments(), getDatabaseType(), currentDatabaseName); + tablesContext = new TablesContext(getAllSimpleTableSegments()); getSqlStatement().getWhere().ifPresent(whereSegments::add); ColumnExtractor.extractColumnSegments(columnSegments, whereSegments); ExpressionExtractor.extractJoinConditions(joinConditions, whereSegments); diff --git a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/SimpleTableSegmentBinder.java b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/SimpleTableSegmentBinder.java index e77dc4f7f4ebe..be851ce38965e 100644 --- a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/SimpleTableSegmentBinder.java +++ b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/from/type/SimpleTableSegmentBinder.java @@ -89,6 +89,7 @@ public static SimpleTableSegment bind(final SimpleTableSegment segment, final SQ tableBinderContexts.put(new CaseInsensitiveString(segment.getAliasName().orElseGet(tableName::getValue)), createSimpleTableBinderContext(segment, schema, databaseName, schemaName, binderContext)); TableNameSegment tableNameSegment = new TableNameSegment(segment.getTableName().getStartIndex(), segment.getTableName().getStopIndex(), tableName); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(databaseName, schemaName)); SimpleTableSegment result = new SimpleTableSegment(tableNameSegment); segment.getOwner().ifPresent(result::setOwner); segment.getAliasSegment().ifPresent(result::setAlias); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/engine/ProjectionsContextEngineTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/engine/ProjectionsContextEngineTest.java index 3abaf2d0df173..145801229a9a5 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/engine/ProjectionsContextEngineTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/engine/ProjectionsContextEngineTest.java @@ -36,6 +36,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.order.item.IndexOrderByItemSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.AliasSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.OwnerSegment; +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.SubqueryTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; @@ -126,6 +127,7 @@ private void assertProjectionsContextCreatedProperlyWhenProjectionPresent(final selectStatement.setProjections(projectionsSegment); ShorthandProjectionSegment shorthandProjectionSegment = new ShorthandProjectionSegment(0, 10); OwnerSegment owner = new OwnerSegment(0, 10, new IdentifierValue("name")); + owner.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); shorthandProjectionSegment.setOwner(owner); projectionsSegment.getProjections().add(shorthandProjectionSegment); SelectStatementContext selectStatementContext = createSelectStatementContext(selectStatement); @@ -164,6 +166,7 @@ private void createProjectionsContextWhenOrderByContextOrderItemsPresent(final S selectStatement.setProjections(projectionsSegment); ShorthandProjectionSegment shorthandProjectionSegment = new ShorthandProjectionSegment(0, 10); OwnerSegment owner = new OwnerSegment(0, 10, new IdentifierValue("name")); + owner.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); shorthandProjectionSegment.setOwner(owner); projectionsSegment.getProjections().add(shorthandProjectionSegment); OrderByItem orderByItem = new OrderByItem(new IndexOrderByItemSegment(0, 1, 0, OrderDirection.ASC, NullsOrderType.FIRST)); @@ -204,6 +207,7 @@ private void assertCreateProjectionsContextWithoutIndexOrderByItemSegment(final selectStatement.setProjections(projectionsSegment); ShorthandProjectionSegment shorthandProjectionSegment = new ShorthandProjectionSegment(0, 10); OwnerSegment owner = new OwnerSegment(0, 10, new IdentifierValue("name")); + owner.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); shorthandProjectionSegment.setOwner(owner); projectionsSegment.getProjections().add(shorthandProjectionSegment); OrderByItem orderByItem = new OrderByItem(new ExpressionOrderByItemSegment(0, 1, "", OrderDirection.ASC, NullsOrderType.FIRST)); @@ -248,9 +252,12 @@ void assertCreateProjectionsContextWhenColumnOrderByItemSegmentOwnerAbsentForSQL private void assertCreateProjectionsContextWhenColumnOrderByItemSegmentOwnerAbsent(final SelectStatement selectStatement) { ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0); selectStatement.setProjections(projectionsSegment); - selectStatement.setFrom(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("name")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("name")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + selectStatement.setFrom(new SimpleTableSegment(tableNameSegment)); ShorthandProjectionSegment shorthandProjectionSegment = new ShorthandProjectionSegment(0, 10); OwnerSegment owner = new OwnerSegment(0, 10, new IdentifierValue("name")); + owner.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); shorthandProjectionSegment.setOwner(owner); projectionsSegment.getProjections().add(shorthandProjectionSegment); OrderByItem orderByItem = new OrderByItem(new ColumnOrderByItemSegment(new ColumnSegment(0, 0, new IdentifierValue("name")), OrderDirection.ASC, NullsOrderType.FIRST)); @@ -289,9 +296,12 @@ void assertCreateProjectionsContextWhenColumnOrderByItemSegmentOwnerPresentForSQ private void assertCreateProjectionsContextWhenColumnOrderByItemSegmentOwnerPresent(final SelectStatement selectStatement) { ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0); selectStatement.setProjections(projectionsSegment); - selectStatement.setFrom(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("name")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("name")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + selectStatement.setFrom(new SimpleTableSegment(tableNameSegment)); ShorthandProjectionSegment shorthandProjectionSegment = new ShorthandProjectionSegment(0, 10); OwnerSegment owner = new OwnerSegment(0, 10, new IdentifierValue("name")); + owner.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); shorthandProjectionSegment.setOwner(owner); projectionsSegment.getProjections().add(shorthandProjectionSegment); OrderByItem orderByItem = new OrderByItem(new ColumnOrderByItemSegment(new ColumnSegment(0, 0, new IdentifierValue("name")), OrderDirection.ASC, NullsOrderType.FIRST)); @@ -328,14 +338,17 @@ void assertCreateProjectionsContextWhenColumnOrderByItemSegmentOwnerPresentAndTa } private void assertCreateProjectionsContextWhenColumnOrderByItemSegmentOwnerPresentAndTablePresent(final SelectStatement selectStatement) { - SimpleTableSegment tableSegment = new SimpleTableSegment(new TableNameSegment(0, 10, new IdentifierValue("name"))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 10, new IdentifierValue("name")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + SimpleTableSegment tableSegment = new SimpleTableSegment(tableNameSegment); ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0); selectStatement.setProjections(projectionsSegment); tableSegment.setOwner(new OwnerSegment(0, 0, new IdentifierValue("foo_db"))); selectStatement.setFrom(tableSegment); ShorthandProjectionSegment shorthandProjectionSegment = new ShorthandProjectionSegment(0, 10); - SimpleTableSegment table = new SimpleTableSegment(new TableNameSegment(0, 10, new IdentifierValue("name"))); + SimpleTableSegment table = new SimpleTableSegment(tableNameSegment); OwnerSegment owner = new OwnerSegment(0, 10, new IdentifierValue("name")); + owner.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); table.setOwner(new OwnerSegment(0, 10, new IdentifierValue("name"))); shorthandProjectionSegment.setOwner(owner); ColumnSegment columnSegment = new ColumnSegment(0, 0, new IdentifierValue("col")); @@ -447,7 +460,9 @@ void assertCreateProjectionsContextWithOrderByExpressionForMySQL() { ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0); projectionsSegment.getProjections().add(new ShorthandProjectionSegment(0, 0)); selectStatement.setProjections(projectionsSegment); - selectStatement.setFrom(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("t_order")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + selectStatement.setFrom(new SimpleTableSegment(tableNameSegment)); OrderByItem orderByItem = new OrderByItem(new ExpressionOrderByItemSegment(0, 0, "id + 1", OrderDirection.ASC, NullsOrderType.FIRST)); OrderByContext orderByContext = new OrderByContext(Collections.singleton(orderByItem), false); SelectStatementContext selectStatementContext = createSelectStatementContext(selectStatement); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContextTest.java index 6beda71aba140..377c317dfb3da 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/table/TablesContextTest.java @@ -17,14 +17,13 @@ package org.apache.shardingsphere.infra.binder.context.segment.table; -import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable; -import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.AliasSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.OwnerSegment; +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.segment.generic.table.TableSegment; @@ -47,92 +46,94 @@ class TablesContextTest { - private final DatabaseType databaseType = TypedSPILoader.getService(DatabaseType.class, "FIXTURE"); - @Test void assertGetTableNamesWithoutTableSegments() { - assertTrue(new TablesContext(Collections.emptyList(), Collections.emptyMap(), databaseType, "foo_db").getTableNames().isEmpty()); + assertTrue(new TablesContext(Collections.emptyList(), Collections.emptyMap()).getTableNames().isEmpty()); } @Test void assertGetTableNamesWithoutSimpleTableSegments() { - assertTrue(new TablesContext(Collections.singleton(mock(TableSegment.class)), Collections.emptyMap(), databaseType, "foo_db").getTableNames().isEmpty()); + assertTrue(new TablesContext(Collections.singleton(mock(TableSegment.class)), Collections.emptyMap()).getTableNames().isEmpty()); } @Test void assertGetTableNames() { TablesContext tablesContext = new TablesContext( - Arrays.asList(createTableSegment("table_1", "tbl_1"), createTableSegment("table_2", "tbl_2"), createTableSegment("DUAL", "dual")), databaseType, "foo_db"); + Arrays.asList(createTableSegment("table_1", "tbl_1", "sharding_db_1"), createTableSegment("table_2", "tbl_2", "sharding_db_1"), createTableSegment("DUAL", "dual", "sharding_db_1"))); assertThat(tablesContext.getTableNames(), is(new HashSet<>(Arrays.asList("table_1", "table_2")))); } @Test void assertInstanceCreatedWhenNoExceptionThrown() { - SimpleTableSegment tableSegment = new SimpleTableSegment(new TableNameSegment(0, 10, new IdentifierValue("tbl"))); - tableSegment.setOwner(new OwnerSegment(0, 0, new IdentifierValue("schema"))); - TablesContext tablesContext = new TablesContext(Collections.singleton(tableSegment), databaseType, "foo_db"); - assertThat(tablesContext.getDatabaseName(), is(Optional.of("schema"))); - assertThat(tablesContext.getSchemaName(), is(Optional.of("schema"))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 10, new IdentifierValue("tbl")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_db"))); + SimpleTableSegment tableSegment = new SimpleTableSegment(tableNameSegment); + tableSegment.setOwner(new OwnerSegment(0, 0, new IdentifierValue("foo_db"))); + TablesContext tablesContext = new TablesContext(Collections.singleton(tableSegment)); + assertThat(tablesContext.getDatabaseName(), is(Optional.of("foo_db"))); + assertThat(tablesContext.getSchemaName(), is(Optional.of("foo_db"))); assertThat(tablesContext.getTableNames(), is(Collections.singleton("tbl"))); } @Test void assertFindTableNameWhenSingleTable() { - SimpleTableSegment tableSegment = createTableSegment("table_1", "tbl_1"); + SimpleTableSegment tableSegment = createTableSegment("table_1", "tbl_1", "sharding_db_1"); ColumnSegment columnSegment = createColumnSegment(null, "col"); - Map actual = new TablesContext(Collections.singletonList(tableSegment), databaseType, "foo_db").findTableNames(Collections.singletonList(columnSegment), mock()); + Map actual = new TablesContext(Collections.singletonList(tableSegment)).findTableNames(Collections.singletonList(columnSegment), mock()); assertFalse(actual.isEmpty()); assertThat(actual.get("col"), is("table_1")); } @Test void assertFindTableNameWhenColumnSegmentOwnerPresent() { - SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1"); - SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2"); + SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1", "sharding_db_1"); + SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2", "sharding_db_1"); ColumnSegment columnSegment = createColumnSegment("table_1", "col"); - Map actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db").findTableNames(Collections.singletonList(columnSegment), mock()); + Map actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2)).findTableNames(Collections.singletonList(columnSegment), mock()); assertFalse(actual.isEmpty()); assertThat(actual.get("table_1.col"), is("table_1")); } @Test void assertFindTableNameWhenColumnSegmentOwnerAbsent() { - SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1"); - SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2"); + SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1", "sharding_db_1"); + SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2", "sharding_db_1"); ColumnSegment columnSegment = createColumnSegment(null, "col"); - Map actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db").findTableNames(Collections.singletonList(columnSegment), mock()); + Map actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2)).findTableNames(Collections.singletonList(columnSegment), mock()); assertTrue(actual.isEmpty()); } @Test void assertFindTableNameWhenColumnSegmentOwnerAbsentAndSchemaMetaDataContainsColumn() { - SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1"); - SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2"); + SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1", "sharding_db_1"); + SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2", "sharding_db_1"); ShardingSphereSchema schema = mock(ShardingSphereSchema.class); when(schema.containsTable("table_1")).thenReturn(true); ShardingSphereTable table = mock(ShardingSphereTable.class); when(table.containsColumn("col")).thenReturn(true); when(schema.getTable("table_1")).thenReturn(table); ColumnSegment columnSegment = createColumnSegment(null, "col"); - Map actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db").findTableNames(Collections.singletonList(columnSegment), schema); + Map actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2)).findTableNames(Collections.singletonList(columnSegment), schema); assertThat(actual.get("col"), is("table_1")); } @Test void assertFindTableNameWhenColumnSegmentOwnerAbsentAndSchemaMetaDataContainsColumnInUpperCase() { - SimpleTableSegment tableSegment1 = createTableSegment("TABLE_1", "TBL_1"); - SimpleTableSegment tableSegment2 = createTableSegment("TABLE_2", "TBL_2"); + SimpleTableSegment tableSegment1 = createTableSegment("TABLE_1", "TBL_1", "sharding_db_1"); + SimpleTableSegment tableSegment2 = createTableSegment("TABLE_2", "TBL_2", "sharding_db_1"); ShardingSphereTable table = new ShardingSphereTable("TABLE_1", Collections.singletonList(new ShardingSphereColumn("COL", 0, false, false, true, true, false, false)), Collections.emptyList(), Collections.emptyList()); ShardingSphereSchema schema = new ShardingSphereSchema("foo_db", Collections.singleton(table), Collections.emptyList()); ColumnSegment columnSegment = createColumnSegment(null, "COL"); - Map actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db").findTableNames(Collections.singletonList(columnSegment), schema); + Map actual = new TablesContext(Arrays.asList(tableSegment1, tableSegment2)).findTableNames(Collections.singletonList(columnSegment), schema); assertFalse(actual.isEmpty()); assertThat(actual.get("col"), is("TABLE_1")); } - private SimpleTableSegment createTableSegment(final String tableName, final String alias) { - SimpleTableSegment result = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue(tableName))); + private SimpleTableSegment createTableSegment(final String tableName, final String alias, final String databaseName) { + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue(tableName)); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue(databaseName), new IdentifierValue(databaseName))); + SimpleTableSegment result = new SimpleTableSegment(tableNameSegment); AliasSegment aliasSegment = new AliasSegment(0, 0, new IdentifierValue(alias)); result.setAlias(aliasSegment); return result; @@ -148,51 +149,51 @@ private ColumnSegment createColumnSegment(final String owner, final String name) @Test void assertGetSchemaNameWithSameSchemaAndSameTable() { - SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1"); + SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1", "sharding_db_1"); tableSegment1.setOwner(new OwnerSegment(0, 0, new IdentifierValue("sharding_db_1"))); - SimpleTableSegment tableSegment2 = createTableSegment("table_1", "tbl_1"); + SimpleTableSegment tableSegment2 = createTableSegment("table_1", "tbl_1", "sharding_db_1"); tableSegment2.setOwner(new OwnerSegment(0, 0, new IdentifierValue("sharding_db_1"))); - TablesContext tablesContext = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db"); + TablesContext tablesContext = new TablesContext(Arrays.asList(tableSegment1, tableSegment2)); assertTrue(tablesContext.getDatabaseName().isPresent()); assertThat(tablesContext.getDatabaseName().get(), is("sharding_db_1")); } @Test void assertGetSchemaNameWithSameSchemaAndDifferentTable() { - SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1"); + SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1", "sharding_db_1"); tableSegment1.setOwner(new OwnerSegment(0, 0, new IdentifierValue("sharding_db_1"))); - SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2"); + SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2", "sharding_db_1"); tableSegment2.setOwner(new OwnerSegment(0, 0, new IdentifierValue("sharding_db_1"))); - TablesContext tablesContext = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db"); + TablesContext tablesContext = new TablesContext(Arrays.asList(tableSegment1, tableSegment2)); assertTrue(tablesContext.getDatabaseName().isPresent()); assertThat(tablesContext.getDatabaseName().get(), is("sharding_db_1")); } @Test void assertGetSchemaNameWithDifferentSchemaAndSameTable() { - SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1"); + SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1", "sharding_db_1"); tableSegment1.setOwner(new OwnerSegment(0, 0, new IdentifierValue("sharding_db_1"))); - SimpleTableSegment tableSegment2 = createTableSegment("table_1", "tbl_1"); + SimpleTableSegment tableSegment2 = createTableSegment("table_1", "tbl_1", "sharding_db_2"); tableSegment2.setOwner(new OwnerSegment(0, 0, new IdentifierValue("sharding_db_2"))); - assertThrows(IllegalStateException.class, () -> new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db").getDatabaseName()); + assertThrows(IllegalStateException.class, () -> new TablesContext(Arrays.asList(tableSegment1, tableSegment2)).getDatabaseName()); } @Test void assertGetSchemaNameWithDifferentSchemaAndDifferentTable() { - SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1"); + SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1", "sharding_db_1"); tableSegment1.setOwner(new OwnerSegment(0, 0, new IdentifierValue("sharding_db_1"))); - SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2"); + SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2", "sharding_db_2"); tableSegment2.setOwner(new OwnerSegment(0, 0, new IdentifierValue("sharding_db_2"))); - assertThrows(IllegalStateException.class, () -> new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db").getDatabaseName()); + assertThrows(IllegalStateException.class, () -> new TablesContext(Arrays.asList(tableSegment1, tableSegment2)).getDatabaseName()); } @Test void assertGetSchemaName() { - SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1"); + SimpleTableSegment tableSegment1 = createTableSegment("table_1", "tbl_1", "sharding_db_1"); tableSegment1.setOwner(new OwnerSegment(0, 0, new IdentifierValue("sharding_db_1"))); - SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2"); + SimpleTableSegment tableSegment2 = createTableSegment("table_2", "tbl_2", "sharding_db_1"); tableSegment2.setOwner(new OwnerSegment(0, 0, new IdentifierValue("sharding_db_1"))); - TablesContext tablesContext = new TablesContext(Arrays.asList(tableSegment1, tableSegment2), databaseType, "foo_db"); + TablesContext tablesContext = new TablesContext(Arrays.asList(tableSegment1, tableSegment2)); assertTrue(tablesContext.getSchemaName().isPresent()); assertThat(tablesContext.getSchemaName().get(), is("sharding_db_1")); } diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/AnalyzeTableStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/AnalyzeTableStatementContextTest.java index b7a3b7c303273..c1df0eb15adc1 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/AnalyzeTableStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/AnalyzeTableStatementContextTest.java @@ -18,6 +18,7 @@ package org.apache.shardingsphere.infra.binder.context.statement.dal; import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext; +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; @@ -36,7 +37,7 @@ class AnalyzeTableStatementContextTest { @Test - void assertMysqlNewInstance() { + void assertMySQLNewInstance() { assertNewInstance(new MySQLAnalyzeTableStatement()); } @@ -46,10 +47,14 @@ void assertPostgreSQLNewInstance() { } private void assertNewInstance(final AnalyzeTableStatement analyzeTableStatement) { - SimpleTableSegment table1 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_1"))); - SimpleTableSegment table2 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_2"))); + TableNameSegment tableNameSegment1 = new TableNameSegment(0, 0, new IdentifierValue("tbl_1")); + tableNameSegment1.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + TableNameSegment tableNameSegment2 = new TableNameSegment(0, 0, new IdentifierValue("tbl_2")); + tableNameSegment2.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + SimpleTableSegment table1 = new SimpleTableSegment(tableNameSegment1); + SimpleTableSegment table2 = new SimpleTableSegment(tableNameSegment2); analyzeTableStatement.getTables().addAll(Arrays.asList(table1, table2)); - AnalyzeTableStatementContext actual = new AnalyzeTableStatementContext(analyzeTableStatement, "foo_db"); + AnalyzeTableStatementContext actual = new AnalyzeTableStatementContext(analyzeTableStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(analyzeTableStatement)); assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), is(Arrays.asList("tbl_1", "tbl_2"))); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ExplainStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ExplainStatementContextTest.java index fda4d10df6e39..76b7dc2f3096b 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ExplainStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ExplainStatementContextTest.java @@ -48,7 +48,7 @@ void assertPostgreSQLNewInstance() { private void assertNewInstance(final ExplainStatement explainStatement) { SQLStatement statement = mock(SQLStatement.class); when(explainStatement.getSqlStatement()).thenReturn(Optional.of(statement)); - ExplainStatementContext actual = new ExplainStatementContext(explainStatement, "foo_db"); + ExplainStatementContext actual = new ExplainStatementContext(explainStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(explainStatement)); assertThat(actual.getSqlStatement().getSqlStatement().orElse(null), is(statement)); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/OptimizeTableStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/OptimizeTableStatementContextTest.java index 8fb44f8d550c9..3e6576d9b27e6 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/OptimizeTableStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/OptimizeTableStatementContextTest.java @@ -18,6 +18,7 @@ package org.apache.shardingsphere.infra.binder.context.statement.dal; import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext; +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.value.identifier.IdentifierValue; @@ -36,8 +37,10 @@ class OptimizeTableStatementContextTest { @Test void assertNewInstance() { MySQLOptimizeTableStatement sqlStatement = new MySQLOptimizeTableStatement(); - sqlStatement.getTables().add(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_1")))); - OptimizeTableStatementContext actual = new OptimizeTableStatementContext(sqlStatement, "foo_db"); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("tbl_1")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + sqlStatement.getTables().add(new SimpleTableSegment(tableNameSegment)); + OptimizeTableStatementContext actual = new OptimizeTableStatementContext(sqlStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(sqlStatement)); assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowColumnsStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowColumnsStatementContextTest.java index 35bbd289fdc55..5fb7bc6768e81 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowColumnsStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowColumnsStatementContextTest.java @@ -20,6 +20,7 @@ import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext; import org.apache.shardingsphere.sql.parser.statement.core.segment.dal.FromDatabaseSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.DatabaseSegment; +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.value.identifier.IdentifierValue; @@ -38,10 +39,12 @@ class ShowColumnsStatementContextTest { @Test void assertNewInstance() { MySQLShowColumnsStatement sqlStatement = new MySQLShowColumnsStatement(); - sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("foo_tbl")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("foo_tbl")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + sqlStatement.setTable(new SimpleTableSegment(tableNameSegment)); FromDatabaseSegment fromDatabase = new FromDatabaseSegment(0, 0, new DatabaseSegment(0, 0, new IdentifierValue("foo_db"))); sqlStatement.setFromDatabase(fromDatabase); - ShowColumnsStatementContext actual = new ShowColumnsStatementContext(sqlStatement, "foo_db"); + ShowColumnsStatementContext actual = new ShowColumnsStatementContext(sqlStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(sqlStatement)); assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowCreateTableStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowCreateTableStatementContextTest.java index 8495b3f077878..9eb20175d8928 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowCreateTableStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowCreateTableStatementContextTest.java @@ -18,6 +18,7 @@ package org.apache.shardingsphere.infra.binder.context.statement.dal; import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext; +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.value.identifier.IdentifierValue; @@ -36,8 +37,10 @@ class ShowCreateTableStatementContextTest { @Test void assertNewInstance() { MySQLShowCreateTableStatement sqlStatement = new MySQLShowCreateTableStatement(); - sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("foo_tbl")))); - ShowCreateTableStatementContext actual = new ShowCreateTableStatementContext(sqlStatement, "foo_db"); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("foo_tbl")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + sqlStatement.setTable(new SimpleTableSegment(tableNameSegment)); + ShowCreateTableStatementContext actual = new ShowCreateTableStatementContext(sqlStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(sqlStatement)); assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowIndexStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowIndexStatementContextTest.java index 602ebb2c4e9e1..0893b896fde29 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowIndexStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dal/ShowIndexStatementContextTest.java @@ -18,6 +18,7 @@ package org.apache.shardingsphere.infra.binder.context.statement.dal; import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext; +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.value.identifier.IdentifierValue; @@ -36,8 +37,10 @@ class ShowIndexStatementContextTest { @Test void assertNewInstance() { MySQLShowIndexStatement sqlStatement = new MySQLShowIndexStatement(); - sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("foo_tbl")))); - ShowIndexStatementContext actual = new ShowIndexStatementContext(sqlStatement, "foo_db"); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("foo_tbl")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + sqlStatement.setTable(new SimpleTableSegment(tableNameSegment)); + ShowIndexStatementContext actual = new ShowIndexStatementContext(sqlStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(sqlStatement)); assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/DenyUserStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/DenyUserStatementContextTest.java index ad7f4fabda468..bbd448dc87f19 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/DenyUserStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/DenyUserStatementContextTest.java @@ -18,6 +18,7 @@ package org.apache.shardingsphere.infra.binder.context.statement.dcl; import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext; +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.value.identifier.IdentifierValue; @@ -36,9 +37,11 @@ class DenyUserStatementContextTest { @Test void assertNewInstance() { SQLServerDenyUserStatement sqlStatement = new SQLServerDenyUserStatement(); - SimpleTableSegment table = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("foo_tbl"))); + 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); sqlStatement.setTable(table); - DenyUserStatementContext actual = new DenyUserStatementContext(sqlStatement, "foo_db"); + DenyUserStatementContext actual = new DenyUserStatementContext(sqlStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(sqlStatement)); assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/GrantStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/GrantStatementContextTest.java index 08f0b286caea2..5d52f83f74967 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/GrantStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/GrantStatementContextTest.java @@ -18,6 +18,7 @@ package org.apache.shardingsphere.infra.binder.context.statement.dcl; import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext; +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.GrantStatement; @@ -64,10 +65,14 @@ void assertSQL92NewInstance() { } private void assertNewInstance(final GrantStatement grantStatement) { - SimpleTableSegment table1 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("foo_tbl"))); - SimpleTableSegment table2 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("bar_tbl"))); + TableNameSegment tableNameSegment1 = new TableNameSegment(0, 0, new IdentifierValue("foo_tbl")); + tableNameSegment1.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + TableNameSegment tableNameSegment2 = new TableNameSegment(0, 0, new IdentifierValue("bar_tbl")); + tableNameSegment2.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + SimpleTableSegment table1 = new SimpleTableSegment(tableNameSegment1); + SimpleTableSegment table2 = new SimpleTableSegment(tableNameSegment2); grantStatement.getTables().addAll(Arrays.asList(table1, table2)); - GrantStatementContext actual = new GrantStatementContext(grantStatement, "foo_db"); + GrantStatementContext actual = new GrantStatementContext(grantStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(grantStatement)); assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/RevokeStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/RevokeStatementContextTest.java index af3f91c127f48..b8a18d75a37dd 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/RevokeStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dcl/RevokeStatementContextTest.java @@ -18,6 +18,7 @@ package org.apache.shardingsphere.infra.binder.context.statement.dcl; import org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext; +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; @@ -64,10 +65,14 @@ void assertSQL92NewInstance() { } private void assertNewInstance(final RevokeStatement revokeStatement) { - SimpleTableSegment table1 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("foo_tbl"))); - SimpleTableSegment table2 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("bar_tbl"))); + TableNameSegment tableNameSegment1 = new TableNameSegment(0, 0, new IdentifierValue("foo_tbl")); + tableNameSegment1.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + TableNameSegment tableNameSegment2 = new TableNameSegment(0, 0, new IdentifierValue("bar_tbl")); + tableNameSegment2.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + SimpleTableSegment table1 = new SimpleTableSegment(tableNameSegment1); + SimpleTableSegment table2 = new SimpleTableSegment(tableNameSegment2); revokeStatement.getTables().addAll(Arrays.asList(table1, table2)); - RevokeStatementContext actual = new RevokeStatementContext(revokeStatement, "foo_db"); + RevokeStatementContext actual = new RevokeStatementContext(revokeStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(revokeStatement)); assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterIndexStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterIndexStatementContextTest.java index 3ffcca418e53f..dddcf50d788ab 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterIndexStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterIndexStatementContextTest.java @@ -57,7 +57,7 @@ void assertSQLServerNewInstance() { private void assertNewInstance(final AlterIndexStatement alterIndexStatement) { IndexSegment indexSegment = new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("index_1"))); when(alterIndexStatement.getIndex()).thenReturn(Optional.of(indexSegment)); - AlterIndexStatementContext actual = new AlterIndexStatementContext(alterIndexStatement, "foo_db"); + AlterIndexStatementContext actual = new AlterIndexStatementContext(alterIndexStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(alterIndexStatement)); assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), is(Collections.emptyList())); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterTableStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterTableStatementContextTest.java index 8567b81cd23f1..945ef575558f4 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterTableStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterTableStatementContextTest.java @@ -29,6 +29,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.DropIndexDefinitionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexNameSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexSegment; +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.AlterTableStatement; @@ -80,8 +81,12 @@ void assertSQL92NewInstance() { } private void assertNewInstance(final AlterTableStatement alterTableStatement) { - SimpleTableSegment table = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_1"))); - SimpleTableSegment renameTable = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("rename_tbl_1"))); + TableNameSegment tableNameSegment1 = new TableNameSegment(0, 0, new IdentifierValue("tbl_1")); + tableNameSegment1.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + TableNameSegment tableNameSegment2 = new TableNameSegment(0, 0, new IdentifierValue("rename_tbl_1")); + tableNameSegment2.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + SimpleTableSegment table = new SimpleTableSegment(tableNameSegment1); + SimpleTableSegment renameTable = new SimpleTableSegment(tableNameSegment2); alterTableStatement.setTable(table); alterTableStatement.setRenameTable(renameTable); Collection referencedTables = Collections.singletonList(table); @@ -110,7 +115,7 @@ private void assertNewInstance(final AlterTableStatement alterTableStatement) { DropIndexDefinitionSegment dropIndexDefinitionSegment = mock(DropIndexDefinitionSegment.class); when(dropIndexDefinitionSegment.getIndexSegment()).thenReturn(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("drop_index")))); alterTableStatement.getDropIndexDefinitions().add(dropIndexDefinitionSegment); - AlterTableStatementContext actual = new AlterTableStatementContext(alterTableStatement, "foo_db"); + AlterTableStatementContext actual = new AlterTableStatementContext(alterTableStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(alterTableStatement)); assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterViewStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterViewStatementContextTest.java index 1da87742c075f..0feea9fbeddb0 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterViewStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/AlterViewStatementContextTest.java @@ -18,6 +18,7 @@ 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.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.AlterViewStatement; @@ -43,7 +44,9 @@ class AlterViewStatementContextTest { @BeforeEach void setUp() { - view = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("view"))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("view")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + view = new SimpleTableSegment(tableNameSegment); } @Test @@ -60,12 +63,14 @@ void assertMySQLNewInstance() { void assertPostgreSQLNewInstance() { PostgreSQLAlterViewStatement alterViewStatement = new PostgreSQLAlterViewStatement(); alterViewStatement.setView(view); - alterViewStatement.setRenameView(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("view")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("view")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + alterViewStatement.setRenameView(new SimpleTableSegment(tableNameSegment)); assertNewInstance(alterViewStatement); } private void assertNewInstance(final AlterViewStatement alterViewStatement) { - AlterViewStatementContext actual = new AlterViewStatementContext(alterViewStatement, "foo_db"); + AlterViewStatementContext actual = new AlterViewStatementContext(alterViewStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(alterViewStatement)); assertThat(actual.getTablesContext().getSimpleTables().size(), is(2)); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateFunctionStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateFunctionStatementContextTest.java index 3a35101c12361..594602813481e 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateFunctionStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateFunctionStatementContextTest.java @@ -47,7 +47,7 @@ void assertSQLServerNewInstance() { } private void assertNewInstance(final CreateFunctionStatement createDatabaseStatement) { - CreateFunctionStatementContext actual = new CreateFunctionStatementContext(createDatabaseStatement, "foo_db"); + CreateFunctionStatementContext actual = new CreateFunctionStatementContext(createDatabaseStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(createDatabaseStatement)); } diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateIndexStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateIndexStatementContextTest.java index 93af84f0b560c..e162431b56627 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateIndexStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateIndexStatementContextTest.java @@ -61,14 +61,14 @@ void assertSQLServerSQLNewInstance() { } private void assertNewInstance(final CreateIndexStatement createIndexStatement) { - CreateIndexStatementContext actual = new CreateIndexStatementContext(createIndexStatement, "foo_db"); + CreateIndexStatementContext actual = new CreateIndexStatementContext(createIndexStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(createIndexStatement)); assertTrue(actual.isGeneratedIndex()); assertThat(actual.getTablesContext().getSimpleTables(), is(Collections.emptyList())); assertThat(actual.getIndexes(), is(Collections.emptyList())); when(createIndexStatement.getIndex()).thenReturn(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new IdentifierValue("index_2")))); - CreateIndexStatementContext actual2 = new CreateIndexStatementContext(createIndexStatement, "foo_db"); + CreateIndexStatementContext actual2 = new CreateIndexStatementContext(createIndexStatement); assertThat(actual2.getIndexes().stream().map(each -> each.getIndexName().getIdentifier().getValue()).collect(Collectors.toList()), is(Collections.singletonList("index_2"))); } } diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateProcedureStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateProcedureStatementContextTest.java index 3c57c0e7ad7c1..15af5fd7d38df 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateProcedureStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateProcedureStatementContextTest.java @@ -41,7 +41,7 @@ void assertPostgreSQLNewInstance() { } private void assertNewInstance(final CreateProcedureStatement createProcedureStatement) { - CreateProcedureStatementContext actual = new CreateProcedureStatementContext(createProcedureStatement, "foo_db"); + CreateProcedureStatementContext actual = new CreateProcedureStatementContext(createProcedureStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(createProcedureStatement)); } diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateTableStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateTableStatementContextTest.java index b6acd3c670334..9f256f9c9335e 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateTableStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateTableStatementContextTest.java @@ -73,7 +73,7 @@ void assertSQL92NewInstance() { } private void assertNewInstance(final CreateTableStatement createTableStatement) { - CreateTableStatementContext actual = new CreateTableStatementContext(createTableStatement, "foo_db"); + CreateTableStatementContext actual = new CreateTableStatementContext(createTableStatement); SimpleTableSegment table = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_1"))); when(createTableStatement.getTable()).thenReturn(table); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateViewStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateViewStatementContextTest.java index cd584254ea5ae..5a59b58cc00b9 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateViewStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/CreateViewStatementContextTest.java @@ -18,6 +18,7 @@ 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.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.CreateViewStatement; @@ -45,10 +46,12 @@ void assertPostgreSQLNewInstance() { } private void assertNewInstance(final CreateViewStatement createViewStatement) { - SimpleTableSegment view = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("view"))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("view")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + SimpleTableSegment view = new SimpleTableSegment(tableNameSegment); createViewStatement.setView(view); createViewStatement.setSelect(mock(SelectStatement.class)); - CreateViewStatementContext actual = new CreateViewStatementContext(createViewStatement, "foo_db"); + CreateViewStatementContext actual = new CreateViewStatementContext(createViewStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(createViewStatement)); } diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropIndexStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropIndexStatementContextTest.java index 59459297a060f..30f88aa9eaeae 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropIndexStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropIndexStatementContextTest.java @@ -69,7 +69,7 @@ private void assertNewInstance(final DropIndexStatement dropIndexStatement) { indexes.add(index1); indexes.add(index2); when(dropIndexStatement.getIndexes()).thenReturn(indexes); - DropIndexStatementContext actual = new DropIndexStatementContext(dropIndexStatement, "foo_db"); + DropIndexStatementContext actual = new DropIndexStatementContext(dropIndexStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(dropIndexStatement)); assertThat(actual.getTablesContext().getSimpleTables(), is(Collections.emptyList())); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropTableStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropTableStatementContextTest.java index 0fe7f4e2f0193..54104522fae81 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropTableStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropTableStatementContextTest.java @@ -65,7 +65,7 @@ void assertSQL92NewInstance() { } private void assertNewInstance(final DropTableStatement dropTableStatement) { - DropTableStatementContext actual = new DropTableStatementContext(dropTableStatement, "foo_db"); + DropTableStatementContext actual = new DropTableStatementContext(dropTableStatement); SimpleTableSegment table1 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_1"))); SimpleTableSegment table2 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_2"))); when(dropTableStatement.getTables()).thenReturn(Arrays.asList(table1, table2)); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropViewStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropViewStatementContextTest.java index 068deaee09768..cdc1720e1beb6 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropViewStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/DropViewStatementContextTest.java @@ -18,6 +18,7 @@ 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.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.DropViewStatement; @@ -45,10 +46,14 @@ void assertPostgreSQLNewInstance() { } private void assertNewInstance(final DropViewStatement dropViewStatement) { - SimpleTableSegment table1 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_1"))); - SimpleTableSegment table2 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_2"))); + TableNameSegment tableNameSegment1 = new TableNameSegment(0, 0, new IdentifierValue("tbl_1")); + tableNameSegment1.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + TableNameSegment tableNameSegment2 = new TableNameSegment(0, 0, new IdentifierValue("tbl_2")); + tableNameSegment2.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + SimpleTableSegment table1 = new SimpleTableSegment(tableNameSegment1); + SimpleTableSegment table2 = new SimpleTableSegment(tableNameSegment2); dropViewStatement.getViews().addAll(Arrays.asList(table1, table2)); - DropViewStatementContext actual = new DropViewStatementContext(dropViewStatement, "foo_db"); + DropViewStatementContext actual = new DropViewStatementContext(dropViewStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(dropViewStatement)); } diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/PrepareStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/PrepareStatementContextTest.java index 5f85b0745ebdf..4b32d861ac89f 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/PrepareStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/PrepareStatementContextTest.java @@ -21,6 +21,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.assignment.ColumnAssignmentSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.assignment.SetAssignmentSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment; +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.dml.DeleteStatement; @@ -52,7 +53,9 @@ class PrepareStatementContextTest { @BeforeEach void setUp() { - table = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_1"))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("tbl_1")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + table = new SimpleTableSegment(tableNameSegment); column = new ColumnSegment(0, 0, new IdentifierValue("col_1")); } @@ -63,7 +66,7 @@ void assertNewInstance() { sqlStatement.setInsert(getInsert()); sqlStatement.setUpdate(getUpdate()); sqlStatement.setDelete(getDelete()); - PrepareStatementContext actual = new PrepareStatementContext(sqlStatement, "foo_db"); + PrepareStatementContext actual = new PrepareStatementContext(sqlStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(sqlStatement)); assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/TruncateStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/TruncateStatementContextTest.java index 6acd2a9bc561d..8574372855ef4 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/TruncateStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/ddl/TruncateStatementContextTest.java @@ -18,6 +18,7 @@ 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.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; @@ -58,10 +59,14 @@ void assertSQLServerNewInstance() { } private void assertNewInstance(final TruncateStatement truncateStatement) { - SimpleTableSegment table1 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_1"))); - SimpleTableSegment table2 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_2"))); + TableNameSegment tableNameSegment1 = new TableNameSegment(0, 0, new IdentifierValue("tbl_1")); + tableNameSegment1.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + TableNameSegment tableNameSegment2 = new TableNameSegment(0, 0, new IdentifierValue("tbl_2")); + tableNameSegment2.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + SimpleTableSegment table1 = new SimpleTableSegment(tableNameSegment1); + SimpleTableSegment table2 = new SimpleTableSegment(tableNameSegment2); truncateStatement.getTables().addAll(Arrays.asList(table1, table2)); - TruncateStatementContext actual = new TruncateStatementContext(truncateStatement, "foo_db"); + TruncateStatementContext actual = new TruncateStatementContext(truncateStatement); assertThat(actual, instanceOf(CommonSQLStatementContext.class)); assertThat(actual.getSqlStatement(), is(truncateStatement)); assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), is(Arrays.asList("tbl_1", "tbl_2"))); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/DeleteStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/DeleteStatementContextTest.java index c010c6ada9c5d..1b828ebf4e3a4 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/DeleteStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/DeleteStatementContextTest.java @@ -19,6 +19,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.ExpressionSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.JoinTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; @@ -77,14 +78,18 @@ void assertSQLServerNewInstance() { private void assertNewInstance(final DeleteStatement deleteStatement) { when(whereSegment.getExpr()).thenReturn(mock(ExpressionSegment.class)); - SimpleTableSegment table1 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_1"))); - SimpleTableSegment table2 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_2"))); + TableNameSegment tableNameSegment1 = new TableNameSegment(0, 0, new IdentifierValue("tbl_1")); + tableNameSegment1.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + TableNameSegment tableNameSegment2 = new TableNameSegment(0, 0, new IdentifierValue("tbl_2")); + tableNameSegment2.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + SimpleTableSegment table1 = new SimpleTableSegment(tableNameSegment1); + SimpleTableSegment table2 = new SimpleTableSegment(tableNameSegment2); JoinTableSegment tableSegment = new JoinTableSegment(); tableSegment.setLeft(table1); tableSegment.setRight(table2); deleteStatement.setWhere(whereSegment); deleteStatement.setTable(tableSegment); - DeleteStatementContext actual = new DeleteStatementContext(deleteStatement, "foo_db"); + DeleteStatementContext actual = new DeleteStatementContext(deleteStatement); assertThat(actual.getTablesContext().getTableNames(), is(new HashSet<>(Arrays.asList("tbl_1", "tbl_2")))); assertThat(actual.getWhereSegments(), is(Collections.singletonList(whereSegment))); assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), is(Arrays.asList("tbl_1", "tbl_2"))); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/InsertStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/InsertStatementContextTest.java index 0665b71acfe55..17da31d5c807d 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/InsertStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/InsertStatementContextTest.java @@ -32,6 +32,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.subquery.SubquerySegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.item.ProjectionsSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.OwnerSegment; +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.dml.InsertStatement; @@ -92,7 +93,9 @@ void assertSQLServerInsertStatementContextWithColumnNames() { } private void assertInsertStatementContextWithColumnNames(final InsertStatement insertStatement) { - SimpleTableSegment tableSegment = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl"))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("tbl")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + SimpleTableSegment tableSegment = new SimpleTableSegment(tableNameSegment); tableSegment.setOwner(new OwnerSegment(0, 0, new IdentifierValue("foo_db".toUpperCase()))); insertStatement.setTable(tableSegment); InsertColumnsSegment insertColumnsSegment = new InsertColumnsSegment(0, 0, Arrays.asList( @@ -125,7 +128,9 @@ private String getSchemaName(final InsertStatement insertStatement) { @Test void assertInsertStatementContextWithoutColumnNames() { InsertStatement insertStatement = new MySQLInsertStatement(); - insertStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("tbl")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + insertStatement.setTable(new SimpleTableSegment(tableNameSegment)); setUpInsertValues(insertStatement); InsertStatementContext actual = createInsertStatementContext(Arrays.asList(1, "Tom", 2, "Jerry"), insertStatement); actual.setUpParameters(Arrays.asList(1, "Tom", 2, "Jerry")); @@ -135,7 +140,9 @@ void assertInsertStatementContextWithoutColumnNames() { @Test void assertGetGroupedParametersWithoutOnDuplicateParameter() { InsertStatement insertStatement = new MySQLInsertStatement(); - insertStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("tbl")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + insertStatement.setTable(new SimpleTableSegment(tableNameSegment)); setUpInsertValues(insertStatement); InsertStatementContext actual = createInsertStatementContext(Arrays.asList(1, "Tom", 2, "Jerry"), insertStatement); actual.setUpParameters(Arrays.asList(1, "Tom", 2, "Jerry")); @@ -147,7 +154,9 @@ void assertGetGroupedParametersWithoutOnDuplicateParameter() { @Test void assertGetGroupedParametersWithOnDuplicateParameters() { MySQLInsertStatement insertStatement = new MySQLInsertStatement(); - insertStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("tbl")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + insertStatement.setTable(new SimpleTableSegment(tableNameSegment)); setUpInsertValues(insertStatement); setUpOnDuplicateValues(insertStatement); InsertStatementContext actual = createInsertStatementContext(Arrays.asList(1, "Tom", 2, "Jerry", "onDuplicateKeyUpdateColumnValue"), insertStatement); @@ -165,7 +174,9 @@ void assertInsertSelect() { selectStatement.setProjections(new ProjectionsSegment(0, 0)); SubquerySegment insertSelect = new SubquerySegment(0, 0, selectStatement, ""); insertStatement.setInsertSelect(insertSelect); - insertStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("tbl")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + insertStatement.setTable(new SimpleTableSegment(tableNameSegment)); InsertStatementContext actual = createInsertStatementContext(Collections.singletonList("param"), insertStatement); actual.setUpParameters(Collections.singletonList("param")); assertThat(actual.getInsertSelectContext().getParameterCount(), is(1)); @@ -246,7 +257,9 @@ void assertUseDefaultColumnsForSQLServer() { } private void assertNotContainsInsertColumns(final InsertStatement insertStatement) { - insertStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + insertStatement.setTable(new SimpleTableSegment(tableNameSegment)); InsertStatementContext insertStatementContext = createInsertStatementContext(Collections.emptyList(), insertStatement); assertFalse(insertStatementContext.containsInsertColumns()); } @@ -279,7 +292,9 @@ void assertNotUseDefaultColumnsWithColumnsForSQLServer() { private void assertContainsInsertColumns(final InsertStatement insertStatement) { InsertColumnsSegment insertColumnsSegment = new InsertColumnsSegment(0, 0, Collections.singletonList(new ColumnSegment(0, 0, new IdentifierValue("col")))); insertStatement.setInsertColumns(insertColumnsSegment); - insertStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + insertStatement.setTable(new SimpleTableSegment(tableNameSegment)); InsertStatementContext insertStatementContext = createInsertStatementContext(Collections.emptyList(), insertStatement); assertTrue(insertStatementContext.containsInsertColumns()); } @@ -288,7 +303,9 @@ private void assertContainsInsertColumns(final InsertStatement insertStatement) void assertContainsInsertColumnsWithSetAssignmentForMySQL() { MySQLInsertStatement insertStatement = new MySQLInsertStatement(); insertStatement.setSetAssignment(new SetAssignmentSegment(0, 0, Collections.emptyList())); - insertStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + insertStatement.setTable(new SimpleTableSegment(tableNameSegment)); InsertStatementContext insertStatementContext = createInsertStatementContext(Collections.emptyList(), insertStatement); assertTrue(insertStatementContext.containsInsertColumns()); } @@ -321,7 +338,9 @@ void assertGetValueListCountWithValuesForSQLServer() { private void assertGetValueListCountWithValues(final InsertStatement insertStatement) { insertStatement.getValues().add(new InsertValuesSegment(0, 0, Collections.singletonList(new LiteralExpressionSegment(0, 0, 1)))); insertStatement.getValues().add(new InsertValuesSegment(0, 0, Collections.singletonList(new LiteralExpressionSegment(0, 0, 2)))); - insertStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + insertStatement.setTable(new SimpleTableSegment(tableNameSegment)); InsertStatementContext insertStatementContext = createInsertStatementContext(Collections.emptyList(), insertStatement); assertThat(insertStatementContext.getValueListCount(), is(2)); } @@ -333,7 +352,9 @@ void assertGetValueListCountWithSetAssignmentForMySQL() { columns.add(new ColumnSegment(0, 0, new IdentifierValue("col"))); ColumnAssignmentSegment insertStatementAssignment = new ColumnAssignmentSegment(0, 0, columns, new LiteralExpressionSegment(0, 0, 1)); insertStatement.setSetAssignment(new SetAssignmentSegment(0, 0, Collections.singletonList(insertStatementAssignment))); - insertStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + insertStatement.setTable(new SimpleTableSegment(tableNameSegment)); InsertStatementContext insertStatementContext = createInsertStatementContext(Collections.emptyList(), insertStatement); assertThat(insertStatementContext.getValueListCount(), is(1)); } @@ -366,7 +387,9 @@ void assertGetInsertColumnNamesForInsertColumnsForSQLServer() { private void assertGetInsertColumnNamesForInsertColumns(final InsertStatement insertStatement) { InsertColumnsSegment insertColumnsSegment = new InsertColumnsSegment(0, 0, Collections.singletonList(new ColumnSegment(0, 0, new IdentifierValue("col")))); insertStatement.setInsertColumns(insertColumnsSegment); - insertStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + insertStatement.setTable(new SimpleTableSegment(tableNameSegment)); InsertStatementContext insertStatementContext = createInsertStatementContext(Collections.emptyList(), insertStatement); List columnNames = insertStatementContext.getInsertColumnNames(); assertThat(columnNames.size(), is(1)); @@ -380,7 +403,9 @@ void assertGetInsertColumnNamesForSetAssignmentForMySQL() { columns.add(new ColumnSegment(0, 0, new IdentifierValue("col"))); ColumnAssignmentSegment insertStatementAssignment = new ColumnAssignmentSegment(0, 0, columns, new LiteralExpressionSegment(0, 0, 1)); insertStatement.setSetAssignment(new SetAssignmentSegment(0, 0, Collections.singletonList(insertStatementAssignment))); - insertStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + insertStatement.setTable(new SimpleTableSegment(tableNameSegment)); InsertStatementContext insertStatementContext = createInsertStatementContext(Collections.emptyList(), insertStatement); List columnNames = insertStatementContext.getInsertColumnNames(); assertThat(columnNames.size(), is(1)); diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/SelectStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/SelectStatementContextTest.java index 54a25eb915ab6..2f4ebfcd27ab3 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/SelectStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/SelectStatementContextTest.java @@ -48,6 +48,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.AliasSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.OwnerSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.JoinTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SubqueryTableSegment; @@ -108,10 +109,12 @@ void assertSetIndexForItemsByIndexOrderByForSQLServer() { } private void assertSetIndexForItemsByIndexOrderBy(final SelectStatement selectStatement) { - ShardingSphereDatabase database = mockDatabase(); selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(createOrderByItemSegment(INDEX_ORDER_BY)))); selectStatement.setProjections(createProjectionsSegment()); - selectStatement.setFrom(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("table")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("table")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + selectStatement.setFrom(new SimpleTableSegment(tableNameSegment)); + ShardingSphereDatabase database = mockDatabase(); SelectStatementContext selectStatementContext = new SelectStatementContext(createShardingSphereMetaData(database), Collections.emptyList(), selectStatement, "foo_db", Collections.emptyList()); selectStatementContext.setIndexes(Collections.emptyMap()); @@ -155,7 +158,9 @@ void assertSetIndexForItemsByColumnOrderByWithOwnerForSQLServer() { private void assertSetIndexForItemsByColumnOrderByWithOwner(final SelectStatement selectStatement) { selectStatement.setOrderBy(new OrderBySegment(0, 0, Collections.singletonList(createOrderByItemSegment(COLUMN_ORDER_BY_WITH_OWNER)))); selectStatement.setProjections(createProjectionsSegment()); - SimpleTableSegment tableSegment = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("table"))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("table")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + SimpleTableSegment tableSegment = new SimpleTableSegment(tableNameSegment); tableSegment.setOwner(new OwnerSegment(0, 0, new IdentifierValue("foo_db".toUpperCase()))); selectStatement.setFrom(tableSegment); ShardingSphereDatabase database = mockDatabase(); @@ -591,7 +596,9 @@ private OrderByItemSegment createOrderByItemSegment(final String type) { return new IndexOrderByItemSegment(0, 0, 4, OrderDirection.ASC, NullsOrderType.FIRST); case COLUMN_ORDER_BY_WITH_OWNER: ColumnSegment columnSegment = new ColumnSegment(0, 0, new IdentifierValue("name")); - columnSegment.setOwner(new OwnerSegment(0, 0, new IdentifierValue("table"))); + OwnerSegment owner = new OwnerSegment(0, 0, new IdentifierValue("table")); + owner.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + columnSegment.setOwner(owner); return new ColumnOrderByItemSegment(columnSegment, OrderDirection.ASC, NullsOrderType.FIRST); case COLUMN_ORDER_BY_WITH_ALIAS: return new ColumnOrderByItemSegment(new ColumnSegment(0, 0, new IdentifierValue("n")), OrderDirection.ASC, NullsOrderType.FIRST); @@ -601,16 +608,17 @@ private OrderByItemSegment createOrderByItemSegment(final String type) { } private ProjectionsSegment createProjectionsSegment() { - ProjectionsSegment projectionsSegment = new ProjectionsSegment(0, 0); - projectionsSegment.setDistinctRow(true); - projectionsSegment.getProjections().addAll(Arrays.asList(getColumnProjectionSegmentWithoutOwner(), - getColumnProjectionSegmentWithoutOwner(true), getColumnProjectionSegmentWithoutOwner(false))); - return projectionsSegment; + ProjectionsSegment result = new ProjectionsSegment(0, 0); + result.setDistinctRow(true); + result.getProjections().addAll(Arrays.asList(getColumnProjectionSegmentWithoutOwner(), getColumnProjectionSegmentWithoutOwner(true), getColumnProjectionSegmentWithoutOwner(false))); + return result; } private ProjectionSegment getColumnProjectionSegmentWithoutOwner() { ColumnSegment columnSegment = new ColumnSegment(0, 0, new IdentifierValue("name")); - columnSegment.setOwner(new OwnerSegment(0, 0, new IdentifierValue("table"))); + OwnerSegment owner = new OwnerSegment(0, 0, new IdentifierValue("table")); + owner.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + columnSegment.setOwner(owner); return new ColumnProjectionSegment(columnSegment); } @@ -627,7 +635,9 @@ void assertIsContainsEnhancedTable() { projectionsSegment.getProjections().add(new ColumnProjectionSegment(new ColumnSegment(0, 0, new IdentifierValue("order_id")))); SelectStatement selectStatement = new MySQLSelectStatement(); selectStatement.setProjections(projectionsSegment); - selectStatement.setFrom(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("t_order")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + selectStatement.setFrom(new SimpleTableSegment(tableNameSegment)); ShardingSphereMetaData metaData = new ShardingSphereMetaData( Collections.singleton(mockDatabase()), mock(ResourceMetaData.class), mock(RuleMetaData.class), mock(ConfigurationProperties.class)); SelectStatementContext actual = new SelectStatementContext(metaData, Collections.emptyList(), selectStatement, "foo_db", Collections.emptyList()); @@ -650,7 +660,9 @@ private SelectStatement createSubSelectStatement() { projectionsSegment.getProjections().add(new ColumnProjectionSegment(new ColumnSegment(0, 0, new IdentifierValue("order_id")))); SelectStatement result = new MySQLSelectStatement(); result.setProjections(projectionsSegment); - result.setFrom(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("t_order")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + result.setFrom(new SimpleTableSegment(tableNameSegment)); return result; } } diff --git a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/UpdateStatementContextTest.java b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/UpdateStatementContextTest.java index e9b80e88fdbf6..4420b6749c6c1 100644 --- a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/UpdateStatementContextTest.java +++ b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/statement/dml/UpdateStatementContextTest.java @@ -22,6 +22,7 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.expr.BinaryOperationExpression; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.predicate.WhereSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.OwnerSegment; +import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.JoinTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment; @@ -54,11 +55,17 @@ class UpdateStatementContextTest { @Test void assertNewInstance() { - when(columnSegment.getOwner()).thenReturn(Optional.of(new OwnerSegment(0, 0, new IdentifierValue("tbl_2")))); + OwnerSegment ownerSegment = new OwnerSegment(0, 0, new IdentifierValue("tbl_2")); + ownerSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + when(columnSegment.getOwner()).thenReturn(Optional.of(ownerSegment)); BinaryOperationExpression expression = new BinaryOperationExpression(0, 0, columnSegment, null, null, null); when(whereSegment.getExpr()).thenReturn(expression); - SimpleTableSegment table1 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_1"))); - SimpleTableSegment table2 = new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("tbl_2"))); + TableNameSegment tableNameSegment1 = new TableNameSegment(0, 0, new IdentifierValue("tbl_1")); + tableNameSegment1.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + TableNameSegment tableNameSegment2 = new TableNameSegment(0, 0, new IdentifierValue("tbl_2")); + tableNameSegment2.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + SimpleTableSegment table1 = new SimpleTableSegment(tableNameSegment1); + SimpleTableSegment table2 = new SimpleTableSegment(tableNameSegment2); JoinTableSegment joinTableSegment = new JoinTableSegment(); joinTableSegment.setLeft(table1); joinTableSegment.setRight(table2); @@ -66,7 +73,7 @@ void assertNewInstance() { updateStatement.setWhere(whereSegment); updateStatement.setTable(joinTableSegment); updateStatement.setSetAssignment(new SetAssignmentSegment(0, 0, Collections.emptyList())); - UpdateStatementContext actual = new UpdateStatementContext(updateStatement, "foo_db"); + UpdateStatementContext actual = new UpdateStatementContext(updateStatement); assertThat(actual.getTablesContext().getTableNames(), is(new HashSet<>(Arrays.asList("tbl_1", "tbl_2")))); assertThat(actual.getWhereSegments(), is(Collections.singletonList(whereSegment))); assertThat(actual.getTablesContext().getSimpleTables().stream().map(each -> each.getTableName().getIdentifier().getValue()).collect(Collectors.toList()), diff --git a/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/process/ProcessEngineTest.java b/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/process/ProcessEngineTest.java index 149449f5e1a7d..88450ae0fbd8e 100644 --- a/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/process/ProcessEngineTest.java +++ b/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/process/ProcessEngineTest.java @@ -26,6 +26,7 @@ import org.apache.shardingsphere.infra.session.connection.ConnectionContext; import org.apache.shardingsphere.infra.session.query.QueryContext; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.assignment.SetAssignmentSegment; +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.value.identifier.IdentifierValue; @@ -65,7 +66,7 @@ void assertExecuteSQL() { ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); ExecutionGroupContext executionGroupContext = mockExecutionGroupContext(); new ProcessEngine().executeSQL(executionGroupContext, - new QueryContext(new UpdateStatementContext(getSQLStatement(), "foo_db"), null, null, new HintValueContext(), connectionContext, metaData)); + new QueryContext(new UpdateStatementContext(getSQLStatement()), null, null, new HintValueContext(), connectionContext, metaData)); verify(processRegistry).add(any()); } @@ -80,7 +81,9 @@ private ExecutionGroupContext mockExecutionGroupCont private MySQLUpdateStatement getSQLStatement() { MySQLUpdateStatement result = new MySQLUpdateStatement(); - result.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("foo_tbl")))); + TableNameSegment tableNameSegment = new TableNameSegment(0, 0, new IdentifierValue("foo_tbl")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + result.setTable(new SimpleTableSegment(tableNameSegment)); result.setSetAssignment(new SetAssignmentSegment(0, 0, Collections.emptyList())); return result; } diff --git a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/checker/sql/SingleDropTableSupportedCheckerTest.java b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/checker/sql/SingleDropTableSupportedCheckerTest.java index a66b824cb2f8c..e4206b50d6b98 100644 --- a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/checker/sql/SingleDropTableSupportedCheckerTest.java +++ b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/checker/sql/SingleDropTableSupportedCheckerTest.java @@ -67,6 +67,6 @@ private DropTableStatementContext createSQLStatementContext(final boolean contai PostgreSQLDropTableStatement dropSchemaStatement = mock(PostgreSQLDropTableStatement.class, RETURNS_DEEP_STUBS); when(dropSchemaStatement.isContainsCascade()).thenReturn(containsCascade); when(dropSchemaStatement.getTables()).thenReturn(Collections.emptyList()); - return new DropTableStatementContext(dropSchemaStatement, "foo_db"); + return new DropTableStatementContext(dropSchemaStatement); } } diff --git a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/SingleSQLRouterTest.java b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/SingleSQLRouterTest.java index 4c39da843870d..d14c60b38c4ab 100644 --- a/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/SingleSQLRouterTest.java +++ b/kernel/single/core/src/test/java/org/apache/shardingsphere/single/route/SingleSQLRouterTest.java @@ -42,6 +42,7 @@ import org.apache.shardingsphere.infra.spi.type.ordered.OrderedSPILoader; import org.apache.shardingsphere.single.config.SingleRuleConfiguration; import org.apache.shardingsphere.single.rule.SingleRule; +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.CreateTableStatement; @@ -215,13 +216,14 @@ void assertDecorateRouteContextWithMultiDataSource() throws SQLException { private QueryContext createQueryContext() { CreateTableStatement createTableStatement = new MySQLCreateTableStatement(false); - createTableStatement.setTable(new SimpleTableSegment(new TableNameSegment(1, 2, new IdentifierValue("t_order")))); + TableNameSegment tableNameSegment = new TableNameSegment(1, 2, new IdentifierValue("t_order")); + tableNameSegment.setTableBoundInfo(new TableSegmentBoundInfo(new IdentifierValue("foo_db"), new IdentifierValue("foo_schema"))); + createTableStatement.setTable(new SimpleTableSegment(tableNameSegment)); ConnectionContext connectionContext = mock(ConnectionContext.class); when(connectionContext.getCurrentDatabaseName()).thenReturn(Optional.of("foo_db")); ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class); when(metaData.containsDatabase("foo_db")).thenReturn(true); when(metaData.getDatabase("foo_db")).thenReturn(mock(ShardingSphereDatabase.class)); - return new QueryContext(new CreateTableStatementContext(createTableStatement, "foo_db"), "CREATE TABLE", new LinkedList<>(), new HintValueContext(), connectionContext, - metaData); + return new QueryContext(new CreateTableStatementContext(createTableStatement), "CREATE TABLE", new LinkedList<>(), new HintValueContext(), connectionContext, metaData); } } diff --git a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/extractor/TableExtractor.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/extractor/TableExtractor.java index 7b3ae07a2b06e..310f2238af603 100644 --- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/extractor/TableExtractor.java +++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/extractor/TableExtractor.java @@ -225,7 +225,9 @@ private void extractTablesFromProjections(final ProjectionsSegment projections) } private SimpleTableSegment createSimpleTableSegment(final OwnerSegment ownerSegment) { - SimpleTableSegment result = new SimpleTableSegment(new TableNameSegment(ownerSegment.getStartIndex(), ownerSegment.getStopIndex(), ownerSegment.getIdentifier())); + TableNameSegment tableNameSegment = new TableNameSegment(ownerSegment.getStartIndex(), ownerSegment.getStopIndex(), ownerSegment.getIdentifier()); + ownerSegment.getTableBoundInfo().ifPresent(tableNameSegment::setTableBoundInfo); + SimpleTableSegment result = new SimpleTableSegment(tableNameSegment); ownerSegment.getOwner().ifPresent(result::setOwner); return result; } @@ -235,7 +237,9 @@ private void extractTablesFromOrderByItems(final Collection if (each instanceof ColumnOrderByItemSegment) { Optional owner = ((ColumnOrderByItemSegment) each).getColumn().getOwner(); if (owner.isPresent() && needRewrite(owner.get())) { - rewriteTables.add(new SimpleTableSegment(new TableNameSegment(owner.get().getStartIndex(), owner.get().getStopIndex(), owner.get().getIdentifier()))); + TableNameSegment tableNameSegment = new TableNameSegment(owner.get().getStartIndex(), owner.get().getStopIndex(), owner.get().getIdentifier()); + owner.get().getTableBoundInfo().ifPresent(tableNameSegment::setTableBoundInfo); + rewriteTables.add(new SimpleTableSegment(tableNameSegment)); } } } diff --git a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/generic/table/TableNameSegment.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/generic/table/TableNameSegment.java index d12bf30caad43..936abc3d8ee8e 100644 --- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/generic/table/TableNameSegment.java +++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/segment/generic/table/TableNameSegment.java @@ -24,12 +24,13 @@ import org.apache.shardingsphere.sql.parser.statement.core.segment.generic.bound.TableSegmentBoundInfo; import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue; +import java.util.Optional; + /** * Table name segment. */ @RequiredArgsConstructor @Getter -@Setter public final class TableNameSegment implements SQLSegment { private final int startIndex; @@ -38,5 +39,15 @@ public final class TableNameSegment implements SQLSegment { private final IdentifierValue identifier; + @Setter private TableSegmentBoundInfo tableBoundInfo; + + /** + * Get table bound info. + * + * @return table bound info + */ + public Optional getTableBoundInfo() { + return Optional.ofNullable(tableBoundInfo); + } } 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 e15e19d7bb2ff..b2dbcc146d3fd 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 @@ -240,19 +240,19 @@ void assertCheckExecutePrerequisitesWhenExecuteDDLNotInPostgreSQLTransaction() { private CreateTableStatementContext createMySQLCreateTableStatementContext() { MySQLCreateTableStatement sqlStatement = new MySQLCreateTableStatement(false); sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); - return new CreateTableStatementContext(sqlStatement, "foo_db"); + return new CreateTableStatementContext(sqlStatement); } private TruncateStatementContext createMySQLTruncateStatementContext() { MySQLTruncateStatement sqlStatement = new MySQLTruncateStatement(); sqlStatement.getTables().add(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); - return new TruncateStatementContext(sqlStatement, "foo_db"); + return new TruncateStatementContext(sqlStatement); } private SQLStatementContext createPostgreSQLTruncateStatementContext() { PostgreSQLTruncateStatement sqlStatement = new PostgreSQLTruncateStatement(); sqlStatement.getTables().add(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); - return new TruncateStatementContext(sqlStatement, "foo_db"); + return new TruncateStatementContext(sqlStatement); } private CursorStatementContext createCursorStatementContext() { @@ -276,7 +276,7 @@ private InsertStatementContext createMySQLInsertStatementContext() { private CreateTableStatementContext createPostgreSQLCreateTableStatementContext() { PostgreSQLCreateTableStatement sqlStatement = new PostgreSQLCreateTableStatement(false); sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new IdentifierValue("t_order")))); - return new CreateTableStatementContext(sqlStatement, "foo_db"); + return new CreateTableStatementContext(sqlStatement); } private InsertStatementContext createPostgreSQLInsertStatementContext() { diff --git a/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLAdminExecutorCreatorTest.java b/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLAdminExecutorCreatorTest.java index bb7ed467d3bb2..83a46ca8d2651 100644 --- a/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLAdminExecutorCreatorTest.java +++ b/proxy/backend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/PostgreSQLAdminExecutorCreatorTest.java @@ -163,7 +163,7 @@ void assertCreateWithResetStatement() { @Test void assertCreateWithDMLStatement() { - DeleteStatementContext sqlStatementContext = new DeleteStatementContext(new PostgreSQLDeleteStatement(), "foo_db"); + DeleteStatementContext sqlStatementContext = new DeleteStatementContext(new PostgreSQLDeleteStatement()); assertThat(new PostgreSQLAdminExecutorCreator().create(sqlStatementContext, "delete from t where id = 1", "", Collections.emptyList()), is(Optional.empty())); } } From f67605e69e42eaed528ffb773c276d28e69e5105 Mon Sep 17 00:00:00 2001 From: Raigor Date: Fri, 13 Dec 2024 13:25:42 +0800 Subject: [PATCH 15/32] Support ALL PRIVILEGES ON `DB`.* in MySQLDatabasePrivilegeChecker (#34037) * Support ALL PRIVILEGES ON `DB`.* in MySQLDatabasePrivilegeChecker * Update RELEASE-NOTES.md --- RELEASE-NOTES.md | 1 + .../MySQLDatabasePrivilegeChecker.java | 3 +- .../MySQLDatabasePrivilegeCheckerTest.java | 56 +++++++++++++++++-- 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 6416bae3536d0..dcc167c950336 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -54,6 +54,7 @@ 1. Sharding: Fixes avg, sum, min, max function return empty data when no query result return - [#33449](https://github.com/apache/shardingsphere/pull/33449) 1. Encrypt: Fixes merge exception without encrypt rule in database - [#33708](https://github.com/apache/shardingsphere/pull/33708) 1. SQL Binder: Fixes the expression segment cannot find the outer table when binding - [#34015](https://github.com/apache/shardingsphere/pull/34015) +1. Proxy: Fixes "ALL PRIVILEGES ON `DB`.*" is not recognized during SELECT privilege verification for MySQL - [#34037](https://github.com/apache/shardingsphere/pull/34037) ### Change Logs diff --git a/infra/database/type/mysql/src/main/java/org/apache/shardingsphere/infra/database/mysql/checker/MySQLDatabasePrivilegeChecker.java b/infra/database/type/mysql/src/main/java/org/apache/shardingsphere/infra/database/mysql/checker/MySQLDatabasePrivilegeChecker.java index 61a2614637a00..2fdfe09656d01 100644 --- a/infra/database/type/mysql/src/main/java/org/apache/shardingsphere/infra/database/mysql/checker/MySQLDatabasePrivilegeChecker.java +++ b/infra/database/type/mysql/src/main/java/org/apache/shardingsphere/infra/database/mysql/checker/MySQLDatabasePrivilegeChecker.java @@ -98,7 +98,8 @@ private String[][] getRequiredPrivileges(final Connection connection, final Priv } private String[][] getSelectRequiredPrivilege(final Connection connection) throws SQLException { - return new String[][]{{"ALL PRIVILEGES", "ON *.*"}, {"SELECT", "ON *.*"}, {"SELECT", String.format("ON `%s`.*", connection.getCatalog()).toUpperCase()}}; + String onCatalog = String.format("ON `%s`.*", connection.getCatalog().toUpperCase()); + return new String[][]{{"ALL PRIVILEGES", "ON *.*"}, {"SELECT", "ON *.*"}, {"ALL PRIVILEGES", onCatalog}, {"SELECT", onCatalog}}; } private boolean matchPrivileges(final String grantedPrivileges, final String[][] requiredPrivileges) { diff --git a/infra/database/type/mysql/src/test/java/org/apache/shardingsphere/infra/database/mysql/checker/MySQLDatabasePrivilegeCheckerTest.java b/infra/database/type/mysql/src/test/java/org/apache/shardingsphere/infra/database/mysql/checker/MySQLDatabasePrivilegeCheckerTest.java index 160223f5e5734..4da2b2dce5fab 100644 --- a/infra/database/type/mysql/src/test/java/org/apache/shardingsphere/infra/database/mysql/checker/MySQLDatabasePrivilegeCheckerTest.java +++ b/infra/database/type/mysql/src/test/java/org/apache/shardingsphere/infra/database/mysql/checker/MySQLDatabasePrivilegeCheckerTest.java @@ -56,7 +56,7 @@ void setUp() throws SQLException { } @Test - void assertCheckPrivilegeWithParticularSuccess() throws SQLException { + void assertCheckPipelinePrivilegeWithParticularSuccess() throws SQLException { when(preparedStatement.executeQuery()).thenReturn(resultSet); when(resultSet.next()).thenReturn(true); when(resultSet.getString(1)).thenReturn("GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO '%'@'%'"); @@ -65,22 +65,22 @@ void assertCheckPrivilegeWithParticularSuccess() throws SQLException { } @Test - void assertCheckPrivilegeWithAllSuccess() throws SQLException { + void assertCheckPipelinePrivilegeWithAllSuccess() throws SQLException { when(preparedStatement.executeQuery()).thenReturn(resultSet); when(resultSet.next()).thenReturn(true); - when(resultSet.getString(1)).thenReturn("GRANT ALL PRIVILEGES CLIENT ON *.* TO '%'@'%'"); + when(resultSet.getString(1)).thenReturn("GRANT ALL PRIVILEGES ON *.* TO '%'@'%'"); new MySQLDatabasePrivilegeChecker().check(dataSource, PrivilegeCheckType.PIPELINE); verify(preparedStatement).executeQuery(); } @Test - void assertCheckPrivilegeLackPrivileges() throws SQLException { + void assertCheckPipelinePrivilegeWithLackPrivileges() throws SQLException { when(preparedStatement.executeQuery()).thenReturn(resultSet); assertThrows(MissingRequiredPrivilegeException.class, () -> new MySQLDatabasePrivilegeChecker().check(dataSource, PrivilegeCheckType.PIPELINE)); } @Test - void assertCheckPrivilegeFailure() throws SQLException { + void assertCheckPipelinePrivilegeFailure() throws SQLException { when(preparedStatement.executeQuery()).thenReturn(resultSet); when(resultSet.next()).thenThrow(new SQLException("")); assertThrows(CheckDatabaseEnvironmentFailedException.class, () -> new MySQLDatabasePrivilegeChecker().check(dataSource, PrivilegeCheckType.PIPELINE)); @@ -127,4 +127,50 @@ void assertCheckXAPrivilegeFailureInMySQL8() throws SQLException { when(resultSet.next()).thenThrow(new SQLException("")); assertThrows(CheckDatabaseEnvironmentFailedException.class, () -> new MySQLDatabasePrivilegeChecker().check(dataSource, PrivilegeCheckType.XA)); } + + @Test + void assertCheckSelectWithSelectPrivileges() throws SQLException { + when(dataSource.getConnection().getCatalog()).thenReturn("foo_db"); + when(preparedStatement.executeQuery()).thenReturn(resultSet); + when(resultSet.next()).thenReturn(true); + when(resultSet.getString(1)).thenReturn("GRANT SELECT ON *.* TO '%'@'%'"); + new MySQLDatabasePrivilegeChecker().check(dataSource, PrivilegeCheckType.SELECT); + verify(preparedStatement).executeQuery(); + } + + @Test + void assertCheckSelectWithSelectOnDatabasePrivileges() throws SQLException { + when(dataSource.getConnection().getCatalog()).thenReturn("foo_db"); + when(preparedStatement.executeQuery()).thenReturn(resultSet); + when(resultSet.next()).thenReturn(true); + when(resultSet.getString(1)).thenReturn("GRANT SELECT ON `FOO_DB`.* TO '%'@'%'"); + new MySQLDatabasePrivilegeChecker().check(dataSource, PrivilegeCheckType.SELECT); + verify(preparedStatement).executeQuery(); + } + + @Test + void assertCheckSelectWithAllPrivileges() throws SQLException { + when(dataSource.getConnection().getCatalog()).thenReturn("foo_db"); + when(preparedStatement.executeQuery()).thenReturn(resultSet); + when(resultSet.next()).thenReturn(true); + when(resultSet.getString(1)).thenReturn("GRANT ALL PRIVILEGES ON *.* TO '%'@'%'"); + new MySQLDatabasePrivilegeChecker().check(dataSource, PrivilegeCheckType.SELECT); + verify(preparedStatement).executeQuery(); + } + + @Test + void assertCheckSelectWithAllPrivilegesOnDatabase() throws SQLException { + when(dataSource.getConnection().getCatalog()).thenReturn("foo_db"); + when(preparedStatement.executeQuery()).thenReturn(resultSet); + when(resultSet.next()).thenReturn(true); + when(resultSet.getString(1)).thenReturn("GRANT ALL PRIVILEGES ON `FOO_DB`.* TO '%'@'%'"); + new MySQLDatabasePrivilegeChecker().check(dataSource, PrivilegeCheckType.SELECT); + verify(preparedStatement).executeQuery(); + } + + @Test + void assertCheckSelectWithLackPrivileges() throws SQLException { + when(preparedStatement.executeQuery()).thenReturn(resultSet); + assertThrows(MissingRequiredPrivilegeException.class, () -> new MySQLDatabasePrivilegeChecker().check(dataSource, PrivilegeCheckType.SELECT)); + } } From a9e8e9b1a1a3f3b5874abd1d3c071cbaf2f0ec99 Mon Sep 17 00:00:00 2001 From: Cong Hu Date: Fri, 13 Dec 2024 13:37:26 +0800 Subject: [PATCH 16/32] Add isClosed in ShardingSphereProxy. (#34035) --- .../proxy/frontend/ShardingSphereProxy.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/ShardingSphereProxy.java b/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/ShardingSphereProxy.java index e9dd622965251..f39ac83e0be0a 100644 --- a/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/ShardingSphereProxy.java +++ b/proxy/frontend/core/src/main/java/org/apache/shardingsphere/proxy/frontend/ShardingSphereProxy.java @@ -54,6 +54,8 @@ public final class ShardingSphereProxy { private final EventLoopGroup workerGroup; + private boolean isClosed; + public ShardingSphereProxy() { bossGroup = Epoll.isAvailable() ? new EpollEventLoopGroup(1) : new NioEventLoopGroup(1); workerGroup = getWorkerGroup(); @@ -157,10 +159,14 @@ private void initServerBootstrap(final ServerBootstrap bootstrap, final DomainSo /** * Close ShardingSphere-Proxy. */ - public void close() { + public synchronized void close() { + if (isClosed) { + return; + } bossGroup.shutdownGracefully(); workerGroup.shutdownGracefully(); BackendExecutorContext.getInstance().getExecutorEngine().close(); ProxyContext.getInstance().getContextManager().close(); + isClosed = true; } } From f39b52bfee012ef616082b4d48844a0c713150f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E5=BF=B5=E5=90=9B=20Nianjun=20Sun?= Date: Fri, 13 Dec 2024 15:32:58 +0800 Subject: [PATCH 17/32] Add : add invalid in stale check (#34038) --- .github/workflows/nightly-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/nightly-check.yml b/.github/workflows/nightly-check.yml index dfe30e9f3771f..85412101d1eb0 100644 --- a/.github/workflows/nightly-check.yml +++ b/.github/workflows/nightly-check.yml @@ -126,7 +126,7 @@ jobs: days-before-pr-stale: -1 days-before-close: -1 stale-issue-label: "stale" - any-of-issue-labels: "status: need more info,type: question,type: duplicate" + any-of-issue-labels: "status: need more info,type: question,type: duplicate,status: invalid" operations-per-run: 100 remove-stale-when-updated: true stale-issue-message: > From a2de70671ce1b632e932b440f351a1fb4b5b37f0 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Fri, 13 Dec 2024 17:29:35 +0800 Subject: [PATCH 18/32] Add DeliverEventSubscriberFactory SPI (#34041) * Add DeliverEventSubscriberFactory SPI * Add DeliverEventSubscriberFactory SPI * Add DeliverEventSubscriberFactory SPI --- ...plittingStaticDataSourceRuleAttribute.java | 2 +- .../QualifiedDataSourceDeletedEvent.java | 2 +- .../QualifiedDataSourceDeletedSubscriber.java | 11 +++--- ...iedDataSourceDeletedSubscriberFactory.java | 23 +++++------ ...vent.deliver.DeliverEventSubscriberFactory | 18 +++++++++ ...tingStaticDataSourceRuleAttributeTest.java | 2 +- ...lifiedDataSourceDeletedSubscriberTest.java | 13 +++---- .../DeliverEventSubscriberFactory.java | 39 +++++++++++++++++++ .../cluster/ClusterContextManagerBuilder.java | 9 +++-- 9 files changed, 86 insertions(+), 33 deletions(-) rename {mode/api/src/main/java/org/apache/shardingsphere/mode/event/deliver/datasource/qualified => features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber}/QualifiedDataSourceDeletedEvent.java (94%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/type/DeliverQualifiedDataSourceSubscriber.java => features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/QualifiedDataSourceDeletedSubscriber.java (76%) rename mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/ClusterDeliverEventSubscriberRegistry.java => features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/QualifiedDataSourceDeletedSubscriberFactory.java (54%) create mode 100644 features/readwrite-splitting/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.event.deliver.DeliverEventSubscriberFactory rename mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/type/DeliverQualifiedDataSourceSubscriberTest.java => features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/subscriber/QualifiedDataSourceDeletedSubscriberTest.java (75%) create mode 100644 mode/api/src/main/java/org/apache/shardingsphere/mode/event/deliver/DeliverEventSubscriberFactory.java diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttribute.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttribute.java index 03234fb9e05c1..5ecbd89d1bf4d 100644 --- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttribute.java +++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttribute.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource; import org.apache.shardingsphere.infra.rule.attribute.datasource.StaticDataSourceRuleAttribute; import org.apache.shardingsphere.infra.state.datasource.DataSourceState; -import org.apache.shardingsphere.mode.event.deliver.datasource.qualified.QualifiedDataSourceDeletedEvent; +import org.apache.shardingsphere.readwritesplitting.subscriber.QualifiedDataSourceDeletedEvent; import org.apache.shardingsphere.readwritesplitting.exception.logic.ReadwriteSplittingDataSourceRuleNotFoundException; import org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingDataSourceGroupRule; diff --git a/mode/api/src/main/java/org/apache/shardingsphere/mode/event/deliver/datasource/qualified/QualifiedDataSourceDeletedEvent.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/QualifiedDataSourceDeletedEvent.java similarity index 94% rename from mode/api/src/main/java/org/apache/shardingsphere/mode/event/deliver/datasource/qualified/QualifiedDataSourceDeletedEvent.java rename to features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/QualifiedDataSourceDeletedEvent.java index 4f0497aa541c0..f21213b004d5b 100644 --- a/mode/api/src/main/java/org/apache/shardingsphere/mode/event/deliver/datasource/qualified/QualifiedDataSourceDeletedEvent.java +++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/QualifiedDataSourceDeletedEvent.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.event.deliver.datasource.qualified; +package org.apache.shardingsphere.readwritesplitting.subscriber; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/type/DeliverQualifiedDataSourceSubscriber.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/QualifiedDataSourceDeletedSubscriber.java similarity index 76% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/type/DeliverQualifiedDataSourceSubscriber.java rename to features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/QualifiedDataSourceDeletedSubscriber.java index 252173f110531..878be851d6374 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/type/DeliverQualifiedDataSourceSubscriber.java +++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/QualifiedDataSourceDeletedSubscriber.java @@ -15,22 +15,21 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.deliver.subscriber.type; +package org.apache.shardingsphere.readwritesplitting.subscriber; import com.google.common.eventbus.Subscribe; import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.util.eventbus.EventSubscriber; -import org.apache.shardingsphere.mode.event.deliver.datasource.qualified.QualifiedDataSourceDeletedEvent; -import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; import org.apache.shardingsphere.metadata.persist.node.QualifiedDataSourceNode; +import org.apache.shardingsphere.mode.spi.PersistRepository; /** - * Deliver data source status subscriber. + * Qualified data source deleted subscriber. */ @RequiredArgsConstructor -public final class DeliverQualifiedDataSourceSubscriber implements EventSubscriber { +public final class QualifiedDataSourceDeletedSubscriber implements EventSubscriber { - private final ClusterPersistRepository repository; + private final PersistRepository repository; /** * Delete qualified data source. diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/ClusterDeliverEventSubscriberRegistry.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/QualifiedDataSourceDeletedSubscriberFactory.java similarity index 54% rename from mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/ClusterDeliverEventSubscriberRegistry.java rename to features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/QualifiedDataSourceDeletedSubscriberFactory.java index 3f874da0067fe..942a64d45aa0c 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/ClusterDeliverEventSubscriberRegistry.java +++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/QualifiedDataSourceDeletedSubscriberFactory.java @@ -15,25 +15,20 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.deliver.subscriber; +package org.apache.shardingsphere.readwritesplitting.subscriber; -import lombok.Getter; +import org.apache.shardingsphere.infra.util.eventbus.EventBusContext; import org.apache.shardingsphere.infra.util.eventbus.EventSubscriber; -import org.apache.shardingsphere.mode.manager.cluster.event.deliver.subscriber.type.DeliverQualifiedDataSourceSubscriber; -import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; - -import java.util.Collection; -import java.util.Collections; +import org.apache.shardingsphere.mode.event.deliver.DeliverEventSubscriberFactory; +import org.apache.shardingsphere.mode.spi.PersistRepository; /** - * Cluster deliver event subscriber registry. + * Qualified data source deleted subscriber factory. */ -@Getter -public final class ClusterDeliverEventSubscriberRegistry { - - private final Collection subscribers; +public final class QualifiedDataSourceDeletedSubscriberFactory implements DeliverEventSubscriberFactory { - public ClusterDeliverEventSubscriberRegistry(final ClusterPersistRepository repository) { - subscribers = Collections.singleton(new DeliverQualifiedDataSourceSubscriber(repository)); + @Override + public EventSubscriber create(final PersistRepository repository, final EventBusContext eventBusContext) { + return new QualifiedDataSourceDeletedSubscriber(repository); } } diff --git a/features/readwrite-splitting/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.event.deliver.DeliverEventSubscriberFactory b/features/readwrite-splitting/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.event.deliver.DeliverEventSubscriberFactory new file mode 100644 index 0000000000000..1578fc246e635 --- /dev/null +++ b/features/readwrite-splitting/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.event.deliver.DeliverEventSubscriberFactory @@ -0,0 +1,18 @@ +# +# 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. +# + +org.apache.shardingsphere.readwritesplitting.subscriber.QualifiedDataSourceDeletedSubscriberFactory diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttributeTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttributeTest.java index f56387f3ab4bf..cdfaf039bceb0 100644 --- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttributeTest.java +++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttributeTest.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext; import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource; import org.apache.shardingsphere.infra.state.datasource.DataSourceState; -import org.apache.shardingsphere.mode.event.deliver.datasource.qualified.QualifiedDataSourceDeletedEvent; +import org.apache.shardingsphere.readwritesplitting.subscriber.QualifiedDataSourceDeletedEvent; import org.apache.shardingsphere.readwritesplitting.exception.logic.ReadwriteSplittingDataSourceRuleNotFoundException; import org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingDataSourceGroupRule; import org.junit.jupiter.api.Test; diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/type/DeliverQualifiedDataSourceSubscriberTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/subscriber/QualifiedDataSourceDeletedSubscriberTest.java similarity index 75% rename from mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/type/DeliverQualifiedDataSourceSubscriberTest.java rename to features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/subscriber/QualifiedDataSourceDeletedSubscriberTest.java index f9d25ff1cf5c0..1cdc92dde2f88 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/deliver/subscriber/type/DeliverQualifiedDataSourceSubscriberTest.java +++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/subscriber/QualifiedDataSourceDeletedSubscriberTest.java @@ -15,11 +15,10 @@ * limitations under the License. */ -package org.apache.shardingsphere.mode.manager.cluster.event.deliver.subscriber.type; +package org.apache.shardingsphere.readwritesplitting.subscriber; import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource; -import org.apache.shardingsphere.mode.event.deliver.datasource.qualified.QualifiedDataSourceDeletedEvent; -import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; +import org.apache.shardingsphere.mode.spi.PersistRepository; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -29,16 +28,16 @@ import static org.mockito.Mockito.verify; @ExtendWith(MockitoExtension.class) -class DeliverQualifiedDataSourceSubscriberTest { +class QualifiedDataSourceDeletedSubscriberTest { - private DeliverQualifiedDataSourceSubscriber subscriber; + private QualifiedDataSourceDeletedSubscriber subscriber; @Mock - private ClusterPersistRepository repository; + private PersistRepository repository; @BeforeEach void setUp() { - subscriber = new DeliverQualifiedDataSourceSubscriber(repository); + subscriber = new QualifiedDataSourceDeletedSubscriber(repository); } @Test diff --git a/mode/api/src/main/java/org/apache/shardingsphere/mode/event/deliver/DeliverEventSubscriberFactory.java b/mode/api/src/main/java/org/apache/shardingsphere/mode/event/deliver/DeliverEventSubscriberFactory.java new file mode 100644 index 0000000000000..a43902000c2e6 --- /dev/null +++ b/mode/api/src/main/java/org/apache/shardingsphere/mode/event/deliver/DeliverEventSubscriberFactory.java @@ -0,0 +1,39 @@ +/* + * 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.mode.event.deliver; + +import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI; +import org.apache.shardingsphere.infra.util.eventbus.EventBusContext; +import org.apache.shardingsphere.infra.util.eventbus.EventSubscriber; +import org.apache.shardingsphere.mode.spi.PersistRepository; + +/** + * Deliver event subscriber factory. + */ +@SingletonSPI +public interface DeliverEventSubscriberFactory { + + /** + * Create deliver event subscriber. + * + * @param repository cluster persist repository + * @param eventBusContext event bus context + * @return created event subscriber + */ + EventSubscriber create(PersistRepository repository, EventBusContext eventBusContext); +} diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java index a8c574fd3a5b7..c942b31c0fca5 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java @@ -23,6 +23,7 @@ import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext; import org.apache.shardingsphere.infra.instance.metadata.jdbc.JDBCInstanceMetaData; import org.apache.shardingsphere.infra.lock.LockContext; +import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; import org.apache.shardingsphere.infra.util.eventbus.EventBusContext; import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; @@ -31,10 +32,10 @@ import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.manager.ContextManagerBuilder; import org.apache.shardingsphere.mode.manager.ContextManagerBuilderParameter; -import org.apache.shardingsphere.mode.manager.cluster.event.deliver.subscriber.ClusterDeliverEventSubscriberRegistry; +import org.apache.shardingsphere.mode.event.deliver.DeliverEventSubscriberFactory; +import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener.DataChangedEventListenerRegistry; import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.ClusterDispatchEventSubscriberRegistry; import org.apache.shardingsphere.mode.manager.cluster.exception.MissingRequiredClusterRepositoryConfigurationException; -import org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener.DataChangedEventListenerRegistry; import org.apache.shardingsphere.mode.manager.cluster.persist.service.GlobalLockPersistService; import org.apache.shardingsphere.mode.manager.cluster.workerid.ClusterWorkerIdGenerator; import org.apache.shardingsphere.mode.metadata.MetaDataContexts; @@ -44,6 +45,7 @@ import java.sql.SQLException; import java.util.Collection; +import java.util.stream.Collectors; /** * Cluster context manager builder. @@ -78,7 +80,8 @@ private void registerOnline(final ComputeNodeInstanceContext computeNodeInstance contextManager.getComputeNodeInstanceContext().getAllClusterInstances().addAll(contextManager.getPersistServiceFacade().getComputeNodePersistService().loadAllComputeNodeInstances()); new DataChangedEventListenerRegistry(contextManager, getDatabaseNames(param, contextManager.getPersistServiceFacade().getMetaDataPersistService())).register(); EventSubscriberRegistry eventSubscriberRegistry = new EventSubscriberRegistry(contextManager.getComputeNodeInstanceContext().getEventBusContext()); - eventSubscriberRegistry.register(new ClusterDeliverEventSubscriberRegistry(repository).getSubscribers()); + eventSubscriberRegistry.register(ShardingSphereServiceLoader.getServiceInstances(DeliverEventSubscriberFactory.class).stream() + .map(each -> each.create(repository, contextManager.getComputeNodeInstanceContext().getEventBusContext())).collect(Collectors.toList())); eventSubscriberRegistry.register(new ClusterDispatchEventSubscriberRegistry(contextManager).getSubscribers()); } From 93965c6147fd57a44eedec03f9c389e714d892a4 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Fri, 13 Dec 2024 18:55:40 +0800 Subject: [PATCH 19/32] Rename ReadwriteSplittingQualifiedDataSourceDeletedSubscriber (#34045) * Rename ReadwriteSplittingQualifiedDataSourceDeletedSubscriber * Rename ReadwriteSplittingQualifiedDataSourceDeletedSubscriber --- .../ReadwriteSplittingStaticDataSourceRuleAttribute.java | 5 +++-- ...eadwriteSplittingQualifiedDataSourceDeletedEvent.java} | 4 ++-- ...iteSplittingQualifiedDataSourceDeletedSubscriber.java} | 6 +++--- ...ttingQualifiedDataSourceDeletedSubscriberFactory.java} | 6 +++--- ...phere.mode.event.deliver.DeliverEventSubscriberFactory | 2 +- ...adwriteSplittingStaticDataSourceRuleAttributeTest.java | 6 +++--- ...plittingQualifiedDataSourceDeletedSubscriberTest.java} | 8 ++++---- 7 files changed, 19 insertions(+), 18 deletions(-) rename features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/{QualifiedDataSourceDeletedEvent.java => ReadwriteSplittingQualifiedDataSourceDeletedEvent.java} (88%) rename features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/{QualifiedDataSourceDeletedSubscriber.java => ReadwriteSplittingQualifiedDataSourceDeletedSubscriber.java} (85%) rename features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/{QualifiedDataSourceDeletedSubscriberFactory.java => ReadwriteSplittingQualifiedDataSourceDeletedSubscriberFactory.java} (82%) rename features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/subscriber/{QualifiedDataSourceDeletedSubscriberTest.java => ReadwriteSplittingQualifiedDataSourceDeletedSubscriberTest.java} (80%) diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttribute.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttribute.java index 5ecbd89d1bf4d..f010866034869 100644 --- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttribute.java +++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttribute.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource; import org.apache.shardingsphere.infra.rule.attribute.datasource.StaticDataSourceRuleAttribute; import org.apache.shardingsphere.infra.state.datasource.DataSourceState; -import org.apache.shardingsphere.readwritesplitting.subscriber.QualifiedDataSourceDeletedEvent; +import org.apache.shardingsphere.readwritesplitting.subscriber.ReadwriteSplittingQualifiedDataSourceDeletedEvent; import org.apache.shardingsphere.readwritesplitting.exception.logic.ReadwriteSplittingDataSourceRuleNotFoundException; import org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingDataSourceGroupRule; @@ -69,6 +69,7 @@ public void cleanStorageNodeDataSources() { private void deleteStorageNodeDataSources(final ReadwriteSplittingDataSourceGroupRule rule) { rule.getReadwriteSplittingGroup().getReadDataSources() - .forEach(each -> computeNodeInstanceContext.getEventBusContext().post(new QualifiedDataSourceDeletedEvent(new QualifiedDataSource(databaseName, rule.getName(), each)))); + .forEach(each -> computeNodeInstanceContext.getEventBusContext() + .post(new ReadwriteSplittingQualifiedDataSourceDeletedEvent(new QualifiedDataSource(databaseName, rule.getName(), each)))); } } diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/QualifiedDataSourceDeletedEvent.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingQualifiedDataSourceDeletedEvent.java similarity index 88% rename from features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/QualifiedDataSourceDeletedEvent.java rename to features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingQualifiedDataSourceDeletedEvent.java index f21213b004d5b..391a6830fb4d3 100644 --- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/QualifiedDataSourceDeletedEvent.java +++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingQualifiedDataSourceDeletedEvent.java @@ -23,11 +23,11 @@ import org.apache.shardingsphere.infra.util.event.DeliverEvent; /** - * Qualified data source deleted event. + * Readwrite-splitting qualified data source deleted event. */ @RequiredArgsConstructor @Getter -public final class QualifiedDataSourceDeletedEvent implements DeliverEvent { +public final class ReadwriteSplittingQualifiedDataSourceDeletedEvent implements DeliverEvent { private final QualifiedDataSource qualifiedDataSource; } diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/QualifiedDataSourceDeletedSubscriber.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingQualifiedDataSourceDeletedSubscriber.java similarity index 85% rename from features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/QualifiedDataSourceDeletedSubscriber.java rename to features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingQualifiedDataSourceDeletedSubscriber.java index 878be851d6374..6add89d0c9c4a 100644 --- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/QualifiedDataSourceDeletedSubscriber.java +++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingQualifiedDataSourceDeletedSubscriber.java @@ -24,10 +24,10 @@ import org.apache.shardingsphere.mode.spi.PersistRepository; /** - * Qualified data source deleted subscriber. + * Readwrite-splitting qualified data source deleted subscriber. */ @RequiredArgsConstructor -public final class QualifiedDataSourceDeletedSubscriber implements EventSubscriber { +public final class ReadwriteSplittingQualifiedDataSourceDeletedSubscriber implements EventSubscriber { private final PersistRepository repository; @@ -37,7 +37,7 @@ public final class QualifiedDataSourceDeletedSubscriber implements EventSubscrib * @param event qualified data source deleted event */ @Subscribe - public void delete(final QualifiedDataSourceDeletedEvent event) { + public void delete(final ReadwriteSplittingQualifiedDataSourceDeletedEvent event) { repository.delete(QualifiedDataSourceNode.getQualifiedDataSourceNodePath(event.getQualifiedDataSource())); } } diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/QualifiedDataSourceDeletedSubscriberFactory.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingQualifiedDataSourceDeletedSubscriberFactory.java similarity index 82% rename from features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/QualifiedDataSourceDeletedSubscriberFactory.java rename to features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingQualifiedDataSourceDeletedSubscriberFactory.java index 942a64d45aa0c..0f9f4c3b3da3f 100644 --- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/QualifiedDataSourceDeletedSubscriberFactory.java +++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingQualifiedDataSourceDeletedSubscriberFactory.java @@ -23,12 +23,12 @@ import org.apache.shardingsphere.mode.spi.PersistRepository; /** - * Qualified data source deleted subscriber factory. + * Readwrite-splitting qualified data source deleted subscriber factory. */ -public final class QualifiedDataSourceDeletedSubscriberFactory implements DeliverEventSubscriberFactory { +public final class ReadwriteSplittingQualifiedDataSourceDeletedSubscriberFactory implements DeliverEventSubscriberFactory { @Override public EventSubscriber create(final PersistRepository repository, final EventBusContext eventBusContext) { - return new QualifiedDataSourceDeletedSubscriber(repository); + return new ReadwriteSplittingQualifiedDataSourceDeletedSubscriber(repository); } } diff --git a/features/readwrite-splitting/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.event.deliver.DeliverEventSubscriberFactory b/features/readwrite-splitting/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.event.deliver.DeliverEventSubscriberFactory index 1578fc246e635..a40d43dc35746 100644 --- a/features/readwrite-splitting/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.event.deliver.DeliverEventSubscriberFactory +++ b/features/readwrite-splitting/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.event.deliver.DeliverEventSubscriberFactory @@ -15,4 +15,4 @@ # limitations under the License. # -org.apache.shardingsphere.readwritesplitting.subscriber.QualifiedDataSourceDeletedSubscriberFactory +org.apache.shardingsphere.readwritesplitting.subscriber.ReadwriteSplittingQualifiedDataSourceDeletedSubscriberFactory diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttributeTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttributeTest.java index cdfaf039bceb0..86946d7de5f60 100644 --- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttributeTest.java +++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttributeTest.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext; import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource; import org.apache.shardingsphere.infra.state.datasource.DataSourceState; -import org.apache.shardingsphere.readwritesplitting.subscriber.QualifiedDataSourceDeletedEvent; +import org.apache.shardingsphere.readwritesplitting.subscriber.ReadwriteSplittingQualifiedDataSourceDeletedEvent; import org.apache.shardingsphere.readwritesplitting.exception.logic.ReadwriteSplittingDataSourceRuleNotFoundException; import org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingDataSourceGroupRule; import org.junit.jupiter.api.Test; @@ -75,7 +75,7 @@ void assertCleanStorageNodeDataSource() { ReadwriteSplittingStaticDataSourceRuleAttribute ruleAttribute = new ReadwriteSplittingStaticDataSourceRuleAttribute( "foo_db", Collections.singletonMap("foo_group", dataSourceGroupRule), computeNodeInstanceContext); ruleAttribute.cleanStorageNodeDataSource("foo_group"); - verify(computeNodeInstanceContext.getEventBusContext()).post(deepEq(new QualifiedDataSourceDeletedEvent(new QualifiedDataSource("foo_db.foo_group.read_ds")))); + verify(computeNodeInstanceContext.getEventBusContext()).post(deepEq(new ReadwriteSplittingQualifiedDataSourceDeletedEvent(new QualifiedDataSource("foo_db.foo_group.read_ds")))); } @Test @@ -87,6 +87,6 @@ void assertCleanStorageNodeDataSources() { ReadwriteSplittingStaticDataSourceRuleAttribute ruleAttribute = new ReadwriteSplittingStaticDataSourceRuleAttribute( "foo_db", Collections.singletonMap("foo_group", dataSourceGroupRule), computeNodeInstanceContext); ruleAttribute.cleanStorageNodeDataSources(); - verify(computeNodeInstanceContext.getEventBusContext()).post(deepEq(new QualifiedDataSourceDeletedEvent(new QualifiedDataSource("foo_db.foo_group.read_ds")))); + verify(computeNodeInstanceContext.getEventBusContext()).post(deepEq(new ReadwriteSplittingQualifiedDataSourceDeletedEvent(new QualifiedDataSource("foo_db.foo_group.read_ds")))); } } diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/subscriber/QualifiedDataSourceDeletedSubscriberTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingQualifiedDataSourceDeletedSubscriberTest.java similarity index 80% rename from features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/subscriber/QualifiedDataSourceDeletedSubscriberTest.java rename to features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingQualifiedDataSourceDeletedSubscriberTest.java index 1cdc92dde2f88..c18761ab6da0f 100644 --- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/subscriber/QualifiedDataSourceDeletedSubscriberTest.java +++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingQualifiedDataSourceDeletedSubscriberTest.java @@ -28,21 +28,21 @@ import static org.mockito.Mockito.verify; @ExtendWith(MockitoExtension.class) -class QualifiedDataSourceDeletedSubscriberTest { +class ReadwriteSplittingQualifiedDataSourceDeletedSubscriberTest { - private QualifiedDataSourceDeletedSubscriber subscriber; + private ReadwriteSplittingQualifiedDataSourceDeletedSubscriber subscriber; @Mock private PersistRepository repository; @BeforeEach void setUp() { - subscriber = new QualifiedDataSourceDeletedSubscriber(repository); + subscriber = new ReadwriteSplittingQualifiedDataSourceDeletedSubscriber(repository); } @Test void assertDeleteStorageNodeDataSourceDataSourceState() { - subscriber.delete(new QualifiedDataSourceDeletedEvent(new QualifiedDataSource("foo_db", "foo_group", "foo_ds"))); + subscriber.delete(new ReadwriteSplittingQualifiedDataSourceDeletedEvent(new QualifiedDataSource("foo_db", "foo_group", "foo_ds"))); verify(repository).delete("/nodes/qualified_data_sources/foo_db.foo_group.foo_ds"); } } From 147b22564fdc81ef642d12fdbc22aa14798bb28c Mon Sep 17 00:00:00 2001 From: Maxim Sentyabrskiy <162702318+makssent@users.noreply.github.com> Date: Fri, 13 Dec 2024 18:41:03 +0300 Subject: [PATCH 20/32] Added support returning for some firebird requests (#34047) * Update firebird insert statement to support returning (#33977) * Refactor RETURNING statement to use projections * Update firebird update statement to support returning * Update firebird delete statement to support returning --------- Co-authored-by: TedCraft --- .../antlr4/imports/firebird/DMLStatement.g4 | 12 ++-- .../type/FirebirdDMLStatementVisitor.java | 16 +++++ .../core/statement/dml/UpdateStatement.java | 19 ++++++ .../firebird/dml/FirebirdDeleteStatement.java | 12 ++++ .../firebird/dml/FirebirdInsertStatement.java | 12 ++++ .../firebird/dml/FirebirdUpdateStatement.java | 12 ++++ .../src/main/resources/case/dml/update.xml | 59 +++++++++++++++++++ .../resources/sql/supported/dml/delete.xml | 2 +- .../resources/sql/supported/dml/insert.xml | 2 +- .../resources/sql/supported/dml/update.xml | 1 + 10 files changed, 141 insertions(+), 6 deletions(-) diff --git a/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/DMLStatement.g4 b/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/DMLStatement.g4 index 3d8067b57ae2e..91ef07da8a494 100644 --- a/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/DMLStatement.g4 +++ b/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/DMLStatement.g4 @@ -20,7 +20,7 @@ grammar DMLStatement; import BaseRule; insert - : INSERT INTO? tableName (insertValuesClause | insertSelectClause) + : INSERT INTO? tableName (insertValuesClause | insertSelectClause) returningClause? ; insertValuesClause @@ -31,8 +31,12 @@ insertSelectClause : columnNames? select ; +returningClause + : RETURNING projections + ; + update - : UPDATE tableReferences setAssignmentsClause whereClause? + : UPDATE tableReferences setAssignmentsClause whereClause? returningClause? ; assignment @@ -57,7 +61,7 @@ blobValue ; delete - : DELETE singleTableClause whereClause? + : DELETE singleTableClause whereClause? returningClause? ; singleTableClause @@ -199,4 +203,4 @@ variableList variableListClause : variableList (COMMA_ variableList)* - ; + ; \ No newline at end of file diff --git a/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/visitor/statement/type/FirebirdDMLStatementVisitor.java b/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/visitor/statement/type/FirebirdDMLStatementVisitor.java index c7c69a191b3a9..52e66721a3185 100644 --- a/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/visitor/statement/type/FirebirdDMLStatementVisitor.java +++ b/parser/sql/dialect/firebird/src/main/java/org/apache/shardingsphere/sql/parser/firebird/visitor/statement/type/FirebirdDMLStatementVisitor.java @@ -42,6 +42,7 @@ import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.ProjectionContext; import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.ProjectionsContext; import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.QualifiedShorthandContext; +import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.ReturningClauseContext; import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.SelectClauseContext; import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.SelectContext; import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.SelectSpecificationContext; @@ -55,6 +56,7 @@ import org.apache.shardingsphere.sql.parser.autogen.FirebirdStatementParser.WhereClauseContext; import org.apache.shardingsphere.sql.parser.firebird.visitor.statement.FirebirdStatementVisitor; import org.apache.shardingsphere.sql.parser.statement.core.enums.JoinType; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.ReturningSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.assignment.ColumnAssignmentSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.assignment.InsertValuesSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.assignment.SetAssignmentSegment; @@ -110,6 +112,9 @@ public ASTNode visitInsert(final InsertContext ctx) { FirebirdInsertStatement result = (FirebirdInsertStatement) visit(ctx.insertValuesClause()); result.setTable((SimpleTableSegment) visit(ctx.tableName())); result.addParameterMarkerSegments(getParameterMarkerSegments()); + if (null != ctx.returningClause()) { + result.setReturningSegment((ReturningSegment) visit(ctx.returningClause())); + } return result; } @@ -136,6 +141,11 @@ private Collection createInsertValuesSegments(final Collect return result; } + @Override + public ASTNode visitReturningClause(final ReturningClauseContext ctx) { + return new ReturningSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), (ProjectionsSegment) visit(ctx.projections())); + } + @Override public ASTNode visitUpdate(final UpdateContext ctx) { FirebirdUpdateStatement result = new FirebirdUpdateStatement(); @@ -145,6 +155,9 @@ public ASTNode visitUpdate(final UpdateContext ctx) { result.setWhere((WhereSegment) visit(ctx.whereClause())); } result.addParameterMarkerSegments(getParameterMarkerSegments()); + if (null != ctx.returningClause()) { + result.setReturningSegment((ReturningSegment) visit(ctx.returningClause())); + } return result; } @@ -194,6 +207,9 @@ public ASTNode visitDelete(final DeleteContext ctx) { result.setWhere((WhereSegment) visit(ctx.whereClause())); } result.addParameterMarkerSegments(getParameterMarkerSegments()); + if (null != ctx.returningClause()) { + result.setReturningSegment((ReturningSegment) visit(ctx.returningClause())); + } return result; } diff --git a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dml/UpdateStatement.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dml/UpdateStatement.java index 58e28a66e18f1..9fdef46156496 100644 --- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dml/UpdateStatement.java +++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dml/UpdateStatement.java @@ -19,6 +19,7 @@ import lombok.Getter; import lombok.Setter; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.ReturningSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.assignment.SetAssignmentSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.hint.OptionHintSegment; import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.order.OrderBySegment; @@ -172,4 +173,22 @@ public Optional getFrom() { */ public void setFrom(final TableSegment from) { } + + /** + * Get returning segment of update statement. + * + * @return returning segment + */ + public Optional getReturningSegment() { + return Optional.empty(); + } + + /** + * Set returning segment of update statement. + * + * @param returningSegment returning segment + */ + public void setReturningSegment(final ReturningSegment returningSegment) { + } + } diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dml/FirebirdDeleteStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dml/FirebirdDeleteStatement.java index 080f6f1b3ce16..e62175c0a4a7b 100644 --- a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dml/FirebirdDeleteStatement.java +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dml/FirebirdDeleteStatement.java @@ -17,11 +17,23 @@ package org.apache.shardingsphere.sql.parser.statement.firebird.dml; +import lombok.Setter; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.ReturningSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.DeleteStatement; import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; +import java.util.Optional; + /** * Firebird delete statement. */ +@Setter public final class FirebirdDeleteStatement extends DeleteStatement implements FirebirdStatement { + + private ReturningSegment returningSegment; + + @Override + public Optional getReturningSegment() { + return Optional.ofNullable(returningSegment); + } } diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dml/FirebirdInsertStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dml/FirebirdInsertStatement.java index 1f7e92aa36657..b899dc929081a 100644 --- a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dml/FirebirdInsertStatement.java +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dml/FirebirdInsertStatement.java @@ -17,11 +17,23 @@ package org.apache.shardingsphere.sql.parser.statement.firebird.dml; +import lombok.Setter; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.ReturningSegment; import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.InsertStatement; import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; +import java.util.Optional; + /** * Firebird insert statement. */ +@Setter public final class FirebirdInsertStatement extends InsertStatement implements FirebirdStatement { + + private ReturningSegment returningSegment; + + @Override + public Optional getReturningSegment() { + return Optional.ofNullable(returningSegment); + } } diff --git a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dml/FirebirdUpdateStatement.java b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dml/FirebirdUpdateStatement.java index 3176d5d921bde..927ac1bf5e9fb 100644 --- a/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dml/FirebirdUpdateStatement.java +++ b/parser/sql/statement/type/firebird/src/main/java/org/apache/shardingsphere/sql/parser/statement/firebird/dml/FirebirdUpdateStatement.java @@ -17,11 +17,23 @@ package org.apache.shardingsphere.sql.parser.statement.firebird.dml; +import lombok.Setter; import org.apache.shardingsphere.sql.parser.statement.core.statement.dml.UpdateStatement; +import org.apache.shardingsphere.sql.parser.statement.core.segment.dml.ReturningSegment; import org.apache.shardingsphere.sql.parser.statement.firebird.FirebirdStatement; +import java.util.Optional; + /** * Firebird update statement. */ +@Setter public final class FirebirdUpdateStatement extends UpdateStatement implements FirebirdStatement { + + private ReturningSegment returningSegment; + + @Override + public Optional getReturningSegment() { + return Optional.ofNullable(returningSegment); + } } diff --git a/test/it/parser/src/main/resources/case/dml/update.xml b/test/it/parser/src/main/resources/case/dml/update.xml index a4aded61afd85..890e3d01c740a 100644 --- a/test/it/parser/src/main/resources/case/dml/update.xml +++ b/test/it/parser/src/main/resources/case/dml/update.xml @@ -2337,4 +2337,63 @@ + + + + +
+ + + + + + + + + - + + + + + + + + + + + + + + + + + = + + + + + + + AND + + + + + + = + + + + + + + + + + + + + + +
diff --git a/test/it/parser/src/main/resources/sql/supported/dml/delete.xml b/test/it/parser/src/main/resources/sql/supported/dml/delete.xml index 0b1d83d0d78d9..db5e92fdfe281 100644 --- a/test/it/parser/src/main/resources/sql/supported/dml/delete.xml +++ b/test/it/parser/src/main/resources/sql/supported/dml/delete.xml @@ -44,5 +44,5 @@ - + diff --git a/test/it/parser/src/main/resources/sql/supported/dml/insert.xml b/test/it/parser/src/main/resources/sql/supported/dml/insert.xml index f5f8d8421f080..1ac4e963992ba 100644 --- a/test/it/parser/src/main/resources/sql/supported/dml/insert.xml +++ b/test/it/parser/src/main/resources/sql/supported/dml/insert.xml @@ -153,6 +153,6 @@ - + diff --git a/test/it/parser/src/main/resources/sql/supported/dml/update.xml b/test/it/parser/src/main/resources/sql/supported/dml/update.xml index f8277a410e5cb..c2f7a228d3596 100644 --- a/test/it/parser/src/main/resources/sql/supported/dml/update.xml +++ b/test/it/parser/src/main/resources/sql/supported/dml/update.xml @@ -68,4 +68,5 @@ + From 3faad2599ad6fbedc491af29444df1e1567d4cae Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Fri, 13 Dec 2024 23:41:22 +0800 Subject: [PATCH 21/32] Move ReadwriteSplittingQualifiedDataSourceDeletedSubscriber (#34048) --- .../ReadwriteSplittingQualifiedDataSourceDeletedEvent.java | 2 +- ...writeSplittingQualifiedDataSourceDeletedSubscriber.java | 2 +- ...littingQualifiedDataSourceDeletedSubscriberFactory.java | 2 +- .../ReadwriteSplittingStaticDataSourceRuleAttribute.java | 7 +++---- ...sphere.mode.event.deliver.DeliverEventSubscriberFactory | 2 +- ...eSplittingQualifiedDataSourceDeletedSubscriberTest.java | 2 +- ...eadwriteSplittingStaticDataSourceRuleAttributeTest.java | 2 +- 7 files changed, 9 insertions(+), 10 deletions(-) rename features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/{subscriber => cluster}/ReadwriteSplittingQualifiedDataSourceDeletedEvent.java (95%) rename features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/{subscriber => cluster}/ReadwriteSplittingQualifiedDataSourceDeletedSubscriber.java (96%) rename features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/{subscriber => cluster}/ReadwriteSplittingQualifiedDataSourceDeletedSubscriberFactory.java (95%) rename features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/{subscriber => cluster}/ReadwriteSplittingQualifiedDataSourceDeletedSubscriberTest.java (96%) diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingQualifiedDataSourceDeletedEvent.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedEvent.java similarity index 95% rename from features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingQualifiedDataSourceDeletedEvent.java rename to features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedEvent.java index 391a6830fb4d3..9d8b26d6bd394 100644 --- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingQualifiedDataSourceDeletedEvent.java +++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedEvent.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.readwritesplitting.subscriber; +package org.apache.shardingsphere.readwritesplitting.cluster; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingQualifiedDataSourceDeletedSubscriber.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedSubscriber.java similarity index 96% rename from features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingQualifiedDataSourceDeletedSubscriber.java rename to features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedSubscriber.java index 6add89d0c9c4a..e730c4e5f6e16 100644 --- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingQualifiedDataSourceDeletedSubscriber.java +++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedSubscriber.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.readwritesplitting.subscriber; +package org.apache.shardingsphere.readwritesplitting.cluster; import com.google.common.eventbus.Subscribe; import lombok.RequiredArgsConstructor; diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingQualifiedDataSourceDeletedSubscriberFactory.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedSubscriberFactory.java similarity index 95% rename from features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingQualifiedDataSourceDeletedSubscriberFactory.java rename to features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedSubscriberFactory.java index 0f9f4c3b3da3f..f2de2fff287fc 100644 --- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingQualifiedDataSourceDeletedSubscriberFactory.java +++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedSubscriberFactory.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.readwritesplitting.subscriber; +package org.apache.shardingsphere.readwritesplitting.cluster; import org.apache.shardingsphere.infra.util.eventbus.EventBusContext; import org.apache.shardingsphere.infra.util.eventbus.EventSubscriber; diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttribute.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttribute.java index f010866034869..6667067e160b2 100644 --- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttribute.java +++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttribute.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource; import org.apache.shardingsphere.infra.rule.attribute.datasource.StaticDataSourceRuleAttribute; import org.apache.shardingsphere.infra.state.datasource.DataSourceState; -import org.apache.shardingsphere.readwritesplitting.subscriber.ReadwriteSplittingQualifiedDataSourceDeletedEvent; +import org.apache.shardingsphere.readwritesplitting.cluster.ReadwriteSplittingQualifiedDataSourceDeletedEvent; import org.apache.shardingsphere.readwritesplitting.exception.logic.ReadwriteSplittingDataSourceRuleNotFoundException; import org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingDataSourceGroupRule; @@ -68,8 +68,7 @@ public void cleanStorageNodeDataSources() { } private void deleteStorageNodeDataSources(final ReadwriteSplittingDataSourceGroupRule rule) { - rule.getReadwriteSplittingGroup().getReadDataSources() - .forEach(each -> computeNodeInstanceContext.getEventBusContext() - .post(new ReadwriteSplittingQualifiedDataSourceDeletedEvent(new QualifiedDataSource(databaseName, rule.getName(), each)))); + rule.getReadwriteSplittingGroup().getReadDataSources().forEach(each -> computeNodeInstanceContext.getEventBusContext() + .post(new ReadwriteSplittingQualifiedDataSourceDeletedEvent(new QualifiedDataSource(databaseName, rule.getName(), each)))); } } diff --git a/features/readwrite-splitting/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.event.deliver.DeliverEventSubscriberFactory b/features/readwrite-splitting/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.event.deliver.DeliverEventSubscriberFactory index a40d43dc35746..3b42a3fe23eb9 100644 --- a/features/readwrite-splitting/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.event.deliver.DeliverEventSubscriberFactory +++ b/features/readwrite-splitting/core/src/main/resources/META-INF/services/org.apache.shardingsphere.mode.event.deliver.DeliverEventSubscriberFactory @@ -15,4 +15,4 @@ # limitations under the License. # -org.apache.shardingsphere.readwritesplitting.subscriber.ReadwriteSplittingQualifiedDataSourceDeletedSubscriberFactory +org.apache.shardingsphere.readwritesplitting.cluster.ReadwriteSplittingQualifiedDataSourceDeletedSubscriberFactory diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingQualifiedDataSourceDeletedSubscriberTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedSubscriberTest.java similarity index 96% rename from features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingQualifiedDataSourceDeletedSubscriberTest.java rename to features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedSubscriberTest.java index c18761ab6da0f..66b2bc9a67c67 100644 --- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/subscriber/ReadwriteSplittingQualifiedDataSourceDeletedSubscriberTest.java +++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedSubscriberTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.readwritesplitting.subscriber; +package org.apache.shardingsphere.readwritesplitting.cluster; import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource; import org.apache.shardingsphere.mode.spi.PersistRepository; diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttributeTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttributeTest.java index 86946d7de5f60..23fa810329a8b 100644 --- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttributeTest.java +++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttributeTest.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext; import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource; import org.apache.shardingsphere.infra.state.datasource.DataSourceState; -import org.apache.shardingsphere.readwritesplitting.subscriber.ReadwriteSplittingQualifiedDataSourceDeletedEvent; +import org.apache.shardingsphere.readwritesplitting.cluster.ReadwriteSplittingQualifiedDataSourceDeletedEvent; import org.apache.shardingsphere.readwritesplitting.exception.logic.ReadwriteSplittingDataSourceRuleNotFoundException; import org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingDataSourceGroupRule; import org.junit.jupiter.api.Test; From 69126992856b47d0e493703fbc81634d0b4a767b Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Fri, 13 Dec 2024 23:48:15 +0800 Subject: [PATCH 22/32] Code format for #34047 (#34049) --- .../firebird/src/main/antlr4/imports/firebird/DMLStatement.g4 | 2 +- .../parser/statement/core/statement/dml/UpdateStatement.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/DMLStatement.g4 b/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/DMLStatement.g4 index 91ef07da8a494..a5b35500311e4 100644 --- a/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/DMLStatement.g4 +++ b/parser/sql/dialect/firebird/src/main/antlr4/imports/firebird/DMLStatement.g4 @@ -203,4 +203,4 @@ variableList variableListClause : variableList (COMMA_ variableList)* - ; \ No newline at end of file + ; diff --git a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dml/UpdateStatement.java b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dml/UpdateStatement.java index 9fdef46156496..c8c708c29ddbd 100644 --- a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dml/UpdateStatement.java +++ b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dml/UpdateStatement.java @@ -190,5 +190,4 @@ public Optional getReturningSegment() { */ public void setReturningSegment(final ReturningSegment returningSegment) { } - } From 5f48cc499d1a11e64dbba3d091a6c12ea5de9467 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Sat, 14 Dec 2024 00:38:49 +0800 Subject: [PATCH 23/32] Move QualifiedDataSourceDeletedEvent to mode module (#34050) --- ...dwriteSplittingQualifiedDataSourceDeletedSubscriber.java | 3 ++- .../ReadwriteSplittingStaticDataSourceRuleAttribute.java | 4 ++-- ...teSplittingQualifiedDataSourceDeletedSubscriberTest.java | 3 ++- ...ReadwriteSplittingStaticDataSourceRuleAttributeTest.java | 6 +++--- .../event/deliver/pojo/QualifiedDataSourceDeletedEvent.java | 6 +++--- 5 files changed, 12 insertions(+), 10 deletions(-) rename features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedEvent.java => mode/api/src/main/java/org/apache/shardingsphere/mode/event/deliver/pojo/QualifiedDataSourceDeletedEvent.java (83%) diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedSubscriber.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedSubscriber.java index e730c4e5f6e16..73d5936091ada 100644 --- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedSubscriber.java +++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedSubscriber.java @@ -21,6 +21,7 @@ import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.util.eventbus.EventSubscriber; import org.apache.shardingsphere.metadata.persist.node.QualifiedDataSourceNode; +import org.apache.shardingsphere.mode.event.deliver.pojo.QualifiedDataSourceDeletedEvent; import org.apache.shardingsphere.mode.spi.PersistRepository; /** @@ -37,7 +38,7 @@ public final class ReadwriteSplittingQualifiedDataSourceDeletedSubscriber implem * @param event qualified data source deleted event */ @Subscribe - public void delete(final ReadwriteSplittingQualifiedDataSourceDeletedEvent event) { + public void delete(final QualifiedDataSourceDeletedEvent event) { repository.delete(QualifiedDataSourceNode.getQualifiedDataSourceNodePath(event.getQualifiedDataSource())); } } diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttribute.java b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttribute.java index 6667067e160b2..c6254d814b700 100644 --- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttribute.java +++ b/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttribute.java @@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource; import org.apache.shardingsphere.infra.rule.attribute.datasource.StaticDataSourceRuleAttribute; import org.apache.shardingsphere.infra.state.datasource.DataSourceState; -import org.apache.shardingsphere.readwritesplitting.cluster.ReadwriteSplittingQualifiedDataSourceDeletedEvent; +import org.apache.shardingsphere.mode.event.deliver.pojo.QualifiedDataSourceDeletedEvent; import org.apache.shardingsphere.readwritesplitting.exception.logic.ReadwriteSplittingDataSourceRuleNotFoundException; import org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingDataSourceGroupRule; @@ -69,6 +69,6 @@ public void cleanStorageNodeDataSources() { private void deleteStorageNodeDataSources(final ReadwriteSplittingDataSourceGroupRule rule) { rule.getReadwriteSplittingGroup().getReadDataSources().forEach(each -> computeNodeInstanceContext.getEventBusContext() - .post(new ReadwriteSplittingQualifiedDataSourceDeletedEvent(new QualifiedDataSource(databaseName, rule.getName(), each)))); + .post(new QualifiedDataSourceDeletedEvent(new QualifiedDataSource(databaseName, rule.getName(), each)))); } } diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedSubscriberTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedSubscriberTest.java index 66b2bc9a67c67..60cb412bd8ced 100644 --- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedSubscriberTest.java +++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedSubscriberTest.java @@ -18,6 +18,7 @@ package org.apache.shardingsphere.readwritesplitting.cluster; import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource; +import org.apache.shardingsphere.mode.event.deliver.pojo.QualifiedDataSourceDeletedEvent; import org.apache.shardingsphere.mode.spi.PersistRepository; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -42,7 +43,7 @@ void setUp() { @Test void assertDeleteStorageNodeDataSourceDataSourceState() { - subscriber.delete(new ReadwriteSplittingQualifiedDataSourceDeletedEvent(new QualifiedDataSource("foo_db", "foo_group", "foo_ds"))); + subscriber.delete(new QualifiedDataSourceDeletedEvent(new QualifiedDataSource("foo_db", "foo_group", "foo_ds"))); verify(repository).delete("/nodes/qualified_data_sources/foo_db.foo_group.foo_ds"); } } diff --git a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttributeTest.java b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttributeTest.java index 23fa810329a8b..96f744e6b1c12 100644 --- a/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttributeTest.java +++ b/features/readwrite-splitting/core/src/test/java/org/apache/shardingsphere/readwritesplitting/rule/attribute/ReadwriteSplittingStaticDataSourceRuleAttributeTest.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.instance.ComputeNodeInstanceContext; import org.apache.shardingsphere.infra.metadata.database.schema.QualifiedDataSource; import org.apache.shardingsphere.infra.state.datasource.DataSourceState; -import org.apache.shardingsphere.readwritesplitting.cluster.ReadwriteSplittingQualifiedDataSourceDeletedEvent; +import org.apache.shardingsphere.mode.event.deliver.pojo.QualifiedDataSourceDeletedEvent; import org.apache.shardingsphere.readwritesplitting.exception.logic.ReadwriteSplittingDataSourceRuleNotFoundException; import org.apache.shardingsphere.readwritesplitting.rule.ReadwriteSplittingDataSourceGroupRule; import org.junit.jupiter.api.Test; @@ -75,7 +75,7 @@ void assertCleanStorageNodeDataSource() { ReadwriteSplittingStaticDataSourceRuleAttribute ruleAttribute = new ReadwriteSplittingStaticDataSourceRuleAttribute( "foo_db", Collections.singletonMap("foo_group", dataSourceGroupRule), computeNodeInstanceContext); ruleAttribute.cleanStorageNodeDataSource("foo_group"); - verify(computeNodeInstanceContext.getEventBusContext()).post(deepEq(new ReadwriteSplittingQualifiedDataSourceDeletedEvent(new QualifiedDataSource("foo_db.foo_group.read_ds")))); + verify(computeNodeInstanceContext.getEventBusContext()).post(deepEq(new QualifiedDataSourceDeletedEvent(new QualifiedDataSource("foo_db.foo_group.read_ds")))); } @Test @@ -87,6 +87,6 @@ void assertCleanStorageNodeDataSources() { ReadwriteSplittingStaticDataSourceRuleAttribute ruleAttribute = new ReadwriteSplittingStaticDataSourceRuleAttribute( "foo_db", Collections.singletonMap("foo_group", dataSourceGroupRule), computeNodeInstanceContext); ruleAttribute.cleanStorageNodeDataSources(); - verify(computeNodeInstanceContext.getEventBusContext()).post(deepEq(new ReadwriteSplittingQualifiedDataSourceDeletedEvent(new QualifiedDataSource("foo_db.foo_group.read_ds")))); + verify(computeNodeInstanceContext.getEventBusContext()).post(deepEq(new QualifiedDataSourceDeletedEvent(new QualifiedDataSource("foo_db.foo_group.read_ds")))); } } diff --git a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedEvent.java b/mode/api/src/main/java/org/apache/shardingsphere/mode/event/deliver/pojo/QualifiedDataSourceDeletedEvent.java similarity index 83% rename from features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedEvent.java rename to mode/api/src/main/java/org/apache/shardingsphere/mode/event/deliver/pojo/QualifiedDataSourceDeletedEvent.java index 9d8b26d6bd394..bab5b1395c20c 100644 --- a/features/readwrite-splitting/core/src/main/java/org/apache/shardingsphere/readwritesplitting/cluster/ReadwriteSplittingQualifiedDataSourceDeletedEvent.java +++ b/mode/api/src/main/java/org/apache/shardingsphere/mode/event/deliver/pojo/QualifiedDataSourceDeletedEvent.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.shardingsphere.readwritesplitting.cluster; +package org.apache.shardingsphere.mode.event.deliver.pojo; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -23,11 +23,11 @@ import org.apache.shardingsphere.infra.util.event.DeliverEvent; /** - * Readwrite-splitting qualified data source deleted event. + * Qualified data source deleted event. */ @RequiredArgsConstructor @Getter -public final class ReadwriteSplittingQualifiedDataSourceDeletedEvent implements DeliverEvent { +public final class QualifiedDataSourceDeletedEvent implements DeliverEvent { private final QualifiedDataSource qualifiedDataSource; } From 45e3c9c9d038084a837e9cf7a76ce1f9e9817f03 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Sat, 14 Dec 2024 13:58:40 +0800 Subject: [PATCH 24/32] Rename module from pipeline-scenario-consistencycheck to pipeline-scenario-consistency-check (#34051) --- kernel/data-pipeline/distsql/handler/pom.xml | 2 +- .../scenario/{consistencycheck => consistency-check}/pom.xml | 2 +- .../pipeline/scenario/consistencycheck/ConsistencyCheckJob.java | 0 .../consistencycheck/ConsistencyCheckJobExecutorCallback.java | 0 .../scenario/consistencycheck/ConsistencyCheckJobId.java | 0 .../scenario/consistencycheck/ConsistencyCheckJobType.java | 0 .../scenario/consistencycheck/api/ConsistencyCheckJobAPI.java | 0 .../api/CreateConsistencyCheckJobParameter.java | 0 .../config/ConsistencyCheckJobConfiguration.java | 0 .../yaml/config/YamlConsistencyCheckJobConfiguration.java | 0 .../swapper/YamlConsistencyCheckJobConfigurationSwapper.java | 0 .../context/ConsistencyCheckJobItemContext.java | 0 .../context/ConsistencyCheckProcessContext.java | 0 .../ConsistencyCheckJobConfigurationChangedProcessor.java | 0 .../consistencycheck/task/ConsistencyCheckTasksRunner.java | 0 .../consistencycheck/util/ConsistencyCheckSequence.java | 0 ...e.shardingsphere.data.pipeline.core.job.type.PipelineJobType | 0 ...adata.node.config.processor.JobConfigurationChangedProcessor | 0 .../context/ConsistencyCheckJobItemContextTest.java | 0 .../consistencycheck/util/ConsistencyCheckSequenceTest.java | 0 kernel/data-pipeline/scenario/pom.xml | 2 +- proxy/backend/core/pom.xml | 2 +- test/it/pipeline/pom.xml | 2 +- 23 files changed, 5 insertions(+), 5 deletions(-) rename kernel/data-pipeline/scenario/{consistencycheck => consistency-check}/pom.xml (98%) rename kernel/data-pipeline/scenario/{consistencycheck => consistency-check}/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/ConsistencyCheckJob.java (100%) rename kernel/data-pipeline/scenario/{consistencycheck => consistency-check}/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/ConsistencyCheckJobExecutorCallback.java (100%) rename kernel/data-pipeline/scenario/{consistencycheck => consistency-check}/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/ConsistencyCheckJobId.java (100%) rename kernel/data-pipeline/scenario/{consistencycheck => consistency-check}/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/ConsistencyCheckJobType.java (100%) rename kernel/data-pipeline/scenario/{consistencycheck => consistency-check}/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/api/ConsistencyCheckJobAPI.java (100%) rename kernel/data-pipeline/scenario/{consistencycheck => consistency-check}/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/api/CreateConsistencyCheckJobParameter.java (100%) rename kernel/data-pipeline/scenario/{consistencycheck => consistency-check}/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/config/ConsistencyCheckJobConfiguration.java (100%) rename kernel/data-pipeline/scenario/{consistencycheck => consistency-check}/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/config/yaml/config/YamlConsistencyCheckJobConfiguration.java (100%) rename kernel/data-pipeline/scenario/{consistencycheck => consistency-check}/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/config/yaml/swapper/YamlConsistencyCheckJobConfigurationSwapper.java (100%) rename kernel/data-pipeline/scenario/{consistencycheck => consistency-check}/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/context/ConsistencyCheckJobItemContext.java (100%) rename kernel/data-pipeline/scenario/{consistencycheck => consistency-check}/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/context/ConsistencyCheckProcessContext.java (100%) rename kernel/data-pipeline/scenario/{consistencycheck => consistency-check}/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/metadata/processor/ConsistencyCheckJobConfigurationChangedProcessor.java (100%) rename kernel/data-pipeline/scenario/{consistencycheck => consistency-check}/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/task/ConsistencyCheckTasksRunner.java (100%) rename kernel/data-pipeline/scenario/{consistencycheck => consistency-check}/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/util/ConsistencyCheckSequence.java (100%) rename kernel/data-pipeline/scenario/{consistencycheck => consistency-check}/src/main/resources/META-INF/services/org.apache.shardingsphere.data.pipeline.core.job.type.PipelineJobType (100%) rename kernel/data-pipeline/scenario/{consistencycheck => consistency-check}/src/main/resources/META-INF/services/org.apache.shardingsphere.data.pipeline.core.metadata.node.config.processor.JobConfigurationChangedProcessor (100%) rename kernel/data-pipeline/scenario/{consistencycheck => consistency-check}/src/test/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/context/ConsistencyCheckJobItemContextTest.java (100%) rename kernel/data-pipeline/scenario/{consistencycheck => consistency-check}/src/test/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/util/ConsistencyCheckSequenceTest.java (100%) diff --git a/kernel/data-pipeline/distsql/handler/pom.xml b/kernel/data-pipeline/distsql/handler/pom.xml index b8b52ffcb3fd4..7da4aa05b2e74 100644 --- a/kernel/data-pipeline/distsql/handler/pom.xml +++ b/kernel/data-pipeline/distsql/handler/pom.xml @@ -34,7 +34,7 @@ org.apache.shardingsphere - shardingsphere-data-pipeline-scenario-consistencycheck + shardingsphere-data-pipeline-scenario-consistency-check ${project.version} diff --git a/kernel/data-pipeline/scenario/consistencycheck/pom.xml b/kernel/data-pipeline/scenario/consistency-check/pom.xml similarity index 98% rename from kernel/data-pipeline/scenario/consistencycheck/pom.xml rename to kernel/data-pipeline/scenario/consistency-check/pom.xml index b37836af58a1d..011cf537ae026 100644 --- a/kernel/data-pipeline/scenario/consistencycheck/pom.xml +++ b/kernel/data-pipeline/scenario/consistency-check/pom.xml @@ -23,7 +23,7 @@ shardingsphere-data-pipeline-scenario 5.5.2-SNAPSHOT - shardingsphere-data-pipeline-scenario-consistencycheck + shardingsphere-data-pipeline-scenario-consistency-check ${project.artifactId} diff --git a/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/ConsistencyCheckJob.java b/kernel/data-pipeline/scenario/consistency-check/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/ConsistencyCheckJob.java similarity index 100% rename from kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/ConsistencyCheckJob.java rename to kernel/data-pipeline/scenario/consistency-check/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/ConsistencyCheckJob.java diff --git a/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/ConsistencyCheckJobExecutorCallback.java b/kernel/data-pipeline/scenario/consistency-check/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/ConsistencyCheckJobExecutorCallback.java similarity index 100% rename from kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/ConsistencyCheckJobExecutorCallback.java rename to kernel/data-pipeline/scenario/consistency-check/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/ConsistencyCheckJobExecutorCallback.java diff --git a/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/ConsistencyCheckJobId.java b/kernel/data-pipeline/scenario/consistency-check/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/ConsistencyCheckJobId.java similarity index 100% rename from kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/ConsistencyCheckJobId.java rename to kernel/data-pipeline/scenario/consistency-check/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/ConsistencyCheckJobId.java diff --git a/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/ConsistencyCheckJobType.java b/kernel/data-pipeline/scenario/consistency-check/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/ConsistencyCheckJobType.java similarity index 100% rename from kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/ConsistencyCheckJobType.java rename to kernel/data-pipeline/scenario/consistency-check/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/ConsistencyCheckJobType.java diff --git a/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/api/ConsistencyCheckJobAPI.java b/kernel/data-pipeline/scenario/consistency-check/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/api/ConsistencyCheckJobAPI.java similarity index 100% rename from kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/api/ConsistencyCheckJobAPI.java rename to kernel/data-pipeline/scenario/consistency-check/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/api/ConsistencyCheckJobAPI.java diff --git a/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/api/CreateConsistencyCheckJobParameter.java b/kernel/data-pipeline/scenario/consistency-check/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/api/CreateConsistencyCheckJobParameter.java similarity index 100% rename from kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/api/CreateConsistencyCheckJobParameter.java rename to kernel/data-pipeline/scenario/consistency-check/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/api/CreateConsistencyCheckJobParameter.java diff --git a/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/config/ConsistencyCheckJobConfiguration.java b/kernel/data-pipeline/scenario/consistency-check/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/config/ConsistencyCheckJobConfiguration.java similarity index 100% rename from kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/config/ConsistencyCheckJobConfiguration.java rename to kernel/data-pipeline/scenario/consistency-check/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/config/ConsistencyCheckJobConfiguration.java diff --git a/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/config/yaml/config/YamlConsistencyCheckJobConfiguration.java b/kernel/data-pipeline/scenario/consistency-check/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/config/yaml/config/YamlConsistencyCheckJobConfiguration.java similarity index 100% rename from kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/config/yaml/config/YamlConsistencyCheckJobConfiguration.java rename to kernel/data-pipeline/scenario/consistency-check/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/config/yaml/config/YamlConsistencyCheckJobConfiguration.java diff --git a/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/config/yaml/swapper/YamlConsistencyCheckJobConfigurationSwapper.java b/kernel/data-pipeline/scenario/consistency-check/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/config/yaml/swapper/YamlConsistencyCheckJobConfigurationSwapper.java similarity index 100% rename from kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/config/yaml/swapper/YamlConsistencyCheckJobConfigurationSwapper.java rename to kernel/data-pipeline/scenario/consistency-check/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/config/yaml/swapper/YamlConsistencyCheckJobConfigurationSwapper.java diff --git a/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/context/ConsistencyCheckJobItemContext.java b/kernel/data-pipeline/scenario/consistency-check/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/context/ConsistencyCheckJobItemContext.java similarity index 100% rename from kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/context/ConsistencyCheckJobItemContext.java rename to kernel/data-pipeline/scenario/consistency-check/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/context/ConsistencyCheckJobItemContext.java diff --git a/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/context/ConsistencyCheckProcessContext.java b/kernel/data-pipeline/scenario/consistency-check/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/context/ConsistencyCheckProcessContext.java similarity index 100% rename from kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/context/ConsistencyCheckProcessContext.java rename to kernel/data-pipeline/scenario/consistency-check/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/context/ConsistencyCheckProcessContext.java diff --git a/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/metadata/processor/ConsistencyCheckJobConfigurationChangedProcessor.java b/kernel/data-pipeline/scenario/consistency-check/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/metadata/processor/ConsistencyCheckJobConfigurationChangedProcessor.java similarity index 100% rename from kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/metadata/processor/ConsistencyCheckJobConfigurationChangedProcessor.java rename to kernel/data-pipeline/scenario/consistency-check/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/metadata/processor/ConsistencyCheckJobConfigurationChangedProcessor.java diff --git a/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/task/ConsistencyCheckTasksRunner.java b/kernel/data-pipeline/scenario/consistency-check/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/task/ConsistencyCheckTasksRunner.java similarity index 100% rename from kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/task/ConsistencyCheckTasksRunner.java rename to kernel/data-pipeline/scenario/consistency-check/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/task/ConsistencyCheckTasksRunner.java diff --git a/kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/util/ConsistencyCheckSequence.java b/kernel/data-pipeline/scenario/consistency-check/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/util/ConsistencyCheckSequence.java similarity index 100% rename from kernel/data-pipeline/scenario/consistencycheck/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/util/ConsistencyCheckSequence.java rename to kernel/data-pipeline/scenario/consistency-check/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/util/ConsistencyCheckSequence.java diff --git a/kernel/data-pipeline/scenario/consistencycheck/src/main/resources/META-INF/services/org.apache.shardingsphere.data.pipeline.core.job.type.PipelineJobType b/kernel/data-pipeline/scenario/consistency-check/src/main/resources/META-INF/services/org.apache.shardingsphere.data.pipeline.core.job.type.PipelineJobType similarity index 100% rename from kernel/data-pipeline/scenario/consistencycheck/src/main/resources/META-INF/services/org.apache.shardingsphere.data.pipeline.core.job.type.PipelineJobType rename to kernel/data-pipeline/scenario/consistency-check/src/main/resources/META-INF/services/org.apache.shardingsphere.data.pipeline.core.job.type.PipelineJobType diff --git a/kernel/data-pipeline/scenario/consistencycheck/src/main/resources/META-INF/services/org.apache.shardingsphere.data.pipeline.core.metadata.node.config.processor.JobConfigurationChangedProcessor b/kernel/data-pipeline/scenario/consistency-check/src/main/resources/META-INF/services/org.apache.shardingsphere.data.pipeline.core.metadata.node.config.processor.JobConfigurationChangedProcessor similarity index 100% rename from kernel/data-pipeline/scenario/consistencycheck/src/main/resources/META-INF/services/org.apache.shardingsphere.data.pipeline.core.metadata.node.config.processor.JobConfigurationChangedProcessor rename to kernel/data-pipeline/scenario/consistency-check/src/main/resources/META-INF/services/org.apache.shardingsphere.data.pipeline.core.metadata.node.config.processor.JobConfigurationChangedProcessor diff --git a/kernel/data-pipeline/scenario/consistencycheck/src/test/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/context/ConsistencyCheckJobItemContextTest.java b/kernel/data-pipeline/scenario/consistency-check/src/test/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/context/ConsistencyCheckJobItemContextTest.java similarity index 100% rename from kernel/data-pipeline/scenario/consistencycheck/src/test/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/context/ConsistencyCheckJobItemContextTest.java rename to kernel/data-pipeline/scenario/consistency-check/src/test/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/context/ConsistencyCheckJobItemContextTest.java diff --git a/kernel/data-pipeline/scenario/consistencycheck/src/test/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/util/ConsistencyCheckSequenceTest.java b/kernel/data-pipeline/scenario/consistency-check/src/test/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/util/ConsistencyCheckSequenceTest.java similarity index 100% rename from kernel/data-pipeline/scenario/consistencycheck/src/test/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/util/ConsistencyCheckSequenceTest.java rename to kernel/data-pipeline/scenario/consistency-check/src/test/java/org/apache/shardingsphere/data/pipeline/scenario/consistencycheck/util/ConsistencyCheckSequenceTest.java diff --git a/kernel/data-pipeline/scenario/pom.xml b/kernel/data-pipeline/scenario/pom.xml index 21b245cf3c830..497a3a891aa29 100644 --- a/kernel/data-pipeline/scenario/pom.xml +++ b/kernel/data-pipeline/scenario/pom.xml @@ -29,7 +29,7 @@ migration - consistencycheck + consistency-check cdc diff --git a/proxy/backend/core/pom.xml b/proxy/backend/core/pom.xml index 6d5fa8ce23454..338784bbf393d 100644 --- a/proxy/backend/core/pom.xml +++ b/proxy/backend/core/pom.xml @@ -184,7 +184,7 @@ org.apache.shardingsphere - shardingsphere-data-pipeline-scenario-consistencycheck + shardingsphere-data-pipeline-scenario-consistency-check ${project.version} diff --git a/test/it/pipeline/pom.xml b/test/it/pipeline/pom.xml index 742ad7e7dfa64..a46425bb3ea0c 100644 --- a/test/it/pipeline/pom.xml +++ b/test/it/pipeline/pom.xml @@ -49,7 +49,7 @@ org.apache.shardingsphere - shardingsphere-data-pipeline-scenario-consistencycheck + shardingsphere-data-pipeline-scenario-consistency-check ${project.version} From fe4210f47cbbe1311588d4d866cd1dc1941ec1a5 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Sat, 14 Dec 2024 17:24:05 +0800 Subject: [PATCH 25/32] Refactor DatabaseMetaDataChangedListener (#34053) --- .../type/DatabaseMetaDataChangedListener.java | 37 ++++++++----------- .../type/GlobalMetaDataChangedListener.java | 6 +-- ...andaloneMetaDataManagerPersistService.java | 4 +- 3 files changed, 21 insertions(+), 26 deletions(-) diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListener.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListener.java index f17735beb28c7..2e33d83316161 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListener.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListener.java @@ -17,7 +17,6 @@ package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener.type; -import com.google.common.base.Preconditions; import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.util.eventbus.EventBusContext; import org.apache.shardingsphere.metadata.persist.node.DatabaseMetaDataNode; @@ -52,7 +51,7 @@ public final class DatabaseMetaDataChangedListener implements DataChangedEventLi private final EventBusContext eventBusContext; - private final RuleConfigurationEventBuilder builder = new RuleConfigurationEventBuilder(); + private final RuleConfigurationEventBuilder eventBuilder = new RuleConfigurationEventBuilder(); @Override public void onChange(final DataChangedEvent event) { @@ -70,16 +69,16 @@ private Optional createDispatchEvent(final DataChangedEvent event return createSchemaChangedEvent(databaseName.get(), schemaName.get(), event); } schemaName = DatabaseMetaDataNode.getSchemaNameByTableNode(key); - if (schemaName.isPresent() && tableMetaDataChanged(event.getKey())) { + if (schemaName.isPresent() && isTableMetaDataChanged(event.getKey())) { return createTableChangedEvent(databaseName.get(), schemaName.get(), event); } - if (schemaName.isPresent() && viewMetaDataChanged(event.getKey())) { + if (schemaName.isPresent() && isViewMetaDataChanged(event.getKey())) { return createViewChangedEvent(databaseName.get(), schemaName.get(), event); } if (DataSourceMetaDataNode.isDataSourcesNode(key)) { - return createDataSourceEvent(databaseName.get(), event); + return createDataSourceChangedEvent(databaseName.get(), event); } - return builder.build(databaseName.get(), event); + return eventBuilder.build(databaseName.get(), event); } private Optional createSchemaChangedEvent(final String databaseName, final String schemaName, final DataChangedEvent event) { @@ -94,43 +93,39 @@ private Optional createSchemaChangedEvent(final String databaseNa } } - private boolean tableMetaDataChanged(final String key) { + private boolean isTableMetaDataChanged(final String key) { return TableMetaDataNode.isTableActiveVersionNode(key) || TableMetaDataNode.isTableNode(key); } private Optional createTableChangedEvent(final String databaseName, final String schemaName, final DataChangedEvent event) { if ((Type.ADDED == event.getType() || Type.UPDATED == event.getType()) && TableMetaDataNode.isTableActiveVersionNode(event.getKey())) { - Optional tableName = TableMetaDataNode.getTableNameByActiveVersionNode(event.getKey()); - Preconditions.checkState(tableName.isPresent(), "Not found table name."); - return Optional.of(new CreateOrAlterTableEvent(databaseName, schemaName, tableName.get(), event.getKey(), event.getValue())); + String tableName = TableMetaDataNode.getTableNameByActiveVersionNode(event.getKey()).orElseThrow(() -> new IllegalStateException("Table name not found.")); + return Optional.of(new CreateOrAlterTableEvent(databaseName, schemaName, tableName, event.getKey(), event.getValue())); } if (Type.DELETED == event.getType() && TableMetaDataNode.isTableNode(event.getKey())) { - Optional tableName = TableMetaDataNode.getTableName(event.getKey()); - Preconditions.checkState(tableName.isPresent(), "Not found table name."); - return Optional.of(new DropTableEvent(databaseName, schemaName, tableName.get())); + String tableName = TableMetaDataNode.getTableName(event.getKey()).orElseThrow(() -> new IllegalStateException("Table name not found.")); + return Optional.of(new DropTableEvent(databaseName, schemaName, tableName)); } return Optional.empty(); } - private boolean viewMetaDataChanged(final String key) { + private boolean isViewMetaDataChanged(final String key) { return ViewMetaDataNode.isViewActiveVersionNode(key) || ViewMetaDataNode.isViewNode(key); } private Optional createViewChangedEvent(final String databaseName, final String schemaName, final DataChangedEvent event) { if ((Type.ADDED == event.getType() || Type.UPDATED == event.getType()) && ViewMetaDataNode.isViewActiveVersionNode(event.getKey())) { - Optional viewName = ViewMetaDataNode.getViewNameByActiveVersionNode(event.getKey()); - Preconditions.checkState(viewName.isPresent(), "Not found view name."); - return Optional.of(new CreateOrAlterViewEvent(databaseName, schemaName, viewName.get(), event.getKey(), event.getValue())); + String viewName = ViewMetaDataNode.getViewNameByActiveVersionNode(event.getKey()).orElseThrow(() -> new IllegalStateException("View name not found.")); + return Optional.of(new CreateOrAlterViewEvent(databaseName, schemaName, viewName, event.getKey(), event.getValue())); } if (Type.DELETED == event.getType() && ViewMetaDataNode.isViewNode(event.getKey())) { - Optional viewName = ViewMetaDataNode.getViewName(event.getKey()); - Preconditions.checkState(viewName.isPresent(), "Not found view name."); - return Optional.of(new DropViewEvent(databaseName, schemaName, viewName.get(), event.getKey(), event.getValue())); + String viewName = ViewMetaDataNode.getViewName(event.getKey()).orElseThrow(() -> new IllegalStateException("View name not found.")); + return Optional.of(new DropViewEvent(databaseName, schemaName, viewName, event.getKey(), event.getValue())); } return Optional.empty(); } - private Optional createDataSourceEvent(final String databaseName, final DataChangedEvent event) { + private Optional createDataSourceChangedEvent(final String databaseName, final DataChangedEvent event) { if (DataSourceMetaDataNode.isDataSourceUnitActiveVersionNode(event.getKey()) || DataSourceMetaDataNode.isDataSourceUnitNode(event.getKey())) { return createStorageUnitChangedEvent(databaseName, event); } diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/GlobalMetaDataChangedListener.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/GlobalMetaDataChangedListener.java index cea2df2bbe04b..cbdc96d6a0db7 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/GlobalMetaDataChangedListener.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/GlobalMetaDataChangedListener.java @@ -31,12 +31,12 @@ public final class GlobalMetaDataChangedListener implements DataChangedEventList private final EventBusContext eventBusContext; - private final DispatchEventBuilder builder; + private final DispatchEventBuilder eventBuilder; @Override public void onChange(final DataChangedEvent event) { - if (builder.getSubscribedTypes().contains(event.getType())) { - builder.build(event).ifPresent(eventBusContext::post); + if (eventBuilder.getSubscribedTypes().contains(event.getType())) { + eventBuilder.build(event).ifPresent(eventBusContext::post); } } } diff --git a/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneMetaDataManagerPersistService.java b/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneMetaDataManagerPersistService.java index 264648a1035cf..5e5482666b850 100644 --- a/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneMetaDataManagerPersistService.java +++ b/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneMetaDataManagerPersistService.java @@ -64,7 +64,7 @@ */ public final class StandaloneMetaDataManagerPersistService implements MetaDataManagerPersistService { - private final RuleConfigurationEventBuilder ruleConfigurationEventBuilder = new RuleConfigurationEventBuilder(); + private final RuleConfigurationEventBuilder ruleConfigEventBuilder = new RuleConfigurationEventBuilder(); private final MetaDataPersistService metaDataPersistService; @@ -302,7 +302,7 @@ public void alterRuleConfiguration(final String databaseName, final RuleConfigur } private Optional buildAlterRuleItemEvent(final String databaseName, final MetaDataVersion metaDataVersion, final Type type) { - return ruleConfigurationEventBuilder.build(databaseName, new DataChangedEvent(metaDataVersion.getActiveVersionNodePath(), metaDataVersion.getNextActiveVersion(), type)); + return ruleConfigEventBuilder.build(databaseName, new DataChangedEvent(metaDataVersion.getActiveVersionNodePath(), metaDataVersion.getNextActiveVersion(), type)); } @Override From 521b0cf227e0deb7a0727de4bf14f8c10323906d Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Sat, 14 Dec 2024 17:36:38 +0800 Subject: [PATCH 26/32] Refactor StandaloneMetaDataManagerPersistServiceTest (#34054) --- .../service/StandaloneMetaDataManagerPersistServiceTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneMetaDataManagerPersistServiceTest.java b/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneMetaDataManagerPersistServiceTest.java index 9d7889375c883..788bae7f66c42 100644 --- a/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneMetaDataManagerPersistServiceTest.java +++ b/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneMetaDataManagerPersistServiceTest.java @@ -237,6 +237,6 @@ void assertDropTables() { @SneakyThrows(ReflectiveOperationException.class) private void setRuleConfigurationEventBuilder(final RuleConfigurationEventBuilder ruleConfigurationEventBuilder) { - Plugins.getMemberAccessor().set(StandaloneMetaDataManagerPersistService.class.getDeclaredField("ruleConfigurationEventBuilder"), metaDataManagerPersistService, ruleConfigurationEventBuilder); + Plugins.getMemberAccessor().set(StandaloneMetaDataManagerPersistService.class.getDeclaredField("ruleConfigEventBuilder"), metaDataManagerPersistService, ruleConfigurationEventBuilder); } } From 5b09fb927586efc2c887d12c65cb4b054817672e Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Sat, 14 Dec 2024 17:47:50 +0800 Subject: [PATCH 27/32] Refactor DatabaseMetaDataChangedListenerTest (#34055) --- .../listener/type/DatabaseMetaDataChangedListenerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListenerTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListenerTest.java index b0f36cb514e02..a1a23a6aab3b3 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListenerTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListenerTest.java @@ -78,7 +78,7 @@ void setUp() { private void setMockedBuilder() { RuleConfigurationEventBuilder builder = mock(RuleConfigurationEventBuilder.class); when(builder.build(eq("foo_db"), any(DataChangedEvent.class))).thenReturn(Optional.of(new AlterUniqueRuleItemEvent("foo_db", "key", "value", "type"))); - Plugins.getMemberAccessor().set(DatabaseMetaDataChangedListener.class.getDeclaredField("builder"), listener, builder); + Plugins.getMemberAccessor().set(DatabaseMetaDataChangedListener.class.getDeclaredField("eventBuilder"), listener, builder); } @ParameterizedTest(name = "{0}") From 9455f8a45f1c2862aab517f52f3687f663c034e7 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Sat, 14 Dec 2024 17:57:13 +0800 Subject: [PATCH 28/32] Rename RuleConfigurationChangedEventBuilder (#34056) --- ... RuleConfigurationChangedEventBuilder.java} | 6 +++--- ...eConfigurationChangedEventBuilderTest.java} | 6 +++--- .../type/DatabaseMetaDataChangedListener.java | 6 +++--- .../DatabaseMetaDataChangedListenerTest.java | 8 ++++---- ...tandaloneMetaDataManagerPersistService.java | 6 +++--- ...aloneMetaDataManagerPersistServiceTest.java | 18 +++++++++--------- 6 files changed, 25 insertions(+), 25 deletions(-) rename mode/core/src/main/java/org/apache/shardingsphere/mode/event/builder/{RuleConfigurationEventBuilder.java => RuleConfigurationChangedEventBuilder.java} (97%) rename mode/core/src/test/java/org/apache/shardingsphere/mode/event/builder/{RuleConfigurationEventBuilderTest.java => RuleConfigurationChangedEventBuilderTest.java} (95%) diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/event/builder/RuleConfigurationEventBuilder.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/event/builder/RuleConfigurationChangedEventBuilder.java similarity index 97% rename from mode/core/src/main/java/org/apache/shardingsphere/mode/event/builder/RuleConfigurationEventBuilder.java rename to mode/core/src/main/java/org/apache/shardingsphere/mode/event/builder/RuleConfigurationChangedEventBuilder.java index fa071d22c41ee..9fe445fd099b4 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/event/builder/RuleConfigurationEventBuilder.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/event/builder/RuleConfigurationChangedEventBuilder.java @@ -36,16 +36,16 @@ import java.util.Optional; /** - * Rule configuration event builder. + * Rule configuration changed event builder. */ -public final class RuleConfigurationEventBuilder { +public final class RuleConfigurationChangedEventBuilder { /** * Build rule changed event. * * @param databaseName database name * @param event data changed event - * @return rule changed event + * @return built event */ public Optional build(final String databaseName, final DataChangedEvent event) { for (RuleNodePathProvider each : ShardingSphereServiceLoader.getServiceInstances(RuleNodePathProvider.class)) { diff --git a/mode/core/src/test/java/org/apache/shardingsphere/mode/event/builder/RuleConfigurationEventBuilderTest.java b/mode/core/src/test/java/org/apache/shardingsphere/mode/event/builder/RuleConfigurationChangedEventBuilderTest.java similarity index 95% rename from mode/core/src/test/java/org/apache/shardingsphere/mode/event/builder/RuleConfigurationEventBuilderTest.java rename to mode/core/src/test/java/org/apache/shardingsphere/mode/event/builder/RuleConfigurationChangedEventBuilderTest.java index 01284e6a0ee7a..e9a1fbd1ea74d 100644 --- a/mode/core/src/test/java/org/apache/shardingsphere/mode/event/builder/RuleConfigurationEventBuilderTest.java +++ b/mode/core/src/test/java/org/apache/shardingsphere/mode/event/builder/RuleConfigurationChangedEventBuilderTest.java @@ -51,12 +51,12 @@ @ExtendWith(AutoMockExtension.class) @StaticMockSettings(ShardingSphereServiceLoader.class) -class RuleConfigurationEventBuilderTest { +class RuleConfigurationChangedEventBuilderTest { @Test void assertBuildWithoutRuleNodePathProvider() { when(ShardingSphereServiceLoader.getServiceInstances(RuleNodePathProvider.class)).thenReturn(Collections.emptyList()); - assertFalse(new RuleConfigurationEventBuilder().build("foo_db", new DataChangedEvent("k", "v", Type.IGNORED)).isPresent()); + assertFalse(new RuleConfigurationChangedEventBuilder().build("foo_db", new DataChangedEvent("k", "v", Type.IGNORED)).isPresent()); } @ParameterizedTest(name = "{0}") @@ -66,7 +66,7 @@ void assertBuild(final String name, final String eventKey, final String eventVal RuleNodePathProvider ruleNodePathProvider = mock(RuleNodePathProvider.class, RETURNS_DEEP_STUBS); when(ruleNodePathProvider.getRuleNodePath()).thenReturn(new RuleNodePath("fixture", Collections.singleton("named"), Collections.singleton("unique"))); when(ShardingSphereServiceLoader.getServiceInstances(RuleNodePathProvider.class)).thenReturn(Collections.singleton(ruleNodePathProvider)); - Optional actual = new RuleConfigurationEventBuilder().build("foo_db", new DataChangedEvent(eventKey, eventValue, type)); + Optional actual = new RuleConfigurationChangedEventBuilder().build("foo_db", new DataChangedEvent(eventKey, eventValue, type)); assertThat(actual.isPresent(), is(isEventPresent)); if (actual.isPresent()) { if (dispatchEventClass == AlterNamedRuleItemEvent.class) { diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListener.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListener.java index 2e33d83316161..0342e18ec6cee 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListener.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListener.java @@ -25,7 +25,7 @@ import org.apache.shardingsphere.metadata.persist.node.metadata.ViewMetaDataNode; import org.apache.shardingsphere.mode.event.DataChangedEvent; import org.apache.shardingsphere.mode.event.DataChangedEvent.Type; -import org.apache.shardingsphere.mode.event.builder.RuleConfigurationEventBuilder; +import org.apache.shardingsphere.mode.event.builder.RuleConfigurationChangedEventBuilder; import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; import org.apache.shardingsphere.mode.event.dispatch.datasource.node.AlterStorageNodeEvent; import org.apache.shardingsphere.mode.event.dispatch.datasource.node.RegisterStorageNodeEvent; @@ -51,7 +51,7 @@ public final class DatabaseMetaDataChangedListener implements DataChangedEventLi private final EventBusContext eventBusContext; - private final RuleConfigurationEventBuilder eventBuilder = new RuleConfigurationEventBuilder(); + private final RuleConfigurationChangedEventBuilder ruleConfigChangedEventBuilder = new RuleConfigurationChangedEventBuilder(); @Override public void onChange(final DataChangedEvent event) { @@ -78,7 +78,7 @@ private Optional createDispatchEvent(final DataChangedEvent event if (DataSourceMetaDataNode.isDataSourcesNode(key)) { return createDataSourceChangedEvent(databaseName.get(), event); } - return eventBuilder.build(databaseName.get(), event); + return ruleConfigChangedEventBuilder.build(databaseName.get(), event); } private Optional createSchemaChangedEvent(final String databaseName, final String schemaName, final DataChangedEvent event) { diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListenerTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListenerTest.java index a1a23a6aab3b3..1c663cfd84ca6 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListenerTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListenerTest.java @@ -21,7 +21,7 @@ import org.apache.shardingsphere.infra.util.eventbus.EventBusContext; import org.apache.shardingsphere.mode.event.DataChangedEvent; import org.apache.shardingsphere.mode.event.DataChangedEvent.Type; -import org.apache.shardingsphere.mode.event.builder.RuleConfigurationEventBuilder; +import org.apache.shardingsphere.mode.event.builder.RuleConfigurationChangedEventBuilder; import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; import org.apache.shardingsphere.mode.event.dispatch.datasource.node.AlterStorageNodeEvent; import org.apache.shardingsphere.mode.event.dispatch.datasource.node.RegisterStorageNodeEvent; @@ -76,9 +76,9 @@ void setUp() { @SneakyThrows(ReflectiveOperationException.class) private void setMockedBuilder() { - RuleConfigurationEventBuilder builder = mock(RuleConfigurationEventBuilder.class); - when(builder.build(eq("foo_db"), any(DataChangedEvent.class))).thenReturn(Optional.of(new AlterUniqueRuleItemEvent("foo_db", "key", "value", "type"))); - Plugins.getMemberAccessor().set(DatabaseMetaDataChangedListener.class.getDeclaredField("eventBuilder"), listener, builder); + RuleConfigurationChangedEventBuilder ruleConfigChangedEventBuilder = mock(RuleConfigurationChangedEventBuilder.class); + when(ruleConfigChangedEventBuilder.build(eq("foo_db"), any(DataChangedEvent.class))).thenReturn(Optional.of(new AlterUniqueRuleItemEvent("foo_db", "key", "value", "type"))); + Plugins.getMemberAccessor().set(DatabaseMetaDataChangedListener.class.getDeclaredField("ruleConfigChangedEventBuilder"), listener, ruleConfigChangedEventBuilder); } @ParameterizedTest(name = "{0}") diff --git a/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneMetaDataManagerPersistService.java b/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneMetaDataManagerPersistService.java index 5e5482666b850..1518a07cc8486 100644 --- a/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneMetaDataManagerPersistService.java +++ b/mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneMetaDataManagerPersistService.java @@ -36,7 +36,7 @@ import org.apache.shardingsphere.metadata.persist.service.config.database.DataSourceUnitPersistService; import org.apache.shardingsphere.mode.event.DataChangedEvent; import org.apache.shardingsphere.mode.event.DataChangedEvent.Type; -import org.apache.shardingsphere.mode.event.builder.RuleConfigurationEventBuilder; +import org.apache.shardingsphere.mode.event.builder.RuleConfigurationChangedEventBuilder; import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterRuleItemEvent; import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropRuleItemEvent; @@ -64,7 +64,7 @@ */ public final class StandaloneMetaDataManagerPersistService implements MetaDataManagerPersistService { - private final RuleConfigurationEventBuilder ruleConfigEventBuilder = new RuleConfigurationEventBuilder(); + private final RuleConfigurationChangedEventBuilder ruleConfigChangedEventBuilder = new RuleConfigurationChangedEventBuilder(); private final MetaDataPersistService metaDataPersistService; @@ -302,7 +302,7 @@ public void alterRuleConfiguration(final String databaseName, final RuleConfigur } private Optional buildAlterRuleItemEvent(final String databaseName, final MetaDataVersion metaDataVersion, final Type type) { - return ruleConfigEventBuilder.build(databaseName, new DataChangedEvent(metaDataVersion.getActiveVersionNodePath(), metaDataVersion.getNextActiveVersion(), type)); + return ruleConfigChangedEventBuilder.build(databaseName, new DataChangedEvent(metaDataVersion.getActiveVersionNodePath(), metaDataVersion.getNextActiveVersion(), type)); } @Override diff --git a/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneMetaDataManagerPersistServiceTest.java b/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneMetaDataManagerPersistServiceTest.java index 788bae7f66c42..7ba6f66770cd1 100644 --- a/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneMetaDataManagerPersistServiceTest.java +++ b/mode/type/standalone/core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneMetaDataManagerPersistServiceTest.java @@ -30,7 +30,7 @@ import org.apache.shardingsphere.infra.metadata.version.MetaDataVersion; import org.apache.shardingsphere.metadata.persist.MetaDataPersistService; import org.apache.shardingsphere.metadata.persist.service.metadata.DatabaseMetaDataPersistFacade; -import org.apache.shardingsphere.mode.event.builder.RuleConfigurationEventBuilder; +import org.apache.shardingsphere.mode.event.builder.RuleConfigurationChangedEventBuilder; import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterRuleItemEvent; import org.apache.shardingsphere.mode.event.dispatch.rule.drop.DropRuleItemEvent; import org.apache.shardingsphere.mode.metadata.MetaDataContextManager; @@ -173,9 +173,9 @@ void assertAlterRuleConfiguration() throws SQLException { Collection metaDataVersion = Collections.singleton(mock(MetaDataVersion.class)); when(metaDataPersistService.getDatabaseRulePersistService().persist("foo_db", Collections.singleton(ruleConfig))).thenReturn(metaDataVersion); AlterRuleItemEvent event = mock(AlterRuleItemEvent.class); - RuleConfigurationEventBuilder ruleConfigurationEventBuilder = mock(RuleConfigurationEventBuilder.class); - when(ruleConfigurationEventBuilder.build(eq("foo_db"), any())).thenReturn(Optional.of(event)); - setRuleConfigurationEventBuilder(ruleConfigurationEventBuilder); + RuleConfigurationChangedEventBuilder ruleConfigChangedEventBuilder = mock(RuleConfigurationChangedEventBuilder.class); + when(ruleConfigChangedEventBuilder.build(eq("foo_db"), any())).thenReturn(Optional.of(event)); + setRuleConfigurationEventBuilder(ruleConfigChangedEventBuilder); metaDataManagerPersistService.alterRuleConfiguration("foo_db", ruleConfig); verify(metaDataPersistService.getMetaDataVersionPersistService()).switchActiveVersion(metaDataVersion); verify(metaDataContextManager.getRuleItemManager()).alterRuleItem(event); @@ -192,10 +192,10 @@ void assertRemoveRuleConfigurationItem() throws SQLException { RuleConfiguration ruleConfig = mock(RuleConfiguration.class, RETURNS_DEEP_STUBS); Collection metaDataVersion = Collections.singleton(mock(MetaDataVersion.class)); when(metaDataPersistService.getDatabaseRulePersistService().delete("foo_db", Collections.singleton(ruleConfig))).thenReturn(metaDataVersion); - RuleConfigurationEventBuilder ruleConfigurationEventBuilder = mock(RuleConfigurationEventBuilder.class); + RuleConfigurationChangedEventBuilder ruleConfigChangedEventBuilder = mock(RuleConfigurationChangedEventBuilder.class); DropRuleItemEvent event = mock(DropRuleItemEvent.class); - when(ruleConfigurationEventBuilder.build(eq("foo_db"), any())).thenReturn(Optional.of(event)); - setRuleConfigurationEventBuilder(ruleConfigurationEventBuilder); + when(ruleConfigChangedEventBuilder.build(eq("foo_db"), any())).thenReturn(Optional.of(event)); + setRuleConfigurationEventBuilder(ruleConfigChangedEventBuilder); metaDataManagerPersistService.removeRuleConfigurationItem("foo_db", ruleConfig); verify(metaDataContextManager.getRuleItemManager()).dropRuleItem(event); } @@ -236,7 +236,7 @@ void assertDropTables() { } @SneakyThrows(ReflectiveOperationException.class) - private void setRuleConfigurationEventBuilder(final RuleConfigurationEventBuilder ruleConfigurationEventBuilder) { - Plugins.getMemberAccessor().set(StandaloneMetaDataManagerPersistService.class.getDeclaredField("ruleConfigEventBuilder"), metaDataManagerPersistService, ruleConfigurationEventBuilder); + private void setRuleConfigurationEventBuilder(final RuleConfigurationChangedEventBuilder ruleConfigurationEventBuilder) { + Plugins.getMemberAccessor().set(StandaloneMetaDataManagerPersistService.class.getDeclaredField("ruleConfigChangedEventBuilder"), metaDataManagerPersistService, ruleConfigurationEventBuilder); } } From 911cc578d3f59c68737743dd185de1e960427013 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Sat, 14 Dec 2024 18:29:20 +0800 Subject: [PATCH 29/32] Rename metadata changed event classes (#34057) --- ...vent.java => StorageNodeAlteredEvent.java} | 4 +- ...t.java => StorageNodeRegisteredEvent.java} | 4 +- ...java => StorageNodeUnregisteredEvent.java} | 4 +- ...vent.java => StorageUnitAlteredEvent.java} | 4 +- ...t.java => StorageUnitRegisteredEvent.java} | 4 +- ...java => StorageUnitUnregisteredEvent.java} | 4 +- ...t.java => TableCreatedOrAlteredEvent.java} | 4 +- ...TableEvent.java => TableDroppedEvent.java} | 4 +- ...nt.java => ViewCreatedOrAlteredEvent.java} | 4 +- ...opViewEvent.java => ViewDroppedEvent.java} | 4 +- .../type/DatabaseMetaDataChangedListener.java | 40 ++++++++--------- .../type/MetaDataChangedSubscriber.java | 16 +++---- .../type/StorageUnitEventSubscriber.java | 12 ++--- .../DatabaseMetaDataChangedListenerTest.java | 44 +++++++++---------- .../type/MetaDataChangedSubscriberTest.java | 16 +++---- .../type/StorageUnitEventSubscriberTest.java | 12 ++--- 16 files changed, 90 insertions(+), 90 deletions(-) rename mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/node/{AlterStorageNodeEvent.java => StorageNodeAlteredEvent.java} (92%) rename mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/node/{RegisterStorageNodeEvent.java => StorageNodeRegisteredEvent.java} (92%) rename mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/node/{UnregisterStorageNodeEvent.java => StorageNodeUnregisteredEvent.java} (91%) rename mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/unit/{AlterStorageUnitEvent.java => StorageUnitAlteredEvent.java} (92%) rename mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/unit/{RegisterStorageUnitEvent.java => StorageUnitRegisteredEvent.java} (92%) rename mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/unit/{UnregisterStorageUnitEvent.java => StorageUnitUnregisteredEvent.java} (91%) rename mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/metadata/schema/table/{CreateOrAlterTableEvent.java => TableCreatedOrAlteredEvent.java} (92%) rename mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/metadata/schema/table/{DropTableEvent.java => TableDroppedEvent.java} (93%) rename mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/metadata/schema/view/{CreateOrAlterViewEvent.java => ViewCreatedOrAlteredEvent.java} (92%) rename mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/metadata/schema/view/{DropViewEvent.java => ViewDroppedEvent.java} (93%) diff --git a/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/node/AlterStorageNodeEvent.java b/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/node/StorageNodeAlteredEvent.java similarity index 92% rename from mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/node/AlterStorageNodeEvent.java rename to mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/node/StorageNodeAlteredEvent.java index 20620e290a425..ba1d138f662e8 100644 --- a/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/node/AlterStorageNodeEvent.java +++ b/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/node/StorageNodeAlteredEvent.java @@ -22,11 +22,11 @@ import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; /** - * Add data source node event. + * Storage node altered event. */ @RequiredArgsConstructor @Getter -public final class AlterStorageNodeEvent implements DispatchEvent { +public final class StorageNodeAlteredEvent implements DispatchEvent { private final String databaseName; diff --git a/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/node/RegisterStorageNodeEvent.java b/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/node/StorageNodeRegisteredEvent.java similarity index 92% rename from mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/node/RegisterStorageNodeEvent.java rename to mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/node/StorageNodeRegisteredEvent.java index 0147684f96ef9..a3629450ac091 100644 --- a/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/node/RegisterStorageNodeEvent.java +++ b/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/node/StorageNodeRegisteredEvent.java @@ -22,11 +22,11 @@ import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; /** - * Add data source node event. + * Storage node registered event. */ @RequiredArgsConstructor @Getter -public final class RegisterStorageNodeEvent implements DispatchEvent { +public final class StorageNodeRegisteredEvent implements DispatchEvent { private final String databaseName; diff --git a/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/node/UnregisterStorageNodeEvent.java b/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/node/StorageNodeUnregisteredEvent.java similarity index 91% rename from mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/node/UnregisterStorageNodeEvent.java rename to mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/node/StorageNodeUnregisteredEvent.java index d28c074c5a7b0..cf0f3b6824eb2 100644 --- a/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/node/UnregisterStorageNodeEvent.java +++ b/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/node/StorageNodeUnregisteredEvent.java @@ -22,11 +22,11 @@ import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; /** - * Add data source node event. + * Storage node unregistered event. */ @RequiredArgsConstructor @Getter -public final class UnregisterStorageNodeEvent implements DispatchEvent { +public final class StorageNodeUnregisteredEvent implements DispatchEvent { private final String databaseName; diff --git a/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/unit/AlterStorageUnitEvent.java b/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/unit/StorageUnitAlteredEvent.java similarity index 92% rename from mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/unit/AlterStorageUnitEvent.java rename to mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/unit/StorageUnitAlteredEvent.java index 7447257196071..67ba44b2a131d 100644 --- a/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/unit/AlterStorageUnitEvent.java +++ b/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/unit/StorageUnitAlteredEvent.java @@ -22,11 +22,11 @@ import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; /** - * Add data source unit event. + * Storage unit altered event. */ @RequiredArgsConstructor @Getter -public final class AlterStorageUnitEvent implements DispatchEvent { +public final class StorageUnitAlteredEvent implements DispatchEvent { private final String databaseName; diff --git a/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/unit/RegisterStorageUnitEvent.java b/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/unit/StorageUnitRegisteredEvent.java similarity index 92% rename from mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/unit/RegisterStorageUnitEvent.java rename to mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/unit/StorageUnitRegisteredEvent.java index b87490cdadb3e..d261f41b944d4 100644 --- a/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/unit/RegisterStorageUnitEvent.java +++ b/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/unit/StorageUnitRegisteredEvent.java @@ -22,11 +22,11 @@ import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; /** - * Add data source unit event. + * Storage unit registered event. */ @RequiredArgsConstructor @Getter -public final class RegisterStorageUnitEvent implements DispatchEvent { +public final class StorageUnitRegisteredEvent implements DispatchEvent { private final String databaseName; diff --git a/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/unit/UnregisterStorageUnitEvent.java b/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/unit/StorageUnitUnregisteredEvent.java similarity index 91% rename from mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/unit/UnregisterStorageUnitEvent.java rename to mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/unit/StorageUnitUnregisteredEvent.java index a5ca257298154..09174865ddc69 100644 --- a/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/unit/UnregisterStorageUnitEvent.java +++ b/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/datasource/unit/StorageUnitUnregisteredEvent.java @@ -22,11 +22,11 @@ import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; /** - * Add data source unit event. + * Storage unit unregistered event. */ @RequiredArgsConstructor @Getter -public final class UnregisterStorageUnitEvent implements DispatchEvent { +public final class StorageUnitUnregisteredEvent implements DispatchEvent { private final String databaseName; diff --git a/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/metadata/schema/table/CreateOrAlterTableEvent.java b/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/metadata/schema/table/TableCreatedOrAlteredEvent.java similarity index 92% rename from mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/metadata/schema/table/CreateOrAlterTableEvent.java rename to mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/metadata/schema/table/TableCreatedOrAlteredEvent.java index 31e4635e639bc..a9f203a2f5261 100644 --- a/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/metadata/schema/table/CreateOrAlterTableEvent.java +++ b/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/metadata/schema/table/TableCreatedOrAlteredEvent.java @@ -22,11 +22,11 @@ import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; /** - * Create or alter table event. + * Table created or altered event. */ @RequiredArgsConstructor @Getter -public final class CreateOrAlterTableEvent implements DispatchEvent { +public final class TableCreatedOrAlteredEvent implements DispatchEvent { private final String databaseName; diff --git a/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/metadata/schema/table/DropTableEvent.java b/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/metadata/schema/table/TableDroppedEvent.java similarity index 93% rename from mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/metadata/schema/table/DropTableEvent.java rename to mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/metadata/schema/table/TableDroppedEvent.java index 46f14a3d0e65e..e0677e510f078 100644 --- a/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/metadata/schema/table/DropTableEvent.java +++ b/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/metadata/schema/table/TableDroppedEvent.java @@ -22,11 +22,11 @@ import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; /** - * Drop table event. + * Table dropped event. */ @RequiredArgsConstructor @Getter -public final class DropTableEvent implements DispatchEvent { +public final class TableDroppedEvent implements DispatchEvent { private final String databaseName; diff --git a/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/metadata/schema/view/CreateOrAlterViewEvent.java b/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/metadata/schema/view/ViewCreatedOrAlteredEvent.java similarity index 92% rename from mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/metadata/schema/view/CreateOrAlterViewEvent.java rename to mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/metadata/schema/view/ViewCreatedOrAlteredEvent.java index 13dd3207b51de..9e56a04abe8dd 100644 --- a/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/metadata/schema/view/CreateOrAlterViewEvent.java +++ b/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/metadata/schema/view/ViewCreatedOrAlteredEvent.java @@ -22,11 +22,11 @@ import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; /** - * Create or alter view event. + * View created or altered event. */ @RequiredArgsConstructor @Getter -public final class CreateOrAlterViewEvent implements DispatchEvent { +public final class ViewCreatedOrAlteredEvent implements DispatchEvent { private final String databaseName; diff --git a/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/metadata/schema/view/DropViewEvent.java b/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/metadata/schema/view/ViewDroppedEvent.java similarity index 93% rename from mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/metadata/schema/view/DropViewEvent.java rename to mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/metadata/schema/view/ViewDroppedEvent.java index 5464fa468cf83..d4c47b49442a8 100644 --- a/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/metadata/schema/view/DropViewEvent.java +++ b/mode/api/src/main/java/org/apache/shardingsphere/mode/event/dispatch/metadata/schema/view/ViewDroppedEvent.java @@ -22,11 +22,11 @@ import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; /** - * Drop view event. + * View dropped event. */ @RequiredArgsConstructor @Getter -public final class DropViewEvent implements DispatchEvent { +public final class ViewDroppedEvent implements DispatchEvent { private final String databaseName; diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListener.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListener.java index 0342e18ec6cee..50838500209c8 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListener.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListener.java @@ -27,18 +27,18 @@ import org.apache.shardingsphere.mode.event.DataChangedEvent.Type; import org.apache.shardingsphere.mode.event.builder.RuleConfigurationChangedEventBuilder; import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; -import org.apache.shardingsphere.mode.event.dispatch.datasource.node.AlterStorageNodeEvent; -import org.apache.shardingsphere.mode.event.dispatch.datasource.node.RegisterStorageNodeEvent; -import org.apache.shardingsphere.mode.event.dispatch.datasource.node.UnregisterStorageNodeEvent; -import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.AlterStorageUnitEvent; -import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.RegisterStorageUnitEvent; -import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.UnregisterStorageUnitEvent; +import org.apache.shardingsphere.mode.event.dispatch.datasource.node.StorageNodeAlteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.datasource.node.StorageNodeRegisteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.datasource.node.StorageNodeUnregisteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.StorageUnitAlteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.StorageUnitRegisteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.StorageUnitUnregisteredEvent; import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.SchemaAddedEvent; import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.SchemaDeletedEvent; -import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.table.CreateOrAlterTableEvent; -import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.table.DropTableEvent; -import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.view.CreateOrAlterViewEvent; -import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.view.DropViewEvent; +import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.table.TableCreatedOrAlteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.table.TableDroppedEvent; +import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.view.ViewCreatedOrAlteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.view.ViewDroppedEvent; import org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEventListener; import java.util.Optional; @@ -100,11 +100,11 @@ private boolean isTableMetaDataChanged(final String key) { private Optional createTableChangedEvent(final String databaseName, final String schemaName, final DataChangedEvent event) { if ((Type.ADDED == event.getType() || Type.UPDATED == event.getType()) && TableMetaDataNode.isTableActiveVersionNode(event.getKey())) { String tableName = TableMetaDataNode.getTableNameByActiveVersionNode(event.getKey()).orElseThrow(() -> new IllegalStateException("Table name not found.")); - return Optional.of(new CreateOrAlterTableEvent(databaseName, schemaName, tableName, event.getKey(), event.getValue())); + return Optional.of(new TableCreatedOrAlteredEvent(databaseName, schemaName, tableName, event.getKey(), event.getValue())); } if (Type.DELETED == event.getType() && TableMetaDataNode.isTableNode(event.getKey())) { String tableName = TableMetaDataNode.getTableName(event.getKey()).orElseThrow(() -> new IllegalStateException("Table name not found.")); - return Optional.of(new DropTableEvent(databaseName, schemaName, tableName)); + return Optional.of(new TableDroppedEvent(databaseName, schemaName, tableName)); } return Optional.empty(); } @@ -116,11 +116,11 @@ private boolean isViewMetaDataChanged(final String key) { private Optional createViewChangedEvent(final String databaseName, final String schemaName, final DataChangedEvent event) { if ((Type.ADDED == event.getType() || Type.UPDATED == event.getType()) && ViewMetaDataNode.isViewActiveVersionNode(event.getKey())) { String viewName = ViewMetaDataNode.getViewNameByActiveVersionNode(event.getKey()).orElseThrow(() -> new IllegalStateException("View name not found.")); - return Optional.of(new CreateOrAlterViewEvent(databaseName, schemaName, viewName, event.getKey(), event.getValue())); + return Optional.of(new ViewCreatedOrAlteredEvent(databaseName, schemaName, viewName, event.getKey(), event.getValue())); } if (Type.DELETED == event.getType() && ViewMetaDataNode.isViewNode(event.getKey())) { String viewName = ViewMetaDataNode.getViewName(event.getKey()).orElseThrow(() -> new IllegalStateException("View name not found.")); - return Optional.of(new DropViewEvent(databaseName, schemaName, viewName, event.getKey(), event.getValue())); + return Optional.of(new ViewDroppedEvent(databaseName, schemaName, viewName, event.getKey(), event.getValue())); } return Optional.empty(); } @@ -139,15 +139,15 @@ private Optional createStorageUnitChangedEvent(final String datab Optional dataSourceUnitName = DataSourceMetaDataNode.getDataSourceNameByDataSourceUnitActiveVersionNode(event.getKey()); if (dataSourceUnitName.isPresent()) { if (Type.ADDED == event.getType()) { - return Optional.of(new RegisterStorageUnitEvent(databaseName, dataSourceUnitName.get(), event.getKey(), event.getValue())); + return Optional.of(new StorageUnitRegisteredEvent(databaseName, dataSourceUnitName.get(), event.getKey(), event.getValue())); } if (Type.UPDATED == event.getType()) { - return Optional.of(new AlterStorageUnitEvent(databaseName, dataSourceUnitName.get(), event.getKey(), event.getValue())); + return Optional.of(new StorageUnitAlteredEvent(databaseName, dataSourceUnitName.get(), event.getKey(), event.getValue())); } } dataSourceUnitName = DataSourceMetaDataNode.getDataSourceNameByDataSourceUnitNode(event.getKey()); if (Type.DELETED == event.getType() && dataSourceUnitName.isPresent()) { - return Optional.of(new UnregisterStorageUnitEvent(databaseName, dataSourceUnitName.get())); + return Optional.of(new StorageUnitUnregisteredEvent(databaseName, dataSourceUnitName.get())); } return Optional.empty(); } @@ -156,15 +156,15 @@ private Optional createStorageNodeChangedEvent(final String datab Optional dataSourceNodeName = DataSourceMetaDataNode.getDataSourceNameByDataSourceNodeActiveVersionNode(event.getKey()); if (dataSourceNodeName.isPresent()) { if (Type.ADDED == event.getType()) { - return Optional.of(new RegisterStorageNodeEvent(databaseName, dataSourceNodeName.get(), event.getKey(), event.getValue())); + return Optional.of(new StorageNodeRegisteredEvent(databaseName, dataSourceNodeName.get(), event.getKey(), event.getValue())); } if (Type.UPDATED == event.getType()) { - return Optional.of(new AlterStorageNodeEvent(databaseName, dataSourceNodeName.get(), event.getKey(), event.getValue())); + return Optional.of(new StorageNodeAlteredEvent(databaseName, dataSourceNodeName.get(), event.getKey(), event.getValue())); } } dataSourceNodeName = DataSourceMetaDataNode.getDataSourceNameByDataSourceNodeNode(event.getKey()); if (Type.DELETED == event.getType() && dataSourceNodeName.isPresent()) { - return Optional.of(new UnregisterStorageNodeEvent(databaseName, dataSourceNodeName.get())); + return Optional.of(new StorageNodeUnregisteredEvent(databaseName, dataSourceNodeName.get())); } return Optional.empty(); } diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/MetaDataChangedSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/MetaDataChangedSubscriber.java index 59fb7baff17e5..b27967830c529 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/MetaDataChangedSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/MetaDataChangedSubscriber.java @@ -25,10 +25,10 @@ import org.apache.shardingsphere.infra.util.eventbus.EventSubscriber; import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.SchemaAddedEvent; import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.SchemaDeletedEvent; -import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.table.CreateOrAlterTableEvent; -import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.table.DropTableEvent; -import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.view.CreateOrAlterViewEvent; -import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.view.DropViewEvent; +import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.table.TableCreatedOrAlteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.table.TableDroppedEvent; +import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.view.ViewCreatedOrAlteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.view.ViewDroppedEvent; import org.apache.shardingsphere.mode.lock.GlobalLockContext; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.manager.cluster.persist.service.GlobalLockPersistService; @@ -77,7 +77,7 @@ public synchronized void renew(final SchemaDeletedEvent event) { * @param event create or alter table event */ @Subscribe - public synchronized void renew(final CreateOrAlterTableEvent event) { + public synchronized void renew(final TableCreatedOrAlteredEvent event) { Preconditions.checkArgument(event.getActiveVersion().equals( contextManager.getPersistServiceFacade().getMetaDataPersistService().getMetaDataVersionPersistService().getActiveVersionByFullPath(event.getActiveVersionKey())), "Invalid active version: %s of key: %s", event.getActiveVersion(), event.getActiveVersionKey()); @@ -93,7 +93,7 @@ public synchronized void renew(final CreateOrAlterTableEvent event) { * @param event drop table event */ @Subscribe - public synchronized void renew(final DropTableEvent event) { + public synchronized void renew(final TableDroppedEvent event) { contextManager.getMetaDataContextManager().getSchemaMetaDataManager().alterSchema(event.getDatabaseName(), event.getSchemaName(), event.getTableName(), null); refreshShardingSphereStatisticsData(); } @@ -104,7 +104,7 @@ public synchronized void renew(final DropTableEvent event) { * @param event create or alter view event */ @Subscribe - public synchronized void renew(final CreateOrAlterViewEvent event) { + public synchronized void renew(final ViewCreatedOrAlteredEvent event) { Preconditions.checkArgument(event.getActiveVersion().equals( contextManager.getPersistServiceFacade().getMetaDataPersistService().getMetaDataVersionPersistService().getActiveVersionByFullPath(event.getActiveVersionKey())), "Invalid active version: %s of key: %s", event.getActiveVersion(), event.getActiveVersionKey()); @@ -120,7 +120,7 @@ public synchronized void renew(final CreateOrAlterViewEvent event) { * @param event drop view event */ @Subscribe - public synchronized void renew(final DropViewEvent event) { + public synchronized void renew(final ViewDroppedEvent event) { contextManager.getMetaDataContextManager().getSchemaMetaDataManager().alterSchema(event.getDatabaseName(), event.getSchemaName(), null, event.getViewName()); refreshShardingSphereStatisticsData(); } diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/StorageUnitEventSubscriber.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/StorageUnitEventSubscriber.java index 9c8d9d82da7c6..ea167f1e09402 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/StorageUnitEventSubscriber.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/StorageUnitEventSubscriber.java @@ -22,9 +22,9 @@ import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties; import org.apache.shardingsphere.infra.util.eventbus.EventSubscriber; -import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.AlterStorageUnitEvent; -import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.RegisterStorageUnitEvent; -import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.UnregisterStorageUnitEvent; +import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.StorageUnitAlteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.StorageUnitRegisteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.StorageUnitUnregisteredEvent; import org.apache.shardingsphere.mode.manager.ContextManager; import java.util.Collections; @@ -43,7 +43,7 @@ public final class StorageUnitEventSubscriber implements EventSubscriber { * @param event register storage unit event */ @Subscribe - public synchronized void renew(final RegisterStorageUnitEvent event) { + public synchronized void renew(final StorageUnitRegisteredEvent event) { Preconditions.checkArgument(event.getActiveVersion().equals( contextManager.getPersistServiceFacade().getMetaDataPersistService().getMetaDataVersionPersistService().getActiveVersionByFullPath(event.getActiveVersionKey())), "Invalid active version: %s of key: %s", event.getActiveVersion(), event.getActiveVersionKey()); @@ -58,7 +58,7 @@ public synchronized void renew(final RegisterStorageUnitEvent event) { * @param event register storage unit event */ @Subscribe - public synchronized void renew(final AlterStorageUnitEvent event) { + public synchronized void renew(final StorageUnitAlteredEvent event) { Preconditions.checkArgument(event.getActiveVersion().equals( contextManager.getPersistServiceFacade().getMetaDataPersistService().getMetaDataVersionPersistService().getActiveVersionByFullPath(event.getActiveVersionKey())), "Invalid active version: %s of key: %s", event.getActiveVersion(), event.getActiveVersionKey()); @@ -73,7 +73,7 @@ public synchronized void renew(final AlterStorageUnitEvent event) { * @param event register storage unit event */ @Subscribe - public synchronized void renew(final UnregisterStorageUnitEvent event) { + public synchronized void renew(final StorageUnitUnregisteredEvent event) { Preconditions.checkState(contextManager.getMetaDataContexts().getMetaData().containsDatabase(event.getDatabaseName()), "No database '%s' exists.", event.getDatabaseName()); contextManager.getMetaDataContextManager().getStorageUnitManager().unregisterStorageUnit(event.getDatabaseName(), event.getStorageUnitName()); } diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListenerTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListenerTest.java index 1c663cfd84ca6..d1fda9c64ac84 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListenerTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListenerTest.java @@ -23,18 +23,18 @@ import org.apache.shardingsphere.mode.event.DataChangedEvent.Type; import org.apache.shardingsphere.mode.event.builder.RuleConfigurationChangedEventBuilder; import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; -import org.apache.shardingsphere.mode.event.dispatch.datasource.node.AlterStorageNodeEvent; -import org.apache.shardingsphere.mode.event.dispatch.datasource.node.RegisterStorageNodeEvent; -import org.apache.shardingsphere.mode.event.dispatch.datasource.node.UnregisterStorageNodeEvent; -import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.AlterStorageUnitEvent; -import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.RegisterStorageUnitEvent; -import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.UnregisterStorageUnitEvent; +import org.apache.shardingsphere.mode.event.dispatch.datasource.node.StorageNodeAlteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.datasource.node.StorageNodeRegisteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.datasource.node.StorageNodeUnregisteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.StorageUnitAlteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.StorageUnitRegisteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.StorageUnitUnregisteredEvent; import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.SchemaAddedEvent; import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.SchemaDeletedEvent; -import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.table.CreateOrAlterTableEvent; -import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.table.DropTableEvent; -import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.view.CreateOrAlterViewEvent; -import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.view.DropViewEvent; +import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.table.TableCreatedOrAlteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.table.TableDroppedEvent; +import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.view.ViewCreatedOrAlteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.view.ViewDroppedEvent; import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterUniqueRuleItemEvent; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.ExtendWith; @@ -102,25 +102,25 @@ public final Stream provideArguments(final ExtensionContext Arguments.of("updateSchema", "/metadata/foo_db/schemas/foo_schema", Type.UPDATED, SchemaAddedEvent.class), Arguments.of("deleteSchema", "/metadata/foo_db/schemas/foo_schema", Type.DELETED, SchemaDeletedEvent.class), Arguments.of("ignoreChangeSchema", "/metadata/foo_db/schemas/foo_schema", Type.IGNORED, null), - Arguments.of("addTable", "/metadata/foo_db/schemas/foo_schema/tables/foo_tbl/active_version/0", Type.ADDED, CreateOrAlterTableEvent.class), - Arguments.of("updateTable", "/metadata/foo_db/schemas/foo_schema/tables/foo_tbl/active_version/0", Type.UPDATED, CreateOrAlterTableEvent.class), - Arguments.of("deleteTable", "/metadata/foo_db/schemas/foo_schema/tables/foo_tbl", Type.DELETED, DropTableEvent.class), + Arguments.of("addTable", "/metadata/foo_db/schemas/foo_schema/tables/foo_tbl/active_version/0", Type.ADDED, TableCreatedOrAlteredEvent.class), + Arguments.of("updateTable", "/metadata/foo_db/schemas/foo_schema/tables/foo_tbl/active_version/0", Type.UPDATED, TableCreatedOrAlteredEvent.class), + Arguments.of("deleteTable", "/metadata/foo_db/schemas/foo_schema/tables/foo_tbl", Type.DELETED, TableDroppedEvent.class), Arguments.of("invalidAddTable", "/metadata/foo_db/schemas/foo_schema/tables/foo_tbl", Type.ADDED, null), Arguments.of("invalidDeleteTable", "/metadata/foo_db/schemas/foo_schema/tables/foo_tbl/active_version/0", Type.DELETED, null), - Arguments.of("addView", "/metadata/foo_db/schemas/foo_schema/views/foo_view/active_version/0", Type.ADDED, CreateOrAlterViewEvent.class), - Arguments.of("updateView", "/metadata/foo_db/schemas/foo_schema/views/foo_view/active_version/0", Type.UPDATED, CreateOrAlterViewEvent.class), - Arguments.of("deleteView", "/metadata/foo_db/schemas/foo_schema/views/foo_view", Type.DELETED, DropViewEvent.class), + Arguments.of("addView", "/metadata/foo_db/schemas/foo_schema/views/foo_view/active_version/0", Type.ADDED, ViewCreatedOrAlteredEvent.class), + Arguments.of("updateView", "/metadata/foo_db/schemas/foo_schema/views/foo_view/active_version/0", Type.UPDATED, ViewCreatedOrAlteredEvent.class), + Arguments.of("deleteView", "/metadata/foo_db/schemas/foo_schema/views/foo_view", Type.DELETED, ViewDroppedEvent.class), Arguments.of("invalidAddView", "/metadata/foo_db/schemas/foo_schema/views/foo_view", Type.ADDED, null), Arguments.of("invalidDeleteView", "/metadata/foo_db/schemas/foo_schema/views/foo_view/active_version/0", Type.DELETED, null), - Arguments.of("registerStorageUnit", "/metadata/foo_db/data_sources/units/foo_unit/active_version/0", Type.ADDED, RegisterStorageUnitEvent.class), - Arguments.of("alterStorageUnit", "/metadata/foo_db/data_sources/units/foo_unit/active_version/0", Type.UPDATED, AlterStorageUnitEvent.class), - Arguments.of("unregisterStorageUnit", "/metadata/foo_db/data_sources/units/foo_unit", Type.DELETED, UnregisterStorageUnitEvent.class), + Arguments.of("registerStorageUnit", "/metadata/foo_db/data_sources/units/foo_unit/active_version/0", Type.ADDED, StorageUnitRegisteredEvent.class), + Arguments.of("alterStorageUnit", "/metadata/foo_db/data_sources/units/foo_unit/active_version/0", Type.UPDATED, StorageUnitAlteredEvent.class), + Arguments.of("unregisterStorageUnit", "/metadata/foo_db/data_sources/units/foo_unit", Type.DELETED, StorageUnitUnregisteredEvent.class), Arguments.of("invalidRegisterStorageNode", "/metadata/foo_db/data_sources/units/foo_unit", Type.ADDED, null), Arguments.of("invalidUnregisterStorageNode", "/metadata/foo_db/data_sources/units/foo_unit/active_version/0", Type.DELETED, null), Arguments.of("ignoreChangeStorageUnit", "/metadata/foo_db/data_sources/units/foo_unit", Type.IGNORED, null), - Arguments.of("registerStorageNode", "/metadata/foo_db/data_sources/nodes/foo_node/active_version/0", Type.ADDED, RegisterStorageNodeEvent.class), - Arguments.of("alterStorageNode", "/metadata/foo_db/data_sources/nodes/foo_node/active_version/0", Type.UPDATED, AlterStorageNodeEvent.class), - Arguments.of("unregisterStorageNode", "/metadata/foo_db/data_sources/nodes/foo_node", Type.DELETED, UnregisterStorageNodeEvent.class), + Arguments.of("registerStorageNode", "/metadata/foo_db/data_sources/nodes/foo_node/active_version/0", Type.ADDED, StorageNodeRegisteredEvent.class), + Arguments.of("alterStorageNode", "/metadata/foo_db/data_sources/nodes/foo_node/active_version/0", Type.UPDATED, StorageNodeAlteredEvent.class), + Arguments.of("unregisterStorageNode", "/metadata/foo_db/data_sources/nodes/foo_node", Type.DELETED, StorageNodeUnregisteredEvent.class), Arguments.of("invalidRegisterStorageNode", "/metadata/foo_db/data_sources/nodes/foo_node", Type.ADDED, null), Arguments.of("invalidUnregisterStorageNode", "/metadata/foo_db/data_sources/nodes/foo_node/active_version/0", Type.DELETED, null), Arguments.of("ignoreChangeStorageNode", "/metadata/foo_db/data_sources/nodes/foo_node", Type.IGNORED, null), diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/MetaDataChangedSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/MetaDataChangedSubscriberTest.java index 12cf7bbfb7c86..9f15ff53d66f4 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/MetaDataChangedSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/MetaDataChangedSubscriberTest.java @@ -23,10 +23,10 @@ import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereView; import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.SchemaAddedEvent; import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.SchemaDeletedEvent; -import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.table.CreateOrAlterTableEvent; -import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.table.DropTableEvent; -import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.view.CreateOrAlterViewEvent; -import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.view.DropViewEvent; +import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.table.TableCreatedOrAlteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.table.TableDroppedEvent; +import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.view.ViewCreatedOrAlteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.view.ViewDroppedEvent; import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository; import org.junit.jupiter.api.BeforeEach; @@ -79,13 +79,13 @@ void assertRenewWithCreateOrAlterTableEvent() { ShardingSphereTable table = mock(ShardingSphereTable.class); when(contextManager.getPersistServiceFacade().getMetaDataPersistService().getDatabaseMetaDataFacade().getTable().load("foo_db", "foo_schema", "foo_tbl")) .thenReturn(table); - subscriber.renew(new CreateOrAlterTableEvent("foo_db", "foo_schema", "foo_tbl", "key", "value")); + subscriber.renew(new TableCreatedOrAlteredEvent("foo_db", "foo_schema", "foo_tbl", "key", "value")); verify(contextManager.getMetaDataContextManager().getSchemaMetaDataManager()).alterSchema("foo_db", "foo_schema", table, null); } @Test void assertRenewWithDropTableEvent() { - subscriber.renew(new DropTableEvent("foo_db", "foo_schema", "foo_tbl")); + subscriber.renew(new TableDroppedEvent("foo_db", "foo_schema", "foo_tbl")); verify(contextManager.getMetaDataContextManager().getSchemaMetaDataManager()).alterSchema("foo_db", "foo_schema", "foo_tbl", null); } @@ -95,13 +95,13 @@ void assertRenewWithCreateOrAlterViewEvent() { ShardingSphereView view = mock(ShardingSphereView.class); when(contextManager.getPersistServiceFacade().getMetaDataPersistService().getDatabaseMetaDataFacade().getView().load("foo_db", "foo_schema", "foo_view")) .thenReturn(view); - subscriber.renew(new CreateOrAlterViewEvent("foo_db", "foo_schema", "foo_view", "key", "value")); + subscriber.renew(new ViewCreatedOrAlteredEvent("foo_db", "foo_schema", "foo_view", "key", "value")); verify(contextManager.getMetaDataContextManager().getSchemaMetaDataManager()).alterSchema("foo_db", "foo_schema", null, view); } @Test void assertRenewWithDropViewEvent() { - subscriber.renew(new DropViewEvent("foo_db", "foo_schema", "foo_view", "key", "value")); + subscriber.renew(new ViewDroppedEvent("foo_db", "foo_schema", "foo_view", "key", "value")); verify(contextManager.getMetaDataContextManager().getSchemaMetaDataManager()).alterSchema("foo_db", "foo_schema", null, "foo_view"); } } diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/StorageUnitEventSubscriberTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/StorageUnitEventSubscriberTest.java index df1805f191e57..951d4610cd5b0 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/StorageUnitEventSubscriberTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/subscriber/type/StorageUnitEventSubscriberTest.java @@ -18,9 +18,9 @@ package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.subscriber.type; import org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties; -import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.AlterStorageUnitEvent; -import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.RegisterStorageUnitEvent; -import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.UnregisterStorageUnitEvent; +import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.StorageUnitAlteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.StorageUnitRegisteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.StorageUnitUnregisteredEvent; import org.apache.shardingsphere.mode.manager.ContextManager; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -52,7 +52,7 @@ void setUp() { void assertRenewWithRegisterStorageUnitEvent() { when(contextManager.getPersistServiceFacade().getMetaDataPersistService().getMetaDataVersionPersistService().getActiveVersionByFullPath("key")).thenReturn("value"); when(contextManager.getPersistServiceFacade().getMetaDataPersistService().getDataSourceUnitService().load("foo_db", "foo_unit")).thenReturn(mock(DataSourcePoolProperties.class)); - subscriber.renew(new RegisterStorageUnitEvent("foo_db", "foo_unit", "key", "value")); + subscriber.renew(new StorageUnitRegisteredEvent("foo_db", "foo_unit", "key", "value")); verify(contextManager.getMetaDataContextManager().getStorageUnitManager()).registerStorageUnit(eq("foo_db"), any()); } @@ -60,14 +60,14 @@ void assertRenewWithRegisterStorageUnitEvent() { void assertRenewWithAlterStorageUnitEvent() { when(contextManager.getPersistServiceFacade().getMetaDataPersistService().getMetaDataVersionPersistService().getActiveVersionByFullPath("key")).thenReturn("value"); when(contextManager.getPersistServiceFacade().getMetaDataPersistService().getDataSourceUnitService().load("foo_db", "foo_unit")).thenReturn(mock(DataSourcePoolProperties.class)); - subscriber.renew(new AlterStorageUnitEvent("foo_db", "foo_unit", "key", "value")); + subscriber.renew(new StorageUnitAlteredEvent("foo_db", "foo_unit", "key", "value")); verify(contextManager.getMetaDataContextManager().getStorageUnitManager()).alterStorageUnit(eq("foo_db"), any()); } @Test void assertRenewWithUnregisterStorageUnitEvent() { when(contextManager.getMetaDataContexts().getMetaData().containsDatabase("foo_db")).thenReturn(true); - subscriber.renew(new UnregisterStorageUnitEvent("foo_db", "foo_unit")); + subscriber.renew(new StorageUnitUnregisteredEvent("foo_db", "foo_unit")); verify(contextManager.getMetaDataContextManager().getStorageUnitManager()).unregisterStorageUnit("foo_db", "foo_unit"); } } From d527c00deb6b19926e0a3a62f5cc389864f0c2d1 Mon Sep 17 00:00:00 2001 From: Zhengqiang Duan Date: Sat, 14 Dec 2024 21:07:35 +0800 Subject: [PATCH 30/32] Remove openGauss db-types for group_concat e2e test case (#34058) --- .../src/test/resources/cases/dql/e2e-dql-select-aggregate.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/e2e/sql/src/test/resources/cases/dql/e2e-dql-select-aggregate.xml b/test/e2e/sql/src/test/resources/cases/dql/e2e-dql-select-aggregate.xml index 643f8d69e48d6..f4bd5b4809205 100644 --- a/test/e2e/sql/src/test/resources/cases/dql/e2e-dql-select-aggregate.xml +++ b/test/e2e/sql/src/test/resources/cases/dql/e2e-dql-select-aggregate.xml @@ -145,11 +145,11 @@ - + - + From d9f70bdce394b77112fda3f69d382a5acfd847b6 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Sat, 14 Dec 2024 22:54:57 +0800 Subject: [PATCH 31/32] Add MetaDataChangedEventBuilder (#34060) * Add MetaDataChangedEventBuilder * Add MetaDataChangedEventBuilder --- .../builder/MetaDataChangedEventBuilder.java | 160 ++++++++++++++++++ .../MetaDataChangedEventBuilderTest.java | 98 +++++++++++ ...eConfigurationChangedEventBuilderTest.java | 3 +- .../type/DatabaseMetaDataChangedListener.java | 126 +------------- .../DatabaseMetaDataChangedListenerTest.java | 94 ++-------- 5 files changed, 278 insertions(+), 203 deletions(-) create mode 100644 mode/core/src/main/java/org/apache/shardingsphere/mode/event/builder/MetaDataChangedEventBuilder.java create mode 100644 mode/core/src/test/java/org/apache/shardingsphere/mode/event/builder/MetaDataChangedEventBuilderTest.java diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/event/builder/MetaDataChangedEventBuilder.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/event/builder/MetaDataChangedEventBuilder.java new file mode 100644 index 0000000000000..d8b5bed328838 --- /dev/null +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/event/builder/MetaDataChangedEventBuilder.java @@ -0,0 +1,160 @@ +/* + * 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.mode.event.builder; + +import org.apache.shardingsphere.metadata.persist.node.DatabaseMetaDataNode; +import org.apache.shardingsphere.metadata.persist.node.metadata.DataSourceMetaDataNode; +import org.apache.shardingsphere.metadata.persist.node.metadata.TableMetaDataNode; +import org.apache.shardingsphere.metadata.persist.node.metadata.ViewMetaDataNode; +import org.apache.shardingsphere.mode.event.DataChangedEvent; +import org.apache.shardingsphere.mode.event.DataChangedEvent.Type; +import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; +import org.apache.shardingsphere.mode.event.dispatch.datasource.node.StorageNodeAlteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.datasource.node.StorageNodeRegisteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.datasource.node.StorageNodeUnregisteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.StorageUnitAlteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.StorageUnitRegisteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.StorageUnitUnregisteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.SchemaAddedEvent; +import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.SchemaDeletedEvent; +import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.table.TableCreatedOrAlteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.table.TableDroppedEvent; +import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.view.ViewCreatedOrAlteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.view.ViewDroppedEvent; + +import java.util.Optional; + +/** + * Meta data changed event builder. + */ +public final class MetaDataChangedEventBuilder { + + /** + * Build meta data changed event. + * + * @param databaseName database name + * @param event data changed event + * @return built event + */ + public Optional build(final String databaseName, final DataChangedEvent event) { + String key = event.getKey(); + Optional schemaName = DatabaseMetaDataNode.getSchemaName(key); + if (schemaName.isPresent()) { + return buildSchemaChangedEvent(databaseName, schemaName.get(), event); + } + schemaName = DatabaseMetaDataNode.getSchemaNameByTableNode(key); + if (schemaName.isPresent() && isTableMetaDataChanged(event.getKey())) { + return buildTableChangedEvent(databaseName, schemaName.get(), event); + } + if (schemaName.isPresent() && isViewMetaDataChanged(event.getKey())) { + return buildViewChangedEvent(databaseName, schemaName.get(), event); + } + if (DataSourceMetaDataNode.isDataSourcesNode(key)) { + return buildDataSourceChangedEvent(databaseName, event); + } + return Optional.empty(); + } + + private Optional buildSchemaChangedEvent(final String databaseName, final String schemaName, final DataChangedEvent event) { + switch (event.getType()) { + case ADDED: + case UPDATED: + return Optional.of(new SchemaAddedEvent(databaseName, schemaName)); + case DELETED: + return Optional.of(new SchemaDeletedEvent(databaseName, schemaName)); + default: + return Optional.empty(); + } + } + + private boolean isTableMetaDataChanged(final String key) { + return TableMetaDataNode.isTableActiveVersionNode(key) || TableMetaDataNode.isTableNode(key); + } + + private Optional buildTableChangedEvent(final String databaseName, final String schemaName, final DataChangedEvent event) { + if ((Type.ADDED == event.getType() || Type.UPDATED == event.getType()) && TableMetaDataNode.isTableActiveVersionNode(event.getKey())) { + String tableName = TableMetaDataNode.getTableNameByActiveVersionNode(event.getKey()).orElseThrow(() -> new IllegalStateException("Table name not found.")); + return Optional.of(new TableCreatedOrAlteredEvent(databaseName, schemaName, tableName, event.getKey(), event.getValue())); + } + if (Type.DELETED == event.getType() && TableMetaDataNode.isTableNode(event.getKey())) { + String tableName = TableMetaDataNode.getTableName(event.getKey()).orElseThrow(() -> new IllegalStateException("Table name not found.")); + return Optional.of(new TableDroppedEvent(databaseName, schemaName, tableName)); + } + return Optional.empty(); + } + + private boolean isViewMetaDataChanged(final String key) { + return ViewMetaDataNode.isViewActiveVersionNode(key) || ViewMetaDataNode.isViewNode(key); + } + + private Optional buildViewChangedEvent(final String databaseName, final String schemaName, final DataChangedEvent event) { + if ((Type.ADDED == event.getType() || Type.UPDATED == event.getType()) && ViewMetaDataNode.isViewActiveVersionNode(event.getKey())) { + String viewName = ViewMetaDataNode.getViewNameByActiveVersionNode(event.getKey()).orElseThrow(() -> new IllegalStateException("View name not found.")); + return Optional.of(new ViewCreatedOrAlteredEvent(databaseName, schemaName, viewName, event.getKey(), event.getValue())); + } + if (Type.DELETED == event.getType() && ViewMetaDataNode.isViewNode(event.getKey())) { + String viewName = ViewMetaDataNode.getViewName(event.getKey()).orElseThrow(() -> new IllegalStateException("View name not found.")); + return Optional.of(new ViewDroppedEvent(databaseName, schemaName, viewName, event.getKey(), event.getValue())); + } + return Optional.empty(); + } + + private Optional buildDataSourceChangedEvent(final String databaseName, final DataChangedEvent event) { + if (DataSourceMetaDataNode.isDataSourceUnitActiveVersionNode(event.getKey()) || DataSourceMetaDataNode.isDataSourceUnitNode(event.getKey())) { + return buildStorageUnitChangedEvent(databaseName, event); + } + if (DataSourceMetaDataNode.isDataSourceNodeActiveVersionNode(event.getKey()) || DataSourceMetaDataNode.isDataSourceNodeNode(event.getKey())) { + return buildStorageNodeChangedEvent(databaseName, event); + } + return Optional.empty(); + } + + private Optional buildStorageUnitChangedEvent(final String databaseName, final DataChangedEvent event) { + Optional dataSourceUnitName = DataSourceMetaDataNode.getDataSourceNameByDataSourceUnitActiveVersionNode(event.getKey()); + if (dataSourceUnitName.isPresent()) { + if (Type.ADDED == event.getType()) { + return Optional.of(new StorageUnitRegisteredEvent(databaseName, dataSourceUnitName.get(), event.getKey(), event.getValue())); + } + if (Type.UPDATED == event.getType()) { + return Optional.of(new StorageUnitAlteredEvent(databaseName, dataSourceUnitName.get(), event.getKey(), event.getValue())); + } + } + dataSourceUnitName = DataSourceMetaDataNode.getDataSourceNameByDataSourceUnitNode(event.getKey()); + if (Type.DELETED == event.getType() && dataSourceUnitName.isPresent()) { + return Optional.of(new StorageUnitUnregisteredEvent(databaseName, dataSourceUnitName.get())); + } + return Optional.empty(); + } + + private Optional buildStorageNodeChangedEvent(final String databaseName, final DataChangedEvent event) { + Optional dataSourceNodeName = DataSourceMetaDataNode.getDataSourceNameByDataSourceNodeActiveVersionNode(event.getKey()); + if (dataSourceNodeName.isPresent()) { + if (Type.ADDED == event.getType()) { + return Optional.of(new StorageNodeRegisteredEvent(databaseName, dataSourceNodeName.get(), event.getKey(), event.getValue())); + } + if (Type.UPDATED == event.getType()) { + return Optional.of(new StorageNodeAlteredEvent(databaseName, dataSourceNodeName.get(), event.getKey(), event.getValue())); + } + } + dataSourceNodeName = DataSourceMetaDataNode.getDataSourceNameByDataSourceNodeNode(event.getKey()); + if (Type.DELETED == event.getType() && dataSourceNodeName.isPresent()) { + return Optional.of(new StorageNodeUnregisteredEvent(databaseName, dataSourceNodeName.get())); + } + return Optional.empty(); + } +} diff --git a/mode/core/src/test/java/org/apache/shardingsphere/mode/event/builder/MetaDataChangedEventBuilderTest.java b/mode/core/src/test/java/org/apache/shardingsphere/mode/event/builder/MetaDataChangedEventBuilderTest.java new file mode 100644 index 0000000000000..60e9320caa9cc --- /dev/null +++ b/mode/core/src/test/java/org/apache/shardingsphere/mode/event/builder/MetaDataChangedEventBuilderTest.java @@ -0,0 +1,98 @@ +/* + * 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.mode.event.builder; + +import org.apache.shardingsphere.mode.event.DataChangedEvent; +import org.apache.shardingsphere.mode.event.DataChangedEvent.Type; +import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; +import org.apache.shardingsphere.mode.event.dispatch.datasource.node.StorageNodeAlteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.datasource.node.StorageNodeRegisteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.datasource.node.StorageNodeUnregisteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.StorageUnitAlteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.StorageUnitRegisteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.StorageUnitUnregisteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.SchemaAddedEvent; +import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.SchemaDeletedEvent; +import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.table.TableCreatedOrAlteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.table.TableDroppedEvent; +import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.view.ViewCreatedOrAlteredEvent; +import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.view.ViewDroppedEvent; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.ArgumentsProvider; +import org.junit.jupiter.params.provider.ArgumentsSource; + +import java.util.Optional; +import java.util.stream.Stream; + +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; + +class MetaDataChangedEventBuilderTest { + + @ParameterizedTest(name = "{0}") + @ArgumentsSource(TestCaseArgumentsProvider.class) + void assertBuild(final String name, final String eventKey, final Type type, final Class toBePostedEventType) { + Optional actual = new MetaDataChangedEventBuilder().build("foo_db", new DataChangedEvent(eventKey, "value", type)); + if (null == toBePostedEventType) { + assertFalse(actual.isPresent()); + } else { + assertTrue(actual.isPresent()); + assertThat(actual.get(), instanceOf(toBePostedEventType)); + } + } + + private static class TestCaseArgumentsProvider implements ArgumentsProvider { + + @Override + public final Stream provideArguments(final ExtensionContext extensionContext) { + return Stream.of( + Arguments.of("changeWithoutDatabase", "/metadata", Type.IGNORED, null), + Arguments.of("addSchema", "/metadata/foo_db/schemas/foo_schema", Type.ADDED, SchemaAddedEvent.class), + Arguments.of("updateSchema", "/metadata/foo_db/schemas/foo_schema", Type.UPDATED, SchemaAddedEvent.class), + Arguments.of("deleteSchema", "/metadata/foo_db/schemas/foo_schema", Type.DELETED, SchemaDeletedEvent.class), + Arguments.of("ignoreChangeSchema", "/metadata/foo_db/schemas/foo_schema", Type.IGNORED, null), + Arguments.of("addTable", "/metadata/foo_db/schemas/foo_schema/tables/foo_tbl/active_version/0", Type.ADDED, TableCreatedOrAlteredEvent.class), + Arguments.of("updateTable", "/metadata/foo_db/schemas/foo_schema/tables/foo_tbl/active_version/0", Type.UPDATED, TableCreatedOrAlteredEvent.class), + Arguments.of("deleteTable", "/metadata/foo_db/schemas/foo_schema/tables/foo_tbl", Type.DELETED, TableDroppedEvent.class), + Arguments.of("invalidAddTable", "/metadata/foo_db/schemas/foo_schema/tables/foo_tbl", Type.ADDED, null), + Arguments.of("invalidDeleteTable", "/metadata/foo_db/schemas/foo_schema/tables/foo_tbl/active_version/0", Type.DELETED, null), + Arguments.of("addView", "/metadata/foo_db/schemas/foo_schema/views/foo_view/active_version/0", Type.ADDED, ViewCreatedOrAlteredEvent.class), + Arguments.of("updateView", "/metadata/foo_db/schemas/foo_schema/views/foo_view/active_version/0", Type.UPDATED, ViewCreatedOrAlteredEvent.class), + Arguments.of("deleteView", "/metadata/foo_db/schemas/foo_schema/views/foo_view", Type.DELETED, ViewDroppedEvent.class), + Arguments.of("invalidAddView", "/metadata/foo_db/schemas/foo_schema/views/foo_view", Type.ADDED, null), + Arguments.of("invalidDeleteView", "/metadata/foo_db/schemas/foo_schema/views/foo_view/active_version/0", Type.DELETED, null), + Arguments.of("registerStorageUnit", "/metadata/foo_db/data_sources/units/foo_unit/active_version/0", Type.ADDED, StorageUnitRegisteredEvent.class), + Arguments.of("alterStorageUnit", "/metadata/foo_db/data_sources/units/foo_unit/active_version/0", Type.UPDATED, StorageUnitAlteredEvent.class), + Arguments.of("unregisterStorageUnit", "/metadata/foo_db/data_sources/units/foo_unit", Type.DELETED, StorageUnitUnregisteredEvent.class), + Arguments.of("invalidRegisterStorageNode", "/metadata/foo_db/data_sources/units/foo_unit", Type.ADDED, null), + Arguments.of("invalidUnregisterStorageNode", "/metadata/foo_db/data_sources/units/foo_unit/active_version/0", Type.DELETED, null), + Arguments.of("ignoreChangeStorageUnit", "/metadata/foo_db/data_sources/units/foo_unit", Type.IGNORED, null), + Arguments.of("registerStorageNode", "/metadata/foo_db/data_sources/nodes/foo_node/active_version/0", Type.ADDED, StorageNodeRegisteredEvent.class), + Arguments.of("alterStorageNode", "/metadata/foo_db/data_sources/nodes/foo_node/active_version/0", Type.UPDATED, StorageNodeAlteredEvent.class), + Arguments.of("unregisterStorageNode", "/metadata/foo_db/data_sources/nodes/foo_node", Type.DELETED, StorageNodeUnregisteredEvent.class), + Arguments.of("invalidRegisterStorageNode", "/metadata/foo_db/data_sources/nodes/foo_node", Type.ADDED, null), + Arguments.of("invalidUnregisterStorageNode", "/metadata/foo_db/data_sources/nodes/foo_node/active_version/0", Type.DELETED, null), + Arguments.of("ignoreChangeStorageNode", "/metadata/foo_db/data_sources/nodes/foo_node", Type.IGNORED, null), + Arguments.of("invalidChangeDataSource", "/metadata/foo_db/data_sources/other", Type.ADDED, null)); + } + } +} diff --git a/mode/core/src/test/java/org/apache/shardingsphere/mode/event/builder/RuleConfigurationChangedEventBuilderTest.java b/mode/core/src/test/java/org/apache/shardingsphere/mode/event/builder/RuleConfigurationChangedEventBuilderTest.java index e9a1fbd1ea74d..9d888833df2f4 100644 --- a/mode/core/src/test/java/org/apache/shardingsphere/mode/event/builder/RuleConfigurationChangedEventBuilderTest.java +++ b/mode/core/src/test/java/org/apache/shardingsphere/mode/event/builder/RuleConfigurationChangedEventBuilderTest.java @@ -61,8 +61,7 @@ void assertBuildWithoutRuleNodePathProvider() { @ParameterizedTest(name = "{0}") @ArgumentsSource(TestCaseArgumentsProvider.class) - void assertBuild(final String name, final String eventKey, final String eventValue, final DataChangedEvent.Type type, - final boolean isEventPresent, final Class dispatchEventClass) { + void assertBuild(final String name, final String eventKey, final String eventValue, final Type type, final boolean isEventPresent, final Class dispatchEventClass) { RuleNodePathProvider ruleNodePathProvider = mock(RuleNodePathProvider.class, RETURNS_DEEP_STUBS); when(ruleNodePathProvider.getRuleNodePath()).thenReturn(new RuleNodePath("fixture", Collections.singleton("named"), Collections.singleton("unique"))); when(ShardingSphereServiceLoader.getServiceInstances(RuleNodePathProvider.class)).thenReturn(Collections.singleton(ruleNodePathProvider)); diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListener.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListener.java index 50838500209c8..e0d6c1553780b 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListener.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListener.java @@ -20,25 +20,10 @@ import lombok.RequiredArgsConstructor; import org.apache.shardingsphere.infra.util.eventbus.EventBusContext; import org.apache.shardingsphere.metadata.persist.node.DatabaseMetaDataNode; -import org.apache.shardingsphere.metadata.persist.node.metadata.DataSourceMetaDataNode; -import org.apache.shardingsphere.metadata.persist.node.metadata.TableMetaDataNode; -import org.apache.shardingsphere.metadata.persist.node.metadata.ViewMetaDataNode; import org.apache.shardingsphere.mode.event.DataChangedEvent; -import org.apache.shardingsphere.mode.event.DataChangedEvent.Type; +import org.apache.shardingsphere.mode.event.builder.MetaDataChangedEventBuilder; import org.apache.shardingsphere.mode.event.builder.RuleConfigurationChangedEventBuilder; import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; -import org.apache.shardingsphere.mode.event.dispatch.datasource.node.StorageNodeAlteredEvent; -import org.apache.shardingsphere.mode.event.dispatch.datasource.node.StorageNodeRegisteredEvent; -import org.apache.shardingsphere.mode.event.dispatch.datasource.node.StorageNodeUnregisteredEvent; -import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.StorageUnitAlteredEvent; -import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.StorageUnitRegisteredEvent; -import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.StorageUnitUnregisteredEvent; -import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.SchemaAddedEvent; -import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.SchemaDeletedEvent; -import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.table.TableCreatedOrAlteredEvent; -import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.table.TableDroppedEvent; -import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.view.ViewCreatedOrAlteredEvent; -import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.view.ViewDroppedEvent; import org.apache.shardingsphere.mode.repository.cluster.listener.DataChangedEventListener; import java.util.Optional; @@ -49,10 +34,12 @@ @RequiredArgsConstructor public final class DatabaseMetaDataChangedListener implements DataChangedEventListener { - private final EventBusContext eventBusContext; + private final MetaDataChangedEventBuilder metaDataChangedEventBuilder = new MetaDataChangedEventBuilder(); private final RuleConfigurationChangedEventBuilder ruleConfigChangedEventBuilder = new RuleConfigurationChangedEventBuilder(); + private final EventBusContext eventBusContext; + @Override public void onChange(final DataChangedEvent event) { createDispatchEvent(event).ifPresent(eventBusContext::post); @@ -64,108 +51,7 @@ private Optional createDispatchEvent(final DataChangedEvent event if (!databaseName.isPresent()) { return Optional.empty(); } - Optional schemaName = DatabaseMetaDataNode.getSchemaName(key); - if (schemaName.isPresent()) { - return createSchemaChangedEvent(databaseName.get(), schemaName.get(), event); - } - schemaName = DatabaseMetaDataNode.getSchemaNameByTableNode(key); - if (schemaName.isPresent() && isTableMetaDataChanged(event.getKey())) { - return createTableChangedEvent(databaseName.get(), schemaName.get(), event); - } - if (schemaName.isPresent() && isViewMetaDataChanged(event.getKey())) { - return createViewChangedEvent(databaseName.get(), schemaName.get(), event); - } - if (DataSourceMetaDataNode.isDataSourcesNode(key)) { - return createDataSourceChangedEvent(databaseName.get(), event); - } - return ruleConfigChangedEventBuilder.build(databaseName.get(), event); - } - - private Optional createSchemaChangedEvent(final String databaseName, final String schemaName, final DataChangedEvent event) { - switch (event.getType()) { - case ADDED: - case UPDATED: - return Optional.of(new SchemaAddedEvent(databaseName, schemaName)); - case DELETED: - return Optional.of(new SchemaDeletedEvent(databaseName, schemaName)); - default: - return Optional.empty(); - } - } - - private boolean isTableMetaDataChanged(final String key) { - return TableMetaDataNode.isTableActiveVersionNode(key) || TableMetaDataNode.isTableNode(key); - } - - private Optional createTableChangedEvent(final String databaseName, final String schemaName, final DataChangedEvent event) { - if ((Type.ADDED == event.getType() || Type.UPDATED == event.getType()) && TableMetaDataNode.isTableActiveVersionNode(event.getKey())) { - String tableName = TableMetaDataNode.getTableNameByActiveVersionNode(event.getKey()).orElseThrow(() -> new IllegalStateException("Table name not found.")); - return Optional.of(new TableCreatedOrAlteredEvent(databaseName, schemaName, tableName, event.getKey(), event.getValue())); - } - if (Type.DELETED == event.getType() && TableMetaDataNode.isTableNode(event.getKey())) { - String tableName = TableMetaDataNode.getTableName(event.getKey()).orElseThrow(() -> new IllegalStateException("Table name not found.")); - return Optional.of(new TableDroppedEvent(databaseName, schemaName, tableName)); - } - return Optional.empty(); - } - - private boolean isViewMetaDataChanged(final String key) { - return ViewMetaDataNode.isViewActiveVersionNode(key) || ViewMetaDataNode.isViewNode(key); - } - - private Optional createViewChangedEvent(final String databaseName, final String schemaName, final DataChangedEvent event) { - if ((Type.ADDED == event.getType() || Type.UPDATED == event.getType()) && ViewMetaDataNode.isViewActiveVersionNode(event.getKey())) { - String viewName = ViewMetaDataNode.getViewNameByActiveVersionNode(event.getKey()).orElseThrow(() -> new IllegalStateException("View name not found.")); - return Optional.of(new ViewCreatedOrAlteredEvent(databaseName, schemaName, viewName, event.getKey(), event.getValue())); - } - if (Type.DELETED == event.getType() && ViewMetaDataNode.isViewNode(event.getKey())) { - String viewName = ViewMetaDataNode.getViewName(event.getKey()).orElseThrow(() -> new IllegalStateException("View name not found.")); - return Optional.of(new ViewDroppedEvent(databaseName, schemaName, viewName, event.getKey(), event.getValue())); - } - return Optional.empty(); - } - - private Optional createDataSourceChangedEvent(final String databaseName, final DataChangedEvent event) { - if (DataSourceMetaDataNode.isDataSourceUnitActiveVersionNode(event.getKey()) || DataSourceMetaDataNode.isDataSourceUnitNode(event.getKey())) { - return createStorageUnitChangedEvent(databaseName, event); - } - if (DataSourceMetaDataNode.isDataSourceNodeActiveVersionNode(event.getKey()) || DataSourceMetaDataNode.isDataSourceNodeNode(event.getKey())) { - return createStorageNodeChangedEvent(databaseName, event); - } - return Optional.empty(); - } - - private Optional createStorageUnitChangedEvent(final String databaseName, final DataChangedEvent event) { - Optional dataSourceUnitName = DataSourceMetaDataNode.getDataSourceNameByDataSourceUnitActiveVersionNode(event.getKey()); - if (dataSourceUnitName.isPresent()) { - if (Type.ADDED == event.getType()) { - return Optional.of(new StorageUnitRegisteredEvent(databaseName, dataSourceUnitName.get(), event.getKey(), event.getValue())); - } - if (Type.UPDATED == event.getType()) { - return Optional.of(new StorageUnitAlteredEvent(databaseName, dataSourceUnitName.get(), event.getKey(), event.getValue())); - } - } - dataSourceUnitName = DataSourceMetaDataNode.getDataSourceNameByDataSourceUnitNode(event.getKey()); - if (Type.DELETED == event.getType() && dataSourceUnitName.isPresent()) { - return Optional.of(new StorageUnitUnregisteredEvent(databaseName, dataSourceUnitName.get())); - } - return Optional.empty(); - } - - private Optional createStorageNodeChangedEvent(final String databaseName, final DataChangedEvent event) { - Optional dataSourceNodeName = DataSourceMetaDataNode.getDataSourceNameByDataSourceNodeActiveVersionNode(event.getKey()); - if (dataSourceNodeName.isPresent()) { - if (Type.ADDED == event.getType()) { - return Optional.of(new StorageNodeRegisteredEvent(databaseName, dataSourceNodeName.get(), event.getKey(), event.getValue())); - } - if (Type.UPDATED == event.getType()) { - return Optional.of(new StorageNodeAlteredEvent(databaseName, dataSourceNodeName.get(), event.getKey(), event.getValue())); - } - } - dataSourceNodeName = DataSourceMetaDataNode.getDataSourceNameByDataSourceNodeNode(event.getKey()); - if (Type.DELETED == event.getType() && dataSourceNodeName.isPresent()) { - return Optional.of(new StorageNodeUnregisteredEvent(databaseName, dataSourceNodeName.get())); - } - return Optional.empty(); + Optional metaDataChangedEvent = metaDataChangedEventBuilder.build(databaseName.get(), event); + return metaDataChangedEvent.isPresent() ? metaDataChangedEvent : ruleConfigChangedEventBuilder.build(databaseName.get(), event); } } diff --git a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListenerTest.java b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListenerTest.java index d1fda9c64ac84..d1cdabd4faa51 100644 --- a/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListenerTest.java +++ b/mode/type/cluster/core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListenerTest.java @@ -17,50 +17,20 @@ package org.apache.shardingsphere.mode.manager.cluster.event.dispatch.listener.type; -import lombok.SneakyThrows; import org.apache.shardingsphere.infra.util.eventbus.EventBusContext; import org.apache.shardingsphere.mode.event.DataChangedEvent; import org.apache.shardingsphere.mode.event.DataChangedEvent.Type; -import org.apache.shardingsphere.mode.event.builder.RuleConfigurationChangedEventBuilder; -import org.apache.shardingsphere.mode.event.dispatch.DispatchEvent; -import org.apache.shardingsphere.mode.event.dispatch.datasource.node.StorageNodeAlteredEvent; -import org.apache.shardingsphere.mode.event.dispatch.datasource.node.StorageNodeRegisteredEvent; -import org.apache.shardingsphere.mode.event.dispatch.datasource.node.StorageNodeUnregisteredEvent; -import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.StorageUnitAlteredEvent; -import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.StorageUnitRegisteredEvent; -import org.apache.shardingsphere.mode.event.dispatch.datasource.unit.StorageUnitUnregisteredEvent; -import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.SchemaAddedEvent; -import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.SchemaDeletedEvent; -import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.table.TableCreatedOrAlteredEvent; -import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.table.TableDroppedEvent; -import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.view.ViewCreatedOrAlteredEvent; -import org.apache.shardingsphere.mode.event.dispatch.metadata.schema.view.ViewDroppedEvent; -import org.apache.shardingsphere.mode.event.dispatch.rule.alter.AlterUniqueRuleItemEvent; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.junit.jupiter.api.extension.ExtensionContext; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.ArgumentsProvider; -import org.junit.jupiter.params.provider.ArgumentsSource; import org.mockito.Mock; -import org.mockito.internal.configuration.plugins.Plugins; import org.mockito.junit.jupiter.MockitoExtension; -import org.mockito.junit.jupiter.MockitoSettings; -import org.mockito.quality.Strictness; - -import java.util.Optional; -import java.util.stream.Stream; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) -@MockitoSettings(strictness = Strictness.LENIENT) class DatabaseMetaDataChangedListenerTest { private DatabaseMetaDataChangedListener listener; @@ -71,61 +41,23 @@ class DatabaseMetaDataChangedListenerTest { @BeforeEach void setUp() { listener = new DatabaseMetaDataChangedListener(eventBusContext); - setMockedBuilder(); } - @SneakyThrows(ReflectiveOperationException.class) - private void setMockedBuilder() { - RuleConfigurationChangedEventBuilder ruleConfigChangedEventBuilder = mock(RuleConfigurationChangedEventBuilder.class); - when(ruleConfigChangedEventBuilder.build(eq("foo_db"), any(DataChangedEvent.class))).thenReturn(Optional.of(new AlterUniqueRuleItemEvent("foo_db", "key", "value", "type"))); - Plugins.getMemberAccessor().set(DatabaseMetaDataChangedListener.class.getDeclaredField("ruleConfigChangedEventBuilder"), listener, ruleConfigChangedEventBuilder); + @Test + void assertOnChangeWithoutDatabase() { + listener.onChange(new DataChangedEvent("/metadata", "value", Type.IGNORED)); + verify(eventBusContext, times(0)).post(any()); } - @ParameterizedTest(name = "{0}") - @ArgumentsSource(TestCaseArgumentsProvider.class) - void assertOnChangeWithMetaData(final String name, final String eventKey, final Type type, final Class toBePostedEventType) { - listener.onChange(new DataChangedEvent(eventKey, "value", type)); - if (null == toBePostedEventType) { - verify(eventBusContext, times(0)).post(any()); - } else { - verify(eventBusContext).post(any(toBePostedEventType)); - } + @Test + void assertOnChangeWithMetaDataChanged() { + listener.onChange(new DataChangedEvent("/metadata/foo_db/schemas/foo_schema", "value", Type.ADDED)); + verify(eventBusContext).post(any()); } - private static class TestCaseArgumentsProvider implements ArgumentsProvider { - - @Override - public final Stream provideArguments(final ExtensionContext extensionContext) { - return Stream.of( - Arguments.of("changeWithoutDatabase", "/metadata", Type.IGNORED, null), - Arguments.of("addSchema", "/metadata/foo_db/schemas/foo_schema", Type.ADDED, SchemaAddedEvent.class), - Arguments.of("updateSchema", "/metadata/foo_db/schemas/foo_schema", Type.UPDATED, SchemaAddedEvent.class), - Arguments.of("deleteSchema", "/metadata/foo_db/schemas/foo_schema", Type.DELETED, SchemaDeletedEvent.class), - Arguments.of("ignoreChangeSchema", "/metadata/foo_db/schemas/foo_schema", Type.IGNORED, null), - Arguments.of("addTable", "/metadata/foo_db/schemas/foo_schema/tables/foo_tbl/active_version/0", Type.ADDED, TableCreatedOrAlteredEvent.class), - Arguments.of("updateTable", "/metadata/foo_db/schemas/foo_schema/tables/foo_tbl/active_version/0", Type.UPDATED, TableCreatedOrAlteredEvent.class), - Arguments.of("deleteTable", "/metadata/foo_db/schemas/foo_schema/tables/foo_tbl", Type.DELETED, TableDroppedEvent.class), - Arguments.of("invalidAddTable", "/metadata/foo_db/schemas/foo_schema/tables/foo_tbl", Type.ADDED, null), - Arguments.of("invalidDeleteTable", "/metadata/foo_db/schemas/foo_schema/tables/foo_tbl/active_version/0", Type.DELETED, null), - Arguments.of("addView", "/metadata/foo_db/schemas/foo_schema/views/foo_view/active_version/0", Type.ADDED, ViewCreatedOrAlteredEvent.class), - Arguments.of("updateView", "/metadata/foo_db/schemas/foo_schema/views/foo_view/active_version/0", Type.UPDATED, ViewCreatedOrAlteredEvent.class), - Arguments.of("deleteView", "/metadata/foo_db/schemas/foo_schema/views/foo_view", Type.DELETED, ViewDroppedEvent.class), - Arguments.of("invalidAddView", "/metadata/foo_db/schemas/foo_schema/views/foo_view", Type.ADDED, null), - Arguments.of("invalidDeleteView", "/metadata/foo_db/schemas/foo_schema/views/foo_view/active_version/0", Type.DELETED, null), - Arguments.of("registerStorageUnit", "/metadata/foo_db/data_sources/units/foo_unit/active_version/0", Type.ADDED, StorageUnitRegisteredEvent.class), - Arguments.of("alterStorageUnit", "/metadata/foo_db/data_sources/units/foo_unit/active_version/0", Type.UPDATED, StorageUnitAlteredEvent.class), - Arguments.of("unregisterStorageUnit", "/metadata/foo_db/data_sources/units/foo_unit", Type.DELETED, StorageUnitUnregisteredEvent.class), - Arguments.of("invalidRegisterStorageNode", "/metadata/foo_db/data_sources/units/foo_unit", Type.ADDED, null), - Arguments.of("invalidUnregisterStorageNode", "/metadata/foo_db/data_sources/units/foo_unit/active_version/0", Type.DELETED, null), - Arguments.of("ignoreChangeStorageUnit", "/metadata/foo_db/data_sources/units/foo_unit", Type.IGNORED, null), - Arguments.of("registerStorageNode", "/metadata/foo_db/data_sources/nodes/foo_node/active_version/0", Type.ADDED, StorageNodeRegisteredEvent.class), - Arguments.of("alterStorageNode", "/metadata/foo_db/data_sources/nodes/foo_node/active_version/0", Type.UPDATED, StorageNodeAlteredEvent.class), - Arguments.of("unregisterStorageNode", "/metadata/foo_db/data_sources/nodes/foo_node", Type.DELETED, StorageNodeUnregisteredEvent.class), - Arguments.of("invalidRegisterStorageNode", "/metadata/foo_db/data_sources/nodes/foo_node", Type.ADDED, null), - Arguments.of("invalidUnregisterStorageNode", "/metadata/foo_db/data_sources/nodes/foo_node/active_version/0", Type.DELETED, null), - Arguments.of("ignoreChangeStorageNode", "/metadata/foo_db/data_sources/nodes/foo_node", Type.IGNORED, null), - Arguments.of("invalidChangeDataSource", "/metadata/foo_db/data_sources/other", Type.ADDED, null), - Arguments.of("changeRule", "/metadata/foo_db/schemas/foo_schema/rule/", Type.ADDED, AlterUniqueRuleItemEvent.class)); - } + @Test + void assertOnChangeWithRuleConfigurationChanged() { + listener.onChange(new DataChangedEvent("/metadata/foo_db/schemas/foo_schema/rule/", "value", Type.ADDED)); + verify(eventBusContext, times(0)).post(any()); } } From 2c9996ef048076fb5776051dee8f019addad0774 Mon Sep 17 00:00:00 2001 From: Liang Zhang Date: Sat, 14 Dec 2024 23:08:29 +0800 Subject: [PATCH 32/32] Refactor DatabaseMetaDataChangedListener (#34061) --- .../listener/type/DatabaseMetaDataChangedListener.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListener.java b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListener.java index e0d6c1553780b..8d8d0f46f47fb 100644 --- a/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListener.java +++ b/mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/event/dispatch/listener/type/DatabaseMetaDataChangedListener.java @@ -34,10 +34,6 @@ @RequiredArgsConstructor public final class DatabaseMetaDataChangedListener implements DataChangedEventListener { - private final MetaDataChangedEventBuilder metaDataChangedEventBuilder = new MetaDataChangedEventBuilder(); - - private final RuleConfigurationChangedEventBuilder ruleConfigChangedEventBuilder = new RuleConfigurationChangedEventBuilder(); - private final EventBusContext eventBusContext; @Override @@ -51,7 +47,7 @@ private Optional createDispatchEvent(final DataChangedEvent event if (!databaseName.isPresent()) { return Optional.empty(); } - Optional metaDataChangedEvent = metaDataChangedEventBuilder.build(databaseName.get(), event); - return metaDataChangedEvent.isPresent() ? metaDataChangedEvent : ruleConfigChangedEventBuilder.build(databaseName.get(), event); + Optional metaDataChangedEvent = new MetaDataChangedEventBuilder().build(databaseName.get(), event); + return metaDataChangedEvent.isPresent() ? metaDataChangedEvent : new RuleConfigurationChangedEventBuilder().build(databaseName.get(), event); } }