|
13 | 13 | import java.util.List;
|
14 | 14 | import java.util.Map;
|
15 | 15 |
|
| 16 | +import org.hibernate.ConnectionAcquisitionMode; |
16 | 17 | import org.hibernate.ConnectionReleaseMode;
|
17 | 18 | import org.hibernate.CustomEntityDirtinessStrategy;
|
18 | 19 | import org.hibernate.EmptyInterceptor;
|
|
48 | 49 | import org.hibernate.internal.util.config.ConfigurationHelper;
|
49 | 50 | import org.hibernate.loader.BatchFetchStyle;
|
50 | 51 | import org.hibernate.proxy.EntityNotFoundDelegate;
|
| 52 | +import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode; |
51 | 53 | import org.hibernate.resource.jdbc.spi.StatementInspector;
|
52 | 54 | import org.hibernate.resource.transaction.TransactionCoordinatorBuilder;
|
53 | 55 | import org.hibernate.service.spi.ServiceRegistryImplementor;
|
54 | 56 | import org.hibernate.tuple.entity.EntityTuplizer;
|
55 | 57 | import org.hibernate.tuple.entity.EntityTuplizerFactory;
|
56 | 58 | import org.jboss.logging.Logger;
|
57 | 59 |
|
| 60 | +import static org.hibernate.cfg.AvailableSettings.ACQUIRE_CONNECTIONS; |
58 | 61 | import static org.hibernate.cfg.AvailableSettings.AUTO_CLOSE_SESSION;
|
59 | 62 | import static org.hibernate.cfg.AvailableSettings.AUTO_EVICT_COLLECTION_CACHE;
|
60 | 63 | import static org.hibernate.cfg.AvailableSettings.AUTO_SESSION_EVENTS_LISTENER;
|
@@ -411,9 +414,26 @@ public SessionFactoryBuilder applyJdbcFetchSize(int size) {
|
411 | 414 | return this;
|
412 | 415 | }
|
413 | 416 |
|
| 417 | + @Override |
| 418 | + public SessionFactoryBuilder applyConnectionHandlingMode(PhysicalConnectionHandlingMode connectionHandlingMode) { |
| 419 | + this.options.connectionHandlingMode = connectionHandlingMode; |
| 420 | + return this; |
| 421 | + } |
| 422 | + |
414 | 423 | @Override
|
415 | 424 | public SessionFactoryBuilder applyConnectionReleaseMode(ConnectionReleaseMode connectionReleaseMode) {
|
416 |
| - this.options.connectionReleaseMode = connectionReleaseMode; |
| 425 | + if ( this.options.connectionHandlingMode == null ) { |
| 426 | + this.options.connectionHandlingMode = PhysicalConnectionHandlingMode.interpret( |
| 427 | + ConnectionAcquisitionMode.AS_NEEDED, |
| 428 | + connectionReleaseMode |
| 429 | + ); |
| 430 | + } |
| 431 | + else { |
| 432 | + this.options.connectionHandlingMode = PhysicalConnectionHandlingMode.interpret( |
| 433 | + this.options.connectionHandlingMode.getAcquisitionMode(), |
| 434 | + connectionReleaseMode |
| 435 | + ); |
| 436 | + } |
417 | 437 | return this;
|
418 | 438 | }
|
419 | 439 |
|
@@ -526,7 +546,7 @@ public static class SessionFactoryOptionsStateStandardImpl implements SessionFac
|
526 | 546 | private Integer jdbcFetchSize;
|
527 | 547 | private boolean scrollableResultSetsEnabled;
|
528 | 548 | private boolean commentsEnabled;
|
529 |
| - private ConnectionReleaseMode connectionReleaseMode; |
| 549 | + private PhysicalConnectionHandlingMode connectionHandlingMode; |
530 | 550 | private boolean wrapResultSetsEnabled;
|
531 | 551 |
|
532 | 552 | private Map<String, SQLFunction> sqlFunctions;
|
@@ -684,14 +704,30 @@ public SessionFactoryOptionsStateStandardImpl(StandardServiceRegistry serviceReg
|
684 | 704 | );
|
685 | 705 | this.jdbcFetchSize = ConfigurationHelper.getInteger( STATEMENT_FETCH_SIZE, configurationSettings );
|
686 | 706 |
|
| 707 | + final ConnectionAcquisitionMode connectionAcquisitionMode = ConnectionAcquisitionMode.interpret( |
| 708 | + ConfigurationHelper.getString( |
| 709 | + ACQUIRE_CONNECTIONS, |
| 710 | + configurationSettings, |
| 711 | + ConnectionAcquisitionMode.AS_NEEDED.name() |
| 712 | + ) |
| 713 | + ); |
| 714 | + |
| 715 | + final ConnectionReleaseMode connectionReleaseMode; |
687 | 716 | final String releaseModeName = ConfigurationHelper.getString( RELEASE_CONNECTIONS, configurationSettings, "auto" );
|
688 | 717 | if ( "auto".equals( releaseModeName ) ) {
|
689 |
| - this.connectionReleaseMode = serviceRegistry.getService( TransactionCoordinatorBuilder.class ) |
690 |
| - .getDefaultConnectionReleaseMode(); |
| 718 | + // nothing was specified (or someone happened to configure the "magic" value) |
| 719 | + if ( connectionAcquisitionMode == ConnectionAcquisitionMode.IMMEDIATELY ) { |
| 720 | + connectionReleaseMode = ConnectionReleaseMode.ON_CLOSE; |
| 721 | + } |
| 722 | + else { |
| 723 | + connectionReleaseMode = serviceRegistry.getService( TransactionCoordinatorBuilder.class ) |
| 724 | + .getDefaultConnectionReleaseMode(); |
| 725 | + } |
691 | 726 | }
|
692 | 727 | else {
|
693 | 728 | connectionReleaseMode = ConnectionReleaseMode.parse( releaseModeName );
|
694 | 729 | }
|
| 730 | + this.connectionHandlingMode = PhysicalConnectionHandlingMode.interpret( connectionAcquisitionMode, connectionReleaseMode ); |
695 | 731 |
|
696 | 732 | this.commentsEnabled = ConfigurationHelper.getBoolean( USE_SQL_COMMENTS, configurationSettings );
|
697 | 733 |
|
@@ -928,9 +964,14 @@ public Integer getJdbcFetchSize() {
|
928 | 964 | return jdbcFetchSize;
|
929 | 965 | }
|
930 | 966 |
|
| 967 | + @Override |
| 968 | + public PhysicalConnectionHandlingMode getPhysicalConnectionHandlingMode() { |
| 969 | + return connectionHandlingMode; |
| 970 | + } |
| 971 | + |
931 | 972 | @Override
|
932 | 973 | public ConnectionReleaseMode getConnectionReleaseMode() {
|
933 |
| - return connectionReleaseMode; |
| 974 | + return getPhysicalConnectionHandlingMode().getReleaseMode(); |
934 | 975 | }
|
935 | 976 |
|
936 | 977 | @Override
|
@@ -1194,9 +1235,14 @@ public Integer getJdbcFetchSize() {
|
1194 | 1235 | return options.getJdbcFetchSize();
|
1195 | 1236 | }
|
1196 | 1237 |
|
| 1238 | + @Override |
| 1239 | + public PhysicalConnectionHandlingMode getPhysicalConnectionHandlingMode() { |
| 1240 | + return options.getPhysicalConnectionHandlingMode(); |
| 1241 | + } |
| 1242 | + |
1197 | 1243 | @Override
|
1198 | 1244 | public ConnectionReleaseMode getConnectionReleaseMode() {
|
1199 |
| - return options.getConnectionReleaseMode(); |
| 1245 | + return getPhysicalConnectionHandlingMode().getReleaseMode(); |
1200 | 1246 | }
|
1201 | 1247 |
|
1202 | 1248 | @Override
|
|
0 commit comments