HHH-16507 Use subsystem logger instead of hard-coded "SQL dialect"

Signed-off-by: Sven Strickroth <email@cs-ware.de>
This commit is contained in:
Sven Strickroth 2023-04-24 13:54:19 +02:00 committed by Steve Ebersole
parent 7cf31fdd44
commit 2e303c4b0d
3 changed files with 45 additions and 4 deletions

View File

@ -0,0 +1,39 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.dialect;
import org.hibernate.internal.log.SubSystemLogging;
import org.jboss.logging.Logger;
import org.jboss.logging.annotations.LogMessage;
import org.jboss.logging.annotations.Message;
import org.jboss.logging.annotations.MessageLogger;
import org.jboss.logging.annotations.ValidIdRange;
import static org.jboss.logging.Logger.Level.INFO;
/**
* Logging related to Hibernate dialects
*/
@SubSystemLogging(
name = DialectLogging.LOGGER_NAME,
description = "Logging related to the dialects of SQL implemented by particular RDBMS"
)
@ValidIdRange( min = 35001, max = 36000)
@MessageLogger(projectCode = "HHH")
public interface DialectLogging {
String LOGGER_NAME = SubSystemLogging.BASE + ".dialect";
Logger DIALECT_LOGGER = Logger.getLogger(LOGGER_NAME);
DialectLogging DIALECT_MESSAGE_LOGGER = Logger.getMessageLogger(DialectLogging.class, LOGGER_NAME);
boolean DEBUG_ENABLED = DIALECT_LOGGER.isDebugEnabled();
boolean TRACE_ENABLED = DIALECT_LOGGER.isTraceEnabled();
@LogMessage(level = INFO)
@Message(value = "Using dialect: %s", id = 35001)
void usingDialect(Dialect dialect);
}

View File

@ -15,12 +15,11 @@ import org.hibernate.boot.registry.selector.spi.StrategySelectionException;
import org.hibernate.boot.registry.selector.spi.StrategySelector;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.DialectLogging;
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.internal.util.StringHelper;
import org.hibernate.service.spi.ServiceRegistryAwareService;
import org.hibernate.service.spi.ServiceRegistryImplementor;
@ -33,7 +32,6 @@ import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER;
* @author Steve Ebersole
*/
public class DialectFactoryImpl implements DialectFactory, ServiceRegistryAwareService {
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( "SQL dialect" );
private static final Set<String> LEGACY_DIALECTS = Set.of(
"org.hibernate.community.dialect.DB297Dialect",
"org.hibernate.community.dialect.DB2390Dialect",
@ -92,7 +90,7 @@ public class DialectFactoryImpl implements DialectFactory, ServiceRegistryAwareS
}
private static void logSelectedDialect(Dialect dialect) {
LOG.usingDialect( dialect );
DialectLogging.DIALECT_MESSAGE_LOGGER.usingDialect( dialect );
Class<? extends Dialect> dialectClass = dialect.getClass();
if ( dialectClass.isAnnotationPresent( Deprecated.class ) ) {

View File

@ -1359,8 +1359,12 @@ public interface CoreMessageLogger extends BasicLogger {
@Message(value = "Using default transaction strategy (direct JDBC transactions)", id = 399)
void usingDefaultTransactionStrategy();
/**
* @deprecated Use {@link org.hibernate.dialect.DialectLogging#usingDialect} instead
*/
@LogMessage(level = INFO)
@Message(value = "Using dialect: %s", id = 400)
@Deprecated
void usingDialect(Dialect dialect);
@LogMessage(level = ERROR)