diff --git a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/BroadcastRule.java b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/BroadcastRule.java index 3d07beb1297be..195abb599d9c2 100644 --- a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/BroadcastRule.java +++ b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/BroadcastRule.java @@ -43,19 +43,16 @@ public final class BroadcastRule implements DatabaseRule { private final BroadcastRuleConfiguration configuration; - private final String databaseName; - private final Collection tables; private final Collection dataSourceNames; private final RuleAttributes attributes; - public BroadcastRule(final BroadcastRuleConfiguration config, final String databaseName, final Map dataSources, final Collection builtRules) { + public BroadcastRule(final BroadcastRuleConfiguration config, final Map dataSources, final Collection builtRules) { configuration = config; - this.databaseName = databaseName; dataSourceNames = getAggregatedDataSourceNames(dataSources, builtRules); - tables = createBroadcastTables(config.getTables()); + tables = new CaseInsensitiveSet<>(config.getTables()); attributes = new RuleAttributes(new BroadcastDataNodeRuleAttribute(dataSourceNames, tables), new BroadcastTableNamesRuleAttribute(tables)); } @@ -86,10 +83,6 @@ private Collection getAggregatedDataSourceNames(final Collection return result; } - private Collection createBroadcastTables(final Collection broadcastTables) { - return new CaseInsensitiveSet<>(broadcastTables); - } - /** * Get broadcast rule table names. * diff --git a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/builder/BroadcastRuleBuilder.java b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/builder/BroadcastRuleBuilder.java index fe3285f7e0c27..3ea4b8df634d5 100644 --- a/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/builder/BroadcastRuleBuilder.java +++ b/features/broadcast/core/src/main/java/org/apache/shardingsphere/broadcast/rule/builder/BroadcastRuleBuilder.java @@ -36,7 +36,7 @@ public final class BroadcastRuleBuilder implements DatabaseRuleBuilder builtRules, final ComputeNodeInstanceContext computeNodeInstanceContext) { - return new BroadcastRule(ruleConfig, databaseName, resourceMetaData.getDataSourceMap(), builtRules); + return new BroadcastRule(ruleConfig, resourceMetaData.getDataSourceMap(), builtRules); } @Override diff --git a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/route/BroadcastSqlRouterTest.java b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/route/BroadcastSqlRouterTest.java index 3fec9f7ff5f71..7361bf4a4d52d 100644 --- a/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/route/BroadcastSqlRouterTest.java +++ b/features/broadcast/core/src/test/java/org/apache/shardingsphere/broadcast/route/BroadcastSqlRouterTest.java @@ -76,7 +76,7 @@ class BroadcastSqlRouterTest { void assertCreateBroadcastRouteContextWithMultiDataSource() throws SQLException { BroadcastRuleConfiguration currentConfig = mock(BroadcastRuleConfiguration.class); when(currentConfig.getTables()).thenReturn(Collections.singleton("t_order")); - BroadcastRule broadcastRule = new BroadcastRule(currentConfig, DefaultDatabase.LOGIC_NAME, createMultiDataSourceMap(), Collections.emptyList()); + BroadcastRule broadcastRule = new BroadcastRule(currentConfig, createMultiDataSourceMap(), Collections.emptyList()); RouteContext routeContext = new BroadcastSQLRouter().createRouteContext(createQueryContext(), mock(RuleMetaData.class), mockDatabaseWithMultipleResources(), broadcastRule, new ConfigurationProperties(new Properties())); List routeUnits = new ArrayList<>(routeContext.getRouteUnits()); @@ -92,7 +92,7 @@ void assertCreateBroadcastRouteContextWithMultiDataSource() throws SQLException void assertCreateBroadcastRouteContextWithSingleDataSource() throws SQLException { BroadcastRuleConfiguration currentConfig = mock(BroadcastRuleConfiguration.class); when(currentConfig.getTables()).thenReturn(Collections.singleton("t_order")); - BroadcastRule broadcastRule = new BroadcastRule(currentConfig, DefaultDatabase.LOGIC_NAME, Collections.singletonMap("tmp_ds", new MockedDataSource(mockConnection())), Collections.emptyList()); + BroadcastRule broadcastRule = new BroadcastRule(currentConfig, Collections.singletonMap("tmp_ds", new MockedDataSource(mockConnection())), Collections.emptyList()); broadcastRule.getAttributes().getAttribute(DataNodeRuleAttribute.class).getAllDataNodes().put("t_order", Collections.singletonList(createDataNode("tmp_ds"))); ShardingSphereDatabase database = mockSingleDatabase(); RouteContext routeContext = new BroadcastSQLRouter().createRouteContext( @@ -108,7 +108,7 @@ void assertCreateBroadcastRouteContextWithSingleDataSource() throws SQLException void assertDecorateBroadcastRouteContextWithSingleDataSource() { BroadcastRuleConfiguration currentConfig = mock(BroadcastRuleConfiguration.class); when(currentConfig.getTables()).thenReturn(Collections.singleton("t_order")); - BroadcastRule broadcastRule = new BroadcastRule(currentConfig, DefaultDatabase.LOGIC_NAME, Collections.singletonMap("foo_ds", new MockedDataSource()), Collections.emptyList()); + BroadcastRule broadcastRule = new BroadcastRule(currentConfig, Collections.singletonMap("foo_ds", new MockedDataSource()), Collections.emptyList()); RouteContext routeContext = new RouteContext(); routeContext.getRouteUnits().add(new RouteUnit(new RouteMapper("foo_ds", "foo_ds"), Lists.newArrayList())); BroadcastSQLRouter sqlRouter = (BroadcastSQLRouter) OrderedSPILoader.getServices(SQLRouter.class, Collections.singleton(broadcastRule)).get(broadcastRule);