Package org.hibernate.engine.internal
Class NaturalIdResolutionsImpl
java.lang.Object
org.hibernate.engine.internal.NaturalIdResolutionsImpl
- All Implemented Interfaces:
Serializable,NaturalIdResolutions
- See Also:
-
Field Summary
Fields inherited from interface org.hibernate.engine.spi.NaturalIdResolutions
INVALID_NATURAL_ID_REFERENCE -
Constructor Summary
ConstructorsConstructorDescriptionNaturalIdResolutionsImpl(org.hibernate.engine.internal.StatefulPersistenceContext persistenceContext) Constructs a NaturalIdXrefDelegate -
Method Summary
Modifier and TypeMethodDescriptionbooleancacheResolution(Object id, Object naturalId, EntityMappingType entityDescriptor) Caches a natural-id-to-identifier resolution.voidcacheResolutionFromLoad(Object id, Object naturalId, EntityMappingType entityDescriptor) voidvoidclear()Clear the resolution cachefindCachedIdByNaturalId(Object naturalId, EntityMappingType entityDescriptor) Find the cached identifier for the given natural-idfindCachedNaturalIdById(Object id, EntityMappingType entityDescriptor) Find the cached natural-id for the given identifierCollection<?> getCachedPkResolutions(EntityMappingType entityDescriptor) Find all the locally cached primary key cross-reference entries for the given entity.voidhandleEviction(Object id, Object object, EntityMappingType entityDescriptor) Called onSession.evict(java.lang.Object)to give a chance to clean up natural-id cross refs.voidhandleSynchronization(Object pk, Object entity, EntityMappingType entityDescriptor) Part of the "load synchronization process".protected EntityPersisterlocatePersisterForKey(EntityPersister persister) It is only valid to define natural ids at the root of an entity hierarchy.voidmanageLocalResolution(Object id, Object naturalIdValue, EntityMappingType entityDescriptor, CachedNaturalIdValueSource source) Ensures that the necessary local cross-reference exists.voidmanageSharedResolution(Object id, Object naturalId, Object previousNaturalId, EntityMappingType entityDescriptor, CachedNaturalIdValueSource source) Ensures that the necessary cross-reference exists in the L2 cacheremoveLocalResolution(Object id, Object naturalId, EntityMappingType entityDescriptor) Removes any local cross-reference, returning the previously cached value if one.removeResolution(Object id, Object naturalId, EntityMappingType entityDescriptor) Removes a natural-id-to-identifier resolution.voidremoveSharedResolution(Object id, Object naturalId, EntityMappingType entityDescriptor) voidremoveSharedResolution(Object id, Object naturalId, EntityMappingType entityDescriptor, boolean delayToAfterTransactionCompletion) Removes any cross-reference from the L2 cachebooleansameAsCached(EntityPersister persister, Object pk, Object naturalIdValues) Are the naturals id values cached here (if any) for the given persister+pk combo the same as the given values?protected SharedSessionContractImplementorsession()Access to the session (via the PersistenceContext) to which this delegate ultimately belongs.voidstashInvalidNaturalIdReference(EntityPersister persister, Object invalidNaturalIdValues) As part of "load synchronization process", if a particular natural id is found to have changed we need to track its invalidity until after the next flush.voidAgain, as part of "load synchronization process" we need to also be able to clear references to these known-invalid natural-ids after flush.protected voidvalidateNaturalId(EntityMappingType entityDescriptor, Object naturalIdValues) Invariant validate of the natural id.
-
Constructor Details
-
NaturalIdResolutionsImpl
public NaturalIdResolutionsImpl(org.hibernate.engine.internal.StatefulPersistenceContext persistenceContext) Constructs a NaturalIdXrefDelegate- Parameters:
persistenceContext- The persistence context that owns this delegate
-
-
Method Details
-
session
Access to the session (via the PersistenceContext) to which this delegate ultimately belongs.- Returns:
- The session
-
cacheResolution
Description copied from interface:NaturalIdResolutionsCaches a natural-id-to-identifier resolution. Handles both the local (transactional) and shared (second-level) caches.- Specified by:
cacheResolutionin interfaceNaturalIdResolutions- Returns:
trueif a new entry was actually added;falseotherwise.
-
cacheResolutionFromLoad
public void cacheResolutionFromLoad(Object id, Object naturalId, EntityMappingType entityDescriptor) - Specified by:
cacheResolutionFromLoadin interfaceNaturalIdResolutions
-
removeResolution
Description copied from interface:NaturalIdResolutionsRemoves a natural-id-to-identifier resolution.Handles both the local (transactional) and shared (second-level) caches.
- Specified by:
removeResolutionin interfaceNaturalIdResolutions- Returns:
- The cached values, if any. May be different from incoming values.
-
manageLocalResolution
public void manageLocalResolution(Object id, Object naturalIdValue, EntityMappingType entityDescriptor, CachedNaturalIdValueSource source) Description copied from interface:NaturalIdResolutionsEnsures that the necessary local cross-reference exists. Specifically, this only effects the persistence-context cache, not the L2 cache- Specified by:
manageLocalResolutionin interfaceNaturalIdResolutions
-
removeLocalResolution
public Object removeLocalResolution(Object id, Object naturalId, EntityMappingType entityDescriptor) Description copied from interface:NaturalIdResolutionsRemoves any local cross-reference, returning the previously cached value if one.Again, this only effects the persistence-context cache, not the L2 cache
- Specified by:
removeLocalResolutionin interfaceNaturalIdResolutions
-
handleSynchronization
Description copied from interface:NaturalIdResolutionsPart of the "load synchronization process".Responsible for maintaining cross-reference entries when natural-id values were found to have changed.
Also responsible for tracking the old values as no longer valid until the next flush because otherwise going to the database would just re-pull the old values as valid. In this responsibility,
NaturalIdResolutions.cleanupFromSynchronizations()is the inverse process called after flush to clean up those entries.- Specified by:
handleSynchronizationin interfaceNaturalIdResolutions- See Also:
-
cleanupFromSynchronizations
public void cleanupFromSynchronizations()Description copied from interface:NaturalIdResolutionsThe clean up process ofNaturalIdResolutions.handleSynchronization(java.lang.Object, java.lang.Object, org.hibernate.metamodel.mapping.EntityMappingType). Responsible for cleaning up the tracking of old values as no longer valid.- Specified by:
cleanupFromSynchronizationsin interfaceNaturalIdResolutions
-
handleEviction
Description copied from interface:NaturalIdResolutionsCalled onSession.evict(java.lang.Object)to give a chance to clean up natural-id cross refs.- Specified by:
handleEvictionin interfaceNaturalIdResolutions
-
sameAsCached
Are the naturals id values cached here (if any) for the given persister+pk combo the same as the given values?- Parameters:
persister- The persister representing the entity type.pk- The primary key valuenaturalIdValues- The natural id value(s) to check- Returns:
trueif the given naturalIdValues match the current cached values;falseotherwise.
-
locatePersisterForKey
It is only valid to define natural ids at the root of an entity hierarchy. This method makes sure we are using the root persister.- Parameters:
persister- The persister representing the entity type.- Returns:
- The root persister.
-
validateNaturalId
Invariant validate of the natural id. Checks include- that the entity defines a natural id
- the number of natural id values matches the expected number
- Parameters:
entityDescriptor- The entity type descriptornaturalIdValues- The natural id values
-
findCachedNaturalIdById
Description copied from interface:NaturalIdResolutionsFind the cached natural-id for the given identifier- Specified by:
findCachedNaturalIdByIdin interfaceNaturalIdResolutions- Returns:
- The cross-referenced natural-id values or
null
-
findCachedIdByNaturalId
Description copied from interface:NaturalIdResolutionsFind the cached identifier for the given natural-id- Specified by:
findCachedIdByNaturalIdin interfaceNaturalIdResolutions- Returns:
- The cross-referenced primary key,
NaturalIdResolutions.INVALID_NATURAL_ID_REFERENCEornull.
-
getCachedPkResolutions
Description copied from interface:NaturalIdResolutionsFind all the locally cached primary key cross-reference entries for the given entity.- Specified by:
getCachedPkResolutionsin interfaceNaturalIdResolutions- Returns:
- The primary keys
-
stashInvalidNaturalIdReference
public void stashInvalidNaturalIdReference(EntityPersister persister, Object invalidNaturalIdValues) As part of "load synchronization process", if a particular natural id is found to have changed we need to track its invalidity until after the next flush. This method lets the "load synchronization process" indicate when it has encountered such changes.- Parameters:
persister- The persister representing the entity type.invalidNaturalIdValues- The "old" natural id values.- See Also:
-
unStashInvalidNaturalIdReferences
public void unStashInvalidNaturalIdReferences()Again, as part of "load synchronization process" we need to also be able to clear references to these known-invalid natural-ids after flush. This method exposes that capability. -
clear
public void clear()Clear the resolution cache
-