Skip to content

Commit ae2fed4

Browse files
committed
HHH-10664 - Prep 6.0 feature branch - merge hibernate-entitymanager into hibernate-core (continued fixing of hibernate-core test failures)
1 parent a80ceae commit ae2fed4

File tree

65 files changed

+584
-643
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+584
-643
lines changed

documentation/src/main/asciidoc/userguide/appendices/Configurations.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,8 @@ Should we prefer using the `org.hibernate.engine.transaction.jta.platform.spi.Jt
424424
|`hibernate.transaction.auto_close_session` |`true` or `false` (default value) |Causes the session to be closed during the after completion phase of the transaction. If possible, use built-in and automatic session context management instead.
425425
|`hibernate.transaction.coordinator_class` | a|
426426

427-
Names the implementation of `org.hibernate.resource.transaction.TransactionCoordinatorBuilder` to use for creating `org.hibernate.resource.transaction.TransactionCoordinator` instances.
427+
Names the implementation of `org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder` to use for creating
428+
`org.hibernate.resource.transaction.spi.TransactionCoordinator` instances.
428429

429430
Can be
430431

documentation/src/main/asciidoc/userguide/chapters/transactions/Transactions.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ This documentation largely treats the physical and logic notions of a transactio
2020
Hibernate uses the JDBC API for persistence. In the world of Java there are two well-defined mechanism for dealing with transactions in JDBC: JDBC itself and JTA.
2121
Hibernate supports both mechanisms for integrating with transactions and allowing applications to manage physical transactions.
2222

23-
Transaction handling per `Session` is handled by the `org.hibernate.resource.transaction.TransactionCoordinator` contract, which are built by the `org.hibernate.resource.transaction.TransactionCoordinatorBuilder` service.
23+
Transaction handling per `Session` is handled by the `org.hibernate.resource.transaction.spi.TransactionCoordinator` contract,
24+
which are built by the `org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder` service.
2425
`TransactionCoordinatorBuilder` represents a strategy for dealing with transactions whereas TransactionCoordinator represents one instance of that strategy related to a Session.
2526
Which `TransactionCoordinatorBuilder` implementation to use is defined by the `hibernate.transaction.coordinator_class` setting.
2627

documentation/src/main/docbook/integrationsGuide/en-US/chapters/services/Services.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,9 @@
444444
<section>
445445
<title>TransactionCoordinatorBuilder</title>
446446
<para>
447-
<interfacename>org.hibernate.resource.transaction.TransactionCoordinatorBuilder</interfacename>
447+
<interfacename>org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder</interfacename>
448448
is used by Hibernate to integrate with and underlying transaction system. It is responsible for
449-
building <interfacename>org.hibernate.resource.transaction.TransactionCoordinator</interfacename>
449+
building <interfacename>org.hibernate.resource.transaction.spi.TransactionCoordinator</interfacename>
450450
instances for use by each Hibernate Session.
451451
</para>
452452
</section>

documentation/src/main/docbook/manual-old/en-US/content/bootstrap.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,8 @@
410410
<title>Transaction configuration</title>
411411

412412
<para>
413-
Transaction handling per Session is handled by the <interfacename>org.hibernate.resource.transaction.TransactionCoordinator</interfacename>
414-
contract, which are built by the <interfacename>org.hibernate.resource.transaction.TransactionCoordinatorBuilder</interfacename>
413+
Transaction handling per Session is handled by the <interfacename>org.hibernate.resource.transaction.spi.TransactionCoordinator</interfacename>
414+
contract, which are built by the <interfacename>org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder</interfacename>
415415
service. TransactionCoordinatorBuilder represents a strategy for dealing with transactions whereas
416416
TransactionCoordinator represents one instance of that strategy related to a Session. Which
417417
TransactionCoordinatorBuilder implementation to use is defined by the <literal>hibernate.transaction.coordinator_class</literal>

documentation/src/main/docbook/userGuide/en-US/chapters/transactions/Transactions.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252

5353
<para>
5454
Transaction handling per Session is handled by the
55-
<interfacename>org.hibernate.resource.transaction.TransactionCoordinator</interfacename> contract, which
56-
are built by the <interfacename>org.hibernate.resource.transaction.TransactionCoordinatorBuilder</interfacename>
55+
<interfacename>org.hibernate.resource.transaction.spi.TransactionCoordinator</interfacename> contract, which
56+
are built by the <interfacename>org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder</interfacename>
5757
service. TransactionCoordinatorBuilder represents a strategy for dealing with transactions whereas
5858
TransactionCoordinator represents one instance of that strategy related to a Session. Which
5959
TransactionCoordinatorBuilder implementation to use is defined by the

hibernate-core/src/main/java/org/hibernate/ConnectionAcquisitionMode.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
*/
77
package org.hibernate;
88

9+
import org.hibernate.internal.util.StringHelper;
10+
911
/**
1012
* Indicates the manner in which JDBC Connections should be acquired. Inverse to
1113
* {@link org.hibernate.ConnectionReleaseMode}.
@@ -32,4 +34,21 @@ public static ConnectionAcquisitionMode interpret(String value) {
3234

3335
return AS_NEEDED;
3436
}
37+
38+
public static ConnectionAcquisitionMode interpret(Object setting) {
39+
if ( setting == null ) {
40+
return null;
41+
}
42+
43+
if ( setting instanceof ConnectionAcquisitionMode ) {
44+
return (ConnectionAcquisitionMode) setting;
45+
}
46+
47+
final String value = setting.toString();
48+
if ( StringHelper.isEmpty( value ) ) {
49+
return null;
50+
}
51+
52+
return interpret( value );
53+
}
3554
}

hibernate-core/src/main/java/org/hibernate/ConnectionReleaseMode.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
import java.util.Locale;
1010

11+
import org.hibernate.internal.util.StringHelper;
12+
1113
/**
1214
* Defines the various policies by which Hibernate might release its underlying
1315
* JDBC connection. Inverse of {@link ConnectionAcquisitionMode}.
@@ -48,4 +50,26 @@ public enum ConnectionReleaseMode{
4850
public static ConnectionReleaseMode parse(final String name) {
4951
return ConnectionReleaseMode.valueOf( name.toUpperCase(Locale.ROOT) );
5052
}
53+
54+
public static ConnectionReleaseMode interpret(Object setting) {
55+
if ( setting == null ) {
56+
return null;
57+
}
58+
59+
if ( setting instanceof ConnectionReleaseMode ) {
60+
return (ConnectionReleaseMode) setting;
61+
}
62+
63+
final String value = setting.toString();
64+
if ( StringHelper.isEmpty( value ) ) {
65+
return null;
66+
}
67+
68+
// here we disregard "auto"
69+
if ( value.equalsIgnoreCase( "auto" ) ) {
70+
return null;
71+
}
72+
73+
return parse( value );
74+
}
5175
}

hibernate-core/src/main/java/org/hibernate/SessionBuilder.java

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
package org.hibernate;
88

99
import java.sql.Connection;
10-
import javax.persistence.spi.PersistenceUnitTransactionType;
1110

1211
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
1312
import org.hibernate.resource.jdbc.spi.StatementInspector;
@@ -92,30 +91,62 @@ public interface SessionBuilder<T extends SessionBuilder> {
9291
* @param autoJoinTransactions Should JTA transactions be automatically joined
9392
*
9493
* @return {@code this}, for method chaining
94+
*
95+
* @see javax.persistence.SynchronizationType#SYNCHRONIZED
9596
*/
9697
T autoJoinTransactions(boolean autoJoinTransactions);
9798

9899
/**
99-
* Should the session be automatically closed afterQuery transaction completion.
100+
* Should the session be automatically closed after transaction completion?
100101
*
101102
* @param autoClose Should the session be automatically closed
102103
*
103104
* @return {@code this}, for method chaining
104105
*
105-
* @deprecated Only integrations can specify autoClosing behavior of individual sessions. See
106-
* {@link org.hibernate.engine.spi.SessionOwner}
106+
* @see javax.persistence.PersistenceContextType
107107
*/
108-
@Deprecated
109108
T autoClose(boolean autoClose);
110109

110+
/**
111+
* Should the session be automatically cleared on a failed transaction?
112+
*
113+
* @param autoClear Whether the Session should be automatically cleared
114+
*
115+
* @return {@code this}, for method chaining
116+
*/
117+
T autoClear(boolean autoClear);
118+
119+
/**
120+
* Specify the initial FlushMode to use for the opened Session
121+
*
122+
* @param flushMode The initial FlushMode to use for the opened Session
123+
*
124+
* @return {@code this}, for method chaining
125+
*
126+
* @see javax.persistence.PersistenceContextType
127+
*/
128+
T flushMode(FlushMode flushMode);
129+
111130
/**
112131
* Should the session be automatically flushed during the "beforeQuery completion" phase of transaction handling.
113132
*
114133
* @param flushBeforeCompletion Should the session be automatically flushed
115134
*
116135
* @return {@code this}, for method chaining
136+
*
137+
* @deprecated (since 5.2) use {@link #flushMode(FlushMode)} instead.
117138
*/
118-
T flushBeforeCompletion(boolean flushBeforeCompletion);
139+
@Deprecated
140+
@SuppressWarnings("unchecked")
141+
default T flushBeforeCompletion(boolean flushBeforeCompletion) {
142+
if ( flushBeforeCompletion ) {
143+
flushMode( FlushMode.ALWAYS );
144+
}
145+
else {
146+
flushMode( FlushMode.MANUAL );
147+
}
148+
return (T) this;
149+
}
119150

120151
/**
121152
* Define the tenant identifier to be associated with the opened session.
@@ -143,6 +174,4 @@ public interface SessionBuilder<T extends SessionBuilder> {
143174
*/
144175
T clearEventListeners();
145176

146-
T persistenceUnitTransactionType(PersistenceUnitTransactionType persistenceUnitTransactionType);
147-
148177
}

hibernate-core/src/main/java/org/hibernate/SharedSessionBuilder.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,30 @@ default T transactionContext() {
6464
T autoJoinTransactions();
6565

6666
/**
67-
* Signifies that the autoClose flag from the original session should be used to create the new session.
67+
* Signifies that the FlushMode from the original session should be used to create the new session.
6868
*
6969
* @return {@code this}, for method chaining
70+
*/
71+
T flushMode();
72+
73+
/**
74+
* Signifies that the autoClose flag from the original session should be used to create the new session.
7075
*
71-
* @deprecated For same reasons as {@link SessionBuilder#autoClose(boolean)} was deprecated. However, shared
72-
* session builders can use {@link #autoClose(boolean)} since they do not "inherit" the owner.
76+
* @return {@code this}, for method chaining
7377
*/
74-
@Deprecated
7578
T autoClose();
7679

7780
/**
7881
* Signifies that the flushBeforeCompletion flag from the original session should be used to create the new session.
7982
*
8083
* @return {@code this}, for method chaining
84+
*
85+
* @deprecated (since 5.2) use {@link #flushMode()} instead.
8186
*/
82-
T flushBeforeCompletion();
87+
@Deprecated
88+
@SuppressWarnings("unchecked")
89+
default T flushBeforeCompletion() {
90+
flushMode();
91+
return (T) this;
92+
}
8393
}

hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryBuilderImpl.java

Lines changed: 59 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@
4646
import org.hibernate.engine.jdbc.spi.JdbcServices;
4747
import org.hibernate.hql.spi.id.MultiTableBulkIdStrategy;
4848
import org.hibernate.internal.SessionFactoryImpl;
49+
import org.hibernate.internal.log.DeprecationLogger;
4950
import org.hibernate.internal.util.config.ConfigurationHelper;
5051
import org.hibernate.loader.BatchFetchStyle;
5152
import org.hibernate.proxy.EntityNotFoundDelegate;
5253
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
5354
import org.hibernate.resource.jdbc.spi.StatementInspector;
54-
import org.hibernate.resource.transaction.TransactionCoordinatorBuilder;
55+
import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder;
5556
import org.hibernate.service.spi.ServiceRegistryImplementor;
5657
import org.hibernate.tuple.entity.EntityTuplizer;
5758
import org.hibernate.tuple.entity.EntityTuplizerFactory;
@@ -66,6 +67,7 @@
6667
import static org.hibernate.cfg.AvailableSettings.BATCH_VERSIONED_DATA;
6768
import static org.hibernate.cfg.AvailableSettings.CACHE_REGION_PREFIX;
6869
import static org.hibernate.cfg.AvailableSettings.CHECK_NULLABILITY;
70+
import static org.hibernate.cfg.AvailableSettings.CONNECTION_HANDLING;
6971
import static org.hibernate.cfg.AvailableSettings.CUSTOM_ENTITY_DIRTINESS_STRATEGY;
7072
import static org.hibernate.cfg.AvailableSettings.DEFAULT_BATCH_FETCH_SIZE;
7173
import static org.hibernate.cfg.AvailableSettings.DEFAULT_ENTITY_MODE;
@@ -587,7 +589,7 @@ public SessionFactoryOptionsStateStandardImpl(StandardServiceRegistry serviceReg
587589
true
588590
);
589591

590-
this.flushBeforeCompletionEnabled = cfgService.getSetting( FLUSH_BEFORE_COMPLETION, BOOLEAN, false );
592+
this.flushBeforeCompletionEnabled = cfgService.getSetting( FLUSH_BEFORE_COMPLETION, BOOLEAN, true );
591593
this.autoCloseSessionEnabled = cfgService.getSetting( AUTO_CLOSE_SESSION, BOOLEAN, false );
592594

593595
this.statisticsEnabled = cfgService.getSetting( GENERATE_STATISTICS, BOOLEAN, false );
@@ -730,34 +732,71 @@ else if ( statelessInterceptorSetting instanceof Class ) {
730732
);
731733
this.jdbcFetchSize = ConfigurationHelper.getInteger( STATEMENT_FETCH_SIZE, configurationSettings );
732734

733-
final ConnectionAcquisitionMode connectionAcquisitionMode = ConnectionAcquisitionMode.interpret(
734-
ConfigurationHelper.getString(
735-
ACQUIRE_CONNECTIONS,
736-
configurationSettings,
737-
ConnectionAcquisitionMode.AS_NEEDED.name()
738-
)
735+
this.connectionHandlingMode = interpretConnectionHandlingMode( configurationSettings, serviceRegistry );
736+
737+
this.commentsEnabled = ConfigurationHelper.getBoolean( USE_SQL_COMMENTS, configurationSettings );
738+
739+
this.preferUserTransaction = ConfigurationHelper.getBoolean( PREFER_USER_TRANSACTION, configurationSettings, false );
740+
}
741+
742+
private PhysicalConnectionHandlingMode interpretConnectionHandlingMode(
743+
Map configurationSettings,
744+
StandardServiceRegistry serviceRegistry) {
745+
final PhysicalConnectionHandlingMode specifiedHandlingMode = PhysicalConnectionHandlingMode.interpret(
746+
configurationSettings.get( CONNECTION_HANDLING )
739747
);
740748

741-
final ConnectionReleaseMode connectionReleaseMode;
742-
final String releaseModeName = ConfigurationHelper.getString( RELEASE_CONNECTIONS, configurationSettings, "auto" );
743-
if ( "auto".equals( releaseModeName ) ) {
749+
if ( specifiedHandlingMode != null ) {
750+
return specifiedHandlingMode;
751+
}
752+
753+
754+
final TransactionCoordinatorBuilder transactionCoordinatorBuilder = serviceRegistry.getService( TransactionCoordinatorBuilder.class );
755+
756+
// see if the deprecated ConnectionAcquisitionMode/ConnectionReleaseMode were used..
757+
final ConnectionAcquisitionMode specifiedAcquisitionMode = ConnectionAcquisitionMode.interpret(
758+
configurationSettings.get( ACQUIRE_CONNECTIONS )
759+
);
760+
final ConnectionReleaseMode specifiedReleaseMode = ConnectionReleaseMode.interpret(
761+
configurationSettings.get( RELEASE_CONNECTIONS )
762+
);
763+
if ( specifiedAcquisitionMode != null || specifiedReleaseMode != null ) {
764+
return interpretConnectionHandlingMode( specifiedAcquisitionMode, specifiedReleaseMode, configurationSettings, transactionCoordinatorBuilder );
765+
}
766+
767+
return transactionCoordinatorBuilder.getDefaultConnectionHandlingMode();
768+
}
769+
770+
@Deprecated
771+
private PhysicalConnectionHandlingMode interpretConnectionHandlingMode(
772+
ConnectionAcquisitionMode specifiedAcquisitionMode,
773+
ConnectionReleaseMode specifiedReleaseMode,
774+
Map configurationSettings,
775+
TransactionCoordinatorBuilder transactionCoordinatorBuilder) {
776+
DeprecationLogger.DEPRECATION_LOGGER.logUseOfDeprecatedConnectionHandlingSettings();
777+
778+
final ConnectionAcquisitionMode effectiveAcquisitionMode = specifiedAcquisitionMode == null
779+
? ConnectionAcquisitionMode.AS_NEEDED
780+
: specifiedAcquisitionMode;
781+
782+
final ConnectionReleaseMode effectiveReleaseMode;
783+
if ( specifiedReleaseMode == null ) {
784+
// check the actual setting. If we get in here it *should* be "auto" or null
785+
final String releaseModeName = ConfigurationHelper.getString( RELEASE_CONNECTIONS, configurationSettings, "auto" );
786+
assert "auto".equalsIgnoreCase( releaseModeName );
744787
// nothing was specified (or someone happened to configure the "magic" value)
745-
if ( connectionAcquisitionMode == ConnectionAcquisitionMode.IMMEDIATELY ) {
746-
connectionReleaseMode = ConnectionReleaseMode.ON_CLOSE;
788+
if ( effectiveAcquisitionMode == ConnectionAcquisitionMode.IMMEDIATELY ) {
789+
effectiveReleaseMode = ConnectionReleaseMode.ON_CLOSE;
747790
}
748791
else {
749-
connectionReleaseMode = serviceRegistry.getService( TransactionCoordinatorBuilder.class )
750-
.getDefaultConnectionReleaseMode();
792+
effectiveReleaseMode = transactionCoordinatorBuilder.getDefaultConnectionReleaseMode();
751793
}
752794
}
753795
else {
754-
connectionReleaseMode = ConnectionReleaseMode.parse( releaseModeName );
796+
effectiveReleaseMode = specifiedReleaseMode;
755797
}
756-
this.connectionHandlingMode = PhysicalConnectionHandlingMode.interpret( connectionAcquisitionMode, connectionReleaseMode );
757-
758-
this.commentsEnabled = ConfigurationHelper.getBoolean( USE_SQL_COMMENTS, configurationSettings );
759798

760-
this.preferUserTransaction = ConfigurationHelper.getBoolean( PREFER_USER_TRANSACTION, configurationSettings, false );
799+
return PhysicalConnectionHandlingMode.interpret( effectiveAcquisitionMode, effectiveReleaseMode );
761800
}
762801

763802
@Override

0 commit comments

Comments
 (0)