HHH-7866 Avoid redundant log level checking in StandardQueryCache
This commit is contained in:
parent
11ed12ef8f
commit
3c9c226159
|
@ -61,7 +61,7 @@ public class StandardQueryCache implements QueryCache {
|
|||
StandardQueryCache.class.getName()
|
||||
);
|
||||
|
||||
private static final boolean tracing = LOG.isTraceEnabled();
|
||||
private static final boolean tracing = LOG.isTraceEnabled();
|
||||
|
||||
private QueryResultsRegion cacheRegion;
|
||||
private UpdateTimestampsCache updateTimestampsCache;
|
||||
|
@ -88,13 +88,13 @@ public class StandardQueryCache implements QueryCache {
|
|||
this.updateTimestampsCache = updateTimestampsCache;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "UnnecessaryBoxing", "unchecked" })
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public boolean put(
|
||||
QueryKey key,
|
||||
Type[] returnTypes,
|
||||
List result,
|
||||
boolean isNaturalKeyLookup,
|
||||
SessionImplementor session) throws HibernateException {
|
||||
final QueryKey key,
|
||||
final Type[] returnTypes,
|
||||
final List result,
|
||||
final boolean isNaturalKeyLookup,
|
||||
final SessionImplementor session) throws HibernateException {
|
||||
if ( isNaturalKeyLookup && result.isEmpty() ) {
|
||||
return false;
|
||||
}
|
||||
|
@ -103,7 +103,9 @@ public class StandardQueryCache implements QueryCache {
|
|||
LOG.debugf( "Caching query results in region: %s; timestamp=%s", cacheRegion.getName(), ts );
|
||||
|
||||
List cacheable = new ArrayList( result.size() + 1 );
|
||||
logCachedResultDetails( key, null, returnTypes, cacheable );
|
||||
if ( tracing ) {
|
||||
logCachedResultDetails( key, null, returnTypes, cacheable );
|
||||
}
|
||||
cacheable.add( ts );
|
||||
final boolean singleResult = returnTypes.length == 1;
|
||||
for ( Object aResult : result ) {
|
||||
|
@ -113,7 +115,7 @@ public class StandardQueryCache implements QueryCache {
|
|||
null
|
||||
) : TypeHelper.disassemble( (Object[]) aResult, returnTypes, null, session, null );
|
||||
cacheable.add( cacheItem );
|
||||
logCachedResultRowDetails( returnTypes, aResult );
|
||||
if ( tracing ) logCachedResultRowDetails( returnTypes, aResult );
|
||||
}
|
||||
|
||||
cacheRegion.put( key, cacheable );
|
||||
|
@ -122,28 +124,29 @@ public class StandardQueryCache implements QueryCache {
|
|||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public List get(
|
||||
QueryKey key,
|
||||
Type[] returnTypes,
|
||||
boolean isNaturalKeyLookup,
|
||||
Set spaces,
|
||||
SessionImplementor session) throws HibernateException {
|
||||
LOG.debugf( "Checking cached query results in region: %s", cacheRegion.getName() );
|
||||
final QueryKey key,
|
||||
final Type[] returnTypes,
|
||||
final boolean isNaturalKeyLookup,
|
||||
final Set spaces,
|
||||
final SessionImplementor session) throws HibernateException {
|
||||
final boolean debugEnabled = LOG.isDebugEnabled();
|
||||
if ( debugEnabled ) LOG.debugf( "Checking cached query results in region: %s", cacheRegion.getName() );
|
||||
|
||||
List cacheable = (List) cacheRegion.get( key );
|
||||
logCachedResultDetails( key, spaces, returnTypes, cacheable );
|
||||
if ( tracing ) logCachedResultDetails( key, spaces, returnTypes, cacheable );
|
||||
|
||||
if ( cacheable == null ) {
|
||||
LOG.debug( "Query results were not found in cache" );
|
||||
if ( debugEnabled ) LOG.debug( "Query results were not found in cache" );
|
||||
return null;
|
||||
}
|
||||
|
||||
Long timestamp = (Long) cacheable.get( 0 );
|
||||
if ( !isNaturalKeyLookup && !isUpToDate( spaces, timestamp ) ) {
|
||||
LOG.debug( "Cached query results were not up-to-date" );
|
||||
if ( debugEnabled ) LOG.debug( "Cached query results were not up-to-date" );
|
||||
return null;
|
||||
}
|
||||
|
||||
LOG.debug( "Returning cached query results" );
|
||||
if ( debugEnabled ) LOG.debug( "Returning cached query results" );
|
||||
final boolean singleResult = returnTypes.length == 1;
|
||||
for ( int i = 1; i < cacheable.size(); i++ ) {
|
||||
if ( singleResult ) {
|
||||
|
@ -164,7 +167,7 @@ public class StandardQueryCache implements QueryCache {
|
|||
TypeHelper.assemble( (Serializable[]) cacheable.get( i ), returnTypes, session, null )
|
||||
);
|
||||
}
|
||||
logCachedResultRowDetails( returnTypes, result.get( i - 1 ) );
|
||||
if ( tracing ) logCachedResultRowDetails( returnTypes, result.get( i - 1 ) );
|
||||
}
|
||||
catch ( RuntimeException ex ) {
|
||||
if ( isNaturalKeyLookup &&
|
||||
|
@ -174,7 +177,7 @@ public class StandardQueryCache implements QueryCache {
|
|||
// the uoe could occur while resolving
|
||||
// associations, leaving the PC in an
|
||||
// inconsistent state
|
||||
LOG.debug( "Unable to reassemble cached result set" );
|
||||
if ( debugEnabled ) LOG.debug( "Unable to reassemble cached result set" );
|
||||
cacheRegion.evict( key );
|
||||
return null;
|
||||
}
|
||||
|
@ -184,7 +187,7 @@ public class StandardQueryCache implements QueryCache {
|
|||
return result;
|
||||
}
|
||||
|
||||
protected boolean isUpToDate(Set spaces, Long timestamp) {
|
||||
protected boolean isUpToDate(final Set spaces, final Long timestamp) {
|
||||
LOG.debugf( "Checking query spaces are up-to-date: %s", spaces );
|
||||
return updateTimestampsCache.isUpToDate( spaces, timestamp );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue