diff --git a/hibernate-core/src/main/java/org/hibernate/internal/FastSessionServices.java b/hibernate-core/src/main/java/org/hibernate/internal/FastSessionServices.java index e1688c3293..0557705813 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/FastSessionServices.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/FastSessionServices.java @@ -125,7 +125,7 @@ final class FastSessionServices { private final Dialect dialect; private final CacheStoreMode defaultCacheStoreMode; private final CacheRetrieveMode defaultCacheRetrieveMode; - private List defaultJdbcObservers; + private final ConnectionObserverStatsBridge defaultJdbcObservers; FastSessionServices(SessionFactoryImpl sf) { Objects.requireNonNull( sf ); @@ -174,7 +174,7 @@ final class FastSessionServices { this.defaultCacheRetrieveMode = determineCacheRetrieveMode( defaultSessionProperties ); this.initialSessionCacheMode = CacheModeHelper.interpretCacheMode( defaultCacheStoreMode, defaultCacheRetrieveMode ); this.discardOnClose = sessionFactoryOptions.isReleaseResourcesOnCloseEnabled(); - this.defaultJdbcObservers = Collections.singletonList( new ConnectionObserverStatsBridge( sf ) ); + this.defaultJdbcObservers = new ConnectionObserverStatsBridge( sf ); this.defaultSessionEventListeners = sessionFactoryOptions.getBaselineSessionEventsListenerBuilder(); this.defaultLockOptions = initializeDefaultLockOptions( defaultSessionProperties ); } @@ -273,7 +273,7 @@ final class FastSessionServices { return ( CacheStoreMode ) settings.get( JPA_SHARED_CACHE_STORE_MODE ); } - public Iterable getDefaultJdbcObservers() { + public ConnectionObserverStatsBridge getDefaultJdbcObserver() { return defaultJdbcObservers; } diff --git a/hibernate-core/src/main/java/org/hibernate/internal/JdbcObserverImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/JdbcObserverImpl.java index be3cf12978..01f2eb71b4 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/JdbcObserverImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/JdbcObserverImpl.java @@ -8,7 +8,6 @@ package org.hibernate.internal; import java.sql.Connection; -import org.hibernate.engine.jdbc.spi.ConnectionObserver; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.resource.jdbc.spi.JdbcObserver; @@ -18,11 +17,11 @@ import org.hibernate.resource.jdbc.spi.JdbcObserver; public class JdbcObserverImpl implements JdbcObserver { private final SharedSessionContractImplementor session; - private final Iterable observers; + private final ConnectionObserverStatsBridge observer; public JdbcObserverImpl(SharedSessionContractImplementor session, FastSessionServices fastSessionServices) { this.session = session; - this.observers = fastSessionServices.getDefaultJdbcObservers(); + this.observer = fastSessionServices.getDefaultJdbcObserver(); } @Override @@ -32,9 +31,7 @@ public class JdbcObserverImpl implements JdbcObserver { @Override public void jdbcConnectionAcquisitionEnd(Connection connection) { - for ( ConnectionObserver observer : observers ) { - observer.physicalConnectionObtained( connection ); - } + observer.physicalConnectionObtained( connection ); } @Override @@ -44,9 +41,7 @@ public class JdbcObserverImpl implements JdbcObserver { @Override public void jdbcConnectionReleaseEnd() { - for ( ConnectionObserver observer : observers ) { - observer.physicalConnectionReleased(); - } + observer.physicalConnectionReleased(); } @Override @@ -56,9 +51,7 @@ public class JdbcObserverImpl implements JdbcObserver { @Override public void jdbcPrepareStatementEnd() { - for ( ConnectionObserver observer : observers ) { - observer.statementPrepared(); - } + observer.statementPrepared(); session.getEventListenerManager().jdbcPrepareStatementEnd(); } diff --git a/hibernate-core/src/main/java/org/hibernate/resource/jdbc/spi/JdbcObserver.java b/hibernate-core/src/main/java/org/hibernate/resource/jdbc/spi/JdbcObserver.java index 49aa95db79..124d28921d 100644 --- a/hibernate-core/src/main/java/org/hibernate/resource/jdbc/spi/JdbcObserver.java +++ b/hibernate-core/src/main/java/org/hibernate/resource/jdbc/spi/JdbcObserver.java @@ -9,8 +9,11 @@ package org.hibernate.resource.jdbc.spi; import java.sql.Connection; /** + * @deprecated It is no longer possible to plug custom implementations of + * this SPI. It will be removed. * @author Steve Ebersole */ +@Deprecated public interface JdbcObserver { public void jdbcConnectionAcquisitionStart(); public void jdbcConnectionAcquisitionEnd(Connection connection);