Top Inners Fields Constructors Methods
org.hibernate.engine.internal

public Class NaturalIdResolutionsImpl

extends Object
implements NaturalIdResolutions, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.hibernate.engine.spi.NaturalIdResolutions
Imports
java.io.Serializable, java.util.ArrayList, .Collection, .List, .Map, .Objects, java.util.concurrent.ConcurrentHashMap, org.hibernate.AssertionFailure, org.hibernate.cache.spi.access.NaturalIdDataAccess, .SoftLock, org.hibernate.engine.spi.CachedNaturalIdValueSource, .NaturalIdResolutions, .PersistenceContext, .Resolution, .SessionFactoryImplementor, .SharedSessionContractImplementor, org.hibernate.event.spi.EventManager, .HibernateMonitoringEvent, org.hibernate.metamodel.mapping.EntityMappingType, .NaturalIdLogging, .NaturalIdMapping, org.hibernate.persister.entity.EntityPersister, org.hibernate.sql.results.LoadingLogger, org.hibernate.stat.internal.StatsHelper, org.hibernate.stat.spi.StatisticsImplementor, org.jboss.logging.Logger

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
NaturalIdResolutionsImpl.EntityResolutions

Represents the entity-specific cross-reference cache.

private static class

Field Summary

Modifier and TypeField and Description
private static final Logger
private final StatefulPersistenceContext
private final ConcurrentHashMap<EntityMappingType, NaturalIdResolutionsImpl.EntityResolutions>

Constructor Summary

AccessConstructor and Description
public
NaturalIdResolutionsImpl(StatefulPersistenceContext
The persistence context that owns this delegate
persistenceContext
)

Constructs a NaturalIdXrefDelegate

Method Summary

Modifier and TypeMethod and Description
public boolean
cacheResolution(Object id, Object naturalId, EntityMappingType entityDescriptor)

Implements org.hibernate.engine.spi.NaturalIdResolutions.cacheResolution.

Caches a natural-id-to-identifier resolution.
public void
private boolean
cacheResolutionLocally(Object id, Object naturalId, EntityMappingType entityDescriptor)

Private, but see cacheResolution for public version

public void
public void
clear()

Clear the resolution cache

public Object
findCachedIdByNaturalId(Object naturalId, EntityMappingType entityDescriptor)

Implements org.hibernate.engine.spi.NaturalIdResolutions.findCachedIdByNaturalId.

Find the cached identifier for the given natural-id
public Object
findCachedNaturalIdById(Object id, EntityMappingType entityDescriptor)

Implements org.hibernate.engine.spi.NaturalIdResolutions.findCachedNaturalIdById.

Find the cached natural-id for the given identifier
public Collection<?>
getCachedPkResolutions(EntityMappingType entityDescriptor)

Implements org.hibernate.engine.spi.NaturalIdResolutions.getCachedPkResolutions.

Find all the locally cached primary key cross-reference entries for the given entity.
public void
handleEviction(Object id, Object object, EntityMappingType entityDescriptor)

Implements org.hibernate.engine.spi.NaturalIdResolutions.handleEviction.

Called on org.hibernate.Session#evict to give a chance to clean up natural-id cross refs.
public void
handleSynchronization(Object pk, Object entity, EntityMappingType entityDescriptor)

Implements org.hibernate.engine.spi.NaturalIdResolutions.handleSynchronization.

Part of the "load synchronization process".
private boolean
isValidValue(Object naturalIdValues, EntityMappingType entityDescriptor)

protected EntityPersister

Returns:

The root persister.
locatePersisterForKey
(EntityPersister
The persister representing the entity type.
persister
)

It is only valid to define natural ids at the root of an entity hierarchy.

public void
manageLocalResolution(Object id, Object naturalIdValue, EntityMappingType entityDescriptor, CachedNaturalIdValueSource source)

Implements org.hibernate.engine.spi.NaturalIdResolutions.manageLocalResolution.

Ensures that the necessary local cross-reference exists.
public void
manageSharedResolution(final Object id, Object naturalId, Object previousNaturalId, EntityMappingType entityDescriptor, CachedNaturalIdValueSource source)

Implements org.hibernate.engine.spi.NaturalIdResolutions.manageSharedResolution.

Ensures that the necessary cross-reference exists in the L2 cache
private void
manageSharedResolution(EntityPersister persister, final Object id, Object naturalIdValues, Object previousNaturalIdValues, CachedNaturalIdValueSource source)

public Object
removeLocalResolution(Object id, Object naturalId, EntityMappingType entityDescriptor)

