gs-liut commented on issue #25025:
URL:
https://github.com/apache/shardingsphere/issues/25025#issuecomment-1501399678
@strongduanmu yes,
ShardingDataSourceConfiguration.java:
```
public class ShardingDataSourceConfiguration {
private static final String DATABASE_NAME = "gold_coin_logic_db";
@Bean
public DataSource dataSource(DataSourceMapProperties properties) throws
SQLException {
return
ShardingSphereDataSourceFactory.createDataSource(DATABASE_NAME,
createModeConfiguration(), createDataSourceMap(properties),
createRuleConfiguration(), createProperties());
}
private ModeConfiguration createModeConfiguration() {
return new ModeConfiguration("Standalone", new
StandalonePersistRepositoryConfiguration("JDBC", new Properties()));
}
private Collection<RuleConfiguration> createRuleConfiguration() {
ShardingRuleConfiguration configuration = new
ShardingRuleConfiguration();
configuration.getAutoTables().add(getPayLogTableRuleConfiguration());
Properties payLogProps = new Properties();
payLogProps.setProperty("sharding-count", "40");
configuration.getShardingAlgorithms().put("pay_log_hash", new
AlgorithmConfiguration("HASH_MOD", payLogProps));
Collection<RuleConfiguration> collection = new LinkedList<>();
collection.add(configuration);
return collection;
}
private ShardingAutoTableRuleConfiguration
getPayLogTableRuleConfiguration() {
ShardingAutoTableRuleConfiguration configuration = new
ShardingAutoTableRuleConfiguration("pay_log", "ds_${0..9}");
configuration.setShardingStrategy(new
StandardShardingStrategyConfiguration("user_id", "pay_log_hash"));
return configuration;
}
private Properties createProperties() {
Properties properties = new Properties();
properties.setProperty(ConfigurationPropertyKey.SQL_SHOW.getKey(),
"false");
properties.setProperty(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY.getKey(),
"4");
return properties;
}
private Map<String, DataSource>
createDataSourceMap(DataSourceMapProperties properties) {
Map<String, DataSource> dataSourceMap = new
LinkedHashMap<>(properties.getDsMap().size());
properties.dsMap.forEach((k, v) -> {
v.setPoolName(properties.getPoolName() + k);
v.setAutoCommit(properties.getAutoCommit());
v.setReadOnly(properties.getReadOnly());
v.setMaximumPoolSize(properties.getMaxPoolSize());
v.setIdleTimeout(properties.getIdleTimeout());
v.setMaxLifetime(properties.getMaxLifetime());
dataSourceMap.put(k, v);
});
return dataSourceMap;
}
@Data
@Component
@ConfigurationProperties(prefix = "sharding")
@PropertySource(value =
{"classpath:config/sharding-ds-${spring.profiles.active:dev}.yml"}, encoding =
"UTF-8", factory = YamlPropertySourceFactory.class)
public static class DataSourceMapProperties {
private String poolName;
private Boolean autoCommit, readOnly;
private Integer maxPoolSize, idleTimeout, maxLifetime;
private LinkedHashMap<String, HikariDataSource> dsMap;
}
}
```
Spring JPA config:
```
spring:
jpa:
show-sql: false
open-in-view: true
database-platform: org.hibernate.dialect.PostgreSQLDialect
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]