From 03c010e519bc9a33da514b9ea0be38bc944670af Mon Sep 17 00:00:00 2001 From: Brett Meyer Date: Thu, 3 Jan 2013 15:08:22 -0500 Subject: [PATCH] HHH-7866 Cleanup and added a few more checks --- .../cache/internal/StandardQueryCache.java | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/cache/internal/StandardQueryCache.java b/hibernate-core/src/main/java/org/hibernate/cache/internal/StandardQueryCache.java index 444c1ca5d3..9cb2c7daa7 100644 --- a/hibernate-core/src/main/java/org/hibernate/cache/internal/StandardQueryCache.java +++ b/hibernate-core/src/main/java/org/hibernate/cache/internal/StandardQueryCache.java @@ -61,7 +61,8 @@ public class StandardQueryCache implements QueryCache { StandardQueryCache.class.getName() ); - private static final boolean tracing = LOG.isTraceEnabled(); + private static final boolean DEBUGGING = LOG.isDebugEnabled(); + private static final boolean TRACING = LOG.isTraceEnabled(); private QueryResultsRegion cacheRegion; private UpdateTimestampsCache updateTimestampsCache; @@ -100,12 +101,10 @@ public class StandardQueryCache implements QueryCache { } long ts = cacheRegion.nextTimestamp(); - LOG.debugf( "Caching query results in region: %s; timestamp=%s", cacheRegion.getName(), ts ); + if ( DEBUGGING ) LOG.debugf( "Caching query results in region: %s; timestamp=%s", cacheRegion.getName(), ts ); List cacheable = new ArrayList( result.size() + 1 ); - if ( tracing ) { - logCachedResultDetails( key, null, returnTypes, cacheable ); - } + logCachedResultDetails( key, null, returnTypes, cacheable ); cacheable.add( ts ); final boolean singleResult = returnTypes.length == 1; for ( Object aResult : result ) { @@ -115,7 +114,7 @@ public class StandardQueryCache implements QueryCache { null ) : TypeHelper.disassemble( (Object[]) aResult, returnTypes, null, session, null ); cacheable.add( cacheItem ); - if ( tracing ) logCachedResultRowDetails( returnTypes, aResult ); + logCachedResultRowDetails( returnTypes, aResult ); } cacheRegion.put( key, cacheable ); @@ -129,24 +128,23 @@ public class StandardQueryCache implements QueryCache { 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() ); + if ( DEBUGGING ) LOG.debugf( "Checking cached query results in region: %s", cacheRegion.getName() ); List cacheable = (List) cacheRegion.get( key ); - if ( tracing ) logCachedResultDetails( key, spaces, returnTypes, cacheable ); + logCachedResultDetails( key, spaces, returnTypes, cacheable ); if ( cacheable == null ) { - if ( debugEnabled ) LOG.debug( "Query results were not found in cache" ); + if ( DEBUGGING ) LOG.debug( "Query results were not found in cache" ); return null; } Long timestamp = (Long) cacheable.get( 0 ); if ( !isNaturalKeyLookup && !isUpToDate( spaces, timestamp ) ) { - if ( debugEnabled ) LOG.debug( "Cached query results were not up-to-date" ); + if ( DEBUGGING ) LOG.debug( "Cached query results were not up-to-date" ); return null; } - if ( debugEnabled ) LOG.debug( "Returning cached query results" ); + if ( DEBUGGING ) LOG.debug( "Returning cached query results" ); final boolean singleResult = returnTypes.length == 1; for ( int i = 1; i < cacheable.size(); i++ ) { if ( singleResult ) { @@ -167,7 +165,7 @@ public class StandardQueryCache implements QueryCache { TypeHelper.assemble( (Serializable[]) cacheable.get( i ), returnTypes, session, null ) ); } - if ( tracing ) logCachedResultRowDetails( returnTypes, result.get( i - 1 ) ); + logCachedResultRowDetails( returnTypes, result.get( i - 1 ) ); } catch ( RuntimeException ex ) { if ( isNaturalKeyLookup && @@ -177,7 +175,7 @@ public class StandardQueryCache implements QueryCache { // the uoe could occur while resolving // associations, leaving the PC in an // inconsistent state - if ( debugEnabled ) LOG.debug( "Unable to reassemble cached result set" ); + if ( DEBUGGING ) LOG.debug( "Unable to reassemble cached result set" ); cacheRegion.evict( key ); return null; } @@ -188,7 +186,7 @@ public class StandardQueryCache implements QueryCache { } protected boolean isUpToDate(final Set spaces, final Long timestamp) { - LOG.debugf( "Checking query spaces are up-to-date: %s", spaces ); + if ( DEBUGGING ) LOG.debugf( "Checking query spaces are up-to-date: %s", spaces ); return updateTimestampsCache.isUpToDate( spaces, timestamp ); } @@ -211,7 +209,7 @@ public class StandardQueryCache implements QueryCache { } private static void logCachedResultDetails(QueryKey key, Set querySpaces, Type[] returnTypes, List result) { - if ( !LOG.isTraceEnabled() ) { + if ( !TRACING ) { return; } LOG.trace( "key.hashCode=" + key.hashCode() ); @@ -236,7 +234,7 @@ public class StandardQueryCache implements QueryCache { } private static void logCachedResultRowDetails(Type[] returnTypes, Object result) { - if ( !LOG.isTraceEnabled() ) { + if ( !TRACING ) { return; } logCachedResultRowDetails( @@ -246,7 +244,7 @@ public class StandardQueryCache implements QueryCache { } private static void logCachedResultRowDetails(Type[] returnTypes, Object[] tuple) { - if ( !tracing ) { + if ( !TRACING ) { return; } if ( tuple == null ) {