Пример #1
0
  /**
   * 基于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();
    }
  }
Пример #2
0
 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;
 }