HHH-7866 Cleanup and added a few more checks
This commit is contained in:
parent
3c9c226159
commit
03c010e519
|
@ -61,7 +61,8 @@ public class StandardQueryCache implements QueryCache {
|
||||||
StandardQueryCache.class.getName()
|
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 QueryResultsRegion cacheRegion;
|
||||||
private UpdateTimestampsCache updateTimestampsCache;
|
private UpdateTimestampsCache updateTimestampsCache;
|
||||||
|
@ -100,12 +101,10 @@ public class StandardQueryCache implements QueryCache {
|
||||||
}
|
}
|
||||||
long ts = cacheRegion.nextTimestamp();
|
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 );
|
List cacheable = new ArrayList( result.size() + 1 );
|
||||||
if ( tracing ) {
|
|
||||||
logCachedResultDetails( key, null, returnTypes, cacheable );
|
logCachedResultDetails( key, null, returnTypes, cacheable );
|
||||||
}
|
|
||||||
cacheable.add( ts );
|
cacheable.add( ts );
|
||||||
final boolean singleResult = returnTypes.length == 1;
|
final boolean singleResult = returnTypes.length == 1;
|
||||||
for ( Object aResult : result ) {
|
for ( Object aResult : result ) {
|
||||||
|
@ -115,7 +114,7 @@ public class StandardQueryCache implements QueryCache {
|
||||||
null
|
null
|
||||||
) : TypeHelper.disassemble( (Object[]) aResult, returnTypes, null, session, null );
|
) : TypeHelper.disassemble( (Object[]) aResult, returnTypes, null, session, null );
|
||||||
cacheable.add( cacheItem );
|
cacheable.add( cacheItem );
|
||||||
if ( tracing ) logCachedResultRowDetails( returnTypes, aResult );
|
logCachedResultRowDetails( returnTypes, aResult );
|
||||||
}
|
}
|
||||||
|
|
||||||
cacheRegion.put( key, cacheable );
|
cacheRegion.put( key, cacheable );
|
||||||
|
@ -129,24 +128,23 @@ public class StandardQueryCache implements QueryCache {
|
||||||
final boolean isNaturalKeyLookup,
|
final boolean isNaturalKeyLookup,
|
||||||
final Set spaces,
|
final Set spaces,
|
||||||
final SessionImplementor session) throws HibernateException {
|
final SessionImplementor session) throws HibernateException {
|
||||||
final boolean debugEnabled = LOG.isDebugEnabled();
|
if ( DEBUGGING ) LOG.debugf( "Checking cached query results in region: %s", cacheRegion.getName() );
|
||||||
if ( debugEnabled ) LOG.debugf( "Checking cached query results in region: %s", cacheRegion.getName() );
|
|
||||||
|
|
||||||
List cacheable = (List) cacheRegion.get( key );
|
List cacheable = (List) cacheRegion.get( key );
|
||||||
if ( tracing ) logCachedResultDetails( key, spaces, returnTypes, cacheable );
|
logCachedResultDetails( key, spaces, returnTypes, cacheable );
|
||||||
|
|
||||||
if ( cacheable == null ) {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Long timestamp = (Long) cacheable.get( 0 );
|
Long timestamp = (Long) cacheable.get( 0 );
|
||||||
if ( !isNaturalKeyLookup && !isUpToDate( spaces, timestamp ) ) {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( debugEnabled ) LOG.debug( "Returning cached query results" );
|
if ( DEBUGGING ) LOG.debug( "Returning cached query results" );
|
||||||
final boolean singleResult = returnTypes.length == 1;
|
final boolean singleResult = returnTypes.length == 1;
|
||||||
for ( int i = 1; i < cacheable.size(); i++ ) {
|
for ( int i = 1; i < cacheable.size(); i++ ) {
|
||||||
if ( singleResult ) {
|
if ( singleResult ) {
|
||||||
|
@ -167,7 +165,7 @@ public class StandardQueryCache implements QueryCache {
|
||||||
TypeHelper.assemble( (Serializable[]) cacheable.get( i ), returnTypes, session, null )
|
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 ) {
|
catch ( RuntimeException ex ) {
|
||||||
if ( isNaturalKeyLookup &&
|
if ( isNaturalKeyLookup &&
|
||||||
|
@ -177,7 +175,7 @@ public class StandardQueryCache implements QueryCache {
|
||||||
// the uoe could occur while resolving
|
// the uoe could occur while resolving
|
||||||
// associations, leaving the PC in an
|
// associations, leaving the PC in an
|
||||||
// inconsistent state
|
// 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 );
|
cacheRegion.evict( key );
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -188,7 +186,7 @@ public class StandardQueryCache implements QueryCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isUpToDate(final Set spaces, final Long timestamp) {
|
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 );
|
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) {
|
private static void logCachedResultDetails(QueryKey key, Set querySpaces, Type[] returnTypes, List result) {
|
||||||
if ( !LOG.isTraceEnabled() ) {
|
if ( !TRACING ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LOG.trace( "key.hashCode=" + key.hashCode() );
|
LOG.trace( "key.hashCode=" + key.hashCode() );
|
||||||
|
@ -236,7 +234,7 @@ public class StandardQueryCache implements QueryCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void logCachedResultRowDetails(Type[] returnTypes, Object result) {
|
private static void logCachedResultRowDetails(Type[] returnTypes, Object result) {
|
||||||
if ( !LOG.isTraceEnabled() ) {
|
if ( !TRACING ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logCachedResultRowDetails(
|
logCachedResultRowDetails(
|
||||||
|
@ -246,7 +244,7 @@ public class StandardQueryCache implements QueryCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void logCachedResultRowDetails(Type[] returnTypes, Object[] tuple) {
|
private static void logCachedResultRowDetails(Type[] returnTypes, Object[] tuple) {
|
||||||
if ( !tracing ) {
|
if ( !TRACING ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ( tuple == null ) {
|
if ( tuple == null ) {
|
||||||
|
|
Loading…
Reference in New Issue