diff --git a/hibernate-agroal/src/main/java/org/hibernate/agroal/internal/AgroalConnectionProvider.java b/hibernate-agroal/src/main/java/org/hibernate/agroal/internal/AgroalConnectionProvider.java index f0dd50069b..6374f9a643 100644 --- a/hibernate-agroal/src/main/java/org/hibernate/agroal/internal/AgroalConnectionProvider.java +++ b/hibernate-agroal/src/main/java/org/hibernate/agroal/internal/AgroalConnectionProvider.java @@ -14,6 +14,7 @@ import io.agroal.api.configuration.supplier.AgroalPropertiesReader; import io.agroal.api.security.NamePrincipal; import io.agroal.api.security.SimplePassword; import org.hibernate.HibernateException; +import org.hibernate.cfg.AgroalSettings; import org.hibernate.cfg.AvailableSettings; import org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator; import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; @@ -43,15 +44,17 @@ import java.util.function.Function; * hibernate.connection.isolation * * - * Other configuration options are available, using the
hibernate.agroalprefix ( @see AgroalPropertiesReader ) + * Other configuration options are available, using the {@code hibernate.agroal} prefix * + * @see AgroalSettings + * @see AgroalPropertiesReader * @see AvailableSettings#CONNECTION_PROVIDER * * @author Luis Barreiro */ public class AgroalConnectionProvider implements ConnectionProvider, Configurable, Stoppable { - public static final String CONFIG_PREFIX = "hibernate.agroal."; + public static final String CONFIG_PREFIX = AgroalSettings.AGROAL_CONFIG_PREFIX + "."; private static final long serialVersionUID = 1L; private static final Logger LOGGER = Logger.getLogger( AgroalConnectionProvider.class ); private AgroalDataSource agroalDataSource = null; diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/AgroalSettings.java b/hibernate-core/src/main/java/org/hibernate/cfg/AgroalSettings.java new file mode 100644 index 0000000000..a19ec12a5a --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/cfg/AgroalSettings.java @@ -0,0 +1,132 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or
+ * There is no default, this setting is mandatory. + */ + String AGROAL_MAX_SIZE = AGROAL_CONFIG_PREFIX + ".maxSize"; + + /** + * The ninimum size of the connection pool. + *
+ * The default is zero. + */ + String AGROAL_MIN_SIZE = AGROAL_CONFIG_PREFIX + ".minSize"; + + /** + * Initial size of the connection pool. + *
+ * The default is zero. + */ + String AGROAL_INITIAL_SIZE = AGROAL_CONFIG_PREFIX + ".initialSize"; + + /** + * The maximum amount of time a connection can live, after which it is evicted. + *
+ * The default is zero, resulting in no restriction on connection lifetime. + *
+ * Parsed as a {@link java.time.Duration}. + * + * @see java.time.Duration#parse(CharSequence) + */ + String AGROAL_MAX_LIFETIME = AGROAL_CONFIG_PREFIX + ".maxLifetime"; + + /** + * The maximum amount of time a connection can remain out of the pool, after + * which it is reported as a leak. + *
+ * The default is zero, resulting in no checks for connection leaks. + *
+ * Parsed as a {@link java.time.Duration}. + * + * @see java.time.Duration#parse(CharSequence) + */ + String AGROAL_LEAK_TIMEOUT = AGROAL_CONFIG_PREFIX + ".leakTimeout"; + + /** + * The maximum amount of time a connection can remain idle, after which it is evicted. + *
+ * The default is zero, resulting in connections never being considered idle. + *
+ * Parsed as a {@link java.time.Duration}. + * + * @see java.time.Duration#parse(CharSequence) + */ + String AGROAL_IDLE_TIMEOUT = AGROAL_CONFIG_PREFIX + ".reapTimeout"; + + /** + * The maximum amount of time a thread can wait for a connection, after which an + * exception is thrown instead. + *
+ * The default is zero, resulting in threads waiting indefinitely. + *
+ * Parsed as a {@link java.time.Duration}. + * + * @see java.time.Duration#parse(CharSequence) + */ + String AGROAL_ACQUISITION_TIMEOUT = AGROAL_CONFIG_PREFIX + ".acquisitionTimeout"; + + /** + * Background validation is executed at intervals of this value. + *
+ * The default is zero, resulting in background validation not being performed. + *
+ * Parsed as a {@link java.time.Duration}. + * + * @see java.time.Duration#parse(CharSequence) + */ + String AGROAL_VALIDATION_TIMEOUT = AGROAL_CONFIG_PREFIX + ".validationTimeout"; + + /** + * A foreground validation is executed if a connection has been idle in the pool + * for longer than this value. + *
+ * The default is zero, resulting in foreground validation not being performed. + *
+ * Parsed as a {@link java.time.Duration}. + * + * @see java.time.Duration#parse(CharSequence) + */ + String AGROAL_IDLE_VALIDATION_TIMEOUT = AGROAL_CONFIG_PREFIX + ".idleValidation"; + + /** + * An SQL command to be executed when a connection is created. + */ + String AGROAL_INITIAL_SQL = AGROAL_CONFIG_PREFIX + ".initialSQL"; + + /** + * If {@code true}, connections will be flushed whenever they return to the pool. + *
+ * The default is {@code false}. + * + * @since agroal-api 1.6 + */ + String AGROAL_FLUSH_ON_CLOSE = AGROAL_CONFIG_PREFIX + ".flushOnClose"; + + /** + * If {@code true}, connections will receive foreground validation on every acquisition + * regardless of {@link AgroalSettings#AGROAL_IDLE_VALIDATION_TIMEOUT}. + *
+ * The default is {@code false}.
+ *
+ * @since agroal-api 2.3
+ */
+ String AGROAL_VALIDATE_ON_BORROW = AGROAL_CONFIG_PREFIX + ".validateOnBorrow";
+}
diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/HikariCPSettings.java b/hibernate-core/src/main/java/org/hibernate/cfg/HikariCPSettings.java
new file mode 100644
index 0000000000..75be367506
--- /dev/null
+++ b/hibernate-core/src/main/java/org/hibernate/cfg/HikariCPSettings.java
@@ -0,0 +1,118 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
+ * See the lgpl.txt file in the root directory or
+ * The default is 10.
+ */
+ String HIKARI_MAX_SIZE = HIKARI_CONFIG_PREFIX + ".maximumPoolSize";
+
+ /**
+ * The minimum number of idle connections to try and maintain in the pool.
+ *
+ * The default is the same as {@link HikariCPSettings#HIKARI_MAX_SIZE}.
+ */
+ String HIKARI_MIN_IDLE_SIZE = HIKARI_CONFIG_PREFIX + ".minimumIdle";
+
+ /**
+ * The maximum amount of time a connection can live, after which it is evicted.
+ *
+ * The default is 1800000 milliseconds (30 minutes).
+ */
+ String HIKARI_MAX_LIFETIME = HIKARI_CONFIG_PREFIX + ".maxLifetime";
+
+ /**
+ * The maximum amount of time a connection can remain out of the pool, after
+ * which it is reported as a leak.
+ *
+ * The default is 0 milliseconds, resulting in no checks for connection leaks.
+ */
+ String HIKARI_LEAK_TIMEOUT = HIKARI_CONFIG_PREFIX + ".leakDetectionThreshold";
+
+ /**
+ * The maximum amount of time a connection can remain idle, after which it is evicted.
+ *
+ * The default is 600000 milliseconds (10 minutes).
+ */
+ String HIKARI_IDLE_TIMEOUT = HIKARI_CONFIG_PREFIX + ".idleTimeout";
+
+ /**
+ * The maximum amount of time a thread can wait for a connection, after which an
+ * exception is thrown instead.
+ *
+ * The default is 30000 milliseconds (30 seconds).
+ */
+ String HIKARI_ACQUISITION_TIMEOUT = HIKARI_CONFIG_PREFIX + ".connectionTimeout";
+
+ /**
+ * The maximum amount of time that a connection will be tested for aliveness. Must
+ * be lower than {@link HikariCPSettings#HIKARI_ACQUISITION_TIMEOUT}.
+ *
+ * The default is 5000 milliseconds (5 seconds).
+ */
+ String HIKARI_VALIDATION_TIMEOUT = HIKARI_CONFIG_PREFIX + ".validationTimeout";
+
+ /**
+ * The maximum amount of time the application thread can wait to attempt to acquire
+ * an initial connection. Applied after {@link HikariCPSettings#HIKARI_ACQUISITION_TIMEOUT}.
+ *
+ * The default is 1 millisecond.
+ */
+ String HIKARI_INITIALIZATION_TIMEOUT = HIKARI_CONFIG_PREFIX + ".initializationFailTimeout";
+
+ /**
+ * How often connections will attempt to be kept alive to prevent a timeout.
+ *
+ * The default is 0 milliseconds, resulting in no keep-alive behaviour.
+ */
+ String HIKARI_KEEPALIVE_TIME = HIKARI_CONFIG_PREFIX + ".keepaliveTime";
+
+ /**
+ * An SQL command to be executed when a connection is created.
+ */
+ String HIKARI_INITIAL_SQL = HIKARI_CONFIG_PREFIX + ".connectionInitSql";
+
+ /**
+ * A user-defined name for the pool that appears in logging.
+ *
+ * The default is auto-generated.
+ */
+ String HIKARI_POOL_NAME = HIKARI_CONFIG_PREFIX + ".poolName";
+
+ /**
+ * If {@code true}, connections obtained from the pool are in read-only mode
+ * by default.
+ *
+ * Some databases do not support read-only mode while some will provide query
+ * optimizations when a connection is in read-only mode.
+ *
+ * The default is {@code false}.
+ */
+ String HIKARI_READ_ONLY = HIKARI_CONFIG_PREFIX + ".readOnly";
+
+ /**
+ * If {@code true}, internal pool queries (such as keep-alives) will be isolated
+ * in their own transaction.
+ *
+ * Only applies if {@link AvailableSettings#AUTOCOMMIT} is disabled.
+ *
+ * The default is {@code false}.
+ */
+ String HIKARI_ISOLATE_INTERNAL_QUERIES = HIKARI_CONFIG_PREFIX + ".isolateInternalQueries";
+}
diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/JdbcSettings.java b/hibernate-core/src/main/java/org/hibernate/cfg/JdbcSettings.java
index 9e15a64ddc..8c836fbd56 100644
--- a/hibernate-core/src/main/java/org/hibernate/cfg/JdbcSettings.java
+++ b/hibernate-core/src/main/java/org/hibernate/cfg/JdbcSettings.java
@@ -21,7 +21,7 @@ import org.hibernate.sql.ast.spi.ParameterMarkerStrategy;
*
* @author Steve Ebersole
*/
-public interface JdbcSettings extends C3p0Settings, ProxoolSettings {
+public interface JdbcSettings extends C3p0Settings, ProxoolSettings, AgroalSettings, HikariCPSettings {
/**
* Specifies a JTA {@link javax.sql.DataSource} to use for Connections.
diff --git a/hibernate-hikaricp/src/main/java/org/hibernate/hikaricp/internal/HikariConfigurationUtil.java b/hibernate-hikaricp/src/main/java/org/hibernate/hikaricp/internal/HikariConfigurationUtil.java
index 80831de868..1c11f6d8fa 100644
--- a/hibernate-hikaricp/src/main/java/org/hibernate/hikaricp/internal/HikariConfigurationUtil.java
+++ b/hibernate-hikaricp/src/main/java/org/hibernate/hikaricp/internal/HikariConfigurationUtil.java
@@ -11,6 +11,7 @@ import java.util.Map;
import java.util.Properties;
import org.hibernate.cfg.AvailableSettings;
+import org.hibernate.cfg.HikariCPSettings;
import org.hibernate.cfg.JdbcSettings;
import org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator;
@@ -26,7 +27,7 @@ import static org.hibernate.engine.jdbc.connections.internal.ConnectionProviderI
* @author Brett Meyer
*/
public class HikariConfigurationUtil {
- public static final String CONFIG_PREFIX = "hibernate.hikari.";
+ public static final String CONFIG_PREFIX = HikariCPSettings.HIKARI_CONFIG_PREFIX + ".";
/**
* Create/load a HikariConfig from Hibernate properties.