From 9c93861ad34e1d8bca55b962b7c13c1b1a481dc3 Mon Sep 17 00:00:00 2001 From: Matthias Kaemmer Date: Mon, 30 Oct 2023 16:31:33 +0100 Subject: [PATCH] Review fixes: changed declaration of default values for connection pool Signed-off-by: Matthias Kaemmer --- .../hono/service/base/jdbc/config/JdbcOptions.java | 14 +++++++++----- .../service/base/jdbc/config/JdbcProperties.java | 12 ++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/services/base-jdbc/src/main/java/org/eclipse/hono/service/base/jdbc/config/JdbcOptions.java b/services/base-jdbc/src/main/java/org/eclipse/hono/service/base/jdbc/config/JdbcOptions.java index 65b72b7dc5..9a99158780 100644 --- a/services/base-jdbc/src/main/java/org/eclipse/hono/service/base/jdbc/config/JdbcOptions.java +++ b/services/base-jdbc/src/main/java/org/eclipse/hono/service/base/jdbc/config/JdbcOptions.java @@ -14,10 +14,10 @@ package org.eclipse.hono.service.base.jdbc.config; import java.util.Optional; -import java.util.OptionalInt; import io.smallrye.config.ConfigMapping; import io.smallrye.config.ConfigMapping.NamingStrategy; +import io.smallrye.config.WithDefault; /** * Configuration properties for a JDBC service. @@ -58,28 +58,32 @@ public interface JdbcOptions { * * @return The maximum number of connections in the pool. */ - OptionalInt maximumPoolSize(); + @WithDefault("15") + int maximumPoolSize(); /** * Gets the minimum size of the DB connection pool. * * @return The minimum number of connections in the pool. */ - OptionalInt minimumPoolSize(); + @WithDefault("3") + int minimumPoolSize(); /** * Gets the initial size of the DB connection pool. * * @return The initial number of connections in the pool. */ - OptionalInt initialPoolSize(); + @WithDefault("3") + int initialPoolSize(); /** * Gets the maximum idle time of connections in the DB connection pool. * * @return The maximum idle time of connections in the pool. */ - OptionalInt maximumIdleTime(); + @WithDefault("3600") + int maximumIdleTime(); /** * Gets the name of the table that contains the data. diff --git a/services/base-jdbc/src/main/java/org/eclipse/hono/service/base/jdbc/config/JdbcProperties.java b/services/base-jdbc/src/main/java/org/eclipse/hono/service/base/jdbc/config/JdbcProperties.java index 08561b4569..32a9329d87 100644 --- a/services/base-jdbc/src/main/java/org/eclipse/hono/service/base/jdbc/config/JdbcProperties.java +++ b/services/base-jdbc/src/main/java/org/eclipse/hono/service/base/jdbc/config/JdbcProperties.java @@ -32,10 +32,6 @@ public class JdbcProperties { private static final Logger log = LoggerFactory.getLogger(JdbcProperties.class); - private static final Integer MAXIMUM_POOL_SIZE_DEFAULT = 15; - private static final Integer MINIMUM_POOL_SIZE_DEFAULT = 3; - private static final Integer INITIAL_POOL_SIZE_DEFAULT = 3; - private static final Integer MAXIMUM_IDLE_TIME_DEFAULT = 3600; private String url; private String driverClass; @@ -63,10 +59,10 @@ public JdbcProperties() { public JdbcProperties(final JdbcOptions options) { Objects.requireNonNull(options); setDriverClass(options.driverClass()); - options.maximumPoolSize().ifPresentOrElse(this::setMaximumPoolSize, () -> setMaximumPoolSize(MAXIMUM_POOL_SIZE_DEFAULT)); - options.minimumPoolSize().ifPresentOrElse(this::setMinimumPoolSize, () -> setMinimumPoolSize(MINIMUM_POOL_SIZE_DEFAULT)); - options.initialPoolSize().ifPresentOrElse(this::setInitialPoolSize, () -> setInitialPoolSize(INITIAL_POOL_SIZE_DEFAULT)); - options.maximumIdleTime().ifPresentOrElse(this::setMaximumIdleTime, () -> setMaximumIdleTime(MAXIMUM_IDLE_TIME_DEFAULT)); + setMaximumPoolSize(options.maximumPoolSize()); + setMinimumPoolSize(options.minimumPoolSize()); + setInitialPoolSize(options.initialPoolSize()); + setMaximumIdleTime(options.maximumIdleTime()); options.password().ifPresent(this::setPassword); options.tableName().ifPresent(this::setTableName); setUrl(options.url());