コード例 #1
0
 @Override
 public void flush() throws AtomException {
   try {
     localTxDataSource.flush();
   } catch (Exception e) {
     throw new AtomException(e);
   }
 }
コード例 #2
0
  @Override
  protected DataSource getDataSource() throws SQLException {
    if (null == wrapDataSource) {
      try {
        String errorMsg = null;
        _ds_lock_.lock();
        if (null != wrapDataSource) {
          return wrapDataSource;
        }

        if (null == localTxDataSource) {
          errorMsg = "DynamicAtomDataSource maybe not inited";
          logger.error(errorMsg);
          throw new SQLException(errorMsg);
        }

        DataSource ds = localTxDataSource.getDatasource();
        if (null == ds) {
          errorMsg = "DynamicAtomDataSource maybe not inited";
          logger.error(errorMsg);
          throw new SQLException(errorMsg);
        }

        DBStatus status = config.getDbStatus();
        if (null == status || status == DBStatus.NA_STATUS) {
          errorMsg = "DynamicAtomDataSource database status unknown";
          logger.error(errorMsg);
          throw new SQLException(errorMsg);
        }

        AtomDataSourceWrapper newds =
            new AtomDataSourceWrapper(localTxDataSource.getDatasource(), config);
        wrapDataSource = newds;
        return wrapDataSource;
      } finally {
        _ds_lock_.unlock();
      }
    } else {
      return wrapDataSource;
    }
  }
コード例 #3
0
 @Override
 public void destroy() throws AtomException {
   if (null != localTxDataSource) {
     try {
       localTxDataSource.destroy();
     } catch (Exception e) {
       throw new AtomException(e);
     }
   }
   if (null != configManager) {
     configManager.stop();
   }
 }
コード例 #4
0
  /**
   * 刷新数据源
   *
   * @param newConfig
   */
  private void reflush(DataSourceConfig newConfig) {
    // 本地配置优先
    overByLocal(newConfig);

    try {
      _ds_lock_.lock();
      if (null == config
          || (config.getDbStatus() == DBStatus.NA_STATUS
              && newConfig.getDbStatus() != DBStatus.NA_STATUS)) {
        // 创建数据源
        localTxDataSource =
            IDataSourceFactory.createLocalTxDataSource(
                dataSourceConfig2LocalTxDataSourceConfig(newConfig));
        logger.warn("Init datasource");
      } else if (config.getDbStatus() != DBStatus.NA_STATUS
          && newConfig.getDbStatus() == DBStatus.NA_STATUS) {
        // 销毁数据源
        destroy();
        logger.warn("Destroy datasource");
      } else {
        // 刷新
        if (isNeedFlush(config, newConfig)) {
          LocalTxDataSourceConfig c = dataSourceConfig2LocalTxDataSourceConfig(newConfig);
          localTxDataSource.setConnectionURL(c.getConnectionURL());
          localTxDataSource.setDriverClass(c.getDriverClassName());
          localTxDataSource.setExceptionSorterClassName(c.getExceptionSorterClassName());
          flush();
        }
      }

      config = newConfig;
      dbType = config.getDbType();
    } catch (Exception e) {
      logger.error(e);
    } finally {
      _ds_lock_.unlock();
    }
  }