Skip to content

Commit a9d7ab5

Browse files
committed
more typesafe logging in ConnectionInfoLogger
1 parent 7569ccf commit a9d7ab5

File tree

6 files changed

+52
-16
lines changed

6 files changed

+52
-16
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo;
1818
import org.hibernate.engine.jdbc.env.spi.ExtractedDatabaseMetaData;
1919
import org.hibernate.engine.jndi.spi.JndiService;
20-
import org.hibernate.internal.log.ConnectionInfoLogger;
2120
import org.hibernate.service.UnknownUnwrapTypeException;
2221
import org.hibernate.service.spi.Configurable;
2322
import org.hibernate.service.spi.InjectService;

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.hibernate.service.spi.ServiceRegistryAwareService;
2727
import org.hibernate.service.spi.ServiceRegistryImplementor;
2828
import org.hibernate.service.spi.Stoppable;
29-
import org.hibernate.internal.log.ConnectionInfoLogger;
3029

3130
import static org.hibernate.cfg.JdbcSettings.AUTOCOMMIT;
3231
import static org.hibernate.cfg.JdbcSettings.DRIVER;
@@ -220,7 +219,7 @@ else if ( connectionCreatorFactory != null ) {
220219

221220
private static Driver loadDriverIfPossible(String driverClassName, ServiceRegistry serviceRegistry) {
222221
if ( driverClassName == null ) {
223-
CONNECTION_INFO_LOGGER.debug( "No driver class specified" );
222+
CONNECTION_INFO_LOGGER.noDriverClassSpecified();
224223
return null;
225224
}
226225
else if ( serviceRegistry != null ) {
@@ -247,7 +246,7 @@ else if ( serviceRegistry != null ) {
247246
private static ConnectionCreatorFactory loadConnectionCreatorFactory(
248247
String connectionCreatorFactoryClassName, ServiceRegistry serviceRegistry) {
249248
if ( connectionCreatorFactoryClassName == null ) {
250-
CONNECTION_INFO_LOGGER.debug( "No connection creator factory class specified" );
249+
CONNECTION_INFO_LOGGER.noConnectionCreatorFactoryClassSpecified();
251250
return null;
252251
}
253252
else if ( serviceRegistry != null ) {
@@ -340,7 +339,7 @@ protected int getOpenConnections() {
340339
protected void validateConnectionsReturned() {
341340
final int allocationCount = getOpenConnections();
342341
if ( allocationCount != 0 ) {
343-
CONNECTION_INFO_LOGGER.error( "Connection leak detected: there are " + allocationCount + " unclosed connections");
342+
CONNECTION_INFO_LOGGER.connectionLeakDetected( allocationCount );
344343
}
345344
}
346345

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55
package org.hibernate.engine.jdbc.connections.internal;
66

7-
import org.hibernate.internal.log.ConnectionInfoLogger;
87

98
import java.sql.Connection;
109
import java.sql.SQLException;

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package org.hibernate.engine.jdbc.connections.internal;
66

77
import org.hibernate.HibernateException;
8-
import org.hibernate.internal.log.ConnectionInfoLogger;
98

109
import java.sql.Connection;
1110
import java.sql.SQLException;
@@ -32,7 +31,7 @@ class PooledConnections {
3231

3332
private PooledConnections(
3433
Builder builder) {
35-
CONNECTION_INFO_LOGGER.debugf( "Initializing Connection pool with %s Connections", builder.initialSize );
34+
CONNECTION_INFO_LOGGER.initializingConnectionPool( builder.initialSize );
3635
connectionCreator = builder.connectionCreator;
3736
connectionValidator = builder.connectionValidator == null
3837
? ConnectionValidator.ALWAYS_VALID
@@ -49,18 +48,18 @@ void validate() {
4948
if ( !primed && size >= minSize ) {
5049
// IMPL NOTE: the purpose of primed is to allow the pool to lazily reach its
5150
// defined min-size.
52-
CONNECTION_INFO_LOGGER.debug( "Connection pool now considered primed; min-size will be maintained" );
51+
CONNECTION_INFO_LOGGER.connectionPoolPrimed();
5352
primed = true;
5453
}
5554

5655
if ( size < minSize && primed ) {
5756
int numberToBeAdded = minSize - size;
58-
CONNECTION_INFO_LOGGER.debugf( "Adding %s Connections to the pool", numberToBeAdded );
57+
CONNECTION_INFO_LOGGER.addingConnectionsToPool( numberToBeAdded );
5958
addConnections( numberToBeAdded );
6059
}
6160
else if ( size > maxSize ) {
6261
int numberToBeRemoved = size - maxSize;
63-
CONNECTION_INFO_LOGGER.debugf( "Removing %s Connections from the pool", numberToBeRemoved );
62+
CONNECTION_INFO_LOGGER.removingConnectionsFromPool( numberToBeRemoved );
6463
removeConnections( numberToBeRemoved );
6564
}
6665
}
@@ -85,7 +84,7 @@ private Connection releaseConnection(Connection conn) {
8584
t = ex;
8685
}
8786
closeConnection( conn, t );
88-
CONNECTION_INFO_LOGGER.debug( "Connection release failed. Closing pooled connection", t );
87+
CONNECTION_INFO_LOGGER.connectionReleaseFailedClosingPooledConnection( t );
8988
return null;
9089
}
9190

@@ -121,7 +120,7 @@ protected Connection prepareConnection(Connection conn) {
121120
t = ex;
122121
}
123122
closeConnection( conn, t );
124-
CONNECTION_INFO_LOGGER.debug( "Connection preparation failed. Closing pooled connection", t );
123+
CONNECTION_INFO_LOGGER.connectionPreparationFailedClosingPooledConnection( t );
125124
return null;
126125
}
127126

@@ -137,7 +136,7 @@ protected void closeConnection(Connection conn, Throwable t) {
137136
}
138137
finally {
139138
if ( !allConnections.remove( conn ) ) {
140-
CONNECTION_INFO_LOGGER.debug( "Connection remove failed." );
139+
CONNECTION_INFO_LOGGER.connectionRemoveFailed();
141140
}
142141
}
143142
}

hibernate-core/src/main/java/org/hibernate/engine/jdbc/env/internal/JdbcEnvironmentInitiator.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.hibernate.engine.jdbc.spi.SqlExceptionHelper;
3232
import org.hibernate.event.monitor.internal.EmptyEventMonitor;
3333
import org.hibernate.event.monitor.spi.EventMonitor;
34-
import org.hibernate.internal.log.ConnectionInfoLogger;
3534
import org.hibernate.jdbc.AbstractReturningWork;
3635
import org.hibernate.jpa.internal.MutableJpaComplianceImpl;
3736
import org.hibernate.jpa.spi.JpaCompliance;

hibernate-core/src/main/java/org/hibernate/internal/log/ConnectionInfoLogger.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static org.jboss.logging.Logger.Level.DEBUG;
2121
import static org.jboss.logging.Logger.Level.INFO;
2222
import static org.jboss.logging.Logger.Level.WARN;
23+
import static org.jboss.logging.Logger.Level.ERROR;
2324

2425
/**
2526
* @author Steve Ebersole
@@ -79,7 +80,47 @@ public interface ConnectionInfoLogger extends BasicLogger {
7980
@Message(value = "Configuring connection pool [%s]", id = 10001012)
8081
void configureConnectionPool(String type);
8182

82-
@LogMessage(level = INFO)
83+
@LogMessage(level = INFO)
8384
@Message(value = "Ignoring setting '%s' for connection provider [%s]", id = 10001013)
8485
void ignoredSetting(String setting, Class<?> provider);
86+
87+
@LogMessage(level = DEBUG)
88+
@Message(value = "Initializing connection pool with %s connections", id = 10001014)
89+
void initializingConnectionPool(int size);
90+
91+
@LogMessage(level = DEBUG)
92+
@Message(value = "Connection pool now considered primed; min-size will be maintained", id = 10001015)
93+
void connectionPoolPrimed();
94+
95+
@LogMessage(level = DEBUG)
96+
@Message(value = "Adding %s connections to the pool", id = 10001016)
97+
void addingConnectionsToPool(int numberToBeAdded);
98+
99+
@LogMessage(level = DEBUG)
100+
@Message(value = "Removing %s connections from the pool", id = 10001017)
101+
void removingConnectionsFromPool(int numberToBeRemoved);
102+
103+
@LogMessage(level = DEBUG)
104+
@Message(value = "Connection release failed, closing pooled connection", id = 10001018)
105+
void connectionReleaseFailedClosingPooledConnection(@Cause Throwable t);
106+
107+
@LogMessage(level = DEBUG)
108+
@Message(value = "Connection preparation failed, closing pooled connection", id = 10001019)
109+
void connectionPreparationFailedClosingPooledConnection(@Cause Throwable t);
110+
111+
@LogMessage(level = DEBUG)
112+
@Message(value = "Connection remove failed", id = 10001020)
113+
void connectionRemoveFailed();
114+
115+
@LogMessage(level = DEBUG)
116+
@Message(value = "No driver class specified", id = 10001021)
117+
void noDriverClassSpecified();
118+
119+
@LogMessage(level = DEBUG)
120+
@Message(value = "No connection creator factory class specified", id = 10001022)
121+
void noConnectionCreatorFactoryClassSpecified();
122+
123+
@LogMessage(level = ERROR)
124+
@Message(value = "Connection leak detected: there are %s unclosed connections", id = 10001023)
125+
void connectionLeakDetected(int allocationCount);
85126
}

0 commit comments

Comments
 (0)