Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.hibernate.engine.jdbc.connections.spi.ConnectionProviderConfigurationException;
import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo;
import org.hibernate.exception.JDBCConnectionException;
import org.hibernate.internal.log.ConnectionInfoLogger;
import org.hibernate.service.UnknownUnwrapTypeException;
import org.hibernate.service.spi.Configurable;
import org.hibernate.service.spi.Stoppable;
Expand All @@ -45,6 +44,7 @@
import static org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl.getSchema;
import static org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl.hasCatalog;
import static org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl.hasSchema;
import static org.hibernate.internal.log.ConnectionInfoLogger.CONNECTION_INFO_LOGGER;

/**
* {@link ConnectionProvider} based on Agroal connection pool.
Expand Down Expand Up @@ -105,7 +105,7 @@ private static <T> void copyProperty(Map<String, Object> properties, String key,

@Override
public void configure(Map<String, Object> properties) throws HibernateException {
ConnectionInfoLogger.INSTANCE.configureConnectionPool( "Agroal" );
CONNECTION_INFO_LOGGER.configureConnectionPool( "Agroal" );
try {
final var config = toStringValuedProperties( properties );
if ( !properties.containsKey( AgroalSettings.AGROAL_MAX_SIZE ) ) {
Expand All @@ -130,7 +130,7 @@ public void configure(Map<String, Object> properties) throws HibernateException
agroalDataSource = AgroalDataSource.from( agroalProperties );
}
catch ( Exception e ) {
ConnectionInfoLogger.INSTANCE.unableToInstantiateConnectionPool( e );
CONNECTION_INFO_LOGGER.unableToInstantiateConnectionPool( e );
throw new ConnectionProviderConfigurationException(
"Could not configure Agroal: " + e.getMessage(), e );
}
Expand Down Expand Up @@ -225,7 +225,7 @@ else if ( unwrapType.isAssignableFrom( AgroalDataSource.class ) ) {
@Override
public void stop() {
if ( agroalDataSource != null ) {
ConnectionInfoLogger.INSTANCE.cleaningUpConnectionPool(
CONNECTION_INFO_LOGGER.cleaningUpConnectionPool(
agroalDataSource.getConfiguration()
.connectionPoolConfiguration()
.connectionFactoryConfiguration()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.hibernate.engine.jdbc.connections.spi.ConnectionProviderConfigurationException;
import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo;
import org.hibernate.exception.JDBCConnectionException;
import org.hibernate.internal.log.ConnectionInfoLogger;
import org.hibernate.service.UnknownUnwrapTypeException;
import org.hibernate.service.spi.Configurable;
import org.hibernate.service.spi.ServiceRegistryAwareService;
Expand Down Expand Up @@ -51,6 +50,7 @@
import static org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl.getSchema;
import static org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl.hasCatalog;
import static org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl.hasSchema;
import static org.hibernate.internal.log.ConnectionInfoLogger.CONNECTION_INFO_LOGGER;
import static org.hibernate.internal.util.config.ConfigurationHelper.getBoolean;
import static org.hibernate.internal.util.config.ConfigurationHelper.getInteger;

Expand Down Expand Up @@ -135,7 +135,7 @@ else if ( unwrapType.isAssignableFrom( DataSource.class ) ) {

@Override
public void configure(Map<String, Object> properties) {
ConnectionInfoLogger.INSTANCE.configureConnectionPool( "c3p0" );
CONNECTION_INFO_LOGGER.configureConnectionPool( "c3p0" );

final String jdbcDriverClass = extractSetting(
properties,
Expand Down Expand Up @@ -205,15 +205,15 @@ private DataSource createDataSource(String jdbcUrl, Properties connectionProps,
return pooledDataSource( unpooledDataSource( jdbcUrl, connectionProps ), poolProperties );
}
catch (Exception e) {
ConnectionInfoLogger.INSTANCE.unableToInstantiateConnectionPool( e );
CONNECTION_INFO_LOGGER.unableToInstantiateConnectionPool( e );
throw new ConnectionProviderConfigurationException(
"Could not configure c3p0: " + e.getMessage(), e );
}
}

private void loadDriverClass(String jdbcDriverClass) {
if ( jdbcDriverClass == null ) {
ConnectionInfoLogger.INSTANCE.jdbcDriverNotSpecified();
CONNECTION_INFO_LOGGER.jdbcDriverNotSpecified();
}
else {
try {
Expand Down Expand Up @@ -313,12 +313,12 @@ private void warnPropertyConflict(String hibernateStyle, String c3p0Style) {

@Override
public void stop() {
ConnectionInfoLogger.INSTANCE.cleaningUpConnectionPool( C3P0_CONFIG_PREFIX );
CONNECTION_INFO_LOGGER.cleaningUpConnectionPool( C3P0_CONFIG_PREFIX );
try {
DataSources.destroy( dataSource );
}
catch (SQLException sqle) {
ConnectionInfoLogger.INSTANCE.unableToDestroyConnectionPool( sqle );
CONNECTION_INFO_LOGGER.unableToDestroyConnectionPool( sqle );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public interface ScannerLogger extends BasicLogger {
void multipleScannerFactoriesAvailable(String scannerClassName);

@LogMessage(level = Logger.Level.DEBUG)
@Message(id = 60002, value = "No ScannerFactory available; to enable scanning add 'hibernate-scan-jandex' dependency or supply a custom ScannerFactory")
@Message(id = 60002, value = "No ScannerFactory available (to enable scanning add 'hibernate-scan-jandex' dependency or supply a custom ScannerFactory)")
void noScannerFactoryAvailable();

@LogMessage(level = Logger.Level.DEBUG)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
* The strategy is any interface that has multiple, (possibly short) named implementations.
* <p>
* {@code StrategySelector} manages resolution of particular implementation by (possibly short) name via the
* {@link #selectStrategyImplementor} method, which is the main contract here. As indicated in the docs of that
* method the given name might be either a short registered name or the implementation FQN. As an example, consider
* {@link #selectStrategyImplementor} method, which is the main contract here. As indicated in the Javadoc of that
* method, the given name might be either a short registered name or the implementation FQN. As an example, consider
* resolving the {@link org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder} implementation to use.
* To use the JDBC-based {@code TransactionCoordinatorBuilder} the passed name might be either {@code "jdbc"} or
* {@code "org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl"}.
Expand All @@ -30,7 +30,7 @@
* <p>
* The service also exposes a general typing API via {@link #resolveStrategy} and {@link #resolveDefaultableStrategy}
* which accept implementation references rather than implementation names, allowing for a multitude of interpretations
* of said "implementation reference". See the docs for {@link #resolveDefaultableStrategy} for details.
* of said "implementation reference". See the docs for {@link #resolveDefaultableStrategy} for details.
*
* @author Steve Ebersole
*/
Expand Down Expand Up @@ -121,9 +121,9 @@ public interface StrategySelector extends Service, Stoppable {
<T> T resolveStrategy(Class<T> strategy, Object strategyReference, T defaultValue, StrategyCreator<T> creator);

/**
* Retrieve all of the registered implementors of the given strategy. Useful
* to allow defaulting the choice to the single registered implementor when
* only one is registered
* Retrieve all the registered implementors of the given strategy.
* Useful to allow defaulting the choice to the single registered
* implementor when only one is registered
*
* @return The implementors. Should never return {@code null}
*/
Expand All @@ -144,8 +144,9 @@ public interface StrategySelector extends Service, Stoppable {
<T> void registerStrategyImplementor(Class<T> strategy, String name, Class<? extends T> implementation);

/**
* Un-registers a named implementor of a particular strategy contract. Un-registers all named registrations
* for the given strategy contract naming the given class.
* Unregisters a named implementor of a particular strategy contract.
* Unregisters all named registrations for the given strategy contract
* naming the given class.
*
* @param strategy The strategy contract.
* @param implementation The implementation class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected RegionFactory resolveRegionFactory(Map<String,Object> configurationVal
final var implementors = selector.getRegisteredStrategyImplementors( RegionFactory.class );

if ( setting == null && implementors.size() != 1 ) {
// if either is explicitly defined as TRUE we need a RegionFactory
// if either is explicitly defined as TRUE, we need a RegionFactory
if ( useSecondLevelCache == TRUE || useQueryCache == TRUE ) {
throw new CacheException( "Caching was explicitly requested, but no RegionFactory was defined and there is not a single registered RegionFactory" );
}
Expand All @@ -104,17 +104,21 @@ protected RegionFactory resolveRegionFactory(Map<String,Object> configurationVal
return fallback;
}

if ( implementors.size() == 1 ) {
final var registeredFactory = selector.resolveStrategy( RegionFactory.class, implementors.iterator().next() );
configurationValues.put( CACHE_REGION_FACTORY, registeredFactory );
configurationValues.put( USE_SECOND_LEVEL_CACHE, "true" );
return registeredFactory;
}
else {
L2CACHE_LOGGER.cannotDefaultRegionFactory( implementors.size() );
switch ( implementors.size() ) {
case 1:
final var registeredFactory =
selector.resolveStrategy( RegionFactory.class,
implementors.iterator().next() );
configurationValues.put( CACHE_REGION_FACTORY, registeredFactory );
configurationValues.put( USE_SECOND_LEVEL_CACHE, "true" );
return registeredFactory;
case 0:
L2CACHE_LOGGER.noDefaultRegionFactory();
return NoCachingRegionFactory.INSTANCE;
default:
L2CACHE_LOGGER.cannotDefaultRegionFactory( implementors.size() );
return NoCachingRegionFactory.INSTANCE;
}

return NoCachingRegionFactory.INSTANCE;
}

protected RegionFactory getFallback(Map<?,?> configurationValues, ServiceRegistryImplementor registry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.lang.invoke.MethodHandles;

import static org.hibernate.cfg.CacheSettings.CACHE_REGION_FACTORY;
import static org.jboss.logging.Logger.Level.DEBUG;
import static org.jboss.logging.Logger.Level.INFO;
import static org.jboss.logging.Logger.Level.TRACE;
Expand Down Expand Up @@ -237,10 +238,18 @@ public interface SecondLevelCacheLogger extends BasicLogger {
)
void noRegionFactory();

@LogMessage(level = INFO)
@LogMessage(level = DEBUG)
@Message(
value = "Cannot default RegionFactory based on registered strategies as %s RegionFactory strategies were registered",
value = "Cannot default RegionFactory based on registered strategies as %s RegionFactory strategies were registered"
+ " (explicitly set '" + CACHE_REGION_FACTORY + "')",
id = NAMESPACE + 30
)
void cannotDefaultRegionFactory(int size);

@LogMessage(level = DEBUG)
@Message(
value = "Cannot default RegionFactory since no RegionFactory strategies were registered",
id = NAMESPACE + 31
)
void noDefaultRegionFactory();
}
17 changes: 6 additions & 11 deletions hibernate-core/src/main/java/org/hibernate/cfg/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@
package org.hibernate.cfg;

import java.io.IOException;
import java.lang.invoke.MethodHandles;
import java.util.Properties;

import org.hibernate.HibernateException;
import org.hibernate.Internal;
import org.hibernate.Version;
import org.hibernate.internal.CoreMessageLogger;

import org.jboss.logging.Logger;

import static org.hibernate.internal.CoreMessageLogger.CORE_LOGGER;
import static org.hibernate.internal.util.ConfigHelper.getResourceAsStream;
import static org.hibernate.internal.util.config.ConfigurationHelper.maskOut;

Expand Down Expand Up @@ -132,8 +129,6 @@
@Internal
public final class Environment implements AvailableSettings {

private static final CoreMessageLogger LOG = Logger.getMessageLogger( MethodHandles.lookup(), CoreMessageLogger.class, Environment.class.getName());

private static final Properties GLOBAL_PROPERTIES;

static {
Expand All @@ -145,19 +140,19 @@ public final class Environment implements AvailableSettings {
try (var stream = getResourceAsStream("/hibernate.properties")) {
try {
GLOBAL_PROPERTIES.load(stream);
LOG.propertiesLoaded( maskOut( GLOBAL_PROPERTIES,
CORE_LOGGER.propertiesLoaded( maskOut( GLOBAL_PROPERTIES,
PASS, JAKARTA_JDBC_PASSWORD, JPA_JDBC_PASSWORD ) );
}
catch (Exception e) {
LOG.unableToLoadProperties();
CORE_LOGGER.unableToLoadProperties();
}
}
catch (IOException ioe) {
LOG.unableToCloseStreamError( ioe );
CORE_LOGGER.unableToCloseStreamError( ioe );
}
}
catch (HibernateException he) {
LOG.propertiesNotFound();
CORE_LOGGER.propertiesNotFound();
}

try {
Expand All @@ -170,7 +165,7 @@ public final class Environment implements AvailableSettings {
}
}
catch (SecurityException se) {
LOG.unableToCopySystemProperties();
CORE_LOGGER.unableToCopySystemProperties();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
import org.hibernate.engine.jdbc.connections.spi.DatabaseConnectionInfo;
import org.hibernate.engine.jdbc.env.spi.ExtractedDatabaseMetaData;
import org.hibernate.engine.jndi.spi.JndiService;
import org.hibernate.internal.log.ConnectionInfoLogger;
import org.hibernate.service.UnknownUnwrapTypeException;
import org.hibernate.service.spi.Configurable;
import org.hibernate.service.spi.InjectService;
import org.hibernate.service.spi.Stoppable;

import static org.hibernate.cfg.JdbcSettings.DATASOURCE;
import static org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.toIsolationNiceName;
import static org.hibernate.internal.log.ConnectionInfoLogger.CONNECTION_INFO_LOGGER;

/**
* A {@link ConnectionProvider} that manages connections from an underlying {@link DataSource}.
Expand Down Expand Up @@ -110,11 +110,11 @@ else if ( dataSourceSetting instanceof String jndiName ) {
}

if ( configuration.containsKey( JdbcSettings.AUTOCOMMIT ) ) {
ConnectionInfoLogger.INSTANCE.ignoredSetting( JdbcSettings.AUTOCOMMIT,
CONNECTION_INFO_LOGGER.ignoredSetting( JdbcSettings.AUTOCOMMIT,
DataSourceConnectionProvider.class );
}
if ( configuration.containsKey( JdbcSettings.ISOLATION ) ) {
ConnectionInfoLogger.INSTANCE.ignoredSetting( JdbcSettings.ISOLATION,
CONNECTION_INFO_LOGGER.ignoredSetting( JdbcSettings.ISOLATION,
DataSourceConnectionProvider.class );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.hibernate.service.spi.ServiceRegistryAwareService;
import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.service.spi.Stoppable;
import org.hibernate.internal.log.ConnectionInfoLogger;

import static org.hibernate.cfg.JdbcSettings.AUTOCOMMIT;
import static org.hibernate.cfg.JdbcSettings.DRIVER;
Expand All @@ -43,6 +42,7 @@
import static org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl.getSchema;
import static org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl.hasCatalog;
import static org.hibernate.engine.jdbc.connections.internal.DatabaseConnectionInfoImpl.hasSchema;
import static org.hibernate.internal.log.ConnectionInfoLogger.CONNECTION_INFO_LOGGER;
import static org.hibernate.internal.util.config.ConfigurationHelper.getBoolean;
import static org.hibernate.internal.util.config.ConfigurationHelper.getInt;
import static org.hibernate.internal.util.config.ConfigurationHelper.getLong;
Expand Down Expand Up @@ -82,7 +82,7 @@ public void injectServices(ServiceRegistryImplementor serviceRegistry) {

@Override
public void configure(Map<String, Object> configurationValues) {
ConnectionInfoLogger.INSTANCE.usingHibernateBuiltInConnectionPool();
CONNECTION_INFO_LOGGER.usingHibernateBuiltInConnectionPool();
final PooledConnections pool = buildPool( configurationValues, serviceRegistry );
final long validationInterval = getLong( VALIDATION_INTERVAL, configurationValues, 30 );
state = new PoolState( pool, validationInterval );
Expand Down Expand Up @@ -181,7 +181,7 @@ private static Driver loadDriver(String driverClassName, ServiceRegistry service
}

private static void logAvailableDrivers() {
ConnectionInfoLogger.INSTANCE.jdbcDriverNotSpecified();
CONNECTION_INFO_LOGGER.jdbcDriverNotSpecified();
final var list = new StringBuilder();
DriverManager.drivers()
.forEach( driver -> {
Expand All @@ -190,7 +190,7 @@ private static void logAvailableDrivers() {
}
list.append( driver.getClass().getName() );
} );
ConnectionInfoLogger.INSTANCE.availableJdbcDrivers( list.toString() );
CONNECTION_INFO_LOGGER.availableJdbcDrivers( list.toString() );
}

private static String jdbcUrl(Map<String, Object> configuration) {
Expand Down Expand Up @@ -219,7 +219,7 @@ else if ( connectionCreatorFactory != null ) {

private static Driver loadDriverIfPossible(String driverClassName, ServiceRegistry serviceRegistry) {
if ( driverClassName == null ) {
ConnectionInfoLogger.INSTANCE.debug( "No driver class specified" );
CONNECTION_INFO_LOGGER.noDriverClassSpecified();
return null;
}
else if ( serviceRegistry != null ) {
Expand All @@ -246,7 +246,7 @@ else if ( serviceRegistry != null ) {
private static ConnectionCreatorFactory loadConnectionCreatorFactory(
String connectionCreatorFactoryClassName, ServiceRegistry serviceRegistry) {
if ( connectionCreatorFactoryClassName == null ) {
ConnectionInfoLogger.INSTANCE.debug( "No connection creator factory class specified" );
CONNECTION_INFO_LOGGER.noConnectionCreatorFactoryClassSpecified();
return null;
}
else if ( serviceRegistry != null ) {
Expand Down Expand Up @@ -339,7 +339,7 @@ protected int getOpenConnections() {
protected void validateConnectionsReturned() {
final int allocationCount = getOpenConnections();
if ( allocationCount != 0 ) {
ConnectionInfoLogger.INSTANCE.error( "Connection leak detected: there are " + allocationCount + " unclosed connections");
CONNECTION_INFO_LOGGER.connectionLeakDetected( allocationCount );
}
}

Expand Down
Loading
Loading