vuhoanghiep1993 commented on issue #1976: URL: https://github.com/apache/shardingsphere/issues/1976#issuecomment-2560823105
I add my full source to custom sharding algorithm ``` private Map<String, AlgorithmConfiguration> getShardingAlgorithms() { Map<String, AlgorithmConfiguration> shardingAlgorithms = new LinkedHashMap<>(); Properties databaseAlgorithmslocation = new Properties(); databaseAlgorithmslocation.setProperty("strategy", "standard"); databaseAlgorithmslocation.setProperty("algorithmClassName", LocationDatasourceShardingAlgorithm.class.getName()); shardingAlgorithms.put("database-inline-location", new AlgorithmConfiguration("CLASS_BASED", databaseAlgorithmslocation)); return shardingAlgorithms; } public DataSource getShardingDataSource() throws SQLException { Map<String, DataSource> dataSourceMap = new HashMap<>(); dataSourceMap.put("db0", dataSource0()); dataSourceMap.put("db1", dataSource1()); dataSourceMap.put("db2", dataSource2()); serverMap.put("North", "db0"); serverMap.put("West", "db1"); serverMap.put("South", "db2"); ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration(); shardingRuleConfig.setShardingAlgorithms(getShardingAlgorithms()); orderTableRuleConfig.setDatabaseShardingStrategy(new StandardShardingStrategyConfiguration("location", "database-inline-location")); shardingRuleConfig.getTables().add(orderTableRuleConfig); return ShardingSphereDataSourceFactory.createDataSource(dataSourceMap, Collections.singleton(shardingRuleConfig), properties); } public class LocationDatasourceShardingAlgorithm implements StandardShardingAlgorithm<OrderEntity> { @Override public String doSharding(Collection<String> collection, PreciseShardingValue<OrderEntity> preciseShardingValue) { return serverMap.get(preciseShardingValue.getValue()); } @Override public Collection<String> doSharding(Collection collection, RangeShardingValue rangeShardingValue) { return collection; } } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@shardingsphere.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org