mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-28 06:49:09 +00:00
HHH-7866 Cleanup and added a few more checks
This commit is contained in:
parent
5cf1b469dd
commit
510f876ff0
@ -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 boolean put(
|
||||
}
|
||||
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 );
|
||||
}
|
||||
cacheable.add( ts );
|
||||
final boolean singleResult = returnTypes.length == 1;
|
||||
for ( Object aResult : result ) {
|
||||
@ -115,7 +114,7 @@ public boolean put(
|
||||
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 List get(
|
||||
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 List get(
|
||||
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 List get(
|
||||
// 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 List get(
|
||||
}
|
||||
|
||||
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 String toString() {
|
||||
}
|
||||
|
||||
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 @@ private static void logCachedResultDetails(QueryKey key, Set querySpaces, Type[]
|
||||
}
|
||||
|
||||
private static void logCachedResultRowDetails(Type[] returnTypes, Object result) {
|
||||
if ( !LOG.isTraceEnabled() ) {
|
||||
if ( !TRACING ) {
|
||||
return;
|
||||
}
|
||||
logCachedResultRowDetails(
|
||||
@ -246,7 +244,7 @@ private static void logCachedResultRowDetails(Type[] returnTypes, Object result)
|
||||
}
|
||||
|
||||
private static void logCachedResultRowDetails(Type[] returnTypes, Object[] tuple) {
|
||||
if ( !tracing ) {
|
||||
if ( !TRACING ) {
|
||||
return;
|
||||
}
|
||||
if ( tuple == null ) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user