HHH-10366 Check for trace logging before calling log method and unused method parameters

This commit is contained in:
Ståle W. Pedersen 2015-12-14 14:25:22 +01:00 committed by Sanne Grinovero
parent c1cb413c2a
commit a679528f71
2 changed files with 18 additions and 42 deletions

View File

@ -116,7 +116,9 @@ public class StandardQueryCache implements QueryCache {
}
final List cacheable = new ArrayList( result.size() + 1 );
if ( TRACING ) {
logCachedResultDetails( key, null, returnTypes, cacheable );
}
cacheable.add( session.getTimestamp() );
final boolean isSingleResult = returnTypes.length == 1;
@ -125,8 +127,10 @@ public class StandardQueryCache implements QueryCache {
? returnTypes[0].disassemble( aResult, session, null )
: TypeHelper.disassemble( (Object[]) aResult, returnTypes, null, session, null );
cacheable.add( cacheItem );
if ( TRACING ) {
logCachedResultRowDetails( returnTypes, aResult );
}
}
try {
session.getEventListenerManager().cachePutStart();
@ -152,8 +156,9 @@ public class StandardQueryCache implements QueryCache {
}
final List cacheable = getCachedResults( key, session );
if ( TRACING ) {
logCachedResultDetails( key, spaces, returnTypes, cacheable );
}
if ( cacheable == null ) {
if ( DEBUGGING ) {
LOG.debug( "Query results were not found in cache" );
@ -205,9 +210,11 @@ public class StandardQueryCache implements QueryCache {
result.add(
TypeHelper.assemble( (Serializable[]) cacheable.get( i ), returnTypes, session, null )
);
if ( TRACING ) {
logCachedResultRowDetails( returnTypes, result.get( i - 1 ) );
}
}
}
return result;
}
catch ( RuntimeException ex ) {
@ -280,9 +287,6 @@ public class StandardQueryCache implements QueryCache {
}
private static void logCachedResultRowDetails(Type[] returnTypes, Object result) {
if ( !TRACING ) {
return;
}
logCachedResultRowDetails(
returnTypes,
( result instanceof Object[] ? (Object[]) result : new Object[] { result } )

View File

@ -613,12 +613,12 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
if(entry.isReferenceEntry()) {
if( event.getInstanceToLoad() != null ) {
throw new HibernateException(
String.format( "Attempt to load entity [%s] from cache using provided object instance, but cache " +
"is storing references: "+ event.getEntityId()));
"Attempt to load entity [%s] from cache using provided object instance, but cache " +
"is storing references: "+ event.getEntityId());
}
else {
return convertCacheReferenceEntryToEntity( (ReferenceCacheEntryImpl) entry,
event.getEntityId(), persister, event.getSession(), entityKey, event );
event.getSession(), entityKey);
}
}
else {
@ -666,51 +666,25 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
private Object convertCacheReferenceEntryToEntity(
ReferenceCacheEntryImpl referenceCacheEntry,
Serializable entityId,
EntityPersister persister,
EventSource session,
EntityKey entityKey,
LoadEvent loadEvent) {
EntityKey entityKey) {
final Object entity = referenceCacheEntry.getReference();
if ( entity == null ) {
throw new IllegalStateException(
"Reference cache entry contained null : " + entityId);
"Reference cache entry contained null : " + referenceCacheEntry.toString());
}
else {
makeEntityCircularReferenceSafe(referenceCacheEntry, entityId, session, entity, entityKey);
//PostLoad is needed for EJB3
//but not for reference cached entities??
/*
EventListenerGroup<PostLoadEventListener> evenListenerGroup = getEvenListenerGroup(session);
if(!evenListenerGroup.isEmpty()) {
postLoad(session, evenListenerGroup.listeners(), entity, entityId, persister, loadEvent);
}
*/
makeEntityCircularReferenceSafe( referenceCacheEntry, session, entity, entityKey );
return entity;
}
}
private void postLoad(EventSource session, Iterable<PostLoadEventListener> listeners,
Object entity, Serializable entityId, EntityPersister persister, LoadEvent event) {
PostLoadEvent postLoadEvent = event.getPostLoadEvent()
.setEntity(entity)
.setId(entityId)
.setPersister(persister);
for (PostLoadEventListener listener : listeners) {
listener.onPostLoad(postLoadEvent);
}
}
private void makeEntityCircularReferenceSafe(ReferenceCacheEntryImpl referenceCacheEntry,
Serializable entityId,
EventSource session,
Object entity,
EntityKey entityKey) {
//final EntityPersister subclassPersister = referenceCacheEntry.getSubclassPersister();
// make it circular-reference safe
final StatefulPersistenceContext statefulPersistenceContext = (StatefulPersistenceContext) session.getPersistenceContext();
@ -730,8 +704,6 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
session
);
}
//subclassPersister.afterInitialize( entity, referenceCacheEntry.areLazyPropertiesUnfetched(), session );
statefulPersistenceContext.initializeNonLazyCollections();
}