HHH-7866 Cleanup and added a few more checks

This commit is contained in:
Brett Meyer 2013-01-03 15:08:22 -05:00 committed by Brett Meyer
parent 3c9c226159
commit 03c010e519
1 changed files with 16 additions and 18 deletions

View File

@ -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 ) {