
* 修改健康检查选择数据库的逻辑 修改健康检查的 引用类型转基本类型可能的报错。 * 修复 mybatis cache 开启后, 引起的 association 实效 * pom 默认构建doc,source * 主从插件支持多主多从 * 给健康检查加入适配器, 可以处理: 开启健康检查没引入包的特殊情况
41 lines
1.3 KiB
Java
41 lines
1.3 KiB
Java
/**
|
|
* Copyright © 2018 organization baomidou
|
|
* <pre>
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
* <pre/>
|
|
*/
|
|
package com.baomidou.dynamic.datasource.strategy;
|
|
|
|
import javax.sql.DataSource;
|
|
import java.util.List;
|
|
import java.util.concurrent.ThreadLocalRandom;
|
|
|
|
/**
|
|
* Random strategy to switch a database
|
|
*
|
|
* @author TaoYu Kanyuxia
|
|
* @since 1.0.0
|
|
*/
|
|
public class RandomDynamicDataSourceStrategy implements DynamicDataSourceStrategy {
|
|
|
|
@Override
|
|
public DataSource determineDataSource(List<DataSource> dataSources) {
|
|
return dataSources.get(ThreadLocalRandom.current().nextInt(dataSources.size()));
|
|
}
|
|
|
|
@Override
|
|
public String determineDSKey(List<String> dsNames) {
|
|
return dsNames.get(ThreadLocalRandom.current().nextInt(dsNames.size()));
|
|
}
|
|
}
|