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);
}
Aggregations