Move Dialect logging to DialectFactoryImpl

As suggested by @Sanne.
This commit is contained in:
gavinking 2020-02-20 12:06:45 +01:00
parent 285b7d8696
commit 78423a8d55
2 changed files with 26 additions and 26 deletions

View File

@ -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<? extends Dialect> 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

View File

@ -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<? extends Dialect> 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() );
}
}
}