Implements org.hibernate.engine.spi.NaturalIdResolutions.removeLocalResolution.

Removes any local cross-reference, returning the previously cached value if one.
private Object
removeNaturalIdCrossReference(Object id, Object naturalIdValue, EntityPersister persister)

Removes the cross-reference from both Session cache (Resolution) as well as the second-level cache (NaturalIdDataAccess).

public Object
removeResolution(Object id, Object naturalId, EntityMappingType entityDescriptor)

Implements org.hibernate.engine.spi.NaturalIdResolutions.removeResolution.

Removes a natural-id-to-identifier resolution.
public void
removeSharedResolution(Object id, Object naturalId, EntityMappingType entityDescriptor)

Implements org.hibernate.engine.spi.NaturalIdResolutions.removeSharedResolution.

Removes any cross-reference from the L2 cache
public boolean

Returns:

true if the given naturalIdValues match the current cached values; false otherwise.
sameAsCached
(EntityPersister
The persister representing the entity type.
persister
,
Object
The primary key value
pk
,
Object
The natural id value(s) to check
naturalIdValues
)

Are the naturals id values cached here (if any) for the given persister+pk combo the same as the given values?

protected SharedSessionContractImplementor

Returns:

The session
session
()

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

public void
stashInvalidNaturalIdReference(EntityPersister
The persister representing the entity type.
persister
,
Object
The "old" natural id values.
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.

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.

protected void
validateNaturalId(EntityMappingType
The entity type descriptor
entityDescriptor
,
Object
The natural id values
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
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

LOGback to summary
private static final Logger LOG
persistenceContextback to summary
private final StatefulPersistenceContext persistenceContext
resolutionsByEntityback to summary
private final ConcurrentHashMap<EntityMappingType, NaturalIdResolutionsImpl.EntityResolutions> resolutionsByEntity

Constructor Detail

NaturalIdResolutionsImplback to summary
public NaturalIdResolutionsImpl(StatefulPersistenceContext persistenceContext)

Constructs a NaturalIdXrefDelegate

Parameters
persistenceContext:StatefulPersistenceContext

The persistence context that owns this delegate

Method Detail

cacheResolutionback to summary
public boolean cacheResolution(Object id, Object naturalId, EntityMappingType entityDescriptor)

Implements org.hibernate.engine.spi.NaturalIdResolutions.cacheResolution.

Doc from org.hibernate.engine.spi.NaturalIdResolutions.cacheResolution.

Caches a natural-id-to-identifier resolution. Handles both the local (transactional) and shared (second-level) caches.

Returns:boolean

true if a new entry was actually added; false otherwise.

Annotations
@Override
cacheResolutionFromLoadback to summary
public void cacheResolutionFromLoad(Object id, Object naturalId, EntityMappingType entityDescriptor)

Implements org.hibernate.engine.spi.NaturalIdResolutions.cacheResolutionFromLoad.

Annotations
@Override
cacheResolutionLocallyback to summary
private boolean cacheResolutionLocally(Object id, Object naturalId, EntityMappingType entityDescriptor)

Private, but see cacheResolution for public version

cleanupFromSynchronizationsback to summary
public void cleanupFromSynchronizations()

Implements org.hibernate.engine.spi.NaturalIdResolutions.cleanupFromSynchronizations.

Doc from org.hibernate.engine.spi.NaturalIdResolutions.cleanupFromSynchronizations.

The clean up process of handleSynchronization. Responsible for cleaning up the tracking of old values as no longer valid.

Annotations
@Override
clearback to summary
public void clear()

Clear the resolution cache

findCachedIdByNaturalIdback to summary
public Object findCachedIdByNaturalId(Object naturalId, EntityMappingType entityDescriptor)

Implements org.hibernate.engine.spi.NaturalIdResolutions.findCachedIdByNaturalId.

Doc from org.hibernate.engine.spi.NaturalIdResolutions.findCachedIdByNaturalId.

Find the cached identifier for the given natural-id

Returns:Object

The cross-referenced primary key, INVALID_NATURAL_ID_REFERENCE or null.

Annotations
@Override
findCachedNaturalIdByIdback to summary
public Object findCachedNaturalIdById(Object id, EntityMappingType entityDescriptor)

Implements org.hibernate.engine.spi.NaturalIdResolutions.findCachedNaturalIdById.

Doc from org.hibernate.engine.spi.NaturalIdResolutions.findCachedNaturalIdById.

Find the cached natural-id for the given identifier

Returns:Object

The cross-referenced natural-id values or null

Annotations
@Override
getCachedPkResolutionsback to summary
public Collection<?> getCachedPkResolutions(EntityMappingType entityDescriptor)

Implements org.hibernate.engine.spi.NaturalIdResolutions.getCachedPkResolutions.

Doc from org.hibernate.engine.spi.NaturalIdResolutions.getCachedPkResolutions.

Find all the locally cached primary key cross-reference entries for the given entity.

Returns:Collection<?>

The primary keys

Annotations
@Override
handleEvictionback to summary
public void handleEviction(Object id, Object object, EntityMappingType entityDescriptor)

Implements org.hibernate.engine.spi.NaturalIdResolutions.handleEviction.

Doc from org.hibernate.engine.spi.NaturalIdResolutions.handleEviction.

Called on org.hibernate.Session#evict to give a chance to clean up natural-id cross refs.

Annotations
@Override
handleSynchronizationback to summary
public void handleSynchronization(Object pk, Object entity, EntityMappingType entityDescriptor)

Implements org.hibernate.engine.spi.NaturalIdResolutions.handleSynchronization.

Doc from org.hibernate.engine.spi.NaturalIdResolutions.handleSynchronization.

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 responsibility, cleanupFromSynchronizations is the inverse process called after flush to clean up those entries.

Annotations
@Override
isValidValueback to summary
private boolean isValidValue(Object naturalIdValues, EntityMappingType entityDescriptor)
locatePersisterForKeyback to summary
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:EntityPersister

The persister representing the entity type.

Returns:EntityPersister

The root persister.

manageLocalResolutionback to summary
public void manageLocalResolution(Object id, Object naturalIdValue, EntityMappingType entityDescriptor, CachedNaturalIdValueSource source)

Implements org.hibernate.engine.spi.NaturalIdResolutions.manageLocalResolution.

Doc from org.hibernate.engine.spi.NaturalIdResolutions.manageLocalResolution.

Ensures that the necessary local cross-reference exists. Specifically, this only effects the persistence-context cache, not the L2 cache

Annotations
@Override
manageSharedResolutionback to summary
public void manageSharedResolution(final Object id, Object naturalId, Object previousNaturalId, EntityMappingType entityDescriptor, CachedNaturalIdValueSource source)

Implements org.hibernate.engine.spi.NaturalIdResolutions.manageSharedResolution.

Doc from org.hibernate.engine.spi.NaturalIdResolutions.manageSharedResolution.

Ensures that the necessary cross-reference exists in the L2 cache

Annotations
@Override
manageSharedResolutionback to summary
private void manageSharedResolution(EntityPersister persister, final Object id, Object naturalIdValues, Object previousNaturalIdValues, CachedNaturalIdValueSource source)
removeLocalResolutionback to summary
public Object removeLocalResolution(Object id, Object naturalId, EntityMappingType entityDescriptor)

Implements org.hibernate.engine.spi.NaturalIdResolutions.removeLocalResolution.

Doc from org.hibernate.engine.spi.NaturalIdResolutions.removeLocalResolution.

Removes any local cross-reference, returning the previously cached value if one.

Again, this only effects the persistence-context cache, not the L2 cache

Annotations
@Override
removeNaturalIdCrossReferenceback to summary
private Object removeNaturalIdCrossReference(Object id, Object naturalIdValue, EntityPersister persister)

Removes the cross-reference from both Session cache (Resolution) as well as the second-level cache (NaturalIdDataAccess). Returns the natural-id value previously cached on the Session

removeResolutionback to summary
public Object removeResolution(Object id, Object naturalId, EntityMappingType entityDescriptor)

Implements org.hibernate.engine.spi.NaturalIdResolutions.removeResolution.

Doc from org.hibernate.engine.spi.NaturalIdResolutions.removeResolution.

Removes a natural-id-to-identifier resolution.

Handles both the local (transactional) and shared (second-level) caches.

Returns:Object

The cached values, if any. May be different from incoming values.

Annotations
@Override
removeSharedResolutionback to summary
public void removeSharedResolution(Object id, Object naturalId, EntityMappingType entityDescriptor)

Implements org.hibernate.engine.spi.NaturalIdResolutions.removeSharedResolution.

Doc from org.hibernate.engine.spi.NaturalIdResolutions.removeSharedResolution.

Removes any cross-reference from the L2 cache

Annotations
@Override
sameAsCachedback to summary
public boolean sameAsCached(EntityPersister persister, Object 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:EntityPersister

The persister representing the entity type.

pk:Object

The primary key value

naturalIdValues:Object

The natural id value(s) to check

Returns:boolean

true if the given naturalIdValues match the current cached values; false otherwise.

sessionback to summary
protected SharedSessionContractImplementor session()

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

Returns:SharedSessionContractImplementor

The session

stashInvalidNaturalIdReferenceback to summary
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:EntityPersister

The persister representing the entity type.

invalidNaturalIdValues:Object

The "old" natural id values.

See Also
org.hibernate.NaturalIdLoadAccess#setSynchronizationEnabled
unStashInvalidNaturalIdReferencesback to summary
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.

validateNaturalIdback to summary
protected void validateNaturalId(EntityMappingType entityDescriptor, 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
entityDescriptor:EntityMappingType

The entity type descriptor

naturalIdValues:Object

The natural id values

org.hibernate.engine.internal back to summary

private Class NaturalIdResolutionsImpl.EntityResolutions

extends Object
implements Serializable
Class Inheritance
  • java.lang.Object
  • org.hibernate.engine.internal.NaturalIdResolutionsImpl.EntityResolutions
All Implemented Interfaces
java.io.Serializable

Represents the entity-specific cross-reference cache.

Field Summary

Modifier and TypeField and Description
private final EntityMappingType
private List<Resolution>
private final Map<Resolution, Object>
private final PersistenceContext
private final Map<Object, Resolution>

Constructor Summary

AccessConstructor and Description
private
EntityResolutions(EntityMappingType entityDescriptor, PersistenceContext persistenceContext)

Method Summary

Modifier and TypeMethod and Description
public boolean
cache(Object pk, Object naturalIdValues)

public boolean
public EntityMappingType
public EntityPersister
public boolean
sameAsCached(Object pk, Object naturalIdValues)

public void
stashInvalidNaturalIdReference(Object invalidNaturalIdValues)

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

entityDescriptorback to summary
private final EntityMappingType entityDescriptor
invalidNaturalIdListback to summary
private List<Resolution> invalidNaturalIdList
naturalIdToPkMapback to summary
private final Map<Resolution, Object> naturalIdToPkMap
persistenceContextback to summary
private final PersistenceContext persistenceContext
pkToNaturalIdMapback to summary
private final Map<Object, Resolution> pkToNaturalIdMap

Constructor Detail

EntityResolutionsback to summary
private EntityResolutions(EntityMappingType entityDescriptor, PersistenceContext persistenceContext)

Method Detail

cacheback to summary
public boolean cache(Object pk, Object naturalIdValues)
containsInvalidNaturalIdReferenceback to summary
public boolean containsInvalidNaturalIdReference(Object naturalIdValues)
getEntityDescriptorback to summary
public EntityMappingType getEntityDescriptor()
getPersisterback to summary
public EntityPersister getPersister()
sameAsCachedback to summary
public boolean sameAsCached(Object pk, Object naturalIdValues)
stashInvalidNaturalIdReferenceback to summary
public void stashInvalidNaturalIdReference(Object invalidNaturalIdValues)
unStashInvalidNaturalIdReferencesback to summary
public void unStashInvalidNaturalIdReferences()
org.hibernate.engine.internal back to summary

private Class NaturalIdResolutionsImpl.ResolutionImpl

extends Object
implements Resolution, Serializable
Class Inheritance
  • java.lang.Object
  • org.hibernate.engine.internal.NaturalIdResolutionsImpl.ResolutionImpl
All Implemented Interfaces
java.io.Serializable, org.hibernate.engine.spi.Resolution

Field Summary

Modifier and TypeField and Description
private final EntityMappingType
private final int
private final Object
private final PersistenceContext

Constructor Summary

AccessConstructor and Description
public
ResolutionImpl(EntityMappingType entityDescriptor, Object naturalIdValue, PersistenceContext persistenceContext)

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public Object
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public boolean
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

entityDescriptorback to summary
private final EntityMappingType entityDescriptor
hashCodeback to summary
private final int hashCode
naturalIdValueback to summary
private final Object naturalIdValue
persistenceContextback to summary
private final PersistenceContext persistenceContext

Constructor Detail

ResolutionImplback to summary
public ResolutionImpl(EntityMappingType entityDescriptor, Object naturalIdValue, PersistenceContext persistenceContext)

Method Detail

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getNaturalIdValueback to summary
public Object getNaturalIdValue()

Implements org.hibernate.engine.spi.Resolution.getNaturalIdValue.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
isSameback to summary
public boolean isSame(Object otherValue)

Implements org.hibernate.engine.spi.Resolution.isSame.

Annotations
@Override