Skip to content

Commit 9dcae54

Browse files
committed
add two additional convenience methods to HibernatePersistenceConfiguration
improve some jdoc
1 parent aa26709 commit 9dcae54

File tree

2 files changed

+56
-9
lines changed

2 files changed

+56
-9
lines changed

hibernate-core/src/main/java/org/hibernate/cfg/JdbcSettings.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ public interface JdbcSettings extends C3p0Settings, AgroalSettings, HikariCPSett
105105
* </ul>
106106
* <p>
107107
* See section 8.2.1.9
108+
*
109+
* @see java.sql.DriverManager#getConnection(String, String, String)
110+
* @see javax.sql.DataSource#getConnection(String, String)
108111
*/
109112
String JAKARTA_JDBC_USER = "jakarta.persistence.jdbc.user";
110113

@@ -115,6 +118,9 @@ public interface JdbcSettings extends C3p0Settings, AgroalSettings, HikariCPSett
115118
* and {@link #JAKARTA_JDBC_USER} to specify how to connect to the database.
116119
* <p>
117120
* See JPA 2 section 8.2.1.9
121+
*
122+
* @see java.sql.DriverManager#getConnection(String, String, String)
123+
* @see javax.sql.DataSource#getConnection(String, String)
118124
*/
119125
String JAKARTA_JDBC_PASSWORD = "jakarta.persistence.jdbc.password";
120126

@@ -256,11 +262,13 @@ public interface JdbcSettings extends C3p0Settings, AgroalSettings, HikariCPSett
256262
* {@link org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl}.
257263
* <p>
258264
* Possible values are enumerated by {@link java.sql.Connection}:
259-
* {@code NONE}, {@code READ_UNCOMMITTED}, {@code READ_COMMITTED},
265+
* {@code READ_UNCOMMITTED}, {@code READ_COMMITTED},
260266
* {@code REPEATABLE_READ}, {@code SERIALIZABLE}.
261267
* <p>
262268
* If this setting is not explicitly specified, Hibernate does not modify
263269
* the transaction isolation level of the JDBC connection.
270+
*
271+
* @see java.sql.Connection#setTransactionIsolation(int)
264272
*/
265273
String ISOLATION = "hibernate.connection.isolation";
266274

@@ -270,6 +278,8 @@ public interface JdbcSettings extends C3p0Settings, AgroalSettings, HikariCPSett
270278
* including every built-in implementation except for
271279
* {@link org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl}.
272280
*
281+
* @see java.sql.Connection#setAutoCommit(boolean)
282+
*
273283
* @settingDefault {@code false}
274284
*/
275285
String AUTOCOMMIT = "hibernate.connection.autocommit";

hibernate-core/src/main/java/org/hibernate/jpa/HibernatePersistenceConfiguration.java

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ public SessionFactory createEntityManagerFactory() {
9999
}
100100

101101
/**
102-
* JDBC driver class name for non-{@link javax.sql.DataSource DataSource}
103-
* connection.
102+
* JDBC driver class name. This setting is ignored when Hibernate is configured
103+
* to obtain connections from a {@link javax.sql.DataSource}.
104104
*
105105
* @see #JDBC_DRIVER
106106
*/
@@ -110,7 +110,8 @@ public HibernatePersistenceConfiguration jdbcDriver(String driverName) {
110110
}
111111

112112
/**
113-
* JDBC URL of non-{@link javax.sql.DataSource DataSource} JDBC connection.
113+
* JDBC URL. This setting is ignored when Hibernate is configured to obtain
114+
* connections from a {@link javax.sql.DataSource}.
114115
*
115116
* @see #JDBC_URL
116117
*/
@@ -120,35 +121,40 @@ public HibernatePersistenceConfiguration jdbcUrl(String url) {
120121
}
121122

122123
/**
123-
* Username for non-{@link javax.sql.DataSource DataSource} JDBC connection.
124+
* Username for JDBC authentication.
124125
*
125126
* @see #JDBC_USER
126127
* @see #jdbcPassword
128+
* @see java.sql.DriverManager#getConnection(String, String, String)
129+
* @see javax.sql.DataSource#getConnection(String, String)
127130
*/
128131
public HibernatePersistenceConfiguration jdbcUsername(String username) {
129132
property( JDBC_USER, username );
130133
return this;
131134
}
132135

133136
/**
134-
* Password for non-{@link javax.sql.DataSource DataSource} JDBC connection.
137+
* Password for JDBC authentication.
135138
*
136139
* @see #JDBC_PASSWORD
137140
* @see #jdbcUsername
141+
* @see java.sql.DriverManager#getConnection(String, String, String)
142+
* @see javax.sql.DataSource#getConnection(String, String)
138143
*/
139144
public HibernatePersistenceConfiguration jdbcPassword(String password) {
140145
property( JDBC_PASSWORD, password );
141146
return this;
142147
}
143148

144149
/**
145-
* Username and password for non-{@link javax.sql.DataSource DataSource}
146-
* JDBC connection.
150+
* Username and password for JDBC authentication.
147151
*
148152
* @see #JDBC_USER
149153
* @see #JDBC_PASSWORD
150154
* @see #jdbcUsername
151155
* @see #jdbcPassword
156+
* @see java.sql.DriverManager#getConnection(String, String, String)
157+
* @see javax.sql.DataSource#getConnection(String, String)
152158
*/
153159
public HibernatePersistenceConfiguration jdbcCredentials(String username, String password) {
154160
jdbcUsername( username );
@@ -157,7 +163,8 @@ public HibernatePersistenceConfiguration jdbcCredentials(String username, String
157163
}
158164

159165
/**
160-
* The JDBC connection pool size.
166+
* The JDBC connection pool size. This setting is ignored when Hibernate is
167+
* configured to obtain connections from a {@link javax.sql.DataSource}.
161168
*
162169
* @see JdbcSettings#POOL_SIZE
163170
*/
@@ -166,6 +173,36 @@ public HibernatePersistenceConfiguration jdbcPoolSize(int poolSize) {
166173
return this;
167174
}
168175

176+
/**
177+
* The JDBC {@linkplain java.sql.Connection#setAutoCommit autocommit mode}
178+
* for pooled connections. This setting is ignored when Hibernate is
179+
* configured to obtain connections from a {@link javax.sql.DataSource}.
180+
*
181+
* @see JdbcSettings#AUTOCOMMIT
182+
*/
183+
public HibernatePersistenceConfiguration jdbcAutocommit(boolean autocommit) {
184+
property( JdbcSettings.AUTOCOMMIT, autocommit );
185+
return this;
186+
}
187+
188+
/**
189+
* The JDBC {@linkplain java.sql.Connection#setTransactionIsolation transaction
190+
* isolation level}. This setting is ignored when Hibernate is configured to
191+
* obtain connections from a {@link javax.sql.DataSource}.
192+
* <p>
193+
* Possible values are enumerated by {@link java.sql.Connection}:
194+
* {@link java.sql.Connection#TRANSACTION_READ_UNCOMMITTED},
195+
* {@link java.sql.Connection#TRANSACTION_READ_COMMITTED},
196+
* {@link java.sql.Connection#TRANSACTION_REPEATABLE_READ}, and
197+
* {@link java.sql.Connection#TRANSACTION_SERIALIZABLE}.
198+
*
199+
* @see JdbcSettings#ISOLATION
200+
*/
201+
public HibernatePersistenceConfiguration jdbcTransactionIsolation(int isolationLevel) {
202+
property( JdbcSettings.ISOLATION, isolationLevel );
203+
return this;
204+
}
205+
169206
/**
170207
* Enables SQL logging to the console.
171208
* <p>

0 commit comments

Comments
 (0)