Skip to content

Commit 9d6ff28

Browse files
committed
improvements to logging and unwrapping in EnabledCaching
1 parent 3917398 commit 9d6ff28

File tree

1 file changed

+20
-31
lines changed

1 file changed

+20
-31
lines changed

hibernate-core/src/main/java/org/hibernate/cache/internal/EnabledCaching.java

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,8 @@ public void evictEntityData(String entityName, Object identifier) {
260260
final EntityDataAccess cacheAccess = persister.getCacheAccessStrategy();
261261
if ( cacheAccess != null ) {
262262
if ( LOG.isDebugEnabled() ) {
263-
LOG.debugf(
264-
"Evicting second-level cache: %s",
265-
infoString( persister, identifier, sessionFactory )
266-
);
263+
LOG.debug( "Evicting entity second-level cache: "
264+
+ infoString( persister, identifier, sessionFactory ) );
267265
}
268266

269267
final Object cacheKey =
@@ -308,7 +306,7 @@ protected void evictEntityData(EntityPersister entityDescriptor) {
308306
private void evictEntityData(NavigableRole navigableRole, EntityDataAccess cacheAccess) {
309307
if ( cacheAccess != null ) {
310308
if ( LOG.isDebugEnabled() ) {
311-
LOG.debugf( "Evicting entity cache: %s", navigableRole.getFullPath() );
309+
LOG.debug( "Evicting entity second-level cache: " + navigableRole.getFullPath() );
312310
}
313311
cacheAccess.evictAll();
314312
}
@@ -347,7 +345,7 @@ public void evictNaturalIdData() {
347345
private void evictNaturalIdData(NavigableRole rootEntityRole, NaturalIdDataAccess cacheAccess) {
348346
if ( cacheAccess != null ) {
349347
if ( LOG.isDebugEnabled() ) {
350-
LOG.debugf( "Evicting natural-id cache: %s", rootEntityRole.getFullPath() );
348+
LOG.debug( "Evicting natural-id cache: " + rootEntityRole.getFullPath() );
351349
}
352350
cacheAccess.evictAll();
353351
}
@@ -378,10 +376,8 @@ public void evictCollectionData(String role, Object ownerIdentifier) {
378376
final CollectionDataAccess cacheAccess = persister.getCacheAccessStrategy();
379377
if ( cacheAccess != null ) {
380378
if ( LOG.isDebugEnabled() ) {
381-
LOG.debugf(
382-
"Evicting second-level cache: %s",
383-
collectionInfoString( persister, ownerIdentifier, sessionFactory )
384-
);
379+
LOG.debug( "Evicting collection second-level cache: "
380+
+ collectionInfoString( persister, ownerIdentifier, sessionFactory ) );
385381
}
386382

387383
final Object cacheKey =
@@ -403,7 +399,7 @@ private void evictCollectionData(CollectionPersister collectionDescriptor) {
403399
private void evictCollectionData(NavigableRole navigableRole, CollectionDataAccess cacheAccess) {
404400
if ( cacheAccess != null ) {
405401
if ( LOG.isDebugEnabled() ) {
406-
LOG.debugf( "Evicting second-level cache: %s", navigableRole.getFullPath() );
402+
LOG.debug( "Evicting collection second-level cache: " + navigableRole.getFullPath() );
407403
}
408404
cacheAccess.evictAll();
409405
}
@@ -440,7 +436,7 @@ public void evictQueryRegion(String regionName) {
440436
private void evictQueryResultRegion(QueryResultsCache cache) {
441437
if ( cache != null ) {
442438
if ( LOG.isDebugEnabled() ) {
443-
LOG.debugf( "Evicting query cache, region: %s", cache.getRegion().getName() );
439+
LOG.debug( "Evicting query cache region: " + cache.getRegion().getName() );
444440
}
445441
cache.clear();
446442
}
@@ -449,7 +445,7 @@ private void evictQueryResultRegion(QueryResultsCache cache) {
449445
@Override
450446
public void evictQueryRegions() {
451447
if ( LOG.isDebugEnabled() ) {
452-
LOG.debug( "Evicting cache of all query regions." );
448+
LOG.debug( "Evicting cache of all query regions" );
453449
}
454450

455451
evictQueryResultRegion( defaultQueryResultsCache );
@@ -507,20 +503,10 @@ protected QueryResultsCache makeQueryResultsRegionAccess(String regionName) {
507503
}
508504

509505
private QueryResultsRegion getQueryResultsRegion(String regionName) {
510-
final Region region = regionsByName.computeIfAbsent(
511-
regionName,
512-
this::makeQueryResultsRegion
513-
);
514-
if ( region instanceof QueryResultsRegion queryResultsRegion ) {
515-
return queryResultsRegion;
516-
}
517-
else {
518-
// There was already a different type of Region with the same name.
519-
return queryResultsRegionsByDuplicateName.computeIfAbsent(
520-
regionName,
521-
this::makeQueryResultsRegion
522-
);
523-
}
506+
final Region region = regionsByName.computeIfAbsent( regionName, this::makeQueryResultsRegion );
507+
return region instanceof QueryResultsRegion queryResultsRegion
508+
? queryResultsRegion // There was already a different type of Region with the same name.
509+
: queryResultsRegionsByDuplicateName.computeIfAbsent( regionName, this::makeQueryResultsRegion );
524510
}
525511

526512
protected QueryResultsRegion makeQueryResultsRegion(String regionName) {
@@ -544,16 +530,19 @@ public void evictRegion(String regionName) {
544530

545531
@Override
546532
@SuppressWarnings("unchecked")
547-
public <T> T unwrap(Class<T> cls) {
548-
if ( org.hibernate.Cache.class.isAssignableFrom( cls ) ) {
533+
public <T> T unwrap(Class<T> type) {
534+
if ( org.hibernate.Cache.class.isAssignableFrom( type ) ) {
535+
return (T) this;
536+
}
537+
if ( org.hibernate.cache.spi.CacheImplementor.class.isAssignableFrom( type ) ) {
549538
return (T) this;
550539
}
551540

552-
if ( RegionFactory.class.isAssignableFrom( cls ) ) {
541+
if ( RegionFactory.class.isAssignableFrom( type ) ) {
553542
return (T) regionFactory;
554543
}
555544

556-
throw new PersistenceException( "Hibernate cannot unwrap Cache as " + cls.getName() );
545+
throw new PersistenceException( "Hibernate cannot unwrap Cache as '" + type.getName() + "'" );
557546
}
558547

559548
@Override

0 commit comments

Comments
 (0)