HHH-12529 - Some StatisticsImpl methods throw an exception instead of returning null

This commit is contained in:
Steve Ebersole 2018-05-14 13:19:27 -05:00
parent e2ac4eb22f
commit 26bf33abdc
2 changed files with 10 additions and 2 deletions

View File

@ -625,10 +625,12 @@ public class StatisticsImpl implements StatisticsImplementor, Service {
return l2CacheStatsMap.computeIfAbsent(
regionName,
s -> {
final Region region = sessionFactory.getCache().getRegion( regionName );
Region region = sessionFactory.getCache().getRegion( regionName );
if ( region == null ) {
throw new IllegalArgumentException( "Unknown cache region : " + regionName );
// this is the pre-5.3 behavior. and since this is a pre-5.3 method it should behave consistently
// NOTE that this method is deprecated
region = sessionFactory.getCache().getQueryResultsCache( regionName ).getRegion();
}
return new CacheRegionStatisticsImpl( region );
@ -638,6 +640,9 @@ public class StatisticsImpl implements StatisticsImplementor, Service {
@Override
public CacheRegionStatisticsImpl getSecondLevelCacheStatistics(String regionName) {
if ( sessionFactory == null ) {
return null;
}
return getCacheRegionStatistics( sessionFactory.getCache().unqualifyRegionName( regionName ) );
}

View File

@ -82,6 +82,9 @@ public class RegionNameTest extends BaseNonConfigCoreFunctionalTestCase {
final NaturalIdCacheStatistics naturalIdCacheStatistics = stats.getNaturalIdCacheStatistics( regionName );
assert naturalIdCacheStatistics != null;
final SecondLevelCacheStatistics dne = stats.getSecondLevelCacheStatistics( cachePrefix + ".does.not.exist" );
assert dne != null;
}
// todo (5.3) : any other API I can think of that deals with region-name?