类 NaturalIdXrefDelegate


  • public class NaturalIdXrefDelegate
    extends Object
    Maintains a PersistenceContext-level 2-way cross-reference (xref) between the identifiers and natural ids of entities associated with the PersistenceContext.

    Most operations resolve the proper NaturalIdXrefDelegate.NaturalIdResolutionCache to use based on the persister and simply delegate calls there.

    作者:
    Steve Ebersole
    • 构造器详细资料

      • 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, false would be returned here.
        参数:
        persister - The persister representing the entity type.
        pk - The primary key value
        naturalIdValues - The natural id value(s)
        返回:
        true if a new entry was actually added; false otherwise.
      • 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 value
        naturalIdValues - 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 value
        naturalIdValues - The natural id value(s) to check
        返回:
        true if the given naturalIdValues match the current cached values; false otherwise.
      • 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 null if none
      • 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