Package org.hibernate.engine.spi
Interface PersistenceContext.NaturalIdHelper
-
- Enclosing interface:
- PersistenceContext
public static interface PersistenceContext.NaturalIdHelper
Provides centralized access to natural-id-related functionality.
-
-
Field Summary
Fields Modifier and Type Field Description static java.io.Serializable
INVALID_NATURAL_ID_REFERENCE
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
cacheNaturalIdCrossReferenceFromLoad(EntityPersister persister, java.io.Serializable id, java.lang.Object[] naturalIdValues)
Performs processing related to creating natural-id cross-reference entries on load.void
cleanupFromSynchronizations()
java.lang.Object[]
extractNaturalIdValues(java.lang.Object[] state, EntityPersister persister)
Given an array of "full entity state", extract the portions that represent the natural idjava.lang.Object[]
extractNaturalIdValues(java.lang.Object entity, EntityPersister persister)
Given an entity instance, extract the values that represent the natural idjava.lang.Object[]
findCachedNaturalId(EntityPersister persister, java.io.Serializable pk)
Given a persister and primary key, find the corresponding cross-referenced natural id values.java.io.Serializable
findCachedNaturalIdResolution(EntityPersister persister, java.lang.Object[] naturalIdValues)
Given a persister and natural-id values, find the corresponding cross-referenced primary key.java.util.Collection<java.io.Serializable>
getCachedPkResolutions(EntityPersister persister)
Find all the locally cached primary key cross-reference entries for the given persister.void
handleEviction(java.lang.Object object, EntityPersister persister, java.io.Serializable identifier)
Called onSession.evict(java.lang.Object)
to give a chance to clean up natural-id cross refs.void
handleSynchronization(EntityPersister persister, java.io.Serializable pk, java.lang.Object entity)
Part of the "load synchronization process".void
manageLocalNaturalIdCrossReference(EntityPersister persister, java.io.Serializable id, java.lang.Object[] state, java.lang.Object[] previousState, CachedNaturalIdValueSource source)
Creates necessary local cross-reference entries.void
manageSharedNaturalIdCrossReference(EntityPersister persister, java.io.Serializable id, java.lang.Object[] state, java.lang.Object[] previousState, CachedNaturalIdValueSource source)
Creates necessary shared (second level cache) cross-reference entries.java.lang.Object[]
removeLocalNaturalIdCrossReference(EntityPersister persister, java.io.Serializable id, java.lang.Object[] state)
Cleans up local cross-reference entries.void
removeSharedNaturalIdCrossReference(EntityPersister persister, java.io.Serializable id, java.lang.Object[] naturalIdValues)
Cleans up local cross-reference entries.
-
-
-
Method Detail
-
extractNaturalIdValues
java.lang.Object[] extractNaturalIdValues(java.lang.Object[] state, EntityPersister persister)
Given an array of "full entity state", extract the portions that represent the natural id- Parameters:
state
- The attribute state arraypersister
- The persister representing the entity type.- Returns:
- The extracted natural id values
-
extractNaturalIdValues
java.lang.Object[] extractNaturalIdValues(java.lang.Object entity, EntityPersister persister)
Given an entity instance, extract the values that represent the natural id- Parameters:
entity
- The entity instancepersister
- The persister representing the entity type.- Returns:
- The extracted natural id values
-
cacheNaturalIdCrossReferenceFromLoad
void cacheNaturalIdCrossReferenceFromLoad(EntityPersister persister, java.io.Serializable id, java.lang.Object[] naturalIdValues)
Performs processing related to creating natural-id cross-reference entries on load. Handles both the local (transactional) and shared (second-level) caches.- Parameters:
persister
- The persister representing the entity type.id
- The primary key valuenaturalIdValues
- The natural id values
-
manageLocalNaturalIdCrossReference
void manageLocalNaturalIdCrossReference(EntityPersister persister, java.io.Serializable id, java.lang.Object[] state, java.lang.Object[] previousState, CachedNaturalIdValueSource source)
Creates necessary local cross-reference entries.- Parameters:
persister
- The persister representing the entity type.id
- The primary key valuestate
- Generally the "full entity state array", though could also be the natural id values arraypreviousState
- Generally the "full entity state array", though could also be the natural id values array. Specifically represents the previous values on update, and so is only used withCachedNaturalIdValueSource.UPDATE
source
- Enumeration representing how these values are coming into cache.
-
removeLocalNaturalIdCrossReference
java.lang.Object[] removeLocalNaturalIdCrossReference(EntityPersister persister, java.io.Serializable id, java.lang.Object[] state)
Cleans up local cross-reference entries.- Parameters:
persister
- The persister representing the entity type.id
- The primary key valuestate
- Generally the "full entity state array", though could also be the natural id values array- Returns:
- The local cached natural id values (could be different from given values).
-
manageSharedNaturalIdCrossReference
void manageSharedNaturalIdCrossReference(EntityPersister persister, java.io.Serializable id, java.lang.Object[] state, java.lang.Object[] previousState, CachedNaturalIdValueSource source)
Creates necessary shared (second level cache) cross-reference entries.- Parameters:
persister
- The persister representing the entity type.id
- The primary key valuestate
- Generally the "full entity state array", though could also be the natural id values arraypreviousState
- Generally the "full entity state array", though could also be the natural id values array. Specifically represents the previous values on update, and so is only used withCachedNaturalIdValueSource.UPDATE
source
- Enumeration representing how these values are coming into cache.
-
removeSharedNaturalIdCrossReference
void removeSharedNaturalIdCrossReference(EntityPersister persister, java.io.Serializable id, java.lang.Object[] naturalIdValues)
Cleans up local cross-reference entries.- Parameters:
persister
- The persister representing the entity type.id
- The primary key valuenaturalIdValues
- The natural id values array
-
findCachedNaturalId
java.lang.Object[] findCachedNaturalId(EntityPersister persister, java.io.Serializable pk)
Given a persister and primary key, find the corresponding cross-referenced natural id values.- Parameters:
persister
- The persister representing the entity type.pk
- The primary key value- Returns:
- The cross-referenced natural-id values, or
null
-
findCachedNaturalIdResolution
java.io.Serializable findCachedNaturalIdResolution(EntityPersister persister, java.lang.Object[] naturalIdValues)
Given a persister and natural-id values, find the corresponding cross-referenced primary key. Will returnINVALID_NATURAL_ID_REFERENCE
if the given natural ids are known to be invalid.- Parameters:
persister
- The persister representing the entity type.naturalIdValues
- The natural id value(s)- Returns:
- The corresponding cross-referenced primary key,
INVALID_NATURAL_ID_REFERENCE
, ornull
.
-
getCachedPkResolutions
java.util.Collection<java.io.Serializable> getCachedPkResolutions(EntityPersister persister)
Find all the locally cached primary key cross-reference entries for the given persister.- Parameters:
persister
- The persister representing the entity type.- Returns:
- The primary keys
-
handleSynchronization
void handleSynchronization(EntityPersister persister, java.io.Serializable pk, java.lang.Object entity)
Part 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 last responsibility,cleanupFromSynchronizations()
is the inverse process called after flush to clean up those entries.- Parameters:
persister
- The persister representing the entity type.pk
- The primary keyentity
- The entity instance- See Also:
cleanupFromSynchronizations()
-
cleanupFromSynchronizations
void cleanupFromSynchronizations()
The clean up process ofhandleSynchronization(org.hibernate.persister.entity.EntityPersister, java.io.Serializable, java.lang.Object)
. Responsible for cleaning up the tracking of old values as no longer valid.
-
handleEviction
void handleEviction(java.lang.Object object, EntityPersister persister, java.io.Serializable identifier)
Called onSession.evict(java.lang.Object)
to give a chance to clean up natural-id cross refs.- Parameters:
object
- The entity instance.persister
- The entity persisteridentifier
- The entity identifier
-
-