From 78423a8d55c677097f3cbc3c593cd9db7988ea72 Mon Sep 17 00:00:00 2001 From: gavinking Date: Thu, 20 Feb 2020 12:06:45 +0100 Subject: [PATCH] Move Dialect logging to DialectFactoryImpl As suggested by @Sanne. --- .../java/org/hibernate/dialect/Dialect.java | 21 ------------- .../dialect/internal/DialectFactoryImpl.java | 31 ++++++++++++++++--- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java index 60b3c1c026..87f6618248 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java @@ -33,8 +33,6 @@ import org.hibernate.exception.spi.SQLExceptionConverter; import org.hibernate.exception.spi.ViolatedConstraintNameExtracter; import org.hibernate.id.IdentityGenerator; import org.hibernate.id.enhanced.SequenceStyleGenerator; -import org.hibernate.internal.CoreLogging; -import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.ArrayHelper; @@ -89,7 +87,6 @@ import java.time.temporal.TemporalAccessor; import java.util.Date; import java.util.*; -import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER; import static org.hibernate.type.descriptor.DateTimeUtils.*; /** @@ -107,7 +104,6 @@ import static org.hibernate.type.descriptor.DateTimeUtils.*; * @author Gavin King, David Channon */ public abstract class Dialect implements ConversionContext { - private static final CoreMessageLogger LOG = CoreLogging.messageLogger( Dialect.class ); /** * Defines a default batch size constant @@ -143,7 +139,6 @@ public abstract class Dialect implements ConversionContext { // constructors and factory methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ protected Dialect() { - logSelectedDialect(); registerColumnType( Types.BIT, 1, "bit" ); registerColumnType( Types.BIT, "bit($l)" ); @@ -232,22 +227,6 @@ public abstract class Dialect implements ConversionContext { defaultSizeStrategy = new DefaultSizeStrategyImpl(); } - private void logSelectedDialect() { - LOG.usingDialect( this ); - - Class dialect = getClass(); - if ( dialect.isAnnotationPresent(Deprecated.class) ) { - Class superDialect = dialect.getSuperclass(); - if ( !superDialect.isAnnotationPresent(Deprecated.class) - && !superDialect.equals(Dialect.class) ) { - DEPRECATION_LOGGER.deprecatedDialect( dialect.getSimpleName(), superDialect.getName() ); - } - else { - DEPRECATION_LOGGER.deprecatedDialect( dialect.getSimpleName() ); - } - } - } - /** * Useful conversion for databases which represent the * precision of a float(p) using p expressed in decimal diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/dialect/internal/DialectFactoryImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/dialect/internal/DialectFactoryImpl.java index c773974fd5..a9738fe707 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/dialect/internal/DialectFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/dialect/internal/DialectFactoryImpl.java @@ -19,15 +19,21 @@ import org.hibernate.engine.jdbc.dialect.spi.DialectFactory; import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfo; import org.hibernate.engine.jdbc.dialect.spi.DialectResolutionInfoSource; import org.hibernate.engine.jdbc.dialect.spi.DialectResolver; +import org.hibernate.internal.CoreLogging; +import org.hibernate.internal.CoreMessageLogger; import org.hibernate.service.spi.ServiceRegistryAwareService; import org.hibernate.service.spi.ServiceRegistryImplementor; +import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER; + /** * Standard implementation of the {@link DialectFactory} service. * * @author Steve Ebersole */ public class DialectFactoryImpl implements DialectFactory, ServiceRegistryAwareService { + private static final CoreMessageLogger LOG = CoreLogging.messageLogger( "SQL dialect" ); + private StrategySelector strategySelector; private DialectResolver dialectResolver; @@ -49,11 +55,26 @@ public class DialectFactoryImpl implements DialectFactory, ServiceRegistryAwareS @Override public Dialect buildDialect(Map configValues, DialectResolutionInfoSource resolutionInfoSource) throws HibernateException { final Object dialectReference = configValues.get( AvailableSettings.DIALECT ); - if ( !isEmpty( dialectReference ) ) { - return constructDialect( dialectReference, resolutionInfoSource ); - } - else { - return determineDialect( resolutionInfoSource ); + Dialect dialect = !isEmpty(dialectReference) ? + constructDialect(dialectReference, resolutionInfoSource) : + determineDialect(resolutionInfoSource); + logSelectedDialect( dialect ); + return dialect; + } + + private static void logSelectedDialect(Dialect dialect) { + LOG.usingDialect( dialect ); + + Class dialectClass = dialect.getClass(); + if ( dialectClass.isAnnotationPresent(Deprecated.class) ) { + Class superDialectClass = dialectClass.getSuperclass(); + if ( !superDialectClass.isAnnotationPresent(Deprecated.class) + && !superDialectClass.equals(Dialect.class) ) { + DEPRECATION_LOGGER.deprecatedDialect( dialectClass.getSimpleName(), superDialectClass.getName() ); + } + else { + DEPRECATION_LOGGER.deprecatedDialect( dialectClass.getSimpleName() ); + } } }