/** * 基于dbGroupKey、appName来初始化多个TAtomDataSource * * @throws com.taobao.tddl.jdbc.group.exception.ConfigException */ public void init() { if (dsKeyAndWeightCommaArray != null) { // 本地配置方式:dsKeyAndWeightCommaArray + dataSourceFetcher + dyType DataSourceFetcher wrapper = new DataSourceFetcher() { @Override public DataSource getDataSource(String key) { return dataSourceFetcher.getDataSource(key); } @Override public DBType getDataSourceDBType(String key) { DBType type = dataSourceFetcher.getDataSourceDBType(key); return type == null ? dbType : type; // 如果dataSourceFetcher没dbType,用tgds的dbType } }; List<DataSourceWrapper> dss = ConfigManager.buildDataSourceWrapper(dsKeyAndWeightCommaArray, wrapper); init(dss); } else { checkProperties(); configManager = new ConfigManager(this); configManager.init(); } }
public static TGroupDataSource build( String groupKey, String dsWeights, DataSourceFetcher fetcher, DataSourceType dataSourceType) { List<DataSourceWrapper> dss = ConfigManager.buildDataSourceWrapper(dsWeights, fetcher); TGroupDataSource tGroupDataSource = new TGroupDataSource(); tGroupDataSource.setDataSourceType(dataSourceType); tGroupDataSource.setDbGroupKey(groupKey); tGroupDataSource.init(dss); return tGroupDataSource; }
public void init(List<DataSourceWrapper> dataSourceWrappers) { configManager = new ConfigManager(this); configManager.init(dataSourceWrappers); }
/** * 销毁数据源,慎用 * * @throws Exception */ public void destroyDataSource() throws Exception { if (configManager != null) { configManager.destroyDataSource(); } }
// 包访问级别,调用者不能缓存,否则会失去动态性 DBSelector getDBSelector(boolean isRead) { return configManager.getDBSelector(isRead, this.autoSelectWriteDataSource); }
/** 危险接口。一般用于测试。应用也可以直接通过该接口重置数据源配置 */ public void resetDbGroup(String configInfo) { configManager.resetDbGroup(configInfo); }