HHH-12649 Move the created cache warning to org.hibernate.cache.spi.SecondLevelCacheLogger

This commit is contained in:
Yoann Rodière 2018-07-03 16:53:29 +02:00 committed by Guillaume Smet
parent 033203abc7
commit 2649e1372c
9 changed files with 34 additions and 69 deletions

View File

@ -72,4 +72,14 @@ public interface SecondLevelCacheLogger extends BasicLogger {
)
void softLockedCacheExpired(String regionName, Object key);
@LogMessage(level = WARN)
@Message(
value = "Missing cache[%1$s] was created on-the-fly." +
" The created cache will use a provider-specific default configuration:" +
" make sure you defined one." +
" You can disable this warning by setting '%2$s' to '%3$s'.",
id = NAMESPACE + 6
)
void missingCacheCreated(String regionName, String configurationPropertyToDisableKey, String configurationPropertyToDisableValue);
}

View File

@ -36,6 +36,10 @@ public enum MissingCacheStrategy {
this.externalRepresentation = externalRepresentation;
}
public String getExternalRepresentation() {
return externalRepresentation;
}
public static MissingCacheStrategy interpretSetting(Object value) {
if ( value instanceof MissingCacheStrategy ) {
return (MissingCacheStrategy) value;

View File

@ -113,15 +113,4 @@ public interface EhCacheMessageLogger extends CoreMessageLogger {
)
void softLockedCacheExpired(String regionName, Object key, String lock);
@LogMessage(level = WARN)
@Message(
value = "Missing cache[%s] was created on-the-fly." +
" The created cache will use the <defaultCache> configuration: " +
" make sure to configure it." +
" You can disable this warning by setting '" + ConfigSettings.MISSING_CACHE_STRATEGY +
"' to 'create'.",
id = 20009
)
void missingCacheCreated(String regionName);
}

View File

@ -24,14 +24,13 @@ import org.hibernate.cache.ehcache.ConfigSettings;
import org.hibernate.cache.ehcache.MissingCacheStrategy;
import org.hibernate.cache.internal.DefaultCacheKeysFactory;
import org.hibernate.cache.spi.CacheKeysFactory;
import org.hibernate.cache.spi.SecondLevelCacheLogger;
import org.hibernate.cache.spi.support.DomainDataStorageAccess;
import org.hibernate.cache.spi.support.RegionFactoryTemplate;
import org.hibernate.cache.spi.support.RegionNameQualifier;
import org.hibernate.cache.spi.support.StorageAccess;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.jboss.logging.Logger;
import static org.hibernate.cache.ehcache.ConfigSettings.EHCACHE_CONFIGURATION_RESOURCE_NAME;
import static org.hibernate.cache.ehcache.internal.HibernateEhcacheUtils.setCacheManagerNameIfNeeded;
@ -107,7 +106,10 @@ public class EhcacheRegionFactory extends RegionFactoryTemplate {
protected Cache createCache(String regionName) {
switch ( missingCacheStrategy ) {
case CREATE_WARN:
LOG.missingCacheCreated( regionName );
SecondLevelCacheLogger.INSTANCE.missingCacheCreated(
regionName,
ConfigSettings.MISSING_CACHE_STRATEGY, MissingCacheStrategy.CREATE.getExternalRepresentation()
);
cacheManager.addCache( regionName );
return cacheManager.getCache( regionName );
case CREATE:

View File

@ -13,7 +13,7 @@ import java.util.function.Consumer;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.ehcache.ConfigSettings;
import org.hibernate.cache.ehcache.internal.EhCacheMessageLogger;
import org.hibernate.cache.spi.SecondLevelCacheLogger;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.service.spi.ServiceException;
@ -34,7 +34,7 @@ import static org.junit.Assert.fail;
public class MissingCacheStrategyTest extends BaseUnitTestCase {
@Rule
public LoggerInspectionRule logInspection = new LoggerInspectionRule( EhCacheMessageLogger.INSTANCE );
public LoggerInspectionRule logInspection = new LoggerInspectionRule( SecondLevelCacheLogger.INSTANCE );
@Test
public void testMissingCacheStrategyDefault() {
@ -103,7 +103,7 @@ public class MissingCacheStrategyTest extends BaseUnitTestCase {
triggerables.put(
regionName,
logInspection.watchForLogMessages(
"HHH020009: Missing cache[" + TestHelper.prefix( regionName ) + "] was created on-the-fly"
"HHH90001006: Missing cache[" + TestHelper.prefix( regionName ) + "] was created on-the-fly"
)
);
}

View File

@ -39,6 +39,10 @@ public enum MissingCacheStrategy {
this.externalRepresentation = externalRepresentation;
}
public String getExternalRepresentation() {
return externalRepresentation;
}
public static MissingCacheStrategy interpretSetting(Object value) {
if ( value instanceof MissingCacheStrategy ) {
return (MissingCacheStrategy) value;

View File

@ -1,46 +0,0 @@
/*
* 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.cache.jcache.internal;
import org.hibernate.cache.jcache.ConfigSettings;
import org.hibernate.internal.CoreMessageLogger;
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.WARN;
/**
* The jboss-logging {@link MessageLogger} for the hibernate-jcache module. It reserves message ids ranging from
* 25099 to 25099 inclusively.
* <p/>
* New messages must be added after the last message defined to ensure message codes are unique.
*/
@MessageLogger(projectCode = "HHH")
@ValidIdRange(min = 25001, max = 25099)
public interface JCacheMessageLogger extends CoreMessageLogger {
JCacheMessageLogger INSTANCE = Logger.getMessageLogger(
JCacheMessageLogger.class,
"org.hibernate.orm.javax.cache"
);
@LogMessage(level = WARN)
@Message(
value = "Missing cache[%s] was created on-the-fly." +
" The created cache will use a provider-specific default configuration:" +
" make sure you defined one." +
" You can disable this warning by setting '" + ConfigSettings.MISSING_CACHE_STRATEGY +
"' to 'create'.",
id = 25001
)
void missingCacheCreated(String regionName);
}

View File

@ -24,6 +24,7 @@ import org.hibernate.cache.internal.DefaultCacheKeysFactory;
import org.hibernate.cache.jcache.ConfigSettings;
import org.hibernate.cache.jcache.MissingCacheStrategy;
import org.hibernate.cache.spi.CacheKeysFactory;
import org.hibernate.cache.spi.SecondLevelCacheLogger;
import org.hibernate.cache.spi.support.DomainDataStorageAccess;
import org.hibernate.cache.spi.support.RegionFactoryTemplate;
import org.hibernate.cache.spi.support.RegionNameQualifier;
@ -34,8 +35,6 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
* @author Alex Snaps
*/
public class JCacheRegionFactory extends RegionFactoryTemplate {
private static final JCacheMessageLogger LOG = JCacheMessageLogger.INSTANCE;
private final CacheKeysFactory cacheKeysFactory;
private volatile CacheManager cacheManager;
@ -90,7 +89,10 @@ public class JCacheRegionFactory extends RegionFactoryTemplate {
protected Cache<Object, Object> createCache(String regionName) {
switch ( missingCacheStrategy ) {
case CREATE_WARN:
LOG.missingCacheCreated( regionName );
SecondLevelCacheLogger.INSTANCE.missingCacheCreated(
regionName,
ConfigSettings.MISSING_CACHE_STRATEGY, MissingCacheStrategy.CREATE.getExternalRepresentation()
);
return cacheManager.createCache( regionName, new MutableConfiguration<>() );
case CREATE:
return cacheManager.createCache( regionName, new MutableConfiguration<>() );

View File

@ -13,7 +13,7 @@ import java.util.function.Consumer;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.jcache.ConfigSettings;
import org.hibernate.cache.jcache.internal.JCacheMessageLogger;
import org.hibernate.cache.spi.SecondLevelCacheLogger;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.service.spi.ServiceException;
@ -41,7 +41,7 @@ import static org.junit.Assert.fail;
public class MissingCacheStrategyTest extends BaseUnitTestCase {
@Rule
public LoggerInspectionRule logInspection = new LoggerInspectionRule( JCacheMessageLogger.INSTANCE );
public LoggerInspectionRule logInspection = new LoggerInspectionRule( SecondLevelCacheLogger.INSTANCE );
@Test
public void testMissingCacheStrategyDefault() {
@ -106,7 +106,7 @@ public class MissingCacheStrategyTest extends BaseUnitTestCase {
triggerables.put(
regionName,
logInspection.watchForLogMessages(
"HHH025001: Missing cache[" + TestHelper.prefix( regionName ) + "] was created on-the-fly"
"HHH90001006: Missing cache[" + TestHelper.prefix( regionName ) + "] was created on-the-fly"
)
);
}