ShardingRule implements DataNodeRoutedRule { public boolean isShardingColumn(final String columnName, final String tableName) { return tableRules.stream().anyMatch(each -> each.getLogicTable().equalsIgnoreCase(tableName) && isShardingColumn(each, columnName)); } ShardingRule(final ShardingRuleConfiguration config, final Collection<String> dataSourceNames);  ShardingRule(final AlgorithmProvidedShardingRuleConfiguration config, final Collection<String> dataSourceNames); Optional<TableRule> findTableRule(final String logicTableName); Optional<TableRule> findTableRuleByActualTable(final String actualTableName); TableRule getTableRule(final String logicTableName); ShardingStrategy getDatabaseShardingStrategy(final TableRule tableRule); ShardingStrategy getTableShardingStrategy(final TableRule tableRule); boolean isAllBindingTables(final Collection<String> logicTableNames); Optional<BindingTableRule> findBindingTableRule(final String logicTableName); boolean isAllBroadcastTables(final Collection<String> logicTableNames); boolean isBroadcastTable(final String logicTableName); boolean tableRuleExists(final Collection<String> logicTableNames); boolean isShardingColumn(final String columnName, final String tableName); boolean isGenerateKeyColumn(final String columnName, final String tableName); Optional<String> findGenerateKeyColumnName(final String logicTableName); Comparable<?> generateKey(final String logicTableName); DataNode getDataNode(final String logicTableName); DataNode getDataNode(final String dataSourceName, final String logicTableName); Collection<String> getShardingLogicTableNames(final Collection<String> logicTableNames); Map<String, String> getLogicAndActualTablesFromBindingTable(final String dataSourceName,
                                                                       final String logicTable, final String actualTable, final Collection<String> availableLogicBindingTables); @Override Map<String, Collection<DataNode>> getAllDataNodes(); @Override Collection<String> getAllActualTables(); @Override Optional<String> findFirstActualTable(final String logicTable); @Override boolean isNeedAccumulate(final Collection<String> tables); @Override Optional<String> findLogicTableByActualTable(final String actualTable);  }
@Test public void assertIsShardingColumnForDefaultDatabaseShardingStrategy() { ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration(); shardingRuleConfig.getTables().add(createTableRuleConfigWithAllStrategies()); shardingRuleConfig.setDefaultDatabaseShardingStrategy(new StandardShardingStrategyConfiguration("column", "STANDARD_TEST")); shardingRuleConfig.getShardingAlgorithms().put("standard", new ShardingSphereAlgorithmConfiguration("STANDARD_TEST", new Properties())); assertTrue(new ShardingRule(shardingRuleConfig, createDataSourceNames()).isShardingColumn("column", "LOGIC_TABLE")); }
@Test public void assertIsShardingColumnForDefaultTableShardingStrategy() { ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration(); shardingRuleConfig.getTables().add(createTableRuleConfigWithAllStrategies()); shardingRuleConfig.setDefaultTableShardingStrategy(new StandardShardingStrategyConfiguration("column", "STANDARD_TEST")); shardingRuleConfig.getShardingAlgorithms().put("standard", new ShardingSphereAlgorithmConfiguration("STANDARD_TEST", new Properties())); assertTrue(new ShardingRule(shardingRuleConfig, createDataSourceNames()).isShardingColumn("column", "LOGIC_TABLE")); }
@Test public void assertIsShardingColumnForDatabaseShardingStrategy() { ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration(); shardingRuleConfig.getTables().add(createTableRuleConfigWithAllStrategies()); shardingRuleConfig.getShardingAlgorithms().put("standard", new ShardingSphereAlgorithmConfiguration("STANDARD_TEST", new Properties())); assertTrue(new ShardingRule(shardingRuleConfig, createDataSourceNames()).isShardingColumn("column", "logic_Table")); }
@Test public void assertIsShardingColumnForTableShardingStrategy() { ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration(); shardingRuleConfig.getTables().add(createTableRuleConfigWithTableStrategies()); shardingRuleConfig.getShardingAlgorithms().put("standard", new ShardingSphereAlgorithmConfiguration("STANDARD_TEST", new Properties())); assertTrue(new ShardingRule(shardingRuleConfig, createDataSourceNames()).isShardingColumn("column", "logic_Table")); }
@Test public void assertIsNotShardingColumn() { ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration(); shardingRuleConfig.getTables().add(createTableRuleConfigWithAllStrategies()); assertFalse(new ShardingRule(shardingRuleConfig, createDataSourceNames()).isShardingColumn("column", "other_Table")); }