Search in sources :

Example 1 with ArrayUtils.getLength

use of org.apache.commons.lang3.ArrayUtils.getLength in project adeptj-modules by AdeptJ.

the class DataSources method createDataSource.

public static HikariDataSource createDataSource(DataSourceConfig config) {
    HikariConfig hikariConfig = new HikariConfig();
    hikariConfig.setPoolName(config.poolName());
    hikariConfig.setJdbcUrl(config.jdbcUrl());
    hikariConfig.setDriverClassName(config.driverClassName());
    hikariConfig.setUsername(config.username());
    hikariConfig.setPassword(config.password());
    hikariConfig.setAutoCommit(config.autoCommit());
    hikariConfig.setConnectionTimeout(config.connectionTimeout());
    hikariConfig.setIdleTimeout(config.idleTimeout());
    hikariConfig.setMaxLifetime(config.maxLifetime());
    hikariConfig.setMinimumIdle(config.minimumIdle());
    hikariConfig.setMaximumPoolSize(config.maximumPoolSize());
    Stream.of(config.dataSourceProperties()).filter(row -> ArrayUtils.getLength(row.split(Constants.EQ)) == 2).forEach(entry -> {
        String[] mapping = entry.split(Constants.EQ);
        hikariConfig.getDataSourceProperties().put(mapping[0], mapping[1]);
    });
    return new HikariDataSource(hikariConfig);
}
Also used : HikariConfig(com.zaxxer.hikari.HikariConfig) Stream(java.util.stream.Stream) Constants(com.adeptj.modules.commons.utils.Constants) HikariDataSource(com.zaxxer.hikari.HikariDataSource) ArrayUtils(org.apache.commons.lang3.ArrayUtils) HikariDataSource(com.zaxxer.hikari.HikariDataSource) HikariConfig(com.zaxxer.hikari.HikariConfig)

Aggregations

Constants (com.adeptj.modules.commons.utils.Constants)1 HikariConfig (com.zaxxer.hikari.HikariConfig)1 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 Stream (java.util.stream.Stream)1 ArrayUtils (org.apache.commons.lang3.ArrayUtils)1