HHH-8159 - Apply fixups indicated by analysis tools

This commit is contained in:
Steve Ebersole 2013-04-26 11:36:58 -05:00
parent 42fd32a81a
commit 48331ed8cf
2 changed files with 19 additions and 8 deletions

View File

@ -24,10 +24,7 @@
package org.hibernate.engine; package org.hibernate.engine;
/** /**
* Describes the strategy for fetching an association * Describes the strategy for fetching an association, which includes both when and how.
* <p/>
* todo not really a fan of the name. not sure of a better one though.
* I'd almost rather see this be called the style, but then what to call FetchStyle? HowToFetch?
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@ -35,6 +32,12 @@ public class FetchStrategy {
private final FetchTiming timing; private final FetchTiming timing;
private final FetchStyle style; private final FetchStyle style;
/**
* Constructs a FetchStrategy.
*
* @param timing The fetch timing (the when)
* @param style The fetch style (the how).
*/
public FetchStrategy(FetchTiming timing, FetchStyle style) { public FetchStrategy(FetchTiming timing, FetchStyle style) {
this.timing = timing; this.timing = timing;
this.style = style; this.style = style;

View File

@ -57,6 +57,11 @@ public class NaturalIdXrefDelegate {
private final StatefulPersistenceContext persistenceContext; private final StatefulPersistenceContext persistenceContext;
private final Map<EntityPersister, NaturalIdResolutionCache> naturalIdResolutionCacheMap = new ConcurrentHashMap<EntityPersister, NaturalIdResolutionCache>(); private final Map<EntityPersister, NaturalIdResolutionCache> naturalIdResolutionCacheMap = new ConcurrentHashMap<EntityPersister, NaturalIdResolutionCache>();
/**
* Constructs a NaturalIdXrefDelegate
*
* @param persistenceContext The persistence context that owns this delegate
*/
public NaturalIdXrefDelegate(StatefulPersistenceContext persistenceContext) { public NaturalIdXrefDelegate(StatefulPersistenceContext persistenceContext) {
this.persistenceContext = persistenceContext; this.persistenceContext = persistenceContext;
} }
@ -105,7 +110,7 @@ public class NaturalIdXrefDelegate {
persister = locatePersisterForKey( persister ); persister = locatePersisterForKey( persister );
validateNaturalId( persister, naturalIdValues ); validateNaturalId( persister, naturalIdValues );
NaturalIdResolutionCache entityNaturalIdResolutionCache = naturalIdResolutionCacheMap.get( persister ); final NaturalIdResolutionCache entityNaturalIdResolutionCache = naturalIdResolutionCacheMap.get( persister );
Object[] sessionCachedNaturalIdValues = null; Object[] sessionCachedNaturalIdValues = null;
if ( entityNaturalIdResolutionCache != null ) { if ( entityNaturalIdResolutionCache != null ) {
final CachedNaturalId cachedNaturalId = entityNaturalIdResolutionCache.pkToNaturalIdMap final CachedNaturalId cachedNaturalId = entityNaturalIdResolutionCache.pkToNaturalIdMap
@ -142,7 +147,7 @@ public class NaturalIdXrefDelegate {
* @return {@code true} if the given naturalIdValues match the current cached values; {@code false} otherwise. * @return {@code true} if the given naturalIdValues match the current cached values; {@code false} otherwise.
*/ */
public boolean sameAsCached(EntityPersister persister, Serializable pk, Object[] naturalIdValues) { public boolean sameAsCached(EntityPersister persister, Serializable pk, Object[] naturalIdValues) {
NaturalIdResolutionCache entityNaturalIdResolutionCache = naturalIdResolutionCacheMap.get( persister ); final NaturalIdResolutionCache entityNaturalIdResolutionCache = naturalIdResolutionCacheMap.get( persister );
return entityNaturalIdResolutionCache != null return entityNaturalIdResolutionCache != null
&& entityNaturalIdResolutionCache.sameAsCached( pk, naturalIdValues ); && entityNaturalIdResolutionCache.sameAsCached( pk, naturalIdValues );
} }
@ -302,7 +307,7 @@ public class NaturalIdXrefDelegate {
Collection<Serializable> pks = null; Collection<Serializable> pks = null;
NaturalIdResolutionCache entityNaturalIdResolutionCache = naturalIdResolutionCacheMap.get( persister ); final NaturalIdResolutionCache entityNaturalIdResolutionCache = naturalIdResolutionCacheMap.get( persister );
if ( entityNaturalIdResolutionCache != null ) { if ( entityNaturalIdResolutionCache != null ) {
pks = entityNaturalIdResolutionCache.pkToNaturalIdMap.keySet(); pks = entityNaturalIdResolutionCache.pkToNaturalIdMap.keySet();
} }
@ -369,7 +374,7 @@ public class NaturalIdXrefDelegate {
for ( int naturalIdPropertyIndex : naturalIdPropertyIndexes ) { for ( int naturalIdPropertyIndex : naturalIdPropertyIndexes ) {
final Type type = persister.getPropertyType( persister.getPropertyNames()[ naturalIdPropertyIndex ] ); final Type type = persister.getPropertyType( persister.getPropertyNames()[ naturalIdPropertyIndex ] );
naturalIdTypes[i] = type; naturalIdTypes[i] = type;
int elementHashCode = values[i] == null ? 0 :type.getHashCode( values[i], persister.getFactory() ); final int elementHashCode = values[i] == null ? 0 :type.getHashCode( values[i], persister.getFactory() );
hashCodeCalculation = prime * hashCodeCalculation + elementHashCode; hashCodeCalculation = prime * hashCodeCalculation + elementHashCode;
i++; i++;
} }
@ -491,6 +496,9 @@ public class NaturalIdXrefDelegate {
} }
} }
/**
* Clear the resolution cache
*/
public void clear() { public void clear() {
naturalIdResolutionCacheMap.clear(); naturalIdResolutionCacheMap.clear();
} }