From bb875c81b40f1fd0fb4975c200f24e9731433f5a Mon Sep 17 00:00:00 2001 From: mkrueger92 <7305571+mkrueger92@users.noreply.github.com> Date: Tue, 2 Jul 2024 15:24:26 +0200 Subject: [PATCH] Expose validate-on-borrow Expose the option to validate the connection on borrow as supported by Agroal. Fix #41616 --- .../agroal/runtime/DataSourceJdbcRuntimeConfig.java | 9 +++++++++ .../main/java/io/quarkus/agroal/runtime/DataSources.java | 1 + 2 files changed, 10 insertions(+) diff --git a/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSourceJdbcRuntimeConfig.java b/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSourceJdbcRuntimeConfig.java index 392903d7d3105f..d2c1528f877152 100644 --- a/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSourceJdbcRuntimeConfig.java +++ b/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSourceJdbcRuntimeConfig.java @@ -115,6 +115,15 @@ public interface DataSourceJdbcRuntimeConfig { */ Optional validationQuerySql(); + /** + * Forces connection validation prior to acquisition (foreground validation) regardless of the idle status. + *

+ * Because of the overhead of performing validation on every call, it’s recommended to rely on default idle validation + * instead, and to leave this to `false`. + */ + @WithDefault("false") + boolean validateOnBorrow(); + /** * Disable pooling to prevent reuse of Connections. Use this when an external pool manages the life-cycle * of Connections. diff --git a/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSources.java b/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSources.java index 3b8694dcc50252..a8b005fc4aa538 100644 --- a/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSources.java +++ b/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSources.java @@ -410,6 +410,7 @@ public boolean isValid(Connection connection) { } }); } + poolConfiguration.validateOnBorrow(dataSourceJdbcRuntimeConfig.validateOnBorrow()); poolConfiguration.reapTimeout(dataSourceJdbcRuntimeConfig.idleRemovalInterval()); if (dataSourceJdbcRuntimeConfig.leakDetectionInterval().isPresent()) { poolConfiguration.leakTimeout(dataSourceJdbcRuntimeConfig.leakDetectionInterval().get());