private DataSource open()

in src/main/java/com/googlesource/gerrit/plugins/verifystatus/server/schema/CiDataSourceProvider.java [105:166]


  private DataSource open(Context context, CiDataSourceType dst) {
    // ConfigSection dbs = new ConfigSection(cfg, "database");
    String driver = config.getString("driver");
    if (Strings.isNullOrEmpty(driver)) {
      driver = dst.getDriver();
    }

    String url = config.getString("dbUrl");
    if (Strings.isNullOrEmpty(url)) {
      url = dst.getUrl();
    }

    String username = config.getString("username");
    String password = config.getString("password");

    boolean usePool;
    if (context == Context.SINGLE_USER) {
      usePool = false;
    } else {
      usePool = config.getBoolean("connectionpool", dst.usePool());
    }

    if (usePool) {
      final BasicDataSource ds = new BasicDataSource();
      ds.setDriverClassName(driver);
      ds.setUrl(url);
      if (username != null && !username.isEmpty()) {
        ds.setUsername(username);
      }
      if (password != null && !password.isEmpty()) {
        ds.setPassword(password);
      }
      ds.setMaxActive(config.getInt("poollimit", DEFAULT_POOL_LIMIT));
      ds.setMinIdle(config.getInt("poolminidle", 4));
      ds.setMaxIdle(config.getInt("poolmaxidle", 4));
      String valueString = config.getString("poolmaxwait");
      if (Strings.isNullOrEmpty(valueString)) {
        ds.setMaxWait(MILLISECONDS.convert(30, SECONDS));
      } else {
        ds.setMaxWait(
            ConfigUtil.getTimeUnit(valueString, MILLISECONDS.convert(30, SECONDS), MILLISECONDS));
      }
      ds.setInitialSize(ds.getMinIdle());
      exportPoolMetrics(ds);
      return ds;
    }
    // Don't use the connection pool.
    try {
      Properties p = new Properties();
      p.setProperty("driver", driver);
      p.setProperty("url", url);
      if (username != null) {
        p.setProperty("user", username);
      }
      if (password != null) {
        p.setProperty("password", password);
      }
      return new SimpleDataSource(p);
    } catch (SQLException se) {
      throw new ProvisionException("Database unavailable", se);
    }
  }