joinhappy81 opened a new issue #5252:
URL: https://github.com/apache/shardingsphere/issues/5252
In version 4.0.1, HintManager getInstance (). SetDatabaseShardingValue ()
can't use, don't enter DataSourceTypeHintShardingAlgorithm,I just want to
switch database, not tables
m1:
!!org.apache.shardingsphere.orchestration.yaml.config.YamlDataSourceConfiguration
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
properties:
driverClassName: com.mysql.cj.jdbc.Driver
jdbcUrl:
jdbc:mysql://127.0.0.1:3306/order_db_1?useSSL=true&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&autoReconnect=true&failOverReadOnly=false&allowMultiQueries=true&serverTimezone=GMT
username: root
password: admin888
connectionTimeout: 30000
minimumIdle: 5
maximumPoolSize: 15
idleTimeout: 30000
maxLifetime: 120000
autoCommit: true
m2:
!!org.apache.shardingsphere.orchestration.yaml.config.YamlDataSourceConfiguration
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
properties:
driverClassName: com.mysql.cj.jdbc.Driver
jdbcUrl:
jdbc:mysql://127.0.0.1:3306/order_db_2?useSSL=true&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&autoReconnect=true&failOverReadOnly=false&allowMultiQueries=true&serverTimezone=GMT
username: root
password: admin888
connectionTimeout: 30000
minimumIdle: 5
maximumPoolSize: 15
idleTimeout: 30000
maxLifetime: 120000
autoCommit: true
config:
sharding:
defaultDatabaseStrategy:
hint:
algorithmClassName:
cn.com.hatech.sharding.config.DataSourceTypeHintShardingAlgorithm
public class DataSourceTypeHintShardingAlgorithm implements
HintShardingAlgorithm<String> {
@Override
public Collection<String> doSharding(Collection<String>
availableTargetNames, HintShardingValue<String> shardingValue) {
if (!CollectionUtils.isEmpty(shardingValue.getValues())) {
log.info("当前所选择的数据源是:{}",shardingValue.getValues());
return availableTargetNames.stream().filter(availableTargetName
->
shardingValue.getValues().contains(availableTargetName)).collect(Collectors.toList());
}
return availableTargetNames;
}
}
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]