类 NaturalIdXrefDelegate
- java.lang.Object
-
- org.hibernate.engine.internal.NaturalIdXrefDelegate
-
public class NaturalIdXrefDelegate extends Object
Maintains aPersistenceContext-level 2-way cross-reference (xref) between the identifiers and natural ids of entities associated with the PersistenceContext. Most operations resolve the properNaturalIdXrefDelegate.NaturalIdResolutionCacheto use based on the persister and simply delegate calls there.- 作者:
- Steve Ebersole
-
-
构造器概要
构造器 构造器 说明 NaturalIdXrefDelegate(StatefulPersistenceContext persistenceContext)Constructs a NaturalIdXrefDelegate
-
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 booleancacheNaturalIdCrossReference(EntityPersister persister, Serializable pk, Object[] naturalIdValues)Creates needed cross-reference entries between the given primary (pk) and natural (naturalIdValues) key values for the given persister.voidclear()Clear the resolution cacheObject[]findCachedNaturalId(EntityPersister persister, Serializable pk)Given a persister and primary key, find the locally cross-referenced natural id.SerializablefindCachedNaturalIdResolution(EntityPersister persister, Object[] naturalIdValues)Given a persister and natural-id value(s), find the locally cross-referenced primary key.Collection<Serializable>getCachedPkResolutions(EntityPersister persister)Return all locally cross-referenced primary keys for the given persister.protected EntityPersisterlocatePersisterForKey(EntityPersister persister)It is only valid to define natural ids at the root of an entity hierarchy.Object[]removeNaturalIdCrossReference(EntityPersister persister, Serializable pk, Object[] naturalIdValues)Handle removing cross reference entries for the given natural-id/pk combobooleansameAsCached(EntityPersister persister, Serializable 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.voidunStashInvalidNaturalIdReferences()Again, 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(EntityPersister persister, Object[] naturalIdValues)Invariant validate of the natural id.
-
-
-
构造器详细资料
-
NaturalIdXrefDelegate
public NaturalIdXrefDelegate(StatefulPersistenceContext persistenceContext)
Constructs a NaturalIdXrefDelegate- 参数:
persistenceContext- The persistence context that owns this delegate
-
-
方法详细资料
-
session
protected SharedSessionContractImplementor session()
Access to the session (via the PersistenceContext) to which this delegate ultimately belongs.- 返回:
- The session
-
cacheNaturalIdCrossReference
public boolean cacheNaturalIdCrossReference(EntityPersister persister, Serializable pk, Object[] naturalIdValues)
Creates needed cross-reference entries between the given primary (pk) and natural (naturalIdValues) key values for the given persister. Returns an indication of whether entries were actually made. If those values already existed as an entry,falsewould be returned here.- 参数:
persister- The persister representing the entity type.pk- The primary key valuenaturalIdValues- The natural id value(s)- 返回:
trueif a new entry was actually added;falseotherwise.
-
removeNaturalIdCrossReference
public Object[] removeNaturalIdCrossReference(EntityPersister persister, Serializable pk, Object[] naturalIdValues)
Handle removing cross reference entries for the given natural-id/pk combo- 参数:
persister- The persister representing the entity type.pk- The primary key valuenaturalIdValues- The natural id value(s)- 返回:
- The cached values, if any. May be different from incoming values.
-
sameAsCached
public boolean sameAsCached(EntityPersister persister, Serializable pk, Object[] naturalIdValues)
Are the naturals id values cached here (if any) for the given persister+pk combo the same as the given values?- 参数:
persister- The persister representing the entity type.pk- The primary key valuenaturalIdValues- The natural id value(s) to check- 返回:
trueif the given naturalIdValues match the current cached values;falseotherwise.
-
locatePersisterForKey
protected EntityPersister locatePersisterForKey(EntityPersister persister)
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.- 参数:
persister- The persister representing the entity type.- 返回:
- The root persister.
-
validateNaturalId
protected void validateNaturalId(EntityPersister persister, Object[] naturalIdValues)
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
- 参数:
persister- The persister representing the entity type.naturalIdValues- The natural id values
-
findCachedNaturalId
public Object[] findCachedNaturalId(EntityPersister persister, Serializable pk)
Given a persister and primary key, find the locally cross-referenced natural id.- 参数:
persister- The persister representing the entity type.pk- The entity primary key- 返回:
- The corresponding cross-referenced natural id values, or
nullif none
-
findCachedNaturalIdResolution
public Serializable findCachedNaturalIdResolution(EntityPersister persister, Object[] naturalIdValues)
Given a persister and natural-id value(s), find the locally cross-referenced primary key. Will returnPersistenceContext.NaturalIdHelper.INVALID_NATURAL_ID_REFERENCEif the given natural ids are known to be invalid (seestashInvalidNaturalIdReference(org.hibernate.persister.entity.EntityPersister, java.lang.Object[])).- 参数:
persister- The persister representing the entity type.naturalIdValues- The natural id value(s)- 返回:
- The corresponding cross-referenced primary key,
PersistenceContext.NaturalIdHelper.INVALID_NATURAL_ID_REFERENCE, ornullif none
-
getCachedPkResolutions
public Collection<Serializable> getCachedPkResolutions(EntityPersister persister)
Return all locally cross-referenced primary keys for the given persister. Used as part of load synchronization process.- 参数:
persister- The persister representing the entity type.- 返回:
- The primary keys
- 另请参阅:
NaturalIdLoadAccess.setSynchronizationEnabled(boolean)
-
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.- 参数:
persister- The persister representing the entity type.invalidNaturalIdValues- The "old" natural id values.- 另请参阅:
NaturalIdLoadAccess.setSynchronizationEnabled(boolean)
-
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
-
-