From 55108d0740d3d46502659ed8098b02fede4abbe5 Mon Sep 17 00:00:00 2001 From: Jan Schatteman Date: Thu, 4 Jul 2024 22:55:40 +0200 Subject: [PATCH] HHH-18224 - db info logging cleanup Signed-off-by: Jan Schatteman --- design/logger_id_ranges.adoc | 8 +- .../internal/AgroalConnectionProvider.java | 10 +-- .../c3p0/internal/C3P0ConnectionProvider.java | 19 +++-- .../c3p0/internal/C3P0MessageLogger.java | 38 +--------- .../internal/DatabaseConnectionInfoImpl.java | 11 ++- .../DriverManagerConnectionProviderImpl.java | 52 +++++-------- .../spi/DatabaseConnectionInfo.java | 2 +- .../internal/JdbcEnvironmentInitiator.java | 6 +- ...gLogger.java => ConnectionInfoLogger.java} | 41 +++++----- .../log/ConnectionProviderLogger.java | 44 ----------- .../internal/HikariCPConnectionProvider.java | 11 +-- .../internal/ProxoolConnectionProvider.java | 25 +++---- .../internal/ProxoolMessageLogger.java | 74 ++----------------- .../internal/UCPConnectionProvider.java | 16 ++-- .../internal/ViburDBCPConnectionProvider.java | 8 +- 15 files changed, 108 insertions(+), 257 deletions(-) rename hibernate-core/src/main/java/org/hibernate/internal/log/{ConnectionPoolingLogger.java => ConnectionInfoLogger.java} (60%) delete mode 100644 hibernate-core/src/main/java/org/hibernate/internal/log/ConnectionProviderLogger.java diff --git a/design/logger_id_ranges.adoc b/design/logger_id_ranges.adoc index 58d8e1c3e2..6ef47008a7 100644 --- a/design/logger_id_ranges.adoc +++ b/design/logger_id_ranges.adoc @@ -73,8 +73,8 @@ public interface MappingModelCreationLogger extends BasicLogger { |[[connections-pooling]]org.hibernate.orm.connections.pooling -|<> -|Logging related to connection pooling +|<> +|Logging related to connections and connection pooling |org.hibernate.orm.boot |n/a @@ -93,9 +93,9 @@ public interface MappingModelCreationLogger extends BasicLogger { |Sub-system (?) -|[[ConnectionPoolingLogger]]10001001 +|[[ConnectionInfoLogger]]10001001 |10001500 -|org.hibernate.internal.log.ConnectionPoolingLogger +|org.hibernate.internal.log.ConnectionInfoLogger | <> |1 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 e0da779265..8a591b76d5 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 @@ -21,6 +21,7 @@ import org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiato import org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl; import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo; +import org.hibernate.internal.log.ConnectionInfoLogger; import org.hibernate.service.UnknownUnwrapTypeException; import org.hibernate.service.spi.Configurable; import org.hibernate.service.spi.Stoppable; @@ -32,8 +33,6 @@ import java.util.Map; import java.util.function.Consumer; import java.util.function.Function; -import org.jboss.logging.Logger; - import static org.hibernate.cfg.AgroalSettings.AGROAL_CONFIG_PREFIX; /** @@ -62,7 +61,6 @@ public class AgroalConnectionProvider implements ConnectionProvider, Configurabl public static final String CONFIG_PREFIX = AGROAL_CONFIG_PREFIX + "."; private static final long serialVersionUID = 1L; - private static final Logger LOGGER = Logger.getLogger( AgroalConnectionProvider.class ); private AgroalDataSource agroalDataSource = null; private DatabaseConnectionInfo dbInfo; @@ -93,7 +91,7 @@ public class AgroalConnectionProvider implements ConnectionProvider, Configurabl @Override public void configure(Map props) throws HibernateException { - LOGGER.debug( "Configuring Agroal" ); + ConnectionInfoLogger.INSTANCE.configureConnectionPool( "Agroal" ); try { AgroalPropertiesReader agroalProperties = new AgroalPropertiesReader( CONFIG_PREFIX ) .readProperties( (Map) props ); //TODO: this is a garbage cast @@ -122,9 +120,9 @@ public class AgroalConnectionProvider implements ConnectionProvider, Configurabl .setDBMaxPoolSize( String.valueOf(acpc.maxSize()) ); } catch ( Exception e ) { + ConnectionInfoLogger.INSTANCE.unableToInstantiateConnectionPool( e ); throw new HibernateException( e ); } - LOGGER.debug( "Agroal Configured" ); } // --- ConnectionProvider @@ -177,6 +175,8 @@ public class AgroalConnectionProvider implements ConnectionProvider, Configurabl @Override public void stop() { if ( agroalDataSource != null ) { + ConnectionInfoLogger.INSTANCE.cleaningUpConnectionPool( agroalDataSource.getConfiguration().connectionPoolConfiguration(). + connectionFactoryConfiguration().jdbcUrl() ); agroalDataSource.close(); } } 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 093965ea4e..e4e3007187 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 @@ -24,15 +24,14 @@ import org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiato import org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl; import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo; +import org.hibernate.internal.log.ConnectionInfoLogger; import org.hibernate.internal.util.PropertiesHelper; -import org.hibernate.internal.util.config.ConfigurationHelper; import org.hibernate.service.UnknownUnwrapTypeException; import org.hibernate.service.spi.Configurable; import org.hibernate.service.spi.ServiceRegistryAwareService; import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.service.spi.Stoppable; -import static org.hibernate.c3p0.internal.C3P0MessageLogger.C3P0_LOGGER; import static org.hibernate.c3p0.internal.C3P0MessageLogger.C3P0_MSG_LOGGER; import static org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.extractSetting; import static org.hibernate.internal.util.config.ConfigurationHelper.getBoolean; @@ -111,6 +110,8 @@ public class C3P0ConnectionProvider @Override public void configure(Map props) { + ConnectionInfoLogger.INSTANCE.configureConnectionPool( "C3p0" ); + final String jdbcDriverClass = extractSetting( props, JdbcSettings.JAKARTA_JDBC_DRIVER, @@ -126,19 +127,17 @@ public class C3P0ConnectionProvider final Properties connectionProps = ConnectionProviderInitiator.getConnectionProperties( props ); - C3P0_MSG_LOGGER.connectionProperties( ConfigurationHelper.maskOut( connectionProps, "password" ) ); - autocommit = getBoolean( JdbcSettings.AUTOCOMMIT, props ); if ( jdbcDriverClass == null ) { - C3P0_MSG_LOGGER.jdbcDriverNotSpecified(); + ConnectionInfoLogger.INSTANCE.jdbcDriverNotSpecified(); } else { try { serviceRegistry.requireService( ClassLoaderService.class ).classForName( jdbcDriverClass ); } catch (ClassLoadingException e) { - throw new ClassLoadingException( C3P0_MSG_LOGGER.jdbcDriverNotFound( jdbcDriverClass ), e ); + throw new ClassLoadingException( "JDBC Driver class " + jdbcDriverClass + " not found", e ); } } @@ -197,8 +196,8 @@ public class C3P0ConnectionProvider ds = DataSources.pooledDataSource( unpooled, allProps ); } catch (Exception e) { - C3P0_LOGGER.error( C3P0_MSG_LOGGER.unableToInstantiateC3p0ConnectionPool(), e );; - throw new HibernateException( C3P0_MSG_LOGGER.unableToInstantiateC3p0ConnectionPool(), e ); + ConnectionInfoLogger.INSTANCE.unableToInstantiateConnectionPool( e ); + throw new HibernateException( e ); } isolation = ConnectionProviderInitiator.extractIsolation( props ); @@ -247,12 +246,12 @@ public class C3P0ConnectionProvider @Override public void stop() { + ConnectionInfoLogger.INSTANCE.cleaningUpConnectionPool( C3p0Settings.C3P0_CONFIG_PREFIX ); try { DataSources.destroy( ds ); } catch (SQLException sqle) { - C3P0_MSG_LOGGER.unableToDestroyC3p0ConnectionPool( sqle ); - throw new HibernateException( "Unable to destroy the connection pool", sqle ); + ConnectionInfoLogger.INSTANCE.unableToDestroyConnectionPool( sqle ); } } diff --git a/hibernate-c3p0/src/main/java/org/hibernate/c3p0/internal/C3P0MessageLogger.java b/hibernate-c3p0/src/main/java/org/hibernate/c3p0/internal/C3P0MessageLogger.java index 4fabc20f22..766b63001d 100644 --- a/hibernate-c3p0/src/main/java/org/hibernate/c3p0/internal/C3P0MessageLogger.java +++ b/hibernate-c3p0/src/main/java/org/hibernate/c3p0/internal/C3P0MessageLogger.java @@ -6,19 +6,15 @@ */ package org.hibernate.c3p0.internal; -import java.sql.SQLException; - -import org.hibernate.internal.log.ConnectionPoolingLogger; +import org.hibernate.internal.log.ConnectionInfoLogger; import org.hibernate.internal.log.SubSystemLogging; import org.jboss.logging.Logger; -import org.jboss.logging.annotations.Cause; import org.jboss.logging.annotations.LogMessage; import org.jboss.logging.annotations.Message; import org.jboss.logging.annotations.MessageLogger; import org.jboss.logging.annotations.ValidIdRange; -import static org.jboss.logging.Logger.Level.INFO; import static org.jboss.logging.Logger.Level.WARN; /** @@ -33,10 +29,9 @@ import static org.jboss.logging.Logger.Level.WARN; name = C3P0MessageLogger.NAME, description = "Logging related to the C3P0 connection pool" ) -public interface C3P0MessageLogger extends ConnectionPoolingLogger { - String NAME = ConnectionPoolingLogger.LOGGER_NAME + ".c3p0"; +public interface C3P0MessageLogger extends ConnectionInfoLogger { + String NAME = ConnectionInfoLogger.LOGGER_NAME + ".c3p0"; - Logger C3P0_LOGGER = Logger.getLogger( NAME ); C3P0MessageLogger C3P0_MSG_LOGGER = Logger.getMessageLogger( C3P0MessageLogger.class, NAME ); /** @@ -49,31 +44,4 @@ public interface C3P0MessageLogger extends ConnectionPoolingLogger { @Message(value = "Both hibernate-style property '%1$s' and c3p0-style property '%2$s' have been set in Hibernate " + "properties. Hibernate-style property '%1$s' will be used and c3p0-style property '%2$s' will be ignored!", id = 10001) void bothHibernateAndC3p0StylesSet(String hibernateStyle,String c3p0Style); - - /** - * Build a message about not being able to find the JDBC driver class - * - * @param jdbcDriverClass The JDBC driver class we could not find - * - * @return The message - */ - @Message(value = "JDBC Driver class not found: %s", id = 10003) - String jdbcDriverNotFound(String jdbcDriverClass); - - /** - * Log a message (WARN) about not being able to stop the underlying c3p0 pool. - * - * @param e The exception when we tried to stop pool - */ - @LogMessage(level = WARN) - @Message(value = "Could not destroy C3P0 connection pool", id = 10004) - void unableToDestroyC3p0ConnectionPool(@Cause SQLException e); - - /** - * Build a message about not being able to start the underlying c3p0 pool. - * - * @return The message - */ - @Message(value = "Could not instantiate C3P0 connection pool", id = 10005) - String unableToInstantiateC3p0ConnectionPool(); } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DatabaseConnectionInfoImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DatabaseConnectionInfoImpl.java index f595320a97..dd3fbed991 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DatabaseConnectionInfoImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DatabaseConnectionInfoImpl.java @@ -18,6 +18,7 @@ import static org.hibernate.dialect.SimpleDatabaseVersion.NO_VERSION; */ public class DatabaseConnectionInfoImpl implements DatabaseConnectionInfo { + // Means either the value was not explicitly set, or simply not offered by the connection provider public static final String DEFAULT = "undefined/unknown"; protected String dbUrl = DEFAULT; @@ -86,7 +87,12 @@ public class DatabaseConnectionInfoImpl implements DatabaseConnectionInfo { } private boolean checkValidInteger(String integerString) { - return checkValidString( integerString ) && Integer.parseInt( integerString, 10 ) >= 0; + try { + return checkValidString( integerString ) && Integer.parseInt( integerString, 10 ) >= 0; + } + catch (NumberFormatException e) { + return false; + } } private boolean checkValidString(String value) { @@ -101,7 +107,8 @@ public class DatabaseConnectionInfoImpl implements DatabaseConnectionInfo { return DEFAULT.equalsIgnoreCase( value ); } - public String toString() { + @Override + public String getDBInfoAsString() { StringBuilder sb = new StringBuilder(); sb.append( "\tDatabase JDBC URL [" ).append( dbUrl ).append(']'); sb.append(sb.length() > 0 ? "\n\t" : "" ).append( "Database driver: " ).append( dbDriverName ); diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DriverManagerConnectionProviderImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DriverManagerConnectionProviderImpl.java index 960e77f916..244fa8b56d 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DriverManagerConnectionProviderImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DriverManagerConnectionProviderImpl.java @@ -28,7 +28,6 @@ import org.hibernate.HibernateException; import org.hibernate.Internal; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.cfg.AvailableSettings; -import org.hibernate.cfg.JdbcSettings; import org.hibernate.dialect.Database; import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo; @@ -40,9 +39,9 @@ import org.hibernate.service.spi.ServiceException; 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.internal.log.ConnectionPoolingLogger.CONNECTIONS_LOGGER; -import static org.hibernate.internal.log.ConnectionPoolingLogger.CONNECTIONS_MESSAGE_LOGGER; +import static org.hibernate.cfg.JdbcSettings.JAKARTA_JDBC_URL; /** * A connection provider that uses the {@link DriverManager} directly to open connections and provides @@ -82,7 +81,7 @@ public class DriverManagerConnectionProviderImpl @Override public void configure(Map configurationValues) { - CONNECTIONS_MESSAGE_LOGGER.usingHibernateBuiltInConnectionPool(); + ConnectionInfoLogger.INSTANCE.usingHibernateBuiltInConnectionPool(); PooledConnections pool = buildPool( configurationValues, serviceRegistry ); final long validationInterval = ConfigurationHelper.getLong( VALIDATION_INTERVAL, configurationValues, 30 ); this.state = new PoolState( pool, validationInterval ); @@ -139,7 +138,7 @@ public class DriverManagerConnectionProviderImpl StringBuilder list = new StringBuilder(); if ( !success ) { //we're hoping that the driver is already loaded - CONNECTIONS_MESSAGE_LOGGER.noDriver( AvailableSettings.DRIVER ); + ConnectionInfoLogger.INSTANCE.jdbcDriverNotSpecified(); Enumeration drivers = DriverManager.getDrivers(); while ( drivers.hasMoreElements() ) { if ( list.length() != 0) { @@ -150,21 +149,11 @@ public class DriverManagerConnectionProviderImpl } if ( url == null ) { - final String msg = CONNECTIONS_MESSAGE_LOGGER.jdbcUrlNotSpecified( AvailableSettings.URL ); - CONNECTIONS_LOGGER.error( msg ); - throw new HibernateException( msg ); + throw new HibernateException( "No JDBC URL specified by property " + JAKARTA_JDBC_URL ); } final Properties connectionProps = ConnectionProviderInitiator.getConnectionProperties( configurationValues ); - // if debug level is enabled, then log the password, otherwise mask it - if ( CONNECTIONS_LOGGER.isDebugEnabled() ) { - CONNECTIONS_MESSAGE_LOGGER.connectionProperties( connectionProps ); - } - else { - CONNECTIONS_MESSAGE_LOGGER.connectionProperties( ConfigurationHelper.maskOut( connectionProps, "password" ) ); - } - final boolean autoCommit = ConfigurationHelper.getBoolean( AvailableSettings.AUTOCOMMIT, configurationValues ); final Integer isolation = ConnectionProviderInitiator.extractIsolation( configurationValues ); final String initSql = (String) configurationValues.get( INIT_SQL ); @@ -186,8 +175,8 @@ public class DriverManagerConnectionProviderImpl .setDBDriverName( success ? driverClassName : list.toString() ) .setDBAutoCommitMode( Boolean.toString( autoCommit ) ) .setDBIsolationLevel( isolation != null ? ConnectionProviderInitiator.toIsolationNiceName(isolation) : null ) - // no standard setting for minimum size? - .setDBMaxPoolSize( ConfigurationHelper.getString(JdbcSettings.POOL_SIZE, configurationValues) ); + .setDBMinPoolSize( String.valueOf(ConfigurationHelper.getInt(MIN_SIZE, configurationValues, 1)) ) + .setDBMaxPoolSize( String.valueOf(ConfigurationHelper.getInt(AvailableSettings.POOL_SIZE, configurationValues, 20)) ); return factory.create( @@ -204,7 +193,7 @@ public class DriverManagerConnectionProviderImpl private static Driver loadDriverIfPossible(String driverClassName, ServiceRegistryImplementor serviceRegistry) { if ( driverClassName == null ) { - CONNECTIONS_LOGGER.debug( "No driver class specified" ); + ConnectionInfoLogger.INSTANCE.debug( "No driver class specified" ); return null; } @@ -229,7 +218,7 @@ public class DriverManagerConnectionProviderImpl private static ConnectionCreatorFactory loadConnectionCreatorFactory(String connectionCreatorFactoryClassName, ServiceRegistryImplementor serviceRegistry) { if ( connectionCreatorFactoryClassName == null ) { - CONNECTIONS_LOGGER.debug( "No connection creator factory class specified" ); + ConnectionInfoLogger.INSTANCE.debug( "No connection creator factory class specified" ); return null; } @@ -307,7 +296,7 @@ public class DriverManagerConnectionProviderImpl protected void validateConnectionsReturned() { int allocationCount = getOpenConnections(); if ( allocationCount != 0 ) { - CONNECTIONS_MESSAGE_LOGGER.error( "Connection leak detected: there are " + allocationCount + " unclosed connections"); + ConnectionInfoLogger.INSTANCE.error( "Connection leak detected: there are " + allocationCount + " unclosed connections"); } } @@ -368,7 +357,7 @@ public class DriverManagerConnectionProviderImpl private PooledConnections( Builder builder) { - CONNECTIONS_LOGGER.debugf( "Initializing Connection pool with %s Connections", builder.initialSize ); + ConnectionInfoLogger.INSTANCE.debugf( "Initializing Connection pool with %s Connections", builder.initialSize ); connectionCreator = builder.connectionCreator; connectionValidator = builder.connectionValidator == null ? ConnectionValidator.ALWAYS_VALID @@ -376,7 +365,6 @@ public class DriverManagerConnectionProviderImpl autoCommit = builder.autoCommit; maxSize = builder.maxSize; minSize = builder.minSize; - CONNECTIONS_MESSAGE_LOGGER.hibernateConnectionPoolSize( maxSize, minSize ); addConnections( builder.initialSize ); } @@ -386,18 +374,18 @@ public class DriverManagerConnectionProviderImpl if ( !primed && size >= minSize ) { // IMPL NOTE : the purpose of primed is to allow the pool to lazily reach its // defined min-size. - CONNECTIONS_LOGGER.debug( "Connection pool now considered primed; min-size will be maintained" ); + ConnectionInfoLogger.INSTANCE.debug( "Connection pool now considered primed; min-size will be maintained" ); primed = true; } if ( size < minSize && primed ) { int numberToBeAdded = minSize - size; - CONNECTIONS_LOGGER.debugf( "Adding %s Connections to the pool", numberToBeAdded ); + ConnectionInfoLogger.INSTANCE.debugf( "Adding %s Connections to the pool", numberToBeAdded ); addConnections( numberToBeAdded ); } else if ( size > maxSize ) { int numberToBeRemoved = size - maxSize; - CONNECTIONS_LOGGER.debugf( "Removing %s Connections from the pool", numberToBeRemoved ); + ConnectionInfoLogger.INSTANCE.debugf( "Removing %s Connections from the pool", numberToBeRemoved ); removeConnections( numberToBeRemoved ); } } @@ -422,7 +410,7 @@ public class DriverManagerConnectionProviderImpl t = ex; } closeConnection( conn, t ); - CONNECTIONS_MESSAGE_LOGGER.debug( "Connection release failed. Closing pooled connection", t ); + ConnectionInfoLogger.INSTANCE.debug( "Connection release failed. Closing pooled connection", t ); return null; } @@ -457,7 +445,7 @@ public class DriverManagerConnectionProviderImpl t = ex; } closeConnection( conn, t ); - CONNECTIONS_MESSAGE_LOGGER.debug( "Connection preparation failed. Closing pooled connection", t ); + ConnectionInfoLogger.INSTANCE.debug( "Connection preparation failed. Closing pooled connection", t ); return null; } @@ -466,7 +454,7 @@ public class DriverManagerConnectionProviderImpl conn.close(); } catch (SQLException ex) { - CONNECTIONS_MESSAGE_LOGGER.unableToCloseConnection( ex ); + ConnectionInfoLogger.INSTANCE.unableToClosePooledConnection( ex ); if ( t != null ) { t.addSuppressed( ex ); } @@ -480,7 +468,7 @@ public class DriverManagerConnectionProviderImpl try { int allocationCount = allConnections.size() - availableConnections.size(); if (allocationCount > 0) { - CONNECTIONS_LOGGER.error( "Connection leak detected: there are " + allocationCount + " unclosed connections upon shutting down pool " + getUrl()); + ConnectionInfoLogger.INSTANCE.error( "Connection leak detected: there are " + allocationCount + " unclosed connections upon shutting down pool " + getUrl()); } } finally { @@ -611,7 +599,7 @@ public class DriverManagerConnectionProviderImpl if ( !active ) { return; } - CONNECTIONS_MESSAGE_LOGGER.cleaningUpConnectionPool( pool.getUrl() ); + ConnectionInfoLogger.INSTANCE.cleaningUpConnectionPool( pool.getUrl() ); active = false; if ( executorService != null ) { PrivilegedAction delegateToPrivilegedAction = @@ -636,7 +624,7 @@ public class DriverManagerConnectionProviderImpl pool.close(); } catch (SQLException e) { - CONNECTIONS_MESSAGE_LOGGER.unableToClosePooledConnection( e ); + ConnectionInfoLogger.INSTANCE.unableToDestroyConnectionPool( e ); } } finally { diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/spi/DatabaseConnectionInfo.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/spi/DatabaseConnectionInfo.java index 5537a301b3..57a1129dc7 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/spi/DatabaseConnectionInfo.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/spi/DatabaseConnectionInfo.java @@ -26,5 +26,5 @@ public interface DatabaseConnectionInfo { DatabaseConnectionInfo setDBMaxPoolSize(String maxPoolSize); - String toString(); + String getDBInfoAsString(); } 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 ebb1332e63..9dd5e1645d 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 @@ -17,10 +17,8 @@ import org.hibernate.boot.registry.StandardServiceInitiator; import org.hibernate.cfg.JdbcSettings; import org.hibernate.dialect.DatabaseVersion; import org.hibernate.dialect.Dialect; -import org.hibernate.dialect.SimpleDatabaseVersion; import org.hibernate.engine.config.spi.ConfigurationService; import org.hibernate.engine.jdbc.batch.spi.BatchBuilder; -import org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl; import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo; import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess; @@ -36,7 +34,7 @@ import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.event.internal.EmptyEventManager; import org.hibernate.event.spi.EventManager; import org.hibernate.internal.CoreMessageLogger; -import org.hibernate.internal.log.ConnectionProviderLogger; +import org.hibernate.internal.log.ConnectionInfoLogger; import org.hibernate.jdbc.AbstractReturningWork; import org.hibernate.jpa.internal.MutableJpaComplianceImpl; import org.hibernate.jpa.spi.JpaCompliance; @@ -169,7 +167,7 @@ public class JdbcEnvironmentInitiator implements StandardServiceInitiator. - */ -package org.hibernate.internal.log; - -import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo; - -import org.jboss.logging.BasicLogger; -import org.jboss.logging.Logger; -import org.jboss.logging.annotations.LogMessage; -import org.jboss.logging.annotations.Message; -import org.jboss.logging.annotations.MessageLogger; -import org.jboss.logging.annotations.ValidIdRange; - -import static org.jboss.logging.Logger.Level.INFO; - -@MessageLogger( projectCode = "HHH" ) -@ValidIdRange( min = 10002001, max = 10002100 ) -@SubSystemLogging( - name = ConnectionProviderLogger.LOGGER_NAME, - description = "Used to log details of database access through `ConnectionProvider`" -) -public interface ConnectionProviderLogger extends BasicLogger { - String LOGGER_NAME = SubSystemLogging.BASE + ".connections.provider"; - - /** - * Static access to the logging instance - */ - ConnectionProviderLogger INSTANCE = Logger.getMessageLogger( - ConnectionProviderLogger.class, - LOGGER_NAME - ); - - - @LogMessage(level = INFO) - @Message( - value = "Database info:\n%s", - id = 10002001 - ) - void logConnectionDetails(DatabaseConnectionInfo databaseConnectionInfo); -} 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 3047ce1276..b25d095006 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,12 +16,11 @@ import org.hibernate.HibernateException; import org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl; import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo; +import org.hibernate.internal.log.ConnectionInfoLogger; import org.hibernate.service.UnknownUnwrapTypeException; import org.hibernate.service.spi.Configurable; import org.hibernate.service.spi.Stoppable; -import org.jboss.logging.Logger; - import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; @@ -35,8 +34,6 @@ public class HikariCPConnectionProvider implements ConnectionProvider, Configura private static final long serialVersionUID = -9131625057941275711L; - private static final Logger LOGGER = Logger.getLogger( HikariCPConnectionProvider.class ); - /** * HikariCP configuration. */ @@ -56,7 +53,7 @@ public class HikariCPConnectionProvider implements ConnectionProvider, Configura @Override public void configure(Map props) throws HibernateException { try { - LOGGER.debug( "Configuring HikariCP" ); + ConnectionInfoLogger.INSTANCE.configureConnectionPool( "HikariCP" ); hcfg = HikariConfigurationUtil.loadConfiguration( props ); hds = new HikariDataSource( hcfg ); @@ -70,10 +67,9 @@ public class HikariCPConnectionProvider implements ConnectionProvider, Configura .setDBMaxPoolSize( String.valueOf(hcfg.getMaximumPoolSize()) ); } catch (Exception e) { + ConnectionInfoLogger.INSTANCE.unableToInstantiateConnectionPool( e ); throw new HibernateException( e ); } - - LOGGER.debug( "HikariCP Configured" ); } // ************************************************************************* @@ -129,6 +125,7 @@ public class HikariCPConnectionProvider implements ConnectionProvider, Configura @Override public void stop() { if ( hds != null ) { + ConnectionInfoLogger.INSTANCE.cleaningUpConnectionPool( "HikariCP" ); hds.close(); } } diff --git a/hibernate-proxool/src/main/java/org/hibernate/proxool/internal/ProxoolConnectionProvider.java b/hibernate-proxool/src/main/java/org/hibernate/proxool/internal/ProxoolConnectionProvider.java index 1b96f14be5..3a632409b5 100644 --- a/hibernate-proxool/src/main/java/org/hibernate/proxool/internal/ProxoolConnectionProvider.java +++ b/hibernate-proxool/src/main/java/org/hibernate/proxool/internal/ProxoolConnectionProvider.java @@ -23,6 +23,7 @@ import org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiato import org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl; import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo; +import org.hibernate.internal.log.ConnectionInfoLogger; import org.hibernate.service.UnknownUnwrapTypeException; import org.hibernate.service.spi.Configurable; import org.hibernate.service.spi.ServiceRegistryAwareService; @@ -37,7 +38,6 @@ import org.logicalcobwebs.proxool.configuration.PropertyConfigurator; import static org.hibernate.internal.util.StringHelper.isNotEmpty; import static org.hibernate.internal.util.config.ConfigurationHelper.getBoolean; -import static org.hibernate.proxool.internal.ProxoolMessageLogger.PROXOOL_LOGGER; import static org.hibernate.proxool.internal.ProxoolMessageLogger.PROXOOL_MESSAGE_LOGGER; /** @@ -115,6 +115,8 @@ public class ProxoolConnectionProvider @Override public void configure(Map props) { + ConnectionInfoLogger.INSTANCE.configureConnectionPool( "Proxool" ); + // Get the configurator files (if available) final String jaxpFile = (String) props.get( ProxoolSettings.PROXOOL_XML ); final String propFile = (String) props.get( ProxoolSettings.PROXOOL_PROPERTIES ); @@ -129,8 +131,8 @@ public class ProxoolConnectionProvider if ( "true".equals( externalConfig ) ) { // Validate that an alias name was provided to determine which pool to use if ( !isNotEmpty( proxoolAlias ) ) { - final String msg = PROXOOL_MESSAGE_LOGGER.unableToConfigureProxoolProviderToUseExistingInMemoryPool( ProxoolSettings.PROXOOL_POOL_ALIAS ); - PROXOOL_LOGGER.error( msg ); + final String msg = "Cannot configure Proxool Provider to use an existing in memory pool without the " + + ProxoolSettings.PROXOOL_POOL_ALIAS + " property set."; throw new HibernateException( msg ); } // Append the stem to the proxool pool alias @@ -148,8 +150,7 @@ public class ProxoolConnectionProvider // Validate that an alias name was provided to determine which pool to use if ( !isNotEmpty( proxoolAlias ) ) { - final String msg = PROXOOL_MESSAGE_LOGGER.unableToConfigureProxoolProviderToUseJaxp( ProxoolSettings.PROXOOL_POOL_ALIAS ); - PROXOOL_LOGGER.error( msg ); + final String msg = "Cannot configure Proxool Provider to use JAXP without the " + ProxoolSettings.PROXOOL_POOL_ALIAS + " property set."; throw new HibernateException( msg ); } @@ -157,8 +158,7 @@ public class ProxoolConnectionProvider JAXPConfigurator.configure( getConfigStreamReader( jaxpFile ), false ); } catch (ProxoolException e) { - final String msg = PROXOOL_MESSAGE_LOGGER.unableToLoadJaxpConfiguratorFile( jaxpFile ); - PROXOOL_LOGGER.error( msg, e ); + final String msg = "Proxool Provider unable to load JAXP configurator file: " + jaxpFile; throw new HibernateException( msg, e ); } @@ -173,8 +173,7 @@ public class ProxoolConnectionProvider // Validate that an alias name was provided to determine which pool to use if ( !isNotEmpty( proxoolAlias ) ) { - final String msg = PROXOOL_MESSAGE_LOGGER.unableToConfigureProxoolProviderToUsePropertiesFile( ProxoolSettings.PROXOOL_POOL_ALIAS ); - PROXOOL_LOGGER.error( msg ); + final String msg = "Cannot configure Proxool Provider to use Properties File without the " + ProxoolSettings.PROXOOL_POOL_ALIAS + " property set."; throw new HibernateException( msg ); } @@ -182,8 +181,7 @@ public class ProxoolConnectionProvider PropertyConfigurator.configure( getConfigProperties( propFile ) ); } catch (ProxoolException e) { - final String msg = PROXOOL_MESSAGE_LOGGER.unableToLoadPropertyConfiguratorFile( propFile ); - PROXOOL_LOGGER.error( msg, e ); + final String msg = "Proxool Provider unable to load Property configurator file: " + propFile; throw new HibernateException( msg, e ); } @@ -241,6 +239,7 @@ public class ProxoolConnectionProvider } // We have created the pool ourselves, so shut it down + ConnectionInfoLogger.INSTANCE.cleaningUpConnectionPool( "proxool" ); try { if ( ProxoolFacade.getAliases().length == 1 ) { ProxoolFacade.shutdown( 0 ); @@ -252,9 +251,7 @@ public class ProxoolConnectionProvider catch (Exception e) { // If you're closing down the ConnectionProvider chances are an // is not a real big deal, just warn - final String msg = PROXOOL_MESSAGE_LOGGER.exceptionClosingProxoolPool(); - PROXOOL_LOGGER.warn( msg, e ); - throw new HibernateException( msg, e ); + ConnectionInfoLogger.INSTANCE.unableToDestroyConnectionPool( e ); } } diff --git a/hibernate-proxool/src/main/java/org/hibernate/proxool/internal/ProxoolMessageLogger.java b/hibernate-proxool/src/main/java/org/hibernate/proxool/internal/ProxoolMessageLogger.java index 9942ddd0e3..f44a836ae4 100644 --- a/hibernate-proxool/src/main/java/org/hibernate/proxool/internal/ProxoolMessageLogger.java +++ b/hibernate-proxool/src/main/java/org/hibernate/proxool/internal/ProxoolMessageLogger.java @@ -6,7 +6,7 @@ */ package org.hibernate.proxool.internal; -import org.hibernate.internal.log.ConnectionPoolingLogger; +import org.hibernate.internal.log.ConnectionInfoLogger; import org.hibernate.internal.log.SubSystemLogging; import org.jboss.logging.Logger; @@ -15,7 +15,7 @@ import org.jboss.logging.annotations.Message; import org.jboss.logging.annotations.MessageLogger; import org.jboss.logging.annotations.ValidIdRange; -import static org.jboss.logging.Logger.Level.INFO; +import static org.jboss.logging.Logger.Level.DEBUG; /** * The jboss-logging {@link MessageLogger} for the hibernate-proxool module. It reserves message ids ranging from @@ -29,9 +29,8 @@ import static org.jboss.logging.Logger.Level.INFO; name = ProxoolMessageLogger.LOGGER_NAME, description = "Logs details related to Proxool connection pooling" ) -public interface ProxoolMessageLogger extends ConnectionPoolingLogger { - String LOGGER_NAME = ConnectionPoolingLogger.LOGGER_NAME + ".proxool"; - Logger PROXOOL_LOGGER = Logger.getLogger( LOGGER_NAME ); +public interface ProxoolMessageLogger extends ConnectionInfoLogger { + String LOGGER_NAME = ConnectionInfoLogger.LOGGER_NAME + ".proxool"; ProxoolMessageLogger PROXOOL_MESSAGE_LOGGER = Logger.getMessageLogger( ProxoolMessageLogger.class, LOGGER_NAME ); /** @@ -39,7 +38,7 @@ public interface ProxoolMessageLogger extends ConnectionPoolingLogger { * * @param proxoolAlias The name (alias) of the proxool pool */ - @LogMessage(level = INFO) + @LogMessage(level = DEBUG) @Message(value = "Configuring Proxool Provider to use pool alias: %s", id = 30002) void configuringProxoolProviderToUsePoolAlias(String proxoolAlias); @@ -48,7 +47,7 @@ public interface ProxoolMessageLogger extends ConnectionPoolingLogger { * * @param proxoolAlias The name (alias) of the proxool pool */ - @LogMessage(level = INFO) + @LogMessage(level = DEBUG) @Message(value = "Configuring Proxool Provider using existing pool in memory: %s", id = 30003) void configuringProxoolProviderUsingExistingPool(String proxoolAlias); @@ -57,7 +56,7 @@ public interface ProxoolMessageLogger extends ConnectionPoolingLogger { * * @param jaxpFile The XML configuration file to use */ - @LogMessage(level = INFO) + @LogMessage(level = DEBUG) @Message(value = "Configuring Proxool Provider using JAXPConfigurator: %s", id = 30004) void configuringProxoolProviderUsingJaxpConfigurator(String jaxpFile); @@ -66,65 +65,8 @@ public interface ProxoolMessageLogger extends ConnectionPoolingLogger { * * @param propFile The properties file to use */ - @LogMessage(level = INFO) + @LogMessage(level = DEBUG) @Message(value = "Configuring Proxool Provider using Properties File: %s", id = 30005) void configuringProxoolProviderUsingPropertiesFile(String propFile); - /** - * Builds a message about not being able to close the underlying proxool pool. - * - * @return The message - */ - @Message(value = "Exception occurred when closing the Proxool pool", id = 30006) - String exceptionClosingProxoolPool(); - - /** - * Builds a message about invalid configuration - * - * @param proxoolPoolAlias The name (alias) of the proxool pool - * - * @return The message - */ - @Message(value = "Cannot configure Proxool Provider to use an existing in memory pool without the %s property set.", id = 30007) - String unableToConfigureProxoolProviderToUseExistingInMemoryPool(String proxoolPoolAlias); - - /** - * Builds a message about invalid configuration - * - * @param proxoolPoolAlias The name (alias) of the proxool pool - * - * @return The message - */ - @Message(value = "Cannot configure Proxool Provider to use JAXP without the %s property set.", id = 30008) - String unableToConfigureProxoolProviderToUseJaxp(String proxoolPoolAlias); - - /** - * Builds a message about invalid configuration - * - * @param proxoolPoolAlias The name (alias) of the proxool pool - * - * @return The message - */ - @Message(value = "Cannot configure Proxool Provider to use Properties File without the %s property set.", id = 30009) - String unableToConfigureProxoolProviderToUsePropertiesFile(String proxoolPoolAlias); - - /** - * Builds a message about not being able to find or load the XML configuration file - * - * @param jaxpFile The XML file - * - * @return The message - */ - @Message(value = "Proxool Provider unable to load JAXP configurator file: %s", id = 30010) - String unableToLoadJaxpConfiguratorFile(String jaxpFile); - - /** - * Builds a message about not being able to find or load the properties configuration file - * - * @param propFile The properties file - * - * @return The message - */ - @Message(value = "Proxool Provider unable to load Property configurator file: %s", id = 30011) - String unableToLoadPropertyConfiguratorFile(String propFile); } diff --git a/hibernate-ucp/src/main/java/org/hibernate/oracleucp/internal/UCPConnectionProvider.java b/hibernate-ucp/src/main/java/org/hibernate/oracleucp/internal/UCPConnectionProvider.java index b6be90c800..2181caa63e 100644 --- a/hibernate-ucp/src/main/java/org/hibernate/oracleucp/internal/UCPConnectionProvider.java +++ b/hibernate-ucp/src/main/java/org/hibernate/oracleucp/internal/UCPConnectionProvider.java @@ -23,13 +23,12 @@ import org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiato import org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl; import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo; +import org.hibernate.internal.log.ConnectionInfoLogger; import org.hibernate.internal.util.config.ConfigurationHelper; import org.hibernate.service.UnknownUnwrapTypeException; import org.hibernate.service.spi.Configurable; import org.hibernate.service.spi.Stoppable; -import org.jboss.logging.Logger; - import oracle.ucp.UniversalConnectionPoolException; import oracle.ucp.admin.UniversalConnectionPoolManager; import oracle.ucp.admin.UniversalConnectionPoolManagerImpl; @@ -41,10 +40,10 @@ import org.hibernate.cfg.AvailableSettings; public class UCPConnectionProvider implements ConnectionProvider, Configurable, Stoppable { private static final long serialVersionUID = 1L; - private static final Logger LOGGER = Logger.getLogger( "UCPConnectionProvider.class" ); private PoolDataSource ucpDS = null; private UniversalConnectionPoolManager poolManager = null; - private static final String CONFIG_PREFIX = "hibernate.oracleucp."; + private static final String UCP_CONFIG_PREFIX = "hibernate.oracleucp"; + private static final String CONFIG_PREFIX = UCP_CONFIG_PREFIX + "."; private boolean autoCommit; private Integer isolation; @@ -54,7 +53,7 @@ public class UCPConnectionProvider implements ConnectionProvider, Configurable, @Override public void configure(Map props) throws HibernateException { try { - LOGGER.trace( "Configuring oracle UCP" ); + ConnectionInfoLogger.INSTANCE.configureConnectionPool( "Ucp" ); isolation = ConnectionProviderInitiator.extractIsolation( props ); autoCommit = ConfigurationHelper.getBoolean( AvailableSettings.AUTOCOMMIT, props ); @@ -74,11 +73,9 @@ public class UCPConnectionProvider implements ConnectionProvider, Configurable, .setDBMaxPoolSize( String.valueOf(ucpDS.getMaxPoolSize()) ); } catch (Exception e) { - LOGGER.debug( "oracle UCP Configuration failed" ); + ConnectionInfoLogger.INSTANCE.unableToInstantiateConnectionPool( e ); throw new HibernateException( e ); } - - LOGGER.trace( "oracle UCP Configured" ); } private void configureDataSource(PoolDataSource ucpDS, Properties ucpProps) { @@ -226,13 +223,14 @@ public class UCPConnectionProvider implements ConnectionProvider, Configurable, @Override public void stop() { if(this.ucpDS!=null && ucpDS.getConnectionPoolName() != null) { + ConnectionInfoLogger.INSTANCE.cleaningUpConnectionPool( UCP_CONFIG_PREFIX + " [" + ucpDS.getConnectionPoolName() + "]" ); try { UniversalConnectionPoolManager poolManager = UniversalConnectionPoolManagerImpl. getUniversalConnectionPoolManager(); poolManager.destroyConnectionPool(ucpDS.getConnectionPoolName()); } catch (UniversalConnectionPoolException e) { - LOGGER.debug("Unable to destroy UCP connection pool"); + ConnectionInfoLogger.INSTANCE.unableToDestroyConnectionPool( e ); } } } diff --git a/hibernate-vibur/src/main/java/org/hibernate/vibur/internal/ViburDBCPConnectionProvider.java b/hibernate-vibur/src/main/java/org/hibernate/vibur/internal/ViburDBCPConnectionProvider.java index 519b2fe2ae..5c83c47a50 100644 --- a/hibernate-vibur/src/main/java/org/hibernate/vibur/internal/ViburDBCPConnectionProvider.java +++ b/hibernate-vibur/src/main/java/org/hibernate/vibur/internal/ViburDBCPConnectionProvider.java @@ -10,6 +10,7 @@ package org.hibernate.vibur.internal; import org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl; import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo; +import org.hibernate.internal.log.ConnectionInfoLogger; import org.hibernate.service.UnknownUnwrapTypeException; import org.hibernate.service.spi.Configurable; import org.hibernate.service.spi.Stoppable; @@ -48,7 +49,9 @@ import static org.hibernate.cfg.AvailableSettings.*; * @see ConnectionProvider */ public class ViburDBCPConnectionProvider implements ConnectionProvider, Configurable, Stoppable { - private static final String VIBUR_PREFIX = "hibernate.vibur."; + + private static final String VIBUR_CONFIG_PREFIX = "hibernate.vibur"; + private static final String VIBUR_PREFIX = VIBUR_CONFIG_PREFIX + "."; private ViburDBCPDataSource dataSource = null; @@ -56,6 +59,8 @@ public class ViburDBCPConnectionProvider implements ConnectionProvider, Configur @Override public void configure(Map configurationValues) { + ConnectionInfoLogger.INSTANCE.configureConnectionPool( "Vibur" ); + dataSource = new ViburDBCPDataSource( transform( configurationValues ) ); dataSource.start(); @@ -81,6 +86,7 @@ public class ViburDBCPConnectionProvider implements ConnectionProvider, Configur @Override public void stop() { if ( dataSource != null ) { + ConnectionInfoLogger.INSTANCE.cleaningUpConnectionPool( VIBUR_CONFIG_PREFIX ); dataSource.terminate(); dataSource = null; }