From ced60a34cd2df64913564b7cc973695a088faf5c Mon Sep 17 00:00:00 2001 From: Johan Chavaillaz Date: Wed, 7 Feb 2024 22:53:30 +0100 Subject: [PATCH] Keep code old style following PR comment --- .../config/jdbc/runtime/Repository.java | 57 ++++++++++++------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/jdbc/runtime/src/main/java/io/quarkiverse/config/jdbc/runtime/Repository.java b/jdbc/runtime/src/main/java/io/quarkiverse/config/jdbc/runtime/Repository.java index 698183a..ae7e116 100644 --- a/jdbc/runtime/src/main/java/io/quarkiverse/config/jdbc/runtime/Repository.java +++ b/jdbc/runtime/src/main/java/io/quarkiverse/config/jdbc/runtime/Repository.java @@ -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; @@ -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; @@ -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) {