public static DataSource createDataSource()

in baremaps-postgres/src/main/java/org/apache/baremaps/postgres/utils/PostgresUtils.java [117:163]


  public static DataSource createDataSource(Database datasource) {
    var config = new HikariConfig();
    if (datasource.getDataSourceClassName() != null) {
      config.setDataSourceClassName(datasource.getDataSourceClassName());
    }
    if (datasource.getJdbcUrl() != null) {
      config.setJdbcUrl(datasource.getJdbcUrl());
    }
    if (datasource.getUsername() != null) {
      config.setUsername(datasource.getUsername());
    }
    if (datasource.getPassword() != null) {
      config.setPassword(datasource.getPassword());
    }
    if (datasource.getAutoCommit() != null) {
      config.setAutoCommit(datasource.getAutoCommit());
    }
    if (datasource.getConnectionTimeout() != null) {
      config.setConnectionTimeout(datasource.getConnectionTimeout());
    }
    if (datasource.getIdleTimeout() != null) {
      config.setInitializationFailTimeout(datasource.getIdleTimeout());
    }
    if (datasource.getKeepAliveTime() != null) {
      config.setKeepaliveTime(datasource.getKeepAliveTime());
    }
    if (datasource.getMaxLifetime() != null) {
      config.setMaxLifetime(datasource.getMaxLifetime());
    }
    if (datasource.getMinimumIdle() != null) {
      config.setMinimumIdle(datasource.getMinimumIdle());
    }
    if (datasource.getMaximumPoolSize() != null) {
      config.setMaximumPoolSize(datasource.getMaximumPoolSize());
    }
    if (datasource.getPoolName() != null) {
      config.setPoolName(datasource.getPoolName());
    }
    if (datasource.getReadOnly() != null) {
      config.setReadOnly(datasource.getReadOnly());
    }

    config.addDataSourceProperty("allowMultiQueries", true);
    config.addDataSourceProperty("prepareThreshold", 100);

    return new HikariDataSource(config);
  }