Skip to content

Commit 55108d0

Browse files
jrenaatsebersole
authored andcommitted
HHH-18224 - db info logging cleanup
Signed-off-by: Jan Schatteman <[email protected]>
1 parent f556ba9 commit 55108d0

File tree

15 files changed

+108
-257
lines changed

15 files changed

+108
-257
lines changed

design/logger_id_ranges.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ public interface MappingModelCreationLogger extends BasicLogger {
7373

7474

7575
|[[connections-pooling]]org.hibernate.orm.connections.pooling
76-
|<<ConnectionPoolingLogger>>
77-
|Logging related to connection pooling
76+
|<<ConnectionInfoLogger>>
77+
|Logging related to connections and connection pooling
7878

7979
|org.hibernate.orm.boot
8080
|n/a
@@ -93,9 +93,9 @@ public interface MappingModelCreationLogger extends BasicLogger {
9393
|Sub-system (?)
9494

9595

96-
|[[ConnectionPoolingLogger]]10001001
96+
|[[ConnectionInfoLogger]]10001001
9797
|10001500
98-
|org.hibernate.internal.log.ConnectionPoolingLogger
98+
|org.hibernate.internal.log.ConnectionInfoLogger
9999
| <<connections-pooling>>
100100

101101
|1

hibernate-agroal/src/main/java/org/hibernate/agroal/internal/AgroalConnectionProvider.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl;
2222
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
2323
import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo;
24+
import org.hibernate.internal.log.ConnectionInfoLogger;
2425
import org.hibernate.service.UnknownUnwrapTypeException;
2526
import org.hibernate.service.spi.Configurable;
2627
import org.hibernate.service.spi.Stoppable;
@@ -32,8 +33,6 @@
3233
import java.util.function.Consumer;
3334
import java.util.function.Function;
3435

35-
import org.jboss.logging.Logger;
36-
3736
import static org.hibernate.cfg.AgroalSettings.AGROAL_CONFIG_PREFIX;
3837

3938
/**
@@ -62,7 +61,6 @@ public class AgroalConnectionProvider implements ConnectionProvider, Configurabl
6261

6362
public static final String CONFIG_PREFIX = AGROAL_CONFIG_PREFIX + ".";
6463
private static final long serialVersionUID = 1L;
65-
private static final Logger LOGGER = Logger.getLogger( AgroalConnectionProvider.class );
6664
private AgroalDataSource agroalDataSource = null;
6765
private DatabaseConnectionInfo dbInfo;
6866

@@ -93,7 +91,7 @@ private static <T> void copyProperty(Map<String, Object> properties, String key,
9391

9492
@Override
9593
public void configure(Map<String, Object> props) throws HibernateException {
96-
LOGGER.debug( "Configuring Agroal" );
94+
ConnectionInfoLogger.INSTANCE.configureConnectionPool( "Agroal" );
9795
try {
9896
AgroalPropertiesReader agroalProperties = new AgroalPropertiesReader( CONFIG_PREFIX )
9997
.readProperties( (Map) props ); //TODO: this is a garbage cast
@@ -122,9 +120,9 @@ public void configure(Map<String, Object> props) throws HibernateException {
122120
.setDBMaxPoolSize( String.valueOf(acpc.maxSize()) );
123121
}
124122
catch ( Exception e ) {
123+
ConnectionInfoLogger.INSTANCE.unableToInstantiateConnectionPool( e );
125124
throw new HibernateException( e );
126125
}
127-
LOGGER.debug( "Agroal Configured" );
128126
}
129127

130128
// --- ConnectionProvider
@@ -177,6 +175,8 @@ public <T> T unwrap(Class<T> unwrapType) {
177175
@Override
178176
public void stop() {
179177
if ( agroalDataSource != null ) {
178+
ConnectionInfoLogger.INSTANCE.cleaningUpConnectionPool( agroalDataSource.getConfiguration().connectionPoolConfiguration().
179+
connectionFactoryConfiguration().jdbcUrl() );
180180
agroalDataSource.close();
181181
}
182182
}

hibernate-c3p0/src/main/java/org/hibernate/c3p0/internal/C3P0ConnectionProvider.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,14 @@
2424
import org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl;
2525
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
2626
import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo;
27+
import org.hibernate.internal.log.ConnectionInfoLogger;
2728
import org.hibernate.internal.util.PropertiesHelper;
28-
import org.hibernate.internal.util.config.ConfigurationHelper;
2929
import org.hibernate.service.UnknownUnwrapTypeException;
3030
import org.hibernate.service.spi.Configurable;
3131
import org.hibernate.service.spi.ServiceRegistryAwareService;
3232
import org.hibernate.service.spi.ServiceRegistryImplementor;
3333
import org.hibernate.service.spi.Stoppable;
3434

35-
import static org.hibernate.c3p0.internal.C3P0MessageLogger.C3P0_LOGGER;
3635
import static org.hibernate.c3p0.internal.C3P0MessageLogger.C3P0_MSG_LOGGER;
3736
import static org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.extractSetting;
3837
import static org.hibernate.internal.util.config.ConfigurationHelper.getBoolean;
@@ -111,6 +110,8 @@ else if ( DataSource.class.isAssignableFrom( unwrapType ) ) {
111110

112111
@Override
113112
public void configure(Map<String, Object> props) {
113+
ConnectionInfoLogger.INSTANCE.configureConnectionPool( "C3p0" );
114+
114115
final String jdbcDriverClass = extractSetting(
115116
props,
116117
JdbcSettings.JAKARTA_JDBC_DRIVER,
@@ -126,19 +127,17 @@ public void configure(Map<String, Object> props) {
126127

127128
final Properties connectionProps = ConnectionProviderInitiator.getConnectionProperties( props );
128129

129-
C3P0_MSG_LOGGER.connectionProperties( ConfigurationHelper.maskOut( connectionProps, "password" ) );
130-
131130
autocommit = getBoolean( JdbcSettings.AUTOCOMMIT, props );
132131

133132
if ( jdbcDriverClass == null ) {
134-
C3P0_MSG_LOGGER.jdbcDriverNotSpecified();
133+
ConnectionInfoLogger.INSTANCE.jdbcDriverNotSpecified();
135134
}
136135
else {
137136
try {
138137
serviceRegistry.requireService( ClassLoaderService.class ).classForName( jdbcDriverClass );
139138
}
140139
catch (ClassLoadingException e) {
141-
throw new ClassLoadingException( C3P0_MSG_LOGGER.jdbcDriverNotFound( jdbcDriverClass ), e );
140+
throw new ClassLoadingException( "JDBC Driver class " + jdbcDriverClass + " not found", e );
142141
}
143142
}
144143

@@ -197,8 +196,8 @@ public void configure(Map<String, Object> props) {
197196
ds = DataSources.pooledDataSource( unpooled, allProps );
198197
}
199198
catch (Exception e) {
200-
C3P0_LOGGER.error( C3P0_MSG_LOGGER.unableToInstantiateC3p0ConnectionPool(), e );;
201-
throw new HibernateException( C3P0_MSG_LOGGER.unableToInstantiateC3p0ConnectionPool(), e );
199+
ConnectionInfoLogger.INSTANCE.unableToInstantiateConnectionPool( e );
200+
throw new HibernateException( e );
202201
}
203202

204203
isolation = ConnectionProviderInitiator.extractIsolation( props );
@@ -247,12 +246,12 @@ private void warnPropertyConflict(String hibernateStyle, String c3p0Style) {
247246

248247
@Override
249248
public void stop() {
249+
ConnectionInfoLogger.INSTANCE.cleaningUpConnectionPool( C3p0Settings.C3P0_CONFIG_PREFIX );
250250
try {
251251
DataSources.destroy( ds );
252252
}
253253
catch (SQLException sqle) {
254-
C3P0_MSG_LOGGER.unableToDestroyC3p0ConnectionPool( sqle );
255-
throw new HibernateException( "Unable to destroy the connection pool", sqle );
254+
ConnectionInfoLogger.INSTANCE.unableToDestroyConnectionPool( sqle );
256255
}
257256
}
258257

hibernate-c3p0/src/main/java/org/hibernate/c3p0/internal/C3P0MessageLogger.java

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,15 @@
66
*/
77
package org.hibernate.c3p0.internal;
88

9-
import java.sql.SQLException;
10-
11-
import org.hibernate.internal.log.ConnectionPoolingLogger;
9+
import org.hibernate.internal.log.ConnectionInfoLogger;
1210
import org.hibernate.internal.log.SubSystemLogging;
1311

1412
import org.jboss.logging.Logger;
15-
import org.jboss.logging.annotations.Cause;
1613
import org.jboss.logging.annotations.LogMessage;
1714
import org.jboss.logging.annotations.Message;
1815
import org.jboss.logging.annotations.MessageLogger;
1916
import org.jboss.logging.annotations.ValidIdRange;
2017

21-
import static org.jboss.logging.Logger.Level.INFO;
2218
import static org.jboss.logging.Logger.Level.WARN;
2319

2420
/**
@@ -33,10 +29,9 @@
3329
name = C3P0MessageLogger.NAME,
3430
description = "Logging related to the C3P0 connection pool"
3531
)
36-
public interface C3P0MessageLogger extends ConnectionPoolingLogger {
37-
String NAME = ConnectionPoolingLogger.LOGGER_NAME + ".c3p0";
32+
public interface C3P0MessageLogger extends ConnectionInfoLogger {
33+
String NAME = ConnectionInfoLogger.LOGGER_NAME + ".c3p0";
3834

39-
Logger C3P0_LOGGER = Logger.getLogger( NAME );
4035
C3P0MessageLogger C3P0_MSG_LOGGER = Logger.getMessageLogger( C3P0MessageLogger.class, NAME );
4136

4237
/**
@@ -49,31 +44,4 @@ public interface C3P0MessageLogger extends ConnectionPoolingLogger {
4944
@Message(value = "Both hibernate-style property '%1$s' and c3p0-style property '%2$s' have been set in Hibernate "
5045
+ "properties. Hibernate-style property '%1$s' will be used and c3p0-style property '%2$s' will be ignored!", id = 10001)
5146
void bothHibernateAndC3p0StylesSet(String hibernateStyle,String c3p0Style);
52-
53-
/**
54-
* Build a message about not being able to find the JDBC driver class
55-
*
56-
* @param jdbcDriverClass The JDBC driver class we could not find
57-
*
58-
* @return The message
59-
*/
60-
@Message(value = "JDBC Driver class not found: %s", id = 10003)
61-
String jdbcDriverNotFound(String jdbcDriverClass);
62-
63-
/**
64-
* Log a message (WARN) about not being able to stop the underlying c3p0 pool.
65-
*
66-
* @param e The exception when we tried to stop pool
67-
*/
68-
@LogMessage(level = WARN)
69-
@Message(value = "Could not destroy C3P0 connection pool", id = 10004)
70-
void unableToDestroyC3p0ConnectionPool(@Cause SQLException e);
71-
72-
/**
73-
* Build a message about not being able to start the underlying c3p0 pool.
74-
*
75-
* @return The message
76-
*/
77-
@Message(value = "Could not instantiate C3P0 connection pool", id = 10005)
78-
String unableToInstantiateC3p0ConnectionPool();
7947
}

hibernate-core/src/main/java/org/hibernate/engine/jdbc/connections/internal/DatabaseConnectionInfoImpl.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
public class DatabaseConnectionInfoImpl implements DatabaseConnectionInfo {
2020

21+
// Means either the value was not explicitly set, or simply not offered by the connection provider
2122
public static final String DEFAULT = "undefined/unknown";
2223

2324
protected String dbUrl = DEFAULT;
@@ -86,7 +87,12 @@ public DatabaseConnectionInfo setDBMaxPoolSize(String maxPoolSize) {
8687
}
8788

8889
private boolean checkValidInteger(String integerString) {
89-
return checkValidString( integerString ) && Integer.parseInt( integerString, 10 ) >= 0;
90+
try {
91+
return checkValidString( integerString ) && Integer.parseInt( integerString, 10 ) >= 0;
92+
}
93+
catch (NumberFormatException e) {
94+
return false;
95+
}
9096
}
9197

9298
private boolean checkValidString(String value) {
@@ -101,7 +107,8 @@ private boolean isDefaultStringValue(String value) {
101107
return DEFAULT.equalsIgnoreCase( value );
102108
}
103109

104-
public String toString() {
110+
@Override
111+
public String getDBInfoAsString() {
105112
StringBuilder sb = new StringBuilder();
106113
sb.append( "\tDatabase JDBC URL [" ).append( dbUrl ).append(']');
107114
sb.append(sb.length() > 0 ? "\n\t" : "" ).append( "Database driver: " ).append( dbDriverName );

0 commit comments

Comments
 (0)