public class NaturalIdXrefDelegate extends Object
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 and Description |
---|
NaturalIdXrefDelegate(StatefulPersistenceContext persistenceContext)
Constructs a NaturalIdXrefDelegate
|
Modifier and Type | Method and Description |
---|---|
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.
|
void |
clear()
Clear the resolution cache
|
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.
|
public NaturalIdXrefDelegate(StatefulPersistenceContext persistenceContext)
persistenceContext
- The persistence context that owns this delegateprotected SessionImplementor session()
public boolean cacheNaturalIdCrossReference(EntityPersister persister, Serializable pk, Object[] naturalIdValues)
false
would be returned here.persister
- The persister representing the entity type.pk
- The primary key valuenaturalIdValues
- The natural id value(s)true
if a new entry was actually added; false
otherwise.public Object[] removeNaturalIdCrossReference(EntityPersister persister, Serializable pk, Object[] naturalIdValues)
persister
- The persister representing the entity type.pk
- The primary key valuenaturalIdValues
- The natural id value(s)public boolean sameAsCached(EntityPersister persister, Serializable pk, Object[] naturalIdValues)
persister
- The persister representing the entity type.pk
- The primary key valuenaturalIdValues
- The natural id value(s) to checktrue
if the given naturalIdValues match the current cached values; false
otherwise.protected EntityPersister locatePersisterForKey(EntityPersister persister)
persister
- The persister representing the entity type.protected void validateNaturalId(EntityPersister persister, Object[] naturalIdValues)
persister
- The persister representing the entity type.naturalIdValues
- The natural id valuespublic Object[] findCachedNaturalId(EntityPersister persister, Serializable pk)
persister
- The persister representing the entity type.pk
- The entity primary keynull
if nonepublic Serializable findCachedNaturalIdResolution(EntityPersister persister, Object[] naturalIdValues)
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[])
).persister
- The persister representing the entity type.naturalIdValues
- The natural id value(s)PersistenceContext.NaturalIdHelper#INVALID_NATURAL_ID_REFERENCE
,
or null
if nonepublic Collection<Serializable> getCachedPkResolutions(EntityPersister persister)
persister
- The persister representing the entity type.NaturalIdLoadAccess.setSynchronizationEnabled(boolean)
public void stashInvalidNaturalIdReference(EntityPersister persister, Object[] invalidNaturalIdValues)
persister
- The persister representing the entity type.invalidNaturalIdValues
- The "old" natural id values.NaturalIdLoadAccess.setSynchronizationEnabled(boolean)
public void unStashInvalidNaturalIdReferences()
public void clear()
Copyright © 2017 JBoss by Red Hat. All rights reserved.