Skip to content

Commit 3cb68f5

Browse files
committed
introduce ConnectionProviderLogging
1 parent 2a05a9d commit 3cb68f5

File tree

8 files changed

+71
-43
lines changed

8 files changed

+71
-43
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: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
import org.checkerframework.checker.nullness.qual.Nullable;
1010

11+
import static org.hibernate.cfg.MappingSettings.SEQUENCE_INCREMENT_SIZE_MISMATCH_STRATEGY;
12+
1113
/**
1214
* Describes the strategy for handling the mismatch between a database sequence configuration and
1315
* the one defined by the entity mapping.
@@ -47,29 +49,27 @@ public enum SequenceMismatchStrategy {
4749
* <p>
4850
* Valid values are either a {@link SequenceMismatchStrategy} object or its String representation.
4951
* <p>
50-
* For string values, the matching is case insensitive, so you can use either {@code FIX} or {@code fix}.
52+
* For string values, the matching is case-insensitive, so you can use either {@code FIX} or {@code fix}.
5153
*
52-
* @param sequenceMismatchStrategy configured {@link SequenceMismatchStrategy} representation
54+
* @param setting configured {@link SequenceMismatchStrategy} representation
5355
*
5456
* @return associated {@link SequenceMismatchStrategy} object
5557
*/
56-
public static SequenceMismatchStrategy interpret(@Nullable Object sequenceMismatchStrategy) {
57-
if ( sequenceMismatchStrategy == null ) {
58+
public static SequenceMismatchStrategy interpret(@Nullable Object setting) {
59+
if ( setting == null ) {
5860
return EXCEPTION;
5961
}
60-
else if ( sequenceMismatchStrategy instanceof SequenceMismatchStrategy mismatchStrategy ) {
62+
else if ( setting instanceof SequenceMismatchStrategy mismatchStrategy ) {
6163
return mismatchStrategy;
6264
}
63-
else if ( sequenceMismatchStrategy instanceof String sequenceMismatchStrategyString ) {
64-
for ( SequenceMismatchStrategy value : values() ) {
65-
if ( value.name().equalsIgnoreCase( sequenceMismatchStrategyString ) ) {
65+
else if ( setting instanceof String mismatchStrategyName ) {
66+
for ( var value : values() ) {
67+
if ( value.name().equalsIgnoreCase( mismatchStrategyName ) ) {
6668
return value;
6769
}
6870
}
6971
}
70-
throw new HibernateException(
71-
"Unrecognized sequence.increment_size_mismatch_strategy value : [" + sequenceMismatchStrategy
72-
+ "]. Supported values include [log], [exception], and [fix]."
73-
);
72+
throw new HibernateException( "Setting '" + SEQUENCE_INCREMENT_SIZE_MISMATCH_STRATEGY
73+
+ "' should be one of [LOG, EXCEPTION, FIX, NONE] but was [" + setting + "]" );
7474
}
7575
}

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

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.hibernate.testing.util.ExceptionUtil;
1313
import org.junit.jupiter.api.Test;
1414

15-
import static org.junit.jupiter.api.Assertions.assertEquals;
1615
import static org.junit.jupiter.api.Assertions.assertTrue;
1716
import static org.junit.jupiter.api.Assertions.fail;
1817

@@ -33,7 +32,6 @@ public void test() {
3332
catch (Exception e) {
3433
Throwable rootCause = ExceptionUtil.rootCause( e );
3534
assertTrue( rootCause instanceof HibernateException );
36-
assertEquals( "Unrecognized sequence.increment_size_mismatch_strategy value : [acme]. Supported values include [log], [exception], and [fix].", rootCause.getMessage() );
3735
}
3836
}
3937
}

0 commit comments

Comments
 (0)