Skip to content

Commit 77c8cc9

Browse files
committed
migrate QueryResultsCacheImpl logging to SecondLevelCacheLogger
1 parent 64d9696 commit 77c8cc9

File tree

2 files changed

+47
-11
lines changed

2 files changed

+47
-11
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public boolean put(
5151
final List<?> results,
5252
final SharedSessionContractImplementor session) throws HibernateException {
5353
if ( L2CACHE_LOGGER.isTraceEnabled() ) {
54-
L2CACHE_LOGGER.tracef( "Caching query results in region: %s; timestamp=%s",
54+
L2CACHE_LOGGER.cachingQueryResults(
5555
cacheRegion.getName(),
5656
session.getCacheTransactionSynchronization().getCachingTimestamp() );
5757
}
@@ -92,26 +92,26 @@ public List<?> get(
9292
final SharedSessionContractImplementor session) throws HibernateException {
9393
final boolean loggerTraceEnabled = L2CACHE_LOGGER.isTraceEnabled();
9494
if ( loggerTraceEnabled ) {
95-
L2CACHE_LOGGER.tracef( "Checking cached query results in region: %s", cacheRegion.getName() );
95+
L2CACHE_LOGGER.checkingCachedQueryResults( cacheRegion.getName() );
9696
}
9797

9898
final CacheItem cacheItem = getCachedData( key, session );
9999
if ( cacheItem == null ) {
100100
if ( loggerTraceEnabled ) {
101-
L2CACHE_LOGGER.trace( "Query results were not found in cache" );
101+
L2CACHE_LOGGER.queryResultsNotFound();
102102
}
103103
return null;
104104
}
105105

106106
if ( !timestampsCache.isUpToDate( spaces, cacheItem.timestamp, session ) ) {
107107
if ( loggerTraceEnabled ) {
108-
L2CACHE_LOGGER.trace( "Cached query results were not up-to-date" );
108+
L2CACHE_LOGGER.cachedQueryResultsStale();
109109
}
110110
return null;
111111
}
112112

113113
if ( loggerTraceEnabled ) {
114-
L2CACHE_LOGGER.trace( "Returning cached query results" );
114+
L2CACHE_LOGGER.returningCachedQueryResults();
115115
}
116116

117117
// No need to copy results, since consumers will never mutate
@@ -124,27 +124,28 @@ public List<?> get(
124124
final String[] spaces,
125125
final SharedSessionContractImplementor session) throws HibernateException {
126126
final boolean loggerTraceEnabled = L2CACHE_LOGGER.isTraceEnabled();
127+
127128
if ( loggerTraceEnabled ) {
128-
L2CACHE_LOGGER.tracef( "Checking cached query results in region: %s", cacheRegion.getName() );
129+
L2CACHE_LOGGER.checkingCachedQueryResults( cacheRegion.getName() );
129130
}
130131

131132
final CacheItem cacheItem = getCachedData( key, session );
132133
if ( cacheItem == null ) {
133134
if ( loggerTraceEnabled ) {
134-
L2CACHE_LOGGER.trace( "Query results were not found in cache" );
135+
L2CACHE_LOGGER.queryResultsNotFound();
135136
}
136137
return null;
137138
}
138139

139140
if ( !timestampsCache.isUpToDate( spaces, cacheItem.timestamp, session ) ) {
140141
if ( loggerTraceEnabled ) {
141-
L2CACHE_LOGGER.trace( "Cached query results were not up-to-date" );
142+
L2CACHE_LOGGER.cachedQueryResultsStale();
142143
}
143144
return null;
144145
}
145146

146147
if ( loggerTraceEnabled ) {
147-
L2CACHE_LOGGER.trace( "Returning cached query results" );
148+
L2CACHE_LOGGER.returningCachedQueryResults();
148149
}
149150

150151
return deepCopy( cacheItem.results );

hibernate-core/src/main/java/org/hibernate/cache/spi/SecondLevelCacheLogger.java

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.lang.invoke.MethodHandles;
1818

1919
import static org.jboss.logging.Logger.Level.INFO;
20+
import static org.jboss.logging.Logger.Level.TRACE;
2021
import static org.jboss.logging.Logger.Level.WARN;
2122

2223
/**
@@ -26,7 +27,7 @@
2627
@ValidIdRange( min = 90001001, max = 90002000 )
2728
@SubSystemLogging(
2829
name = SecondLevelCacheLogger.LOGGER_NAME,
29-
description = "Logging related to Hibernate second-level caching"
30+
description = "Logging related to the second-level cache"
3031
)
3132
@Internal
3233
public interface SecondLevelCacheLogger extends BasicLogger {
@@ -60,7 +61,7 @@ public interface SecondLevelCacheLogger extends BasicLogger {
6061

6162
@LogMessage( level = WARN )
6263
@Message(
63-
value = "Read-only caching was requested for mutable natural-id for entity [%s]",
64+
value = "Read-only caching was requested for entity [%s] with mutable natural id",
6465
id = NAMESPACE + 4
6566
)
6667
void readOnlyCachingMutableNaturalId(String entity);
@@ -100,4 +101,38 @@ public interface SecondLevelCacheLogger extends BasicLogger {
100101
@SuppressWarnings( "unused" ) // used by hibernate-jcache
101102
void nonStandardSupportForAccessType(String regionName, String accessType, String regionFactoryClass);
102103

104+
@LogMessage(level = TRACE)
105+
@Message(
106+
value = "Caching query results in region '%s' with timestamp %s",
107+
id = NAMESPACE + 9
108+
)
109+
void cachingQueryResults(String regionName, long timestamp);
110+
111+
@LogMessage(level = TRACE)
112+
@Message(
113+
value = "Checking cached query results in region '%s'",
114+
id = NAMESPACE + 10
115+
)
116+
void checkingCachedQueryResults(String regionName);
117+
118+
@LogMessage(level = TRACE)
119+
@Message(
120+
value = "Query results were not found in cache",
121+
id = NAMESPACE + 11
122+
)
123+
void queryResultsNotFound();
124+
125+
@LogMessage(level = TRACE)
126+
@Message(
127+
value = "Cached query results were stale",
128+
id = NAMESPACE + 12
129+
)
130+
void cachedQueryResultsStale();
131+
132+
@LogMessage(level = TRACE)
133+
@Message(
134+
value = "Returning cached query results",
135+
id = NAMESPACE + 14
136+
)
137+
void returningCachedQueryResults();
103138
}

0 commit comments

Comments
 (0)