diff --git a/hibernate-agroal/src/main/java/org/hibernate/agroal/internal/AgroalConnectionProvider.java b/hibernate-agroal/src/main/java/org/hibernate/agroal/internal/AgroalConnectionProvider.java index 330ebdcd24ae..ddbc596fdd0b 100644 --- a/hibernate-agroal/src/main/java/org/hibernate/agroal/internal/AgroalConnectionProvider.java +++ b/hibernate-agroal/src/main/java/org/hibernate/agroal/internal/AgroalConnectionProvider.java @@ -23,7 +23,6 @@ import org.hibernate.engine.jdbc.connections.spi.ConnectionProviderConfigurationException; import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo; import org.hibernate.exception.JDBCConnectionException; -import org.hibernate.internal.log.ConnectionInfoLogger; import org.hibernate.service.UnknownUnwrapTypeException; import org.hibernate.service.spi.Configurable; import org.hibernate.service.spi.Stoppable; @@ -45,6 +44,7 @@ import static org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl.getSchema; import static org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl.hasCatalog; import static org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl.hasSchema; +import static org.hibernate.internal.log.ConnectionInfoLogger.CONNECTION_INFO_LOGGER; /** * {@link ConnectionProvider} based on Agroal connection pool. @@ -105,7 +105,7 @@ private static void copyProperty(Map properties, String key, @Override public void configure(Map properties) throws HibernateException { - ConnectionInfoLogger.INSTANCE.configureConnectionPool( "Agroal" ); + CONNECTION_INFO_LOGGER.configureConnectionPool( "Agroal" ); try { final var config = toStringValuedProperties( properties ); if ( !properties.containsKey( AgroalSettings.AGROAL_MAX_SIZE ) ) { @@ -130,7 +130,7 @@ public void configure(Map properties) throws HibernateException agroalDataSource = AgroalDataSource.from( agroalProperties ); } catch ( Exception e ) { - ConnectionInfoLogger.INSTANCE.unableToInstantiateConnectionPool( e ); + CONNECTION_INFO_LOGGER.unableToInstantiateConnectionPool( e ); throw new ConnectionProviderConfigurationException( "Could not configure Agroal: " + e.getMessage(), e ); } @@ -225,7 +225,7 @@ else if ( unwrapType.isAssignableFrom( AgroalDataSource.class ) ) { @Override public void stop() { if ( agroalDataSource != null ) { - ConnectionInfoLogger.INSTANCE.cleaningUpConnectionPool( + CONNECTION_INFO_LOGGER.cleaningUpConnectionPool( agroalDataSource.getConfiguration() .connectionPoolConfiguration() .connectionFactoryConfiguration() diff --git a/hibernate-c3p0/src/main/java/org/hibernate/c3p0/internal/C3P0ConnectionProvider.java b/hibernate-c3p0/src/main/java/org/hibernate/c3p0/internal/C3P0ConnectionProvider.java index 232f2e8297f3..6d85d2adc478 100644 --- a/hibernate-c3p0/src/main/java/org/hibernate/c3p0/internal/C3P0ConnectionProvider.java +++ b/hibernate-c3p0/src/main/java/org/hibernate/c3p0/internal/C3P0ConnectionProvider.java @@ -14,7 +14,6 @@ import org.hibernate.engine.jdbc.connections.spi.ConnectionProviderConfigurationException; import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo; import org.hibernate.exception.JDBCConnectionException; -import org.hibernate.internal.log.ConnectionInfoLogger; import org.hibernate.service.UnknownUnwrapTypeException; import org.hibernate.service.spi.Configurable; import org.hibernate.service.spi.ServiceRegistryAwareService; @@ -51,6 +50,7 @@ import static org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl.getSchema; import static org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl.hasCatalog; import static org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl.hasSchema; +import static org.hibernate.internal.log.ConnectionInfoLogger.CONNECTION_INFO_LOGGER; import static org.hibernate.internal.util.config.ConfigurationHelper.getBoolean; import static org.hibernate.internal.util.config.ConfigurationHelper.getInteger; @@ -135,7 +135,7 @@ else if ( unwrapType.isAssignableFrom( DataSource.class ) ) { @Override public void configure(Map properties) { - ConnectionInfoLogger.INSTANCE.configureConnectionPool( "c3p0" ); + CONNECTION_INFO_LOGGER.configureConnectionPool( "c3p0" ); final String jdbcDriverClass = extractSetting( properties, @@ -205,7 +205,7 @@ private DataSource createDataSource(String jdbcUrl, Properties connectionProps, return pooledDataSource( unpooledDataSource( jdbcUrl, connectionProps ), poolProperties ); } catch (Exception e) { - ConnectionInfoLogger.INSTANCE.unableToInstantiateConnectionPool( e ); + CONNECTION_INFO_LOGGER.unableToInstantiateConnectionPool( e ); throw new ConnectionProviderConfigurationException( "Could not configure c3p0: " + e.getMessage(), e ); } @@ -213,7 +213,7 @@ private DataSource createDataSource(String jdbcUrl, Properties connectionProps, private void loadDriverClass(String jdbcDriverClass) { if ( jdbcDriverClass == null ) { - ConnectionInfoLogger.INSTANCE.jdbcDriverNotSpecified(); + CONNECTION_INFO_LOGGER.jdbcDriverNotSpecified(); } else { try { @@ -313,12 +313,12 @@ private void warnPropertyConflict(String hibernateStyle, String c3p0Style) { @Override public void stop() { - ConnectionInfoLogger.INSTANCE.cleaningUpConnectionPool( C3P0_CONFIG_PREFIX ); + CONNECTION_INFO_LOGGER.cleaningUpConnectionPool( C3P0_CONFIG_PREFIX ); try { DataSources.destroy( dataSource ); } catch (SQLException sqle) { - ConnectionInfoLogger.INSTANCE.unableToDestroyConnectionPool( sqle ); + CONNECTION_INFO_LOGGER.unableToDestroyConnectionPool( sqle ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/internal/ScannerLogger.java b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/internal/ScannerLogger.java index 929459ccdb07..3cac3e83bf6a 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/internal/ScannerLogger.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/archive/scan/internal/ScannerLogger.java @@ -37,7 +37,7 @@ public interface ScannerLogger extends BasicLogger { void multipleScannerFactoriesAvailable(String scannerClassName); @LogMessage(level = Logger.Level.DEBUG) - @Message(id = 60002, value = "No ScannerFactory available; to enable scanning add 'hibernate-scan-jandex' dependency or supply a custom ScannerFactory") + @Message(id = 60002, value = "No ScannerFactory available (to enable scanning add 'hibernate-scan-jandex' dependency or supply a custom ScannerFactory)") void noScannerFactoryAvailable(); @LogMessage(level = Logger.Level.DEBUG) diff --git a/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/spi/StrategySelector.java b/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/spi/StrategySelector.java index 604bec381292..68b00e0a80c6 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/spi/StrategySelector.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/registry/selector/spi/StrategySelector.java @@ -19,8 +19,8 @@ * The strategy is any interface that has multiple, (possibly short) named implementations. *

* {@code StrategySelector} manages resolution of particular implementation by (possibly short) name via the - * {@link #selectStrategyImplementor} method, which is the main contract here. As indicated in the docs of that - * method the given name might be either a short registered name or the implementation FQN. As an example, consider + * {@link #selectStrategyImplementor} method, which is the main contract here. As indicated in the Javadoc of that + * method, the given name might be either a short registered name or the implementation FQN. As an example, consider * resolving the {@link org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder} implementation to use. * To use the JDBC-based {@code TransactionCoordinatorBuilder} the passed name might be either {@code "jdbc"} or * {@code "org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl"}. @@ -30,7 +30,7 @@ *

* The service also exposes a general typing API via {@link #resolveStrategy} and {@link #resolveDefaultableStrategy} * which accept implementation references rather than implementation names, allowing for a multitude of interpretations - * of said "implementation reference". See the docs for {@link #resolveDefaultableStrategy} for details. + * of said "implementation reference". See the docs for {@link #resolveDefaultableStrategy} for details. * * @author Steve Ebersole */ @@ -121,9 +121,9 @@ public interface StrategySelector extends Service, Stoppable { T resolveStrategy(Class strategy, Object strategyReference, T defaultValue, StrategyCreator creator); /** - * Retrieve all of the registered implementors of the given strategy. Useful - * to allow defaulting the choice to the single registered implementor when - * only one is registered + * Retrieve all the registered implementors of the given strategy. + * Useful to allow defaulting the choice to the single registered + * implementor when only one is registered * * @return The implementors. Should never return {@code null} */ @@ -144,8 +144,9 @@ public interface StrategySelector extends Service, Stoppable { void registerStrategyImplementor(Class strategy, String name, Class implementation); /** - * Un-registers a named implementor of a particular strategy contract. Un-registers all named registrations - * for the given strategy contract naming the given class. + * Unregisters a named implementor of a particular strategy contract. + * Unregisters all named registrations for the given strategy contract + * naming the given class. * * @param strategy The strategy contract. * @param implementation The implementation class diff --git a/hibernate-core/src/main/java/org/hibernate/cache/internal/RegionFactoryInitiator.java b/hibernate-core/src/main/java/org/hibernate/cache/internal/RegionFactoryInitiator.java index e0199ee78f8a..e0398a339a74 100644 --- a/hibernate-core/src/main/java/org/hibernate/cache/internal/RegionFactoryInitiator.java +++ b/hibernate-core/src/main/java/org/hibernate/cache/internal/RegionFactoryInitiator.java @@ -82,7 +82,7 @@ protected RegionFactory resolveRegionFactory(Map configurationVal final var implementors = selector.getRegisteredStrategyImplementors( RegionFactory.class ); if ( setting == null && implementors.size() != 1 ) { - // if either is explicitly defined as TRUE we need a RegionFactory + // if either is explicitly defined as TRUE, we need a RegionFactory if ( useSecondLevelCache == TRUE || useQueryCache == TRUE ) { throw new CacheException( "Caching was explicitly requested, but no RegionFactory was defined and there is not a single registered RegionFactory" ); } @@ -104,17 +104,21 @@ protected RegionFactory resolveRegionFactory(Map configurationVal return fallback; } - if ( implementors.size() == 1 ) { - final var registeredFactory = selector.resolveStrategy( RegionFactory.class, implementors.iterator().next() ); - configurationValues.put( CACHE_REGION_FACTORY, registeredFactory ); - configurationValues.put( USE_SECOND_LEVEL_CACHE, "true" ); - return registeredFactory; - } - else { - L2CACHE_LOGGER.cannotDefaultRegionFactory( implementors.size() ); + switch ( implementors.size() ) { + case 1: + final var registeredFactory = + selector.resolveStrategy( RegionFactory.class, + implementors.iterator().next() ); + configurationValues.put( CACHE_REGION_FACTORY, registeredFactory ); + configurationValues.put( USE_SECOND_LEVEL_CACHE, "true" ); + return registeredFactory; + case 0: + L2CACHE_LOGGER.noDefaultRegionFactory(); + return NoCachingRegionFactory.INSTANCE; + default: + L2CACHE_LOGGER.cannotDefaultRegionFactory( implementors.size() ); + return NoCachingRegionFactory.INSTANCE; } - - return NoCachingRegionFactory.INSTANCE; } protected RegionFactory getFallback(Map configurationValues, ServiceRegistryImplementor registry) { diff --git a/hibernate-core/src/main/java/org/hibernate/cache/spi/SecondLevelCacheLogger.java b/hibernate-core/src/main/java/org/hibernate/cache/spi/SecondLevelCacheLogger.java index 4a39dbe4fa5b..748665c2fa86 100644 --- a/hibernate-core/src/main/java/org/hibernate/cache/spi/SecondLevelCacheLogger.java +++ b/hibernate-core/src/main/java/org/hibernate/cache/spi/SecondLevelCacheLogger.java @@ -16,6 +16,7 @@ import java.lang.invoke.MethodHandles; +import static org.hibernate.cfg.CacheSettings.CACHE_REGION_FACTORY; import static org.jboss.logging.Logger.Level.DEBUG; import static org.jboss.logging.Logger.Level.INFO; import static org.jboss.logging.Logger.Level.TRACE; @@ -237,10 +238,18 @@ public interface SecondLevelCacheLogger extends BasicLogger { ) void noRegionFactory(); - @LogMessage(level = INFO) + @LogMessage(level = DEBUG) @Message( - value = "Cannot default RegionFactory based on registered strategies as %s RegionFactory strategies were registered", + value = "Cannot default RegionFactory based on registered strategies as %s RegionFactory strategies were registered" + + " (explicitly set '" + CACHE_REGION_FACTORY + "')", id = NAMESPACE + 30 ) void cannotDefaultRegionFactory(int size); + + @LogMessage(level = DEBUG) + @Message( + value = "Cannot default RegionFactory since no RegionFactory strategies were registered", + id = NAMESPACE + 31 + ) + void noDefaultRegionFactory(); } diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/Environment.java b/hibernate-core/src/main/java/org/hibernate/cfg/Environment.java index 0560029277be..8c763b3d7979 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/Environment.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/Environment.java @@ -5,16 +5,13 @@ package org.hibernate.cfg; import java.io.IOException; -import java.lang.invoke.MethodHandles; import java.util.Properties; import org.hibernate.HibernateException; import org.hibernate.Internal; import org.hibernate.Version; -import org.hibernate.internal.CoreMessageLogger; - -import org.jboss.logging.Logger; +import static org.hibernate.internal.CoreMessageLogger.CORE_LOGGER; import static org.hibernate.internal.util.ConfigHelper.getResourceAsStream; import static org.hibernate.internal.util.config.ConfigurationHelper.maskOut; @@ -132,8 +129,6 @@ @Internal public final class Environment implements AvailableSettings { - private static final CoreMessageLogger LOG = Logger.getMessageLogger( MethodHandles.lookup(), CoreMessageLogger.class, Environment.class.getName()); - private static final Properties GLOBAL_PROPERTIES; static { @@ -145,19 +140,19 @@ public final class Environment implements AvailableSettings { try (var stream = getResourceAsStream("/hibernate.properties")) { try { GLOBAL_PROPERTIES.load(stream); - LOG.propertiesLoaded( maskOut( GLOBAL_PROPERTIES, + CORE_LOGGER.propertiesLoaded( maskOut( GLOBAL_PROPERTIES, PASS, JAKARTA_JDBC_PASSWORD, JPA_JDBC_PASSWORD ) ); } catch (Exception e) { - LOG.unableToLoadProperties(); + CORE_LOGGER.unableToLoadProperties(); } } catch (IOException ioe) { - LOG.unableToCloseStreamError( ioe ); + CORE_LOGGER.unableToCloseStreamError( ioe ); } } catch (HibernateException he) { - LOG.propertiesNotFound(); + CORE_LOGGER.propertiesNotFound(); } try { @@ -170,7 +165,7 @@ public final class Environment implements AvailableSettings { } } catch (SecurityException se) { - LOG.unableToCopySystemProperties(); + CORE_LOGGER.unableToCopySystemProperties(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DataSourceConnectionProvider.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DataSourceConnectionProvider.java index f9f27ad5e9ef..5fb8e27e552e 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DataSourceConnectionProvider.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DataSourceConnectionProvider.java @@ -17,7 +17,6 @@ import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo; import org.hibernate.engine.jdbc.env.spi.ExtractedDatabaseMetaData; import org.hibernate.engine.jndi.spi.JndiService; -import org.hibernate.internal.log.ConnectionInfoLogger; import org.hibernate.service.UnknownUnwrapTypeException; import org.hibernate.service.spi.Configurable; import org.hibernate.service.spi.InjectService; @@ -25,6 +24,7 @@ import static org.hibernate.cfg.JdbcSettings.DATASOURCE; import static org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.toIsolationNiceName; +import static org.hibernate.internal.log.ConnectionInfoLogger.CONNECTION_INFO_LOGGER; /** * A {@link ConnectionProvider} that manages connections from an underlying {@link DataSource}. @@ -110,11 +110,11 @@ else if ( dataSourceSetting instanceof String jndiName ) { } if ( configuration.containsKey( JdbcSettings.AUTOCOMMIT ) ) { - ConnectionInfoLogger.INSTANCE.ignoredSetting( JdbcSettings.AUTOCOMMIT, + CONNECTION_INFO_LOGGER.ignoredSetting( JdbcSettings.AUTOCOMMIT, DataSourceConnectionProvider.class ); } if ( configuration.containsKey( JdbcSettings.ISOLATION ) ) { - ConnectionInfoLogger.INSTANCE.ignoredSetting( JdbcSettings.ISOLATION, + CONNECTION_INFO_LOGGER.ignoredSetting( JdbcSettings.ISOLATION, DataSourceConnectionProvider.class ); } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DriverManagerConnectionProvider.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DriverManagerConnectionProvider.java index 168e78865dae..3013dd5054d0 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DriverManagerConnectionProvider.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DriverManagerConnectionProvider.java @@ -26,7 +26,6 @@ import org.hibernate.service.spi.ServiceRegistryAwareService; import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.service.spi.Stoppable; -import org.hibernate.internal.log.ConnectionInfoLogger; import static org.hibernate.cfg.JdbcSettings.AUTOCOMMIT; import static org.hibernate.cfg.JdbcSettings.DRIVER; @@ -43,6 +42,7 @@ import static org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl.getSchema; import static org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl.hasCatalog; import static org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl.hasSchema; +import static org.hibernate.internal.log.ConnectionInfoLogger.CONNECTION_INFO_LOGGER; import static org.hibernate.internal.util.config.ConfigurationHelper.getBoolean; import static org.hibernate.internal.util.config.ConfigurationHelper.getInt; import static org.hibernate.internal.util.config.ConfigurationHelper.getLong; @@ -82,7 +82,7 @@ public void injectServices(ServiceRegistryImplementor serviceRegistry) { @Override public void configure(Map configurationValues) { - ConnectionInfoLogger.INSTANCE.usingHibernateBuiltInConnectionPool(); + CONNECTION_INFO_LOGGER.usingHibernateBuiltInConnectionPool(); final PooledConnections pool = buildPool( configurationValues, serviceRegistry ); final long validationInterval = getLong( VALIDATION_INTERVAL, configurationValues, 30 ); state = new PoolState( pool, validationInterval ); @@ -181,7 +181,7 @@ private static Driver loadDriver(String driverClassName, ServiceRegistry service } private static void logAvailableDrivers() { - ConnectionInfoLogger.INSTANCE.jdbcDriverNotSpecified(); + CONNECTION_INFO_LOGGER.jdbcDriverNotSpecified(); final var list = new StringBuilder(); DriverManager.drivers() .forEach( driver -> { @@ -190,7 +190,7 @@ private static void logAvailableDrivers() { } list.append( driver.getClass().getName() ); } ); - ConnectionInfoLogger.INSTANCE.availableJdbcDrivers( list.toString() ); + CONNECTION_INFO_LOGGER.availableJdbcDrivers( list.toString() ); } private static String jdbcUrl(Map configuration) { @@ -219,7 +219,7 @@ else if ( connectionCreatorFactory != null ) { private static Driver loadDriverIfPossible(String driverClassName, ServiceRegistry serviceRegistry) { if ( driverClassName == null ) { - ConnectionInfoLogger.INSTANCE.debug( "No driver class specified" ); + CONNECTION_INFO_LOGGER.noDriverClassSpecified(); return null; } else if ( serviceRegistry != null ) { @@ -246,7 +246,7 @@ else if ( serviceRegistry != null ) { private static ConnectionCreatorFactory loadConnectionCreatorFactory( String connectionCreatorFactoryClassName, ServiceRegistry serviceRegistry) { if ( connectionCreatorFactoryClassName == null ) { - ConnectionInfoLogger.INSTANCE.debug( "No connection creator factory class specified" ); + CONNECTION_INFO_LOGGER.noConnectionCreatorFactoryClassSpecified(); return null; } else if ( serviceRegistry != null ) { @@ -339,7 +339,7 @@ protected int getOpenConnections() { protected void validateConnectionsReturned() { final int allocationCount = getOpenConnections(); if ( allocationCount != 0 ) { - ConnectionInfoLogger.INSTANCE.error( "Connection leak detected: there are " + allocationCount + " unclosed connections"); + CONNECTION_INFO_LOGGER.connectionLeakDetected( allocationCount ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/PoolState.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/PoolState.java index a6cb71ab5f25..3d15206445b6 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/PoolState.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/PoolState.java @@ -4,7 +4,6 @@ */ package org.hibernate.engine.jdbc.connections.internal; -import org.hibernate.internal.log.ConnectionInfoLogger; import java.sql.Connection; import java.sql.SQLException; @@ -14,6 +13,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor; +import static org.hibernate.internal.log.ConnectionInfoLogger.CONNECTION_INFO_LOGGER; class PoolState implements Runnable { @@ -76,7 +76,7 @@ void stop() { if ( !active ) { return; } - ConnectionInfoLogger.INSTANCE.cleaningUpConnectionPool( pool.getUrl() ); + CONNECTION_INFO_LOGGER.cleaningUpConnectionPool( pool.getUrl() ); active = false; if ( executorService != null ) { executorService.shutdown(); @@ -86,7 +86,7 @@ void stop() { pool.close(); } catch (SQLException e) { - ConnectionInfoLogger.INSTANCE.unableToDestroyConnectionPool( e ); + CONNECTION_INFO_LOGGER.unableToDestroyConnectionPool( e ); } } finally { diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/PooledConnections.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/PooledConnections.java index a9bd9e70e24f..b4309bdf3fe7 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/PooledConnections.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/PooledConnections.java @@ -5,12 +5,13 @@ package org.hibernate.engine.jdbc.connections.internal; import org.hibernate.HibernateException; -import org.hibernate.internal.log.ConnectionInfoLogger; import java.sql.Connection; import java.sql.SQLException; import java.util.concurrent.ConcurrentLinkedQueue; +import static org.hibernate.internal.log.ConnectionInfoLogger.CONNECTION_INFO_LOGGER; + class PooledConnections { // Thanks to Oleg Varaksin and his article on object pooling using the {@link java.util.concurrent} @@ -30,7 +31,7 @@ class PooledConnections { private PooledConnections( Builder builder) { - ConnectionInfoLogger.INSTANCE.debugf( "Initializing Connection pool with %s Connections", builder.initialSize ); + CONNECTION_INFO_LOGGER.initializingConnectionPool( builder.initialSize ); connectionCreator = builder.connectionCreator; connectionValidator = builder.connectionValidator == null ? ConnectionValidator.ALWAYS_VALID @@ -47,18 +48,18 @@ void validate() { if ( !primed && size >= minSize ) { // IMPL NOTE: the purpose of primed is to allow the pool to lazily reach its // defined min-size. - ConnectionInfoLogger.INSTANCE.debug( "Connection pool now considered primed; min-size will be maintained" ); + CONNECTION_INFO_LOGGER.connectionPoolPrimed(); primed = true; } if ( size < minSize && primed ) { int numberToBeAdded = minSize - size; - ConnectionInfoLogger.INSTANCE.debugf( "Adding %s Connections to the pool", numberToBeAdded ); + CONNECTION_INFO_LOGGER.addingConnectionsToPool( numberToBeAdded ); addConnections( numberToBeAdded ); } else if ( size > maxSize ) { int numberToBeRemoved = size - maxSize; - ConnectionInfoLogger.INSTANCE.debugf( "Removing %s Connections from the pool", numberToBeRemoved ); + CONNECTION_INFO_LOGGER.removingConnectionsFromPool( numberToBeRemoved ); removeConnections( numberToBeRemoved ); } } @@ -83,7 +84,7 @@ private Connection releaseConnection(Connection conn) { t = ex; } closeConnection( conn, t ); - ConnectionInfoLogger.INSTANCE.debug( "Connection release failed. Closing pooled connection", t ); + CONNECTION_INFO_LOGGER.connectionReleaseFailedClosingPooledConnection( t ); return null; } @@ -119,7 +120,7 @@ protected Connection prepareConnection(Connection conn) { t = ex; } closeConnection( conn, t ); - ConnectionInfoLogger.INSTANCE.debug( "Connection preparation failed. Closing pooled connection", t ); + CONNECTION_INFO_LOGGER.connectionPreparationFailedClosingPooledConnection( t ); return null; } @@ -128,14 +129,14 @@ protected void closeConnection(Connection conn, Throwable t) { conn.close(); } catch (SQLException ex) { - ConnectionInfoLogger.INSTANCE.unableToClosePooledConnection( ex ); + CONNECTION_INFO_LOGGER.unableToClosePooledConnection( ex ); if ( t != null ) { t.addSuppressed( ex ); } } finally { if ( !allConnections.remove( conn ) ) { - ConnectionInfoLogger.INSTANCE.debug( "Connection remove failed." ); + CONNECTION_INFO_LOGGER.connectionRemoveFailed(); } } } @@ -144,7 +145,7 @@ public void close() throws SQLException { try { final int allocationCount = allConnections.size() - availableConnections.size(); if ( allocationCount > 0 ) { - ConnectionInfoLogger.INSTANCE.error( + CONNECTION_INFO_LOGGER.error( "Connection leak detected: there are " + allocationCount + " unclosed connections upon shutting down pool " + getUrl() ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/JdbcEnvironmentInitiator.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/JdbcEnvironmentInitiator.java index 52183ca7f473..efb7db8751ba 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/JdbcEnvironmentInitiator.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/JdbcEnvironmentInitiator.java @@ -31,7 +31,6 @@ import org.hibernate.engine.jdbc.spi.SqlExceptionHelper; import org.hibernate.event.monitor.internal.EmptyEventMonitor; import org.hibernate.event.monitor.spi.EventMonitor; -import org.hibernate.internal.log.ConnectionInfoLogger; import org.hibernate.jdbc.AbstractReturningWork; import org.hibernate.jpa.internal.MutableJpaComplianceImpl; import org.hibernate.jpa.spi.JpaCompliance; @@ -65,6 +64,7 @@ import static org.hibernate.cfg.JdbcSettings.JAKARTA_HBM2DDL_DB_VERSION; import static org.hibernate.engine.config.spi.StandardConverters.BOOLEAN; import static org.hibernate.context.spi.MultiTenancy.isMultiTenancyEnabled; +import static org.hibernate.internal.log.ConnectionInfoLogger.CONNECTION_INFO_LOGGER; import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER; import static org.hibernate.internal.util.NullnessHelper.coalesceSuppliedValues; import static org.hibernate.internal.util.StringHelper.isNotEmpty; @@ -173,7 +173,7 @@ else if ( explicitDialectConfiguration( explicitDatabaseName, configurationValue // For Hibernate Reactive: it needs to disable or customize the log protected void logConnectionInfo(DatabaseConnectionInfo databaseConnectionInfo) { // Standardized info logging - ConnectionInfoLogger.INSTANCE.logConnectionInfoDetails( databaseConnectionInfo.toInfoString() ); + CONNECTION_INFO_LOGGER.logConnectionInfoDetails( databaseConnectionInfo.toInfoString() ); } private DatabaseConnectionInfo buildInfo(ServiceRegistryImplementor registry, JdbcEnvironment environment) { diff --git a/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java b/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java index 261a907db62d..4c93c572d693 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java @@ -45,7 +45,7 @@ description = "Miscellaneous logging related to Hibernate ORM Core" ) @MessageLogger(projectCode = "HHH") -@ValidIdRange(min=2,max = 8000) +@ValidIdRange(max = 8000) @Internal public interface CoreMessageLogger extends BasicLogger { @@ -54,6 +54,10 @@ public interface CoreMessageLogger extends BasicLogger { Logger LOGGER = Logger.getLogger( NAME ); CoreMessageLogger CORE_LOGGER = Logger.getMessageLogger( MethodHandles.lookup(), CoreMessageLogger.class, NAME ); + @LogMessage(level = INFO) + @Message(value = "Hibernate ORM core version %s", id = 1) + void version(String versionString); + @LogMessage(level = WARN) @Message(value = "Composite id class does not override equals(): %s", id = 38) void compositeIdClassDoesNotOverrideEquals(String name); @@ -266,10 +270,6 @@ void missingArguments( @Message(value = "Don't use old DTDs, read the Hibernate 3.x Migration Guide", id = 404) void usingOldDtd(); - @LogMessage(level = INFO) - @Message(value = "Hibernate ORM core version %s", id = 412) - void version(String versionString); - @LogMessage(level = WARN) @Message(value = "Warnings creating temp table: %s", id = 413) void warningsCreatingTempTable(SQLWarning warning); diff --git a/hibernate-core/src/main/java/org/hibernate/internal/log/ConnectionInfoLogger.java b/hibernate-core/src/main/java/org/hibernate/internal/log/ConnectionInfoLogger.java index 394cc2ff3057..441dca267c0f 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/log/ConnectionInfoLogger.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/log/ConnectionInfoLogger.java @@ -20,6 +20,7 @@ import static org.jboss.logging.Logger.Level.DEBUG; import static org.jboss.logging.Logger.Level.INFO; import static org.jboss.logging.Logger.Level.WARN; +import static org.jboss.logging.Logger.Level.ERROR; /** * @author Steve Ebersole @@ -37,7 +38,7 @@ public interface ConnectionInfoLogger extends BasicLogger { /** * Static access to the logging instance */ - ConnectionInfoLogger INSTANCE = Logger.getMessageLogger( MethodHandles.lookup(), ConnectionInfoLogger.class, LOGGER_NAME ); + ConnectionInfoLogger CONNECTION_INFO_LOGGER = Logger.getMessageLogger( MethodHandles.lookup(), ConnectionInfoLogger.class, LOGGER_NAME ); @LogMessage(level = WARN) @Message(value = "Using built-in connection pool (not intended for production use)", id = 10001002) @@ -79,7 +80,47 @@ public interface ConnectionInfoLogger extends BasicLogger { @Message(value = "Configuring connection pool [%s]", id = 10001012) void configureConnectionPool(String type); - @LogMessage(level = INFO) +@LogMessage(level = INFO) @Message(value = "Ignoring setting '%s' for connection provider [%s]", id = 10001013) void ignoredSetting(String setting, Class provider); + + @LogMessage(level = DEBUG) + @Message(value = "Initializing connection pool with %s connections", id = 10001014) + void initializingConnectionPool(int size); + + @LogMessage(level = DEBUG) + @Message(value = "Connection pool now considered primed; min-size will be maintained", id = 10001015) + void connectionPoolPrimed(); + + @LogMessage(level = DEBUG) + @Message(value = "Adding %s connections to the pool", id = 10001016) + void addingConnectionsToPool(int numberToBeAdded); + + @LogMessage(level = DEBUG) + @Message(value = "Removing %s connections from the pool", id = 10001017) + void removingConnectionsFromPool(int numberToBeRemoved); + + @LogMessage(level = DEBUG) + @Message(value = "Connection release failed, closing pooled connection", id = 10001018) + void connectionReleaseFailedClosingPooledConnection(@Cause Throwable t); + + @LogMessage(level = DEBUG) + @Message(value = "Connection preparation failed, closing pooled connection", id = 10001019) + void connectionPreparationFailedClosingPooledConnection(@Cause Throwable t); + + @LogMessage(level = DEBUG) + @Message(value = "Connection remove failed", id = 10001020) + void connectionRemoveFailed(); + + @LogMessage(level = DEBUG) + @Message(value = "No driver class specified", id = 10001021) + void noDriverClassSpecified(); + + @LogMessage(level = DEBUG) + @Message(value = "No connection creator factory class specified", id = 10001022) + void noConnectionCreatorFactoryClassSpecified(); + + @LogMessage(level = ERROR) + @Message(value = "Connection leak detected: there are %s unclosed connections", id = 10001023) + void connectionLeakDetected(int allocationCount); } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/datasource/DataSourceTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/datasource/DataSourceTest.java index 56a7d11f0b49..260223642b4b 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/datasource/DataSourceTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/datasource/DataSourceTest.java @@ -33,9 +33,9 @@ public class DataSourceTest { @Test void test(EntityManagerFactoryScope scope) { Listener listener = new Listener(); - LogInspectionHelper.registerListener( listener, ConnectionInfoLogger.INSTANCE ); + LogInspectionHelper.registerListener( listener, ConnectionInfoLogger.CONNECTION_INFO_LOGGER ); scope.getEntityManagerFactory(); - LogInspectionHelper.clearAllListeners( ConnectionInfoLogger.INSTANCE ); + LogInspectionHelper.clearAllListeners( ConnectionInfoLogger.CONNECTION_INFO_LOGGER ); Dialect dialect = scope.getDialect(); assertTrue( dialect instanceof OracleDialect || dialect instanceof DB2Dialect diff --git a/hibernate-hikaricp/src/main/java/org/hibernate/hikaricp/internal/HikariCPConnectionProvider.java b/hibernate-hikaricp/src/main/java/org/hibernate/hikaricp/internal/HikariCPConnectionProvider.java index decf33c77a61..00f7b24468a1 100644 --- a/hibernate-hikaricp/src/main/java/org/hibernate/hikaricp/internal/HikariCPConnectionProvider.java +++ b/hibernate-hikaricp/src/main/java/org/hibernate/hikaricp/internal/HikariCPConnectionProvider.java @@ -16,7 +16,6 @@ import org.hibernate.engine.jdbc.connections.spi.ConnectionProviderConfigurationException; import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo; import org.hibernate.exception.JDBCConnectionException; -import org.hibernate.internal.log.ConnectionInfoLogger; import org.hibernate.service.UnknownUnwrapTypeException; import org.hibernate.service.spi.Configurable; import org.hibernate.service.spi.Stoppable; @@ -33,6 +32,7 @@ import static org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl.hasCatalog; import static org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl.hasSchema; import static org.hibernate.hikaricp.internal.HikariConfigurationUtil.loadConfiguration; +import static org.hibernate.internal.log.ConnectionInfoLogger.CONNECTION_INFO_LOGGER; import static org.hibernate.internal.util.StringHelper.isBlank; /** @@ -67,12 +67,12 @@ public class HikariCPConnectionProvider implements ConnectionProvider, Configura @Override public void configure(Map configuration) throws HibernateException { try { - ConnectionInfoLogger.INSTANCE.configureConnectionPool( "HikariCP" ); + CONNECTION_INFO_LOGGER.configureConnectionPool( "HikariCP" ); hikariConfig = loadConfiguration( configuration ); hikariDataSource = new HikariDataSource( hikariConfig ); } catch (Exception e) { - ConnectionInfoLogger.INSTANCE.unableToInstantiateConnectionPool( e ); + CONNECTION_INFO_LOGGER.unableToInstantiateConnectionPool( e ); throw new ConnectionProviderConfigurationException( "Could not configure HikariCP: " + e.getMessage(), e ); } @@ -168,7 +168,7 @@ else if ( unwrapType.isAssignableFrom( HikariConfig.class ) ) { @Override public void stop() { if ( hikariDataSource != null ) { - ConnectionInfoLogger.INSTANCE.cleaningUpConnectionPool( "HikariCP" ); + CONNECTION_INFO_LOGGER.cleaningUpConnectionPool( "HikariCP" ); hikariDataSource.close(); } }