public static DataSource createDataSource(Configurations config) {
    BasicDataSource dataSource = new BasicDataSource();
    dataSource.setUrl(config.getString(AmoroManagementConf.DB_CONNECTION_URL));
    dataSource.setDriverClassName(config.getString(AmoroManagementConf.DB_DRIVER_CLASS_NAME));
    String dbType = config.getString(AmoroManagementConf.DB_TYPE);
    if (AmoroManagementConf.DB_TYPE_MYSQL.equals(dbType)
        || AmoroManagementConf.DB_TYPE_POSTGRES.equals(dbType)) {
      dataSource.setUsername(config.getString(AmoroManagementConf.DB_USER_NAME));
      dataSource.setPassword(config.getString(AmoroManagementConf.DB_PASSWORD));
    }
    dataSource.setDefaultAutoCommit(false);
    dataSource.setMaxTotal(config.getInteger(AmoroManagementConf.DB_CONNECT_MAX_TOTAL));
    dataSource.setMaxIdle(config.getInteger(AmoroManagementConf.DB_CONNECT_MAX_IDLE));
    dataSource.setMinIdle(0);
    dataSource.setMaxWaitMillis(config.getLong(AmoroManagementConf.DB_CONNECT_MAX_WAIT_MILLIS));
    dataSource.setLogAbandoned(true);
    dataSource.setRemoveAbandonedOnBorrow(true);
    dataSource.setRemoveAbandonedTimeout(60);
    dataSource.setTimeBetweenEvictionRunsMillis(Duration.ofMillis(10 * 60 * 1000L).toMillis());
    dataSource.setTestOnBorrow(BaseObjectPoolConfig.DEFAULT_TEST_ON_BORROW);
    dataSource.setTestWhileIdle(BaseObjectPoolConfig.DEFAULT_TEST_WHILE_IDLE);
    dataSource.setMinEvictableIdleTimeMillis(1000);
    dataSource.setNumTestsPerEvictionRun(BaseObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN);
    dataSource.setTestOnReturn(BaseObjectPoolConfig.DEFAULT_TEST_ON_RETURN);
    dataSource.setSoftMinEvictableIdleTimeMillis(
        BaseObjectPoolConfig.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME.toMillis());
    dataSource.setLifo(BaseObjectPoolConfig.DEFAULT_LIFO);
    createTablesIfNeed(dataSource, config);
    return dataSource;
  }
Factory to help create data source
amoro-ams/src/main/java/org/apache/amoro/server/persistence/DataSourceFactory.java