Skip to content

Commit

Permalink
Keep code old style following PR comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Chavjoh committed Feb 7, 2024
1 parent ac28dd9 commit ced60a3
Showing 1 changed file with 35 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.quarkiverse.config.jdbc.runtime;

import static io.agroal.api.configuration.AgroalDataSourceConfiguration.DataSourceImplementation.AGROAL;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
Expand All @@ -15,6 +13,8 @@
import org.jboss.logging.Logger;

import io.agroal.api.AgroalDataSource;
import io.agroal.api.configuration.supplier.AgroalConnectionFactoryConfigurationSupplier;
import io.agroal.api.configuration.supplier.AgroalConnectionPoolConfigurationSupplier;
import io.agroal.api.configuration.supplier.AgroalDataSourceConfigurationSupplier;
import io.agroal.api.security.NamePrincipal;
import io.agroal.api.security.SimplePassword;
Expand Down Expand Up @@ -82,26 +82,39 @@ public String getValue(String propertyName) {
}

private void prepareDataSource(final JdbcConfigConfig config) throws SQLException {
var configuration = new AgroalDataSourceConfigurationSupplier()
.dataSourceImplementation(AGROAL)
.metricsEnabled(false)
.connectionPoolConfiguration(cp -> cp
.minSize(config.minSize())
.maxSize(config.maxSize())
.initialSize(config.initialSize())
.acquisitionTimeout(config.acquisitionTimeout())
.connectionFactoryConfiguration(cf -> cf
.jdbcUrl(config.url())
.connectionProviderClassName(config.driver()
.orElse(null))
.principal(config.username()
.map(NamePrincipal::new)
.orElse(null))
.credential(config.password()
.map(SimplePassword::new)
.orElse(null))));

dataSource = AgroalDataSource.from(configuration);
// create supplier
AgroalDataSourceConfigurationSupplier dataSourceConfiguration = new AgroalDataSourceConfigurationSupplier();
// get reference to connection pool
AgroalConnectionPoolConfigurationSupplier poolConfiguration = dataSourceConfiguration
.connectionPoolConfiguration();
// get reference to connection factory
AgroalConnectionFactoryConfigurationSupplier connectionFactoryConfiguration = poolConfiguration
.connectionFactoryConfiguration();

// configure pool
poolConfiguration
.initialSize(config.initialSize())
.minSize(config.minSize())
.maxSize(config.maxSize())
.acquisitionTimeout(config.acquisitionTimeout());

// configure supplier
connectionFactoryConfiguration
.jdbcUrl(config.url());

if (config.driver().isPresent()) {
connectionFactoryConfiguration.connectionProviderClassName(config.driver().get());
}

if (config.username().isPresent()) {
connectionFactoryConfiguration.credential(new NamePrincipal(config.username().get()));
}

if (config.password().isPresent()) {
connectionFactoryConfiguration.credential(new SimplePassword(config.password().get()));
}

dataSource = AgroalDataSource.from(dataSourceConfiguration.get());
}

private void prepareQueries(final JdbcConfigConfig config) {
Expand Down

0 comments on commit ced60a3

Please sign in to comment.