Created
February 20, 2012 15:34
-
-
Save edalquist/1869688 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void evictNaturalIdResolution(EntityPersister persister, final Serializable pk, Object[] naturalIdValues) { | |
if ( !persister.hasNaturalIdentifier() ) { | |
throw new IllegalArgumentException( "Entity did not define a natrual-id" ); | |
} | |
if ( naturalIdValues != null && persister.getNaturalIdentifierProperties().length != naturalIdValues.length ) { | |
throw new IllegalArgumentException( "Mismatch between expected number of natural-id values and found." ); | |
} | |
NaturalIdResolutionCache entityNaturalIdResolutionCache = naturalIdResolutionCacheMap.get( persister ); | |
if ( entityNaturalIdResolutionCache != null ) { | |
LocalNaturalIdCacheKey localNaturalIdCacheKey = entityNaturalIdResolutionCache.pkToNaturalIdMap.remove( pk ); | |
if ( localNaturalIdCacheKey == null && naturalIdValues == null ) { | |
// No pk->LocalNaturalIdCacheKey cached in session, without naturalIdValues nothing more can be done | |
return; | |
} | |
if ( localNaturalIdCacheKey == null ) { | |
// No pk->LocalNaturalIdCacheKey cached in session but we have naturalIdValues, create LocalNaturalIdCacheKey | |
// and evict that | |
localNaturalIdCacheKey = new LocalNaturalIdCacheKey( persister, naturalIdValues ); | |
} | |
else if ( naturalIdValues == null ) { | |
// Found pk->LocalNaturalIdCacheKey cached in session but we don't have naturalIdValues, populate them from | |
// the session cache so the 2L cache can be evicted | |
naturalIdValues = localNaturalIdCacheKey.getValues(); | |
} | |
entityNaturalIdResolutionCache.naturalIdToPkMap.remove( localNaturalIdCacheKey ); | |
} | |
if ( persister.hasNaturalIdCache() ) { | |
final NaturalIdRegionAccessStrategy naturalIdCacheAccessStrategy = persister.getNaturalIdCacheAccessStrategy(); | |
final NaturalIdCacheKey naturalIdCacheKey = new NaturalIdCacheKey( naturalIdValues, persister, session ); | |
naturalIdCacheAccessStrategy.evict( naturalIdCacheKey ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment