From a9e482bce0d813bdabd5f638d9ed98b443a3547b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A5le=20W=2E=20Pedersen?= Date: Mon, 14 Dec 2015 14:25:22 +0100 Subject: [PATCH] HHH-10366 Check for trace logging before calling log method and unused method parameters --- .../cache/internal/StandardQueryCache.java | 20 ++++++---- .../internal/DefaultLoadEventListener.java | 40 +++---------------- 2 files changed, 18 insertions(+), 42 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 68db3858a3..d0091cac0f 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 @@ -116,7 +116,9 @@ public class StandardQueryCache implements QueryCache { } final List cacheable = new ArrayList( result.size() + 1 ); - logCachedResultDetails( key, null, returnTypes, cacheable ); + if ( TRACING ) { + logCachedResultDetails( key, null, returnTypes, cacheable ); + } cacheable.add( session.getTimestamp() ); final boolean isSingleResult = returnTypes.length == 1; @@ -125,7 +127,9 @@ public class StandardQueryCache implements QueryCache { ? returnTypes[0].disassemble( aResult, session, null ) : TypeHelper.disassemble( (Object[]) aResult, returnTypes, null, session, null ); cacheable.add( cacheItem ); - logCachedResultRowDetails( returnTypes, aResult ); + if ( TRACING ) { + logCachedResultRowDetails( returnTypes, aResult ); + } } try { @@ -152,8 +156,9 @@ public class StandardQueryCache implements QueryCache { } final List cacheable = getCachedResults( key, session ); - logCachedResultDetails( key, spaces, returnTypes, cacheable ); - + if ( TRACING ) { + logCachedResultDetails( key, spaces, returnTypes, cacheable ); + } if ( cacheable == null ) { if ( DEBUGGING ) { LOG.debug( "Query results were not found in cache" ); @@ -205,7 +210,9 @@ public class StandardQueryCache implements QueryCache { result.add( TypeHelper.assemble( (Serializable[]) cacheable.get( i ), returnTypes, session, null ) ); - logCachedResultRowDetails( returnTypes, result.get( i - 1 ) ); + if ( TRACING ) { + logCachedResultRowDetails( returnTypes, result.get( i - 1 ) ); + } } } return result; @@ -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 } ) diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLoadEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLoadEventListener.java index 4ec3ce2b8b..2fd425c3e8 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLoadEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultLoadEventListener.java @@ -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 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 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(); @@ -731,8 +705,6 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i session ); } - - //subclassPersister.afterInitialize( entity, referenceCacheEntry.areLazyPropertiesUnfetched(), session ); statefulPersistenceContext.initializeNonLazyCollections(); }