@Test public void test2() { YamlInlineShardingStrategyConfiguration defaultInline = new YamlInlineShardingStrategyConfiguration(); defaultInline.setShardingColumn("default_column"); defaultInline.setAlgorithmExpression("t_fake_table->${default_column}"); YamlShardingStrategyConfiguration defaultTableStrategy = new YamlShardingStrategyConfiguration(); defaultTableStrategy.setInline(defaultInline); YamlInlineShardingStrategyConfiguration inlineOfTable1 = new YamlInlineShardingStrategyConfiguration(); inlineOfTable1.setAlgorithmExpression("t_table1->${my_column}"); inlineOfTable1.setShardingColumn("my_column"); YamlShardingStrategyConfiguration tableStrategyOfTable1 = new YamlShardingStrategyConfiguration(); tableStrategyOfTable1.setInline(inlineOfTable1); YamlTableRuleConfiguration table1 = new YamlTableRuleConfiguration(); table1.setTableStrategy(tableStrategyOfTable1); Map<String, YamlTableRuleConfiguration> tables = new HashMap<>(); tables.put("shardingDs01", table1); ZebraShardingRuleConfiguration sharding = new ZebraShardingRuleConfiguration(); sharding.setDefaultTableStrategy(defaultTableStrategy); sharding.setTables(tables); ZebraShardingDataSourceCfg zebraShardingDataSourceCfg = new ZebraShardingDataSourceCfg(); zebraShardingDataSourceCfg.setSharding(sharding); ZebraShardingDefaultCfgFiller.checkThenFill(zebraShardingDataSourceCfg); String defaultTableExpression = zebraShardingDataSourceCfg .getSharding() .getDefaultTableStrategy() .getInline() .getAlgorithmExpression(); assertThat(defaultTableExpression, is("t_fake_table->${default_column}")); Collection<YamlTableRuleConfiguration> newTables = zebraShardingDataSourceCfg .getSharding() .getTables() .values(); YamlTableRuleConfiguration newTable1 = newTables.iterator().next(); YamlInlineShardingStrategyConfiguration newInlineOfTable1 = newTable1.getTableStrategy().getInline(); assertThat(newInlineOfTable1.getShardingColumn(), is("my_column")); assertThat(newInlineOfTable1.getAlgorithmExpression(), is("t_table1->${my_column}")); }
public static void checkThenFill(ZebraShardingDataSourceCfg zebraShardingDataSourceCfg) { ZebraShardingRuleConfiguration zebraShardingRuleConfiguration = zebraShardingDataSourceCfg.getSharding(); YamlShardingStrategyConfiguration defaultTableStrategy = zebraShardingRuleConfiguration.getDefaultTableStrategy(); if (defaultTableStrategy == null) { return; } YamlInlineShardingStrategyConfiguration defaultTableInline = defaultTableStrategy.getInline(); fillDefaultInline(defaultTableInline); Map<String, YamlTableRuleConfiguration> tables = zebraShardingDataSourceCfg.getSharding().getTables(); for (Map.Entry<String, YamlTableRuleConfiguration> tableEntry : tables.entrySet()) { YamlTableRuleConfiguration tableConfiguration = tableEntry.getValue(); fillInlineIfNotCfg(tableConfiguration, defaultTableInline); } }
ZebraShardingDefaultCfgFiller { public static void checkThenFill(ZebraShardingDataSourceCfg zebraShardingDataSourceCfg) { ZebraShardingRuleConfiguration zebraShardingRuleConfiguration = zebraShardingDataSourceCfg.getSharding(); YamlShardingStrategyConfiguration defaultTableStrategy = zebraShardingRuleConfiguration.getDefaultTableStrategy(); if (defaultTableStrategy == null) { return; } YamlInlineShardingStrategyConfiguration defaultTableInline = defaultTableStrategy.getInline(); fillDefaultInline(defaultTableInline); Map<String, YamlTableRuleConfiguration> tables = zebraShardingDataSourceCfg.getSharding().getTables(); for (Map.Entry<String, YamlTableRuleConfiguration> tableEntry : tables.entrySet()) { YamlTableRuleConfiguration tableConfiguration = tableEntry.getValue(); fillInlineIfNotCfg(tableConfiguration, defaultTableInline); } } }
ZebraShardingDefaultCfgFiller { public static void checkThenFill(ZebraShardingDataSourceCfg zebraShardingDataSourceCfg) { ZebraShardingRuleConfiguration zebraShardingRuleConfiguration = zebraShardingDataSourceCfg.getSharding(); YamlShardingStrategyConfiguration defaultTableStrategy = zebraShardingRuleConfiguration.getDefaultTableStrategy(); if (defaultTableStrategy == null) { return; } YamlInlineShardingStrategyConfiguration defaultTableInline = defaultTableStrategy.getInline(); fillDefaultInline(defaultTableInline); Map<String, YamlTableRuleConfiguration> tables = zebraShardingDataSourceCfg.getSharding().getTables(); for (Map.Entry<String, YamlTableRuleConfiguration> tableEntry : tables.entrySet()) { YamlTableRuleConfiguration tableConfiguration = tableEntry.getValue(); fillInlineIfNotCfg(tableConfiguration, defaultTableInline); } }  }
ZebraShardingDefaultCfgFiller { public static void checkThenFill(ZebraShardingDataSourceCfg zebraShardingDataSourceCfg) { ZebraShardingRuleConfiguration zebraShardingRuleConfiguration = zebraShardingDataSourceCfg.getSharding(); YamlShardingStrategyConfiguration defaultTableStrategy = zebraShardingRuleConfiguration.getDefaultTableStrategy(); if (defaultTableStrategy == null) { return; } YamlInlineShardingStrategyConfiguration defaultTableInline = defaultTableStrategy.getInline(); fillDefaultInline(defaultTableInline); Map<String, YamlTableRuleConfiguration> tables = zebraShardingDataSourceCfg.getSharding().getTables(); for (Map.Entry<String, YamlTableRuleConfiguration> tableEntry : tables.entrySet()) { YamlTableRuleConfiguration tableConfiguration = tableEntry.getValue(); fillInlineIfNotCfg(tableConfiguration, defaultTableInline); } }  static void checkThenFill(ZebraShardingDataSourceCfg zebraShardingDataSourceCfg); }
ZebraShardingDefaultCfgFiller { public static void checkThenFill(ZebraShardingDataSourceCfg zebraShardingDataSourceCfg) { ZebraShardingRuleConfiguration zebraShardingRuleConfiguration = zebraShardingDataSourceCfg.getSharding(); YamlShardingStrategyConfiguration defaultTableStrategy = zebraShardingRuleConfiguration.getDefaultTableStrategy(); if (defaultTableStrategy == null) { return; } YamlInlineShardingStrategyConfiguration defaultTableInline = defaultTableStrategy.getInline(); fillDefaultInline(defaultTableInline); Map<String, YamlTableRuleConfiguration> tables = zebraShardingDataSourceCfg.getSharding().getTables(); for (Map.Entry<String, YamlTableRuleConfiguration> tableEntry : tables.entrySet()) { YamlTableRuleConfiguration tableConfiguration = tableEntry.getValue(); fillInlineIfNotCfg(tableConfiguration, defaultTableInline); } }  static void checkThenFill(ZebraShardingDataSourceCfg zebraShardingDataSourceCfg);  }