NaturalIdXrefDelegate (Hibernate JavaDocs)
Date: 2012-04-05

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.hibernate.engine.internal
Class NaturalIdXrefDelegate

    java.lang.Object
      org.hibernate.engine.internal.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 `NaturalIdResolutionCache` to use based on the persister and simply delegate calls there.

Constructor Summary
`NaturalIdXrefDelegate(StatefulPersistenceContext persistenceContext)`

Method Summary
`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.
`Object[]` | `findCachedNaturalId(EntityPersister persister, Serializable pk)` Given a persister and primary key, find the locally cross-referenced natural id.
`Serializable` | `findCachedNaturalIdResolution(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 EntityPersister` | `locatePersisterForKey(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 combo
`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?
`protected SessionImplementor` | `session()` Access to the session (via the PersistenceContext) to which this delegate ultimately belongs.
`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.
`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.
`protected void` | `validateNaturalId(EntityPersister persister, Object[] naturalIdValues)` Invariant validate of the natural id.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### NaturalIdXrefDelegate

    public NaturalIdXrefDelegate(StatefulPersistenceContext persistenceContext)

Method Detail

### session

    protected SessionImplementor session()

  Access to the session (via the PersistenceContext) to which this delegate ultimately belongs.

  Returns:
    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.

  Parameters:
    `persister` - The persister representing the entity type.
    `pk` - The primary key value
    `naturalIdValues` - The natural id value(s)
  Returns:
    `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

  Parameters:
    `persister` - The persister representing the entity type.
    `pk` - The primary key value
    `naturalIdValues` - The natural id value(s)
  Returns:
    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?

  Parameters:
    `persister` - The persister representing the entity type.
    `pk` - The primary key value
    `naturalIdValues` - The natural id value(s) to check
  Returns:
    `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.

  Parameters:
    `persister` - The persister representing the entity type.
  Returns:
    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

  Parameters:
    `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.

  Parameters:
    `persister` - The persister representing the entity type.
    `pk` - The entity primary key
  Returns:
    The corresponding cross-referenced natural id values, or `null` if 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 return `PersistenceContext.NaturalIdHelper#INVALID_NATURAL_ID_REFERENCE` if the given natural ids are known to be invalid (see `stashInvalidNaturalIdReference(org.hibernate.persister.entity.EntityPersister, java.lang.Object[])`).

  Parameters:
    `persister` - The persister representing the entity type.
    `naturalIdValues` - The natural id value(s)
  Returns:
    The corresponding cross-referenced primary key, `PersistenceContext.NaturalIdHelper#INVALID_NATURAL_ID_REFERENCE`, or `null` if 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.

  Parameters:
    `persister` - The persister representing the entity type.
  Returns:
    The primary keys
  See Also:
    `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.

  Parameters:
    `persister` - The persister representing the entity type.
    `invalidNaturalIdValues` - The "old" natural id values.
  See Also:
    `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.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2012 Red Hat, Inc. All Rights Reserved.