예제 #1
0
 @Override
 public DataSource getDataSource(String dsKey) {
   DataSourceWrapper dsw = dataSourceWrapperMap.get(dsKey);
   if (dsw != null) {
     dbType = dsw.getDBType();
     return dsw.getWrappedDataSource();
   } else {
     if (createTAtomDataSource) {
       if (tGroupDataSource.getDataSourceType().equals(DataSourceType.TbDataSource)) {
         TAtomDataSource atom = createTAtomDataSource(dsKey);
         dbType = DBType.valueOf(atom.getDbType().name());
         return atom;
       } else if (tGroupDataSource.getDataSourceType().equals(DataSourceType.DruidDataSource)) {
         TDruidDataSource druid = createTDruidDataSource(dsKey);
         dbType = DBType.valueOf(druid.getDbType().name());
         return druid;
       } else {
         throw new IllegalArgumentException(
             "do not havae this datasource type : " + tGroupDataSource.getDataSourceType());
       }
     } else {
       throw new IllegalArgumentException(dsKey + " not exist!");
     }
   }
 }
예제 #2
0
  /**
   * 因为我们的的Group配置中,配置的AtomDataSource都是用这个DataSource的dbkey表示
   * 所以,我们需要将这个dbkey从Diamond上取得我们对应的配置信息,并且生成真正的AtomDataSource ---add by mazhidan.pt
   */
  private TAtomDataSource createTAtomDataSource(String dsKey) {
    TAtomDataSource ads = null;
    try {
      ads = new TAtomDataSource();
      ads.setAppName(tGroupDataSource.getAppName());
      ads.setDbKey(dsKey);

      ads.init(); // TAtomDataSource的init()会throws Exception

      ads.setLogWriter(tGroupDataSource.getLogWriter());
      ads.setLoginTimeout(tGroupDataSource.getLoginTimeout());
    } catch (Exception e) {
      throw new TAtomDataSourceException("TAtomDataSource无法初始化: dsKey=" + dsKey, e);
    }
    return ads;
  }