From 9dcae54dd7b28156396e39dde4fa9e145cfc5e24 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Sun, 22 Dec 2024 01:36:19 +0100 Subject: [PATCH] add two additional convenience methods to HibernatePersistenceConfiguration improve some jdoc --- .../java/org/hibernate/cfg/JdbcSettings.java | 12 ++++- .../HibernatePersistenceConfiguration.java | 53 ++++++++++++++++--- 2 files changed, 56 insertions(+), 9 deletions(-) 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 909d56ec8e8d..d95c69efca4e 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/JdbcSettings.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/JdbcSettings.java @@ -105,6 +105,9 @@ public interface JdbcSettings extends C3p0Settings, AgroalSettings, HikariCPSett * *

* See section 8.2.1.9 + * + * @see java.sql.DriverManager#getConnection(String, String, String) + * @see javax.sql.DataSource#getConnection(String, String) */ String JAKARTA_JDBC_USER = "jakarta.persistence.jdbc.user"; @@ -115,6 +118,9 @@ public interface JdbcSettings extends C3p0Settings, AgroalSettings, HikariCPSett * and {@link #JAKARTA_JDBC_USER} to specify how to connect to the database. *

* See JPA 2 section 8.2.1.9 + * + * @see java.sql.DriverManager#getConnection(String, String, String) + * @see javax.sql.DataSource#getConnection(String, String) */ String JAKARTA_JDBC_PASSWORD = "jakarta.persistence.jdbc.password"; @@ -256,11 +262,13 @@ public interface JdbcSettings extends C3p0Settings, AgroalSettings, HikariCPSett * {@link org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl}. *

* Possible values are enumerated by {@link java.sql.Connection}: - * {@code NONE}, {@code READ_UNCOMMITTED}, {@code READ_COMMITTED}, + * {@code READ_UNCOMMITTED}, {@code READ_COMMITTED}, * {@code REPEATABLE_READ}, {@code SERIALIZABLE}. *

* If this setting is not explicitly specified, Hibernate does not modify * the transaction isolation level of the JDBC connection. + * + * @see java.sql.Connection#setTransactionIsolation(int) */ String ISOLATION = "hibernate.connection.isolation"; @@ -270,6 +278,8 @@ public interface JdbcSettings extends C3p0Settings, AgroalSettings, HikariCPSett * including every built-in implementation except for * {@link org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl}. * + * @see java.sql.Connection#setAutoCommit(boolean) + * * @settingDefault {@code false} */ String AUTOCOMMIT = "hibernate.connection.autocommit"; diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/HibernatePersistenceConfiguration.java b/hibernate-core/src/main/java/org/hibernate/jpa/HibernatePersistenceConfiguration.java index 32aa2d497949..054fdccdaf4f 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/HibernatePersistenceConfiguration.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/HibernatePersistenceConfiguration.java @@ -99,8 +99,8 @@ public SessionFactory createEntityManagerFactory() { } /** - * JDBC driver class name for non-{@link javax.sql.DataSource DataSource} - * connection. + * JDBC driver class name. This setting is ignored when Hibernate is configured + * to obtain connections from a {@link javax.sql.DataSource}. * * @see #JDBC_DRIVER */ @@ -110,7 +110,8 @@ public HibernatePersistenceConfiguration jdbcDriver(String driverName) { } /** - * JDBC URL of non-{@link javax.sql.DataSource DataSource} JDBC connection. + * JDBC URL. This setting is ignored when Hibernate is configured to obtain + * connections from a {@link javax.sql.DataSource}. * * @see #JDBC_URL */ @@ -120,10 +121,12 @@ public HibernatePersistenceConfiguration jdbcUrl(String url) { } /** - * Username for non-{@link javax.sql.DataSource DataSource} JDBC connection. + * Username for JDBC authentication. * * @see #JDBC_USER * @see #jdbcPassword + * @see java.sql.DriverManager#getConnection(String, String, String) + * @see javax.sql.DataSource#getConnection(String, String) */ public HibernatePersistenceConfiguration jdbcUsername(String username) { property( JDBC_USER, username ); @@ -131,10 +134,12 @@ public HibernatePersistenceConfiguration jdbcUsername(String username) { } /** - * Password for non-{@link javax.sql.DataSource DataSource} JDBC connection. + * Password for JDBC authentication. * * @see #JDBC_PASSWORD * @see #jdbcUsername + * @see java.sql.DriverManager#getConnection(String, String, String) + * @see javax.sql.DataSource#getConnection(String, String) */ public HibernatePersistenceConfiguration jdbcPassword(String password) { property( JDBC_PASSWORD, password ); @@ -142,13 +147,14 @@ public HibernatePersistenceConfiguration jdbcPassword(String password) { } /** - * Username and password for non-{@link javax.sql.DataSource DataSource} - * JDBC connection. + * Username and password for JDBC authentication. * * @see #JDBC_USER * @see #JDBC_PASSWORD * @see #jdbcUsername * @see #jdbcPassword + * @see java.sql.DriverManager#getConnection(String, String, String) + * @see javax.sql.DataSource#getConnection(String, String) */ public HibernatePersistenceConfiguration jdbcCredentials(String username, String password) { jdbcUsername( username ); @@ -157,7 +163,8 @@ public HibernatePersistenceConfiguration jdbcCredentials(String username, String } /** - * The JDBC connection pool size. + * The JDBC connection pool size. This setting is ignored when Hibernate is + * configured to obtain connections from a {@link javax.sql.DataSource}. * * @see JdbcSettings#POOL_SIZE */ @@ -166,6 +173,36 @@ public HibernatePersistenceConfiguration jdbcPoolSize(int poolSize) { return this; } + /** + * The JDBC {@linkplain java.sql.Connection#setAutoCommit autocommit mode} + * for pooled connections. This setting is ignored when Hibernate is + * configured to obtain connections from a {@link javax.sql.DataSource}. + * + * @see JdbcSettings#AUTOCOMMIT + */ + public HibernatePersistenceConfiguration jdbcAutocommit(boolean autocommit) { + property( JdbcSettings.AUTOCOMMIT, autocommit ); + return this; + } + + /** + * The JDBC {@linkplain java.sql.Connection#setTransactionIsolation transaction + * isolation level}. This setting is ignored when Hibernate is configured to + * obtain connections from a {@link javax.sql.DataSource}. + *

+ * Possible values are enumerated by {@link java.sql.Connection}: + * {@link java.sql.Connection#TRANSACTION_READ_UNCOMMITTED}, + * {@link java.sql.Connection#TRANSACTION_READ_COMMITTED}, + * {@link java.sql.Connection#TRANSACTION_REPEATABLE_READ}, and + * {@link java.sql.Connection#TRANSACTION_SERIALIZABLE}. + * + * @see JdbcSettings#ISOLATION + */ + public HibernatePersistenceConfiguration jdbcTransactionIsolation(int isolationLevel) { + property( JdbcSettings.ISOLATION, isolationLevel ); + return this; + } + /** * Enables SQL logging to the console. *