Skip to content

Commit 7d49049

Browse files
committed
introduce ConnectionProviderLogging
1 parent 0295899 commit 7d49049

File tree

7 files changed

+62
-32
lines changed

7 files changed

+62
-32
lines changed

hibernate-core/src/main/java/org/hibernate/engine/jdbc/JdbcLogging.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import static org.jboss.logging.Logger.Level.WARN;
2626

2727
/**
28-
* Sub-system logging related to JDBC interactions
28+
* Subsystem logging related to JDBC interactions
2929
*
3030
* @author Steve Ebersole
3131
*/
@@ -39,7 +39,6 @@
3939
public interface JdbcLogging extends BasicLogger {
4040
String NAME = SubSystemLogging.BASE + ".jdbc";
4141

42-
Logger JDBC_LOGGER = Logger.getLogger( NAME );
4342
JdbcLogging JDBC_MESSAGE_LOGGER = Logger.getMessageLogger( MethodHandles.lookup(), JdbcLogging.class, NAME );
4443

4544
@LogMessage(level = WARN)

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
import org.hibernate.boot.registry.selector.spi.StrategySelector;
1818
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
1919
import org.hibernate.engine.jdbc.connections.spi.ConnectionProviderConfigurationException;
20-
import org.hibernate.internal.CoreLogging;
21-
import org.hibernate.internal.CoreMessageLogger;
2220
import org.hibernate.resource.beans.container.spi.BeanContainer;
2321
import org.hibernate.resource.beans.internal.Helper;
2422
import org.hibernate.service.spi.ServiceRegistryImplementor;
@@ -43,6 +41,7 @@
4341
import static org.hibernate.cfg.JdbcSettings.USER;
4442
import static org.hibernate.cfg.SchemaToolingSettings.ENABLE_SYNONYMS;
4543
import static org.hibernate.context.spi.MultiTenancy.isMultiTenancyEnabled;
44+
import static org.hibernate.engine.jdbc.connections.internal.ConnectionProviderLogging.CONNECTION_PROVIDER_LOGGER;
4645
import static org.hibernate.internal.util.StringHelper.isBlank;
4746
import static org.hibernate.internal.util.StringHelper.nullIfBlank;
4847

@@ -55,8 +54,6 @@
5554
*/
5655
public class ConnectionProviderInitiator implements StandardServiceInitiator<ConnectionProvider> {
5756

58-
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( ConnectionProviderInitiator.class );
59-
6057
/**
6158
* Singleton access
6259
*/
@@ -100,7 +97,7 @@ public ConnectionProvider initiateService(
10097
return provider;
10198
}
10299
else if ( explicitSetting instanceof Class<?> providerClass ) {
103-
LOG.instantiatingExplicitConnectionProvider( providerClass.getName() );
100+
CONNECTION_PROVIDER_LOGGER.instantiatingExplicitConnectionProvider( providerClass.getName() );
104101
return instantiateExplicitConnectionProvider( connectionProviderClass( providerClass ), beanContainer );
105102
}
106103
else {
@@ -126,7 +123,7 @@ private static Class<? extends ConnectionProvider> connectionProviderClass(Class
126123

127124
private ConnectionProvider instantiateNamedConnectionProvider(
128125
String providerName, StrategySelector strategySelector, BeanContainer beanContainer) {
129-
LOG.instantiatingExplicitConnectionProvider( providerName );
126+
CONNECTION_PROVIDER_LOGGER.instantiatingExplicitConnectionProvider( providerName );
130127
final var providerClass = strategySelector.selectStrategyImplementor( ConnectionProvider.class, providerName );
131128
try {
132129
return instantiateExplicitConnectionProvider( providerClass, beanContainer );
@@ -181,7 +178,7 @@ else if ( configurationValues.containsKey( URL ) ) {
181178
}
182179

183180
private ConnectionProvider noAppropriateConnectionProvider() {
184-
LOG.noAppropriateConnectionProvider();
181+
CONNECTION_PROVIDER_LOGGER.noAppropriateConnectionProvider();
185182
return new UserSuppliedConnectionProviderImpl();
186183
}
187184

@@ -225,7 +222,7 @@ private static ConnectionProvider instantiateProvider(StrategySelector selector,
225222
return selector.selectStrategyImplementor( ConnectionProvider.class, strategy ).getConstructor().newInstance();
226223
}
227224
catch ( Exception e ) {
228-
LOG.providerClassNotFound(strategy);
225+
CONNECTION_PROVIDER_LOGGER.providerClassNotFound(strategy);
229226
return null;
230227
}
231228
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.engine.jdbc.connections.internal;
6+
7+
import org.hibernate.internal.log.SubSystemLogging;
8+
import org.jboss.logging.Logger;
9+
import org.jboss.logging.annotations.LogMessage;
10+
import org.jboss.logging.annotations.Message;
11+
import org.jboss.logging.annotations.MessageLogger;
12+
import org.jboss.logging.annotations.ValidIdRange;
13+
14+
import java.lang.invoke.MethodHandles;
15+
16+
import static org.jboss.logging.Logger.Level.INFO;
17+
import static org.jboss.logging.Logger.Level.WARN;
18+
19+
/**
20+
* Subsystem logging related to ConnectionProvider
21+
*
22+
* @author Steve Ebersole
23+
*/
24+
@SubSystemLogging(
25+
name = ConnectionProviderLogging.NAME,
26+
description = "Logging related to ConnectionProvider"
27+
)
28+
@MessageLogger(projectCode = "HHH")
29+
@ValidIdRange(min = 102001, max = 102100)
30+
interface ConnectionProviderLogging {
31+
String NAME = SubSystemLogging.BASE + ".connection";
32+
ConnectionProviderLogging CONNECTION_PROVIDER_LOGGER = Logger.getMessageLogger( MethodHandles.lookup(), ConnectionProviderLogging.class, NAME );
33+
34+
@LogMessage(level = WARN)
35+
@Message(id = 102001,
36+
value = "Configuration settings with for connection provider '%s' are set, but the connection provider is not on the classpath; these properties will be ignored")
37+
void providerClassNotFound(String c3p0ProviderClassName);
38+
39+
@LogMessage(level = INFO)
40+
@Message(id = 102002,
41+
value = "Instantiating explicit connection provider: %s")
42+
void instantiatingExplicitConnectionProvider(String providerClassName);
43+
44+
@LogMessage(level = WARN)
45+
@Message(id = 102003,
46+
value = "No appropriate connection provider encountered; client must supply connections")
47+
void noAppropriateConnectionProvider();
48+
49+
}

hibernate-core/src/main/java/org/hibernate/id/SequenceMismatchStrategy.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ public static SequenceMismatchStrategy interpret(@Nullable Object sequenceMismat
6060
else if ( sequenceMismatchStrategy instanceof SequenceMismatchStrategy mismatchStrategy ) {
6161
return mismatchStrategy;
6262
}
63-
else if ( sequenceMismatchStrategy instanceof String sequenceMismatchStrategyString ) {
64-
for ( SequenceMismatchStrategy value : values() ) {
65-
if ( value.name().equalsIgnoreCase( sequenceMismatchStrategyString ) ) {
63+
else if ( sequenceMismatchStrategy instanceof String mismatchStrategyName ) {
64+
for ( var value : values() ) {
65+
if ( value.name().equalsIgnoreCase( mismatchStrategyName ) ) {
6666
return value;
6767
}
6868
}

hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@
4444
@Internal
4545
public interface CoreMessageLogger extends BasicLogger {
4646

47-
@LogMessage(level = WARN)
48-
@Message(value = "Configuration settings with for connection provider '%s' are set, but the connection provider is not on the classpath; these properties will be ignored",
49-
id = 22)
50-
void providerClassNotFound(String c3p0ProviderClassName);
51-
5247
@LogMessage(level = WARN)
5348
@Message(value = "I/O reported cached file could not be found: [%s]: %s", id = 23)
5449
void cachedFileNotFound(String path, FileNotFoundException error);
@@ -108,10 +103,6 @@ void expectedType(String name,
108103
@Message(value = "IllegalArgumentException in class: %s, setter method of property: %s", id = 123)
109104
void illegalPropertySetterArgument(String name, String propertyName);
110105

111-
@LogMessage(level = INFO)
112-
@Message(value = "Instantiating explicit connection provider: %s", id = 130)
113-
void instantiatingExplicitConnectionProvider(String providerClassName);
114-
115106
@LogMessage(level = INFO)
116107
@Message(value = "java.sql.Types mapped the same code [%s] multiple times; was [%s]; now [%s]", id = 141)
117108
void JavaSqlTypesMappedSameCodeMultipleTimes(int code, String old, String name);
@@ -130,11 +121,6 @@ void missingArguments(
130121
@Message(value = "Narrowing proxy to %s - this operation breaks ==", id = 179)
131122
void narrowingProxy(Class<?> concreteProxyClass);
132123

133-
@LogMessage(level = WARN)
134-
@Message(value = "No appropriate connection provider encountered, assuming application will be supplying connections",
135-
id = 181)
136-
void noAppropriateConnectionProvider();
137-
138124
@LogMessage(level = INFO)
139125
@Message(value = "No default (no-argument) constructor for class [%s] (class must be instantiated by Interceptor)",
140126
id = 182)

hibernate-core/src/main/java/org/hibernate/resource/transaction/backend/jdbc/internal/JdbcResourceLocalTransactionCoordinatorImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.hibernate.resource.transaction.spi.TransactionStatus;
2525

2626
import static java.util.Collections.emptyList;
27-
import static org.hibernate.engine.jdbc.JdbcLogging.JDBC_LOGGER;
2827
import static org.hibernate.engine.jdbc.JdbcLogging.JDBC_MESSAGE_LOGGER;
2928

3029
/**
@@ -300,7 +299,7 @@ public TransactionStatus getStatus() {
300299
@Override
301300
public void markRollbackOnly() {
302301
if ( getStatus() != TransactionStatus.ROLLED_BACK ) {
303-
if ( JDBC_LOGGER.isTraceEnabled() ) {
302+
if ( JDBC_MESSAGE_LOGGER.isTraceEnabled() ) {
304303
JDBC_MESSAGE_LOGGER.jdbcTransactionMarkedForRollbackOnly(
305304
new Exception( "exception just for purpose of providing stack trace" ) );
306305
}

hibernate-core/src/test/java/org/hibernate/orm/test/id/hhh12973/PostgreSQLSequenceGeneratorWithSerialTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import static org.hibernate.id.enhanced.SequenceGeneratorLogger.SEQUENCE_GENERATOR_MESSAGE_LOGGER;
3737
import static org.junit.jupiter.api.Assertions.assertEquals;
3838
import static org.junit.jupiter.api.Assertions.assertFalse;
39-
import static org.junit.jupiter.api.Assertions.assertTrue;
4039

4140
/**
4241
* @author Vlad Mihalcea
@@ -48,7 +47,7 @@ public class PostgreSQLSequenceGeneratorWithSerialTest extends EntityManagerFact
4847
@Rule
4948
public LoggerInspectionRule logInspection = new LoggerInspectionRule( SEQUENCE_GENERATOR_MESSAGE_LOGGER );
5049

51-
private final Triggerable triggerable = logInspection.watchForLogMessages( "HHH090202:" );
50+
private final Triggerable triggerable = logInspection.watchForLogMessages( "HHH090203:" );
5251

5352
@Override
5453
protected Class<?>[] getAnnotatedClasses() {
@@ -105,7 +104,8 @@ protected boolean exportSchema() {
105104

106105
@Override
107106
protected void entityManagerFactoryBuilt(EntityManagerFactory factory) {
108-
assertTrue( triggerable.wasTriggered() );
107+
// this message is logged at trace level
108+
assertFalse( triggerable.wasTriggered() );
109109
}
110110

111111
@Test

0 commit comments

Comments
 (0)