diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java index 594d99fbc9eea..6a64055d2e288 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaData.java @@ -108,7 +108,7 @@ public ShardingSphereDatabase getDatabase(final String databaseName) { public void addDatabase(final String databaseName, final DatabaseType protocolType, final ConfigurationProperties props) { ShardingSphereDatabase database = ShardingSphereDatabase.create(databaseName, protocolType, props); databases.put(database.getName(), database); - globalRuleMetaData.getRules().forEach(each -> ((GlobalRule) each).refresh(databases, GlobalRuleChangedType.DATABASE_CHANGED)); + globalRuleMetaData.getRules().forEach(each -> ((GlobalRule) each).refresh(databases.values(), GlobalRuleChangedType.DATABASE_CHANGED)); } /** @@ -122,7 +122,7 @@ public void dropDatabase(final String databaseName) { @SneakyThrows(Exception.class) private void cleanResources(final ShardingSphereDatabase database) { - globalRuleMetaData.getRules().forEach(each -> ((GlobalRule) each).refresh(databases, GlobalRuleChangedType.DATABASE_CHANGED)); + globalRuleMetaData.getRules().forEach(each -> ((GlobalRule) each).refresh(databases.values(), GlobalRuleChangedType.DATABASE_CHANGED)); for (ShardingSphereRule each : database.getRuleMetaData().getRules()) { if (each instanceof AutoCloseable) { ((AutoCloseable) each).close(); diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRuleBuilder.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRuleBuilder.java index 6188828fa35d3..901f7ae21d9b7 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRuleBuilder.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRuleBuilder.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.rule.scope.GlobalRule; import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI; -import java.util.Map; +import java.util.Collection; /** * Global rule builder. @@ -42,5 +42,5 @@ public interface GlobalRuleBuilder extends RuleBuil * @param props props * @return global rule */ - GlobalRule build(T ruleConfig, Map databases, ConfigurationProperties props); + GlobalRule build(T ruleConfig, Collection databases, ConfigurationProperties props); } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilder.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilder.java index eabd82769b412..3786f91c4d751 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilder.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/builder/global/GlobalRulesBuilder.java @@ -52,7 +52,7 @@ public static Collection buildRules(final Collection databases, final ConfigurationProperties props) { Collection result = new LinkedList<>(); for (Entry entry : getRuleBuilderMap(globalRuleConfigs).entrySet()) { - result.add(entry.getValue().build(entry.getKey(), databases, props)); + result.add(entry.getValue().build(entry.getKey(), databases.values(), props)); } return result; } @@ -93,6 +93,6 @@ private static Collection getMissedDefaultRuleBuilders(final @SuppressWarnings("unchecked") public static Collection buildSingleRules(final RuleConfiguration globalRuleConfig, final Map databases, final ConfigurationProperties props) { return OrderedSPILoader.getServices(GlobalRuleBuilder.class, Collections.singleton(globalRuleConfig)).entrySet() - .stream().map(each -> each.getValue().build(each.getKey(), databases, props)).collect(Collectors.toList()); + .stream().map(each -> each.getValue().build(each.getKey(), databases.values(), props)).collect(Collectors.toList()); } } diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/scope/GlobalRule.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/scope/GlobalRule.java index 06ac169be0850..4ccc001ac3898 100644 --- a/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/scope/GlobalRule.java +++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/rule/scope/GlobalRule.java @@ -20,7 +20,7 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.rule.ShardingSphereRule; -import java.util.Map; +import java.util.Collection; /** * Global rule. @@ -33,7 +33,7 @@ public interface GlobalRule extends ShardingSphereRule { * @param databases changed databases * @param changedType changed type */ - default void refresh(final Map databases, GlobalRuleChangedType changedType) { + default void refresh(final Collection databases, GlobalRuleChangedType changedType) { } /** diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java index 45ca20c57c498..21d57c114c689 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/metadata/ShardingSphereMetaDataTest.java @@ -72,8 +72,7 @@ void assertAddDatabase() { Map databases = new HashMap<>(Collections.singletonMap("foo_db", database)); ShardingSphereMetaData metaData = new ShardingSphereMetaData(databases, mock(ResourceMetaData.class), new RuleMetaData(Collections.singleton(globalRule)), configProps); metaData.addDatabase("foo_db", databaseType, configProps); - assertThat(metaData.getDatabases(), is(databases)); - verify(globalRule).refresh(databases, GlobalRuleChangedType.DATABASE_CHANGED); + assertThat(metaData.getDatabase("foo_db"), is(database)); } @Test @@ -91,7 +90,7 @@ void assertDropDatabase() { assertTrue(metaData.getDatabases().isEmpty()); Awaitility.await().pollDelay(10L, TimeUnit.MILLISECONDS).until(dataSource::isClosed); assertTrue(dataSource.isClosed()); - verify(globalRule).refresh(metaData.getDatabases(), GlobalRuleChangedType.DATABASE_CHANGED); + verify(globalRule).refresh(metaData.getAllDatabases(), GlobalRuleChangedType.DATABASE_CHANGED); } @Test diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureGlobalRuleBuilder.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureGlobalRuleBuilder.java index 95743d650a39e..ca7f81f52b3e9 100644 --- a/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureGlobalRuleBuilder.java +++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/rule/builder/fixture/FixtureGlobalRuleBuilder.java @@ -21,12 +21,12 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.rule.builder.global.GlobalRuleBuilder; -import java.util.Map; +import java.util.Collection; public final class FixtureGlobalRuleBuilder implements GlobalRuleBuilder { @Override - public FixtureGlobalRule build(final FixtureGlobalRuleConfiguration ruleConfig, final Map databases, final ConfigurationProperties props) { + public FixtureGlobalRule build(final FixtureGlobalRuleConfiguration ruleConfig, final Collection databases, final ConfigurationProperties props) { return new FixtureGlobalRule(); } diff --git a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/PreparedStatementAdapterTest.java b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/PreparedStatementAdapterTest.java index 15c3a675e2324..1ab61816694c1 100644 --- a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/PreparedStatementAdapterTest.java +++ b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/adapter/PreparedStatementAdapterTest.java @@ -68,7 +68,7 @@ void setUp() throws SQLException { when(connection.getContextManager().getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn( new RuleMetaData(Arrays.asList( new SQLParserRule(new DefaultSQLParserRuleConfigurationBuilder().build()), - new SQLFederationRule(new DefaultSQLFederationRuleConfigurationBuilder().build(), Collections.emptyMap())))); + new SQLFederationRule(new DefaultSQLFederationRuleConfigurationBuilder().build(), Collections.emptyList())))); when(connection.getContextManager().getMetaDataContexts().getMetaData().getProps()).thenReturn(new ConfigurationProperties(new Properties())); when(connection.getContextManager().getMetaDataContexts().getMetaData().getDatabase( connection.getCurrentDatabaseName()).getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "MySQL")); 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 3b68f95f3a425..21147a5d94a27 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 @@ -235,7 +235,7 @@ void assertSetQueryTimeout() throws SQLException { private ShardingSphereStatement mockShardingSphereStatement(final Statement... statements) { ShardingSphereConnection connection = mock(ShardingSphereConnection.class, RETURNS_DEEP_STUBS); RuleMetaData globalRuleMetaData = new RuleMetaData(Arrays.asList( - new SQLFederationRule(new DefaultSQLFederationRuleConfigurationBuilder().build(), Collections.emptyMap()), + new SQLFederationRule(new DefaultSQLFederationRuleConfigurationBuilder().build(), Collections.emptyList()), new SQLParserRule(new DefaultSQLParserRuleConfigurationBuilder().build()))); when(connection.getContextManager().getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(globalRuleMetaData); when(connection.getContextManager().getMetaDataContexts().getMetaData().getProps()).thenReturn(new ConfigurationProperties(new Properties())); @@ -257,7 +257,7 @@ private ShardingSphereStatement mockShardingSphereStatementWithNeedAccumulate(fi DatabaseType databaseType = TypedSPILoader.getService(DatabaseType.class, "FIXTURE"); when(connection.getContextManager().getMetaDataContexts().getMetaData().getDatabase("db").getProtocolType()).thenReturn(databaseType); when(connection.getContextManager().getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(new RuleMetaData(Arrays.asList( - new SQLFederationRule(new DefaultSQLFederationRuleConfigurationBuilder().build(), Collections.emptyMap()), + 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); 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 9169ab0170d94..c0c9014eed97a 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 @@ -210,6 +210,6 @@ private ContextManager mockContextManager(final DataSource dataSource) { } private TransactionRule mockTransactionRule() { - return new TransactionRule(new TransactionRuleConfiguration(TransactionType.LOCAL.name(), "", new Properties()), Collections.emptyMap()); + return new TransactionRule(new TransactionRuleConfiguration(TransactionType.LOCAL.name(), "", new Properties()), Collections.emptyList()); } } diff --git a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationPreparedStatementTest.java b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationPreparedStatementTest.java index c042e94bd0f5f..3c2e0294ca16e 100644 --- a/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationPreparedStatementTest.java +++ b/jdbc/src/test/java/org/apache/shardingsphere/driver/jdbc/unsupported/UnsupportedOperationPreparedStatementTest.java @@ -54,7 +54,7 @@ void setUp() throws SQLException { when(connection.getCurrentDatabaseName()).thenReturn(DefaultDatabase.LOGIC_NAME); when(connection.getContextManager().getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(new RuleMetaData(Arrays.asList( new SQLParserRule(new DefaultSQLParserRuleConfigurationBuilder().build()), - new SQLFederationRule(new DefaultSQLFederationRuleConfigurationBuilder().build(), Collections.emptyMap())))); + new SQLFederationRule(new DefaultSQLFederationRuleConfigurationBuilder().build(), Collections.emptyList())))); when(connection.getContextManager().getMetaDataContexts().getMetaData().getDatabase( connection.getCurrentDatabaseName()).getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "MySQL")); when(connection.getContextManager().getMetaDataContexts().getMetaData().getProps()).thenReturn(new ConfigurationProperties(new Properties())); 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 d1407916d5da4..ed6da52a7ce41 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 @@ -52,7 +52,7 @@ void setUp() { when(connection.getContextManager().getMetaDataContexts().getMetaData().getDatabase("db").getProtocolType()).thenReturn(databaseType); when(connection.getContextManager().getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(new RuleMetaData( Arrays.asList( - new SQLFederationRule(new DefaultSQLFederationRuleConfigurationBuilder().build(), Collections.emptyMap()), + 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); diff --git a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/rule/builder/AuthorityRuleBuilder.java b/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/rule/builder/AuthorityRuleBuilder.java index e85c789113420..316a08f15b379 100644 --- a/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/rule/builder/AuthorityRuleBuilder.java +++ b/kernel/authority/core/src/main/java/org/apache/shardingsphere/authority/rule/builder/AuthorityRuleBuilder.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.rule.builder.global.GlobalRuleBuilder; -import java.util.Map; +import java.util.Collection; /** * Authority rule builder. @@ -32,7 +32,7 @@ public final class AuthorityRuleBuilder implements GlobalRuleBuilder { @Override - public AuthorityRule build(final AuthorityRuleConfiguration ruleConfig, final Map databases, final ConfigurationProperties props) { + public AuthorityRule build(final AuthorityRuleConfiguration ruleConfig, final Collection databases, final ConfigurationProperties props) { return new AuthorityRule(ruleConfig); } diff --git a/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/rule/builder/GlobalClockRuleBuilder.java b/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/rule/builder/GlobalClockRuleBuilder.java index 79e9bba3e1e2c..4330bec3a9e7b 100644 --- a/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/rule/builder/GlobalClockRuleBuilder.java +++ b/kernel/global-clock/core/src/main/java/org/apache/shardingsphere/globalclock/rule/builder/GlobalClockRuleBuilder.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.rule.builder.global.GlobalRuleBuilder; -import java.util.Map; +import java.util.Collection; /** * Global clock rule builder. @@ -32,7 +32,7 @@ public final class GlobalClockRuleBuilder implements GlobalRuleBuilder { @Override - public GlobalClockRule build(final GlobalClockRuleConfiguration ruleConfig, final Map databases, final ConfigurationProperties props) { + public GlobalClockRule build(final GlobalClockRuleConfiguration ruleConfig, final Collection databases, final ConfigurationProperties props) { return new GlobalClockRule(ruleConfig); } diff --git a/kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/rule/builder/GlobalClockRuleBuilderTest.java b/kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/rule/builder/GlobalClockRuleBuilderTest.java index b4fa1a01cf0fe..caa4fed30408f 100644 --- a/kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/rule/builder/GlobalClockRuleBuilderTest.java +++ b/kernel/global-clock/core/src/test/java/org/apache/shardingsphere/globalclock/rule/builder/GlobalClockRuleBuilderTest.java @@ -38,6 +38,6 @@ class GlobalClockRuleBuilderTest { void assertBuild() { GlobalClockRuleConfiguration ruleConfig = new GlobalClockRuleConfiguration("FIXTURE", "FIXTURE", false, new Properties()); Map builders = OrderedSPILoader.getServices(GlobalRuleBuilder.class, Collections.singleton(ruleConfig)); - assertThat(builders.get(ruleConfig).build(ruleConfig, Collections.emptyMap(), null), instanceOf(GlobalClockRule.class)); + assertThat(builders.get(ruleConfig).build(ruleConfig, Collections.emptyList(), null), instanceOf(GlobalClockRule.class)); } } diff --git a/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/rule/builder/LoggingRuleBuilder.java b/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/rule/builder/LoggingRuleBuilder.java index 1f331e524d3de..78d102c8dbc28 100644 --- a/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/rule/builder/LoggingRuleBuilder.java +++ b/kernel/logging/core/src/main/java/org/apache/shardingsphere/logging/rule/builder/LoggingRuleBuilder.java @@ -26,7 +26,7 @@ import org.apache.shardingsphere.logging.logger.ShardingSphereLogger; import org.apache.shardingsphere.logging.rule.LoggingRule; -import java.util.Map; +import java.util.Collection; import java.util.Optional; import java.util.Properties; @@ -36,7 +36,7 @@ public final class LoggingRuleBuilder implements GlobalRuleBuilder { @Override - public LoggingRule build(final LoggingRuleConfiguration ruleConfig, final Map databases, final ConfigurationProperties props) { + public LoggingRule build(final LoggingRuleConfiguration ruleConfig, final Collection databases, final ConfigurationProperties props) { syncLoggingRuleConfiguration(ruleConfig, props); return new LoggingRule(ruleConfig); } diff --git a/kernel/logging/core/src/test/java/org/apache/shardingsphere/logging/rule/builder/LoggingRuleBuilderTest.java b/kernel/logging/core/src/test/java/org/apache/shardingsphere/logging/rule/builder/LoggingRuleBuilderTest.java index 537e2a580beab..030cf8882a104 100644 --- a/kernel/logging/core/src/test/java/org/apache/shardingsphere/logging/rule/builder/LoggingRuleBuilderTest.java +++ b/kernel/logging/core/src/test/java/org/apache/shardingsphere/logging/rule/builder/LoggingRuleBuilderTest.java @@ -44,7 +44,7 @@ void assertBuildWhenSyncPropertiesToRule() { ConfigurationProperties props = new ConfigurationProperties(PropertiesBuilder.build( new Property(LoggingConstants.SQL_SHOW, Boolean.TRUE.toString()), new Property(LoggingConstants.SQL_SIMPLE, Boolean.TRUE.toString()))); LoggingRuleBuilder ruleBuilder = (LoggingRuleBuilder) OrderedSPILoader.getServices(GlobalRuleBuilder.class, Collections.singleton(ruleConfig)).get(ruleConfig); - LoggingRule actual = ruleBuilder.build(ruleConfig, Collections.emptyMap(), props); + LoggingRule actual = ruleBuilder.build(ruleConfig, Collections.emptyList(), props); assertThat(actual.getConfiguration(), is(ruleConfig)); assertThat(logger.getProps().getProperty(LoggingConstants.SQL_LOG_ENABLE), is(Boolean.TRUE.toString())); assertThat(logger.getProps().getProperty(LoggingConstants.SQL_LOG_SIMPLE), is(Boolean.TRUE.toString())); @@ -58,7 +58,7 @@ void assertBuildWhenSyncRuleToProperties() { LoggingRuleConfiguration ruleConfig = new LoggingRuleConfiguration(Collections.singleton(logger), Collections.emptyList()); ConfigurationProperties props = new ConfigurationProperties(new Properties()); LoggingRuleBuilder ruleBuilder = (LoggingRuleBuilder) OrderedSPILoader.getServices(GlobalRuleBuilder.class, Collections.singleton(ruleConfig)).get(ruleConfig); - LoggingRule actual = ruleBuilder.build(ruleConfig, Collections.emptyMap(), props); + LoggingRule actual = ruleBuilder.build(ruleConfig, Collections.emptyList(), props); assertThat(actual.getConfiguration(), is(ruleConfig)); assertThat(props.getProps().getProperty(LoggingConstants.SQL_SHOW), is(Boolean.TRUE.toString())); assertThat(props.getProps().getProperty(LoggingConstants.SQL_SIMPLE), is(Boolean.TRUE.toString())); @@ -70,7 +70,7 @@ void assertBuildWhenSyncNothing() { LoggingRuleConfiguration ruleConfig = new LoggingRuleConfiguration(Collections.singleton(logger), Collections.emptyList()); ConfigurationProperties props = new ConfigurationProperties(new Properties()); LoggingRuleBuilder ruleBuilder = (LoggingRuleBuilder) OrderedSPILoader.getServices(GlobalRuleBuilder.class, Collections.singleton(ruleConfig)).get(ruleConfig); - LoggingRule actual = ruleBuilder.build(ruleConfig, Collections.emptyMap(), props); + LoggingRule actual = ruleBuilder.build(ruleConfig, Collections.emptyList(), props); assertThat(actual.getConfiguration(), is(ruleConfig)); assertFalse(logger.getProps().containsKey(LoggingConstants.SQL_LOG_ENABLE)); assertFalse(logger.getProps().containsKey(LoggingConstants.SQL_LOG_SIMPLE)); diff --git a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/rule/SQLFederationRule.java b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/rule/SQLFederationRule.java index 6fffda59320d7..6db0387b068cf 100644 --- a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/rule/SQLFederationRule.java +++ b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/rule/SQLFederationRule.java @@ -25,7 +25,7 @@ import org.apache.shardingsphere.sqlfederation.optimizer.context.OptimizerContext; import org.apache.shardingsphere.sqlfederation.optimizer.context.OptimizerContextFactory; -import java.util.Map; +import java.util.Collection; import java.util.concurrent.atomic.AtomicReference; /** @@ -38,13 +38,13 @@ public final class SQLFederationRule implements GlobalRule { private final AtomicReference optimizerContext; - public SQLFederationRule(final SQLFederationRuleConfiguration ruleConfig, final Map databases) { + public SQLFederationRule(final SQLFederationRuleConfiguration ruleConfig, final Collection databases) { configuration = ruleConfig; optimizerContext = new AtomicReference<>(OptimizerContextFactory.create(databases)); } @Override - public void refresh(final Map databases, final GlobalRuleChangedType changedType) { + public void refresh(final Collection databases, final GlobalRuleChangedType changedType) { optimizerContext.set(OptimizerContextFactory.create(databases)); } diff --git a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/rule/builder/SQLFederationRuleBuilder.java b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/rule/builder/SQLFederationRuleBuilder.java index 347b9b644fcde..a9459ee05dfcc 100644 --- a/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/rule/builder/SQLFederationRuleBuilder.java +++ b/kernel/sql-federation/core/src/main/java/org/apache/shardingsphere/sqlfederation/rule/builder/SQLFederationRuleBuilder.java @@ -25,7 +25,7 @@ import org.apache.shardingsphere.sqlfederation.constant.SQLFederationOrder; import org.apache.shardingsphere.sqlfederation.rule.SQLFederationRule; -import java.util.Map; +import java.util.Collection; /** * SQL federation rule builder. @@ -33,7 +33,7 @@ public final class SQLFederationRuleBuilder implements GlobalRuleBuilder { @Override - public GlobalRule build(final SQLFederationRuleConfiguration ruleConfig, final Map databases, final ConfigurationProperties props) { + public GlobalRule build(final SQLFederationRuleConfiguration ruleConfig, final Collection databases, final ConfigurationProperties props) { return new SQLFederationRule(ruleConfig, databases); } diff --git a/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/engine/SQLFederationEngineTest.java b/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/engine/SQLFederationEngineTest.java index d1b5438505d26..6b36a079c84a4 100644 --- a/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/engine/SQLFederationEngineTest.java +++ b/kernel/sql-federation/core/src/test/java/org/apache/shardingsphere/sqlfederation/engine/SQLFederationEngineTest.java @@ -62,7 +62,7 @@ class SQLFederationEngineTest { @Test void assertDecideWhenSelectStatementContainsSystemSchema() throws SQLException { Collection globalRules = - Collections.singleton(new SQLFederationRule(new SQLFederationRuleConfiguration(false, false, mock(CacheOption.class)), Collections.emptyMap())); + Collections.singleton(new SQLFederationRule(new SQLFederationRuleConfiguration(false, false, mock(CacheOption.class)), Collections.emptyList())); SelectStatementContext sqlStatementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS); when(sqlStatementContext.getDatabaseType()).thenReturn(databaseType); when(sqlStatementContext.getTablesContext().getDatabaseNames()).thenReturn(Collections.singletonList("information_schema")); @@ -87,7 +87,7 @@ private SQLFederationEngine createSQLFederationEngine(final Collection globalRules = Collections - .singletonList(new SQLFederationRule(new SQLFederationRuleConfiguration(false, false, mock(CacheOption.class)), Collections.emptyMap())); + .singletonList(new SQLFederationRule(new SQLFederationRuleConfiguration(false, false, mock(CacheOption.class)), Collections.emptyList())); SQLFederationEngine engine = createSQLFederationEngine(globalRules, Collections.emptyList()); RuleMetaData globalRuleMetaData = new RuleMetaData(globalRules); assertFalse(engine.decide(mock(QueryContext.class), globalRuleMetaData)); @@ -97,7 +97,7 @@ void assertDecideWhenNotConfigSqlFederationEnabled() throws SQLException { @Test void assertDecideWhenConfigAllQueryUseSQLFederation() throws SQLException { Collection globalRules = - Collections.singletonList(new SQLFederationRule(new SQLFederationRuleConfiguration(true, true, mock(CacheOption.class)), Collections.emptyMap())); + Collections.singletonList(new SQLFederationRule(new SQLFederationRuleConfiguration(true, true, mock(CacheOption.class)), Collections.emptyList())); ShardingSphereDatabase database = new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, databaseType, mock(ResourceMetaData.class, RETURNS_DEEP_STUBS), new RuleMetaData(globalRules), Collections.emptyList()); SelectStatementContext selectStatementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS); @@ -115,7 +115,7 @@ void assertDecideWhenConfigAllQueryUseSQLFederation() throws SQLException { @Test void assertDecideWhenExecuteNotSelectStatement() throws SQLException { Collection globalRules = - Collections.singletonList(new SQLFederationRule(new SQLFederationRuleConfiguration(true, false, mock(CacheOption.class)), Collections.emptyMap())); + Collections.singletonList(new SQLFederationRule(new SQLFederationRuleConfiguration(true, false, mock(CacheOption.class)), Collections.emptyList())); SQLFederationEngine engine = createSQLFederationEngine(globalRules, Collections.emptyList()); RuleMetaData globalRuleMetaData = new RuleMetaData(globalRules); assertFalse(engine.decide(mock(QueryContext.class), globalRuleMetaData)); @@ -125,7 +125,7 @@ void assertDecideWhenExecuteNotSelectStatement() throws SQLException { @Test void assertDecideWhenConfigSingleMatchedRule() throws SQLException { Collection globalRules = - Collections.singletonList(new SQLFederationRule(new SQLFederationRuleConfiguration(true, false, mock(CacheOption.class)), Collections.emptyMap())); + Collections.singletonList(new SQLFederationRule(new SQLFederationRuleConfiguration(true, false, mock(CacheOption.class)), Collections.emptyList())); Collection databaseRules = Collections.singletonList(new SQLFederationDeciderRuleMatchFixture()); ShardingSphereDatabase database = new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, databaseType, mock(ResourceMetaData.class, RETURNS_DEEP_STUBS), new RuleMetaData(globalRules), Collections.emptyList()); @@ -144,7 +144,7 @@ void assertDecideWhenConfigSingleMatchedRule() throws SQLException { @Test void assertDecideWhenConfigSingleNotMatchedRule() throws SQLException { Collection globalRules = - Collections.singletonList(new SQLFederationRule(new SQLFederationRuleConfiguration(true, false, mock(CacheOption.class)), Collections.emptyMap())); + Collections.singletonList(new SQLFederationRule(new SQLFederationRuleConfiguration(true, false, mock(CacheOption.class)), Collections.emptyList())); Collection databaseRules = Collections.singletonList(new SQLFederationDeciderRuleNotMatchFixture()); ShardingSphereDatabase database = new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, databaseType, mock(ResourceMetaData.class, RETURNS_DEEP_STUBS), new RuleMetaData(databaseRules), Collections.emptyList()); @@ -162,7 +162,7 @@ void assertDecideWhenConfigSingleNotMatchedRule() throws SQLException { @Test void assertDecideWhenConfigMultiRule() throws SQLException { Collection globalRules = - Collections.singletonList(new SQLFederationRule(new SQLFederationRuleConfiguration(true, false, mock(CacheOption.class)), Collections.emptyMap())); + Collections.singletonList(new SQLFederationRule(new SQLFederationRuleConfiguration(true, false, mock(CacheOption.class)), Collections.emptyList())); Collection databaseRules = Arrays.asList(new SQLFederationDeciderRuleNotMatchFixture(), new SQLFederationDeciderRuleMatchFixture()); ShardingSphereDatabase database = new ShardingSphereDatabase(DefaultDatabase.LOGIC_NAME, diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/OptimizerContextFactory.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/OptimizerContextFactory.java index 5f2a2ad1bae53..75b76e8c31bb5 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/OptimizerContextFactory.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/OptimizerContextFactory.java @@ -29,6 +29,7 @@ import org.apache.shardingsphere.sqlfederation.optimizer.context.planner.OptimizerMetaData; import org.apache.shardingsphere.sqlfederation.optimizer.context.planner.OptimizerMetaDataFactory; +import java.util.Collection; import java.util.Map; import java.util.Properties; @@ -44,7 +45,7 @@ public final class OptimizerContextFactory { * @param databases databases * @return created optimizer context */ - public static OptimizerContext create(final Map databases) { + public static OptimizerContext create(final Collection databases) { Map parserContexts = OptimizerParserContextFactory.create(databases); // TODO consider to use sqlParserRule in global rule SQLParserRule sqlParserRule = new SQLParserRuleBuilder().build(new DefaultSQLParserRuleConfigurationBuilder().build(), databases, new ConfigurationProperties(new Properties())); diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/OptimizerParserContextFactory.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/OptimizerParserContextFactory.java index 5e029871accf6..9899ce4f0483d 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/OptimizerParserContextFactory.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/parser/OptimizerParserContextFactory.java @@ -24,8 +24,8 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.sqlfederation.optimizer.context.parser.dialect.OptimizerSQLPropertiesBuilder; +import java.util.Collection; import java.util.Map; -import java.util.Map.Entry; /** * Optimizer parser context factory. @@ -39,11 +39,11 @@ public final class OptimizerParserContextFactory { * @param databases databases * @return created optimizer parser context map */ - public static Map create(final Map databases) { + public static Map create(final Collection databases) { Map result = new CaseInsensitiveMap<>(); - for (Entry entry : databases.entrySet()) { - DatabaseType databaseType = entry.getValue().getProtocolType(); - result.put(entry.getKey(), new OptimizerParserContext(databaseType, new OptimizerSQLPropertiesBuilder(databaseType).build())); + for (ShardingSphereDatabase each : databases) { + DatabaseType databaseType = each.getProtocolType(); + result.put(each.getName(), new OptimizerParserContext(databaseType, new OptimizerSQLPropertiesBuilder(databaseType).build())); } return result; } diff --git a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/planner/OptimizerMetaDataFactory.java b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/planner/OptimizerMetaDataFactory.java index 4a5a800648cca..115d503d0fa4c 100644 --- a/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/planner/OptimizerMetaDataFactory.java +++ b/kernel/sql-federation/optimizer/src/main/java/org/apache/shardingsphere/sqlfederation/optimizer/context/planner/OptimizerMetaDataFactory.java @@ -27,8 +27,8 @@ import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema; import org.apache.shardingsphere.sqlfederation.optimizer.metadata.schema.SQLFederationSchema; +import java.util.Collection; import java.util.Map; -import java.util.Map.Entry; /** * Optimizer meta data factory. @@ -44,10 +44,10 @@ public final class OptimizerMetaDataFactory { * @param databases databases * @return created optimizer planner context map */ - public static Map create(final Map databases) { + public static Map create(final Collection databases) { Map result = new CaseInsensitiveMap<>(databases.size(), 1F); - for (Entry entry : databases.entrySet()) { - result.put(entry.getKey(), create(entry.getValue())); + for (ShardingSphereDatabase each : databases) { + result.put(each.getName(), create(each)); } return result; } diff --git a/kernel/sql-federation/optimizer/src/test/java/org/apache/shardingsphere/sqlfederation/optimizer/context/OptimizerContextTest.java b/kernel/sql-federation/optimizer/src/test/java/org/apache/shardingsphere/sqlfederation/optimizer/context/OptimizerContextTest.java index 5fd485769da9b..4321aa763e730 100644 --- a/kernel/sql-federation/optimizer/src/test/java/org/apache/shardingsphere/sqlfederation/optimizer/context/OptimizerContextTest.java +++ b/kernel/sql-federation/optimizer/src/test/java/org/apache/shardingsphere/sqlfederation/optimizer/context/OptimizerContextTest.java @@ -17,7 +17,6 @@ package org.apache.shardingsphere.sqlfederation.optimizer.context; -import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.database.core.type.DatabaseType; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader; @@ -38,24 +37,25 @@ class OptimizerContextTest { @Test void assertGetSqlParserRule() { - OptimizerContext actual = OptimizerContextFactory.create(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, createShardingSphereDatabase())); + OptimizerContext actual = OptimizerContextFactory.create(Collections.singleton(mockDatabase())); assertThat(actual.getSqlParserRule(), instanceOf(SQLParserRule.class)); } @Test void assertGetParserContext() { - OptimizerContext actual = OptimizerContextFactory.create(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, createShardingSphereDatabase())); - assertThat(actual.getParserContext(DefaultDatabase.LOGIC_NAME), instanceOf(OptimizerParserContext.class)); + OptimizerContext actual = OptimizerContextFactory.create(Collections.singleton(mockDatabase())); + assertThat(actual.getParserContext("foo_db"), instanceOf(OptimizerParserContext.class)); } @Test void assertGetOptimizerMetaData() { - OptimizerContext actual = OptimizerContextFactory.create(Collections.singletonMap(DefaultDatabase.LOGIC_NAME, createShardingSphereDatabase())); - assertThat(actual.getMetaData(DefaultDatabase.LOGIC_NAME), instanceOf(OptimizerMetaData.class)); + OptimizerContext actual = OptimizerContextFactory.create(Collections.singleton(mockDatabase())); + assertThat(actual.getMetaData("foo_db"), instanceOf(OptimizerMetaData.class)); } - private ShardingSphereDatabase createShardingSphereDatabase() { + private ShardingSphereDatabase mockDatabase() { ShardingSphereDatabase result = mock(ShardingSphereDatabase.class, RETURNS_DEEP_STUBS); + when(result.getName()).thenReturn("foo_db"); when(result.getProtocolType()).thenReturn(TypedSPILoader.getService(DatabaseType.class, "MySQL")); return result; } diff --git a/kernel/sql-parser/core/src/main/java/org/apache/shardingsphere/parser/rule/builder/SQLParserRuleBuilder.java b/kernel/sql-parser/core/src/main/java/org/apache/shardingsphere/parser/rule/builder/SQLParserRuleBuilder.java index b02b0e2c16783..31291891ddb4b 100644 --- a/kernel/sql-parser/core/src/main/java/org/apache/shardingsphere/parser/rule/builder/SQLParserRuleBuilder.java +++ b/kernel/sql-parser/core/src/main/java/org/apache/shardingsphere/parser/rule/builder/SQLParserRuleBuilder.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.parser.constant.SQLParserOrder; import org.apache.shardingsphere.parser.rule.SQLParserRule; -import java.util.Map; +import java.util.Collection; /** * SQL parser rule builder. @@ -32,7 +32,7 @@ public final class SQLParserRuleBuilder implements GlobalRuleBuilder { @Override - public SQLParserRule build(final SQLParserRuleConfiguration ruleConfig, final Map databases, final ConfigurationProperties props) { + public SQLParserRule build(final SQLParserRuleConfiguration ruleConfig, final Collection databases, final ConfigurationProperties props) { return new SQLParserRule(ruleConfig); } diff --git a/kernel/sql-parser/core/src/test/java/org/apache/shardingsphere/parser/rule/builder/SQLParserRuleBuilderTest.java b/kernel/sql-parser/core/src/test/java/org/apache/shardingsphere/parser/rule/builder/SQLParserRuleBuilderTest.java index 3477814873f78..6688254a1fb41 100644 --- a/kernel/sql-parser/core/src/test/java/org/apache/shardingsphere/parser/rule/builder/SQLParserRuleBuilderTest.java +++ b/kernel/sql-parser/core/src/test/java/org/apache/shardingsphere/parser/rule/builder/SQLParserRuleBuilderTest.java @@ -35,7 +35,7 @@ class SQLParserRuleBuilderTest { @Test void assertBuild() { SQLParserRuleConfiguration ruleConfig = new SQLParserRuleConfiguration(new CacheOption(2, 5L), new CacheOption(4, 7L)); - SQLParserRule actualResult = new SQLParserRuleBuilder().build(ruleConfig, Collections.emptyMap(), new ConfigurationProperties(new Properties())); + SQLParserRule actualResult = new SQLParserRuleBuilder().build(ruleConfig, Collections.emptyList(), new ConfigurationProperties(new Properties())); assertThat(actualResult.getConfiguration(), is(ruleConfig)); assertThat(actualResult.getSqlStatementCache().getInitialCapacity(), is(4)); assertThat(actualResult.getSqlStatementCache().getMaximumSize(), is(7L)); diff --git a/kernel/sql-translator/core/src/main/java/org/apache/shardingsphere/sqltranslator/rule/builder/SQLTranslatorRuleBuilder.java b/kernel/sql-translator/core/src/main/java/org/apache/shardingsphere/sqltranslator/rule/builder/SQLTranslatorRuleBuilder.java index b952eeacdef16..0c4fc94eabf33 100644 --- a/kernel/sql-translator/core/src/main/java/org/apache/shardingsphere/sqltranslator/rule/builder/SQLTranslatorRuleBuilder.java +++ b/kernel/sql-translator/core/src/main/java/org/apache/shardingsphere/sqltranslator/rule/builder/SQLTranslatorRuleBuilder.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.sqltranslator.constant.SQLTranslatorOrder; import org.apache.shardingsphere.sqltranslator.rule.SQLTranslatorRule; -import java.util.Map; +import java.util.Collection; /** * SQL translator rule builder. @@ -32,7 +32,7 @@ public final class SQLTranslatorRuleBuilder implements GlobalRuleBuilder { @Override - public SQLTranslatorRule build(final SQLTranslatorRuleConfiguration ruleConfig, final Map databases, final ConfigurationProperties props) { + public SQLTranslatorRule build(final SQLTranslatorRuleConfiguration ruleConfig, final Collection databases, final ConfigurationProperties props) { return new SQLTranslatorRule(ruleConfig); } diff --git a/kernel/time-service/core/src/main/java/org/apache/shardingsphere/timeservice/core/rule/builder/TimestampServiceRuleBuilder.java b/kernel/time-service/core/src/main/java/org/apache/shardingsphere/timeservice/core/rule/builder/TimestampServiceRuleBuilder.java index 3f09c1947af24..215cf359c4e68 100644 --- a/kernel/time-service/core/src/main/java/org/apache/shardingsphere/timeservice/core/rule/builder/TimestampServiceRuleBuilder.java +++ b/kernel/time-service/core/src/main/java/org/apache/shardingsphere/timeservice/core/rule/builder/TimestampServiceRuleBuilder.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.timeservice.core.rule.TimestampServiceRule; import org.apache.shardingsphere.timeservice.core.rule.constant.TimestampServiceOrder; -import java.util.Map; +import java.util.Collection; /** * Timestamp service rule builder. @@ -32,7 +32,7 @@ public final class TimestampServiceRuleBuilder implements GlobalRuleBuilder { @Override - public TimestampServiceRule build(final TimestampServiceRuleConfiguration ruleConfig, final Map databases, final ConfigurationProperties props) { + public TimestampServiceRule build(final TimestampServiceRuleConfiguration ruleConfig, final Collection databases, final ConfigurationProperties props) { return new TimestampServiceRule(ruleConfig); } diff --git a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionRule.java b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionRule.java index 892bb20ce98bf..f156785119478 100644 --- a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionRule.java +++ b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/rule/TransactionRule.java @@ -35,9 +35,9 @@ import org.apache.shardingsphere.transaction.constant.TransactionOrder; import javax.sql.DataSource; +import java.util.Collection; import java.util.LinkedHashMap; import java.util.Map; -import java.util.Map.Entry; import java.util.Properties; import java.util.concurrent.atomic.AtomicReference; @@ -61,7 +61,7 @@ public final class TransactionRule implements GlobalRule, AutoCloseable { private final RuleAttributes attributes; - public TransactionRule(final TransactionRuleConfiguration ruleConfig, final Map databases) { + public TransactionRule(final TransactionRuleConfiguration ruleConfig, final Collection databases) { configuration = ruleConfig; defaultType = TransactionType.valueOf(ruleConfig.getDefaultType().toUpperCase()); providerType = ruleConfig.getProviderType(); @@ -70,18 +70,17 @@ public TransactionRule(final TransactionRuleConfiguration ruleConfig, final Map< attributes = new RuleAttributes(); } - private synchronized ShardingSphereTransactionManagerEngine createTransactionManagerEngine(final Map databases) { + private synchronized ShardingSphereTransactionManagerEngine createTransactionManagerEngine(final Collection databases) { ShardingSphereTransactionManagerEngine result = new ShardingSphereTransactionManagerEngine(defaultType); if (databases.isEmpty()) { return result; } Map databaseTypes = new LinkedHashMap<>(databases.size(), 1F); Map dataSourceMap = new LinkedHashMap<>(databases.size(), 1F); - for (Entry entry : databases.entrySet()) { - ShardingSphereDatabase database = entry.getValue(); - database.getResourceMetaData().getStorageUnits().forEach((key, value) -> { - databaseTypes.put(database.getName() + "." + key, value.getStorageType()); - dataSourceMap.put(database.getName() + "." + key, value.getDataSource()); + for (ShardingSphereDatabase each : databases) { + each.getResourceMetaData().getStorageUnits().forEach((key, value) -> { + databaseTypes.put(each.getName() + "." + key, value.getStorageType()); + dataSourceMap.put(each.getName() + "." + key, value.getDataSource()); }); } result.init(databaseTypes, dataSourceMap, providerType); @@ -120,7 +119,7 @@ private boolean isWriteDMLStatement(final SQLStatement sqlStatement) { } @Override - public void refresh(final Map databases, final GlobalRuleChangedType changedType) { + public void refresh(final Collection databases, final GlobalRuleChangedType changedType) { if (GlobalRuleChangedType.DATABASE_CHANGED != changedType) { return; } diff --git a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/rule/builder/TransactionRuleBuilder.java b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/rule/builder/TransactionRuleBuilder.java index 1871a5f3ac3c8..a2f0571031e38 100644 --- a/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/rule/builder/TransactionRuleBuilder.java +++ b/kernel/transaction/core/src/main/java/org/apache/shardingsphere/transaction/rule/builder/TransactionRuleBuilder.java @@ -24,7 +24,7 @@ import org.apache.shardingsphere.transaction.constant.TransactionOrder; import org.apache.shardingsphere.transaction.rule.TransactionRule; -import java.util.Map; +import java.util.Collection; /** * Transaction rule builder. @@ -32,7 +32,7 @@ public final class TransactionRuleBuilder implements GlobalRuleBuilder { @Override - public TransactionRule build(final TransactionRuleConfiguration ruleConfig, final Map databases, final ConfigurationProperties props) { + public TransactionRule build(final TransactionRuleConfiguration ruleConfig, final Collection databases, final ConfigurationProperties props) { return new TransactionRule(ruleConfig, databases); } diff --git a/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/rule/TransactionRuleTest.java b/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/rule/TransactionRuleTest.java index 4d1ab1ab3503f..abfa430c67bb7 100644 --- a/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/rule/TransactionRuleTest.java +++ b/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/rule/TransactionRuleTest.java @@ -58,27 +58,27 @@ class TransactionRuleTest { @Test void assertRefreshWithNotDatabaseChange() { - TransactionRule actual = new TransactionRule(new TransactionRuleConfiguration("XA", "Atomikos", new Properties()), Collections.emptyMap()); - actual.refresh(Collections.singletonMap(BAR_DB, createAddDatabase()), GlobalRuleChangedType.SCHEMA_CHANGED); + TransactionRule actual = new TransactionRule(new TransactionRuleConfiguration("XA", "Atomikos", new Properties()), Collections.emptyList()); + actual.refresh(Collections.singleton(createAddDatabase()), GlobalRuleChangedType.SCHEMA_CHANGED); assertThat(actual.getResource().getTransactionManager(TransactionType.XA), instanceOf(ShardingSphereTransactionManagerFixture.class)); } @Test void assertRefreshWithDatabaseChange() { - TransactionRule actual = new TransactionRule(new TransactionRuleConfiguration("XA", "Atomikos", new Properties()), Collections.singletonMap(FOO_DB, createDatabase())); - actual.refresh(Collections.singletonMap(BAR_DB, createAddDatabase()), GlobalRuleChangedType.DATABASE_CHANGED); + TransactionRule actual = new TransactionRule(new TransactionRuleConfiguration("XA", "Atomikos", new Properties()), Collections.singleton(createDatabase())); + actual.refresh(Collections.singleton(createAddDatabase()), GlobalRuleChangedType.DATABASE_CHANGED); assertThat(actual.getResource().getTransactionManager(TransactionType.XA), instanceOf(ShardingSphereTransactionManagerFixture.class)); } @Test void assertIsNotImplicitCommitTransactionWhenNotAutoCommit() { - assertFalse(new TransactionRule(new TransactionRuleConfiguration("XA", "Atomikos", new Properties()), Collections.emptyMap()) + assertFalse(new TransactionRule(new TransactionRuleConfiguration("XA", "Atomikos", new Properties()), Collections.emptyList()) .isImplicitCommitTransaction(mock(ExecutionContext.class), mock(ConnectionTransaction.class), false)); } @Test void assertIsNotImplicitCommitTransactionWhenDefaultTypeIsNotDistributedTransaction() { - assertFalse(new TransactionRule(new TransactionRuleConfiguration("LOCAL", null, new Properties()), Collections.emptyMap()) + assertFalse(new TransactionRule(new TransactionRuleConfiguration("LOCAL", null, new Properties()), Collections.emptyList()) .isImplicitCommitTransaction(mock(ExecutionContext.class), mock(ConnectionTransaction.class), true)); } @@ -86,7 +86,7 @@ void assertIsNotImplicitCommitTransactionWhenDefaultTypeIsNotDistributedTransact void assertIsNotImplicitCommitTransactionWhenInDistributedTransaction() { ConnectionTransaction connectionTransaction = mock(ConnectionTransaction.class); when(connectionTransaction.isInDistributedTransaction()).thenReturn(true); - assertFalse(new TransactionRule(new TransactionRuleConfiguration("XA", null, new Properties()), Collections.emptyMap()) + assertFalse(new TransactionRule(new TransactionRuleConfiguration("XA", null, new Properties()), Collections.emptyList()) .isImplicitCommitTransaction(mock(ExecutionContext.class), connectionTransaction, true)); } @@ -94,7 +94,7 @@ void assertIsNotImplicitCommitTransactionWhenInDistributedTransaction() { void assertIsNotImplicitCommitTransactionWhenQuery() { ExecutionContext executionContext = mock(ExecutionContext.class, RETURNS_DEEP_STUBS); when(executionContext.getSqlStatementContext().getSqlStatement()).thenReturn(mock(SelectStatement.class)); - assertFalse(new TransactionRule(new TransactionRuleConfiguration("XA", null, new Properties()), Collections.emptyMap()) + assertFalse(new TransactionRule(new TransactionRuleConfiguration("XA", null, new Properties()), Collections.emptyList()) .isImplicitCommitTransaction(executionContext, mock(ConnectionTransaction.class), true)); } @@ -103,7 +103,7 @@ void assertIsNotImplicitCommitTransactionForSingleExecutionUnit() { ExecutionContext executionContext = mock(ExecutionContext.class, RETURNS_DEEP_STUBS); when(executionContext.getSqlStatementContext().getSqlStatement()).thenReturn(mock(UpdateStatement.class)); when(executionContext.getExecutionUnits()).thenReturn(Collections.singleton(mock(ExecutionUnit.class))); - assertFalse(new TransactionRule(new TransactionRuleConfiguration("XA", null, new Properties()), Collections.emptyMap()) + assertFalse(new TransactionRule(new TransactionRuleConfiguration("XA", null, new Properties()), Collections.emptyList()) .isImplicitCommitTransaction(executionContext, mock(ConnectionTransaction.class), true)); } @@ -112,13 +112,13 @@ void assertIsImplicitCommitTransaction() { ExecutionContext executionContext = mock(ExecutionContext.class, RETURNS_DEEP_STUBS); when(executionContext.getSqlStatementContext().getSqlStatement()).thenReturn(mock(UpdateStatement.class)); when(executionContext.getExecutionUnits()).thenReturn(Arrays.asList(mock(ExecutionUnit.class), mock(ExecutionUnit.class))); - assertTrue(new TransactionRule(new TransactionRuleConfiguration("XA", null, new Properties()), Collections.emptyMap()) + assertTrue(new TransactionRule(new TransactionRuleConfiguration("XA", null, new Properties()), Collections.emptyList()) .isImplicitCommitTransaction(executionContext, mock(ConnectionTransaction.class), true)); } @Test void assertClose() { - TransactionRule actual = new TransactionRule(new TransactionRuleConfiguration("XA", "Atomikos", new Properties()), Collections.singletonMap(FOO_DB, createDatabase())); + TransactionRule actual = new TransactionRule(new TransactionRuleConfiguration("XA", "Atomikos", new Properties()), Collections.singleton(createDatabase())); actual.close(); assertThat(actual.getResource().getTransactionManager(TransactionType.XA), instanceOf(ShardingSphereTransactionManagerFixture.class)); } @@ -127,7 +127,7 @@ private ShardingSphereDatabase createDatabase() { ShardingSphereDatabase result = mock(ShardingSphereDatabase.class); ResourceMetaData resourceMetaData = createResourceMetaData(); when(result.getResourceMetaData()).thenReturn(resourceMetaData); - when(result.getName()).thenReturn("sharding_db"); + when(result.getName()).thenReturn(FOO_DB); return result; } diff --git a/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/rule/builder/TransactionRuleBuilderTest.java b/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/rule/builder/TransactionRuleBuilderTest.java index d03efb8c08a60..37e6eb644f637 100644 --- a/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/rule/builder/TransactionRuleBuilderTest.java +++ b/kernel/transaction/core/src/test/java/org/apache/shardingsphere/transaction/rule/builder/TransactionRuleBuilderTest.java @@ -18,7 +18,6 @@ package org.apache.shardingsphere.transaction.rule.builder; import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; -import org.apache.shardingsphere.infra.database.core.DefaultDatabase; import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; @@ -45,7 +44,7 @@ void assertBuild() { TransactionRuleConfiguration ruleConfig = new TransactionRuleConfiguration("LOCAL", "provider", new Properties()); ShardingSphereDatabase database = new ShardingSphereDatabase("logic_db", null, new ResourceMetaData(createDataSourceMap()), new RuleMetaData(Collections.singletonList(mock(ShardingSphereRule.class))), Collections.singleton(new ShardingSphereSchema("test"))); - try (TransactionRule rule = new TransactionRuleBuilder().build(ruleConfig, Collections.singletonMap(DefaultDatabase.LOGIC_NAME, database), mock(ConfigurationProperties.class))) { + try (TransactionRule rule = new TransactionRuleBuilder().build(ruleConfig, Collections.singleton(database), mock(ConfigurationProperties.class))) { assertNotNull(rule.getConfiguration()); } } diff --git a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/SchemaMetaDataManager.java b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/SchemaMetaDataManager.java index c14a98957c8be..bd9138e1bdfd7 100644 --- a/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/SchemaMetaDataManager.java +++ b/mode/core/src/main/java/org/apache/shardingsphere/mode/metadata/manager/SchemaMetaDataManager.java @@ -91,7 +91,7 @@ public synchronized void addSchema(final String databaseName, final String schem return; } database.addSchema(new ShardingSphereSchema(schemaName)); - metaData.getGlobalRuleMetaData().getRules().forEach(each -> ((GlobalRule) each).refresh(metaData.getDatabases(), GlobalRuleChangedType.SCHEMA_CHANGED)); + metaData.getGlobalRuleMetaData().getRules().forEach(each -> ((GlobalRule) each).refresh(metaData.getAllDatabases(), GlobalRuleChangedType.SCHEMA_CHANGED)); } /** @@ -107,7 +107,7 @@ public synchronized void dropSchema(final String databaseName, final String sche return; } database.dropSchema(schemaName); - metaData.getGlobalRuleMetaData().getRules().forEach(each -> ((GlobalRule) each).refresh(metaData.getDatabases(), GlobalRuleChangedType.SCHEMA_CHANGED)); + metaData.getGlobalRuleMetaData().getRules().forEach(each -> ((GlobalRule) each).refresh(metaData.getAllDatabases(), GlobalRuleChangedType.SCHEMA_CHANGED)); } /** @@ -126,7 +126,7 @@ public synchronized void alterSchema(final String databaseName, final String sch Optional.ofNullable(toBeChangedTable).ifPresent(optional -> alterTable(databaseName, schemaName, optional)); Optional.ofNullable(toBeChangedView).ifPresent(optional -> alterView(databaseName, schemaName, optional)); if (null != toBeChangedTable || null != toBeChangedView) { - metaData.getGlobalRuleMetaData().getRules().forEach(each -> ((GlobalRule) each).refresh(metaData.getDatabases(), GlobalRuleChangedType.SCHEMA_CHANGED)); + metaData.getGlobalRuleMetaData().getRules().forEach(each -> ((GlobalRule) each).refresh(metaData.getAllDatabases(), GlobalRuleChangedType.SCHEMA_CHANGED)); } } @@ -146,7 +146,7 @@ public synchronized void alterSchema(final String databaseName, final String sch Optional.ofNullable(toBeDeletedTableName).ifPresent(optional -> dropTable(databaseName, schemaName, optional)); Optional.ofNullable(toBeDeletedViewName).ifPresent(optional -> dropView(databaseName, schemaName, optional)); if (!Strings.isNullOrEmpty(toBeDeletedTableName) || !Strings.isNullOrEmpty(toBeDeletedViewName)) { - metaData.getGlobalRuleMetaData().getRules().forEach(each -> ((GlobalRule) each).refresh(metaData.getDatabases(), GlobalRuleChangedType.SCHEMA_CHANGED)); + metaData.getGlobalRuleMetaData().getRules().forEach(each -> ((GlobalRule) each).refresh(metaData.getAllDatabases(), GlobalRuleChangedType.SCHEMA_CHANGED)); } } 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/StandaloneMetaDataManagerPersistService.java index 0cd8d5dcd02b7..f7058181afda7 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/StandaloneMetaDataManagerPersistService.java @@ -94,7 +94,7 @@ public void createSchema(final String databaseName, final String schemaName) { ShardingSphereMetaData metaData = metaDataContextManager.getMetaDataContexts().get().getMetaData(); ShardingSphereDatabase database = metaData.getDatabase(databaseName); database.addSchema(new ShardingSphereSchema(schemaName)); - metaData.getGlobalRuleMetaData().getRules().forEach(each -> ((GlobalRule) each).refresh(metaData.getDatabases(), GlobalRuleChangedType.SCHEMA_CHANGED)); + metaData.getGlobalRuleMetaData().getRules().forEach(each -> ((GlobalRule) each).refresh(metaData.getAllDatabases(), GlobalRuleChangedType.SCHEMA_CHANGED)); metaDataPersistService.getDatabaseMetaDataFacade().getSchema().add(databaseName, schemaName); } @@ -104,7 +104,7 @@ public void alterSchema(final AlterSchemaPOJO alterSchemaPOJO) { ShardingSphereDatabase database = metaData.getDatabase(alterSchemaPOJO.getDatabaseName()); putSchemaMetaData(database, alterSchemaPOJO.getSchemaName(), alterSchemaPOJO.getRenameSchemaName(), alterSchemaPOJO.getLogicDataSourceName()); removeSchemaMetaData(database, alterSchemaPOJO.getSchemaName()); - metaData.getGlobalRuleMetaData().getRules().forEach(each -> ((GlobalRule) each).refresh(metaData.getDatabases(), GlobalRuleChangedType.SCHEMA_CHANGED)); + metaData.getGlobalRuleMetaData().getRules().forEach(each -> ((GlobalRule) each).refresh(metaData.getAllDatabases(), GlobalRuleChangedType.SCHEMA_CHANGED)); ShardingSphereSchema alteredSchema = database.getSchema(alterSchemaPOJO.getRenameSchemaName()); String databaseName = alterSchemaPOJO.getDatabaseName(); String alteredSchemaName = alterSchemaPOJO.getRenameSchemaName(); @@ -202,7 +202,7 @@ public void dropSchema(final String databaseName, final Collection schem tobeRemovedSchemas.add(each.toLowerCase()); } removeDataNode(database.getRuleMetaData().getAttributes(MutableDataNodeRuleAttribute.class), new HashSet<>(tobeRemovedSchemas), new HashSet<>(tobeRemovedTables)); - metaData.getGlobalRuleMetaData().getRules().forEach(each -> ((GlobalRule) each).refresh(metaData.getDatabases(), GlobalRuleChangedType.SCHEMA_CHANGED)); + metaData.getGlobalRuleMetaData().getRules().forEach(each -> ((GlobalRule) each).refresh(metaData.getAllDatabases(), GlobalRuleChangedType.SCHEMA_CHANGED)); } @Override @@ -213,7 +213,7 @@ public void alterSchemaMetaData(final AlterSchemaMetaDataPOJO alterSchemaMetaDat ShardingSphereDatabase database = metaData.getDatabase(databaseName); addDataNode(database, alterSchemaMetaDataPOJO.getLogicDataSourceName(), schemaName, alterSchemaMetaDataPOJO.getAlteredTables(), alterSchemaMetaDataPOJO.getAlteredViews()); removeDataNode(database, schemaName, alterSchemaMetaDataPOJO.getDroppedTables(), alterSchemaMetaDataPOJO.getDroppedViews()); - metaData.getGlobalRuleMetaData().getRules().forEach(each -> ((GlobalRule) each).refresh(metaData.getDatabases(), GlobalRuleChangedType.SCHEMA_CHANGED)); + metaData.getGlobalRuleMetaData().getRules().forEach(each -> ((GlobalRule) each).refresh(metaData.getAllDatabases(), GlobalRuleChangedType.SCHEMA_CHANGED)); metaDataPersistService.getDatabaseMetaDataFacade().getTable().persist(databaseName, schemaName, alterSchemaMetaDataPOJO.getAlteredTables()); metaDataPersistService.getDatabaseMetaDataFacade().getView().persist(databaseName, schemaName, alterSchemaMetaDataPOJO.getAlteredViews()); alterSchemaMetaDataPOJO.getDroppedTables().forEach(each -> metaDataPersistService.getDatabaseMetaDataFacade().getTable().drop(databaseName, schemaName, each)); @@ -228,7 +228,7 @@ public void registerStorageUnits(final String databaseName, final Map ((GlobalRule) each).refresh(metaDataContextManager.getMetaDataContexts().get().getMetaData().getDatabases(), GlobalRuleChangedType.DATABASE_CHANGED)); + .forEach(each -> ((GlobalRule) each).refresh(metaDataContextManager.getMetaDataContexts().get().getMetaData().getAllDatabases(), GlobalRuleChangedType.DATABASE_CHANGED)); metaDataContextManager.getMetaDataContexts().get().getMetaData().getDatabase(databaseName).getAllSchemas() .forEach(each -> { if (each.isEmpty()) { @@ -250,7 +250,7 @@ public void alterStorageUnits(final String databaseName, final Map ((GlobalRule) each).refresh(metaDataContextManager.getMetaDataContexts().get().getMetaData().getDatabases(), GlobalRuleChangedType.DATABASE_CHANGED)); + .forEach(each -> ((GlobalRule) each).refresh(metaDataContextManager.getMetaDataContexts().get().getMetaData().getAllDatabases(), GlobalRuleChangedType.DATABASE_CHANGED)); DataSourceUnitPersistService dataSourceService = metaDataPersistService.getDataSourceUnitService(); metaDataPersistService.getMetaDataVersionPersistService() .switchActiveVersion(dataSourceService.persist(databaseName, toBeUpdatedProps)); @@ -346,7 +346,7 @@ public void createTable(final String databaseName, final String schemaName, fina ShardingSphereMetaData metaData = metaDataContextManager.getMetaDataContexts().get().getMetaData(); ShardingSphereDatabase database = metaData.getDatabase(databaseName); addTableToDataNode(database, schemaName, logicDataSourceName, table); - metaData.getGlobalRuleMetaData().getRules().forEach(each -> ((GlobalRule) each).refresh(metaData.getDatabases(), GlobalRuleChangedType.SCHEMA_CHANGED)); + metaData.getGlobalRuleMetaData().getRules().forEach(each -> ((GlobalRule) each).refresh(metaData.getAllDatabases(), GlobalRuleChangedType.SCHEMA_CHANGED)); metaDataPersistService.getDatabaseMetaDataFacade().getTable().persist(databaseName, schemaName, Collections.singleton(table)); } @@ -355,7 +355,7 @@ public void dropTables(final String databaseName, final String schemaName, final ShardingSphereMetaData metaData = metaDataContextManager.getMetaDataContexts().get().getMetaData(); ShardingSphereDatabase database = metaData.getDatabase(databaseName); removeTablesToDataNode(database, schemaName, tableNames); - metaData.getGlobalRuleMetaData().getRules().forEach(each -> ((GlobalRule) each).refresh(metaData.getDatabases(), GlobalRuleChangedType.SCHEMA_CHANGED)); + metaData.getGlobalRuleMetaData().getRules().forEach(each -> ((GlobalRule) each).refresh(metaData.getAllDatabases(), GlobalRuleChangedType.SCHEMA_CHANGED)); tableNames.forEach(each -> metaDataPersistService.getDatabaseMetaDataFacade().getTable().drop(databaseName, schemaName, each)); } diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactoryTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactoryTest.java index ed17922866629..1bb5adb059f00 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactoryTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactoryTest.java @@ -123,7 +123,7 @@ private ContextManager mockContextManager() { RuleMetaData globalRuleMetaData = new RuleMetaData(Arrays.asList( new AuthorityRule(new DefaultAuthorityRuleConfigurationBuilder().build()), new SQLParserRule(new DefaultSQLParserRuleConfigurationBuilder().build()), - new TransactionRule(new DefaultTransactionRuleConfigurationBuilder().build(), Collections.emptyMap()))); + new TransactionRule(new DefaultTransactionRuleConfigurationBuilder().build(), Collections.emptyList()))); when(metaDataContexts.getMetaData().getGlobalRuleMetaData()).thenReturn(globalRuleMetaData); return result; } diff --git a/proxy/backend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussSystemCatalogAdminQueryExecutorTest.java b/proxy/backend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussSystemCatalogAdminQueryExecutorTest.java index aba12e6e27d04..cf42fd4513499 100644 --- a/proxy/backend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussSystemCatalogAdminQueryExecutorTest.java +++ b/proxy/backend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/backend/opengauss/handler/admin/OpenGaussSystemCatalogAdminQueryExecutorTest.java @@ -58,7 +58,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.LinkedHashMap; import java.util.Map; import java.util.Optional; import java.util.Properties; @@ -88,7 +87,7 @@ void assertExecuteSelectFromPgDatabase() throws SQLException { ConnectionContext connectionContext = mockConnectionContext(); when(connectionSession.getConnectionContext()).thenReturn(connectionContext); Map databases = createDatabases(); - SQLFederationRule sqlFederationRule = new SQLFederationRule(new SQLFederationRuleConfiguration(false, false, new CacheOption(1, 1L)), databases); + SQLFederationRule sqlFederationRule = new SQLFederationRule(new SQLFederationRuleConfiguration(false, false, new CacheOption(1, 1L)), databases.values()); when(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(mock(RuleMetaData.class)); OpenGaussSelectStatement sqlStatement = createSelectStatementForPgDatabase(); ShardingSphereMetaData metaData = @@ -120,7 +119,6 @@ private OpenGaussSelectStatement createSelectStatementForPgDatabase() { } private Map createDatabases() { - Map result = new LinkedHashMap<>(1, 1F); Collection columns = Arrays.asList( new ShardingSphereColumn("datname", 12, false, false, false, true, false, false), new ShardingSphereColumn("datdba", -5, false, false, false, true, false, false), @@ -139,8 +137,8 @@ private Map createDatabases() { new ShardingSphereColumn("datminmxid", 1111, false, false, false, true, false, false)); ShardingSphereSchema schema = new ShardingSphereSchema("pg_catalog", Collections.singleton(new ShardingSphereTable("pg_database", columns, Collections.emptyList(), Collections.emptyList())), Collections.emptyList()); - result.put("sharding_db", new ShardingSphereDatabase("sharding_db", databaseType, mock(ResourceMetaData.class, RETURNS_DEEP_STUBS), mock(RuleMetaData.class), Collections.singleton(schema))); - return result; + return Collections.singletonMap("sharding_db", + new ShardingSphereDatabase("sharding_db", databaseType, mock(ResourceMetaData.class, RETURNS_DEEP_STUBS), mock(RuleMetaData.class), Collections.singleton(schema))); } @Test @@ -151,7 +149,7 @@ void assertExecuteSelectVersion() throws SQLException { ConfigurationProperties props = new ConfigurationProperties(new Properties()); when(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getProps()).thenReturn(props); Map databases = createDatabases(); - SQLFederationRule sqlFederationRule = new SQLFederationRule(new SQLFederationRuleConfiguration(false, false, new CacheOption(1, 1L)), databases); + SQLFederationRule sqlFederationRule = new SQLFederationRule(new SQLFederationRuleConfiguration(false, false, new CacheOption(1, 1L)), databases.values()); OpenGaussSelectStatement sqlStatement = createSelectStatementForVersion(); ShardingSphereMetaData metaData = new ShardingSphereMetaData(databases, mock(ResourceMetaData.class, RETURNS_DEEP_STUBS), new RuleMetaData(Collections.singletonList(sqlFederationRule)), props); @@ -187,7 +185,7 @@ void assertExecuteSelectGsPasswordDeadlineAndIntervalToNum() throws SQLException ConfigurationProperties props = new ConfigurationProperties(new Properties()); when(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getProps()).thenReturn(props); Map databases = createDatabases(); - SQLFederationRule sqlFederationRule = new SQLFederationRule(new SQLFederationRuleConfiguration(false, false, new CacheOption(1, 1L)), databases); + SQLFederationRule sqlFederationRule = new SQLFederationRule(new SQLFederationRuleConfiguration(false, false, new CacheOption(1, 1L)), databases.values()); OpenGaussSelectStatement sqlStatement = createSelectStatementForGsPasswordDeadlineAndIntervalToNum(); ShardingSphereMetaData metaData = new ShardingSphereMetaData(databases, mock(ResourceMetaData.class, RETURNS_DEEP_STUBS), new RuleMetaData(Collections.singletonList(sqlFederationRule)), props); @@ -225,7 +223,7 @@ void assertExecuteSelectGsPasswordNotifyTime() throws SQLException { ConfigurationProperties props = new ConfigurationProperties(new Properties()); when(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getProps()).thenReturn(props); Map databases = createDatabases(); - SQLFederationRule sqlFederationRule = new SQLFederationRule(new SQLFederationRuleConfiguration(false, false, new CacheOption(1, 1L)), databases); + SQLFederationRule sqlFederationRule = new SQLFederationRule(new SQLFederationRuleConfiguration(false, false, new CacheOption(1, 1L)), databases.values()); OpenGaussSelectStatement sqlStatement = createSelectStatementForGsPasswordNotifyTime(); ShardingSphereMetaData metaData = new ShardingSphereMetaData(databases, mock(ResourceMetaData.class, RETURNS_DEEP_STUBS), new RuleMetaData(Collections.singletonList(sqlFederationRule)), props); diff --git a/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngineTest.java b/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngineTest.java index 3b2792e4b3f1c..6387ec5b8f9eb 100644 --- a/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngineTest.java +++ b/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/authentication/OpenGaussAuthenticationEngineTest.java @@ -143,7 +143,7 @@ private ContextManager mockContextManager() { private RuleMetaData buildGlobalRuleMetaData(final UserConfiguration userConfig) { AuthorityRuleConfiguration ruleConfig = new AuthorityRuleConfiguration( Collections.singleton(userConfig), new AlgorithmConfiguration("ALL_PERMITTED", new Properties()), Collections.emptyMap(), null); - return new RuleMetaData(Collections.singleton(new AuthorityRuleBuilder().build(ruleConfig, Collections.emptyMap(), mock(ConfigurationProperties.class)))); + return new RuleMetaData(Collections.singleton(new AuthorityRuleBuilder().build(ruleConfig, Collections.emptyList(), mock(ConfigurationProperties.class)))); } @SneakyThrows(ReflectiveOperationException.class) diff --git a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngineTest.java b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngineTest.java index 691f3a7202ea0..86c57d6725395 100644 --- a/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngineTest.java +++ b/proxy/frontend/type/postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/authentication/PostgreSQLAuthenticationEngineTest.java @@ -206,7 +206,7 @@ private MetaDataContexts getMetaDataContexts(final UserConfiguration userConfig) private RuleMetaData buildGlobalRuleMetaData(final UserConfiguration userConfig) { AuthorityRuleConfiguration ruleConfig = new AuthorityRuleConfiguration( Collections.singleton(userConfig), new AlgorithmConfiguration("ALL_PERMITTED", new Properties()), Collections.emptyMap(), null); - AuthorityRule rule = new AuthorityRuleBuilder().build(ruleConfig, Collections.emptyMap(), mock(ConfigurationProperties.class)); + AuthorityRule rule = new AuthorityRuleBuilder().build(ruleConfig, Collections.emptyList(), mock(ConfigurationProperties.class)); return new RuleMetaData(Collections.singleton(rule)); }